Add option to clear Web Storage
This commit is contained in:
parent
3b13999b03
commit
08eedbe121
@ -70,15 +70,11 @@ import android.view.animation.DecelerateInterpolator;
|
|||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.webkit.CookieManager;
|
|
||||||
import android.webkit.CookieSyncManager;
|
|
||||||
import android.webkit.ValueCallback;
|
import android.webkit.ValueCallback;
|
||||||
import android.webkit.WebChromeClient.CustomViewCallback;
|
import android.webkit.WebChromeClient.CustomViewCallback;
|
||||||
import android.webkit.WebIconDatabase;
|
import android.webkit.WebIconDatabase;
|
||||||
import android.webkit.WebStorage;
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebView.HitTestResult;
|
import android.webkit.WebView.HitTestResult;
|
||||||
import android.webkit.WebViewDatabase;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
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.ProxyUtils;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
import acr.browser.lightning.utils.WebUtils;
|
||||||
import acr.browser.lightning.view.AnimatedProgressBar;
|
import acr.browser.lightning.view.AnimatedProgressBar;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
|
||||||
@ -1291,21 +1288,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
closeActivity();
|
closeActivity();
|
||||||
} else {
|
} else {
|
||||||
mWebViewList.remove(position);
|
mWebViewList.remove(position);
|
||||||
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
|
performExitCleanUp();
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
|
||||||
reference.pauseTimers();
|
reference.pauseTimers();
|
||||||
reference.onDestroy();
|
reference.onDestroy();
|
||||||
mCurrentView = null;
|
mCurrentView = null;
|
||||||
@ -1325,6 +1308,30 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
Log.d(Constants.TAG, "deleted tab");
|
Log.d(Constants.TAG, "deleted tab");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void performExitCleanUp() {
|
||||||
|
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
|
||||||
|
WebUtils.clearCache(mCurrentView.getWebView());
|
||||||
|
Log.d(Constants.TAG, "Cache Cleared");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
|
||||||
|
WebUtils.clearHistory(this, mSystemBrowser);
|
||||||
|
Log.d(Constants.TAG, "History Cleared");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
|
||||||
|
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
|
@Override
|
||||||
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
@ -1335,21 +1342,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
|
|
||||||
private void closeBrowser() {
|
private void closeBrowser() {
|
||||||
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||||||
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
|
performExitCleanUp();
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
|
||||||
mCurrentView = null;
|
mCurrentView = null;
|
||||||
mWebView = null;
|
mWebView = null;
|
||||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||||
@ -1362,38 +1355,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
finish();
|
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
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
||||||
|
@ -12,19 +12,13 @@ import android.os.Message;
|
|||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.provider.Browser;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
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.WebView;
|
||||||
import android.webkit.WebViewDatabase;
|
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.database.HistoryDatabase;
|
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
import acr.browser.lightning.utils.WebUtils;
|
||||||
|
|
||||||
public class PrivacySettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
|
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_CLEARCACHE = "clear_cache";
|
||||||
private static final String SETTINGS_CLEARHISTORY = "clear_history";
|
private static final String SETTINGS_CLEARHISTORY = "clear_history";
|
||||||
private static final String SETTINGS_CLEARCOOKIES = "clear_cookies";
|
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 static final int API = android.os.Build.VERSION.SDK_INT;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private PreferenceManager mPreferences;
|
private PreferenceManager mPreferences;
|
||||||
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit,
|
private CheckBoxPreference cblocation, cb3cookies, cbsavepasswords, cbcacheexit, cbhistoryexit,
|
||||||
cbcookiesexit, cbsynchistory;
|
cbcookiesexit, cbsynchistory, cbwebstorageexit;
|
||||||
private boolean mSystemBrowser;
|
private boolean mSystemBrowser;
|
||||||
private Handler messageHandler;
|
private Handler messageHandler;
|
||||||
|
|
||||||
@ -66,6 +62,8 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
|
Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
|
||||||
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
|
Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
|
||||||
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
|
Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
|
||||||
|
Preference clearwebstorage = findPreference(SETTINGS_CLEARWEBSTORAGE);
|
||||||
|
|
||||||
cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION);
|
cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION);
|
||||||
cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES);
|
cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES);
|
||||||
cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD);
|
cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD);
|
||||||
@ -73,10 +71,13 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT);
|
cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT);
|
||||||
cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT);
|
cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT);
|
||||||
cbsynchistory = (CheckBoxPreference) findPreference(SETTINGS_SYNCHISTORY);
|
cbsynchistory = (CheckBoxPreference) findPreference(SETTINGS_SYNCHISTORY);
|
||||||
|
cbwebstorageexit = (CheckBoxPreference) findPreference(SETTINGS_WEBSTORAGEEXIT);
|
||||||
|
|
||||||
clearcache.setOnPreferenceClickListener(this);
|
clearcache.setOnPreferenceClickListener(this);
|
||||||
clearhistory.setOnPreferenceClickListener(this);
|
clearhistory.setOnPreferenceClickListener(this);
|
||||||
clearcookies.setOnPreferenceClickListener(this);
|
clearcookies.setOnPreferenceClickListener(this);
|
||||||
|
clearwebstorage.setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
cblocation.setOnPreferenceChangeListener(this);
|
cblocation.setOnPreferenceChangeListener(this);
|
||||||
cb3cookies.setOnPreferenceChangeListener(this);
|
cb3cookies.setOnPreferenceChangeListener(this);
|
||||||
cbsavepasswords.setOnPreferenceChangeListener(this);
|
cbsavepasswords.setOnPreferenceChangeListener(this);
|
||||||
@ -84,6 +85,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
cbhistoryexit.setOnPreferenceChangeListener(this);
|
cbhistoryexit.setOnPreferenceChangeListener(this);
|
||||||
cbcookiesexit.setOnPreferenceChangeListener(this);
|
cbcookiesexit.setOnPreferenceChangeListener(this);
|
||||||
cbsynchistory.setOnPreferenceChangeListener(this);
|
cbsynchistory.setOnPreferenceChangeListener(this);
|
||||||
|
cbwebstorageexit.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
cblocation.setChecked(mPreferences.getLocationEnabled());
|
cblocation.setChecked(mPreferences.getLocationEnabled());
|
||||||
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled());
|
cbsavepasswords.setChecked(mPreferences.getSavePasswordsEnabled());
|
||||||
@ -91,6 +93,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled());
|
cbhistoryexit.setChecked(mPreferences.getClearHistoryExitEnabled());
|
||||||
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled());
|
cbcookiesexit.setChecked(mPreferences.getClearCookiesExitEnabled());
|
||||||
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled());
|
cb3cookies.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled());
|
||||||
|
cbwebstorageexit.setChecked(mPreferences.getClearWebStorageExitEnabled());
|
||||||
|
|
||||||
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
||||||
|
|
||||||
@ -141,6 +144,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
case SETTINGS_CLEARCOOKIES:
|
case SETTINGS_CLEARCOOKIES:
|
||||||
clearCookiesDialog();
|
clearCookiesDialog();
|
||||||
return true;
|
return true;
|
||||||
|
case SETTINGS_CLEARWEBSTORAGE:
|
||||||
|
clearWebStorage();
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -203,43 +209,21 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
|
Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void clearHistory() {
|
private void clearHistory() {
|
||||||
mActivity.deleteDatabase(HistoryDatabase.DATABASE_NAME);
|
WebUtils.clearHistory(getActivity(), mSystemBrowser);
|
||||||
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);
|
|
||||||
messageHandler.sendEmptyMessage(1);
|
messageHandler.sendEmptyMessage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void clearCookies() {
|
private void clearCookies() {
|
||||||
// TODO Break out web storage deletion into its own option/action
|
WebUtils.clearCookies(getActivity());
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
messageHandler.sendEmptyMessage(2);
|
messageHandler.sendEmptyMessage(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearWebStorage() {
|
||||||
|
WebUtils.clearWebStorage();
|
||||||
|
Utils.showSnackbar(getActivity(), R.string.message_web_storage_cleared);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
// switch preferences
|
// switch preferences
|
||||||
@ -268,6 +252,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
mPreferences.setClearCookiesExitEnabled((Boolean) newValue);
|
mPreferences.setClearCookiesExitEnabled((Boolean) newValue);
|
||||||
cbcookiesexit.setChecked((Boolean) newValue);
|
cbcookiesexit.setChecked((Boolean) newValue);
|
||||||
return true;
|
return true;
|
||||||
|
case SETTINGS_WEBSTORAGEEXIT:
|
||||||
|
mPreferences.setClearWebStorageExitEnabled((Boolean) newValue);
|
||||||
|
cbwebstorageexit.setChecked((Boolean) newValue);
|
||||||
|
return true;
|
||||||
case SETTINGS_SYNCHISTORY:
|
case SETTINGS_SYNCHISTORY:
|
||||||
mPreferences.setSyncHistoryEnabled((Boolean) newValue);
|
mPreferences.setSyncHistoryEnabled((Boolean) newValue);
|
||||||
cbsynchistory.setChecked((Boolean) newValue);
|
cbsynchistory.setChecked((Boolean) newValue);
|
||||||
|
@ -48,6 +48,7 @@ public class PreferenceManager {
|
|||||||
public static final String THEME = "Theme";
|
public static final String THEME = "Theme";
|
||||||
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
|
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
|
||||||
public static final String TEXT_ENCODING = "textEncoding";
|
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 USE_PROXY = "useProxy";
|
||||||
public static final String PROXY_CHOICE = "proxyChoice";
|
public static final String PROXY_CHOICE = "proxyChoice";
|
||||||
@ -101,6 +102,10 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
|
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getClearWebStorageExitEnabled() {
|
||||||
|
return mPrefs.getBoolean(Name.CLEAR_WEBSTORAGE_EXIT, false);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getClearHistoryExitEnabled() {
|
public boolean getClearHistoryExitEnabled() {
|
||||||
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
|
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
|
||||||
}
|
}
|
||||||
@ -297,6 +302,10 @@ public class PreferenceManager {
|
|||||||
putBoolean(Name.CLEAR_COOKIES_EXIT, enable);
|
putBoolean(Name.CLEAR_COOKIES_EXIT, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setClearWebStorageExitEnabled(boolean enable) {
|
||||||
|
putBoolean(Name.CLEAR_WEBSTORAGE_EXIT, enable);
|
||||||
|
}
|
||||||
|
|
||||||
public void setClearHistoryExitEnabled(boolean enable) {
|
public void setClearHistoryExitEnabled(boolean enable) {
|
||||||
putBoolean(Name.CLEAR_HISTORY_EXIT, enable);
|
putBoolean(Name.CLEAR_HISTORY_EXIT, enable);
|
||||||
}
|
}
|
||||||
|
59
app/src/main/java/acr/browser/lightning/utils/WebUtils.java
Normal file
59
app/src/main/java/acr/browser/lightning/utils/WebUtils.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -210,4 +210,7 @@
|
|||||||
<string name="action_rename">Rename</string>
|
<string name="action_rename">Rename</string>
|
||||||
<string name="title_rename_folder">Rename Folder</string>
|
<string name="title_rename_folder">Rename Folder</string>
|
||||||
<string name="dialog_folder">What would you like to do with this folder?</string>
|
<string name="dialog_folder">What would you like to do with this folder?</string>
|
||||||
|
<string name="clear_web_storage">Clear Web Storage</string>
|
||||||
|
<string name="clear_web_storage_exit">Clear web storage on exit</string>
|
||||||
|
<string name="message_web_storage_cleared">Web Storage Cleared</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="password"
|
android:key="password"
|
||||||
android:title="@string/password"
|
android:summary="@string/recommended"
|
||||||
android:summary="@string/recommended" />
|
android:title="@string/password" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="clear_cache_exit"
|
android:key="clear_cache_exit"
|
||||||
@ -27,6 +27,10 @@
|
|||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="clear_cookies_exit"
|
android:key="clear_cookies_exit"
|
||||||
android:title="@string/clear_cookies_exit" />
|
android:title="@string/clear_cookies_exit" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="clear_webstorage_exit"
|
||||||
|
android:title="@string/clear_web_storage_exit" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="sync_history"
|
android:key="sync_history"
|
||||||
@ -40,5 +44,8 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="clear_cookies"
|
android:key="clear_cookies"
|
||||||
android:title="@string/clear_cookies" />
|
android:title="@string/clear_cookies" />
|
||||||
|
<Preference
|
||||||
|
android:key="clear_webstorage"
|
||||||
|
android:title="@string/clear_web_storage" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user