incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/14] android commit: Add a flag to disable exec() chaining for benchmarking.
Date Tue, 18 Sep 2012 17:52:50 GMT
Add a flag to disable exec() chaining for benchmarking.

- Also moved ENABLE_LOCATION_CHANGE_EXEC_MODE to NativeToJsMessageQueue
  so that all exec() related flags are in one place.


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

Branch: refs/heads/master
Commit: d3cbfd5467497b67bc631da9b1b5e0b064db7c7b
Parents: 9e3e7e1
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Sep 14 16:21:35 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Sep 18 13:24:38 2012 -0400

----------------------------------------------------------------------
 .../org/apache/cordova/CordovaWebViewClient.java   |    5 +----
 framework/src/org/apache/cordova/ExposedJsApi.java |    8 ++++++--
 .../org/apache/cordova/NativeToJsMessageQueue.java |   10 +++++++++-
 .../src/org/apache/cordova/api/PluginManager.java  |    8 +++++---
 4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3cbfd54/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index 8229cf7..fe0e9e9 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -54,9 +54,6 @@ import android.webkit.WebViewClient;
 public class CordovaWebViewClient extends WebViewClient {
 
 	private static final String TAG = "Cordova";
-	// Disable URL-based exec() bridge by default since it's a bit of a
-	// security concern.
-	private static boolean ENABLE_LOCATION_CHANGE_EXEC_MODE = false;
 	private static final String CORDOVA_EXEC_URL_PREFIX = "http://cdv_exec/";
     CordovaInterface cordova;
     CordovaWebView appView;
@@ -124,7 +121,7 @@ public class CordovaWebViewClient extends WebViewClient {
 	@Override
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
     	// Check if it's an exec() bridge command message.
-    	if (ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(CORDOVA_EXEC_URL_PREFIX))
{
+    	if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(CORDOVA_EXEC_URL_PREFIX))
{
     		handleExecUrl(url);
     	}
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3cbfd54/framework/src/org/apache/cordova/ExposedJsApi.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ExposedJsApi.java b/framework/src/org/apache/cordova/ExposedJsApi.java
index b96ec64..710b2e0 100755
--- a/framework/src/org/apache/cordova/ExposedJsApi.java
+++ b/framework/src/org/apache/cordova/ExposedJsApi.java
@@ -40,8 +40,12 @@ import org.json.JSONException;
     public String exec(String service, String action, String callbackId, String arguments)
throws JSONException {
         jsMessageQueue.setPaused(true);
         try {
-            pluginManager.exec(service, action, callbackId, arguments, true /* async */);
-            return jsMessageQueue.popAndEncode();
+            boolean wasSync = pluginManager.exec(service, action, callbackId, arguments,
true /* async */);
+            String ret = "";
+            if (!NativeToJsMessageQueue.DISABLE_EXEC_CHAINING || wasSync) {
+                ret = jsMessageQueue.popAndEncode();
+            }
+            return ret;
         } finally {
             jsMessageQueue.setPaused(false);
         }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3cbfd54/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
index 8e022b4..d2732c4 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -41,6 +41,14 @@ public class NativeToJsMessageQueue {
     // Set this to true to force plugin results to be encoding as
     // JS instead of the custom format (useful for benchmarking).
     private static final boolean FORCE_ENCODE_USING_EVAL = false;
+
+    // Disable URL-based exec() bridge by default since it's a bit of a
+    // security concern.
+    static final boolean ENABLE_LOCATION_CHANGE_EXEC_MODE = false;
+        
+    // Disable sending back native->JS messages during an exec() when the active
+    // exec() is asynchronous. Set this to true when running bridge benchmarks.
+    static final boolean DISABLE_EXEC_CHAINING = false;
     
     // Arbitrarily chosen upper limit for how much data to send to JS in one shot. 
     private static final int MAX_PAYLOAD_SIZE = 50 * 1024;
@@ -68,7 +76,7 @@ public class NativeToJsMessageQueue {
     
     private final CordovaInterface cordova;
     private final CordovaWebView webView;
-        
+
     public NativeToJsMessageQueue(CordovaWebView webView, CordovaInterface cordova) {
         this.cordova = cordova;
         this.webView = webView;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3cbfd54/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index 3230b57..aef6302 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -213,8 +213,9 @@ public class PluginManager {
      * @param async         Boolean indicating whether the calling JavaScript code is expecting
an
      *                      immediate return value. If true, either Cordova.callbackSuccess(...)
or
      *                      Cordova.callbackError(...) is called once the plugin code has
executed.
+     * @return Whether the task completed synchronously.
      */
-    public void exec(final String service, final String action, final String callbackId,
final String jsonArgs, final boolean async) {
+    public boolean exec(final String service, final String action, final String callbackId,
final String jsonArgs, final boolean async) {
         PluginResult cr = null;
         boolean runAsync = async;
         try {
@@ -237,14 +238,14 @@ public class PluginManager {
                             }
                         }
                     });
-                    return;
+                    return false;
                 } else {
                     // Call execute on the plugin so that it can do it's thing
                     cr = plugin.execute(action, args, callbackId);
 
                     // If no result to be sent and keeping callback, then no need to sent
back to JavaScript
                     if ((cr.getStatus() == PluginResult.Status.NO_RESULT.ordinal()) &&
cr.getKeepCallback()) {
-                        return;
+                        return true;
                     }
                 }
             }
@@ -263,6 +264,7 @@ public class PluginManager {
         	cr = new PluginResult(PluginResult.Status.NO_RESULT);
         }
         app.sendPluginResult(cr, callbackId);
+        return true;
     }
 
     /**


Mime
View raw message