From 6aafd6dc3aec1ed1fe1d7a3e08d73deedddbc3a3 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 25 Oct 2012 12:11:09 -0700 Subject: [PATCH 1/7] Moved the initialization of the IceCreamWebViewClient to CordovaWebView, we weren't loading the fix in properly after the refactor - CB-1742 --- framework/src/org/apache/cordova/CordovaWebView.java | 4 ++-- framework/src/org/apache/cordova/DroidGap.java | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 3f64d536..90968ae6 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -122,6 +122,7 @@ public class CordovaWebView extends WebView { { Log.d(TAG, "Your activity must implement CordovaInterface to work"); } + this.initWebViewClient(this.cordova); this.loadConfiguration(); this.setup(); } @@ -167,7 +168,6 @@ public class CordovaWebView extends WebView { Log.d(TAG, "Your activity must implement CordovaInterface to work"); } this.setWebChromeClient(new CordovaChromeClient(this.cordova, this)); - this.initWebViewClient(this.cordova); this.loadConfiguration(); this.setup(); } @@ -199,7 +199,7 @@ public class CordovaWebView extends WebView { private void initWebViewClient(CordovaInterface cordova) { - if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB) + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { this.setWebViewClient(new CordovaWebViewClient(this.cordova, this)); } diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 1176f693..3e207c6f 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -301,7 +301,7 @@ public class DroidGap extends Activity implements CordovaInterface { */ public void init() { CordovaWebView webView = new CordovaWebView(DroidGap.this); - this.init(webView, new CordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView)); + this.init(webView, new CordovaChromeClient(this, webView)); } /** @@ -311,16 +311,14 @@ public class DroidGap extends Activity implements CordovaInterface { * @param webViewClient * @param webChromeClient */ - public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { + public void init(CordovaWebView webView, CordovaChromeClient webChromeClient) { LOG.d(TAG, "DroidGap.init()"); // Set up web container this.appView = webView; this.appView.setId(100); - this.appView.setWebViewClient(webViewClient); this.appView.setWebChromeClient(webChromeClient); - webViewClient.setWebView(this.appView); webChromeClient.setWebView(this.appView); this.appView.setLayoutParams(new LinearLayout.LayoutParams( From 71a7f72ab9d6a7f7e5db6423941adf6b0b99c98f Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 25 Oct 2012 12:17:38 -0700 Subject: [PATCH 2/7] Added fix for webViewClient. CB-1568 --- framework/src/org/apache/cordova/DroidGap.java | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 3e207c6f..47908c43 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -320,6 +320,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.appView.setWebChromeClient(webChromeClient); webChromeClient.setWebView(this.appView); + webViewClient = appView.viewClient; this.appView.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, From 7f4ee7b20a259143a53d335d3a5482f7acfa8073 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 25 Oct 2012 13:18:28 -0700 Subject: [PATCH 3/7] Changing DroidGap back and duplicating code so that we don't have a regression on CB-1568 --- .../src/org/apache/cordova/CordovaWebView.java | 1 - framework/src/org/apache/cordova/DroidGap.java | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 5ec71cec..efb7693c 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -122,7 +122,6 @@ public class CordovaWebView extends WebView { { Log.d(TAG, "Your activity must implement CordovaInterface to work"); } - this.initWebViewClient(this.cordova); this.loadConfiguration(); this.setup(); } diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 47908c43..4c494123 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -301,7 +301,16 @@ public class DroidGap extends Activity implements CordovaInterface { */ public void init() { CordovaWebView webView = new CordovaWebView(DroidGap.this); - this.init(webView, new CordovaChromeClient(this, webView)); + CordovaWebViewClient webViewClient; + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) + { + webViewClient = new CordovaWebViewClient(this, webView); + } + else + { + webViewClient = new IceCreamCordovaWebViewClient(this, webView); + } + this.init(webView, webViewClient, new CordovaChromeClient(this, webView)); } /** @@ -311,16 +320,17 @@ public class DroidGap extends Activity implements CordovaInterface { * @param webViewClient * @param webChromeClient */ - public void init(CordovaWebView webView, CordovaChromeClient webChromeClient) { + public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { LOG.d(TAG, "DroidGap.init()"); // Set up web container this.appView = webView; this.appView.setId(100); + this.appView.setWebViewClient(webViewClient); this.appView.setWebChromeClient(webChromeClient); + webViewClient.setWebView(this.appView); webChromeClient.setWebView(this.appView); - webViewClient = appView.viewClient; this.appView.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, From 49566d29f8cea486b300a8c356d56f9d847f4031 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 25 Oct 2012 14:13:17 -0700 Subject: [PATCH 4/7] Partial fix for CB-1742, still don't know what this should do for notification.confirm's cancel, so we return zero for now --- .../src/org/apache/cordova/Notification.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/framework/src/org/apache/cordova/Notification.java b/framework/src/org/apache/cordova/Notification.java index f0d77b71..958ab26b 100755 --- a/framework/src/org/apache/cordova/Notification.java +++ b/framework/src/org/apache/cordova/Notification.java @@ -163,6 +163,14 @@ public class Notification extends CordovaPlugin { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); + dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { + public void onCancel(DialogInterface dialog) + { + dialog.dismiss(); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); + } + }); + dlg.create(); dlg.show(); }; @@ -225,6 +233,13 @@ public class Notification extends CordovaPlugin { } ); } + dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { + public void onCancel(DialogInterface dialog) + { + dialog.dismiss(); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); + } + }); dlg.create(); dlg.show(); From e4f8f44fb0a89e5664115c5fb7a631f7749896f8 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Fri, 26 Oct 2012 10:41:08 -0400 Subject: [PATCH 5/7] Update JS to new 2.2.0rc2 tag. --- framework/assets/js/cordova.android.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index 5efbd046..131d6544 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 8119d0b96958dfa3a0ce8590a90b24242ec4e31a +// commit 97a05cb0f672ee1bfb7e9e14a0dfd452d7763ba9 -// File generated at :: Thu Oct 25 2012 15:01:24 GMT-0400 (EDT) +// File generated at :: Fri Oct 26 2012 10:37:55 GMT-0400 (EDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -973,7 +973,7 @@ function androidExec(success, fail, service, action, args) { // Remove it after 6 months. function captureReturnValue(value) { returnValue = value; - success(value); + success && success(value); } cordova.callbacks[callbackId] = {success:captureReturnValue, fail:fail}; From 678ae2d684a39017bec3586883c3a528190d4d20 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Fri, 26 Oct 2012 16:08:35 -0400 Subject: [PATCH 6/7] Disable limiting of payload size when sending data to JS. Fixes https://issues.apache.org/jira/browse/CB-1745 --- .../org/apache/cordova/NativeToJsMessageQueue.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 4f9f9ad1..31466238 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -50,8 +50,13 @@ public class NativeToJsMessageQueue { // exec() is asynchronous. Set this to true when running bridge benchmarks. static final boolean DISABLE_EXEC_CHAINING = false; - // Arbitrarily chosen upper limit for how much data to send to JS in one shot. - private static final int MAX_PAYLOAD_SIZE = 50 * 1024; + // Upper limit for how much data to send to JS in one shot. + // TODO(agrieve): This is currently disable. It should be re-enabled once we + // remove support for returning values from exec() calls. This was + // deprecated in 2.2.0. + // Also, this currently only chops up on message boundaries. It may be useful + // to allow it to break up messages. + private static int MAX_PAYLOAD_SIZE = -1; //50 * 1024 * 10240; /** * The index into registeredListeners to treat as active. @@ -144,7 +149,7 @@ public class NativeToJsMessageQueue { int numMessagesToSend = 0; for (JsMessage message : queue) { int messageSize = calculatePackedMessageLength(message); - if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE) { + if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) { break; } totalPayloadLen += messageSize; @@ -178,7 +183,7 @@ public class NativeToJsMessageQueue { int numMessagesToSend = 0; for (JsMessage message : queue) { int messageSize = message.calculateEncodedLength() + 50; // overestimate. - if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE) { + if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) { break; } totalPayloadLen += messageSize; From 3c5815ac0fc1f28a2cba54e648b9d0a7f175ff4e Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Fri, 26 Oct 2012 16:09:54 -0400 Subject: [PATCH 7/7] Update JS to new tag (again). Includes latest fix to CB-1745. --- framework/assets/js/cordova.android.js | 39 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index 131d6544..8dd0ed67 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 97a05cb0f672ee1bfb7e9e14a0dfd452d7763ba9 +// commit d819e1e60599c12ac831379b06bba9110e9f1790 -// File generated at :: Fri Oct 26 2012 10:37:55 GMT-0400 (EDT) +// File generated at :: Fri Oct 26 2012 16:03:51 GMT-0400 (EDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -1001,8 +1001,8 @@ function pollOnce() { function pollingTimerFunc() { if (pollEnabled) { - pollOnce(); - setTimeout(pollingTimerFunc, 50); + pollOnce(); + setTimeout(pollingTimerFunc, 50); } } @@ -1095,25 +1095,34 @@ function processMessage(message) { // This is called from the NativeToJsMessageQueue.java. androidExec.processMessages = function(messages) { - messagesFromNative.push(messages); - // Check for the reentrant case, and enqueue the message if that's the case. - if (messagesFromNative.length > 1) { - return; - } - while (messagesFromNative.length) { - messages = messagesFromNative[0]; - while (messages) { + if (messages) { + messagesFromNative.push(messages); + while (messagesFromNative.length) { + messages = messagesFromNative.shift(); + // The Java side can send a * message to indicate that it + // still has messages waiting to be retrieved. + // TODO(agrieve): This is currently disabled on the Java side + // since it breaks returning the result in exec of synchronous + // plugins. Once we remove this ability, we can remove this comment. if (messages == '*') { window.setTimeout(pollOnce, 0); - break; + continue; } + var spaceIdx = messages.indexOf(' '); var msgLen = +messages.slice(0, spaceIdx); var message = messages.substr(spaceIdx + 1, msgLen); messages = messages.slice(spaceIdx + msgLen + 1); - processMessage(message); + // Put the remaining messages back into queue in case an exec() + // is made by the callback. + if (messages) { + messagesFromNative.unshift(messages); + } + + if (message) { + processMessage(message); + } } - messagesFromNative.shift(); } };