cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [05/11] android commit: Log friendlier messages when bridge calls are recieved from previous page
Date Thu, 10 Jul 2014 14:30:39 GMT
Log friendlier messages when bridge calls are recieved from previous page


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

Branch: refs/heads/4.0.x
Commit: fc2a202afa115c713eb5b8530f4db389ef83c5a8
Parents: 4b4b71f
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jul 10 10:14:47 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jul 10 10:14:47 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaBridge.java     | 18 ++++++++++++++++++
 .../apache/cordova/NativeToJsMessageQueue.java    |  4 ++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/fc2a202a/framework/src/org/apache/cordova/CordovaBridge.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaBridge.java b/framework/src/org/apache/cordova/CordovaBridge.java
index d9efb3b..2bfad11 100644
--- a/framework/src/org/apache/cordova/CordovaBridge.java
+++ b/framework/src/org/apache/cordova/CordovaBridge.java
@@ -40,8 +40,23 @@ public class CordovaBridge {
         this.pluginManager = pluginManager;
         this.jsMessageQueue = jsMessageQueue;
     }
+    
+    private final boolean checkBridgeEnabled(String action) {
+        if (!jsMessageQueue.isBridgeEnabled()) {
+            if (bridgeSecret == -1) {
+                Log.d(LOG_TAG, action + " call made before bridge was enabled.");
+            } else {
+                Log.d(LOG_TAG, "Ignoring " + action + " from previous page load.");     
          
+            }
+            return false;
+        }
+        return true;
+    }
 
     public String jsExec(int bridgeSecret, String service, String action, String callbackId,
String arguments) throws JSONException, IllegalAccessException {
+        if (!checkBridgeEnabled("exec()")) {
+            return "";
+        }
         verifySecret(bridgeSecret);
         // If the arguments weren't received, send a message back to JS.  It will switch
bridge modes and try again.  See CB-2666.
         // We send a message meant specifically for this case.  It starts with "@" so no
other message can be encoded into the same string.
@@ -74,6 +89,9 @@ public class CordovaBridge {
     }
 
     public String jsRetrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws
IllegalAccessException {
+        if (!checkBridgeEnabled("retrieveJsMessages()")) {
+            return "";
+        }
         verifySecret(bridgeSecret);
         return jsMessageQueue.popAndEncode(fromOnlineEvent);
     }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/fc2a202a/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 08ca00e..75d5d43 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -85,6 +85,10 @@ public class NativeToJsMessageQueue {
         reset();
     }
     
+    public boolean isBridgeEnabled() {
+        return activeBridgeMode != null;
+    }
+
     /**
      * Changes the bridge mode.
      */


Mime
View raw message