blob: 95afa71cfa21f1d1b3b42c7dbb1961508a68a6d9 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
Grace Kloba9804c432009-12-02 11:07:40 -080019import android.app.ActivityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.content.ContentResolver;
21import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070023import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080024import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070025import android.net.ConnectivityManager;
26import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070027import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010028import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010029import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010030import android.provider.Browser;
Mathew Inwood825fba72011-10-04 14:52:52 +010031import android.provider.Settings;
John Reck5ba3c762011-09-14 15:00:15 -070032import android.util.DisplayMetrics;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010034import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035import android.webkit.WebIconDatabase;
36import android.webkit.WebSettings;
John Reck35e9dd62011-04-25 09:01:54 -070037import android.webkit.WebSettings.LayoutAlgorithm;
38import android.webkit.WebSettings.PluginState;
39import android.webkit.WebSettings.TextSize;
40import android.webkit.WebSettings.ZoomDensity;
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +000041import android.webkit.WebSettingsClassic;
42import android.webkit.WebSettingsClassic.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010043import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080044import android.webkit.WebView;
45import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046
John Reck46500332011-06-07 14:36:10 -070047import com.android.browser.homepages.HomeProvider;
48import com.android.browser.provider.BrowserProvider;
49import com.android.browser.search.SearchEngine;
50import com.android.browser.search.SearchEngines;
51
John Reck35e9dd62011-04-25 09:01:54 -070052import java.lang.ref.WeakReference;
53import java.util.Iterator;
54import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070055import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080056
John Reck35e9dd62011-04-25 09:01:54 -070057/**
58 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080059 */
John Reck35e9dd62011-04-25 09:01:54 -070060public class BrowserSettings implements OnSharedPreferenceChangeListener,
61 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010062
John Reck35e9dd62011-04-25 09:01:54 -070063 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070064 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
65 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
66 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080067
68 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070069 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
70 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070071
72 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070073 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
74 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070075
76 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070077 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
78 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080079
John Reck7fd1e8f2011-04-27 18:22:57 -070080 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
81 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
82 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
83
John Reck35e9dd62011-04-25 09:01:54 -070084 private static final String USER_AGENTS[] = { null,
85 DESKTOP_USERAGENT,
86 IPHONE_USERAGENT,
87 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070088 FROYO_USERAGENT,
89 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070090 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080091
John Reck8fc22a12011-06-16 14:57:41 -070092 // The minimum min font size
93 // Aka, the lower bounds for the min font size range
94 // which is 1:5..24
95 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070096 // The initial value in the text zoom range
97 // This is what represents 100% in the SeekBarPreference range
98 private static final int TEXT_ZOOM_START_VAL = 10;
99 // The size of a single step in the text zoom range, in percent
100 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700101 // The initial value in the double tap zoom range
102 // This is what represents 100% in the SeekBarPreference range
103 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
104 // The size of a single step in the double tap zoom range, in percent
105 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -0700106
John Reck35e9dd62011-04-25 09:01:54 -0700107 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -0700108
John Reck35e9dd62011-04-25 09:01:54 -0700109 private Context mContext;
110 private SharedPreferences mPrefs;
111 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -0700113 private WebStorageSizeManager mWebStorageSizeManager;
114 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -0700115 private WeakHashMap<WebSettings, String> mCustomUserAgents;
Ben Murdochaaa1f372011-07-25 15:40:58 +0100116 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -0700117 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -0700118 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -0700119
Victoria Lease96497832012-03-23 14:19:56 -0700120 // Current state of network-dependent settings
121 private boolean mLinkPrefetchAllowed = true;
122
John Reck78a6a1d2011-07-21 13:54:03 -0700123 // Cached values
124 private int mPageCacheCapacity = 1;
125 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800126
John Reck35e9dd62011-04-25 09:01:54 -0700127 // Cached settings
128 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129
Ben Murdochaaa1f372011-07-25 15:40:58 +0100130 private static String sFactoryResetUrl;
131
John Reck35e9dd62011-04-25 09:01:54 -0700132 public static void initialize(final Context context) {
133 sInstance = new BrowserSettings(context);
134 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135
John Reck35e9dd62011-04-25 09:01:54 -0700136 public static BrowserSettings getInstance() {
137 return sInstance;
138 }
Ben Murdochef671652010-11-25 17:17:58 +0000139
John Reck35e9dd62011-04-25 09:01:54 -0700140 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100141 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700142 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
143 mAutofillHandler = new AutofillHandler(mContext);
144 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700145 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reck35e9dd62011-04-25 09:01:54 -0700146 mAutofillHandler.asyncLoadFromDb();
John Reckcadae722011-07-25 11:36:17 -0700147 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700148 }
149
150 public void setController(Controller controller) {
151 mController = controller;
John Reckc477e712011-08-17 11:27:15 -0700152 if (sInitialized) {
153 syncSharedSettings();
154 }
Ben Murdochef671652010-11-25 17:17:58 +0000155 }
156
John Reck35e9dd62011-04-25 09:01:54 -0700157 public void startManagingSettings(WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800158
John Reckc477e712011-08-17 11:27:15 -0700159 if (mNeedsSharedSync) {
160 syncSharedSettings();
161 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800162
John Reck35e9dd62011-04-25 09:01:54 -0700163 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800164 syncStaticSettings(settings);
165 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700166 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800167 }
168 }
169
John Reckd1d87312012-03-08 13:25:00 -0800170 public void stopManagingSettings(WebSettings settings) {
171 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
172 while (iter.hasNext()) {
173 WeakReference<WebSettings> ref = iter.next();
174 if (ref.get() == settings) {
175 iter.remove();
176 return;
177 }
178 }
179 }
180
John Reckcadae722011-07-25 11:36:17 -0700181 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700182
183 @Override
184 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700185 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
186 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700187 // the cost of one cached page is ~3M (measured using nytimes.com). For
188 // low end devices, we only cache one page. For high end devices, we try
189 // to cache more pages, currently choose 5.
190 if (ActivityManager.staticGetMemoryClass() > 16) {
191 mPageCacheCapacity = 5;
192 }
193 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
194 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
195 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700196 // Workaround b/5254577
197 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700198 if (Build.VERSION.CODENAME.equals("REL")) {
199 // This is a release build, always startup with debug disabled
200 setDebugEnabled(false);
201 }
202 if (mPrefs.contains(PREF_TEXT_SIZE)) {
203 /*
204 * Update from TextSize enum to zoom percent
205 * SMALLEST is 50%
206 * SMALLER is 75%
207 * NORMAL is 100%
208 * LARGER is 150%
209 * LARGEST is 200%
210 */
211 switch (getTextSize()) {
212 case SMALLEST:
213 setTextZoom(50);
214 break;
215 case SMALLER:
216 setTextZoom(75);
217 break;
218 case LARGER:
219 setTextZoom(150);
220 break;
221 case LARGEST:
222 setTextZoom(200);
223 break;
224 }
225 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
226 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100227
228 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
229 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
230 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
231 BrowserProvider.getClientId(mContext.getContentResolver()));
232 }
233
Ben Murdochaaa1f372011-07-25 15:40:58 +0100234 synchronized (BrowserSettings.class) {
235 sInitialized = true;
236 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700237 }
238 }
239 };
240
Ben Murdochaaa1f372011-07-25 15:40:58 +0100241 private static void requireInitialization() {
242 synchronized (BrowserSettings.class) {
243 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700244 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100245 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700246 } catch (InterruptedException e) {
247 }
248 }
249 }
250 }
251
The Android Open Source Project0c908882009-03-03 19:32:16 -0800252 /**
John Reck35e9dd62011-04-25 09:01:54 -0700253 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800254 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800255 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700256 settings.setGeolocationEnabled(enableGeolocation());
257 settings.setJavaScriptEnabled(enableJavascript());
258 settings.setLightTouchEnabled(enableLightTouch());
259 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700260 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
261 settings.setDefaultZoom(getDefaultZoom());
262 settings.setMinimumFontSize(getMinimumFontSize());
263 settings.setMinimumLogicalFontSize(getMinimumFontSize());
264 settings.setPluginState(getPluginState());
John Reck7dc444b2011-06-16 17:44:29 -0700265 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700266 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100267 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700268 settings.setLoadsImagesAutomatically(loadImages());
269 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
270 settings.setSavePassword(rememberPasswords());
271 settings.setSaveFormData(saveFormdata());
272 settings.setUseWideViewPort(isWideViewport());
John Reckb8b2af82011-05-20 15:58:33 -0700273
274 String ua = mCustomUserAgents.get(settings);
John Reck46500332011-06-07 14:36:10 -0700275 if (ua != null) {
John Reckb8b2af82011-05-20 15:58:33 -0700276 settings.setUserAgentString(ua);
277 } else {
278 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
279 }
John Reck2fd9d0e2011-07-15 11:13:48 -0700280
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800281 if (!(settings instanceof WebSettingsClassic)) return;
282
283 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
284 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
285 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
286 settingsClassic.setForceUserScalable(forceEnableUserScalable());
287 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
288 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
289 settingsClassic.setAutoFillProfile(getAutoFillProfile());
290
John Reckea17e782011-10-27 17:15:59 -0700291 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800292 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700293 useInverted ? "true" : "false");
294 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800295 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700296 Float.toString(getInvertedContrast()));
297 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700298
John Reckea17e782011-10-27 17:15:59 -0700299 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800300 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700301 enableCpuUploadPath() ? "true" : "false");
302 }
Victoria Lease96497832012-03-23 14:19:56 -0700303
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800304 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000305 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800306
John Reck35e9dd62011-04-25 09:01:54 -0700307 /**
308 * Syncs all the settings that have no UI
309 * These cannot change, so we only need to set them once per WebSettings
310 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800311 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700312 settings.setDefaultFontSize(16);
313 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000314
John Reck35e9dd62011-04-25 09:01:54 -0700315 // WebView inside Browser doesn't want initial focus to be set.
316 settings.setNeedInitialFocus(false);
317 // Browser supports multiple windows
318 settings.setSupportMultipleWindows(true);
319 // enable smooth transition for better performance during panning or
320 // zooming
321 settings.setEnableSmoothTransition(true);
322 // disable content url access
323 settings.setAllowContentAccess(false);
324
325 // HTML5 API flags
326 settings.setAppCacheEnabled(true);
327 settings.setDatabaseEnabled(true);
328 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700329
330 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700331 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700332 settings.setAppCachePath(getAppCachePath());
333 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
334 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700335 // origin policy for file access
336 settings.setAllowUniversalAccessFromFileURLs(false);
337 settings.setAllowFileAccessFromFileURLs(false);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800338
339 if (!(settings instanceof WebSettingsClassic)) return;
340
341 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
342 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
343 // WebView should be preserving the memory as much as possible.
344 // However, apps like browser wish to turn on the performance mode which
345 // would require more memory.
346 // TODO: We need to dynamically allocate/deallocate temporary memory for
347 // apps which are trying to use minimal memory. Currently, double
348 // buffering is always turned on, which is unnecessary.
349 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
350 settingsClassic.setWorkersEnabled(true); // This only affects V8.
John Reck35e9dd62011-04-25 09:01:54 -0700351 }
352
353 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700354 mNeedsSharedSync = false;
John Reck35e9dd62011-04-25 09:01:54 -0700355 CookieManager.getInstance().setAcceptCookie(acceptCookies());
356 if (mController != null) {
357 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700358 }
John Reck35e9dd62011-04-25 09:01:54 -0700359 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700360
John Reck35e9dd62011-04-25 09:01:54 -0700361 private void syncManagedSettings() {
362 syncSharedSettings();
363 synchronized (mManagedSettings) {
364 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
365 while (iter.hasNext()) {
366 WeakReference<WebSettings> ref = iter.next();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800367 WebSettings settings = ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700368 if (settings == null) {
369 iter.remove();
370 continue;
371 }
372 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000373 }
John Reck35e9dd62011-04-25 09:01:54 -0700374 }
375 }
Ben Murdochef671652010-11-25 17:17:58 +0000376
John Reck35e9dd62011-04-25 09:01:54 -0700377 @Override
378 public void onSharedPreferenceChanged(
379 SharedPreferences sharedPreferences, String key) {
380 syncManagedSettings();
381 if (PREF_SEARCH_ENGINE.equals(key)) {
382 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700383 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200384 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700385 mController.getUi().setFullscreen(useFullscreen());
386 }
Michael Kolb0241e752011-07-07 14:58:50 -0700387 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200388 if (mController != null && mController.getUi() != null) {
Michael Kolb0241e752011-07-07 14:58:50 -0700389 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
390 }
Victoria Lease96497832012-03-23 14:19:56 -0700391 } else if (PREF_LINK_PREFETCH.equals(key)) {
392 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700393 }
John Reck35e9dd62011-04-25 09:01:54 -0700394 }
395
John Reck961d35d2011-06-23 09:45:54 -0700396 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100397 requireInitialization();
398 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700399 }
400
401 public LayoutAlgorithm getLayoutAlgorithm() {
402 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
403 if (autofitPages()) {
404 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
405 }
406 if (isDebugEnabled()) {
407 if (isSmallScreen()) {
408 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000409 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700410 if (isNormalLayout()) {
411 layoutAlgorithm = LayoutAlgorithm.NORMAL;
412 } else {
413 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
414 }
Ben Murdochef671652010-11-25 17:17:58 +0000415 }
John Reck35e9dd62011-04-25 09:01:54 -0700416 }
417 return layoutAlgorithm;
418 }
Ben Murdochef671652010-11-25 17:17:58 +0000419
John Reck35e9dd62011-04-25 09:01:54 -0700420 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700421 requireInitialization();
422 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800423 }
424
John Reck35e9dd62011-04-25 09:01:54 -0700425 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700426 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700427 return mWebStorageSizeManager;
428 }
429
John Reck35e9dd62011-04-25 09:01:54 -0700430 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700431 if (mAppCachePath == null) {
432 mAppCachePath = mContext.getDir("appcache", 0).getPath();
433 }
434 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700435 }
436
437 private void updateSearchEngine(boolean force) {
438 String searchEngineName = getSearchEngineName();
439 if (force || mSearchEngine == null ||
440 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700441 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000442 }
443 }
444
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100445 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700446 if (mSearchEngine == null) {
447 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100448 }
John Reck35e9dd62011-04-25 09:01:54 -0700449 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100450 }
451
John Reck35e9dd62011-04-25 09:01:54 -0700452 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700453 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700454 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100455 }
456
John Reck35e9dd62011-04-25 09:01:54 -0700457 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700458 Editor edit = mPrefs.edit();
459 edit.putBoolean(PREF_DEBUG_MENU, value);
460 if (!value) {
461 // Reset to "safe" value
462 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
463 }
464 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100465 }
466
John Reck35e9dd62011-04-25 09:01:54 -0700467 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800468 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 if (mController != null) {
470 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800471 if (current != null) {
472 current.clearCache(true);
473 }
474 }
475 }
476
John Reck35e9dd62011-04-25 09:01:54 -0700477 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800478 CookieManager.getInstance().removeAllCookie();
479 }
480
John Reck35e9dd62011-04-25 09:01:54 -0700481 public void clearHistory() {
482 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800483 Browser.clearHistory(resolver);
484 Browser.clearSearches(resolver);
485 }
486
John Reck35e9dd62011-04-25 09:01:54 -0700487 public void clearFormData() {
488 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 if (mController!= null) {
490 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100491 if (currentTopView != null) {
492 currentTopView.clearFormData();
493 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800494 }
495 }
496
John Reck35e9dd62011-04-25 09:01:54 -0700497 public void clearPasswords() {
498 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800499 db.clearUsernamePassword();
500 db.clearHttpAuthUsernamePassword();
501 }
502
John Reck35e9dd62011-04-25 09:01:54 -0700503 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100504 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100505 }
506
John Reck35e9dd62011-04-25 09:01:54 -0700507 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100508 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100509 }
510
John Reck35e9dd62011-04-25 09:01:54 -0700511 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700512 // Preserve autologin setting
513 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1);
514 mPrefs.edit()
515 .clear()
516 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal)
517 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200518 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700519 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700520 }
521
Björn Isakssonc885a242012-06-05 17:19:04 +0200522 private void resetCachedValues() {
523 updateSearchEngine(false);
524 }
525
John Reck35e9dd62011-04-25 09:01:54 -0700526 public AutoFillProfile getAutoFillProfile() {
John Reck35e9dd62011-04-25 09:01:54 -0700527 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800528 }
529
John Reck35e9dd62011-04-25 09:01:54 -0700530 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
John Reck35e9dd62011-04-25 09:01:54 -0700531 mAutofillHandler.setAutoFillProfile(profile, msg);
Ben Murdoch273330a2011-07-08 18:37:22 +0100532 // Auto-fill will reuse the same profile ID when making edits to the profile,
533 // so we need to force a settings sync (otherwise the SharedPreferences
534 // manager will optimise out the call to onSharedPreferenceChanged(), as
535 // it thinks nothing has changed).
536 syncManagedSettings();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800537 }
538
John Reck35e9dd62011-04-25 09:01:54 -0700539 public void toggleDebugSettings() {
540 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800541 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100542
John Reckb8b2af82011-05-20 15:58:33 -0700543 public boolean hasDesktopUseragent(WebView view) {
544 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
545 }
546
547 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700548 if (view == null) {
549 return;
550 }
John Reckb8b2af82011-05-20 15:58:33 -0700551 WebSettings settings = view.getSettings();
552 if (mCustomUserAgents.get(settings) != null) {
553 mCustomUserAgents.remove(settings);
554 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
555 } else {
556 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
557 settings.setUserAgentString(DESKTOP_USERAGENT);
558 }
559 }
560
John Reck7dc444b2011-06-16 17:44:29 -0700561 public static int getAdjustedMinimumFontSize(int rawValue) {
562 rawValue++; // Preference starts at 0, min font at 1
563 if (rawValue > 1) {
564 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
565 }
566 return rawValue;
567 }
568
John Reck5ba3c762011-09-14 15:00:15 -0700569 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700570 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700571 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700572 }
573
574 static int getRawTextZoom(int percent) {
575 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
576 }
577
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700578 public int getAdjustedDoubleTapZoom(int rawValue) {
579 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
580 return (int) ((rawValue + 100) * mFontSizeMult);
581 }
582
583 static int getRawDoubleTapZoom(int percent) {
584 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
585 }
586
John Reckcadae722011-07-25 11:36:17 -0700587 public SharedPreferences getPreferences() {
588 return mPrefs;
589 }
590
Victoria Lease96497832012-03-23 14:19:56 -0700591 // update connectivity-dependent options
592 public void updateConnectionType() {
593 ConnectivityManager cm = (ConnectivityManager)
594 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
595 String linkPrefetchPreference = getLinkPrefetchEnabled();
596 boolean linkPrefetchAllowed = linkPrefetchPreference.
597 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
598 NetworkInfo ni = cm.getActiveNetworkInfo();
599 if (ni != null) {
600 switch (ni.getType()) {
601 case ConnectivityManager.TYPE_WIFI:
602 case ConnectivityManager.TYPE_ETHERNET:
603 case ConnectivityManager.TYPE_BLUETOOTH:
604 linkPrefetchAllowed |= linkPrefetchPreference.
605 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
606 break;
607 case ConnectivityManager.TYPE_MOBILE:
608 case ConnectivityManager.TYPE_MOBILE_DUN:
609 case ConnectivityManager.TYPE_MOBILE_MMS:
610 case ConnectivityManager.TYPE_MOBILE_SUPL:
611 case ConnectivityManager.TYPE_WIMAX:
612 default:
613 break;
614 }
615 }
616 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
617 mLinkPrefetchAllowed = linkPrefetchAllowed;
618 syncManagedSettings();
619 }
620 }
621
John Reck35e9dd62011-04-25 09:01:54 -0700622 // -----------------------------
623 // getter/setters for accessibility_preferences.xml
624 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100625
John Reck7dc444b2011-06-16 17:44:29 -0700626 @Deprecated
627 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700628 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
629 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100630 }
631
John Reck35e9dd62011-04-25 09:01:54 -0700632 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700633 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700634 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100635 }
636
John Reck92f25f82011-04-26 16:57:10 -0700637 public boolean forceEnableUserScalable() {
638 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
639 }
640
John Reck7dc444b2011-06-16 17:44:29 -0700641 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700642 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700643 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
644 return getAdjustedTextZoom(textZoom);
645 }
646
647 public void setTextZoom(int percent) {
648 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
649 }
650
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700651 public int getDoubleTapZoom() {
652 requireInitialization();
653 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
654 return getAdjustedDoubleTapZoom(doubleTapZoom);
655 }
656
657 public void setDoubleTapZoom(int percent) {
658 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
659 }
660
John Reck35e9dd62011-04-25 09:01:54 -0700661 // -----------------------------
662 // getter/setters for advanced_preferences.xml
663 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100664
John Reck35e9dd62011-04-25 09:01:54 -0700665 public String getSearchEngineName() {
666 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100667 }
John Reck63bb6872010-12-01 19:29:32 -0800668
Michael Kolb8d772b02012-01-19 13:56:00 -0800669 public boolean allowAppTabs() {
670 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
671 }
672
John Reck35e9dd62011-04-25 09:01:54 -0700673 public boolean openInBackground() {
674 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800675 }
John Reck35e9dd62011-04-25 09:01:54 -0700676
677 public boolean enableJavascript() {
678 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
679 }
680
681 // TODO: Cache
682 public PluginState getPluginState() {
683 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
684 return PluginState.valueOf(state);
685 }
686
687 // TODO: Cache
688 public ZoomDensity getDefaultZoom() {
689 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
690 return ZoomDensity.valueOf(zoom);
691 }
692
693 public boolean loadPageInOverviewMode() {
694 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
695 }
696
697 public boolean autofitPages() {
698 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
699 }
700
701 public boolean blockPopupWindows() {
702 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
703 }
704
705 public boolean loadImages() {
706 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
707 }
708
709 public String getDefaultTextEncoding() {
710 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
711 }
712
713 // -----------------------------
714 // getter/setters for general_preferences.xml
715 // -----------------------------
716
717 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700718 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
719 }
720
721 public void setHomePage(String value) {
722 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
723 }
724
725 public boolean isAutofillEnabled() {
726 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
727 }
728
729 public void setAutofillEnabled(boolean value) {
730 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
731 }
732
733 // -----------------------------
734 // getter/setters for debug_preferences.xml
735 // -----------------------------
736
737 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700738 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700739 return true;
740 }
741 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
742 }
743
Derek Sollenberger31adf672011-07-08 11:31:30 -0400744 public boolean isSkiaHardwareAccelerated() {
745 if (!isDebugEnabled()) {
746 return false;
747 }
748 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
749 }
750
John Reck35e9dd62011-04-25 09:01:54 -0700751 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700752 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700753 return 0;
754 }
755 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
756 }
757
758 // -----------------------------
759 // getter/setters for hidden_debug_preferences.xml
760 // -----------------------------
761
762 public boolean enableVisualIndicator() {
763 if (!isDebugEnabled()) {
764 return false;
765 }
766 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
767 }
768
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700769 public boolean enableCpuUploadPath() {
770 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700771 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700772 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700773 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700774 }
775
John Reck35e9dd62011-04-25 09:01:54 -0700776 public boolean enableJavascriptConsole() {
777 if (!isDebugEnabled()) {
778 return false;
779 }
780 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
781 }
782
783 public boolean isSmallScreen() {
784 if (!isDebugEnabled()) {
785 return false;
786 }
787 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
788 }
789
790 public boolean isWideViewport() {
791 if (!isDebugEnabled()) {
792 return true;
793 }
794 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
795 }
796
797 public boolean isNormalLayout() {
798 if (!isDebugEnabled()) {
799 return false;
800 }
801 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
802 }
803
804 public boolean isTracing() {
805 if (!isDebugEnabled()) {
806 return false;
807 }
808 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
809 }
810
811 public boolean enableLightTouch() {
812 if (!isDebugEnabled()) {
813 return false;
814 }
815 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
816 }
817
818 public boolean enableNavDump() {
819 if (!isDebugEnabled()) {
820 return false;
821 }
822 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
823 }
824
825 public String getJsEngineFlags() {
826 if (!isDebugEnabled()) {
827 return "";
828 }
829 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
830 }
831
832 // -----------------------------
833 // getter/setters for lab_preferences.xml
834 // -----------------------------
835
836 public boolean useQuickControls() {
837 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
838 }
839
840 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700841 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700842 }
843
Michael Kolbc38c6042011-04-27 10:46:06 -0700844 public boolean useFullscreen() {
845 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
846 }
847
John Reck2fd9d0e2011-07-15 11:13:48 -0700848 public boolean useInvertedRendering() {
849 return mPrefs.getBoolean(PREF_INVERTED, false);
850 }
851
Nicolas Roard5d513102011-08-03 15:35:34 -0700852 public float getInvertedContrast() {
853 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
854 }
855
John Reck35e9dd62011-04-25 09:01:54 -0700856 // -----------------------------
857 // getter/setters for privacy_security_preferences.xml
858 // -----------------------------
859
860 public boolean showSecurityWarnings() {
861 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
862 }
863
864 public boolean acceptCookies() {
865 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
866 }
867
868 public boolean saveFormdata() {
869 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
870 }
871
872 public boolean enableGeolocation() {
873 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
874 }
875
876 public boolean rememberPasswords() {
877 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
878 }
879
Michael Kolb14612442011-06-24 13:06:29 -0700880 // -----------------------------
881 // getter/setters for bandwidth_preferences.xml
882 // -----------------------------
883
Mathew Inwood467813f2011-09-02 15:43:17 +0100884 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
885 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700886 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100887
888 public static String getPreloadAlwaysPreferenceString(Context context) {
889 return context.getResources().getString(R.string.pref_data_preload_value_always);
890 }
891
Mathew Inwood825fba72011-10-04 14:52:52 +0100892 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
893 "browser_default_preload_setting";
894
895 public String getDefaultPreloadSetting() {
896 String preload = Settings.Secure.getString(mContext.getContentResolver(),
897 DEAULT_PRELOAD_SECURE_SETTING_KEY);
898 if (preload == null) {
899 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
900 }
901 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100902 }
903
904 public String getPreloadEnabled() {
905 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
906 }
907
Victoria Lease96497832012-03-23 14:19:56 -0700908 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
909 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
910 }
911
912 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
913 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
914 }
915
916 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
917 "browser_default_link_prefetch_setting";
918
919 public String getDefaultLinkPrefetchSetting() {
920 String preload = Settings.Secure.getString(mContext.getContentResolver(),
921 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
922 if (preload == null) {
923 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
924 }
925 return preload;
926 }
927
928 public String getLinkPrefetchEnabled() {
929 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
930 }
931
George Mount3636d0a2011-11-21 09:08:21 -0800932 // -----------------------------
933 // getter/setters for browser recovery
934 // -----------------------------
935 /**
936 * The last time browser was started.
937 * @return The last browser start time as System.currentTimeMillis. This
938 * can be 0 if this is the first time or the last tab was closed.
939 */
940 public long getLastRecovered() {
941 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
942 }
943
944 /**
945 * Sets the last browser start time.
946 * @param time The last time as System.currentTimeMillis that the browser
947 * was started. This should be set to 0 if the last tab is closed.
948 */
949 public void setLastRecovered(long time) {
950 mPrefs.edit()
951 .putLong(KEY_LAST_RECOVERED, time)
952 .apply();
953 }
954
955 /**
956 * Used to determine whether or not the previous browser run crashed. Once
957 * the previous state has been determined, the value will be set to false
958 * until a pause is received.
959 * @return true if the last browser run was paused or false if it crashed.
960 */
961 public boolean wasLastRunPaused() {
962 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
963 }
964
965 /**
966 * Sets whether or not the last run was a pause or crash.
967 * @param isPaused Set to true When a pause is received or false after
968 * resuming.
969 */
970 public void setLastRunPaused(boolean isPaused) {
971 mPrefs.edit()
972 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
973 .apply();
974 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800975}