You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/17 17:43:42 UTC

[1/2] android commit: Provide an addJavascriptInterface() exec object.

Updated Branches:
  refs/heads/master 999c548e6 -> 1b33dbe2a


Provide an addJavascriptInterface() exec object.

-Disabled for 2.3 emulator to avoid a crash bug.


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/1b33dbe2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/1b33dbe2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/1b33dbe2

Branch: refs/heads/master
Commit: 1b33dbe2aeae8882a2cc85c566ffb5e6c844c249
Parents: 80654c0
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Aug 16 17:21:30 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 17 11:15:19 2012 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   17 +++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1b33dbe2/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index 03d916e..85c3cd8 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
 import org.apache.cordova.api.CordovaInterface;
 import org.apache.cordova.api.LOG;
 import org.apache.cordova.api.PluginManager;
+import org.json.JSONException;
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.annotation.SuppressLint;
@@ -38,6 +39,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.res.XmlResourceParser;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -232,6 +234,21 @@ public class CordovaWebView extends WebView {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
+        exposeJsInterface();
+    }
+
+    private void exposeJsInterface() {
+        // addJavascriptInterface crashes on the 2.3 emulator.
+        if (Build.VERSION.RELEASE.startsWith("2.3") && Build.MANUFACTURER.equals("unknown")) {
+            Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator");
+            return;
+        }
+        this.addJavascriptInterface(new Object() {
+            @SuppressWarnings("unused")
+            public String exec(String service, String action, String callbackId, String arguments) throws JSONException {
+                return pluginManager.exec(service, action, callbackId, arguments, true /* async */);
+            }
+        }, "_cordovaExec");
     }
 
     /**