Update JS snapshot (was missing "CoreAndroid" name change)

This commit is contained in:
Andrew Grieve 2015-02-05 20:45:14 -05:00
parent 81dafb7b3f
commit 66424b7ed5

View File

@ -1,5 +1,5 @@
// Platform: android // Platform: android
// 24ab6855470f2dc0662624b597c98585e56a1666 // fc4db9145934bd0053161cbf9ffc0caf83b770c6
/* /*
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file or more contributor license agreements. See the NOTICE file
@ -19,7 +19,7 @@
under the License. under the License.
*/ */
;(function() { ;(function() {
var PLATFORM_VERSION_BUILD_LABEL = '4.0.x'; var PLATFORM_VERSION_BUILD_LABEL = '4.0.0-dev';
// file: src/scripts/require.js // file: src/scripts/require.js
/*jshint -W079 */ /*jshint -W079 */
@ -900,9 +900,13 @@ var cordova = require('cordova'),
jsToNativeBridgeMode, // Set lazily. jsToNativeBridgeMode, // Set lazily.
nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT, nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
pollEnabled = false, pollEnabled = false,
messagesFromNative = [],
bridgeSecret = -1; bridgeSecret = -1;
var messagesFromNative = [];
var isProcessing = false;
var resolvedPromise = typeof Promise == 'undefined' ? null : Promise.resolve();
var nextTick = resolvedPromise ? function(fn) { resolvedPromise.then(fn); } : function(fn) { setTimeout(fn); };
function androidExec(success, fail, service, action, args) { function androidExec(success, fail, service, action, args) {
if (bridgeSecret < 0) { if (bridgeSecret < 0) {
// If we ever catch this firing, we'll need to queue up exec()s // If we ever catch this firing, we'll need to queue up exec()s
@ -931,16 +935,17 @@ function androidExec(success, fail, service, action, args) {
cordova.callbacks[callbackId] = {success:success, fail:fail}; cordova.callbacks[callbackId] = {success:success, fail:fail};
} }
var messages = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson); var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
// If argsJson was received by Java as null, try again with the PROMPT bridge mode. // 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. // 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.") { if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && msgs === "@Null arguments.") {
androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT); androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
androidExec(success, fail, service, action, args); androidExec(success, fail, service, action, args);
androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT); androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
return; } else if (msgs) {
} else { messagesFromNative.push(msgs);
androidExec.processMessages(messages, true); // Always process async to avoid exceptions messing up stack.
nextTick(processMessages);
} }
} }
@ -959,8 +964,12 @@ function pollOnce(opt_fromOnlineEvent) {
// We know there's nothing to retrieve, so no need to poll. // We know there's nothing to retrieve, so no need to poll.
return; return;
} }
var msg = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent); var msgs = nativeApiProvider.get().retrieveJsMessages(bridgeSecret, !!opt_fromOnlineEvent);
androidExec.processMessages(msg); if (msgs) {
messagesFromNative.push(msgs);
// Process sync since we know we're already top-of-stack.
processMessages();
}
} }
function pollingTimerFunc() { function pollingTimerFunc() {
@ -1053,63 +1062,51 @@ function buildPayload(payload, message) {
// Processes a single message, as encoded by NativeToJsMessageQueue.java. // Processes a single message, as encoded by NativeToJsMessageQueue.java.
function processMessage(message) { function processMessage(message) {
try { var firstChar = message.charAt(0);
var firstChar = message.charAt(0); if (firstChar == 'J') {
if (firstChar == 'J') { // This is deprecated on the .java side. It doesn't work with CSP enabled.
eval(message.slice(1)); eval(message.slice(1));
} else if (firstChar == 'S' || firstChar == 'F') { } else if (firstChar == 'S' || firstChar == 'F') {
var success = firstChar == 'S'; var success = firstChar == 'S';
var keepCallback = message.charAt(1) == '1'; var keepCallback = message.charAt(1) == '1';
var spaceIdx = message.indexOf(' ', 2); var spaceIdx = message.indexOf(' ', 2);
var status = +message.slice(2, spaceIdx); var status = +message.slice(2, spaceIdx);
var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1); var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx); var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
var payloadMessage = message.slice(nextSpaceIdx + 1); var payloadMessage = message.slice(nextSpaceIdx + 1);
var payload = []; var payload = [];
buildPayload(payload, payloadMessage); buildPayload(payload, payloadMessage);
cordova.callbackFromNative(callbackId, success, status, payload, keepCallback); cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
} else { } else {
console.log("processMessage failed: invalid message: " + JSON.stringify(message)); console.log("processMessage failed: invalid message: " + JSON.stringify(message));
}
} catch (e) {
console.log("processMessage failed: Error: " + e);
console.log("processMessage failed: Stack: " + e.stack);
console.log("processMessage failed: Message: " + message);
} }
} }
var isProcessing = false; function processMessages() {
// This is called from the NativeToJsMessageQueue.java.
androidExec.processMessages = function(messages, opt_useTimeout) {
if (messages) {
messagesFromNative.push(messages);
}
// Check for the reentrant case. // Check for the reentrant case.
if (isProcessing) { if (isProcessing) {
return; return;
} }
if (opt_useTimeout) { if (messagesFromNative.length === 0) {
window.setTimeout(androidExec.processMessages, 0);
return; return;
} }
isProcessing = true; isProcessing = true;
try { try {
// TODO: add setImmediate polyfill and process only one message at a time. var msg = popMessageFromQueue();
while (messagesFromNative.length) { // The Java side can send a * message to indicate that it
var msg = popMessageFromQueue(); // still has messages waiting to be retrieved.
// The Java side can send a * message to indicate that it if (msg == '*' && messagesFromNative.length === 0) {
// still has messages waiting to be retrieved. nextTick(pollOnce);
if (msg == '*' && messagesFromNative.length === 0) { return;
setTimeout(pollOnce, 0);
return;
}
processMessage(msg);
} }
processMessage(msg);
} finally { } finally {
isProcessing = false; isProcessing = false;
if (messagesFromNative.length > 0) {
nextTick(processMessages);
}
} }
}; }
function popMessageFromQueue() { function popMessageFromQueue() {
var messageBatch = messagesFromNative.shift(); var messageBatch = messagesFromNative.shift();
@ -1566,9 +1563,6 @@ function onMessageFromNative(msg) {
// App life cycle events // App life cycle events
case 'pause': case 'pause':
case 'resume': case 'resume':
// Keyboard events
case 'hidekeyboard':
case 'showkeyboard':
// Volume events // Volume events
case 'volumedownbutton': case 'volumedownbutton':
case 'volumeupbutton': case 'volumeupbutton':
@ -1585,13 +1579,14 @@ function onMessageFromNative(msg) {
define("cordova/plugin/android/app", function(require, exports, module) { define("cordova/plugin/android/app", function(require, exports, module) {
var exec = require('cordova/exec'); var exec = require('cordova/exec');
var APP_PLUGIN_NAME = Number(require('cordova').platformVersion.split('.')[0]) >= 4 ? 'CoreAndroid' : 'App';
module.exports = { module.exports = {
/** /**
* Clear the resource cache. * Clear the resource cache.
*/ */
clearCache:function() { clearCache:function() {
exec(null, null, "App", "clearCache", []); exec(null, null, APP_PLUGIN_NAME, "clearCache", []);
}, },
/** /**
@ -1609,14 +1604,14 @@ module.exports = {
* navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000}); * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
*/ */
loadUrl:function(url, props) { loadUrl:function(url, props) {
exec(null, null, "App", "loadUrl", [url, props]); exec(null, null, APP_PLUGIN_NAME, "loadUrl", [url, props]);
}, },
/** /**
* Cancel loadUrl that is waiting to be loaded. * Cancel loadUrl that is waiting to be loaded.
*/ */
cancelLoadUrl:function() { cancelLoadUrl:function() {
exec(null, null, "App", "cancelLoadUrl", []); exec(null, null, APP_PLUGIN_NAME, "cancelLoadUrl", []);
}, },
/** /**
@ -1624,7 +1619,7 @@ module.exports = {
* Instead of BACK button loading the previous web page, it will exit the app. * Instead of BACK button loading the previous web page, it will exit the app.
*/ */
clearHistory:function() { clearHistory:function() {
exec(null, null, "App", "clearHistory", []); exec(null, null, APP_PLUGIN_NAME, "clearHistory", []);
}, },
/** /**
@ -1632,7 +1627,7 @@ module.exports = {
* This is the same as pressing the backbutton on Android device. * This is the same as pressing the backbutton on Android device.
*/ */
backHistory:function() { backHistory:function() {
exec(null, null, "App", "backHistory", []); exec(null, null, APP_PLUGIN_NAME, "backHistory", []);
}, },
/** /**
@ -1645,7 +1640,7 @@ module.exports = {
* @param override T=override, F=cancel override * @param override T=override, F=cancel override
*/ */
overrideBackbutton:function(override) { overrideBackbutton:function(override) {
exec(null, null, "App", "overrideBackbutton", [override]); exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [override]);
}, },
/** /**
@ -1660,14 +1655,14 @@ module.exports = {
* @param override T=override, F=cancel override * @param override T=override, F=cancel override
*/ */
overrideButton:function(button, override) { overrideButton:function(button, override) {
exec(null, null, "App", "overrideButton", [button, override]); exec(null, null, APP_PLUGIN_NAME, "overrideButton", [button, override]);
}, },
/** /**
* Exit and terminate the application. * Exit and terminate the application.
*/ */
exitApp:function() { exitApp:function() {
return exec(null, null, "App", "exitApp", []); return exec(null, null, APP_PLUGIN_NAME, "exitApp", []);
} }
}; };