cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [1/2] android commit: Creating an evaluateJavascript branch
Date Thu, 01 Sep 2016 15:52:55 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 0ee672d2b -> 047ed52d6


Creating an evaluateJavascript branch


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

Branch: refs/heads/master
Commit: bb96bb9a88e8997e5d5ef0a9e7ca12bf3773e473
Parents: 0ee672d
Author: Joe Bowser <bowserj@apache.org>
Authored: Wed Mar 9 10:35:09 2016 -0800
Committer: Joe Bowser <bowserj@apache.org>
Committed: Thu Sep 1 08:49:32 2016 -0700

----------------------------------------------------------------------
 bin/templates/project/assets/www/cordova.js     | 15 ++++++------
 cordova-js-src/exec.js                          |  3 ++-
 .../apache/cordova/CordovaWebViewEngine.java    |  4 ++++
 .../apache/cordova/NativeToJsMessageQueue.java  | 25 ++++++++++++++++++++
 .../cordova/engine/SystemWebViewEngine.java     |  6 +++++
 5 files changed, 45 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb96bb9a/bin/templates/project/assets/www/cordova.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/assets/www/cordova.js b/bin/templates/project/assets/www/cordova.js
index cbfaed7..700c667 100644
--- a/bin/templates/project/assets/www/cordova.js
+++ b/bin/templates/project/assets/www/cordova.js
@@ -330,7 +330,7 @@ module.exports = cordova;
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/nativeapiprovider.js
+// file: /Users/jbowser/cordova/cordova-android/cordova-js-src/android/nativeapiprovider.js
 define("cordova/android/nativeapiprovider", function(require, exports, module) {
 
 /**
@@ -353,7 +353,7 @@ module.exports = {
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/promptbasednativeapi.js
+// file: /Users/jbowser/cordova/cordova-android/cordova-js-src/android/promptbasednativeapi.js
 define("cordova/android/promptbasednativeapi", function(require, exports, module) {
 
 /**
@@ -862,7 +862,7 @@ module.exports = channel;
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/exec.js
+// file: /Users/jbowser/cordova/cordova-android/cordova-js-src/exec.js
 define("cordova/exec", function(require, exports, module) {
 
 /**
@@ -897,7 +897,8 @@ var cordova = require('cordova'),
         // For the ONLINE_EVENT to be viable, it would need to intercept all event
         // listeners (both through addEventListener and window.ononline) as well
         // as set the navigator property itself.
-        ONLINE_EVENT: 2
+        ONLINE_EVENT: 2,
+        EVAL_BRIDGE: 3
     },
     jsToNativeBridgeMode,  // Set lazily.
     nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,
@@ -1611,7 +1612,7 @@ exports.reset();
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/platform.js
+// file: /Users/jbowser/cordova/cordova-android/cordova-js-src/platform.js
 define("cordova/platform", function(require, exports, module) {
 
 // The last resume event that was received that had the result of a plugin call.
@@ -1721,7 +1722,7 @@ function onMessageFromNative(msg) {
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/plugin/android/app.js
+// file: /Users/jbowser/cordova/cordova-android/cordova-js-src/plugin/android/app.js
 define("cordova/plugin/android/app", function(require, exports, module) {
 
 var exec = require('cordova/exec');
@@ -2164,4 +2165,4 @@ window.cordova = require('cordova');
 
 require('cordova/init');
 
-})();
\ No newline at end of file
+})();

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb96bb9a/cordova-js-src/exec.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js
index fa8b41b..197fb5d 100644
--- a/cordova-js-src/exec.js
+++ b/cordova-js-src/exec.js
@@ -51,7 +51,8 @@ var cordova = require('cordova'),
         // For the ONLINE_EVENT to be viable, it would need to intercept all event
         // listeners (both through addEventListener and window.ononline) as well
         // as set the navigator property itself.
-        ONLINE_EVENT: 2
+        ONLINE_EVENT: 2,
+        EVAL_BRIDGE: 3
     },
     jsToNativeBridgeMode,  // Set lazily.
     nativeToJsBridgeMode = nativeToJsModes.ONLINE_EVENT,

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb96bb9a/framework/src/org/apache/cordova/CordovaWebViewEngine.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewEngine.java b/framework/src/org/apache/cordova/CordovaWebViewEngine.java
index f34c749..c8e5a55 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewEngine.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewEngine.java
@@ -20,6 +20,7 @@ package org.apache.cordova;
 
 import android.view.KeyEvent;
 import android.view.View;
+import android.webkit.ValueCallback;
 
 /**
  * Interface for all Cordova engines.
@@ -58,6 +59,9 @@ public interface CordovaWebViewEngine {
     /** Clean up all resources associated with the WebView. */
     void destroy();
 
+    /** Add the evaulate Javascript method **/
+    void evaluateJavascript(String js, ValueCallback<String> callback);
+
     /**
      * Used to retrieve the associated CordovaWebView given a View without knowing the type
of Engine.
      * E.g. ((CordovaWebView.EngineView)activity.findViewById(android.R.id.webView)).getCordovaWebView();

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb96bb9a/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 03a62b0..61d04f1 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -349,6 +349,31 @@ public class NativeToJsMessageQueue {
         }
     }
 
+    /** Uses webView.evaluateJavascript to execute messages. */
+    public static class EvalBridgeMode extends BridgeMode {
+        private final CordovaWebViewEngine engine;
+        private final CordovaInterface cordova;
+
+        public EvalBridgeMode(CordovaWebViewEngine engine, CordovaInterface cordova) {
+            this.engine = engine;
+            this.cordova = cordova;
+        }
+
+        @Override
+        public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
+            cordova.getActivity().runOnUiThread(new Runnable() {
+                public void run() {
+                    String js = queue.popAndEncodeAsJs();
+                    if (js != null) {
+                        engine.evaluateJavascript(js, null);
+                    }
+                }
+            });
+        }
+    }
+
+
+
     private static class JsMessage {
         final String jsPayloadOrCallbackId;
         final PluginResult pluginResult;

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb96bb9a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java
index 672c2c2..7951b35 100755
--- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java
+++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java
@@ -28,6 +28,7 @@ import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.os.Build;
 import android.view.View;
+import android.webkit.ValueCallback;
 import android.webkit.WebSettings;
 import android.webkit.WebSettings.LayoutAlgorithm;
 import android.webkit.WebView;
@@ -331,4 +332,9 @@ public class SystemWebViewEngine implements CordovaWebViewEngine {
             }
         }
     }
+
+    @Override
+    public void evaluateJavascript(String js, ValueCallback<String> callback) {
+        webView.evaluateJavascript(js, callback);
+    }
 }


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


Mime
View raw message