From bdecdea568f6bada0a68c8fb333b8bdc2f50ace8 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 22 Oct 2013 15:45:38 -0400 Subject: [PATCH] Update JS snapshot and VERSION to 2.9.1-dev --- VERSION | 2 +- framework/assets/www/cordova.js | 661 +++++++++++-------- framework/src/org/apache/cordova/Device.java | 2 +- 3 files changed, 372 insertions(+), 293 deletions(-) diff --git a/VERSION b/VERSION index c8e38b61..ee57e1e6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.9.0 +2.9.1-dev diff --git a/framework/assets/www/cordova.js b/framework/assets/www/cordova.js index 873c0682..05a64e0d 100644 --- a/framework/assets/www/cordova.js +++ b/framework/assets/www/cordova.js @@ -1,5 +1,5 @@ // Platform: android -// 2.9.0-0-g83dc4bd +// 2.9.1-dev-af4bcf4 /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -19,7 +19,7 @@ under the License. */ ;(function() { -var CORDOVA_JS_BUILD_LABEL = '2.9.0-0-g83dc4bd'; +var CORDOVA_JS_BUILD_LABEL = '2.9.1-dev-af4bcf4'; // file: lib/scripts/require.js var require, @@ -100,6 +100,7 @@ define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); +var platform = require('cordova/platform'); /** * Listen for DOMContentLoaded and notify our channel subscribers. @@ -182,10 +183,18 @@ if(typeof window.console === "undefined") { log:function(){} }; } +// there are places in the framework where we call `warn` also, so we should make sure it exists +if(typeof window.console.warn === "undefined") { + window.console.warn = function(msg) { + this.log("warn: " + msg); + }; +} var cordova = { define:define, require:require, + version:CORDOVA_JS_BUILD_LABEL, + platformId:platform.id, /** * Methods to add/remove your own addEventListener hijacking on document + window. */ @@ -221,16 +230,16 @@ var cordova = { var evt = createEvent(type, data); if (typeof documentEventHandlers[type] != 'undefined') { if( bNoDetach ) { - documentEventHandlers[type].fire(evt); + documentEventHandlers[type].fire(evt); } else { - setTimeout(function() { - // Fire deviceready on listeners that were registered before cordova.js was loaded. - if (type == 'deviceready') { - document.dispatchEvent(evt); - } - documentEventHandlers[type].fire(evt); - }, 0); + setTimeout(function() { + // Fire deviceready on listeners that were registered before cordova.js was loaded. + if (type == 'deviceready') { + document.dispatchEvent(evt); + } + documentEventHandlers[type].fire(evt); + }, 0); } } else { document.dispatchEvent(evt); @@ -347,7 +356,7 @@ var typeMap = { }; function extractParamName(callee, argIndex) { - return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex]; + return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex]; } function checkArgs(spec, functionName, args, opt_callee) { @@ -376,7 +385,7 @@ function checkArgs(spec, functionName, args, opt_callee) { if (errMsg) { errMsg += ', but got ' + typeName + '.'; errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg; - // Don't log when running jake test. + // Don't log when running unit tests. if (typeof jasmine == 'undefined') { console.error(errMsg); } @@ -393,6 +402,62 @@ moduleExports.getValue = getValue; moduleExports.enableChecks = true; +}); + +// file: lib/common/base64.js +define("cordova/base64", function(require, exports, module) { + +var base64 = exports; + +base64.fromArrayBuffer = function(arrayBuffer) { + var array = new Uint8Array(arrayBuffer); + return uint8ToBase64(array); +}; + +//------------------------------------------------------------------------------ + +/* This code is based on the performance tests at http://jsperf.com/b64tests + * This 12-bit-at-a-time algorithm was the best performing version on all + * platforms tested. + */ + +var b64_6bit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +var b64_12bit; + +var b64_12bitTable = function() { + b64_12bit = []; + for (var i=0; i<64; i++) { + for (var j=0; j<64; j++) { + b64_12bit[i*64+j] = b64_6bit[i] + b64_6bit[j]; + } + } + b64_12bitTable = function() { return b64_12bit; }; + return b64_12bit; +}; + +function uint8ToBase64(rawData) { + var numBytes = rawData.byteLength; + var output=""; + var segment; + var table = b64_12bitTable(); + for (var i=0;i> 12]; + output += table[segment & 0xfff]; + } + if (numBytes - i == 2) { + segment = (rawData[i] << 16) + (rawData[i+1] << 8); + output += table[segment >> 12]; + output += b64_6bit[(segment & 0xfff) >> 6]; + output += '='; + } else if (numBytes - i == 1) { + segment = (rawData[i] << 16); + output += table[segment >> 12]; + output += '=='; + } + return output; +} + }); // file: lib/common/builder.js @@ -435,36 +500,36 @@ function assignOrWrapInDeprecateGetter(obj, key, value, message) { function include(parent, objects, clobber, merge) { each(objects, function (obj, key) { try { - var result = obj.path ? require(obj.path) : {}; + var result = obj.path ? require(obj.path) : {}; - if (clobber) { - // Clobber if it doesn't exist. - if (typeof parent[key] === 'undefined') { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); - } else if (typeof obj.path !== 'undefined') { - // If merging, merge properties onto parent, otherwise, clobber. - if (merge) { - recursiveMerge(parent[key], result); - } else { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); - } - } - result = parent[key]; - } else { - // Overwrite if not currently defined. - if (typeof parent[key] == 'undefined') { - assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + if (clobber) { + // Clobber if it doesn't exist. + if (typeof parent[key] === 'undefined') { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } else if (typeof obj.path !== 'undefined') { + // If merging, merge properties onto parent, otherwise, clobber. + if (merge) { + recursiveMerge(parent[key], result); + } else { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } + } + result = parent[key]; } else { - // Set result to what already exists, so we can build children into it if they exist. - result = parent[key]; + // Overwrite if not currently defined. + if (typeof parent[key] == 'undefined') { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } else { + // Set result to what already exists, so we can build children into it if they exist. + result = parent[key]; + } } - } - if (obj.children) { - include(result, obj.children, clobber, merge); - } + if (obj.children) { + include(result, obj.children, clobber, merge); + } } catch(e) { - utils.alert('Exception building cordova JS globals: ' + e + ' for key "' + key + '"'); + utils.alert('Exception building cordova JS globals: ' + e + ' for key "' + key + '"'); } }); } @@ -808,6 +873,7 @@ define("cordova/exec", function(require, exports, module) { var cordova = require('cordova'), nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'), utils = require('cordova/utils'), + base64 = require('cordova/base64'), jsToNativeModes = { PROMPT: 0, JS_OBJECT: 1, @@ -846,7 +912,7 @@ function androidExec(success, fail, service, action, args) { // Process any ArrayBuffers in the args into a string. for (var i = 0; i < args.length; i++) { if (utils.typeName(args[i]) == 'ArrayBuffer') { - args[i] = window.btoa(String.fromCharCode.apply(null, new Uint8Array(args[i]))); + args[i] = base64.fromArrayBuffer(args[i]); } } @@ -874,8 +940,12 @@ function androidExec(success, fail, service, action, args) { } } -function pollOnce() { - var msg = nativeApiProvider.get().retrieveJsMessages(); +function pollOnceFromOnlineEvent() { + pollOnce(true); +} + +function pollOnce(opt_fromOnlineEvent) { + var msg = nativeApiProvider.get().retrieveJsMessages(!!opt_fromOnlineEvent); androidExec.processMessages(msg); } @@ -894,8 +964,8 @@ function hookOnlineApis() { // It currently fires them only on document though, so we bridge them // to window here (while first listening for exec()-releated online/offline // events). - window.addEventListener('online', pollOnce, false); - window.addEventListener('offline', pollOnce, false); + window.addEventListener('online', pollOnceFromOnlineEvent, false); + window.addEventListener('offline', pollOnceFromOnlineEvent, false); cordova.addWindowEventHandler('online'); cordova.addWindowEventHandler('offline'); document.addEventListener('online', proxyEvent, false); @@ -1056,6 +1126,10 @@ exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) { addEntry('d', moduleName, symbolPath, opt_deprecationMessage); }; +exports.runs = function(moduleName) { + addEntry('r', moduleName, null); +}; + function prepareNamespace(symbolPath, context) { if (!symbolPath) { return context; @@ -1074,12 +1148,16 @@ exports.mapModules = function(context) { for (var i = 0, len = symbolList.length; i < len; i += 3) { var strategy = symbolList[i]; var moduleName = symbolList[i + 1]; + var module = require(moduleName); + // + if (strategy == 'r') { + continue; + } var symbolPath = symbolList[i + 2]; var lastDot = symbolPath.lastIndexOf('.'); var namespace = symbolPath.substr(0, lastDot); var lastName = symbolPath.substr(lastDot + 1); - var module = require(moduleName); var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null; var parentObj = prepareNamespace(namespace, context); var target = parentObj[lastName]; @@ -1928,6 +2006,7 @@ var exec = require('cordova/exec'), */ function DirectoryReader(path) { this.path = path || null; + this.hasReadEntries = false; } /** @@ -1937,6 +2016,12 @@ function DirectoryReader(path) { * @param {Function} errorCallback is called with a FileError */ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { + // If we've already read and passed on this directory's entries, return an empty list. + if (this.hasReadEntries) { + successCallback([]); + return; + } + var reader = this; var win = typeof successCallback !== 'function' ? null : function(result) { var retVal = []; for (var i=0; i wait msec before loading URL - * loadingDialog: "Title,Message" => display a native loading dialog - * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error - * clearHistory: boolean => clear webview history (default=false) - * openExternal: boolean => open in a new browser (default=false) - * - * Example: - * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000}); - */ - loadUrl:function(url, props) { - exec(null, null, "App", "loadUrl", [url, props]); - }, + /** + * Load the url into the webview or into new browser instance. + * + * @param url The URL to load + * @param props Properties that can be passed in to the activity: + * wait: int => wait msec before loading URL + * loadingDialog: "Title,Message" => display a native loading dialog + * loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error + * clearHistory: boolean => clear webview history (default=false) + * openExternal: boolean => open in a new browser (default=false) + * + * Example: + * navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000}); + */ + loadUrl:function(url, props) { + exec(null, null, "App", "loadUrl", [url, props]); + }, - /** - * Cancel loadUrl that is waiting to be loaded. - */ - cancelLoadUrl:function() { - exec(null, null, "App", "cancelLoadUrl", []); - }, + /** + * Cancel loadUrl that is waiting to be loaded. + */ + cancelLoadUrl:function() { + exec(null, null, "App", "cancelLoadUrl", []); + }, - /** - * Clear web history in this web view. - * Instead of BACK button loading the previous web page, it will exit the app. - */ - clearHistory:function() { - exec(null, null, "App", "clearHistory", []); - }, + /** + * Clear web history in this web view. + * Instead of BACK button loading the previous web page, it will exit the app. + */ + clearHistory:function() { + exec(null, null, "App", "clearHistory", []); + }, - /** - * Go to previous page displayed. - * This is the same as pressing the backbutton on Android device. - */ - backHistory:function() { - exec(null, null, "App", "backHistory", []); - }, + /** + * Go to previous page displayed. + * This is the same as pressing the backbutton on Android device. + */ + backHistory:function() { + exec(null, null, "App", "backHistory", []); + }, - /** - * Override the default behavior of the Android back button. - * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired. - * - * Note: The user should not have to call this method. Instead, when the user - * registers for the "backbutton" event, this is automatically done. - * - * @param override T=override, F=cancel override - */ - overrideBackbutton:function(override) { - exec(null, null, "App", "overrideBackbutton", [override]); - }, + /** + * Override the default behavior of the Android back button. + * If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired. + * + * Note: The user should not have to call this method. Instead, when the user + * registers for the "backbutton" event, this is automatically done. + * + * @param override T=override, F=cancel override + */ + overrideBackbutton:function(override) { + exec(null, null, "App", "overrideBackbutton", [override]); + }, - /** - * Exit and terminate the application. - */ - exitApp:function() { - return exec(null, null, "App", "exitApp", []); - } + /** + * Exit and terminate the application. + */ + exitApp:function() { + return exec(null, null, "App", "exitApp", []); + } }; }); @@ -4186,8 +4279,8 @@ module.exports = { setNativeToJsBridgeMode: function(value) { prompt(value, 'gap_bridge_mode:'); }, - retrieveJsMessages: function() { - return prompt('', 'gap_poll:'); + retrieveJsMessages: function(fromOnlineEvent) { + return prompt(+fromOnlineEvent, 'gap_poll:'); } }; @@ -4482,9 +4575,9 @@ var DroidDB_openDatabase = function(name, version, display_name, size) { module.exports = { - openDatabase:DroidDB_openDatabase, - failQuery:failQuery, - completeQuery:completeQuery + openDatabase:DroidDB_openDatabase, + failQuery:failQuery, + completeQuery:completeQuery }; }); @@ -6515,6 +6608,127 @@ var modulemapper = require('cordova/modulemapper'); modulemapper.clobbers('cordova/plugin/splashscreen', 'navigator.splashscreen'); +}); + +// file: lib/common/pluginloader.js +define("cordova/pluginloader", function(require, exports, module) { + +var channel = require('cordova/channel'); +var modulemapper = require('cordova/modulemapper'); + +// Helper function to inject a