You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by gt...@apache.org on 2013/01/09 18:14:13 UTC

webworks commit: BlackBerry 10 InAppBrowser Support

Updated Branches:
  refs/heads/master 1420a0cf0 -> 0d2daab33


BlackBerry 10 InAppBrowser Support

- updated javascript with support for InAppBrowser on BlackBerry 10 (see
  cordova-js repo for details)
- added cordova custom plugin
- added plugin method to get if a URL is whitelisted or not


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/0d2daab3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/0d2daab3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/0d2daab3

Branch: refs/heads/master
Commit: 0d2daab33f6f2acb2399fcfcc88449015f6c4bd4
Parents: 1420a0c
Author: Gord Tanner <gt...@gmail.com>
Authored: Tue Jan 8 01:15:11 2013 -0500
Committer: Gord Tanner <gt...@gmail.com>
Committed: Wed Jan 9 12:10:32 2013 -0500

----------------------------------------------------------------------
 framework/ext-qnx/org.apache.cordova/client.js     |   16 ++
 framework/ext-qnx/org.apache.cordova/index.js      |   34 +++
 framework/ext-qnx/org.apache.cordova/manifest.json |    5 +
 javascript/cordova.blackberry.js                   |  199 ++++++++++++---
 4 files changed, 213 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/0d2daab3/framework/ext-qnx/org.apache.cordova/client.js
----------------------------------------------------------------------
diff --git a/framework/ext-qnx/org.apache.cordova/client.js b/framework/ext-qnx/org.apache.cordova/client.js
new file mode 100644
index 0000000..f8308b8
--- /dev/null
+++ b/framework/ext-qnx/org.apache.cordova/client.js
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2010-2011 Research In Motion Limited.
+ *
+ * Licensed 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.
+ */
+

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/0d2daab3/framework/ext-qnx/org.apache.cordova/index.js
----------------------------------------------------------------------
diff --git a/framework/ext-qnx/org.apache.cordova/index.js b/framework/ext-qnx/org.apache.cordova/index.js
new file mode 100644
index 0000000..4a60b93
--- /dev/null
+++ b/framework/ext-qnx/org.apache.cordova/index.js
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010-2011 Research In Motion Limited.
+ *
+ * Licensed 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 Whitelist = require("../../lib/policy/whitelist").Whitelist,
+    whitelist = new Whitelist(),
+    noop = function () {};
+
+module.exports = {
+    isWhitelisted: function (success, fail, args) {
+        var url = JSON.parse(decodeURIComponent(args[0])),
+            success = success || noop,
+            fail = fail || noop;
+
+        if (url) {
+            success(whitelist.isAccessAllowed(url));
+        }
+        else {
+            error("please provide an url");
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/0d2daab3/framework/ext-qnx/org.apache.cordova/manifest.json
----------------------------------------------------------------------
diff --git a/framework/ext-qnx/org.apache.cordova/manifest.json b/framework/ext-qnx/org.apache.cordova/manifest.json
new file mode 100644
index 0000000..9efdda2
--- /dev/null
+++ b/framework/ext-qnx/org.apache.cordova/manifest.json
@@ -0,0 +1,5 @@
+{
+    "global": false,
+    "namespace": "org.apache.cordova",
+    "dependencies": []
+}

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/0d2daab3/javascript/cordova.blackberry.js
----------------------------------------------------------------------
diff --git a/javascript/cordova.blackberry.js b/javascript/cordova.blackberry.js
index 3637ee3..a2accd5 100644
--- a/javascript/cordova.blackberry.js
+++ b/javascript/cordova.blackberry.js
@@ -1,6 +1,6 @@
-// commit 24d65ab645742e8360c3dd16d7a36411cc3383e0
+// commit d240deab4eaf707dab2e32d15fbdca00a0c9c4e9
 
-// File generated at :: Thu Jan 03 2013 11:11:25 GMT-0800 (PST)
+// File generated at :: Wed Jan 09 2013 12:05:41 GMT-0500 (EST)
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one
@@ -2198,8 +2198,46 @@ var File = function(name, fullPath, type, lastModifiedDate, size){
     this.type = type || null;
     this.lastModifiedDate = lastModifiedDate || null;
     this.size = size || 0;
+
+    // These store the absolute start and end for slicing the file.
+    this.start = 0;
+    this.end = this.size;
 };
 
+/**
+ * Returns a "slice" of the file. Since Cordova Files don't contain the actual
+ * content, this really returns a File with adjusted start and end.
+ * Slices of slices are supported.
+ * start {Number} The index at which to start the slice (inclusive).
+ * end {Number} The index at which to end the slice (exclusive).
+ */
+File.prototype.slice = function(start, end) {
+    var size = this.end - this.start;
+    var newStart = 0;
+    var newEnd = size;
+    if (arguments.length) {
+        if (start < 0) {
+            newStart = Math.max(size + start, 0);
+        } else {
+            newStart = Math.min(size, start);
+        }
+    }
+
+    if (arguments.length >= 2) {
+        if (end < 0) {
+            newEnd = Math.max(size + end, 0);
+        } else {
+            newEnd = Math.min(end, size);
+        }
+    }
+
+    var newFile = new File(this.name, this.fullPath, this.type, this.lastModifiedData, this.size);
+    newFile.start = this.start + newStart;
+    newFile.end = this.start + newEnd;
+    return newFile;
+};
+
+
 module.exports = File;
 
 });
@@ -2399,6 +2437,15 @@ FileReader.prototype.readAsText = function(file, encoding) {
 
     var me = this;
 
+    var execArgs = [this.fileName, enc];
+
+    // Maybe add slice parameters.
+    if (file.end < file.size) {
+        execArgs.push(file.start, file.end);
+    } else if (file.start > 0) {
+        execArgs.push(file.start);
+    }
+
     // Read file
     exec(
         // Success callback
@@ -2449,7 +2496,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
             if (typeof me.onloadend === "function") {
                 me.onloadend(new ProgressEvent("loadend", {target:me}));
             }
-        }, "File", "readAsText", [this.fileName, enc]);
+        }, "File", "readAsText", execArgs);
 };
 
 
@@ -2483,6 +2530,15 @@ FileReader.prototype.readAsDataURL = function(file) {
 
     var me = this;
 
+    var execArgs = [this.fileName];
+
+    // Maybe add slice parameters.
+    if (file.end < file.size) {
+        execArgs.push(file.start, file.end);
+    } else if (file.start > 0) {
+        execArgs.push(file.start);
+    }
+
     // Read file
     exec(
         // Success callback
@@ -2532,7 +2588,7 @@ FileReader.prototype.readAsDataURL = function(file) {
             if (typeof me.onloadend === "function") {
                 me.onloadend(new ProgressEvent("loadend", {target:me}));
             }
-        }, "File", "readAsDataURL", [this.fileName]);
+        }, "File", "readAsDataURL", execArgs);
 };
 
 /**
@@ -3091,55 +3147,48 @@ module.exports = GlobalizationError;
 define("cordova/plugin/InAppBrowser", function(require, exports, module) {
 
 var exec = require('cordova/exec');
+var channel = require('cordova/channel');
 
-function InAppBrowser()
-{
-   var _channel = require('cordova/channel');
+function InAppBrowser() {
    this.channels = {
-        'loadstart': _channel.create('loadstart'),
-        'loadstop' : _channel.create('loadstop'),
-        'exit' : _channel.create('exit')
+        'loadstart': channel.create('loadstart'),
+        'loadstop' : channel.create('loadstop'),
+        'exit' : channel.create('exit')
    };
 }
 
-InAppBrowser.prototype._eventHandler = function(event)
-{
-    if (event.type in this.channels) {
-        this.channels[event.type].fire(event);
+InAppBrowser.prototype = {
+    _eventHandler: function (event) {
+        if (event.type in this.channels) {
+            this.channels[event.type].fire(event);
+        }
+    },
+    close: function (eventname) {
+        exec(null, null, "InAppBrowser", "close", []);
+    },
+    addEventListener: function (eventname,f) {
+        if (eventname in this.channels) {
+            this.channels[eventname].subscribe(f);
+        }
+    },
+    removeEventListener: function(eventname, f) {
+        if (eventname in this.channels) {
+            this.channels[eventname].unsubscribe(f);
+        }
     }
-}
+};
 
-InAppBrowser.open = function(strUrl, strWindowName, strWindowFeatures)
-{
+module.exports = function(strUrl, strWindowName, strWindowFeatures) {
     var iab = new InAppBrowser();
     var cb = function(eventname) {
        iab._eventHandler(eventname);
-    }
+    };
     exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
     return iab;
-}
-
-InAppBrowser.prototype.close = function(eventname, f)
-{
-    exec(null, null, "InAppBrowser", "close", []);
-}
-
-InAppBrowser.prototype.addEventListener = function(eventname, f)
-{
-    if (eventname in this.channels) {
-        this.channels[eventname].subscribe(f);
-    }
-}
-
-InAppBrowser.prototype.removeEventListener = function(eventname, f)
-{
-    if (eventname in this.channels) {
-        this.channels[eventname].unsubscribe(f);
-    }
-}
-
-module.exports = InAppBrowser.open;
+};
 
+//Export the original open so it can be used if needed
+module.exports._orig = window.open;
 
 });
 
@@ -8668,6 +8717,68 @@ module.exports = {
 
 });
 
+// file: lib/blackberry/plugin/qnx/InAppBrowser.js
+define("cordova/plugin/qnx/InAppBrowser", function(require, exports, module) {
+
+var cordova = require('cordova'),
+    core = require('cordova/plugin/InAppBrowser');
+
+var navigate = {
+    "_blank": function (url, whitelisted) {
+        core._orig.apply(null, [url, "_blank"]);
+    },
+
+    "_self": function (url, whitelisted) {
+        if (whitelisted) {
+            window.location.href = url;
+        }
+        else {
+            core._orig.apply(null, [url, "_blank"]);
+        }
+    },
+
+    "_system": function (url, whitelisted) {
+        blackberry.invoke.invoke({
+            target: "sys.browser",
+            uri: url
+        }, function () {}, function () {});
+    }
+};
+
+
+module.exports = {
+    open: function (args, win, fail) {
+        var url = args[0],
+            target = args[1] || '_self',
+            a = document.createElement('a');
+
+        //Make all URLs absolute
+        a.href = url;
+        url = a.href;
+
+        switch (target) {
+            case '_self':
+            case '_system':
+            case '_blank':
+                break;
+            default:
+                target = '_blank';
+                break;
+        }
+
+        webworks.exec(function (whitelisted) {
+            navigate[target](url, whitelisted);
+        }, fail, "org.apache.cordova", "isWhitelisted", [url], true);
+
+        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "" };
+    },
+    close: function (args, win, fail) {
+        return { "status" : cordova.callbackStatus.OK, "message" : "" };
+    }
+};
+
+});
+
 // file: lib/blackberry/plugin/qnx/battery.js
 define("cordova/plugin/qnx/battery", function(require, exports, module) {
 
@@ -9430,6 +9541,7 @@ var cordova = require('cordova'),
         'Notification' : require('cordova/plugin/webworks/notification'),
         'Media': require('cordova/plugin/webworks/media'),
         'File' : require('cordova/plugin/qnx/file'),
+        'InAppBrowser' : require('cordova/plugin/qnx/InAppBrowser'),
         'FileTransfer': require('cordova/plugin/qnx/fileTransfer')
     };
 
@@ -9496,6 +9608,11 @@ module.exports = {
             });
         });
     },
+    clobbers: {
+        open: {
+            path: "cordova/plugin/InAppBrowser"
+        }
+    },
     merges: {
         navigator: {
             children: {
@@ -10106,7 +10223,7 @@ window.cordova = require('cordova');
     // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
     // We replace it so that properties that can't be clobbered can instead be overridden.
     if (context.navigator) {
-        function CordovaNavigator() {}
+        var CordovaNavigator = function() {};
         CordovaNavigator.prototype = context.navigator;
         context.navigator = new CordovaNavigator();
     }