[BlackBerry10] Initial work on cleaning up the exec chain. Includes the removal of the battery extension to test its working correctly.
Reviewed by Bryan Higgins <bhigg...@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/e8f1e595 Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/e8f1e595 Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/e8f1e595 Branch: refs/heads/3.0.0 Commit: e8f1e595c7c6056dcb3d131b930e3f1cf1efe2f1 Parents: 2e12eda Author: Jeffrey Heifetz <jheif...@rim.com> Authored: Thu Mar 21 14:31:20 2013 -0400 Committer: Bryan Higgins <bhigg...@blackberry.com> Committed: Fri May 3 09:49:38 2013 -0400 ---------------------------------------------------------------------- lib/blackberry10/exec.js | 35 +-------- lib/blackberry10/plugin/blackberry10/battery.js | 40 ---------- lib/blackberry10/plugin/blackberry10/manager.js | 1 - lib/scripts/bootstrap-blackberry10.js | 40 ++++++---- test/blackberry10/test.battery.js | 72 ------------------ 5 files changed, 27 insertions(+), 161 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e8f1e595/lib/blackberry10/exec.js ---------------------------------------------------------------------- diff --git a/lib/blackberry10/exec.js b/lib/blackberry10/exec.js index 5880fbc..e84cd69 100644 --- a/lib/blackberry10/exec.js +++ b/lib/blackberry10/exec.js @@ -40,39 +40,8 @@ var cordova = require('cordova'), module.exports = function(success, fail, service, action, args) { try { - var manager = require('cordova/plugin/blackberry10/manager'), - v = manager.exec(success, fail, service, action, args); - - // If status is OK, then return value back to caller - if (v.status == cordova.callbackStatus.OK) { - - // If there is a success callback, then call it now with returned value - if (success) { - try { - success(v.message); - } - catch (e) { - console.log("Error in success callback: "+cordova.callbackId+" = "+e); - } - } - return v.message; - } else if (v.status == cordova.callbackStatus.NO_RESULT) { - - } else { - // If error, then display error - console.log("Error: Status="+v.status+" Message="+v.message); - - // If there is a fail callback, then call it now with returned value - if (fail) { - try { - fail(v.message); - } - catch (e) { - console.log("Error in error callback: "+cordova.callbackId+" = "+e); - } - } - return null; - } + require('cordova/plugin/blackberry10/manager').exec(success, fail, service, action, args); + return null; } catch (e) { utils.alert("Error: "+e); } http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e8f1e595/lib/blackberry10/plugin/blackberry10/battery.js ---------------------------------------------------------------------- diff --git a/lib/blackberry10/plugin/blackberry10/battery.js b/lib/blackberry10/plugin/blackberry10/battery.js deleted file mode 100644 index 8bd9f44..0000000 --- a/lib/blackberry10/plugin/blackberry10/battery.js +++ /dev/null @@ -1,40 +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'), - interval; - -module.exports = { - start: function (args, win, fail) { - interval = window.setInterval(function () { - win({ - level: navigator.webkitBattery.level * 100, - isPlugged: navigator.webkitBattery.charging - }); - }, 500); - return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" }; - }, - - stop: function (args, win, fail) { - window.clearInterval(interval); - return { "status" : cordova.callbackStatus.OK, "message" : "stopped" }; - } -}; http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e8f1e595/lib/blackberry10/plugin/blackberry10/manager.js ---------------------------------------------------------------------- diff --git a/lib/blackberry10/plugin/blackberry10/manager.js b/lib/blackberry10/plugin/blackberry10/manager.js index b0855b7..6fc0dda 100644 --- a/lib/blackberry10/plugin/blackberry10/manager.js +++ b/lib/blackberry10/plugin/blackberry10/manager.js @@ -22,7 +22,6 @@ var cordova = require('cordova'), plugins = { 'Accelerometer' : require('cordova/plugin/blackberry10/accelerometer'), - 'Battery' : require('cordova/plugin/blackberry10/battery'), 'Compass' : require('cordova/plugin/blackberry10/magnetometer'), 'Camera' : require('cordova/plugin/blackberry10/camera'), 'Capture' : require('cordova/plugin/blackberry10/capture'), http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e8f1e595/lib/scripts/bootstrap-blackberry10.js ---------------------------------------------------------------------- diff --git a/lib/scripts/bootstrap-blackberry10.js b/lib/scripts/bootstrap-blackberry10.js index 153d2c9..ac32edd 100644 --- a/lib/scripts/bootstrap-blackberry10.js +++ b/lib/scripts/bootstrap-blackberry10.js @@ -95,20 +95,8 @@ data; request.send(JSON.stringify(params)); - response = JSON.parse(decodeURIComponent(request.responseText) || "null"); - errored = response.code < 0; - cb = errored ? error : success; - data = errored ? response.msg : response.data; - - if (cb) { - cb(data, response); - } - else if (errored) { - throw data; - } - - return { status: 0 }; + return response; }; } @@ -116,7 +104,10 @@ exec: function (success, fail, service, action, args) { var uri = service + "/" + action, request = new RemoteFunctionCall(uri), - name; + callbackId = service + cordova.callbackId++, + response, + name, + didSucceed; for (name in args) { if (Object.hasOwnProperty.call(args, name)) { @@ -124,7 +115,26 @@ } } - return request.makeSyncCall(success, fail); + 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, { http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e8f1e595/test/blackberry10/test.battery.js ---------------------------------------------------------------------- diff --git a/test/blackberry10/test.battery.js b/test/blackberry10/test.battery.js deleted file mode 100644 index 4e8b0b0..0000000 --- a/test/blackberry10/test.battery.js +++ /dev/null @@ -1,72 +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. - * -*/ - -describe("blackberry10 battery", function () { - var battery = require('cordova/plugin/blackberry10/battery'), - cordova = require('cordova'); - - beforeEach(function () { - spyOn(window, "setInterval").andReturn(1); - spyOn(window, "clearInterval"); - }); - - it("returns no_result when calling start", function () { - expect(battery.start()).toEqual({ - status: cordova.callbackStatus.NO_RESULT, - message: "WebWorks Is On It" - }); - }); - - it("sets an interval for 500 ms when calling start", function () { - battery.start(); - expect(window.setInterval).toHaveBeenCalledWith(jasmine.any(Function), 500); - }); - - it("calls the win callback with values from navigator.webkitBattery", function () { - global.navigator = window.navigator; - window.navigator.webkitBattery = { level: 0.12, charging: true }; - - var win = jasmine.createSpy("win"); - battery.start({}, win); - - window.setInterval.mostRecentCall.args[0](); - - expect(win).toHaveBeenCalledWith({ - level: 12, - isPlugged: true - }); - - delete window.navigator.webkitBattery; - }); - - it("returns ok when calling stop", function () { - expect(battery.stop()).toEqual({ - status: cordova.callbackStatus.OK, - message: "stopped" - }); - }); - - it("calls clearInterval when stopping", function () { - battery.start(); - battery.stop(); - expect(window.clearInterval).toHaveBeenCalledWith(1); - }); -});