incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject ios commit: Updated interim js (for exec method switching)
Date Fri, 17 Aug 2012 23:44:36 GMT
Updated Branches:
  refs/heads/master fdf804341 -> 2a43d7957


Updated interim js (for exec method switching)


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/2a43d795
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/2a43d795
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/2a43d795

Branch: refs/heads/master
Commit: 2a43d79573826ba3f1cef22304f6c26423c0dbc1
Parents: fdf8043
Author: Shazron Abdullah <shazron@apache.org>
Authored: Fri Aug 17 16:44:31 2012 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Fri Aug 17 16:44:31 2012 -0700

----------------------------------------------------------------------
 CordovaLib/javascript/cordova.ios.js |  132 +++++++++++++++++++++++------
 1 files changed, 104 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/2a43d795/CordovaLib/javascript/cordova.ios.js
----------------------------------------------------------------------
diff --git a/CordovaLib/javascript/cordova.ios.js b/CordovaLib/javascript/cordova.ios.js
index 26600b1..9cd7f70 100644
--- a/CordovaLib/javascript/cordova.ios.js
+++ b/CordovaLib/javascript/cordova.ios.js
@@ -1,6 +1,6 @@
-// commit 8c46a970a0719d0f16a225b75421ecf6f12dcc02
+// commit 3cd1e8438d90f1fb72ae6eac45d0dac3b0f6c6f6
 
-// File generated at :: Sun Jul 29 2012 14:26:58 GMT-0400 (EDT)
+// File generated at :: Fri Aug 17 2012 12:30:31 GMT-0700 (PDT)
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one
@@ -207,10 +207,6 @@ var cordova = {
             window.dispatchEvent(evt);
         }
     },
-    // TODO: this is Android only; think about how to do this better
-    shuttingDown:false,
-    UsePolling:false,
-    // END TODO
 
     // TODO: iOS only
     // This queue holds the currently executing command and all pending
@@ -883,20 +879,42 @@ define("cordova/exec", function(require, exports, module) {
      * @private
      */
 var cordova = require('cordova'),
+    channel = require('cordova/channel'),
+    nativecomm = require('cordova/plugin/ios/nativecomm'),
     utils = require('cordova/utils'),
-    gapBridge,
-    createGapBridge = function() {
-
-        gapBridge = document.createElement("iframe");
-        gapBridge.setAttribute("style", "display:none;");
-        gapBridge.setAttribute("height","0px");
-        gapBridge.setAttribute("width","0px");
-        gapBridge.setAttribute("frameborder","0");
-        document.documentElement.appendChild(gapBridge);
+    jsToNativeModes = {
+        IFRAME_NAV: 0,
+        XHR_NO_PAYLOAD: 1,
+        XHR_WITH_PAYLOAD: 2,
+        XHR_OPTIONAL_PAYLOAD: 3
     },
-    channel = require('cordova/channel');
+    bridgeMode = jsToNativeModes.IFRAME_NAV,
+    execIframe,
+    execXhr;
+
+function createExecIframe() {
+    var iframe = document.createElement("iframe");
+    iframe.style.display = 'none';
+    document.body.appendChild(iframe);
+    return iframe;
+}
 
-module.exports = function() {
+function shouldBundleCommandJson() {
+    if (bridgeMode == 2) {
+        return true;
+    }
+    if (bridgeMode == 3) {
+        var payloadLength = 0;
+        for (var i = 0; i < cordova.commandQueue.length; ++i) {
+            payloadLength += cordova.commandQueue[i].length;
+        }
+        // The value here was determined using the benchmark within CordovaLibApp on an iPad
3.
+        return payloadLength < 4500;
+    }
+    return false;
+}
+
+function iOSExec() {
     if (!channel.onCordovaReady.fired) {
         utils.alert("ERROR: Attempting to call cordova.exec()" +
               " before 'deviceready'. Ignoring.");
@@ -946,13 +964,40 @@ module.exports = function() {
     // commands to execute, unless the queue is currently being flushed, in
     // which case the command will be picked up without notification.
     if (cordova.commandQueue.length == 1 && !cordova.commandQueueFlushing) {
-        if (!gapBridge) {
-            createGapBridge();
+        if (bridgeMode) {
+            execXhr = execXhr || new XMLHttpRequest();
+            execXhr.open('HEAD', "file:///!gap_exec", true);
+            execXhr.setRequestHeader('vc', cordova.iOSVCAddr);
+            if (shouldBundleCommandJson()) {
+                execXhr.setRequestHeader('cmds', nativecomm());
+            }
+            execXhr.send(null);
+        } else {
+            execIframe = execIframe || createExecIframe();
+            execIframe.src = "gap://ready";
         }
-        gapBridge.src = "gap://ready";
     }
+}
+
+iOSExec.jsToNativeModes = jsToNativeModes;
+
+iOSExec.setJsToNativeBridgeMode = function(mode) {
+    // Remove the iFrame since it may be no longer required, and its existence
+    // can trigger browser bugs.
+    // https://issues.apache.org/jira/browse/CB-593
+    if (execIframe) {
+        execIframe.parentNode.removeChild(execIframe);
+        execIframe = null;
+    }
+    if (mode && !cordova.iOSVCAddr) {
+        alert('ViewController not correctly initialized for XHR mode.');
+        mode = 0;
+    }
+    bridgeMode = mode;
 };
 
+module.exports = iOSExec;
+
 });
 
 // file: lib/ios/platform.js
@@ -972,6 +1017,9 @@ module.exports = {
         File: { // exists natively, override
             path: "cordova/plugin/File"
         },
+        FileReader: { // exists natively, override
+            path: "cordova/plugin/FileReader"
+        },
         MediaError: { // exists natively, override
             path: "cordova/plugin/MediaError"
         },
@@ -2982,7 +3030,6 @@ Media.prototype.stop = function() {
     var me = this;
     exec(function() {
         me._position = 0;
-        me.successCallback();
     }, this.errorCallback, "Media", "stopPlayingAudio", [this.id]);
 };
 
@@ -3028,14 +3075,14 @@ Media.prototype.getCurrentPosition = function(success, fail) {
  * Start recording audio file.
  */
 Media.prototype.startRecord = function() {
-    exec(this.successCallback, this.errorCallback, "Media", "startRecordingAudio", [this.id,
this.src]);
+    exec(null, this.errorCallback, "Media", "startRecordingAudio", [this.id, this.src]);
 };
 
 /**
  * Stop recording audio file.
  */
 Media.prototype.stopRecord = function() {
-    exec(this.successCallback, this.errorCallback, "Media", "stopRecordingAudio", [this.id]);
+    exec(null, this.errorCallback, "Media", "stopRecordingAudio", [this.id]);
 };
 
 /**
@@ -3064,14 +3111,14 @@ Media.onStatus = function(id, msg, value) {
     var media = mediaObjects[id];
     // If state update
     if (msg === Media.MEDIA_STATE) {
+        if (media.statusCallback) {
+            media.statusCallback(value);
+        }
         if (value === Media.MEDIA_STOPPED) {
             if (media.successCallback) {
                 media.successCallback();
             }
         }
-        if (media.statusCallback) {
-            media.statusCallback(value);
-        }
     }
     else if (msg === Media.MEDIA_DURATION) {
         media._duration = value;
@@ -4030,6 +4077,25 @@ module.exports = new Device();
 
 });
 
+// file: lib/common/plugin/echo.js
+define("cordova/plugin/echo", function(require, exports, module) {
+var exec = require('cordova/exec');
+
+/**
+ * Sends the given message through exec() to the Echo plugink, which sends it back to the
successCallback.
+ * @param successCallback  invoked with a FileSystem object
+ * @param errorCallback  invoked if error occurs retrieving file system
+ * @param message  The string to be echoed.
+ * @param forceAsync  Whether to force an async return value (for testing native->js bridge).
+ */
+module.exports = function(successCallback, errorCallback, message, forceAsync) {
+    var action = forceAsync ? 'echoAsync' : 'echo';
+    exec(successCallback, errorCallback, "Echo", action, [message]);
+};
+
+
+});
+
 // file: lib/common/plugin/geolocation.js
 define("cordova/plugin/geolocation", function(require, exports, module) {
 var utils = require('cordova/utils'),
@@ -4478,10 +4544,20 @@ module.exports = {
          *    allowsEditing: boolean AS STRING
          *        "true" to allow editing the contact
          *        "false" (default) display contact
+         *      fields: array of fields to return in contact object (see ContactOptions.fields)
+         *
+         *    @returns
+         *        id of contact selected
+         *        ContactObject
+         *            if no fields provided contact contains just id information
+         *            if fields provided contact object contains information for the specified
fields
          *
-         * returns:  the id of the selected contact as param to successCallback
          */
-        exec(successCallback, null, "Contacts","chooseContact", [options]);
+         var win = function(result) {
+             var fullContact = require('cordova/plugin/contacts').create(result);
+            successCallback(fullContact.id, fullContact);
+       };
+        exec(win, null, "Contacts","chooseContact", [options]);
     }
 };
 });


Mime
View raw message