Repository: cordova-plugin-inappbrowser
Updated Branches:
  refs/heads/master 1b4859c17 -> 8ab07277c


CB-12184 executeScript leads to a null pointer on exception on Android.

 This closes #199


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/8ab07277
Tree: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/8ab07277
Diff: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/8ab07277

Branch: refs/heads/master
Commit: 8ab07277cd9bf8aa81de89fcc1d54dde503c28e9
Parents: 1b4859c
Author: Julio César <jcesarmob...@gmail.com>
Authored: Thu Nov 24 18:50:49 2016 +0100
Committer: Julio César <jcesarmob...@gmail.com>
Committed: Thu Nov 24 19:47:50 2016 +0100

----------------------------------------------------------------------
 README.md                     |  8 +++----
 src/android/InAppBrowser.java | 46 +++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/8ab07277/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 1e0645c..18aadd2 100644
--- a/README.md
+++ b/README.md
@@ -222,7 +222,7 @@ The object returned from a call to 
`cordova.InAppBrowser.open` when the target i
 
 ## InAppBrowser.addEventListener
 
-> Adds a listener for an event from the `InAppBrowser`.
+> Adds a listener for an event from the `InAppBrowser`. (Only available when 
the target is set to `'_blank'`)
 
     ref.addEventListener(eventname, callback);
 
@@ -338,7 +338,7 @@ function executeScriptCallBack(params) {
 
 ## InAppBrowser.removeEventListener
 
-> Removes a listener for an event from the `InAppBrowser`.
+> Removes a listener for an event from the `InAppBrowser`. (Only available 
when the target is set to `'_blank'`)
 
     ref.removeEventListener(eventname, callback);
 
@@ -438,7 +438,7 @@ The function is passed an `InAppBrowserEvent` object.
 
 ## InAppBrowser.executeScript
 
-> Injects JavaScript code into the `InAppBrowser` window
+> Injects JavaScript code into the `InAppBrowser` window. (Only available when 
the target is set to `'_blank'`)
 
     ref.executeScript(details, callback);
 
@@ -480,7 +480,7 @@ Due to [MSDN 
docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont
 
 ## InAppBrowser.insertCSS
 
-> Injects CSS into the `InAppBrowser` window.
+> Injects CSS into the `InAppBrowser` window. (Only available when the target 
is set to `'_blank'`)
 
     ref.insertCSS(details, callback);
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/8ab07277/src/android/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 07ac31e..ef37fed 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -323,29 +323,33 @@ public class InAppBrowser extends CordovaPlugin {
      *                    which should be executed directly.
      */
     private void injectDeferredObject(String source, String jsWrapper) {
-        String scriptToInject;
-        if (jsWrapper != null) {
-            org.json.JSONArray jsonEsc = new org.json.JSONArray();
-            jsonEsc.put(source);
-            String jsonRepr = jsonEsc.toString();
-            String jsonSourceString = jsonRepr.substring(1, 
jsonRepr.length()-1);
-            scriptToInject = String.format(jsWrapper, jsonSourceString);
+        if (inAppWebView!=null) {
+            String scriptToInject;
+            if (jsWrapper != null) {
+                org.json.JSONArray jsonEsc = new org.json.JSONArray();
+                jsonEsc.put(source);
+                String jsonRepr = jsonEsc.toString();
+                String jsonSourceString = jsonRepr.substring(1, 
jsonRepr.length()-1);
+                scriptToInject = String.format(jsWrapper, jsonSourceString);
+            } else {
+                scriptToInject = source;
+            }
+            final String finalScriptToInject = scriptToInject;
+            this.cordova.getActivity().runOnUiThread(new Runnable() {
+                @SuppressLint("NewApi")
+                @Override
+                public void run() {
+                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+                        // This action will have the side-effect of blurring 
the currently focused element
+                        inAppWebView.loadUrl("javascript:" + 
finalScriptToInject);
+                    } else {
+                        inAppWebView.evaluateJavascript(finalScriptToInject, 
null);
+                    }
+                }
+            });
         } else {
-            scriptToInject = source;
+            LOG.d(LOG_TAG, "Can't inject code into the system browser");
         }
-        final String finalScriptToInject = scriptToInject;
-        this.cordova.getActivity().runOnUiThread(new Runnable() {
-            @SuppressLint("NewApi")
-            @Override
-            public void run() {
-                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
-                    // This action will have the side-effect of blurring the 
currently focused element
-                    inAppWebView.loadUrl("javascript:" + finalScriptToInject);
-                } else {
-                    inAppWebView.evaluateJavascript(finalScriptToInject, null);
-                }
-            }
-        });
     }
 
     /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to