Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E202AF582 for ; Mon, 25 Mar 2013 21:21:34 +0000 (UTC) Received: (qmail 76184 invoked by uid 500); 25 Mar 2013 21:21:34 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 76153 invoked by uid 500); 25 Mar 2013 21:21:34 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 76135 invoked by uid 99); 25 Mar 2013 21:21:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Mar 2013 21:21:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 807E18203B7; Mon, 25 Mar 2013 21:21:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hermwong@apache.org To: commits@cordova.apache.org Date: Mon, 25 Mar 2013 21:21:35 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/4] update cordova.js libs to 2.6.0 http://git-wip-us.apache.org/repos/asf/cordova-webos/blob/8124a94e/lib/cordova.webos.js ---------------------------------------------------------------------- diff --git a/lib/cordova.webos.js b/lib/cordova.webos.js index da2986a..614b1fa 100644 --- a/lib/cordova.webos.js +++ b/lib/cordova.webos.js @@ -1,8 +1,8 @@ // Platform: webos -// commit 6b1ca4e5e6db2525cfa4d0de41306d9edf61642b +// commit bbf1562d4934b1331ffb263424b6ae054cedeb71 -// File generated at :: Wed Feb 27 2013 10:55:38 GMT-0800 (PST) +// File generated at :: Thu Mar 21 2013 14:40:07 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -725,7 +725,6 @@ channel.createSticky('onCordovaInfoReady'); channel.createSticky('onCordovaConnectionReady'); // Event to indicate that all automatically loaded JS plugins are loaded and ready. -// This is used in conjunction with the automatic plugin JS loading CLI prototype. channel.createSticky('onPluginsReady'); // Event to indicate that Cordova is ready @@ -934,6 +933,13 @@ module.exports = { var modulemapper = require('cordova/modulemapper'); modulemapper.loadMatchingModules(/cordova.*\/symbols$/); + + modulemapper.merges('cordova/plugin/webos/service', 'navigator.service'); + modulemapper.merges('cordova/plugin/webos/application', 'navigator.application'); + modulemapper.merges('cordova/plugin/webos/window', 'navigator.window'); + modulemapper.merges('cordova/plugin/webos/orientation', 'navigator.orientation'); + modulemapper.merges('cordova/plugin/webos/keyboard', 'navigator.keyboard'); + modulemapper.mapModules(window); if (window.PalmSystem) { @@ -1005,27 +1011,6 @@ module.exports = { }); }); - }, - merges: { - navigator: { - children: { - service: { - path: "cordova/plugin/webos/service" - }, - application: { - path: "cordova/plugin/webos/application" - }, - window: { - path: "cordova/plugin/webos/window" - }, - orientation: { - path: "cordova/plugin/webos/orientation" - }, - keyboard: { - path: "cordova/plugin/webos/keyboard" - } - } - } } }; @@ -1086,9 +1071,10 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { var correctOrientation = !!options.correctOrientation; var saveToPhotoAlbum = !!options.saveToPhotoAlbum; var popoverOptions = getValue(options.popoverOptions, null); + var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK); var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, - mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions]; + mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection]; exec(successCallback, errorCallback, "Camera", "takePicture", args); return new CameraPopoverHandle(); @@ -1131,6 +1117,10 @@ module.exports = { ARROW_LEFT : 4, ARROW_RIGHT : 8, ARROW_ANY : 15 + }, + Direction:{ + BACK: 0, + FRONT: 1 } }; @@ -2322,14 +2312,7 @@ FileReader.prototype.readAsText = function(file, encoding) { // Default encoding is UTF-8 var enc = encoding ? encoding : "UTF-8"; var me = this; - var execArgs = [this._fileName, enc]; - - // Maybe add slice parameters. - if (file.end < file.size) { - execArgs.push(file.start, file.end); - } else if (file.start > 0) { - execArgs.push(file.start); - } + var execArgs = [this._fileName, enc, file.start, file.end]; // Read file exec( @@ -2398,14 +2381,7 @@ FileReader.prototype.readAsDataURL = function(file) { } var me = this; - var execArgs = [this._fileName]; - - // Maybe add slice parameters. - if (file.end < file.size) { - execArgs.push(file.start, file.end); - } else if (file.start > 0) { - execArgs.push(file.start); - } + var execArgs = [this._fileName, file.start, file.end]; // Read file exec( @@ -2468,9 +2444,59 @@ FileReader.prototype.readAsBinaryString = function(file) { if (initRead(this, file)) { return this._realReader.readAsBinaryString(file); } - // TODO - Can't return binary data to browser. - console.log('method "readAsBinaryString" is not supported at this time.'); - this.abort(); + + var me = this; + var execArgs = [this._fileName, file.start, file.end]; + + // Read file + exec( + // Success callback + function(r) { + // If DONE (cancelled), then don't do anything + if (me._readyState === FileReader.DONE) { + return; + } + + // DONE state + me._readyState = FileReader.DONE; + + me._result = r; + + // If onload callback + if (typeof me.onload === "function") { + me.onload(new ProgressEvent("load", {target:me})); + } + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + }, + // Error callback + function(e) { + // If DONE (cancelled), then don't do anything + if (me._readyState === FileReader.DONE) { + return; + } + + // DONE state + me._readyState = FileReader.DONE; + + me._result = null; + + // Save error + me._error = new FileError(e); + + // If onerror callback + if (typeof me.onerror === "function") { + me.onerror(new ProgressEvent("error", {target:me})); + } + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + }, "File", "readAsBinaryString", execArgs); }; /** @@ -2482,9 +2508,59 @@ FileReader.prototype.readAsArrayBuffer = function(file) { if (initRead(this, file)) { return this._realReader.readAsArrayBuffer(file); } - // TODO - Can't return binary data to browser. - console.log('This method is not supported at this time.'); - this.abort(); + + var me = this; + var execArgs = [this._fileName, file.start, file.end]; + + // Read file + exec( + // Success callback + function(r) { + // If DONE (cancelled), then don't do anything + if (me._readyState === FileReader.DONE) { + return; + } + + // DONE state + me._readyState = FileReader.DONE; + + me._result = r; + + // If onload callback + if (typeof me.onload === "function") { + me.onload(new ProgressEvent("load", {target:me})); + } + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + }, + // Error callback + function(e) { + // If DONE (cancelled), then don't do anything + if (me._readyState === FileReader.DONE) { + return; + } + + // DONE state + me._readyState = FileReader.DONE; + + me._result = null; + + // Save error + me._error = new FileError(e); + + // If onerror callback + if (typeof me.onerror === "function") { + me.onerror(new ProgressEvent("error", {target:me})); + } + + // If onloadend callback + if (typeof me.onloadend === "function") { + me.onloadend(new ProgressEvent("loadend", {target:me})); + } + }, "File", "readAsArrayBuffer", execArgs); }; module.exports = FileReader; @@ -2530,6 +2606,38 @@ function newProgressEvent(result) { return pe; } +function getBasicAuthHeader(urlString) { + var header = null; + + if (window.btoa) { + // parse the url using the Location object + var url = document.createElement('a'); + url.href = urlString; + + var credentials = null; + var protocol = url.protocol + "//"; + var origin = protocol + url.host; + + // check whether there are the username:password credentials in the url + if (url.href.indexOf(origin) != 0) { // credentials found + var atIndex = url.href.indexOf("@"); + credentials = url.href.substring(protocol.length, atIndex); + } + + if (credentials) { + var authHeader = "Authorization"; + var authHeaderValue = "Basic " + window.btoa(credentials); + + header = { + name : authHeader, + value : authHeaderValue + }; + } + } + + return header; +} + var idCounter = 0; /** @@ -2560,6 +2668,18 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro var params = null; var chunkedMode = true; var headers = null; + + var basicAuthHeader = getBasicAuthHeader(server); + if (basicAuthHeader) { + if (!options) { + options = new FileUploadOptions(); + } + if (!options.headers) { + options.headers = {}; + } + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + if (options) { fileKey = options.fileKey; fileName = options.fileName; @@ -2601,10 +2721,28 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro * @param successCallback (Function} Callback to be invoked when upload has completed * @param errorCallback {Function} Callback to be invoked upon error * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false + * @param options {FileDownloadOptions} Optional parameters such as headers */ -FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts) { +FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) { argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments); var self = this; + + var basicAuthHeader = getBasicAuthHeader(source); + if (basicAuthHeader) { + if (!options) { + options = {}; + } + if (!options.headers) { + options.headers = {}; + } + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + + var headers = null; + if (options) { + headers = options.headers || null; + } + var win = function(result) { if (typeof result.lengthComputable != "undefined") { if (self.onprogress) { @@ -2631,7 +2769,7 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro errorCallback(error); }; - exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]); + exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]); }; /** @@ -3029,6 +3167,7 @@ function InAppBrowser() { this.channels = { 'loadstart': channel.create('loadstart'), 'loadstop' : channel.create('loadstop'), + 'loaderror' : channel.create('loaderror'), 'exit' : channel.create('exit') }; } @@ -3059,7 +3198,7 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) { var cb = function(eventname) { iab._eventHandler(eventname); }; - exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); + exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); return iab; }; @@ -5282,6 +5421,7 @@ modulemapper.defaults('cordova/plugin/Connection', 'Connection'); define("cordova/plugin/notification", function(require, exports, module) { var exec = require('cordova/exec'); +var platform = require('cordova/platform'); /** * Provides access to notifications on the device. @@ -5310,15 +5450,53 @@ module.exports = { * @param {String} message Message to print in the body of the alert * @param {Function} resultCallback The callback that is called when user clicks on a button. * @param {String} title Title of the alert dialog (default: Confirm) - * @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel') + * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) */ confirm: function(message, resultCallback, title, buttonLabels) { var _title = (title || "Confirm"); - var _buttonLabels = (buttonLabels || "OK,Cancel"); + var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); + + // Strings are deprecated! + if (typeof _buttonLabels === 'string') { + 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. + // Other platforms take a comma separated list. + // For compatibility, we convert to the desired type based on the platform. + if (platform.id == "android" || platform.id == "ios") { + if (typeof _buttonLabels === 'string') { + var buttonLabelString = _buttonLabels; + _buttonLabels = buttonLabelString.split(","); + } + } else { + if (Array.isArray(_buttonLabels)) { + var buttonLabelArray = _buttonLabels; + _buttonLabels = buttonLabelArray.toString(); + } + } exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); }, /** + * Open a native prompt dialog, with a customizable title and button text. + * The following results are returned to the result callback: + * buttonIndex Index number of the button selected. + * input1 The text entered in the prompt dialog box. + * + * @param {String} message Dialog message to display (default: "Prompt message") + * @param {Function} resultCallback The callback that is called when user clicks on a button. + * @param {String} title Title of the dialog (default: "Prompt") + * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) + */ + prompt: function(message, resultCallback, title, buttonLabels) { + var _message = (message || "Prompt message"); + var _title = (title || "Prompt"); + var _buttonLabels = (buttonLabels || ["OK","Cancel"]); + exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]); + }, + + /** * Causes the device to vibrate. * * @param {Integer} mills The number of milliseconds to vibrate for. @@ -6510,15 +6688,6 @@ window.cordova = require('cordova'); /** * Create all cordova objects once page has fully loaded and native side is ready. */ - var joinEvents = [ channel.onDOMContentLoaded, channel.onNativeReady ]; - - // If this property is set to something truthy, join on onPluginsReady too. - // This property is set by the automatic JS installation prototype in cordova-cli, - // and will be removed when the prototype either becomes mainline or is dropped. - if (window.__onPluginsLoadedHack) { - joinEvents.push(channel.onPluginsReady); - } - channel.join(function() { var builder = require('cordova/builder'), platform = require('cordova/platform'); @@ -6539,7 +6708,7 @@ window.cordova = require('cordova'); require('cordova').fireDocumentEvent('deviceready'); }, channel.deviceReadyChannelsArray); - }, joinEvents); + }, [ channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady ]); }(window)); @@ -6547,5 +6716,105 @@ window.cordova = require('cordova'); require('cordova/channel').onNativeReady.fire(); +// file: lib/scripts/plugin_loader.js + +// Tries to load all plugins' js-modules. +// This is an async process, but onDeviceReady is blocked on onPluginsReady. +// onPluginsReady is fired when there are no plugins to load, or they are all done. +(function (context) { + // To be populated with the handler by handlePluginsObject. + var onScriptLoadingComplete; + + var scriptCounter = 0; + function scriptLoadedCallback() { + scriptCounter--; + if (scriptCounter === 0) { + onScriptLoadingComplete && onScriptLoadingComplete(); + } + } + + // Helper function to inject a