From 629964d61cf9f6e57e96950791b0e7f6aa8bf340 Mon Sep 17 00:00:00 2001 From: kira Date: Sat, 4 May 2013 17:21:43 -0400 Subject: [PATCH] add "clearallcache" and "clearsessioncache" option to InAppbrowser --- src/android/InAppBrowser.java | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 581a4a0..fedfa0d 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -51,6 +51,7 @@ import android.view.WindowManager; 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; @@ -78,6 +79,9 @@ public class InAppBrowser extends CordovaPlugin { private static final String LOAD_STOP_EVENT = "loadstop"; private static final String LOAD_ERROR_EVENT = "loaderror"; private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption"; + private static final String CLEAR_ALL_CACHE = "clearallcache"; + private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; + private long MAX_QUOTA = 100 * 1024 * 1024; private Dialog dialog; @@ -87,7 +91,9 @@ public class InAppBrowser extends CordovaPlugin { private boolean showLocationBar = true; private boolean openWindowHidden = false; private String buttonLabel = "Done"; - + private boolean clearAllCache= false; + private boolean clearSessionCache=false; + /** * Executes the request and returns PluginResult. * @@ -382,9 +388,18 @@ public class InAppBrowser extends CordovaPlugin { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); - if(hidden != null) { + if (hidden != null) { openWindowHidden = hidden.booleanValue(); } + Boolean cache = features.get(CLEAR_ALL_CACHE); + if (cache != null) { + clearAllCache = cache.booleanValue(); + } else { + cache = features.get(CLEAR_SESSION_CACHE); + if (cache != null) { + clearSessionCache = cache.booleanValue(); + } + } } final CordovaWebView thatWebView = this.webView; @@ -522,14 +537,19 @@ public class InAppBrowser extends CordovaPlugin { //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); - if(enableDatabase) - { + if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); - + + if (clearAllCache) { + CookieManager.getInstance().removeAllCookie(); + } else if (clearSessionCache) { + CookieManager.getInstance().removeSessionCookie(); + } + inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true);