You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/09/24 05:44:17 UTC
[03/21] js commit: Upleveled amazon-fireos changes.
Upleveled amazon-fireos changes.
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/0b5a3a87
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/0b5a3a87
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/0b5a3a87
Branch: refs/heads/cb-7219
Commit: 0b5a3a87736cbe31d005f8abbc662c864fcbde62
Parents: ff0358b
Author: Archana Naik <na...@lab126.com>
Authored: Thu Aug 14 11:40:42 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Thu Aug 21 10:02:15 2014 -0700
----------------------------------------------------------------------
.../android/promptbasednativeapi.js | 14 ++---
src/amazon-fireos/exec.js | 56 ++++++++++++--------
src/amazon-fireos/platform.js | 6 +--
3 files changed, 44 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0b5a3a87/src/amazon-fireos/android/promptbasednativeapi.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/android/promptbasednativeapi.js b/src/amazon-fireos/android/promptbasednativeapi.js
index c12f46e..f7fb6bc 100644
--- a/src/amazon-fireos/android/promptbasednativeapi.js
+++ b/src/amazon-fireos/android/promptbasednativeapi.js
@@ -19,17 +19,17 @@
/**
* Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
- * This is used only on the 2.3 simulator, where addJavascriptInterface() is broken.
+ * This is used pre-JellyBean, where addJavascriptInterface() is disabled.
*/
module.exports = {
- exec: function(service, action, callbackId, argsJson) {
- return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
+ exec: function(bridgeSecret, service, action, callbackId, argsJson) {
+ return prompt(argsJson, 'gap:'+JSON.stringify([bridgeSecret, service, action, callbackId]));
},
- setNativeToJsBridgeMode: function(value) {
- prompt(value, 'gap_bridge_mode:');
+ setNativeToJsBridgeMode: function(bridgeSecret, value) {
+ prompt(value, 'gap_bridge_mode:' + bridgeSecret);
},
- retrieveJsMessages: function(fromOnlineEvent) {
- return prompt(+fromOnlineEvent, 'gap_poll:');
+ retrieveJsMessages: function(bridgeSecret, fromOnlineEvent) {
+ return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret);
}
};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0b5a3a87/src/amazon-fireos/exec.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/exec.js b/src/amazon-fireos/exec.js
index 7eca8c6..eb7f862 100644
--- a/src/amazon-fireos/exec.js
+++ b/src/amazon-fireos/exec.js
@@ -37,13 +37,10 @@ var cordova = require('cordova'),
nativeApiProvider = require('cordova/android/nativeapiprovider'),
utils = require('cordova/utils'),
base64 = require('cordova/base64'),
+ channel = require('cordova/channel'),
jsToNativeModes = {
PROMPT: 0,
- JS_OBJECT: 1,
- // This mode is currently for benchmarking purposes only. It must be enabled
- // on the native side through the ENABLE_LOCATION_CHANGE_EXEC_MODE
- // constant within CordovaWebViewClient.java before it will work.
- LOCATION_CHANGE: 2
+ JS_OBJECT: 1
},
nativeToJsModes = {
// Polls for messages using the JS->Native bridge.
@@ -63,9 +60,17 @@ var cordova = require('cordova'),
jsToNativeBridgeMode, // Set lazily.
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
pollEnabled = false,
- messagesFromNative = [];
+ messagesFromNative = [],
+ bridgeSecret = -1;
function androidExec(success, fail, service, action, args) {
+ if (bridgeSecret < 0) {
+ // If we ever catch this firing, we'll need to queue up exec()s
+ // and fire them once we get a secret. For now, I don't think
+ // it's possible for exec() to be called since plugins are parsed but
+ // not run until until after onNativeReady.
+ throw new Error('exec() called without bridgeSecret');
+ }
// Set default bridge modes if they have not already been set.
// By default, we use the failsafe, since addJavascriptInterface breaks too often
if (jsToNativeBridgeMode === undefined) {
@@ -86,29 +91,35 @@ function androidExec(success, fail, service, action, args) {
cordova.callbacks[callbackId] = {success:success, fail:fail};
}
- if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) {
- window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson;
+ var messages = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
+ // If argsJson was received by Java as null, try again with the PROMPT bridge mode.
+ // This happens in rare circumstances, such as when certain Unicode characters are passed over the bridge on a Galaxy S2. See CB-2666.
+ if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && messages === "@Null arguments.") {
+ androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
+ androidExec(success, fail, service, action, args);
+ androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
+ return;
} else {
- var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson);
- // If argsJson was received by Java as null, try again with the PROMPT bridge mode.
- // This happens in rare circumstances, such as when certain Unicode characters are passed over the bridge on a Galaxy S2. See CB-2666.
- if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && messages === "@Null arguments.") {
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
- androidExec(success, fail, service, action, args);
- androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
- return;
- } else {
- androidExec.processMessages(messages, true);
- }
+ androidExec.processMessages(messages, true);
}
}
+androidExec.init = function() {
+ bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
+ channel.onNativeReady.fire();
+};
+
function pollOnceFromOnlineEvent() {
pollOnce(true);
}
function pollOnce(opt_fromOnlineEvent) {
- var msg = nativeApiProvider.get().retrieveJsMessages(!!opt_fromOnlineEvent);
+ if (bridgeSecret < 0) {
+ // This can happen when the NativeToJsMessageQueue resets the online state on page transitions.
+ // We know there's nothing to retrieve, so no need to poll.
+ return;
+ }
+ var msg = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent);
androidExec.processMessages(msg);
}
@@ -158,7 +169,10 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
nativeToJsBridgeMode = mode;
// Tell the native side to switch modes.
- nativeApiProvider.get().setNativeToJsBridgeMode(mode);
+ // Otherwise, it will be set by androidExec.init()
+ if (bridgeSecret >= 0) {
+ nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode);
+ }
if (mode == nativeToJsModes.POLLING) {
pollEnabled = true;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0b5a3a87/src/amazon-fireos/platform.js
----------------------------------------------------------------------
diff --git a/src/amazon-fireos/platform.js b/src/amazon-fireos/platform.js
index 768b39b..e2e08c9 100644
--- a/src/amazon-fireos/platform.js
+++ b/src/amazon-fireos/platform.js
@@ -27,10 +27,8 @@ module.exports = {
exec = require('cordova/exec'),
modulemapper = require('cordova/modulemapper');
- // Tell the native code that a page change has occurred.
- exec(null, null, 'PluginManager', 'startup', []);
- // Tell the JS that the native side is ready.
- channel.onNativeReady.fire();
+ // Get the shared secret needed to use the bridge.
+ exec.init();
// TODO: Extract this as a proper plugin.
modulemapper.clobbers('cordova/plugin/android/app', 'navigator.app');