summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser/BrowserSettings.java')
-rw-r--r--src/com/android/browser/BrowserSettings.java137
1 files changed, 127 insertions, 10 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 236955493..415e72da9 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -22,6 +22,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Build;
import android.os.Message;
import android.preference.PreferenceManager;
@@ -32,11 +34,12 @@ import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions;
import android.webkit.WebIconDatabase;
import android.webkit.WebSettings;
-import android.webkit.WebSettings.AutoFillProfile;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebSettings.TextSize;
import android.webkit.WebSettings.ZoomDensity;
+import android.webkit.WebSettingsClassic;
+import android.webkit.WebSettingsClassic.AutoFillProfile;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewDatabase;
@@ -114,6 +117,9 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
private boolean mNeedsSharedSync = true;
private float mFontSizeMult = 1.0f;
+ // Current state of network-dependent settings
+ private boolean mLinkPrefetchAllowed = true;
+
// Cached values
private int mPageCacheCapacity = 1;
private String mAppCachePath;
@@ -149,16 +155,28 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
}
public void startManagingSettings(WebSettings settings) {
+ WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
if (mNeedsSharedSync) {
syncSharedSettings();
}
synchronized (mManagedSettings) {
- syncStaticSettings(settings);
- syncSetting(settings);
+ syncStaticSettings(settingsClassic);
+ syncSetting(settingsClassic);
mManagedSettings.add(new WeakReference<WebSettings>(settings));
}
}
+ public void stopManagingSettings(WebSettings settings) {
+ Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
+ while (iter.hasNext()) {
+ WeakReference<WebSettings> ref = iter.next();
+ if (ref.get() == settings) {
+ iter.remove();
+ return;
+ }
+ }
+ }
+
private Runnable mSetup = new Runnable() {
@Override
@@ -174,8 +192,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
mWebStorageSizeManager = new WebStorageSizeManager(mContext,
new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
- // Workaround b/5253777
- CookieManager.getInstance().acceptCookie();
// Workaround b/5254577
mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
if (Build.VERSION.CODENAME.equals("REL")) {
@@ -235,7 +251,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
/**
* Syncs all the settings that have a Preference UI
*/
- private void syncSetting(WebSettings settings) {
+ private void syncSetting(WebSettingsClassic settings) {
settings.setGeolocationEnabled(enableGeolocation());
settings.setJavaScriptEnabled(enableJavascript());
settings.setLightTouchEnabled(enableLightTouch());
@@ -279,13 +295,15 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
settings.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
enableCpuUploadPath() ? "true" : "false");
}
+
+ settings.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
}
/**
* Syncs all the settings that have no UI
* These cannot change, so we only need to set them once per WebSettings
*/
- private void syncStaticSettings(WebSettings settings) {
+ private void syncStaticSettings(WebSettingsClassic settings) {
settings.setDefaultFontSize(16);
settings.setDefaultFixedFontSize(13);
settings.setPageCacheCapacity(getPageCacheCapacity());
@@ -334,7 +352,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
while (iter.hasNext()) {
WeakReference<WebSettings> ref = iter.next();
- WebSettings settings = ref.get();
+ WebSettingsClassic settings = (WebSettingsClassic)ref.get();
if (settings == null) {
iter.remove();
continue;
@@ -350,8 +368,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
syncManagedSettings();
if (PREF_SEARCH_ENGINE.equals(key)) {
updateSearchEngine(false);
- }
- if (PREF_FULLSCREEN.equals(key)) {
+ } else if (PREF_FULLSCREEN.equals(key)) {
if (mController.getUi() != null) {
mController.getUi().setFullscreen(useFullscreen());
}
@@ -359,6 +376,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
if (mController.getUi() != null) {
mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
}
+ } else if (PREF_LINK_PREFETCH.equals(key)) {
+ updateConnectionType();
}
}
@@ -565,6 +584,37 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
return mPrefs;
}
+ // update connectivity-dependent options
+ public void updateConnectionType() {
+ ConnectivityManager cm = (ConnectivityManager)
+ mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ String linkPrefetchPreference = getLinkPrefetchEnabled();
+ boolean linkPrefetchAllowed = linkPrefetchPreference.
+ equals(getLinkPrefetchAlwaysPreferenceString(mContext));
+ NetworkInfo ni = cm.getActiveNetworkInfo();
+ if (ni != null) {
+ switch (ni.getType()) {
+ case ConnectivityManager.TYPE_WIFI:
+ case ConnectivityManager.TYPE_ETHERNET:
+ case ConnectivityManager.TYPE_BLUETOOTH:
+ linkPrefetchAllowed |= linkPrefetchPreference.
+ equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
+ break;
+ case ConnectivityManager.TYPE_MOBILE:
+ case ConnectivityManager.TYPE_MOBILE_DUN:
+ case ConnectivityManager.TYPE_MOBILE_MMS:
+ case ConnectivityManager.TYPE_MOBILE_SUPL:
+ case ConnectivityManager.TYPE_WIMAX:
+ default:
+ break;
+ }
+ }
+ if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
+ mLinkPrefetchAllowed = linkPrefetchAllowed;
+ syncManagedSettings();
+ }
+ }
+
// -----------------------------
// getter/setters for accessibility_preferences.xml
// -----------------------------
@@ -847,4 +897,71 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
}
+ public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
+ }
+
+ public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_link_prefetch_value_always);
+ }
+
+ private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
+ "browser_default_link_prefetch_setting";
+
+ public String getDefaultLinkPrefetchSetting() {
+ String preload = Settings.Secure.getString(mContext.getContentResolver(),
+ DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
+ if (preload == null) {
+ preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
+ }
+ return preload;
+ }
+
+ public String getLinkPrefetchEnabled() {
+ return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
+ }
+
+ // -----------------------------
+ // getter/setters for browser recovery
+ // -----------------------------
+ /**
+ * The last time browser was started.
+ * @return The last browser start time as System.currentTimeMillis. This
+ * can be 0 if this is the first time or the last tab was closed.
+ */
+ public long getLastRecovered() {
+ return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
+ }
+
+ /**
+ * Sets the last browser start time.
+ * @param time The last time as System.currentTimeMillis that the browser
+ * was started. This should be set to 0 if the last tab is closed.
+ */
+ public void setLastRecovered(long time) {
+ mPrefs.edit()
+ .putLong(KEY_LAST_RECOVERED, time)
+ .apply();
+ }
+
+ /**
+ * Used to determine whether or not the previous browser run crashed. Once
+ * the previous state has been determined, the value will be set to false
+ * until a pause is received.
+ * @return true if the last browser run was paused or false if it crashed.
+ */
+ public boolean wasLastRunPaused() {
+ return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
+ }
+
+ /**
+ * Sets whether or not the last run was a pause or crash.
+ * @param isPaused Set to true When a pause is received or false after
+ * resuming.
+ */
+ public void setLastRunPaused(boolean isPaused) {
+ mPrefs.edit()
+ .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
+ .apply();
+ }
}