incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/6] android commit: Implements the LOAD_URL Native->JS bridge mode
Date Wed, 22 Aug 2012 13:57:11 GMT
Implements the LOAD_URL Native->JS bridge mode

(without keyboard work-around)


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

Branch: refs/heads/master
Commit: 7fa4515c289e5fd4d824faa1570402197d0eefd1
Parents: b40eb0a
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Tue Aug 21 11:36:54 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Aug 22 09:46:30 2012 -0400

----------------------------------------------------------------------
 .../org/apache/cordova/NativeToJsMessageQueue.java |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7fa4515c/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 037cc9c..6abb970 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -47,9 +47,10 @@ public class NativeToJsMessageQueue {
     private BridgeMode[] registeredListeners;    
         
     public NativeToJsMessageQueue(CordovaWebView webView) {
-    	registeredListeners = new BridgeMode[2];
+    	registeredListeners = new BridgeMode[3];
     	registeredListeners[0] = null;
     	registeredListeners[1] = new CallbackBridgeMode(webView);
+    	registeredListeners[2] = new LoadUrlBridgeMode(webView);
     	reset();
 //        POLLING: 0,
 //        HANGING_GET: 1,
@@ -148,6 +149,7 @@ public class NativeToJsMessageQueue {
 		void onNativeToJsMessageAvailable(NativeToJsMessageQueue queue);
 	}
 	
+    /** Uses a local server to send messages to JS via an XHR */
     private static class CallbackBridgeMode implements BridgeMode {
     	private CordovaWebView webView;
 		public CallbackBridgeMode(CordovaWebView webView) {
@@ -159,5 +161,16 @@ public class NativeToJsMessageQueue {
     		}
         }
     }
+    
+    /** Uses webView.loadUrl("javascript:") to execute messages. */
+    public static class LoadUrlBridgeMode implements BridgeMode {
+		private CordovaWebView webView;
+		public LoadUrlBridgeMode(CordovaWebView webView) {
+    		this.webView = webView;
+    	}
+    	public void onNativeToJsMessageAvailable(NativeToJsMessageQueue queue) {
+    		webView.loadUrlNow("javascript:" + queue.popAll());
+        }
+    }
 
 }


Mime
View raw message