diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
index 5fe4314..922a591 100644
--- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
+++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
@@ -70,15 +70,11 @@ import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
-import android.webkit.CookieManager;
-import android.webkit.CookieSyncManager;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebIconDatabase;
-import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebView.HitTestResult;
-import android.webkit.WebViewDatabase;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
@@ -126,6 +122,7 @@ import acr.browser.lightning.receiver.NetworkReceiver;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils;
+import acr.browser.lightning.utils.WebUtils;
import acr.browser.lightning.view.AnimatedProgressBar;
import acr.browser.lightning.view.LightningView;
@@ -1291,21 +1288,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
closeActivity();
} else {
mWebViewList.remove(position);
- if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
- mCurrentView.clearCache(true);
- Log.d(Constants.TAG, "Cache Cleared");
-
- }
- if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
- clearHistory();
- Log.d(Constants.TAG, "History Cleared");
-
- }
- if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
- clearCookies();
- Log.d(Constants.TAG, "Cookies Cleared");
-
- }
+ performExitCleanUp();
reference.pauseTimers();
reference.onDestroy();
mCurrentView = null;
@@ -1325,31 +1308,41 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
Log.d(Constants.TAG, "deleted tab");
}
- @Override
- public boolean onKeyLongPress(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- showCloseDialog(mDrawerListLeft.getCheckedItemPosition());
- }
- return true;
- }
-
- private void closeBrowser() {
- mBrowserFrame.setBackgroundColor(mBackgroundColor);
+ public void performExitCleanUp() {
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
- mCurrentView.clearCache(true);
+ WebUtils.clearCache(mCurrentView.getWebView());
Log.d(Constants.TAG, "Cache Cleared");
}
if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
- clearHistory();
+ WebUtils.clearHistory(this, mSystemBrowser);
Log.d(Constants.TAG, "History Cleared");
}
if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
- clearCookies();
+ WebUtils.clearCookies(this);
Log.d(Constants.TAG, "Cookies Cleared");
}
+ if (mPreferences.getClearWebStorageExitEnabled() && !isIncognito()) {
+ WebUtils.clearWebStorage();
+ Log.d(Constants.TAG, "WebStorage Cleared");
+ } else if (isIncognito()) {
+ WebUtils.clearWebStorage(); // We want to make sure incognito mode is secure
+ }
+ }
+
+ @Override
+ public boolean onKeyLongPress(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ showCloseDialog(mDrawerListLeft.getCheckedItemPosition());
+ }
+ return true;
+ }
+
+ private void closeBrowser() {
+ mBrowserFrame.setBackgroundColor(mBackgroundColor);
+ performExitCleanUp();
mCurrentView = null;
mWebView = null;
for (int n = 0; n < mWebViewList.size(); n++) {
@@ -1362,38 +1355,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
finish();
}
- private void clearHistory() {
- this.deleteDatabase(HistoryDatabase.DATABASE_NAME);
- WebViewDatabase m = WebViewDatabase.getInstance(this);
- m.clearFormData();
- m.clearHttpAuthUsernamePassword();
- if (API < 18) {
- m.clearUsernamePassword();
- WebIconDatabase.getInstance().removeAllIcons();
- }
- if (mSystemBrowser) {
- try {
- Browser.clearHistory(getContentResolver());
- } catch (NullPointerException ignored) {
- }
- }
- Utils.trimCache(this);
- }
-
- private void clearCookies() {
- // TODO Break out web storage deletion into its own option/action
- // TODO clear web storage for all sites that are visited in Incognito mode
- WebStorage storage = WebStorage.getInstance();
- storage.deleteAllData();
- CookieManager c = CookieManager.getInstance();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- c.removeAllCookies(null);
- } else {
- CookieSyncManager.createInstance(this);
- c.removeAllCookie();
- }
- }
-
@Override
public void onBackPressed() {
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
diff --git a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
index 40229e8..359d05d 100644
--- a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
+++ b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
@@ -12,19 +12,13 @@ import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
-import android.provider.Browser;
import android.support.v7.app.AlertDialog;
-import android.webkit.CookieManager;
-import android.webkit.CookieSyncManager;
-import android.webkit.WebIconDatabase;
-import android.webkit.WebStorage;
import android.webkit.WebView;
-import android.webkit.WebViewDatabase;
import acr.browser.lightning.R;
-import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
+import acr.browser.lightning.utils.WebUtils;
public class PrivacySettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
@@ -38,12 +32,14 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
private static final String SETTINGS_CLEARCACHE = "clear_cache";
private static final String SETTINGS_CLEARHISTORY = "clear_history";
private static final String SETTINGS_CLEARCOOKIES = "clear_cookies";
+ private static final String SETTINGS_CLEARWEBSTORAGE = "clear_webstorage";
+ private static final String SETTINGS_WEBSTORAGEEXIT = "clear_webstorage_exit";
private static final int API = android.os.Build.VERSION.SDK_INT;
private Activity mActivity;
private PreferenceManager mPreferences;
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit,
- cbcookiesexit, cbsynchistory;
+ cbcookiesexit, cbsynchistory, cbwebstorageexit;
private boolean mSystemBrowser;
private Handler messageHandler;
@@ -66,6 +62,8 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
+ Preference clearwebstorage = findPreference(SETTINGS_CLEARWEBSTORAGE);
+
cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION);
cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES);
cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD);
@@ -73,10 +71,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT);
cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT);
cbsynchistory = (CheckBoxPreference) findPreference(SETTINGS_SYNCHISTORY);
+ cbwebstorageexit = (CheckBoxPreference) findPreference(SETTINGS_WEBSTORAGEEXIT);
clearcache.setOnPreferenceClickListener(this);
clearhistory.setOnPreferenceClickListener(this);
clearcookies.setOnPreferenceClickListener(this);
+ clearwebstorage.setOnPreferenceClickListener(this);
+
cblocation.setOnPreferenceChangeListener(this);
cb3cookies.setOnPreferenceChangeListener(this);
cbsavepasswords.setOnPreferenceChangeListener(this);
@@ -84,6 +85,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
cbhistoryexit.setOnPreferenceChangeListener(this);
cbcookiesexit.setOnPreferenceChangeListener(this);
cbsynchistory.setOnPreferenceChangeListener(this);
+ cbwebstorageexit.setOnPreferenceChangeListener(this);
cblocation.setChecked(mPreferences.getLocationEnabled());
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled());
@@ -91,6 +93,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled());
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled());
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled());
+ cbwebstorageexit.setChecked(mPreferences.getClearWebStorageExitEnabled());
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
@@ -141,6 +144,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
case SETTINGS_CLEARCOOKIES:
clearCookiesDialog();
return true;
+ case SETTINGS_CLEARWEBSTORAGE:
+ clearWebStorage();
+ return true;
default:
return false;
}
@@ -203,43 +209,21 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
}
- @SuppressWarnings("deprecation")
private void clearHistory() {
- mActivity.deleteDatabase(HistoryDatabase.DATABASE_NAME);
- WebViewDatabase m = WebViewDatabase.getInstance(mActivity);
- m.clearFormData();
- m.clearHttpAuthUsernamePassword();
- if (API < 18) {
- m.clearUsernamePassword();
- WebIconDatabase.getInstance().removeAllIcons();
- }
- if (mSystemBrowser) {
- try {
- Browser.clearHistory(mActivity.getContentResolver());
- } catch (Exception ignored) {
- }
- }
- Utils.trimCache(mActivity);
+ WebUtils.clearHistory(getActivity(), mSystemBrowser);
messageHandler.sendEmptyMessage(1);
}
- @SuppressWarnings("deprecation")
private void clearCookies() {
- // TODO Break out web storage deletion into its own option/action
- // TODO clear web storage for all sites that are visited in Incognito mode
- WebStorage storage = WebStorage.getInstance();
- storage.deleteAllData();
- CookieManager c = CookieManager.getInstance();
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- c.removeAllCookies(null);
- } else {
- CookieSyncManager.createInstance(mActivity);
- c.removeAllCookie();
- }
+ WebUtils.clearCookies(getActivity());
messageHandler.sendEmptyMessage(2);
}
+ private void clearWebStorage() {
+ WebUtils.clearWebStorage();
+ Utils.showSnackbar(getActivity(), R.string.message_web_storage_cleared);
+ }
+
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// switch preferences
@@ -268,6 +252,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
mPreferences.setClearCookiesExitEnabled((Boolean) newValue);
cbcookiesexit.setChecked((Boolean) newValue);
return true;
+ case SETTINGS_WEBSTORAGEEXIT:
+ mPreferences.setClearWebStorageExitEnabled((Boolean) newValue);
+ cbwebstorageexit.setChecked((Boolean) newValue);
+ return true;
case SETTINGS_SYNCHISTORY:
mPreferences.setSyncHistoryEnabled((Boolean) newValue);
cbsynchistory.setChecked((Boolean) newValue);
diff --git a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
index 2e01414..7d801b4 100644
--- a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
+++ b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
@@ -48,6 +48,7 @@ public class PreferenceManager {
public static final String THEME = "Theme";
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
public static final String TEXT_ENCODING = "textEncoding";
+ public static final String CLEAR_WEBSTORAGE_EXIT = "clearWebStorageExit";
public static final String USE_PROXY = "useProxy";
public static final String PROXY_CHOICE = "proxyChoice";
@@ -101,6 +102,10 @@ public class PreferenceManager {
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
}
+ public boolean getClearWebStorageExitEnabled() {
+ return mPrefs.getBoolean(Name.CLEAR_WEBSTORAGE_EXIT, false);
+ }
+
public boolean getClearHistoryExitEnabled() {
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
}
@@ -297,6 +302,10 @@ public class PreferenceManager {
putBoolean(Name.CLEAR_COOKIES_EXIT, enable);
}
+ public void setClearWebStorageExitEnabled(boolean enable) {
+ putBoolean(Name.CLEAR_WEBSTORAGE_EXIT, enable);
+ }
+
public void setClearHistoryExitEnabled(boolean enable) {
putBoolean(Name.CLEAR_HISTORY_EXIT, enable);
}
diff --git a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java
new file mode 100644
index 0000000..dbda4af
--- /dev/null
+++ b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java
@@ -0,0 +1,59 @@
+package acr.browser.lightning.utils;
+
+import android.content.Context;
+import android.os.Build;
+import android.provider.Browser;
+import android.support.annotation.NonNull;
+import android.webkit.CookieManager;
+import android.webkit.CookieSyncManager;
+import android.webkit.WebIconDatabase;
+import android.webkit.WebStorage;
+import android.webkit.WebView;
+import android.webkit.WebViewDatabase;
+
+import acr.browser.lightning.database.HistoryDatabase;
+
+/**
+ * Copyright 8/4/2015 Anthony Restaino
+ */
+public class WebUtils {
+
+ public static void clearCookies(@NonNull Context context) {
+ CookieManager c = CookieManager.getInstance();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ c.removeAllCookies(null);
+ } else {
+ CookieSyncManager.createInstance(context);
+ c.removeAllCookie();
+ }
+ }
+
+ public static void clearWebStorage() {
+ WebStorage.getInstance().deleteAllData();
+ }
+
+ public static void clearHistory(@NonNull Context context, boolean systemBrowserPresent) {
+ context.deleteDatabase(HistoryDatabase.DATABASE_NAME);
+ WebViewDatabase m = WebViewDatabase.getInstance(context);
+ m.clearFormData();
+ m.clearHttpAuthUsernamePassword();
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ m.clearUsernamePassword();
+ WebIconDatabase.getInstance().removeAllIcons();
+ }
+ if (systemBrowserPresent) {
+ try {
+ Browser.clearHistory(context.getContentResolver());
+ } catch (NullPointerException ignored) {
+ // ignored
+ }
+ }
+ Utils.trimCache(context);
+ }
+
+ public static void clearCache(WebView view) {
+ if (view == null) return;
+ view.clearCache(true);
+ }
+
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3271a9c..74f27e7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -210,4 +210,7 @@
Rename
Rename Folder
What would you like to do with this folder?
+ Clear Web Storage
+ Clear web storage on exit
+ Web Storage Cleared
diff --git a/app/src/main/res/xml/preference_privacy.xml b/app/src/main/res/xml/preference_privacy.xml
index 9dede77..9a493ec 100644
--- a/app/src/main/res/xml/preference_privacy.xml
+++ b/app/src/main/res/xml/preference_privacy.xml
@@ -13,8 +13,8 @@
+ android:summary="@string/recommended"
+ android:title="@string/password" />
+
+
\ No newline at end of file