From 8df4b7d03b3766cce03e26f996dfa3b54e417f04 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 10 Oct 2013 11:49:00 -0400 Subject: [PATCH] CB-3747 Fix back button having different dismiss logic from the close button. Also made the IAB close when the owner page is navigated (implemented onReset). --- src/android/InAppBrowser.java | 71 ++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index dfe1a50..940a409 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -18,20 +18,6 @@ */ package org.apache.cordova.inappbrowser; -import java.util.HashMap; -import java.util.StringTokenizer; - - -import org.apache.cordova.Config; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginResult; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; @@ -52,11 +38,7 @@ import android.view.WindowManager.LayoutParams; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; -import android.webkit.WebChromeClient; -import android.webkit.GeolocationPermissions.Callback; -import android.webkit.JsPromptResult; import android.webkit.WebSettings; -import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; @@ -64,6 +46,19 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RelativeLayout; +import org.apache.cordova.CallbackContext; +import org.apache.cordova.Config; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; +import org.apache.cordova.LOG; +import org.apache.cordova.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.StringTokenizer; + @SuppressLint("SetJavaScriptEnabled") public class InAppBrowser extends CordovaPlugin { @@ -157,7 +152,6 @@ public class InAppBrowser extends CordovaPlugin { } else if (action.equals("close")) { closeDialog(); - this.callbackContext.success(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; @@ -214,6 +208,22 @@ public class InAppBrowser extends CordovaPlugin { return true; } + /** + * Called when the view navigates. + */ + @Override + public void onReset() { + closeDialog(); + } + + /** + * Called by AccelBroker when listener is to be shut down. + * Stop listener. + */ + public void onDestroy() { + closeDialog(); + } + /** * Inject an object (script or style) into the InAppBrowser WebView. * @@ -442,14 +452,7 @@ public class InAppBrowser extends CordovaPlugin { dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { - try { - JSONObject obj = new JSONObject(); - obj.put("type", EXIT_EVENT); - - sendUpdate(obj, false); - } catch (JSONException e) { - Log.d(LOG_TAG, "Should never happen"); - } + closeDialog(); } }); @@ -624,10 +627,16 @@ public class InAppBrowser extends CordovaPlugin { * * @param obj a JSONObject contain event payload information * @param status the status code to return to the JavaScript environment - */ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { - PluginResult result = new PluginResult(status, obj); - result.setKeepCallback(keepCallback); - this.callbackContext.sendPluginResult(result); + */ + private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { + if (callbackContext != null) { + PluginResult result = new PluginResult(status, obj); + result.setKeepCallback(keepCallback); + callbackContext.sendPluginResult(result); + if (!keepCallback) { + callbackContext = null; + } + } }