You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:24:23 UTC

[18/51] [partial] [BlackBerry10] Added support for new platform

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/plugins/NetworkStatus/index.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/plugins/NetworkStatus/index.js b/lib/cordova-blackberry/blackberry10/bin/test/plugins/NetworkStatus/index.js
new file mode 100644
index 0000000..7d0371c
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/plugins/NetworkStatus/index.js
@@ -0,0 +1,118 @@
+/*
+* Copyright 2013 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.
+*/
+
+
+describe("NetworkStatus", function () {
+    var _apiDir = __dirname + "./../../../templates/project/plugins/NetworkStatus/",
+        index,
+        result = {
+            ok: jasmine.createSpy(),
+            error: jasmine.createSpy()
+        };
+
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+    });
+
+    afterEach(function () {
+        index = null;
+    });
+
+    describe("getConnectionInfo", function () {
+        beforeEach(function () {
+            GLOBAL.window = {
+                qnx: {
+                    webplatform: {
+                        device: {
+                        }
+                    }
+                }
+            };
+            GLOBAL.PluginResult = function () {
+                return result;
+            };
+        });
+
+        afterEach(function () {
+            delete GLOBAL.window;
+            delete GLOBAL.PluginResult;
+        });
+
+        function testConnection(expectedResult, mockedType, mockedTechnology) {
+            var mockedDevice = {
+                activeConnection: {
+                    type: mockedType,
+                    technology: mockedTechnology
+                }
+            };
+
+            if (mockedType) {
+                window.qnx.webplatform.device = mockedDevice;
+            }
+
+            index.getConnectionInfo();
+
+            expect(result.ok).toHaveBeenCalledWith(expectedResult);
+            expect(result.error).not.toHaveBeenCalled();
+        }
+
+        it("calls success with a wired connection", function () {
+            testConnection("ethernet", "wired");
+        });
+
+        it("calls success with a wifi connection", function () {
+            testConnection("wifi", "wifi");
+        });
+
+        it("calls success with no connection", function () {
+            testConnection("none", "none");
+        });
+
+        it("calls success with a cellular edge connection", function () {
+            testConnection("2g", "cellular", "edge");
+        });
+
+        it("calls success with a cellular gsm connection", function () {
+            testConnection("2g", "cellular", "gsm");
+        });
+
+        it("calls success with a cellular evdo connection", function () {
+            testConnection("3g", "cellular", "evdo");
+        });
+
+        it("calls success with a cellular umts connection", function () {
+            testConnection("3g", "cellular", "umts");
+        });
+
+        it("calls success with a lte connection", function () {
+            testConnection("4g", "cellular", "lte");
+        });
+
+        it("calls success with a cellular connection", function () {
+            testConnection("cellular", "cellular");
+        });
+
+        it("defaults to none if no connection is found", function () {
+            testConnection("none");
+        });
+
+        it("defaults to unknown if connection type doesn't exist", function () {
+            testConnection("unknown", "fakeConnectionType");
+        });
+
+    });
+
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/plugins/Notification/index.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/plugins/Notification/index.js b/lib/cordova-blackberry/blackberry10/bin/test/plugins/Notification/index.js
new file mode 100644
index 0000000..2b585f8
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/plugins/Notification/index.js
@@ -0,0 +1,119 @@
+/*
+* Copyright 2013 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.
+*/
+
+function mockAndTestDialog(htmlmessage, title, dialogType, buttonLabel) {
+    GLOBAL.qnx = {
+        webplatform: {
+            getWebViews: function () {
+                var webviews = [{}, {},
+                    {//overlayWebview
+                        dialog: {
+                            show: function(messageObj, callback) {
+                                expect(messageObj.title).toEqual(title);
+                                expect(messageObj.htmlmessage).toEqual(htmlmessage);
+                                expect(messageObj.dialogType).toEqual(dialogType);
+                                expect(messageObj.optionalButtons).toEqual(buttonLabel);
+                                expect(typeof callback).toEqual("function");
+                            }
+                        }
+                    }];
+                return webviews;
+            }
+        }
+    };
+
+}
+
+describe("Notification", function () {
+    var _apiDir = __dirname + "./../../../templates/project/plugins/Notification/",
+    index,
+    success = function() {},
+    fail = function() {},
+    result = {
+        error: jasmine.createSpy(),
+        noResult: jasmine.createSpy()
+    },
+    args = {
+        0: "%22Dialog%20message.%22",
+        1: "%22Dialog%20Title%22",
+        2: "%22Continue%22"
+    };
+
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+
+        GLOBAL.PluginResult = function () {
+            return result;
+        };
+    });
+
+    afterEach(function () {
+        delete require.cache[require.resolve(_apiDir + "index")];
+        delete GLOBAL.qnx;
+        delete GLOBAL.PluginResult;
+    });
+
+    describe("alert", function () {
+        it("fails with invalid number of args", function () {
+            index.alert(success, fail, {}, {});
+            expect(result.error).toHaveBeenCalledWith("Notification action - alert arguments not found.");
+        });
+
+        it("calls dialog.show with correct params", function () {
+            mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue"]);
+            index.alert(success, fail, args, {});
+            expect(result.noResult).toHaveBeenCalled();
+        });
+    });
+
+    describe("confirm", function () {
+        it("fails with invalid number of args", function () {
+            index.confirm(success, fail, {}, {});
+            expect(result.error).toHaveBeenCalledWith("Notification action - confirm arguments not found.");
+        });
+
+        it("calls dialog.show with correct params", function () {
+            mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue"]);
+            index.confirm(success, fail, args, {});
+            expect(result.noResult).toHaveBeenCalled();
+        });
+
+        it("calls dialog.show with correct params [deprecated buttonArg]", function () {
+            var args = {
+                0: "%22Dialog%20message.%22",
+                1: "%22Dialog%20Title%22",
+                2: "%22Continue,Cancel%22"
+            };
+
+            mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue", "Cancel"]);
+            index.confirm(success, fail, args, {});
+            expect(result.noResult).toHaveBeenCalled();
+        });
+    });
+
+    describe("prompt", function () {
+        it("fails with invalid number of args", function () {
+            index.prompt(success, fail, {}, {});
+            expect(result.error).toHaveBeenCalledWith("Notification action - prompt arguments not found.");
+        });
+
+        it("calls dialog.show with correct params", function () {
+            mockAndTestDialog("Dialog message.", "Dialog Title", "JavaScriptPrompt", ["Continue"]);
+            index.prompt(success, fail, args, {});
+            expect(result.noResult).toHaveBeenCalled();
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/plugins/SplashScreen/index.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/plugins/SplashScreen/index.js b/lib/cordova-blackberry/blackberry10/bin/test/plugins/SplashScreen/index.js
new file mode 100644
index 0000000..1dcccee
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/plugins/SplashScreen/index.js
@@ -0,0 +1,82 @@
+/*
+* Copyright 2013 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.
+*/
+describe("SplashScreen", function () {
+    var _apiDir = __dirname + "./../../../templates/project/plugins/SplashScreen/",
+        index,
+        mockedEnv = {
+            response: {
+                send: jasmine.createSpy()
+            }
+        },
+        mockedApplication = {
+            windowVisible: undefined
+        };
+
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+        mockedEnv.response.send.reset();
+    });
+
+    afterEach(function () {
+        index = null;
+        delete require.cache[require.resolve(_apiDir + "index")];
+    });
+    describe("show", function () {
+        beforeEach(function () {
+            GLOBAL.PluginResult = function (args, env) {};
+            GLOBAL.PluginResult.prototype.error = jasmine.createSpy();
+        });
+
+        afterEach(function () {
+            delete GLOBAL.PluginResult;
+        });
+
+        it("calls PluginResult.error if show is called", function () {
+            index.show();
+
+            expect(PluginResult.prototype.error).toHaveBeenCalledWith("Not supported on platform", false);
+        });
+    });
+
+    describe("hide", function () {
+        beforeEach(function () {
+            GLOBAL.window = {
+                qnx: {
+                    webplatform: {
+                        getApplication: function () {
+                            return mockedApplication;
+                        }
+                    }
+                }
+            };
+
+            GLOBAL.PluginResult = function (args, env) {};
+            GLOBAL.PluginResult.prototype.ok = jasmine.createSpy();
+        });
+
+        afterEach(function () {
+            delete GLOBAL.window;
+            delete GLOBAL.PluginResult;
+        });
+
+        it("calls PluginResult.ok if hide is called", function () {
+            index.hide();
+
+            expect(mockedApplication.windowVisible).toBeTruthy();
+            expect(PluginResult.prototype.ok).toHaveBeenCalledWith(undefined, false);
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/bootstrap/index.html
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/bootstrap/index.html b/lib/cordova-blackberry/blackberry10/framework/bootstrap/index.html
new file mode 100644
index 0000000..6e3b028
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/bootstrap/index.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="user-scalable=no, target-densitydpi=device-dpi, width=device-width">
+    <title>WebWorks For BB10 Bootstrap</title>
+    <script src="./require.js"></script>
+    <script src="platform:///webplatform.js"></script>
+    <script src="./frameworkModules.js"></script>
+    <script>
+        function start() {
+            //Must load jnext first, as there seemed to be a race condition for if it was defined before it was used
+            require("lib/jnext.js");
+            require(frameworkModules, function () {
+                require('lib/framework').start();
+            });
+        }
+    </script>
+  </head>
+  <body onload="start();">
+      I am the man behind the curtain.
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/bootstrap/require.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/bootstrap/require.js b/lib/cordova-blackberry/blackberry10/framework/bootstrap/require.js
new file mode 100644
index 0000000..a68bfcc
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/bootstrap/require.js
@@ -0,0 +1,251 @@
+/*
+ *  Copyright 2012 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 define,
+    require;
+
+(function () {
+    var unpreparedModules = {},
+        readyModules = {},
+        ACCEPTABLE_EXTENSIONS = [".js", ".json"],
+        DEFAULT_EXTENSION = ".js";
+
+    function hasValidExtension(moduleName) {
+        return ACCEPTABLE_EXTENSIONS.some(function (element, index, array) {
+            return moduleName.match("\\" + element + "$");
+        });
+    }
+
+
+    function normalizeName(originalName, baseName) {
+        var nameParts,
+            name = originalName.slice(0);
+        //remove ^local:// (if it exists) and .js$
+        //This will not work for local:// without a trailing js
+        name = name.replace(/(?:^local:\/\/)/, "");
+        if (name.charAt(0) === '.' && baseName) {
+            //Split the baseName and remove the final part (the module name)
+            nameParts = baseName.split('/');
+            nameParts.pop();
+            nameParts = nameParts.concat(name.split('/'));
+
+            name = nameParts.reduce(function (previous, current,  index, array) {
+                var returnValue,
+                    slashIndex;
+
+                //If previous is a dot, ignore it
+                //If previous is ever just .. we're screwed anyway
+                if (previous !== '.') {
+                    returnValue = previous;
+                }
+
+                //If we have a .. then remove a chunk of previous
+                if (current === "..") {
+                    slashIndex = previous.lastIndexOf('/');
+                    //If there's no slash we're either screwed or we remove the final token
+                    if (slashIndex !== -1) {
+                        returnValue = previous.slice(0, previous.lastIndexOf('/'));
+                    } else {
+                        returnValue = "";
+                    }
+                } else if (current !== '.') {
+                    //Otherwise simply append anything not a .
+                    //Only append a slash if we're not empty
+                    if (returnValue.length) {
+                        returnValue += "/";
+                    }
+                    returnValue += current;
+                }
+
+                return returnValue;
+            });
+
+        }
+
+        //If there is no acceptable extension tack on a .js
+        if (!hasValidExtension(name)) {
+            name = name + DEFAULT_EXTENSION;
+        }
+
+        return name;
+    }
+
+    function buildModule(name, dependencies, factory) {
+        var module = {exports: {}},
+            localRequire = function (moduleName) {
+                return require(moduleName, name);
+            },
+            args = [];
+        localRequire.toUrl = function (moduleName, baseName) {
+            return require.toUrl(moduleName, baseName || name);
+        };
+        dependencies.forEach(function (dependency) {
+            if (dependency === 'require') {
+                args.push(localRequire);
+            } else if (dependency === 'exports') {
+                args.push(module.exports);
+            } else if (dependency === 'module') {
+                args.push(module);
+            } else {
+                //This is because jshint cannot handle out of order functions
+                /*global loadModule:false */
+                args.push(loadModule(dependency));
+                /*global loadModule:true */
+            }
+        });
+
+        //No need to process dependencies, webworks only has require, exports, module
+        factory.apply(this, args);
+
+        //For full AMD we would need logic to also check the return value
+        return module.exports;
+
+    }
+
+    function getDefineString(moduleName, body) {
+        var evalString = 'define("' + moduleName + '", function (require, exports, module) {',
+            isJson = /\.json$/.test(moduleName);
+
+        evalString += isJson ? ' module.exports = ' : '';
+        evalString += body.replace(/^\s+|\s+$/g, '');
+        evalString += isJson ? ' ;' : '';
+        evalString += '});';
+
+        return evalString;
+    }
+
+    function loadModule(name, baseName) {
+        var normalizedName = normalizeName(name, baseName),
+            url,
+            xhr,
+            loadResult;
+        //Always check undefined first, this allows the user to redefine modules
+        //(Not used in WebWorks, although it is used in our unit tests)
+        if (unpreparedModules[normalizedName]) {
+            readyModules[normalizedName] = buildModule(normalizedName, unpreparedModules[normalizedName].dependencies, unpreparedModules[normalizedName].factory);
+            delete unpreparedModules[normalizedName];
+        }
+
+        //If the module does not exist, load the module from external source
+        //Webworks currently only loads APIs from across bridge
+        if (!readyModules[normalizedName]) {
+            //If the module to be loaded ends in .js then we will define it
+            //Also if baseName exists than we have a local require situation
+            if (hasValidExtension(name) || baseName) {
+                xhr = new XMLHttpRequest();
+                url = name;
+                //If the module to be loaded starts with local:// go over the bridge
+                //Else If the module to be loaded is a relative load it may not have .js extension which is needed
+                if (/^local:\/\//.test(name)) {
+                    url = "http://localhost:8472/extensions/load/" + normalizedName.replace(/(?:^ext\/)(.+)(?:\/client.js$)/, "$1");
+
+                    xhr.open("GET", url, false);
+                    xhr.send(null);
+                    try {
+                        loadResult = JSON.parse(xhr.responseText);
+
+                        loadResult.dependencies.forEach(function (dep) {
+                            /*jshint evil:true */
+                            eval(getDefineString(dep.moduleName, dep.body));
+                            /*jshint evil:false */
+                        });
+
+                        //Trimming responseText to remove EOF chars
+                        /*jshint evil:true */
+                        eval(getDefineString(normalizedName, loadResult.client));
+                        /*jshint evil:false */
+                    } catch (err1) {
+                        err1.message += ' in ' + url;
+                        throw err1;
+                    }
+                } else {
+                    if (baseName) {
+                        url = normalizedName;
+                    }
+
+                    xhr.open("GET", url, false);
+                    xhr.send(null);
+                    try {
+                        //Trimming responseText to remove EOF chars
+                        /*jshint evil:true */
+                        eval(getDefineString(normalizedName, xhr.responseText));
+                        /*jshint evil:false */
+                    } catch (err) {
+                        err.message += ' in ' + url;
+                        throw err;
+                    }
+                }
+
+                if (unpreparedModules[normalizedName]) {
+                    readyModules[normalizedName] = buildModule(normalizedName, unpreparedModules[normalizedName].dependencies, unpreparedModules[normalizedName].factory);
+                    delete unpreparedModules[normalizedName];
+                }
+            } else {
+                throw "module " + name + " cannot be found";
+            }
+
+        }
+
+        return readyModules[normalizedName];
+
+    }
+
+    //Use the AMD signature incase we ever want to change.
+    //For now we will only be using (name, baseName)
+    require = function (dependencies, callback) {
+        if (typeof dependencies === "string") {
+            //dependencies is the module name and callback is the relName
+            //relName is not part of the AMDJS spec, but we use it from localRequire
+            return loadModule(dependencies, callback);
+        } else if (Array.isArray(dependencies) && typeof callback === 'function') {
+            //Call it Asynchronously
+            setTimeout(function () {
+                buildModule(undefined, dependencies, callback);
+            }, 0);
+        }
+    };
+
+    require.toUrl = function (originalName, baseName) {
+        return normalizeName(originalName, baseName);
+    };
+
+    //Use the AMD signature incase we ever want to change.
+    //For now webworks will only be using (name, factory) signature.
+    define = function (name, dependencies, factory) {
+        if (typeof name === "string" && typeof dependencies === 'function') {
+            factory = dependencies;
+            dependencies = ['require', 'exports', 'module'];
+        }
+
+        //According to the AMDJS spec we should parse out the require statments
+        //from factory.toString and add those to the list of dependencies
+
+        //Normalize the name. Remove local:// and .js
+        name = normalizeName(name);
+        unpreparedModules[name] = {
+            dependencies: dependencies,
+            factory: factory
+        };
+    };
+}());
+
+//Export for use in node for unit tests
+if (typeof module === "object" && typeof require === "function") {
+    module.exports = {
+        require: require,
+        define: define
+    };
+}

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/bootstrap/ui.html
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/bootstrap/ui.html b/lib/cordova-blackberry/blackberry10/framework/bootstrap/ui.html
new file mode 100644
index 0000000..98c94a0
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/bootstrap/ui.html
@@ -0,0 +1,73 @@
+<!-- Copyright 2012 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.
+
+ -->
+<!DOCTYPE HTML>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
+        <title>Overlay WebView</title>
+        <link rel="stylesheet" href="platform:///ui-resources/styles/styles.css" type="text/css" media="screen" charset="utf-8">
+
+        <script src="../chrome/require.js" type="text/javascript"></script>
+        <script src="platform:///webplatform.js" type="text/javascript"></script>
+        <script src="platform:///i18n.js" type="text/javascript"></script>
+        <script src="platform:///ui-resources/index.js" type="text/javascript"></script>
+    </head>
+    <body>
+
+        <div id="contextMenuModal" style="display:none;"></div>
+<div id="contextMenu" class="hideMenu">
+    <div id="contextMenuHeader">
+        <div id="contextMenuHeadText"></div>
+        <div id="contextMenuSubheadText"></div>
+    </div>
+    <div id="contextMenuContent"></div>
+    <div id="contextMenuHandle"></div>
+    <div id="contextMenuDelete"></div>
+</div>
+
+        <div id="dialog" class="hidden">
+    <div class="dialog-top-third">
+        <div id="dialog-panel">
+        </div>
+    </div>
+    <div class="dialog-bottom-two-thirds">
+    </div>
+</div>
+
+        <div id="invocationlist" class="screenInner screenSlide removed">
+    <div id="cancelTitlebar"></div>
+    <div id="invocationListContent" class="targetList"></div>
+    <div id="targetLoader">
+        <div id="targetLoaderActivity" class="activityIndicator"></div>
+    </div>
+</div>
+
+        <div id="toaster" class="toaster"></div>
+
+
+        <div id="childwebviewcontrols"></div>
+
+        <div id="formcontrolPanel">
+            <div id="formcontrol">
+                <button id="formcontrol_previous"/>
+                <button id="formcontrol_next"/>
+                <button id="formcontrol_submit"/>
+            </div>
+        </div>
+
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/bootstrap/wwe
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/bootstrap/wwe b/lib/cordova-blackberry/blackberry10/framework/bootstrap/wwe
new file mode 100644
index 0000000..0e48b92
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/bootstrap/wwe
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec weblauncher "$@"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/PluginResult.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/PluginResult.js b/lib/cordova-blackberry/blackberry10/framework/lib/PluginResult.js
new file mode 100644
index 0000000..68acf23
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/PluginResult.js
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013 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.
+ */
+
+function PluginResult (args, env) {
+
+    var CALLBACK_STATUS_NO_RESULT = 0,
+        CALLBACK_STATUS_OK = 1,
+        CALLBACK_STATUS_ERROR = 9,
+        callbackId = JSON.parse(decodeURIComponent(args.callbackId)),
+        send = function (data) {
+            env.response.send(200, encodeURIComponent(JSON.stringify(data)));
+        },
+        callback = function (success, status, data, keepCallback) {
+            var executeString = "cordova.callbackFromNative('" + callbackId  + "', " +
+                !!success + ", " + status + ", [" + data + "], " + !!keepCallback + ");";
+            env.webview.executeJavaScript(executeString);
+        };
+
+    Object.defineProperty(this, "callbackId", {enumerable: true, value: callbackId});
+
+    this.noResult = function (keepCallback) {
+        send({ code: CALLBACK_STATUS_NO_RESULT, keepCallback: !!keepCallback });
+    };
+
+    this.error = function (msg, keepCallback) {
+        send({ code: CALLBACK_STATUS_ERROR, msg: msg, keepCallback: !!keepCallback });
+    };
+
+    this.ok = function (data, keepCallback) {
+        send({ code: CALLBACK_STATUS_OK, data: data, keepCallback: !!keepCallback });
+    };
+
+    this.callbackOk = function (data, keepCallback) {
+        callback(true, CALLBACK_STATUS_OK, JSON.stringify(data), keepCallback);
+    };
+
+    this.callbackError = function (msg, keepCallback) {
+        callback(false, CALLBACK_STATUS_ERROR, JSON.stringify(msg), keepCallback);
+    };
+}
+
+window.PluginResult = PluginResult;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/config.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/config.js b/lib/cordova-blackberry/blackberry10/framework/lib/config.js
new file mode 100644
index 0000000..6fbe527
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/config.js
@@ -0,0 +1,22 @@
+/*
+ *  Copyright 2012 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 defaults = require('./config/default'),
+    user = require('./config/user'),
+    utils = require('./utils');
+
+module.exports = utils.mixin(user,
+                 utils.mixin(defaults, {}));

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/config/default.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/config/default.js b/lib/cordova-blackberry/blackberry10/framework/lib/config/default.js
new file mode 100644
index 0000000..31990b1
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/config/default.js
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+module.exports = {
+    configXML: "config.xml",
+    configXMLDoc: null,
+
+    backButtonBehavior: "back",
+    customHeaders: {},
+    version: "1.0.0",
+
+    author: "",
+    authorURL: "",
+    authorEmail: "",
+    copyright: "",
+    content: "index.html",
+    contentCharset: "",
+    contentType: "",
+    description: "",
+    icon: "AIRApp_72.png",
+    iconHover: "",
+    id: "",
+    license: "",
+    licenseURL: "",
+    name: "WebWorksAppTemplate",
+
+    navigationMode: "pointer",
+
+    preferredTransports: null,
+    transportTimeout: 300000,
+
+    hasMultiAccess: false,
+    widgetExtensions: null,
+    featureTable: null,
+    accessList: null,
+    permissions: null,
+
+    loadingScreenColor: "#FFFFFF",
+    backgroundImage: "",
+    foregroundImage: "",
+    onFirstLaunch: false,
+    onLocalPageLoad: false,
+    onRemotePageLoad: false,
+    transitionType: -1,
+    transitionDuration: 250,
+    transitionDirection: 128,
+
+    disableAllCache: false,
+    aggressiveCacheAge: 2592000,
+    maxCacheSizeTotal: 1024,
+    maxCacheSizeItem: 128,
+    maxStandardCacheAge: 2592000,
+
+    runOnStartUp: false,
+    allowInvokeParams: false,
+    backgroundSource: "",
+    foregroundSource: "index.html",
+    debugEnabled: false,
+    enableFormControl: true,
+    enableChildWebView: true,
+    enableWebSecurity: true,
+    enablePopupBlocker: false
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/config/user.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/config/user.js b/lib/cordova-blackberry/blackberry10/framework/lib/config/user.js
new file mode 100644
index 0000000..5e36885
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/config/user.js
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+module.exports = {
+    authorEmail: "guocat@gmail.com",
+    copyright: "@Rebecca",
+    customHeaders: {
+        "rim-header": "RIM-Widget:rim/widget"
+    },
+    userAgent: "Some extremely long user agent (with) spe/cial, characters",
+    author: "Me",
+    version: "1.0.0.0",
+    hasMultiAccess: true,
+    license: "This is a license",
+    accessList: [{
+        allowSubDomain: false,
+        features: [{
+            version: "1.0.0.0",
+            required: true,
+            id: "blackberry.example.test"
+        }, {
+            version: "1.0.0.0",
+            required: true,
+            id: "blackberry.app"
+        }],
+        uri: "WIDGET_LOCAL"
+    }],
+    licenseURL: "",
+    authorURL: "http://bbtools_win7_01/yui",
+    foregroundSource: "derp.html",
+    backgroundColor: 0xFFFF9900,
+    content: "http://localhost/lib/public/testbed.html",
+    description: "this is the description",
+    configXML: "config.xml",
+    name: "wwTest"
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/controllerWebView.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/controllerWebView.js b/lib/cordova-blackberry/blackberry10/framework/lib/controllerWebView.js
new file mode 100644
index 0000000..9c05ebe
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/controllerWebView.js
@@ -0,0 +1,72 @@
+/*
+ *  Copyright 2012 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 controllerWebView,
+    overlayWebView = require("./overlayWebView"),
+    controller,
+    invocation,
+    utils;
+
+controllerWebView = {
+    init: function (config) {
+        controller = window.qnx.webplatform.getController();
+        invocation = window.qnx.webplatform.getApplication().invocation;
+        utils = require('./utils');
+        controller.enableWebInspector = config.debugEnabled;
+        controller.enableCrossSiteXHR = true;
+        controller.visible = false;
+        controller.active = false;
+        controller.setGeometry(0, 0, screen.width, screen.height);
+        controller.setFileSystemSandbox = false;
+
+        /* Remote functions that are published to allow communication with
+         * the overlay webview, they are called via the RPC bridge
+         */
+        controller.publishRemoteFunction('webview.setSensitivity', function (args) {
+            var sensitivityType = args[0];
+            overlayWebView.setSensitivity(sensitivityType);
+        });
+
+        controller.publishRemoteFunction('webview.notifyContextMenuCancelled', function () {
+            overlayWebView.notifyContextMenuCancelled();
+        });
+    },
+
+    setGeometry: function (x, y, width, height) {
+        controller.setGeometry(x, y, width, height);
+    },
+
+    setApplicationOrientation: function (angle) {
+        controller.setApplicationOrientation(angle);
+    },
+
+    notifyApplicationOrientationDone: function () {
+        controller.notifyApplicationOrientationDone();
+    },
+
+    dispatchEvent: function (eventType, args) {
+        controller.dispatchEvent(eventType, args);
+    }
+};
+
+controllerWebView.__defineGetter__('id', function () {
+    return controller.id;
+});
+
+controllerWebView.__defineSetter__('onChildWebViewCreated', function (input) {
+    controller.onChildWebViewCreated = input;
+});
+module.exports = controllerWebView;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/event.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/event.js b/lib/cordova-blackberry/blackberry10/framework/lib/event.js
new file mode 100644
index 0000000..880e6c4
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/event.js
@@ -0,0 +1,84 @@
+/*
+ *  Copyright 2012 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 _handlers = {},
+    _webview = require("./webview");
+
+module.exports = {
+    trigger: function (actionEvent) {
+        var args = Array.prototype.slice.call(arguments),
+            executeString = "webworks.event.trigger('" + actionEvent + "', '" + escape(encodeURIComponent(JSON.stringify(args.slice(1)))) + "')";
+
+        if (_handlers.hasOwnProperty(actionEvent)) {
+            _handlers[actionEvent].forEach(function (webview) {
+                webview.executeJavaScript(executeString);
+            });
+        } else {
+            //Just dump it in the content webview for consistency
+            _webview.executeJavascript(executeString);
+        }
+    },
+
+    add: function (action, webview) {
+        var triggerEvent;
+
+        if (action) {
+            //Use action.event for old extensions that may not have triggerEvent defined
+            triggerEvent = action.triggerEvent || action.event;
+
+            if (!action.once) {
+                action.context.addEventListener(action.event, action.trigger || this.trigger);
+            }
+
+            //If there are no registered listeners for this event, create an array to hold them
+            if (!_handlers.hasOwnProperty(triggerEvent)) {
+                _handlers[triggerEvent] = [];
+            }
+            //If the webview is not in the list of webviews listening to this action then add it
+            if (!_handlers[triggerEvent].some(function (handlerWebView) {
+                    return handlerWebView.id === webview.id;
+                })) {
+                _handlers[triggerEvent].push(webview);
+            }
+
+        } else {
+            throw "Action is null or undefined";
+        }
+    },
+
+    remove: function (action, webview) {
+        if (action) {
+            action.context.removeEventListener(action.event, action.trigger || this.trigger);
+
+            //Remove the webview from the _handlers
+            if (_handlers.hasOwnProperty(action.event)) {
+
+                _handlers[action.event] = _handlers[action.event].filter(function (sourceWebview) {
+                    return sourceWebview.id !== webview.id;
+                });
+
+                //If the array is empty delete it
+                if (_handlers[action.event].length === 0) {
+                    delete _handlers[action.event];
+                }
+            }
+
+        } else {
+            throw "Action is null or undefined";
+        }
+
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/events/applicationEvents.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/events/applicationEvents.js b/lib/cordova-blackberry/blackberry10/framework/lib/events/applicationEvents.js
new file mode 100644
index 0000000..14a8f9e
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/events/applicationEvents.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.
+ */
+
+module.exports = {
+    addEventListener: function (event, trigger) {
+        if (event) {
+            event = "application." + event;
+            window.qnx.webplatform.getApplication().addEventListener(event, trigger);
+        } else {
+            console.warn("Attempting to register for 'falsey' event: " + event);
+        }
+    },
+    removeEventListener: function (event, trigger) {
+        if (event) {
+            event = "application." + event;
+            window.qnx.webplatform.getApplication().removeEventListener(event, trigger);
+        } else {
+            console.warn("Attempting to un-register for 'falsey' event: " + event);
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/events/deviceEvents.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/events/deviceEvents.js b/lib/cordova-blackberry/blackberry10/framework/lib/events/deviceEvents.js
new file mode 100644
index 0000000..939357b
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/events/deviceEvents.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.
+ */
+
+module.exports = {
+    addEventListener: function (event, trigger) {
+        if (event) {
+            event = "device." + event;
+            window.qnx.webplatform.device.addEventListener(event, trigger);
+        } else {
+            console.warn("Attempting to register for 'falsey' event: " + event);
+        }
+    },
+    removeEventListener: function (event, trigger) {
+        if (event) {
+            event = "device." + event;
+            window.qnx.webplatform.device.removeEventListener(event, trigger);
+        } else {
+            console.warn("Attempting to un-register for 'falsey' event: " + event);
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/exception.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/exception.js b/lib/cordova-blackberry/blackberry10/framework/lib/exception.js
new file mode 100644
index 0000000..f0a8467
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/exception.js
@@ -0,0 +1,69 @@
+/*
+ *  Copyright 2012 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.
+ */
+
+module.exports = {
+
+    types: {
+        Application: "Application",
+        ArgumentLength: "ArgumentLength",
+        ArgumentType: "ArgumentType",
+        Argument: "Argument",
+        NotificationType: "NotificationType",
+        NotificationStateType: "NotificationStateType",
+        DomObjectNotFound: "DomObjectNotFound",
+        MethodNotImplemented: "MethodNotImplemented",
+        InvalidState: "InvalidState",
+        ApplicationState: "ApplicationState"
+    },
+
+    handle: function handle(exception, reThrow) {
+        reThrow = reThrow || false;
+
+        var eMsg = exception.message || "exception caught!",
+        msg = eMsg + "\n\n" + (exception.stack || "*no stack provided*") + "\n\n";
+
+        console.error(msg);
+
+        if (reThrow) {
+            throw exception;
+        }
+    },
+
+    raise: function raise(exceptionType, message, customExceptionObject) {
+        var obj = customExceptionObject || {
+                type: "",
+                message: "",
+
+                toString: function () {
+                    var result = this.name + ': "' + this.message + '"';
+
+                    if (this.stack) {
+                        result += "\n" + this.stack;
+                    }
+                    return result;
+                }
+            };
+
+        message = message || "";
+
+        obj.name = exceptionType;
+        obj.type = exceptionType;
+        // TODO: include the exception objects original message if exists
+        obj.message = message;
+
+        throw obj;
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/framework.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/framework.js b/lib/cordova-blackberry/blackberry10/framework/lib/framework.js
new file mode 100644
index 0000000..7d02c61
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/framework.js
@@ -0,0 +1,138 @@
+/*
+ *  Copyright 2012 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 utils = require('./utils'),
+    controllerWebView = require('./controllerWebView'),
+    webview = require('./webview'),
+    overlayWebView = require('./overlayWebView'),
+    config = require("./config");
+
+function showWebInspectorInfo() {
+    var port = window.qnx.webplatform.getApplication().webInspectorPort,
+        messageObj = {};
+
+    qnx.webplatform.device.getNetworkInterfaces(function (networkInfo) {
+        var connectedInterface;
+
+        utils.forEach(networkInfo, function (info) {
+            if (info && !connectedInterface) {
+                connectedInterface = info;
+            }
+        }, this);
+
+        messageObj.title = "Web Inspector Enabled";
+        if (connectedInterface) {
+            messageObj.htmlmessage =  "\n ip4:    " + connectedInterface.ipv4Address + ":" + port + "<br/> ip6:    " + connectedInterface.ipv6Address + ":" + port;
+        } else {
+            messageObj.message = "";
+        }
+        messageObj.dialogType = 'JavaScriptAlert';
+        overlayWebView.showDialog(messageObj);
+    });
+}
+
+var _self = {
+    start: function (url) {
+        var callback,
+            showUrlCallback;
+
+        // Set up the controller WebView
+        controllerWebView.init(config);
+
+        webview.create(function () {
+            if (config.enableFlash) {
+                //Set webview plugin directory [required for flash]
+                webview.setExtraPluginDirectory('/usr/lib/browser/plugins');
+
+                //Enable plugins for the webview [required for flash]
+                webview.setEnablePlugins(true);
+
+                //Enable flash for the childWebViews
+                controllerWebView.onChildWebViewCreated = function (child) {
+                    //Set webview plugin directory [required for flash]
+                    child.setExtraPluginDirectory('/usr/lib/browser/plugins');
+
+                    //Enable plugins for the webview [required for flash]
+                    child.pluginsEnabled = true;
+                };
+            }
+
+            if (!config.enableWebSecurity) {
+                webview.enableCrossSiteXHR = true;
+            }
+
+            if (!config.enablePopupBlocker) {
+                qnx.webplatform.nativeCall('webview.setBlockPopups', webview.id, false);
+            }
+            // Workaround for executeJavascript doing nothing for the first time
+
+            webview.executeJavascript("1 + 1");
+
+            url = url || config.content;
+
+            showUrlCallback = function () {
+                overlayWebView.removeEventListener("DocumentLoadFinished", showUrlCallback);
+                showUrlCallback = null;
+
+                // Start page
+                if (url) {
+                    webview.setURL(url);
+                }
+            };
+
+            overlayWebView.create(function () {
+                overlayWebView.addEventListener("DocumentLoadFinished", showUrlCallback);
+
+                overlayWebView.setURL("local:///chrome/ui.html");
+                overlayWebView.renderContextMenuFor(webview);
+                overlayWebView.handleDialogFor(webview);
+                controllerWebView.dispatchEvent('ui.init', null);
+                webview.setUIWebViewObj(overlayWebView.getWebViewObj());
+                if (config.enableChildWebView) {
+                    overlayWebView.bindAppWebViewToChildWebViewControls(webview);
+                } else {
+                    webview.onChildWindowOpen = function (data) {
+                        var parsedData = JSON.parse(data);
+                        utils.invokeInBrowser(parsedData.url);
+                    };
+                }
+                if (config.enableFormControl) {
+                    overlayWebView.getWebViewObj().formcontrol.subscribeTo(webview);
+                }
+            });
+        },
+        {
+            debugEnabled : config.debugEnabled
+        });
+
+        //if debugging is enabled, show the IP and port for webinspector
+        if (config.debugEnabled) {
+            callback = function () {
+                showWebInspectorInfo();
+
+                //Remove listener. Alert should only be shown once.
+                webview.removeEventListener("DocumentLoadFinished", callback);
+            };
+
+            webview.addEventListener("DocumentLoadFinished", callback);
+        }
+    },
+    stop: function () {
+        webview.destroy();
+    }
+};
+
+module.exports = _self;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/jnext.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/jnext.js b/lib/cordova-blackberry/blackberry10/framework/lib/jnext.js
new file mode 100755
index 0000000..d0e4d79
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/jnext.js
@@ -0,0 +1,185 @@
+/*
+ *  Copyright 2012 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.
+ */
+/*global objJSExt */
+
+function JNEXT_() {
+    var self = this;
+    var m_bFirstRequire = true;
+
+    self.m_arEvents = {};
+
+    self.onPageLoad = function() {
+    };
+
+    self.attachToDOM = function() {
+        // Make sure JNEXT onPageLoad is called when page load
+        //  completes without damaging existing onLoad handlers
+        var prevOnLoad = window.onload;
+        if( typeof window.onload != 'function') {
+            window.onload = self.onPageLoad;
+        } else {
+            window.onload = function() {
+                if(prevOnLoad) {
+                    prevOnLoad();
+                }
+
+                self.onPageLoad();
+            };
+        }
+
+        // Unobtrusively add the JNEXT plugin or ActiveX to the DOM
+        var objBody = document.getElementsByTagName("body")[0];
+        var objDiv = document.createElement('div');
+        var strHTML;
+
+        if(window.ActiveXObject) {
+            strHTML = '<object id="objJSExt" width="0" height="0" classid="CLSID:C802F39D-BF85-427a-A334-77E501DB62E9" codebase="jnext.ocx"></object>';
+            strHTML += '<script language="JavaScript" for="objJSExt" EVENT="Js2nEvent( strEvent )">JNEXT.processEvent(strEvent)</script>';
+        } else {
+            var strAddSrc = "";
+            if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Windows") != -1) {
+                // This hack required on Safari for Windows
+                strAddSrc = 'src="./jnext/safari.foo"';
+            }
+            strHTML = '<embed id="objJSExt" ' + strAddSrc + ' type="application/jnext-scriptable-plugin" width="0" height="0">';
+        }
+
+        objDiv.innerHTML = strHTML;
+        objBody.appendChild(objDiv);
+    };
+
+    self.getosname = function() {
+        return objJSExt.sendCmd("osname");
+    };
+
+    self.require = function(strLibrary) {
+        // Load a required JNEXT plugin
+        var strCmd;
+        var strVal;
+        var arParams;
+
+        if(m_bFirstRequire) {
+            strCmd = "userAgent " + navigator.userAgent;
+            strVal = objJSExt.sendCmd(strCmd);
+            arParams = strVal.split(" ");
+            if(arParams[0] != "Ok") {
+                alert("userAgent " + strVal);
+                return false;
+            }
+            self.m_bFirstRequire = false;
+        }
+        strCmd = "Require " + strLibrary;
+        strVal = objJSExt.sendCmd(strCmd);
+        arParams = strVal.split(" ");
+        if(arParams[0] != "Ok") {
+            alert("Require " + strVal);
+            return false;
+        }
+
+        return true;
+    };
+
+    self.createObject = function(strObjName) {
+        // Create an instance of a native object
+        var strCmd;
+        var strVal;
+        var arParams;
+        strVal = objJSExt.sendCmd("CreateObject " + strObjName);
+        arParams = strVal.split(" ");
+        if(arParams[0] != "Ok") {
+            alert("CreateObject: " + strVal);
+            return "";
+        }
+        return arParams[1];
+    };
+
+    self.invoke = function(strObjId, strMethod, strParams) {
+        // Invoke a method of a given instance of a native object
+        var strCmd = "InvokeMethod " + strObjId + " " + strMethod;
+
+        if( typeof (strParams) != "undefined") {
+            strCmd += " " + strParams;
+        }
+
+        return objJSExt.sendCmd(strCmd);
+    };
+
+    self.registerEvents = function(objNotify) {
+        var strId = objNotify.getId();
+        self.m_arEvents[strId] = objNotify;
+    };
+
+    self.unregisterEvents = function(objNotify) {
+        var strId = objNotify.getId();
+        delete self.m_arEvents[strId];
+    };
+
+    self.processEvent = function(strNativeEvt) {
+        // Process an event received from native code. The event
+        // containes the target JavaScript object id and the
+        // relevant parameters.
+
+        var arParams = strNativeEvt.split(" ");
+        var strObjId = arParams[0];
+        var strEvent = strNativeEvt.substring(strObjId.length + 1);
+
+        var objNotify = self.m_arEvents[strObjId];
+        if( typeof (objNotify) == 'undefined') {
+            alert("Warning: No object with Id " + strId + " found for event " + strEvent);
+            return;
+        }
+
+        // This will now be handled by the appropriate JavaScript
+        // JNEXT extension object
+        objNotify.onEvent(strEvent);
+    };
+
+    self.ajaxGet = function(strUrl, id) {
+        var req = false;
+        if(window.ActiveXObject) {
+            try {
+                req = new ActiveXObject("Msxml2.XMLHTTP");
+            } catch (e) {
+                try {
+                    req = new ActiveXObject("Microsoft.XMLHTTP");
+                } catch (ex) {
+                }
+            }
+        } else if(window.XMLHttpRequest) {
+            req = new XMLHttpRequest();
+        } else {
+            return false;
+        }
+
+        req.onreadystatechange = function() {
+            if(req.readyState == 4 && (req.status == 200 || window.location.href.indexOf("http") == -1)) {
+                self.onAjaxRecv(req.responseText);
+            }
+        };
+
+        req.open('GET', strUrl, true);
+        req.send(null);
+    };
+
+    self.onAjaxRecv = function(strContent) {
+        alert(strContent);
+    };
+
+    self.attachToDOM();
+}
+
+window.JNEXT = new JNEXT_();
+module.exports = JNEXT;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/overlayWebView.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/overlayWebView.js b/lib/cordova-blackberry/blackberry10/framework/lib/overlayWebView.js
new file mode 100644
index 0000000..a2bba69
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/overlayWebView.js
@@ -0,0 +1,143 @@
+/*
+ *  Copyright 2012 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 CHROME_HEIGHT = 0,
+    webview,
+    _webviewObj;
+
+webview =
+    {
+
+    create: function (ready, configSettings) {
+        _webviewObj = window.qnx.webplatform.createUIWebView(function () {
+
+            _webviewObj.visible = true;
+            _webviewObj.active = true;
+            _webviewObj.zOrder = 2;
+            _webviewObj.enableCrossSiteXHR = true;
+            _webviewObj.setGeometry(0, 0, screen.width, screen.height);
+            _webviewObj.addEventListener("DocumentLoadFinished", function () {
+                _webviewObj.default.setDefaultFont();
+                _webviewObj.visible = true;
+            });
+
+            _webviewObj.allowRpc = true;
+            _webviewObj.backgroundColor = 0x00FFFFFF;
+            _webviewObj.sensitivity = "SensitivityTest";
+            _webviewObj.devicePixelRatio = 1;
+            _webviewObj.allowQnxObject = true;
+
+            if (ready && typeof ready === 'function') {
+                ready();
+            }
+
+            window.qnx.webplatform.getController().dispatchEvent("overlayWebView.initialized", [_webviewObj]);
+
+        });
+    },
+
+    destroy: function () {
+        _webviewObj.destroy();
+    },
+
+    setURL: function (url) {
+        _webviewObj.url = url;
+    },
+
+    setGeometry: function (x, y, width, height) {
+        _webviewObj.setGeometry(x, y, width, height);
+    },
+
+    setSensitivity : function (sensitivity) {
+        _webviewObj.sensitivity = sensitivity;
+    },
+
+    setApplicationOrientation: function (angle) {
+        _webviewObj.setApplicationOrientation(angle);
+    },
+
+    notifyApplicationOrientationDone: function () {
+        _webviewObj.notifyApplicationOrientationDone();
+    },
+
+    executeJavascript: function (js) {
+        _webviewObj.executeJavaScript(js);
+    },
+
+    windowGroup: function () {
+        return _webviewObj.windowGroup;
+    },
+
+    notifyContextMenuCancelled: function () {
+        _webviewObj.notifyContextMenuCancelled();
+    },
+
+    bindAppWebViewToChildWebViewControls: function (appWebView) {
+        if (_webviewObj && _webviewObj.childwebviewcontrols) {
+            _webviewObj.childwebviewcontrols.subscribeTo(appWebView);
+        }
+    },
+
+    renderContextMenuFor: function (targetWebView) {
+        return _webviewObj.contextMenu.subscribeTo(targetWebView);
+    },
+
+    handleDialogFor: function (targetWebView) {
+        return _webviewObj.dialog.subscribeTo(targetWebView);
+    },
+
+    showDialog: function (description, callback) {
+        return _webviewObj.dialog.show(description, callback);
+    },
+
+    getWebViewObj: function (webview) {
+        return _webviewObj;
+    },
+
+    addEventListener: function (eventName, callback) {
+        _webviewObj.addEventListener(eventName, callback);
+    },
+
+    removeEventListener: function (eventName, callback) {
+        _webviewObj.removeEventListener(eventName, callback);
+    },
+
+    showToast : function (message, options) {
+        return _webviewObj.toast.show(message, options);
+    },
+
+    showInvocationList: function (request, title, success, error) {
+        _webviewObj.invocationlist.show(request, title, success, error);
+    }
+};
+
+webview.__defineGetter__('id', function () {
+    if (_webviewObj) {
+        return _webviewObj.id;
+    }
+});
+
+webview.__defineGetter__('zOrder', function () {
+    return _webviewObj.zOrder;
+});
+
+webview.__defineGetter__('contextMenu', function () {
+    if (_webviewObj) {
+        return _webviewObj.contextMenu;
+    }
+});
+
+module.exports = webview;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/plugins/default.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/plugins/default.js b/lib/cordova-blackberry/blackberry10/framework/lib/plugins/default.js
new file mode 100644
index 0000000..8347917
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/plugins/default.js
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010-2012 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("../policy/whitelist").Whitelist,
+    whitelist = new Whitelist();
+
+module.exports = {
+
+    exec: function (request, succ, fail, args, env) {
+        var extPath = "plugin/" + request.params.ext + "/index",
+            requestObj = {
+                extension: null,
+                method: null,
+                getExtension: function () {
+                    if (frameworkModules.indexOf(extPath + ".js") !== -1) {
+                        this.extension = require("../utils").loadModule("../" + extPath);
+                        return requestObj;
+                    } else {
+                        throw {code: 404, msg: "Extension " + request.params.ext + " not found"};
+                    }
+                },
+                getMethod: function () {
+                    var methodParts = request.params.method ? request.params.method.split('/') : [request.params.method],
+                        extMethod;
+
+                    try {
+                        extMethod = this.extension[methodParts.shift()];
+                        extMethod = methodParts.reduce(function (previous, current) {
+                            if (previous[current]) {
+                                return previous[current];
+                            } else {
+                                throw {code: 404, msg: "Method " + request.params.method + " for " + request.params.ext + " not found"};
+                            }
+                        }, extMethod);
+
+                        if (extMethod && typeof extMethod === "function") {
+                            this.method = extMethod;
+                            return requestObj;
+                        } else {
+                            throw {code: 404, msg: "Method " + request.params.method + " for " + request.params.ext + " not found"};
+                        }
+                    } catch (e) {
+                        throw {code: 404, msg: "Method " + request.params.method + " for " + request.params.ext + " not found"};
+                    }
+                },
+                exec: function () {
+                    this.method(succ, fail, args, env);
+                }
+            };
+
+        try {
+            requestObj.getExtension().getMethod().exec();
+        } catch (e) {
+            console.warn(e.msg);
+            fail(-1, e.msg, e.code);
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/plugins/event.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/plugins/event.js b/lib/cordova-blackberry/blackberry10/framework/lib/plugins/event.js
new file mode 100644
index 0000000..441bc70
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/plugins/event.js
@@ -0,0 +1,42 @@
+/*
+ * 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 _event = require("../../lib/event"),
+    ONCE_EVENT_ERROR = "Error occured while adding once event listener.",
+    ERROR_ID = -1;
+
+module.exports = {
+    once: function (request, success, fail, args, env) {
+        try {
+            var eventName = decodeURIComponent(args.eventName).replace(/\"/g, ""),
+                action = {
+                    once: true,
+                    event: eventName
+                };
+
+            _event.add(action, env.webview);
+
+            if (success) {
+                success();
+            }
+        }
+        catch (e) {
+            if (fail) {
+                fail(ERROR_ID, ONCE_EVENT_ERROR);
+            }
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/policy/folderAccess.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/policy/folderAccess.js b/lib/cordova-blackberry/blackberry10/framework/lib/policy/folderAccess.js
new file mode 100644
index 0000000..5cd5690
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/policy/folderAccess.js
@@ -0,0 +1,175 @@
+/*
+ * 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 util = require("../utils");
+
+// Removes the start and end slashes from the path
+function _trimSurroundingSlashes(path) {
+    // Trim starting slash
+    if (util.startsWith(path, "/")) {
+        path = path.substr(1);
+    }
+
+    // Trim ending slash
+    if (util.endsWith(path, "/")) {
+        path = path.substr(0, path.length - 1);
+    }
+
+    return path;
+}
+
+// Determines the depth of the given path
+// Folder path must not include the scheme or the host
+function _determineDepth(folderPath) {
+    var depthCount = 0;
+
+    // Replace all backslashes with forward slash
+    folderPath = folderPath.replace("\\", "/");
+
+    // Special case: "/" is the given path
+    if (folderPath === "/") {
+        return 0;
+    }
+
+    folderPath = _trimSurroundingSlashes(folderPath);
+
+    // Count slashes remaining
+    while (folderPath.indexOf("/") !== -1) {
+        depthCount = depthCount + 1;
+
+        // Add 1 to skip the slash
+        folderPath = folderPath.substring(folderPath.indexOf("/") + 1);
+    }
+
+    // Add one more for the remaining folder
+    depthCount += 1;
+
+    return depthCount;
+}
+
+// Parse a folder path up to the desired depth
+function _getPath(folderPath, desiredDepth) {
+    var depthCount = 0, builtPath = "";
+
+    // Special case: Desired depth is 0
+    if (desiredDepth === 0) {
+        return "/";
+    }
+
+    // Replace all backslashes with forward slash
+    folderPath = folderPath.replace("\\", "/");
+
+    folderPath = _trimSurroundingSlashes(folderPath);
+
+    // Count slashes remaining
+    while (depthCount < desiredDepth) {
+        depthCount += 1;
+
+        // Add 1 to skip the slash
+        builtPath += "/" + folderPath.substring(0, folderPath.indexOf('/'));
+        folderPath = folderPath.substring(folderPath.indexOf('/') + 1);
+    }
+
+    return builtPath;
+}
+
+function WebFolderAccessManager() {
+    this._pathCollection = {};
+    this._maxPathLength = 0;
+}
+
+WebFolderAccessManager.prototype.addAccess = function (folderPath, access) {
+    if (!folderPath) {
+        folderPath = "/";
+    }
+
+    // Trim surrounding slashes for consistency
+    // The root "/" is a special case that does not need this trimming
+    if (folderPath !== "/") {
+        folderPath = "/" + _trimSurroundingSlashes(folderPath);
+    }
+
+    folderPath = folderPath.toLowerCase();
+
+    this._pathCollection[folderPath] = access;
+
+    // Determine the depth of the path
+    this._maxPathLength = Math.max(this._maxPathLength, _determineDepth(folderPath));
+};
+
+WebFolderAccessManager.prototype.getAccess = function (folderPath) {
+    var depth = _determineDepth(folderPath);
+    return this.getAccessRecursively(folderPath, depth);
+};
+
+WebFolderAccessManager.prototype.fetchAccess = function (folderPath) {
+    var queryIndex, folderPathWildcard;
+
+    if (!this._pathCollection.hasOwnProperty(folderPath)) {
+        // If there isn't an exact match and folderPath contains query string,
+        // check if the path collection contains an access with the same folderPath
+        // but with wildcard query
+        if ((queryIndex = folderPath.indexOf("?")) > -1) {
+            folderPathWildcard = folderPath.slice(0, queryIndex + 1) + "*";
+
+            if (this._pathCollection.hasOwnProperty(folderPathWildcard)) {
+                return this._pathCollection[folderPathWildcard];
+            }
+        }
+
+        return null;
+    } else {
+        return this._pathCollection[folderPath];
+    }
+};
+
+WebFolderAccessManager.prototype.getAccessRecursively = function (folderPath, pathLength) {
+    var fetchedAccess,
+        newPathLength,
+        newPath;
+
+    if (!folderPath) {
+        return null;
+    }
+
+    folderPath = folderPath.toLowerCase();
+
+    if (!!(fetchedAccess = this.fetchAccess(folderPath))) {
+        return fetchedAccess;
+    } else {
+        // Truncate the end portion of the path and try again
+        newPathLength = Math.min(this._maxPathLength, pathLength - 1);
+        newPath = _getPath(folderPath, newPathLength);
+
+        return this.getAccessRecursively(newPath, newPathLength);
+    }
+};
+
+function WebFolderAccess() {
+    this._mgr = new WebFolderAccessManager();
+}
+
+// folderPath - folder path must not include the scheme or the host
+WebFolderAccess.prototype.addAccess = function (folderPath, access) {
+    this._mgr.addAccess(folderPath, access);
+};
+
+// folderPath - folder path must not include the scheme or the host
+WebFolderAccess.prototype.getAccess = function (folderPath) {
+    return this._mgr.getAccess(folderPath);
+};
+
+exports.WebFolderAccess = WebFolderAccess;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/lib/policy/webkitOriginAccess.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/lib/policy/webkitOriginAccess.js b/lib/cordova-blackberry/blackberry10/framework/lib/policy/webkitOriginAccess.js
new file mode 100644
index 0000000..84adb49
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/lib/policy/webkitOriginAccess.js
@@ -0,0 +1,123 @@
+/*
+ *  Copyright 2012 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 config = require('./../config'),
+    utils = require('./../utils'),
+    Whitelist = require('./whitelist').Whitelist,
+    LOCAL_URI = "local://",
+    FILE_URI = "file://",
+    WW_URI = utils.getURIPrefix(),
+    _domains = [
+        {
+            url: LOCAL_URI,
+            allowSubDomains: true
+        }
+    ],
+    _webviews = [],
+    _isInitialized = false,
+    _whitelist = new Whitelist();
+
+function addOriginAccessWhitelistEntry(webview, source, destination, allowSubDomains) {
+    webview.addOriginAccessWhitelistEntry(source, destination, !!allowSubDomains);
+}
+
+function addDomain(url, allowSubDomains) {
+    var parsedUri = utils.parseUri(url);
+
+    allowSubDomains = !!allowSubDomains;
+
+    if (utils.isLocalURI(parsedUri)) {
+        url = LOCAL_URI;
+    } else if (utils.isFileURI(parsedUri)) {
+        url = FILE_URI;
+    } else {
+        url = parsedUri.source;
+    }
+
+    if (_whitelist.isAccessAllowed(url) && !_domains.some(function (domain) {
+        return domain.url === url;
+    })) {
+        _webviews.forEach(function (webview) {
+            addOriginAccessWhitelistEntry(webview, url, WW_URI, true);
+
+            _domains.forEach(function (domain) {
+                addOriginAccessWhitelistEntry(webview, domain.url, url, allowSubDomains);
+                addOriginAccessWhitelistEntry(webview, url, domain.url, domain.allowSubDomains);
+            });
+
+        });
+
+        _domains.push({
+            url: url,
+            allowSubDomains: allowSubDomains
+        });
+    }
+}
+
+function initializeDomains() {
+    var accessElements = config.accessList;
+
+    accessElements.forEach(function (element, index, array) {
+        var uri = (element.uri === 'WIDGET_LOCAL' ? LOCAL_URI : element.uri);
+        addDomain(uri, !!element.allowSubDomain);
+    });
+}
+
+function initializaWebview(webview) {
+    //Always allow file access from local and let the OS deal with permissions
+    addOriginAccessWhitelistEntry(webview, LOCAL_URI, FILE_URI, true);
+    addOriginAccessWhitelistEntry(webview, FILE_URI, LOCAL_URI, true);
+    //Always allow LOCAL access to URIs
+    addOriginAccessWhitelistEntry(webview, LOCAL_URI, WW_URI, true);
+
+    _domains.forEach(function (domain, domainIndex, domainArray) {
+        var i,
+            nextDomain;
+
+        if (domain.uri !== LOCAL_URI) {
+            addOriginAccessWhitelistEntry(webview, domain.url, WW_URI, true);
+        }
+
+        for (i = domainIndex + 1; i < domainArray.length; i++) {
+            nextDomain = domainArray[i];
+            addOriginAccessWhitelistEntry(webview, domain.url, nextDomain.url, nextDomain.allowSubDomains);
+            addOriginAccessWhitelistEntry(webview, nextDomain.url, domain.url, domain.allowSubDomains);
+        }
+    });
+
+}
+
+module.exports = {
+
+    addWebView: function (webview) {
+        if (_webviews.indexOf(webview) === -1) {
+            _webviews.push(webview);
+            initializaWebview(webview);
+            if (!_isInitialized) {
+                initializeDomains();
+                _isInitialized = true;
+            }
+        }
+    },
+
+    addOriginAccess: function (origin, allowSubDomains) {
+        if (!_isInitialized) {
+            initializeDomains();
+            _isInitialized = true;
+        }
+        addDomain(origin, allowSubDomains);
+    }
+};