Update JS snapshot to version 9.0.0 (via coho)

This commit is contained in:
Erisu 2020-06-23 18:33:21 +09:00
parent 5276f56cc4
commit 8e53e2aa56
No known key found for this signature in database
GPG Key ID: 2E5FF17FB26AF7F2

View File

@ -1,5 +1,5 @@
// Platform: android // Platform: android
// 74fdba8b327b2a13b4366dd141b52def96d4cb56 // 538a985db128858c0a0eb4dd40fb9c8e5433fc94
/* /*
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 = '9.0.0-dev'; var PLATFORM_VERSION_BUILD_LABEL = '9.0.0';
// file: src/scripts/require.js // file: src/scripts/require.js
var require; var require;
var define; var define;
@ -50,10 +50,10 @@ var define;
require = function (id) { require = function (id) {
if (!modules[id]) { if (!modules[id]) {
throw 'module ' + id + ' not found'; throw new Error('module ' + id + ' not found');
} else if (id in inProgressModules) { } else if (id in inProgressModules) {
var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id; var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
throw 'Cycle in require graph: ' + cycle; throw new Error('Cycle in require graph: ' + cycle);
} }
if (modules[id].factory) { if (modules[id].factory) {
try { try {
@ -70,7 +70,7 @@ var define;
define = function (id, factory) { define = function (id, factory) {
if (Object.prototype.hasOwnProperty.call(modules, id)) { if (Object.prototype.hasOwnProperty.call(modules, id)) {
throw 'module ' + id + ' already defined'; throw new Error('module ' + id + ' already defined');
} }
modules[id] = { modules[id] = {
@ -97,7 +97,7 @@ define("cordova", function(require, exports, module) {
// Workaround for Windows 10 in hosted environment case // Workaround for Windows 10 in hosted environment case
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object // http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
if (window.cordova && !(window.cordova instanceof HTMLElement)) { // eslint-disable-line no-undef if (window.cordova && !(window.cordova instanceof HTMLElement)) {
throw new Error('cordova already defined'); throw new Error('cordova already defined');
} }
@ -162,7 +162,7 @@ function createEvent (type, data) {
event.initEvent(type, false, false); event.initEvent(type, false, false);
if (data) { if (data) {
for (var i in data) { for (var i in data) {
if (data.hasOwnProperty(i)) { if (Object.prototype.hasOwnProperty.call(data, i)) {
event[i] = data[i]; event[i] = data[i];
} }
} }
@ -170,7 +170,6 @@ function createEvent (type, data) {
return event; return event;
} }
/* eslint-disable no-undef */
var cordova = { var cordova = {
define: define, define: define,
require: require, require: require,
@ -178,8 +177,6 @@ var cordova = {
platformVersion: PLATFORM_VERSION_BUILD_LABEL, platformVersion: PLATFORM_VERSION_BUILD_LABEL,
platformId: platform.id, platformId: platform.id,
/* eslint-enable no-undef */
/** /**
* Methods to add/remove your own addEventListener hijacking on document + window. * Methods to add/remove your own addEventListener hijacking on document + window.
*/ */
@ -198,15 +195,25 @@ var cordova = {
removeDocumentEventHandler: function (event) { removeDocumentEventHandler: function (event) {
delete documentEventHandlers[event]; delete documentEventHandlers[event];
}, },
/** /**
* Retrieve original event handlers that were replaced by Cordova * Retrieve original event handlers that were replaced by Cordova
* *
* @return object * @return object
*/ */
getOriginalHandlers: function () { getOriginalHandlers: function () {
return { 'document': { 'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener }, return {
'window': { 'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener } }; document: {
addEventListener: m_document_addEventListener,
removeEventListener: m_document_removeEventListener
},
window: {
addEventListener: m_window_addEventListener,
removeEventListener: m_window_removeEventListener
}
};
}, },
/** /**
* Method to fire event from native code * Method to fire event from native code
* bNoDetach is required for events which cause an exception which needs to be caught in native code * bNoDetach is required for events which cause an exception which needs to be caught in native code
@ -229,6 +236,7 @@ var cordova = {
document.dispatchEvent(evt); document.dispatchEvent(evt);
} }
}, },
fireWindowEvent: function (type, data) { fireWindowEvent: function (type, data) {
var evt = createEvent(type, data); var evt = createEvent(type, data);
if (typeof windowEventHandlers[type] !== 'undefined') { if (typeof windowEventHandlers[type] !== 'undefined') {
@ -302,12 +310,11 @@ var cordova = {
} }
} catch (err) { } catch (err) {
var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err; var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
console && console.log && console.log(msg); cordova.fireWindowEvent('cordovacallbackerror', { message: msg, error: err });
console && console.log && err.stack && console.log(err.stack);
cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg });
throw err; throw err;
} }
}, },
addConstructor: function (func) { addConstructor: function (func) {
channel.onCordovaReady.subscribe(function () { channel.onCordovaReady.subscribe(function () {
try { try {
@ -334,12 +341,12 @@ var nativeApi = this._cordovaNative || require('cordova/android/promptbasednativ
var currentApi = nativeApi; var currentApi = nativeApi;
module.exports = { module.exports = {
get: function() { return currentApi; }, get: function () { return currentApi; },
setPreferPrompt: function(value) { setPreferPrompt: function (value) {
currentApi = value ? require('cordova/android/promptbasednativeapi') : nativeApi; currentApi = value ? require('cordova/android/promptbasednativeapi') : nativeApi;
}, },
// Used only by tests. // Used only by tests.
set: function(value) { set: function (value) {
currentApi = value; currentApi = value;
} }
}; };
@ -355,13 +362,13 @@ define("cordova/android/promptbasednativeapi", function(require, exports, module
*/ */
module.exports = { module.exports = {
exec: function(bridgeSecret, service, action, callbackId, argsJson) { exec: function (bridgeSecret, service, action, callbackId, argsJson) {
return prompt(argsJson, 'gap:'+JSON.stringify([bridgeSecret, service, action, callbackId])); return prompt(argsJson, 'gap:' + JSON.stringify([bridgeSecret, service, action, callbackId]));
}, },
setNativeToJsBridgeMode: function(bridgeSecret, value) { setNativeToJsBridgeMode: function (bridgeSecret, value) {
prompt(value, 'gap_bridge_mode:' + bridgeSecret); prompt(value, 'gap_bridge_mode:' + bridgeSecret);
}, },
retrieveJsMessages: function(bridgeSecret, fromOnlineEvent) { retrieveJsMessages: function (bridgeSecret, fromOnlineEvent) {
return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret); return prompt(+fromOnlineEvent, 'gap_poll:' + bridgeSecret);
} }
}; };
@ -376,12 +383,12 @@ var utils = require('cordova/utils');
var moduleExports = module.exports; var moduleExports = module.exports;
var typeMap = { var typeMap = {
'A': 'Array', A: 'Array',
'D': 'Date', D: 'Date',
'N': 'Number', N: 'Number',
'S': 'String', S: 'String',
'F': 'Function', F: 'Function',
'O': 'Object' O: 'Object'
}; };
function extractParamName (callee, argIndex) { function extractParamName (callee, argIndex) {
@ -472,7 +479,7 @@ base64.fromArrayBuffer = function (arrayBuffer) {
}; };
base64.toArrayBuffer = function (str) { base64.toArrayBuffer = function (str) {
var decodedStr = typeof atob !== 'undefined' ? atob(str) : Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef var decodedStr = atob(str);
var arrayBuffer = new ArrayBuffer(decodedStr.length); var arrayBuffer = new ArrayBuffer(decodedStr.length);
var array = new Uint8Array(arrayBuffer); var array = new Uint8Array(arrayBuffer);
for (var i = 0, len = decodedStr.length; i < len; i++) { for (var i = 0, len = decodedStr.length; i < len; i++) {
@ -534,14 +541,13 @@ var utils = require('cordova/utils');
function each (objects, func, context) { function each (objects, func, context) {
for (var prop in objects) { for (var prop in objects) {
if (objects.hasOwnProperty(prop)) { if (Object.prototype.hasOwnProperty.call(objects, prop)) {
func.apply(context, [objects[prop], prop]); func.apply(context, [objects[prop], prop]);
} }
} }
} }
function clobber (obj, key, value) { function clobber (obj, key, value) {
exports.replaceHookForTesting(obj, key);
var needsProperty = false; var needsProperty = false;
try { try {
obj[key] = value; obj[key] = value;
@ -615,7 +621,7 @@ function include (parent, objects, clobber, merge) {
*/ */
function recursiveMerge (target, src) { function recursiveMerge (target, src) {
for (var prop in src) { for (var prop in src) {
if (src.hasOwnProperty(prop)) { if (Object.prototype.hasOwnProperty.call(src, prop)) {
if (target.prototype && target.prototype.constructor === target) { if (target.prototype && target.prototype.constructor === target) {
// If the target object is a constructor override off prototype. // If the target object is a constructor override off prototype.
clobber(target.prototype, prop, src[prop]); clobber(target.prototype, prop, src[prop]);
@ -641,7 +647,6 @@ exports.buildIntoAndMerge = function (objects, target) {
}; };
exports.recursiveMerge = recursiveMerge; exports.recursiveMerge = recursiveMerge;
exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter; exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
exports.replaceHookForTesting = function () {};
}); });
@ -722,14 +727,14 @@ var channel = {
} }
if (!len) h(); if (!len) h();
}, },
/* eslint-disable no-return-assign */
create: function (type) { create: function (type) {
return channel[type] = new Channel(type, false); return (channel[type] = new Channel(type, false));
}, },
createSticky: function (type) { createSticky: function (type) {
return channel[type] = new Channel(type, true); return (channel[type] = new Channel(type, true));
}, },
/* eslint-enable no-return-assign */
/** /**
* cordova Channels that must fire before "deviceready" is fired. * cordova Channels that must fire before "deviceready" is fired.
*/ */
@ -850,7 +855,6 @@ Channel.prototype.unsubscribe = function (eventListenerOrFunction) {
* Calls all functions subscribed to this channel. * Calls all functions subscribed to this channel.
*/ */
Channel.prototype.fire = function (e) { Channel.prototype.fire = function (e) {
var fail = false; // eslint-disable-line no-unused-vars
var fireArgs = Array.prototype.slice.call(arguments); var fireArgs = Array.prototype.slice.call(arguments);
// Apply stickiness. // Apply stickiness.
if (this.state === 1) { if (this.state === 1) {
@ -924,38 +928,38 @@ define("cordova/exec", function(require, exports, module) {
* @param {String} action Action to be run in cordova * @param {String} action Action to be run in cordova
* @param {String[]} [args] Zero or more arguments to pass to the method * @param {String[]} [args] Zero or more arguments to pass to the method
*/ */
var cordova = require('cordova'), var cordova = require('cordova');
nativeApiProvider = require('cordova/android/nativeapiprovider'), var nativeApiProvider = require('cordova/android/nativeapiprovider');
utils = require('cordova/utils'), var utils = require('cordova/utils');
base64 = require('cordova/base64'), var base64 = require('cordova/base64');
channel = require('cordova/channel'), var channel = require('cordova/channel');
jsToNativeModes = { var jsToNativeModes = {
PROMPT: 0, PROMPT: 0,
JS_OBJECT: 1 JS_OBJECT: 1
}, };
nativeToJsModes = { var nativeToJsModes = {
// Polls for messages using the JS->Native bridge. // Polls for messages using the JS->Native bridge.
POLLING: 0, POLLING: 0,
// For LOAD_URL to be viable, it would need to have a work-around for // For LOAD_URL to be viable, it would need to have a work-around for
// the bug where the soft-keyboard gets dismissed when a message is sent. // the bug where the soft-keyboard gets dismissed when a message is sent.
LOAD_URL: 1, LOAD_URL: 1,
// For the ONLINE_EVENT to be viable, it would need to intercept all event // For the ONLINE_EVENT to be viable, it would need to intercept all event
// listeners (both through addEventListener and window.ononline) as well // listeners (both through addEventListener and window.ononline) as well
// as set the navigator property itself. // as set the navigator property itself.
ONLINE_EVENT: 2, ONLINE_EVENT: 2,
EVAL_BRIDGE: 3 EVAL_BRIDGE: 3
}, };
jsToNativeBridgeMode, // Set lazily. var jsToNativeBridgeMode; // Set lazily.
nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE, var nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE;
pollEnabled = false, var pollEnabled = false;
bridgeSecret = -1; var bridgeSecret = -1;
var messagesFromNative = []; var messagesFromNative = [];
var isProcessing = false; var isProcessing = false;
var resolvedPromise = typeof Promise == 'undefined' ? null : Promise.resolve(); var resolvedPromise = typeof Promise === 'undefined' ? null : Promise.resolve();
var nextTick = resolvedPromise ? function(fn) { resolvedPromise.then(fn); } : function(fn) { setTimeout(fn); }; 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
// and fire them once we get a secret. For now, I don't think // and fire them once we get a secret. For now, I don't think
@ -974,21 +978,21 @@ function androidExec(success, fail, service, action, args) {
// Process any ArrayBuffers in the args into a string. // Process any ArrayBuffers in the args into a string.
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
if (utils.typeName(args[i]) == 'ArrayBuffer') { if (utils.typeName(args[i]) === 'ArrayBuffer') {
args[i] = base64.fromArrayBuffer(args[i]); args[i] = base64.fromArrayBuffer(args[i]);
} }
} }
var callbackId = service + cordova.callbackId++, var callbackId = service + cordova.callbackId++;
argsJson = JSON.stringify(args); var argsJson = JSON.stringify(args);
if (success || fail) { if (success || fail) {
cordova.callbacks[callbackId] = {success:success, fail:fail}; cordova.callbacks[callbackId] = { success: success, fail: fail };
} }
var msgs = 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 && msgs === "@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);
@ -999,16 +1003,16 @@ function androidExec(success, fail, service, action, args) {
} }
} }
androidExec.init = function() { androidExec.init = function () {
bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode); bridgeSecret = +prompt('', 'gap_init:' + nativeToJsBridgeMode);
channel.onNativeReady.fire(); channel.onNativeReady.fire();
}; };
function pollOnceFromOnlineEvent() { function pollOnceFromOnlineEvent () {
pollOnce(true); pollOnce(true);
} }
function pollOnce(opt_fromOnlineEvent) { function pollOnce (opt_fromOnlineEvent) {
if (bridgeSecret < 0) { if (bridgeSecret < 0) {
// This can happen when the NativeToJsMessageQueue resets the online state on page transitions. // 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. // We know there's nothing to retrieve, so no need to poll.
@ -1022,15 +1026,15 @@ function pollOnce(opt_fromOnlineEvent) {
} }
} }
function pollingTimerFunc() { function pollingTimerFunc () {
if (pollEnabled) { if (pollEnabled) {
pollOnce(); pollOnce();
setTimeout(pollingTimerFunc, 50); setTimeout(pollingTimerFunc, 50);
} }
} }
function hookOnlineApis() { function hookOnlineApis () {
function proxyEvent(e) { function proxyEvent (e) {
cordova.fireWindowEvent(e.type); cordova.fireWindowEvent(e.type);
} }
// The network module takes care of firing online and offline events. // The network module takes care of firing online and offline events.
@ -1050,19 +1054,19 @@ hookOnlineApis();
androidExec.jsToNativeModes = jsToNativeModes; androidExec.jsToNativeModes = jsToNativeModes;
androidExec.nativeToJsModes = nativeToJsModes; androidExec.nativeToJsModes = nativeToJsModes;
androidExec.setJsToNativeBridgeMode = function(mode) { androidExec.setJsToNativeBridgeMode = function (mode) {
if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) { if (mode === jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
mode = jsToNativeModes.PROMPT; mode = jsToNativeModes.PROMPT;
} }
nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT); nativeApiProvider.setPreferPrompt(mode === jsToNativeModes.PROMPT);
jsToNativeBridgeMode = mode; jsToNativeBridgeMode = mode;
}; };
androidExec.setNativeToJsBridgeMode = function(mode) { androidExec.setNativeToJsBridgeMode = function (mode) {
if (mode == nativeToJsBridgeMode) { if (mode === nativeToJsBridgeMode) {
return; return;
} }
if (nativeToJsBridgeMode == nativeToJsModes.POLLING) { if (nativeToJsBridgeMode === nativeToJsModes.POLLING) {
pollEnabled = false; pollEnabled = false;
} }
@ -1073,32 +1077,32 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode); nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode);
} }
if (mode == nativeToJsModes.POLLING) { if (mode === nativeToJsModes.POLLING) {
pollEnabled = true; pollEnabled = true;
setTimeout(pollingTimerFunc, 1); setTimeout(pollingTimerFunc, 1);
} }
}; };
function buildPayload(payload, message) { function buildPayload (payload, message) {
var payloadKind = message.charAt(0); var payloadKind = message.charAt(0);
if (payloadKind == 's') { if (payloadKind === 's') {
payload.push(message.slice(1)); payload.push(message.slice(1));
} else if (payloadKind == 't') { } else if (payloadKind === 't') {
payload.push(true); payload.push(true);
} else if (payloadKind == 'f') { } else if (payloadKind === 'f') {
payload.push(false); payload.push(false);
} else if (payloadKind == 'N') { } else if (payloadKind === 'N') {
payload.push(null); payload.push(null);
} else if (payloadKind == 'n') { } else if (payloadKind === 'n') {
payload.push(+message.slice(1)); payload.push(+message.slice(1));
} else if (payloadKind == 'A') { } else if (payloadKind === 'A') {
var data = message.slice(1); var data = message.slice(1);
payload.push(base64.toArrayBuffer(data)); payload.push(base64.toArrayBuffer(data));
} else if (payloadKind == 'S') { } else if (payloadKind === 'S') {
payload.push(window.atob(message.slice(1))); payload.push(window.atob(message.slice(1)));
} else if (payloadKind == 'M') { } else if (payloadKind === 'M') {
var multipartMessages = message.slice(1); var multipartMessages = message.slice(1);
while (multipartMessages !== "") { while (multipartMessages !== '') {
var spaceIdx = multipartMessages.indexOf(' '); var spaceIdx = multipartMessages.indexOf(' ');
var msgLen = +multipartMessages.slice(0, spaceIdx); var msgLen = +multipartMessages.slice(0, spaceIdx);
var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen); var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen);
@ -1111,14 +1115,15 @@ 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) {
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. // This is deprecated on the .java side. It doesn't work with CSP enabled.
// eslint-disable-next-line no-eval
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);
@ -1128,11 +1133,11 @@ function processMessage(message) {
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));
} }
} }
function processMessages() { function processMessages () {
// Check for the reentrant case. // Check for the reentrant case.
if (isProcessing) { if (isProcessing) {
return; return;
@ -1145,7 +1150,7 @@ function processMessages() {
var msg = popMessageFromQueue(); var msg = popMessageFromQueue();
// The Java side can send a * message to indicate that it // The Java side can send a * message to indicate that it
// still has messages waiting to be retrieved. // still has messages waiting to be retrieved.
if (msg == '*' && messagesFromNative.length === 0) { if (msg === '*' && messagesFromNative.length === 0) {
nextTick(pollOnce); nextTick(pollOnce);
return; return;
} }
@ -1158,9 +1163,9 @@ function processMessages() {
} }
} }
function popMessageFromQueue() { function popMessageFromQueue () {
var messageBatch = messagesFromNative.shift(); var messageBatch = messagesFromNative.shift();
if (messageBatch == '*') { if (messageBatch === '*') {
return '*'; return '*';
} }
@ -1216,7 +1221,6 @@ var cordova = require('cordova');
var modulemapper = require('cordova/modulemapper'); var modulemapper = require('cordova/modulemapper');
var platform = require('cordova/platform'); var platform = require('cordova/platform');
var pluginloader = require('cordova/pluginloader'); var pluginloader = require('cordova/pluginloader');
var utils = require('cordova/utils');
var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady]; var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
@ -1236,34 +1240,6 @@ window.setTimeout(function () {
} }
}, 5000); }, 5000);
// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
// We replace it so that properties that can't be clobbered can instead be overridden.
function replaceNavigator (origNavigator) {
var CordovaNavigator = function () {};
CordovaNavigator.prototype = origNavigator;
var newNavigator = new CordovaNavigator();
// This work-around really only applies to new APIs that are newer than Function.bind.
// Without it, APIs such as getGamepads() break.
if (CordovaNavigator.bind) {
for (var key in origNavigator) {
if (typeof origNavigator[key] === 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
} else {
(function (k) {
utils.defineGetterSetter(newNavigator, key, function () {
return origNavigator[k];
});
})(key);
}
}
}
return newNavigator;
}
if (window.navigator) {
window.navigator = replaceNavigator(window.navigator);
}
if (!window.console) { if (!window.console) {
window.console = { window.console = {
log: function () {} log: function () {}
@ -1329,7 +1305,6 @@ channel.join(function () {
channel.join(function () { channel.join(function () {
require('cordova').fireDocumentEvent('deviceready'); require('cordova').fireDocumentEvent('deviceready');
}, channel.deviceReadyChannelsArray); }, channel.deviceReadyChannelsArray);
}, platformInitChannelsArray); }, platformInitChannelsArray);
}); });
@ -1338,7 +1313,7 @@ channel.join(function () {
define("cordova/modulemapper", function(require, exports, module) { define("cordova/modulemapper", function(require, exports, module) {
var builder = require('cordova/builder'); var builder = require('cordova/builder');
var moduleMap = define.moduleMap; // eslint-disable-line no-undef var moduleMap = define.moduleMap;
var symbolList; var symbolList;
var deprecationMap; var deprecationMap;
@ -1378,12 +1353,9 @@ function prepareNamespace (symbolPath, context) {
if (!symbolPath) { if (!symbolPath) {
return context; return context;
} }
var parts = symbolPath.split('.'); return symbolPath.split('.').reduce(function (cur, part) {
var cur = context; return (cur[part] = cur[part] || {});
for (var i = 0, part; part = parts[i]; ++i) { // eslint-disable-line no-cond-assign }, context);
cur = cur[part] = cur[part] || {};
}
return cur;
} }
exports.mapModules = function (context) { exports.mapModules = function (context) {
@ -1442,11 +1414,11 @@ var lastResumeEvent = null;
module.exports = { module.exports = {
id: 'android', id: 'android',
bootstrap: function() { bootstrap: function () {
var channel = require('cordova/channel'), var channel = require('cordova/channel');
cordova = require('cordova'), var cordova = require('cordova');
exec = require('cordova/exec'), var exec = require('cordova/exec');
modulemapper = require('cordova/modulemapper'); var modulemapper = require('cordova/modulemapper');
// Get the shared secret needed to use the bridge. // Get the shared secret needed to use the bridge.
exec.init(); exec.init();
@ -1458,21 +1430,21 @@ module.exports = {
// Inject a listener for the backbutton on the document. // Inject a listener for the backbutton on the document.
var backButtonChannel = cordova.addDocumentEventHandler('backbutton'); var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
backButtonChannel.onHasSubscribersChange = function() { backButtonChannel.onHasSubscribersChange = function () {
// If we just attached the first handler or detached the last handler, // If we just attached the first handler or detached the last handler,
// let native know we need to override the back button. // let native know we need to override the back button.
exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [this.numHandlers == 1]); exec(null, null, APP_PLUGIN_NAME, 'overrideBackbutton', [this.numHandlers === 1]);
}; };
// Add hardware MENU and SEARCH button handlers // Add hardware MENU and SEARCH button handlers
cordova.addDocumentEventHandler('menubutton'); cordova.addDocumentEventHandler('menubutton');
cordova.addDocumentEventHandler('searchbutton'); cordova.addDocumentEventHandler('searchbutton');
function bindButtonChannel(buttonName) { function bindButtonChannel (buttonName) {
// generic button bind used for volumeup/volumedown buttons // generic button bind used for volumeup/volumedown buttons
var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button'); var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
volumeButtonChannel.onHasSubscribersChange = function() { volumeButtonChannel.onHasSubscribersChange = function () {
exec(null, null, APP_PLUGIN_NAME, "overrideButton", [buttonName, this.numHandlers == 1]); exec(null, null, APP_PLUGIN_NAME, 'overrideButton', [buttonName, this.numHandlers === 1]);
}; };
} }
// Inject a listener for the volume buttons on the document. // Inject a listener for the volume buttons on the document.
@ -1484,7 +1456,7 @@ module.exports = {
// plugin result is delivered even after the event is fired (CB-10498) // plugin result is delivered even after the event is fired (CB-10498)
var cordovaAddEventListener = document.addEventListener; var cordovaAddEventListener = document.addEventListener;
document.addEventListener = function(evt, handler, capture) { document.addEventListener = function (evt, handler, capture) {
cordovaAddEventListener(evt, handler, capture); cordovaAddEventListener(evt, handler, capture);
if (evt === 'resume' && lastResumeEvent) { if (evt === 'resume' && lastResumeEvent) {
@ -1494,51 +1466,48 @@ module.exports = {
// Let native code know we are all done on the JS side. // Let native code know we are all done on the JS side.
// Native code will then un-hide the WebView. // Native code will then un-hide the WebView.
channel.onCordovaReady.subscribe(function() { channel.onCordovaReady.subscribe(function () {
exec(onMessageFromNative, null, APP_PLUGIN_NAME, 'messageChannel', []); exec(onMessageFromNative, null, APP_PLUGIN_NAME, 'messageChannel', []);
exec(null, null, APP_PLUGIN_NAME, "show", []); exec(null, null, APP_PLUGIN_NAME, 'show', []);
}); });
} }
}; };
function onMessageFromNative(msg) { function onMessageFromNative (msg) {
var cordova = require('cordova'); var cordova = require('cordova');
var action = msg.action; var action = msg.action;
switch (action) switch (action) {
{ // pause and resume are Android app life cycle events
// Button events case 'backbutton':
case 'backbutton': case 'menubutton':
case 'menubutton': case 'searchbutton':
case 'searchbutton': case 'pause':
// App life cycle events case 'volumedownbutton':
case 'pause': case 'volumeupbutton':
// Volume events cordova.fireDocumentEvent(action);
case 'volumedownbutton': break;
case 'volumeupbutton': case 'resume':
cordova.fireDocumentEvent(action); if (arguments.length > 1 && msg.pendingResult) {
break; if (arguments.length === 2) {
case 'resume': msg.pendingResult.result = arguments[1];
if(arguments.length > 1 && msg.pendingResult) { } else {
if(arguments.length === 2) { // The plugin returned a multipart message
msg.pendingResult.result = arguments[1]; var res = [];
} else { for (var i = 1; i < arguments.length; i++) {
// The plugin returned a multipart message res.push(arguments[i]);
var res = [];
for(var i = 1; i < arguments.length; i++) {
res.push(arguments[i]);
}
msg.pendingResult.result = res;
} }
msg.pendingResult.result = res;
// Save the plugin result so that it can be delivered to the js
// even if they miss the initial firing of the event
lastResumeEvent = msg;
} }
cordova.fireDocumentEvent(action, msg);
break; // Save the plugin result so that it can be delivered to the js
default: // even if they miss the initial firing of the event
throw new Error('Unknown event action ' + action); lastResumeEvent = msg;
}
cordova.fireDocumentEvent(action, msg);
break;
default:
throw new Error('Unknown event action ' + action);
} }
} }
@ -1554,8 +1523,8 @@ module.exports = {
/** /**
* Clear the resource cache. * Clear the resource cache.
*/ */
clearCache:function() { clearCache: function () {
exec(null, null, APP_PLUGIN_NAME, "clearCache", []); exec(null, null, APP_PLUGIN_NAME, 'clearCache', []);
}, },
/** /**
@ -1572,31 +1541,31 @@ module.exports = {
* Example: * Example:
* 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_PLUGIN_NAME, "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_PLUGIN_NAME, "cancelLoadUrl", []); exec(null, null, APP_PLUGIN_NAME, 'cancelLoadUrl', []);
}, },
/** /**
* Clear web history in this web view. * Clear web history in this web view.
* 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_PLUGIN_NAME, "clearHistory", []); exec(null, null, APP_PLUGIN_NAME, 'clearHistory', []);
}, },
/** /**
* Go to previous page displayed. * Go to previous page displayed.
* 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_PLUGIN_NAME, "backHistory", []); exec(null, null, APP_PLUGIN_NAME, 'backHistory', []);
}, },
/** /**
@ -1608,8 +1577,8 @@ 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_PLUGIN_NAME, "overrideBackbutton", [override]); exec(null, null, APP_PLUGIN_NAME, 'overrideBackbutton', [override]);
}, },
/** /**
@ -1623,15 +1592,15 @@ module.exports = {
* @param button volumeup, volumedown * @param button volumeup, volumedown
* @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_PLUGIN_NAME, "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_PLUGIN_NAME, "exitApp", []); return exec(null, null, APP_PLUGIN_NAME, 'exitApp', []);
} }
}; };
@ -1656,11 +1625,11 @@ exports.injectScript = function (url, onload, onerror) {
function injectIfNecessary (id, url, onload, onerror) { function injectIfNecessary (id, url, onload, onerror) {
onerror = onerror || onload; onerror = onerror || onload;
if (id in define.moduleMap) { // eslint-disable-line no-undef if (id in define.moduleMap) {
onload(); onload();
} else { } else {
exports.injectScript(url, function () { exports.injectScript(url, function () {
if (id in define.moduleMap) { // eslint-disable-line no-undef if (id in define.moduleMap) {
onload(); onload();
} else { } else {
onerror(); onerror();
@ -1671,7 +1640,7 @@ function injectIfNecessary (id, url, onload, onerror) {
function onScriptLoadingComplete (moduleList, finishPluginLoading) { function onScriptLoadingComplete (moduleList, finishPluginLoading) {
// Loop through all the plugins and then through their clobbers and merges. // Loop through all the plugins and then through their clobbers and merges.
for (var i = 0, module; module = moduleList[i]; i++) { // eslint-disable-line no-cond-assign for (var i = 0, module; (module = moduleList[i]); i++) {
if (module.clobbers && module.clobbers.length) { if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) { for (var j = 0; j < module.clobbers.length; j++) {
modulemapper.clobbers(module.id, module.clobbers[j]); modulemapper.clobbers(module.id, module.clobbers[j]);
@ -1854,10 +1823,11 @@ utils.clone = function (obj) {
retVal = {}; retVal = {};
for (i in obj) { for (i in obj) {
// https://issues.apache.org/jira/browse/CB-11522 'unknown' type may be returned in // 'unknown' type may be returned in custom protocol activation case on
// custom protocol activation case on Windows Phone 8.1 causing "No such interface supported" exception // Windows Phone 8.1 causing "No such interface supported" exception on
// on cloning. // cloning (https://issues.apache.org/jira/browse/CB-11522)
if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') { // eslint-disable-line valid-typeof // eslint-disable-next-line valid-typeof
if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') {
retVal[i] = utils.clone(obj[i]); retVal[i] = utils.clone(obj[i]);
} }
} }
@ -1907,7 +1877,6 @@ utils.extend = (function () {
var F = function () {}; var F = function () {};
// extend Child from Parent // extend Child from Parent
return function (Child, Parent) { return function (Child, Parent) {
F.prototype = Parent.prototype; F.prototype = Parent.prototype;
Child.prototype = new F(); Child.prototype = new F();
Child.__super__ = Parent.prototype; Child.__super__ = Parent.prototype;