cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lorinb...@apache.org
Subject [16/33] js commit: [BlackBerry10] Move all exec logic (along with window.webworks) into exec.js
Date Tue, 14 May 2013 18:32:58 GMT
[BlackBerry10] Move all exec logic (along with window.webworks) into exec.js

Reviewed by Jeffrey Heifetz <jheifetz@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/56c53149
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/56c53149
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/56c53149

Branch: refs/heads/master
Commit: 56c5314989ffcf8a0be058714e9a7af7e622d5f3
Parents: b5dc123
Author: Bryan Higgins <bryan@bryanhiggins.net>
Authored: Wed Mar 27 14:28:17 2013 -0400
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Fri May 3 09:49:38 2013 -0400

----------------------------------------------------------------------
 lib/blackberry10/exec.js                        |   99 ++++++++++++++++--
 lib/blackberry10/plugin/blackberry10/manager.js |   54 ----------
 lib/scripts/bootstrap-blackberry10.js           |   83 ---------------
 3 files changed, 91 insertions(+), 145 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/56c53149/lib/blackberry10/exec.js
----------------------------------------------------------------------
diff --git a/lib/blackberry10/exec.js b/lib/blackberry10/exec.js
index e84cd69..25ec0ae 100644
--- a/lib/blackberry10/exec.js
+++ b/lib/blackberry10/exec.js
@@ -20,8 +20,17 @@
 */
 
 var cordova = require('cordova'),
-    platform = require('cordova/platform'),
-    utils = require('cordova/utils');
+    plugins = {
+        'Accelerometer' : require('cordova/plugin/blackberry10/accelerometer'),
+        'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
+        'Camera' : require('cordova/plugin/blackberry10/camera'),
+        'Capture' : require('cordova/plugin/blackberry10/capture'),
+        'Logger' : require('cordova/plugin/blackberry10/logger'),
+        'Notification' : require('cordova/plugin/blackberry10/notification'),
+        'Media': require('cordova/plugin/blackberry10/media'),
+        'InAppBrowser' : require('cordova/plugin/blackberry10/InAppBrowser'),
+        'FileTransfer': require('cordova/plugin/blackberry10/fileTransfer')
+    };
 
 /**
  * Execute a cordova command.  It is up to the native side whether this action
@@ -37,12 +46,86 @@ var cordova = require('cordova'),
  * @param {String} action       Action to be run in cordova
  * @param {String[]} [args]     Zero or more arguments to pass to the method
  */
+module.exports = function (success, fail, service, action, args) {
+    if (plugins[service] && plugins[service][action]) {
+        return plugins[service][action](args, success, fail);
+    }
+    return webworks.exec(success, fail, service, action, args);
+};
 
-module.exports = function(success, fail, service, action, args) {
-    try {
-        require('cordova/plugin/blackberry10/manager').exec(success, fail, service, action,
args);
-        return null;
-    } catch (e) {
-        utils.alert("Error: "+e);
+function RemoteFunctionCall(functionUri) {
+     var params = {};
+
+    function composeUri() {
+        return require("cordova/plugin/blackberry10/utils").getURIPrefix() + functionUri;
     }
+
+    function createXhrRequest(uri, isAsync) {
+        var request = new XMLHttpRequest();
+        request.open("POST", uri, isAsync);
+        request.setRequestHeader("Content-Type", "application/json");
+        return request;
+    }
+
+    this.addParam = function (name, value) {
+        params[name] = encodeURIComponent(JSON.stringify(value));
+    };
+
+    this.makeSyncCall = function (success, error) {
+        var requestUri = composeUri(),
+            request = createXhrRequest(requestUri, false),
+            response,
+            errored,
+            cb,
+            data;
+
+        request.send(JSON.stringify(params));
+        response = JSON.parse(decodeURIComponent(request.responseText) || "null");
+        return response;
+    };
+}
+
+window.webworks = {
+    exec: function (success, fail, service, action, args) {
+        var uri = service + "/" + action,
+            request = new RemoteFunctionCall(uri),
+            callbackId = service + cordova.callbackId++,
+            response,
+            name,
+            didSucceed;
+
+        for (name in args) {
+            if (Object.hasOwnProperty.call(args, name)) {
+                request.addParam(name, args[name]);
+            }
+        }
+
+        cordova.callbacks[callbackId] = {success:success, fail:fail};
+        request.addParam("callbackId", callbackId);
+
+        response = request.makeSyncCall();
+
+        //Old WebWorks Extension success
+        if (response.code === 42) {
+            if (success) {
+                success(response.data, response);
+            }
+            delete cordova.callbacks[callbackId];
+        } else if (response.code < 0) {
+            if (fail) {
+                fail(response.msg, response);
+            }
+            delete cordova.callbacks[callbackId];
+        } else {
+            didSucceed = response.code === cordova.callbackStatus.OK || response.code ===
cordova.callbackStatus.NO_RESULT;
+            cordova.callbackFromNative(callbackId, didSucceed, response.code, didSucceed
? response.data : response.msg, !!response.keepCallback);
+        }
+    },
+    defineReadOnlyField: function (obj, field, value) {
+        Object.defineProperty(obj, field, {
+            "value": value,
+            "writable": false
+        });
+    },
+    event: require("cordova/plugin/blackberry10/event")
 };

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/56c53149/lib/blackberry10/plugin/blackberry10/manager.js
----------------------------------------------------------------------
diff --git a/lib/blackberry10/plugin/blackberry10/manager.js b/lib/blackberry10/plugin/blackberry10/manager.js
deleted file mode 100644
index 6fc0dda..0000000
--- a/lib/blackberry10/plugin/blackberry10/manager.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var cordova = require('cordova'),
-    plugins = {
-        'Accelerometer' : require('cordova/plugin/blackberry10/accelerometer'),
-        'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
-        'Camera' : require('cordova/plugin/blackberry10/camera'),
-        'Capture' : require('cordova/plugin/blackberry10/capture'),
-        'Logger' : require('cordova/plugin/blackberry10/logger'),
-        'Notification' : require('cordova/plugin/blackberry10/notification'),
-        'Media': require('cordova/plugin/blackberry10/media'),
-        'File' : require('cordova/plugin/blackberry10/file'),
-        'InAppBrowser' : require('cordova/plugin/blackberry10/InAppBrowser'),
-        'FileTransfer': require('cordova/plugin/blackberry10/fileTransfer')
-    };
-
-module.exports = {
-    addPlugin: function (key, module) {
-        plugins[key] = require(module);
-    },
-    exec: function (win, fail, clazz, action, args) {
-        var result = {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message"
: "Class " + clazz + " cannot be found"};
-
-        if (plugins[clazz] && plugins[clazz][action]) {
-            result = plugins[clazz][action](args, win, fail);
-        }
-        else {
-            result = webworks.exec(win, fail, clazz, action, args);
-        }
-        return result;
-    },
-    resume: function () {},
-    pause: function () {},
-    destroy: function () {}
-};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/56c53149/lib/scripts/bootstrap-blackberry10.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-blackberry10.js b/lib/scripts/bootstrap-blackberry10.js
index ac32edd..e1c2b83 100644
--- a/lib/scripts/bootstrap-blackberry10.js
+++ b/lib/scripts/bootstrap-blackberry10.js
@@ -61,89 +61,6 @@
             fireWebworksReadyEvent();
         }
     );
-
-    /**
-     * webworks.exec
-     *
-     * This will all be moved into lib/blackberry10/exec once cordova.exec can be replaced
-     */
-
-    function RemoteFunctionCall(functionUri) {
-         var params = {};
-
-        function composeUri() {
-            return require("cordova/plugin/blackberry10/utils").getURIPrefix() + functionUri;
-        }
-
-        function createXhrRequest(uri, isAsync) {
-            var request = new XMLHttpRequest();
-            request.open("POST", uri, isAsync);
-            request.setRequestHeader("Content-Type", "application/json");
-            return request;
-        }
-
-        this.addParam = function (name, value) {
-            params[name] = encodeURIComponent(JSON.stringify(value));
-        };
-
-        this.makeSyncCall = function (success, error) {
-            var requestUri = composeUri(),
-                request = createXhrRequest(requestUri, false),
-                response,
-                errored,
-                cb,
-                data;
-
-            request.send(JSON.stringify(params));
-            response = JSON.parse(decodeURIComponent(request.responseText) || "null");
-            return response;
-        };
-    }
-
-    window.webworks = {
-        exec: function (success, fail, service, action, args) {
-            var uri = service + "/" + action,
-                request = new RemoteFunctionCall(uri),
-                callbackId = service + cordova.callbackId++,
-                response,
-                name,
-                didSucceed;
-
-            for (name in args) {
-                if (Object.hasOwnProperty.call(args, name)) {
-                    request.addParam(name, args[name]);
-                }
-            }
-
-            cordova.callbacks[callbackId] = {success:success, fail:fail};
-            request.addParam("callbackId", callbackId);
-
-            response = request.makeSyncCall();
-
-            //Old WebWorks Extension success
-            if (response.code === 42) {
-                if (success) {
-                    success(response.data, response);
-                }
-                delete cordova.callbacks[callbackId];
-            } else if (response.code < 0) {
-                if (fail) {
-                    fail(response.msg, response);
-                }
-                delete cordova.callbacks[callbackId];
-            } else {
-                didSucceed = response.code === cordova.callbackStatus.OK || response.code
=== cordova.callbackStatus.NO_RESULT;
-                cordova.callbackFromNative(callbackId, didSucceed, response.code, [didSucceed
? response.data : response.msg], !!response.keepCallback);
-            }
-        },
-        defineReadOnlyField: function (obj, field, value) {
-            Object.defineProperty(obj, field, {
-                "value": value,
-                "writable": false
-            });
-        },
-        event: require("cordova/plugin/blackberry10/event")
-    };
 }());
 
 document.addEventListener("DOMContentLoaded", function () {


Mime
View raw message