You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ripple.apache.org by gt...@apache.org on 2013/10/21 04:42:34 UTC

[05/15] git commit: inapp browser emulation

inapp browser emulation


Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/80b1964f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/80b1964f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/80b1964f

Branch: refs/heads/next
Commit: 80b1964fe032ea4d706027adfbcebdcde06214e2
Parents: f788155
Author: Gord Tanner <gt...@gmail.com>
Authored: Tue Sep 24 22:40:22 2013 -0400
Committer: Gord Tanner <gt...@gmail.com>
Committed: Tue Sep 24 22:40:22 2013 -0400

----------------------------------------------------------------------
 .../cordova/3.0.0/bridge/inappbrowser.js        |  23 +++-
 lib/client/ui/plugins/browser.js                |  49 +++-----
 lib/client/ui/plugins/browser/overlay.html      |   9 +-
 lib/server/browser.js                           | 122 -------------------
 lib/server/emulate.js                           |   2 -
 5 files changed, 44 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/80b1964f/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js b/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
index 5305ef7..abb5131 100644
--- a/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
+++ b/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
@@ -20,19 +20,30 @@
  */
 
 var emulatorBridge = ripple('emulatorBridge'),
+    event = ripple('event'),
     browser = ripple("ui/plugins/browser");
 
 module.exports = {
     open: function (win, fail, args) {
         var url = args[0],
             target = args[1],
-            options = args[2];
+            options = args[2],
+            trigger = function (event) {
+                return function () {
+                    win({type: event, url: url});
+                };
+            };
 
         browser.show(url);
-        window.setTimeout(function () {
-            //win({type: "loadstart", url: url});
-            //win({type: "loadstop", url: url});
-        }, 100);
+
+        jWorkflow.order()
+                 .chill(1)
+                 .andThen(trigger("loadstart"))
+                 .chill(10)
+                 .andThen(trigger("loadstop"))
+                 .start();
+
+        event.once("browser-close", trigger('exit'));
     },
 
     show: function (win, fail, args) {
@@ -40,7 +51,7 @@ module.exports = {
     },
 
     close: function (win, fail, args) {
-        console.log(args);
+        browser.hide();
     },
 
     injectScriptCode: function (win, fail, args) {

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/80b1964f/lib/client/ui/plugins/browser.js
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/browser.js b/lib/client/ui/plugins/browser.js
index f3c5093..503481d 100644
--- a/lib/client/ui/plugins/browser.js
+++ b/lib/client/ui/plugins/browser.js
@@ -21,33 +21,24 @@
 
 var ui = ripple('ui'),
     event = ripple('event'),
-    close = document.getElementById('close-browser');
+    _url = document.getElementById('browser-url'),
+    _target = document.getElementById('browser-target'),
+    _options = document.getElementById('browser-options');
+    close = document.getElementById('browser-close'),
+    _self = {
+        initialize: function () {
+            close.addEventListener('click', _self.hide);
+        },
+        show: function (url, target, options) {
+            _url.innerHTML = url;
+            _target.innerHTML = target;
+            _options.innerHTML = JSON.stringify(options);
+            ui.showOverlay("inappbrowser");
+        },
+        hide: function () {
+            ui.hideOverlay("inappbrowser");
+            event.trigger("browser-close");
+        }
+    };
 
-module.exports = {
-    initialize: function () {
-        close.addEventListener('click', function () {
-            ui.hideOverlay('inappbrowser');
-        });
-    },
-    show: function (url, target, options) {
-
-        var params = "url=" + url;
-        var xhr = new XMLHttpRequest();
-        xhr.open("POST", "/ripple/browser");
-
-        //Send the proper header information along with the request
-        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-        xhr.setRequestHeader("Content-length", params.length);
-        xhr.setRequestHeader("Connection", "close");
-
-        xhr.send(params, false);
-
-        ui.showOverlay("inappbrowser", function (node) {
-            var iframe = document.getElementById("browser");
-            iframe.src = url;
-        });
-    },
-    hide: function () {
-        ui.hideOverlay("inappbrowser");
-    }
-};
+module.exports = _self;

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/80b1964f/lib/client/ui/plugins/browser/overlay.html
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/browser/overlay.html b/lib/client/ui/plugins/browser/overlay.html
index b8ffa36..766a6e2 100644
--- a/lib/client/ui/plugins/browser/overlay.html
+++ b/lib/client/ui/plugins/browser/overlay.html
@@ -21,8 +21,13 @@
 <section id="inappbrowser" class="overlay-browser">
     <h2>InAppBrowser Emulation</h2>
     It is like a browser, only it is all up in your app
-    <iframe id="browser" src="" frameborder="0"></iframe>
-    <button id="close-browser" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only small-button">
+    <h3>URL:</h3>
+    <blockquote id="browser-url">http://www.google.com</blockquote> 
+    <h3>TARGET:</h3>
+    <blockquote id="browser-target">_blank</blockquote>
+    <h3>OPTIONS:</h3>
+    <blockquote id="browser-options">{}</blockquote>
+    <button id="browser-close" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only small-button">
         <span class="ui-button-text">Close</span>
     </button>
 </section>

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/80b1964f/lib/server/browser.js
----------------------------------------------------------------------
diff --git a/lib/server/browser.js b/lib/server/browser.js
deleted file mode 100644
index 90d9916..0000000
--- a/lib/server/browser.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-var url = require('url'),
-    request = require('request'),
-    _url = "http://slashdot.org";
-
-// TODO: Put this and xhr_proxy into common file (epic DRY..)?
-function proxyRemote(opts, req, res) {
-    var proxyReqData,
-        proxyReqHeaders,
-        proxyReq,
-        parsedURL = url.parse(opts.url),
-
-        // TODO: There should be a better way to inject on files...
-        shouldInjectInto = req.path.match(/^\/$/) || req.path.match(/\.html/);
-
-    console.log("INFO:".green + " Remote proxy: Retrieve -> " + opts.url);
-
-    proxyReqHeaders = Object.keys(req.headers).reduce(function (headers, key) {
-        if (key !== "origin") {
-            headers[key] = req.headers[key];
-        }
-        return headers;
-    }, {});
-
-    proxyReqHeaders["host"] = parsedURL.host;
-
-    if (opts.userAgent) {
-        proxyReqHeaders["user-agent"] = opts.userAgent;
-    }
-
-    // HACK: Makes https://google.com crash (issue with node? request? us?)
-    delete proxyReqHeaders["accept-encoding"];
-
-    proxyReqData = {
-        url: parsedURL,
-        method: req.method,
-        headers: proxyReqHeaders
-    };
-
-    if (Object.keys(req.body).length > 0) {
-        if (req.get("content-type") === "application/json") {
-            proxyReqData.body = JSON.stringify(req.body);
-        } else {
-            proxyReqData.form = req.body;
-        }
-    }
-
-    // Attempt to catch any synchronously thrown exceptions
-    try {
-        proxyReq = request(proxyReqData, function (error, response, body) {
-            if (error) {
-                console.log("ERROR:".red + " Remote proxying failed with:", error);
-                res.send(500, error);
-            } else if (shouldInjectInto) {
-                if (body) {
-                    // pretty sure this callback can be called multiple times (not just when complete)
-                    body = body.replace(HEAD_TAG,
-                              '<head>' +
-                                '<script>' +
-                                    BOOTSTRAP_FROM_IFRAME +
-                                '</script>');
-
-                    // TODO: Why only need to set new content-length here (and not for localInjection)?
-                    response.headers['content-length'] = body.length;
-
-                    res.status(response.statusCode);
-                    res.set(response.headers);
-                    res.send(body);
-                }
-            }
-        });
-
-        // TODO: Pipe is awesome, but can't modify body (?)
-        if (!shouldInjectInto) {
-            proxyReq.pipe(res);
-        }
-    } catch (e) {
-        res.send(500, e.toString());
-    }
-}
-
-module.exports = {
-    inject: function (opts) {
-        return function (req, res, next) {
-            if (req.originalUrl.match(/\/ripple\/browser\/*/)) {
-                console.log(req.method);
-                if (req.method === "POST") {
-                    console.log(req.body.url);
-                    _url = req.body.url;
-                    res.send(200);
-                } else {
-                    proxyRemote({
-                        url: _url + req.url.replace("/ripple/browser", ""),
-                        userAgent: opts.userAgent
-                    }, req, res);
-                }
-            }
-            else {
-                next();
-            }
-        };
-    }
-};

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/80b1964f/lib/server/emulate.js
----------------------------------------------------------------------
diff --git a/lib/server/emulate.js b/lib/server/emulate.js
index 33a67d3..d59a7fa 100644
--- a/lib/server/emulate.js
+++ b/lib/server/emulate.js
@@ -22,7 +22,6 @@ var proxy = require('./proxy'),
     server = require('./index'),
     colors = require('colors'),
     express = require('express'),
-    browser = require('./browser'),
     hosted = require('./emulate/hosted');
 
 colors.mode = "console";
@@ -57,7 +56,6 @@ module.exports = {
         // TODO: How to make into a dynamic route (using options.route)? (set at build time right now)
         app.use("/ripple/assets", express.static(__dirname + "/../../pkg/hosted"));
         app.use(hosted.inject(options));
-        app.use(browser.inject(options));
 
         if (!options.remote) {
             options.path.forEach(function (path) {