This commit is contained in:
Joe Bowser 2013-04-18 14:52:17 -07:00
commit 025676d6e7

View File

@ -1,8 +1,8 @@
// Platform: android // Platform: android
// commit 125dca530923a44a8f44f68f5e1970cbdd4e7faf // commit d0ffb852378ff018bac2f3b12c38098a19b8ce00
// File generated at :: Mon Apr 01 2013 13:28:03 GMT-0700 (PDT) // File generated at :: Thu Apr 18 2013 15:10:54 GMT-0400 (EDT)
/* /*
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one
@ -219,6 +219,10 @@ var cordova = {
} }
else { else {
setTimeout(function() { setTimeout(function() {
// Fire deviceready on listeners that were registered before cordova.js was loaded.
if (type == 'deviceready') {
document.dispatchEvent(evt);
}
documentEventHandlers[type].fire(evt); documentEventHandlers[type].fire(evt);
}, 0); }, 0);
} }
@ -742,6 +746,7 @@ channel.createSticky('onDestroy');
// Channels that must fire before "deviceready" is fired. // Channels that must fire before "deviceready" is fired.
channel.waitForInitialization('onCordovaReady'); channel.waitForInitialization('onCordovaReady');
channel.waitForInitialization('onCordovaConnectionReady'); channel.waitForInitialization('onCordovaConnectionReady');
channel.waitForInitialization('onDOMContentLoaded');
module.exports = channel; module.exports = channel;
@ -840,32 +845,27 @@ function androidExec(success, fail, service, action, args) {
} }
var callbackId = service + cordova.callbackId++, var callbackId = service + cordova.callbackId++,
argsJson = JSON.stringify(args), argsJson = JSON.stringify(args);
returnValue;
// TODO: Returning the payload of a synchronous call was deprecated in 2.2.0. if (success || fail) {
// Remove it after 6 months. cordova.callbacks[callbackId] = {success:success, fail:fail};
function captureReturnValue(value) {
returnValue = value;
success && success(value);
} }
cordova.callbacks[callbackId] = {success:captureReturnValue, fail:fail};
if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) { if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) {
window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson; window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson;
} else { } else {
var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson); var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson);
androidExec.processMessages(messages); // 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 (cordova.callbacks[callbackId]) { if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && messages === "@Null arguments.") {
if (success || fail) { androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
cordova.callbacks[callbackId].success = success; androidExec(success, fail, service, action, args);
androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
return;
} else { } else {
delete cordova.callbacks[callbackId]; androidExec.processMessages(messages);
} }
} }
return returnValue;
} }
function pollOnce() { function pollOnce() {
@ -981,30 +981,30 @@ function processMessage(message) {
androidExec.processMessages = function(messages) { androidExec.processMessages = function(messages) {
if (messages) { if (messages) {
messagesFromNative.push(messages); messagesFromNative.push(messages);
// Check for the reentrant case, and enqueue the message if that's the case.
if (messagesFromNative.length > 1) {
return;
}
while (messagesFromNative.length) { while (messagesFromNative.length) {
messages = messagesFromNative.shift(); // Don't unshift until the end so that reentrancy can be detected.
messages = messagesFromNative[0];
// 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.
// TODO(agrieve): This is currently disabled on the Java side
// since it breaks returning the result in exec of synchronous
// plugins. Once we remove this ability, we can remove this comment.
if (messages == '*') { if (messages == '*') {
messagesFromNative.shift();
window.setTimeout(pollOnce, 0); window.setTimeout(pollOnce, 0);
continue; return;
} }
var spaceIdx = messages.indexOf(' '); var spaceIdx = messages.indexOf(' ');
var msgLen = +messages.slice(0, spaceIdx); var msgLen = +messages.slice(0, spaceIdx);
var message = messages.substr(spaceIdx + 1, msgLen); var message = messages.substr(spaceIdx + 1, msgLen);
messages = messages.slice(spaceIdx + msgLen + 1); messages = messages.slice(spaceIdx + msgLen + 1);
// Put the remaining messages back into queue in case an exec() processMessage(message);
// is made by the callback.
if (messages) { if (messages) {
messagesFromNative.unshift(messages); messagesFromNative[0] = messages;
} } else {
messagesFromNative.shift();
if (message) {
processMessage(message);
} }
} }
} }
@ -2398,7 +2398,7 @@ function initRead(reader, file) {
if (typeof file == 'string') { if (typeof file == 'string') {
// Deprecated in Cordova 2.4. // Deprecated in Cordova 2.4.
console.warning('Using a string argument with FileReader.readAs functions is deprecated.'); console.warn('Using a string argument with FileReader.readAs functions is deprecated.');
reader._fileName = file; reader._fileName = file;
} else if (typeof file.fullPath == 'string') { } else if (typeof file.fullPath == 'string') {
reader._fileName = file.fullPath; reader._fileName = file.fullPath;
@ -2756,7 +2756,7 @@ function getBasicAuthHeader(urlString) {
var origin = protocol + url.host; var origin = protocol + url.host;
// check whether there are the username:password credentials in the url // check whether there are the username:password credentials in the url
if (url.href.indexOf(origin) != 0) { // credentials found if (url.href.indexOf(origin) !== 0) { // credentials found
var atIndex = url.href.indexOf("@"); var atIndex = url.href.indexOf("@");
credentials = url.href.substring(protocol.length, atIndex); credentials = url.href.substring(protocol.length, atIndex);
} }
@ -2805,15 +2805,11 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
var params = null; var params = null;
var chunkedMode = true; var chunkedMode = true;
var headers = null; var headers = null;
var httpMethod = null;
var basicAuthHeader = getBasicAuthHeader(server); var basicAuthHeader = getBasicAuthHeader(server);
if (basicAuthHeader) { if (basicAuthHeader) {
if (!options) { options = options || {};
options = new FileUploadOptions(); options.headers = options.headers || {};
}
if (!options.headers) {
options.headers = {};
}
options.headers[basicAuthHeader.name] = basicAuthHeader.value; options.headers[basicAuthHeader.name] = basicAuthHeader.value;
} }
@ -2822,6 +2818,12 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
fileName = options.fileName; fileName = options.fileName;
mimeType = options.mimeType; mimeType = options.mimeType;
headers = options.headers; headers = options.headers;
httpMethod = options.httpMethod || "POST";
if (httpMethod.toUpperCase() == "PUT"){
httpMethod = "PUT";
} else {
httpMethod = "POST";
}
if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") { if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
chunkedMode = options.chunkedMode; chunkedMode = options.chunkedMode;
} }
@ -2848,7 +2850,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
successCallback && successCallback(result); successCallback && successCallback(result);
} }
}; };
exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id]); exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]);
}; };
/** /**
@ -2866,12 +2868,8 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
var basicAuthHeader = getBasicAuthHeader(source); var basicAuthHeader = getBasicAuthHeader(source);
if (basicAuthHeader) { if (basicAuthHeader) {
if (!options) { options = options || {};
options = {}; options.headers = options.headers || {};
}
if (!options.headers) {
options.headers = {};
}
options.headers[basicAuthHeader.name] = basicAuthHeader.value; options.headers[basicAuthHeader.name] = basicAuthHeader.value;
} }
@ -2910,12 +2908,11 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
}; };
/** /**
* Aborts the ongoing file transfer on this object * Aborts the ongoing file transfer on this object. The original error
* @param successCallback {Function} Callback to be invoked upon success * callback for the file transfer will be called if necessary.
* @param errorCallback {Function} Callback to be invoked upon error
*/ */
FileTransfer.prototype.abort = function(successCallback, errorCallback) { FileTransfer.prototype.abort = function() {
exec(successCallback, errorCallback, 'FileTransfer', 'abort', [this._id]); exec(null, null, 'FileTransfer', 'abort', [this._id]);
}; };
module.exports = FileTransfer; module.exports = FileTransfer;
@ -2959,12 +2956,13 @@ define("cordova/plugin/FileUploadOptions", function(require, exports, module) {
* @param headers {Object} Keys are header names, values are header values. Multiple * @param headers {Object} Keys are header names, values are header values. Multiple
* headers of the same name are not supported. * headers of the same name are not supported.
*/ */
var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers) { var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers, httpMethod) {
this.fileKey = fileKey || null; this.fileKey = fileKey || null;
this.fileName = fileName || null; this.fileName = fileName || null;
this.mimeType = mimeType || null; this.mimeType = mimeType || null;
this.params = params || null; this.params = params || null;
this.headers = headers || null; this.headers = headers || null;
this.httpMethod = httpMethod || null;
}; };
module.exports = FileUploadOptions; module.exports = FileUploadOptions;
@ -3299,6 +3297,7 @@ define("cordova/plugin/InAppBrowser", function(require, exports, module) {
var exec = require('cordova/exec'); var exec = require('cordova/exec');
var channel = require('cordova/channel'); var channel = require('cordova/channel');
var modulemapper = require('cordova/modulemapper');
function InAppBrowser() { function InAppBrowser() {
this.channels = { this.channels = {
@ -3327,6 +3326,26 @@ InAppBrowser.prototype = {
if (eventname in this.channels) { if (eventname in this.channels) {
this.channels[eventname].unsubscribe(f); this.channels[eventname].unsubscribe(f);
} }
},
executeScript: function(injectDetails, cb) {
if (injectDetails.code) {
exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]);
} else if (injectDetails.file) {
exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]);
} else {
throw new Error('executeScript requires exactly one of code or file to be specified');
}
},
insertCSS: function(injectDetails, cb) {
if (injectDetails.code) {
exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]);
} else if (injectDetails.file) {
exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]);
} else {
throw new Error('insertCSS requires exactly one of code or file to be specified');
}
} }
}; };
@ -3335,6 +3354,13 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) {
var cb = function(eventname) { var cb = function(eventname) {
iab._eventHandler(eventname); iab._eventHandler(eventname);
}; };
// Don't catch calls that write to existing frames (e.g. named iframes).
if (window.frames && window.frames[strWindowName]) {
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
return origOpenFunc.apply(window, arguments);
}
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return iab; return iab;
}; };
@ -4858,7 +4884,7 @@ console.debug = function() {
console.assert = function(expression) { console.assert = function(expression) {
if (expression) return; if (expression) return;
var message = utils.vformat(arguments[1], [].slice.call(arguments, 2)); var message = logger.format.apply(logger.format, [].slice.call(arguments, 1));
console.log("ASSERT: " + message); console.log("ASSERT: " + message);
}; };
@ -5958,10 +5984,10 @@ function logWithArgs(level, args) {
* Parameters passed after message are used applied to * Parameters passed after message are used applied to
* the message with utils.format() * the message with utils.format()
*/ */
logger.logLevel = function(level, message /* , ... */) { logger.logLevel = function(level /* , ... */) {
// format the message with the parameters // format the message with the parameters
var formatArgs = [].slice.call(arguments, 2); var formatArgs = [].slice.call(arguments, 1);
message = utils.vformat(message, formatArgs); var message = logger.format.apply(logger.format, formatArgs);
if (LevelsMap[level] === null) { if (LevelsMap[level] === null) {
throw new Error("invalid logging level: " + level); throw new Error("invalid logging level: " + level);
@ -5996,6 +6022,92 @@ logger.logLevel = function(level, message /* , ... */) {
} }
}; };
/**
* Formats a string and arguments following it ala console.log()
*
* Any remaining arguments will be appended to the formatted string.
*
* for rationale, see FireBug's Console API:
* http://getfirebug.com/wiki/index.php/Console_API
*/
logger.format = function(formatString, args) {
return __format(arguments[0], [].slice.call(arguments,1)).join(' ');
};
//------------------------------------------------------------------------------
/**
* Formats a string and arguments following it ala vsprintf()
*
* format chars:
* %j - format arg as JSON
* %o - format arg as JSON
* %c - format arg as ''
* %% - replace with '%'
* any other char following % will format it's
* arg via toString().
*
* Returns an array containing the formatted string and any remaining
* arguments.
*/
function __format(formatString, args) {
if (formatString === null || formatString === undefined) return [""];
if (arguments.length == 1) return [formatString.toString()];
if (typeof formatString != "string")
formatString = formatString.toString();
var pattern = /(.*?)%(.)(.*)/;
var rest = formatString;
var result = [];
while (args.length) {
var match = pattern.exec(rest);
if (!match) break;
var arg = args.shift();
rest = match[3];
result.push(match[1]);
if (match[2] == '%') {
result.push('%');
args.unshift(arg);
continue;
}
result.push(__formatted(arg, match[2]));
}
result.push(rest);
var remainingArgs = [].slice.call(args);
remainingArgs.unshift(result.join(''));
return remainingArgs;
}
function __formatted(object, formatChar) {
try {
switch(formatChar) {
case 'j':
case 'o': return JSON.stringify(object);
case 'c': return '';
}
}
catch (e) {
return "error JSON.stringify()ing argument: " + e;
}
if ((object === null) || (object === undefined)) {
return Object.prototype.toString.call(object);
}
return object.toString();
}
//------------------------------------------------------------------------------
// when deviceready fires, log queued messages // when deviceready fires, log queued messages
logger.__onDeviceReady = function() { logger.__onDeviceReady = function() {
if (DeviceReady) return; if (DeviceReady) return;
@ -6164,13 +6276,13 @@ module.exports = {
console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).");
} }
// Android and iOS take an array of button label names. // Some platforms take an array of button label names.
// Other platforms take a comma separated list. // Other platforms take a comma separated list.
// For compatibility, we convert to the desired type based on the platform. // For compatibility, we convert to the desired type based on the platform.
if (platform.id == "android" || platform.id == "ios") { if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone") {
if (typeof _buttonLabels === 'string') { if (typeof _buttonLabels === 'string') {
var buttonLabelString = _buttonLabels; var buttonLabelString = _buttonLabels;
_buttonLabels = buttonLabelString.split(","); _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here
} }
} else { } else {
if (Array.isArray(_buttonLabels)) { if (Array.isArray(_buttonLabels)) {
@ -6521,62 +6633,6 @@ utils.alert = function(msg) {
} }
}; };
/**
* Formats a string and arguments following it ala sprintf()
*
* see utils.vformat() for more information
*/
utils.format = function(formatString /* ,... */) {
var args = [].slice.call(arguments, 1);
return utils.vformat(formatString, args);
};
/**
* Formats a string and arguments following it ala vsprintf()
*
* format chars:
* %j - format arg as JSON
* %o - format arg as JSON
* %c - format arg as ''
* %% - replace with '%'
* any other char following % will format it's
* arg via toString().
*
* for rationale, see FireBug's Console API:
* http://getfirebug.com/wiki/index.php/Console_API
*/
utils.vformat = function(formatString, args) {
if (formatString === null || formatString === undefined) return "";
if (arguments.length == 1) return formatString.toString();
if (typeof formatString != "string") return formatString.toString();
var pattern = /(.*?)%(.)(.*)/;
var rest = formatString;
var result = [];
while (args.length) {
var arg = args.shift();
var match = pattern.exec(rest);
if (!match) break;
rest = match[3];
result.push(match[1]);
if (match[2] == '%') {
result.push('%');
args.unshift(arg);
continue;
}
result.push(formatted(arg, match[2]));
}
result.push(rest);
return result.join('');
};
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function UUIDcreatePart(length) { function UUIDcreatePart(length) {
@ -6591,26 +6647,6 @@ function UUIDcreatePart(length) {
return uuidpart; return uuidpart;
} }
//------------------------------------------------------------------------------
function formatted(object, formatChar) {
try {
switch(formatChar) {
case 'j':
case 'o': return JSON.stringify(object);
case 'c': return '';
}
}
catch (e) {
return "error JSON.stringify()ing argument: " + e;
}
if ((object === null) || (object === undefined)) {
return Object.prototype.toString.call(object);
}
return object.toString();
}
}); });
@ -6620,6 +6656,25 @@ window.cordova = require('cordova');
// file: lib/scripts/bootstrap.js // file: lib/scripts/bootstrap.js
(function (context) { (function (context) {
var channel = require('cordova/channel');
var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
function logUnfiredChannels(arr) {
for (var i = 0; i < arr.length; ++i) {
if (arr[i].state != 2) {
console.log('Channel not fired: ' + arr[i].type);
}
}
}
window.setTimeout(function() {
if (channel.onDeviceReady.state != 2) {
console.log('deviceready has not fired after 5 seconds.');
logUnfiredChannels(platformInitChannelsArray);
logUnfiredChannels(channel.deviceReadyChannelsArray);
}
}, 5000);
// Replace navigator before any modules are required(), to ensure it happens as soon as possible. // 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. // We replace it so that properties that can't be clobbered can instead be overridden.
function replaceNavigator(origNavigator) { function replaceNavigator(origNavigator) {
@ -6641,8 +6696,6 @@ window.cordova = require('cordova');
context.navigator = replaceNavigator(context.navigator); context.navigator = replaceNavigator(context.navigator);
} }
var channel = require("cordova/channel");
// _nativeReady is global variable that the native side can set // _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since // to signify that the native code is ready. It is a global since
// it may be called before any cordova JS is ready. // it may be called before any cordova JS is ready.
@ -6651,32 +6704,33 @@ window.cordova = require('cordova');
} }
/** /**
* Create all cordova objects once page has fully loaded and native side is ready. * Create all cordova objects once native side is ready.
*/ */
channel.join(function() { channel.join(function() {
var builder = require('cordova/builder'),
platform = require('cordova/platform');
builder.buildIntoButDoNotClobber(platform.defaults, context);
builder.buildIntoAndClobber(platform.clobbers, context);
builder.buildIntoAndMerge(platform.merges, context);
// Call the platform-specific initialization // Call the platform-specific initialization
platform.initialize(); require('cordova/platform').initialize();
// Fire event to notify that all objects are created // Fire event to notify that all objects are created
channel.onCordovaReady.fire(); channel.onCordovaReady.fire();
// Fire onDeviceReady event once all constructors have run and // Fire onDeviceReady event once page has fully loaded, all
// cordova info has been received from native side. // constructors have run and cordova info has been received from native
// side.
// This join call is deliberately made after platform.initialize() in
// order that plugins may manipulate channel.deviceReadyChannelsArray
// if necessary.
channel.join(function() { channel.join(function() {
require('cordova').fireDocumentEvent('deviceready'); require('cordova').fireDocumentEvent('deviceready');
}, channel.deviceReadyChannelsArray); }, channel.deviceReadyChannelsArray);
}, [ channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady ]); }, platformInitChannelsArray);
}(window)); }(window));
// file: lib/scripts/bootstrap-android.js
require('cordova/channel').onNativeReady.fire();
// file: lib/scripts/plugin_loader.js // file: lib/scripts/plugin_loader.js
// Tries to load all plugins' js-modules. // Tries to load all plugins' js-modules.
@ -6752,35 +6806,31 @@ window.cordova = require('cordova');
} }
} }
// Try to XHR the cordova_plugins.json file asynchronously.
try { // we commented we were going to try, so let us actually try and catch
var xhr = new context.XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState != 4) { // not DONE
return;
}
// Try to XHR the cordova_plugins.json file asynchronously.
try { // we commented we were going to try, so let us actually try and catch
var xhr = new context.XMLHttpRequest();
xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject. // If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading. // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
if (this.status == 200) { var obj = JSON.parse(this.responseText);
var obj = JSON.parse(this.responseText); if (obj && obj instanceof Array && obj.length > 0) {
if (obj && obj instanceof Array && obj.length > 0) { handlePluginsObject(obj);
handlePluginsObject(obj);
} else {
finishPluginLoading();
}
} else { } else {
finishPluginLoading(); finishPluginLoading();
} }
}; };
xhr.onerror = function() {
finishPluginLoading();
};
xhr.open('GET', 'cordova_plugins.json', true); // Async xhr.open('GET', 'cordova_plugins.json', true); // Async
xhr.send(); xhr.send();
} }
catch(err) { catch(err){
finishPluginLoading(); finishPluginLoading();
} }
}(window)); }(window));
})(); })();