blob: 5a022efb4c2b309fcc4c2483e68bd44612cfc873 [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
John Reckbafe58a2011-01-11 10:26:02 -080019import com.android.browser.homepages.HomeProvider;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010020import com.android.browser.search.SearchEngine;
21import com.android.browser.search.SearchEngines;
22
Grace Kloba9804c432009-12-02 11:07:40 -080023import android.app.ActivityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080024import android.content.ContentResolver;
25import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080026import android.content.SharedPreferences;
John Reck812d2d62011-01-18 14:16:15 -080027import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
John Reckf48314f2011-04-27 17:52:17 -070028import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010029import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010030import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010031import android.provider.Browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010033import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080034import android.webkit.WebIconDatabase;
35import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010036import android.webkit.WebSettings.AutoFillProfile;
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;
Nicolas Roard78a98e42009-05-11 13:34:17 +010041import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080042import android.webkit.WebView;
43import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
John Reck35e9dd62011-04-25 09:01:54 -070045import java.lang.ref.WeakReference;
46import java.util.Iterator;
47import java.util.LinkedList;
The Android Open Source Project0c908882009-03-03 19:32:16 -080048
John Reck35e9dd62011-04-25 09:01:54 -070049/**
50 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080051 */
John Reck35e9dd62011-04-25 09:01:54 -070052public class BrowserSettings implements OnSharedPreferenceChangeListener,
53 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010054
John Reck35e9dd62011-04-25 09:01:54 -070055 // TODO: Do something with this UserAgent stuff
The Android Open Source Project0c908882009-03-03 19:32:16 -080056 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
John Reck35e9dd62011-04-25 09:01:54 -070057 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
58 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -080059
60 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070061 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
62 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070063
64 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070065 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
66 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070067
68 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070069 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
70 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080071
John Reck35e9dd62011-04-25 09:01:54 -070072 private static final String USER_AGENTS[] = { null,
73 DESKTOP_USERAGENT,
74 IPHONE_USERAGENT,
75 IPAD_USERAGENT,
76 FROYO_USERAGENT
77 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080078
John Reck35e9dd62011-04-25 09:01:54 -070079 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070080
John Reck35e9dd62011-04-25 09:01:54 -070081 private Context mContext;
82 private SharedPreferences mPrefs;
83 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070084 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070085 private WebStorageSizeManager mWebStorageSizeManager;
86 private AutofillHandler mAutofillHandler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080087
John Reck35e9dd62011-04-25 09:01:54 -070088 // Cached settings
89 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080090
John Reck35e9dd62011-04-25 09:01:54 -070091 public static void initialize(final Context context) {
92 sInstance = new BrowserSettings(context);
93 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080094
John Reck35e9dd62011-04-25 09:01:54 -070095 public static BrowserSettings getInstance() {
96 return sInstance;
97 }
Ben Murdochef671652010-11-25 17:17:58 +000098
John Reck35e9dd62011-04-25 09:01:54 -070099 private BrowserSettings(Context context) {
100 mContext = context;
101 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reckf48314f2011-04-27 17:52:17 -0700102 if (Build.VERSION.CODENAME.equals("REL")) {
103 // This is a release build, always startup with debug disabled
104 setDebugEnabled(false);
105 }
John Reck35e9dd62011-04-25 09:01:54 -0700106 mAutofillHandler = new AutofillHandler(mContext);
107 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
108 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
109 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
110 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
111 mPrefs.registerOnSharedPreferenceChangeListener(this);
112 mAutofillHandler.asyncLoadFromDb();
113 }
114
115 public void setController(Controller controller) {
116 mController = controller;
117 syncSharedSettings();
118
119 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
120 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000121 }
122 }
123
John Reck35e9dd62011-04-25 09:01:54 -0700124 public void startManagingSettings(WebSettings settings) {
125 synchronized (mManagedSettings) {
126 syncStaticSettings(settings);
127 syncSetting(settings);
128 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129 }
130 }
131
132 /**
John Reck35e9dd62011-04-25 09:01:54 -0700133 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800134 */
John Reck35e9dd62011-04-25 09:01:54 -0700135 private void syncSetting(WebSettings settings) {
136 settings.setGeolocationEnabled(enableGeolocation());
137 settings.setJavaScriptEnabled(enableJavascript());
138 settings.setLightTouchEnabled(enableLightTouch());
139 settings.setNavDump(enableNavDump());
140 settings.setShowVisualIndicator(enableVisualIndicator());
141 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
142 settings.setDefaultZoom(getDefaultZoom());
143 settings.setMinimumFontSize(getMinimumFontSize());
144 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700145 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700146 settings.setPluginState(getPluginState());
147 settings.setTextSize(getTextSize());
148 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
149 settings.setAutoFillEnabled(isAutofillEnabled());
150 settings.setLayoutAlgorithm(getLayoutAlgorithm());
151 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
152 settings.setLoadsImagesAutomatically(loadImages());
153 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
154 settings.setSavePassword(rememberPasswords());
155 settings.setSaveFormData(saveFormdata());
156 settings.setUseWideViewPort(isWideViewport());
157 settings.setAutoFillProfile(getAutoFillProfile());
Ben Murdochef671652010-11-25 17:17:58 +0000158 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800159
John Reck35e9dd62011-04-25 09:01:54 -0700160 /**
161 * Syncs all the settings that have no UI
162 * These cannot change, so we only need to set them once per WebSettings
163 */
164 private void syncStaticSettings(WebSettings settings) {
165 settings.setDefaultFontSize(16);
166 settings.setDefaultFixedFontSize(13);
167 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000168
John Reck35e9dd62011-04-25 09:01:54 -0700169 // WebView inside Browser doesn't want initial focus to be set.
170 settings.setNeedInitialFocus(false);
171 // Browser supports multiple windows
172 settings.setSupportMultipleWindows(true);
173 // enable smooth transition for better performance during panning or
174 // zooming
175 settings.setEnableSmoothTransition(true);
176 // disable content url access
177 settings.setAllowContentAccess(false);
178
179 // HTML5 API flags
180 settings.setAppCacheEnabled(true);
181 settings.setDatabaseEnabled(true);
182 settings.setDomStorageEnabled(true);
183 settings.setWorkersEnabled(true); // This only affects V8.
184
185 // HTML5 configuration parametersettings.
186 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
187 settings.setAppCachePath(getAppCachePath());
188 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
189 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
190 }
191
192 private void syncSharedSettings() {
193 CookieManager.getInstance().setAcceptCookie(acceptCookies());
194 if (mController != null) {
195 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700196 }
John Reck35e9dd62011-04-25 09:01:54 -0700197 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700198
John Reck35e9dd62011-04-25 09:01:54 -0700199 private void syncManagedSettings() {
200 syncSharedSettings();
201 synchronized (mManagedSettings) {
202 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
203 while (iter.hasNext()) {
204 WeakReference<WebSettings> ref = iter.next();
205 WebSettings settings = ref.get();
206 if (settings == null) {
207 iter.remove();
208 continue;
209 }
210 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000211 }
John Reck35e9dd62011-04-25 09:01:54 -0700212 }
213 }
Ben Murdochef671652010-11-25 17:17:58 +0000214
John Reck35e9dd62011-04-25 09:01:54 -0700215 @Override
216 public void onSharedPreferenceChanged(
217 SharedPreferences sharedPreferences, String key) {
218 syncManagedSettings();
219 if (PREF_SEARCH_ENGINE.equals(key)) {
220 updateSearchEngine(false);
221 }
222 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
223 updateSearchEngine(true);
224 }
225 }
226
227 static String getFactoryResetHomeUrl(Context context) {
228 String url = context.getResources().getString(R.string.homepage_base);
229 if (url.indexOf("{CID}") != -1) {
230 url = url.replace("{CID}",
231 BrowserProvider.getClientId(context.getContentResolver()));
232 }
233 return url;
234 }
235
236 public LayoutAlgorithm getLayoutAlgorithm() {
237 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
238 if (autofitPages()) {
239 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
240 }
241 if (isDebugEnabled()) {
242 if (isSmallScreen()) {
243 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000244 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700245 if (isNormalLayout()) {
246 layoutAlgorithm = LayoutAlgorithm.NORMAL;
247 } else {
248 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
249 }
Ben Murdochef671652010-11-25 17:17:58 +0000250 }
John Reck35e9dd62011-04-25 09:01:54 -0700251 }
252 return layoutAlgorithm;
253 }
Ben Murdochef671652010-11-25 17:17:58 +0000254
John Reck35e9dd62011-04-25 09:01:54 -0700255 // TODO: Cache
256 public int getPageCacheCapacity() {
257 // the cost of one cached page is ~3M (measured using nytimes.com). For
258 // low end devices, we only cache one page. For high end devices, we try
259 // to cache more pages, currently choose 5.
260 if (ActivityManager.staticGetMemoryClass() > 16) {
261 return 5;
262 } else {
263 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800264 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800265 }
266
John Reck35e9dd62011-04-25 09:01:54 -0700267 public WebStorageSizeManager getWebStorageSizeManager() {
268 return mWebStorageSizeManager;
269 }
270
271 // TODO: Cache
272 private String getAppCachePath() {
273 return mContext.getDir("appcache", 0).getPath();
274 }
275
276 private void updateSearchEngine(boolean force) {
277 String searchEngineName = getSearchEngineName();
278 if (force || mSearchEngine == null ||
279 !mSearchEngine.getName().equals(searchEngineName)) {
280 if (mSearchEngine != null) {
281 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000282 // One or more tabs could have been in voice search mode.
283 // Clear it, since the new SearchEngine may not support
284 // it, or may handle it differently.
285 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
286 mController.getTabControl().getTab(i).revertVoiceSearchMode();
287 }
288 }
John Reck35e9dd62011-04-25 09:01:54 -0700289 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000290 }
John Reck35e9dd62011-04-25 09:01:54 -0700291 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000292
John Reck35e9dd62011-04-25 09:01:54 -0700293 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
294 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000295 }
296 }
297 }
298
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100299 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700300 if (mSearchEngine == null) {
301 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100302 }
John Reck35e9dd62011-04-25 09:01:54 -0700303 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100304 }
305
John Reck35e9dd62011-04-25 09:01:54 -0700306 public boolean isDebugEnabled() {
307 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100308 }
309
John Reck35e9dd62011-04-25 09:01:54 -0700310 public void setDebugEnabled(boolean value) {
311 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100312 }
313
John Reck35e9dd62011-04-25 09:01:54 -0700314 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800315 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700316 if (mController != null) {
317 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800318 if (current != null) {
319 current.clearCache(true);
320 }
321 }
322 }
323
John Reck35e9dd62011-04-25 09:01:54 -0700324 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800325 CookieManager.getInstance().removeAllCookie();
326 }
327
John Reck35e9dd62011-04-25 09:01:54 -0700328 public void clearHistory() {
329 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800330 Browser.clearHistory(resolver);
331 Browser.clearSearches(resolver);
332 }
333
John Reck35e9dd62011-04-25 09:01:54 -0700334 public void clearFormData() {
335 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700336 if (mController!= null) {
337 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100338 if (currentTopView != null) {
339 currentTopView.clearFormData();
340 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800341 }
342 }
343
John Reck35e9dd62011-04-25 09:01:54 -0700344 public void clearPasswords() {
345 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800346 db.clearUsernamePassword();
347 db.clearHttpAuthUsernamePassword();
348 }
349
John Reck35e9dd62011-04-25 09:01:54 -0700350 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100351 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100352 }
353
John Reck35e9dd62011-04-25 09:01:54 -0700354 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100355 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100356 }
357
John Reck35e9dd62011-04-25 09:01:54 -0700358 public void resetDefaultPreferences() {
359 mPrefs.edit().clear().apply();
360 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700361 }
362
John Reck35e9dd62011-04-25 09:01:54 -0700363 public AutoFillProfile getAutoFillProfile() {
364 mAutofillHandler.waitForLoad();
365 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800366 }
367
John Reck35e9dd62011-04-25 09:01:54 -0700368 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
369 mAutofillHandler.waitForLoad();
370 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800371 }
372
John Reck35e9dd62011-04-25 09:01:54 -0700373 public void toggleDebugSettings() {
374 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800375 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100376
John Reck35e9dd62011-04-25 09:01:54 -0700377 // -----------------------------
378 // getter/setters for accessibility_preferences.xml
379 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100380
John Reck35e9dd62011-04-25 09:01:54 -0700381 // TODO: Cache
382 public TextSize getTextSize() {
383 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
384 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100385 }
386
John Reck35e9dd62011-04-25 09:01:54 -0700387 public int getMinimumFontSize() {
388 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100389 }
390
John Reck92f25f82011-04-26 16:57:10 -0700391 public boolean forceEnableUserScalable() {
392 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
393 }
394
John Reck35e9dd62011-04-25 09:01:54 -0700395 // -----------------------------
396 // getter/setters for advanced_preferences.xml
397 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100398
John Reck35e9dd62011-04-25 09:01:54 -0700399 public String getSearchEngineName() {
400 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100401 }
John Reck63bb6872010-12-01 19:29:32 -0800402
John Reck35e9dd62011-04-25 09:01:54 -0700403 public boolean openInBackground() {
404 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800405 }
John Reck35e9dd62011-04-25 09:01:54 -0700406
407 public boolean enableJavascript() {
408 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
409 }
410
411 // TODO: Cache
412 public PluginState getPluginState() {
413 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
414 return PluginState.valueOf(state);
415 }
416
417 // TODO: Cache
418 public ZoomDensity getDefaultZoom() {
419 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
420 return ZoomDensity.valueOf(zoom);
421 }
422
423 public boolean loadPageInOverviewMode() {
424 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
425 }
426
427 public boolean autofitPages() {
428 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
429 }
430
431 public boolean blockPopupWindows() {
432 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
433 }
434
435 public boolean loadImages() {
436 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
437 }
438
439 public String getDefaultTextEncoding() {
440 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
441 }
442
443 // -----------------------------
444 // getter/setters for general_preferences.xml
445 // -----------------------------
446
447 public String getHomePage() {
448 if (useMostVisitedHomepage()) {
449 return HomeProvider.MOST_VISITED;
450 }
451 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
452 }
453
454 public void setHomePage(String value) {
455 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
456 }
457
458 public boolean isAutofillEnabled() {
459 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
460 }
461
462 public void setAutofillEnabled(boolean value) {
463 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
464 }
465
466 // -----------------------------
467 // getter/setters for debug_preferences.xml
468 // -----------------------------
469
470 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700471 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700472 return true;
473 }
474 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
475 }
476
477 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700478 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700479 return 0;
480 }
481 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
482 }
483
484 // -----------------------------
485 // getter/setters for hidden_debug_preferences.xml
486 // -----------------------------
487
488 public boolean enableVisualIndicator() {
489 if (!isDebugEnabled()) {
490 return false;
491 }
492 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
493 }
494
495 public boolean enableJavascriptConsole() {
496 if (!isDebugEnabled()) {
497 return false;
498 }
499 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
500 }
501
502 public boolean isSmallScreen() {
503 if (!isDebugEnabled()) {
504 return false;
505 }
506 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
507 }
508
509 public boolean isWideViewport() {
510 if (!isDebugEnabled()) {
511 return true;
512 }
513 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
514 }
515
516 public boolean isNormalLayout() {
517 if (!isDebugEnabled()) {
518 return false;
519 }
520 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
521 }
522
523 public boolean isTracing() {
524 if (!isDebugEnabled()) {
525 return false;
526 }
527 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
528 }
529
530 public boolean enableLightTouch() {
531 if (!isDebugEnabled()) {
532 return false;
533 }
534 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
535 }
536
537 public boolean enableNavDump() {
538 if (!isDebugEnabled()) {
539 return false;
540 }
541 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
542 }
543
544 public String getJsEngineFlags() {
545 if (!isDebugEnabled()) {
546 return "";
547 }
548 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
549 }
550
551 // -----------------------------
552 // getter/setters for lab_preferences.xml
553 // -----------------------------
554
555 public boolean useQuickControls() {
556 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
557 }
558
559 public boolean useMostVisitedHomepage() {
560 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
561 }
562
563 public boolean useInstantSearch() {
564 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
565 }
566
567 // -----------------------------
568 // getter/setters for privacy_security_preferences.xml
569 // -----------------------------
570
571 public boolean showSecurityWarnings() {
572 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
573 }
574
575 public boolean acceptCookies() {
576 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
577 }
578
579 public boolean saveFormdata() {
580 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
581 }
582
583 public boolean enableGeolocation() {
584 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
585 }
586
587 public boolean rememberPasswords() {
588 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
589 }
590
The Android Open Source Project0c908882009-03-03 19:32:16 -0800591}