You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/11/30 14:41:07 UTC

android commit: [CB-1950] InAppBrowser - support events

Updated Branches:
  refs/heads/master 2c202b82d -> 432aec62a


[CB-1950] InAppBrowser - support events


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

Branch: refs/heads/master
Commit: 432aec62a965ace060c02be205298c5ffcf84472
Parents: 2c202b8
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri Nov 30 05:40:59 2012 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Nov 30 05:40:59 2012 -0800

----------------------------------------------------------------------
 framework/src/org/apache/cordova/InAppBrowser.java |   55 ++++++++++----
 1 files changed, 39 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/432aec62/framework/src/org/apache/cordova/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java
index 338d344..1e590d6 100644
--- a/framework/src/org/apache/cordova/InAppBrowser.java
+++ b/framework/src/org/apache/cordova/InAppBrowser.java
@@ -64,8 +64,9 @@ public class InAppBrowser extends CordovaPlugin {
     private static final String SYSTEM = "_system";
     private static final String BLANK = "_blank";
     private static final String LOCATION = "location";
-    private static int CLOSE_EVENT = 0;
-    private static int LOCATION_CHANGED_EVENT = 1;
+    private static final String EXIT_EVENT = "exit";
+    private static final String LOAD_START_EVENT = "loadstart";
+    private static final String LOAD_STOP_EVENT = "loadstop";
 
     private String browserCallbackId = null;
 
@@ -128,17 +129,16 @@ public class InAppBrowser extends CordovaPlugin {
             else if (action.equals("close")) {
                 closeDialog();
 
-                JSONObject obj = new JSONObject();
-                obj.put("type", CLOSE_EVENT);
-
-                PluginResult pluginResult = new PluginResult(status, obj);
+                PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
                 pluginResult.setKeepCallback(false);
                 this.callbackContext.sendPluginResult(pluginResult);
             }
             else {
                 status = PluginResult.Status.INVALID_ACTION;
             }
-            this.callbackContext.sendPluginResult(new PluginResult(status, result));
+            PluginResult pluginResult = new PluginResult(status, result);
+            pluginResult.setKeepCallback(true);
+            this.callbackContext.sendPluginResult(pluginResult);
         } catch (JSONException e) {
             this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
         }
@@ -208,8 +208,15 @@ public class InAppBrowser extends CordovaPlugin {
      * Closes the dialog
      */
     private void closeDialog() {
-        // TODO: fire 'exit' event 
-        this.webView.sendJavascript("cordova.fireWindowEvent('exit');");
+        try {
+            JSONObject obj = new JSONObject();
+            obj.put("type", EXIT_EVENT);
+
+            sendUpdate(obj, false);
+        } catch (JSONException ex) {
+            Log.d(LOG_TAG, "Should never happen");
+        }
+        
         if (dialog != null) {
             dialog.dismiss();
         }
@@ -301,7 +308,7 @@ public class InAppBrowser extends CordovaPlugin {
                         public void onDismiss(DialogInterface dialog) {
                             try {
                                 JSONObject obj = new JSONObject();
-                                obj.put("type", CLOSE_EVENT);
+                                obj.put("type", EXIT_EVENT);
 
                                 sendUpdate(obj, false);
                             } catch (JSONException e) {
@@ -455,11 +462,12 @@ public class InAppBrowser extends CordovaPlugin {
      * @param obj a JSONObject contain event payload information
      */
     private void sendUpdate(JSONObject obj, boolean keepCallback) {
-        if (this.browserCallbackId != null) {
+        // TODO: Not sure how browserCallbackId is used overall, commenting it out for now
+//        if (this.browserCallbackId != null) {
             PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
             result.setKeepCallback(keepCallback);
             this.callbackContext.sendPluginResult(result);
-        }
+//        }
     }
 
     /**
@@ -500,14 +508,29 @@ public class InAppBrowser extends CordovaPlugin {
                 edittext.setText(newloc);
             }
 
-            // TODO: Fire 'loadstart' event only on the InAppBrowser object
-            this.webView.sendJavascript("cordova.fireWindowEvent('loadstart', '" + url + "');");
+            try {
+                JSONObject obj = new JSONObject();
+                obj.put("type", LOAD_START_EVENT);
+                obj.put("url", newloc);
+    
+                sendUpdate(obj, true);
+            } catch (JSONException ex) {
+                Log.d(LOG_TAG, "Should never happen");
+            }
         }
         
         public void onPageFinished(WebView view, String url) {
             super.onPageFinished(view, url);
-            // TODO: Fire 'loadstop' event only on the InAppBrowser object
-            this.webView.sendJavascript("cordova.fireWindowEvent('loadstop', '" + url + "');");
+            
+            try {
+                JSONObject obj = new JSONObject();
+                obj.put("type", LOAD_STOP_EVENT);
+                obj.put("url", url);
+    
+                sendUpdate(obj, true);
+            } catch (JSONException ex) {
+                Log.d(LOG_TAG, "Should never happen");
+            }
         }
     }
 }
\ No newline at end of file