blob: e0e7bc43f26ab34c4a4747770b264918f70bbb1d [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
John Reck7fd1e8f2011-04-27 18:22:57 -070056 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
57 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
58 "Chrome/11.0.696.34 Safari/534.24";
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 Reck7fd1e8f2011-04-27 18:22:57 -070072 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
73 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
74 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
75
John Reck35e9dd62011-04-25 09:01:54 -070076 private static final String USER_AGENTS[] = { null,
77 DESKTOP_USERAGENT,
78 IPHONE_USERAGENT,
79 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070080 FROYO_USERAGENT,
81 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070082 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080083
John Reck35e9dd62011-04-25 09:01:54 -070084 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070085
John Reck35e9dd62011-04-25 09:01:54 -070086 private Context mContext;
87 private SharedPreferences mPrefs;
88 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070089 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070090 private WebStorageSizeManager mWebStorageSizeManager;
91 private AutofillHandler mAutofillHandler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080092
John Reck35e9dd62011-04-25 09:01:54 -070093 // Cached settings
94 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080095
John Reck35e9dd62011-04-25 09:01:54 -070096 public static void initialize(final Context context) {
97 sInstance = new BrowserSettings(context);
98 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080099
John Reck35e9dd62011-04-25 09:01:54 -0700100 public static BrowserSettings getInstance() {
101 return sInstance;
102 }
Ben Murdochef671652010-11-25 17:17:58 +0000103
John Reck35e9dd62011-04-25 09:01:54 -0700104 private BrowserSettings(Context context) {
105 mContext = context;
106 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reckf48314f2011-04-27 17:52:17 -0700107 if (Build.VERSION.CODENAME.equals("REL")) {
108 // This is a release build, always startup with debug disabled
109 setDebugEnabled(false);
110 }
John Reck35e9dd62011-04-25 09:01:54 -0700111 mAutofillHandler = new AutofillHandler(mContext);
112 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
113 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
114 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
115 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
116 mPrefs.registerOnSharedPreferenceChangeListener(this);
117 mAutofillHandler.asyncLoadFromDb();
118 }
119
120 public void setController(Controller controller) {
121 mController = controller;
122 syncSharedSettings();
123
124 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
125 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000126 }
127 }
128
John Reck35e9dd62011-04-25 09:01:54 -0700129 public void startManagingSettings(WebSettings settings) {
130 synchronized (mManagedSettings) {
131 syncStaticSettings(settings);
132 syncSetting(settings);
133 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800134 }
135 }
136
137 /**
John Reck35e9dd62011-04-25 09:01:54 -0700138 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800139 */
John Reck35e9dd62011-04-25 09:01:54 -0700140 private void syncSetting(WebSettings settings) {
141 settings.setGeolocationEnabled(enableGeolocation());
142 settings.setJavaScriptEnabled(enableJavascript());
143 settings.setLightTouchEnabled(enableLightTouch());
144 settings.setNavDump(enableNavDump());
145 settings.setShowVisualIndicator(enableVisualIndicator());
146 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
147 settings.setDefaultZoom(getDefaultZoom());
148 settings.setMinimumFontSize(getMinimumFontSize());
149 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700150 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700151 settings.setPluginState(getPluginState());
152 settings.setTextSize(getTextSize());
153 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
154 settings.setAutoFillEnabled(isAutofillEnabled());
155 settings.setLayoutAlgorithm(getLayoutAlgorithm());
156 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
157 settings.setLoadsImagesAutomatically(loadImages());
158 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
159 settings.setSavePassword(rememberPasswords());
160 settings.setSaveFormData(saveFormdata());
161 settings.setUseWideViewPort(isWideViewport());
162 settings.setAutoFillProfile(getAutoFillProfile());
Ben Murdochef671652010-11-25 17:17:58 +0000163 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800164
John Reck35e9dd62011-04-25 09:01:54 -0700165 /**
166 * Syncs all the settings that have no UI
167 * These cannot change, so we only need to set them once per WebSettings
168 */
169 private void syncStaticSettings(WebSettings settings) {
170 settings.setDefaultFontSize(16);
171 settings.setDefaultFixedFontSize(13);
172 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000173
John Reck35e9dd62011-04-25 09:01:54 -0700174 // WebView inside Browser doesn't want initial focus to be set.
175 settings.setNeedInitialFocus(false);
176 // Browser supports multiple windows
177 settings.setSupportMultipleWindows(true);
178 // enable smooth transition for better performance during panning or
179 // zooming
180 settings.setEnableSmoothTransition(true);
181 // disable content url access
182 settings.setAllowContentAccess(false);
183
184 // HTML5 API flags
185 settings.setAppCacheEnabled(true);
186 settings.setDatabaseEnabled(true);
187 settings.setDomStorageEnabled(true);
188 settings.setWorkersEnabled(true); // This only affects V8.
189
190 // HTML5 configuration parametersettings.
191 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
192 settings.setAppCachePath(getAppCachePath());
193 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
194 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
195 }
196
197 private void syncSharedSettings() {
198 CookieManager.getInstance().setAcceptCookie(acceptCookies());
199 if (mController != null) {
200 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700201 }
John Reck35e9dd62011-04-25 09:01:54 -0700202 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700203
John Reck35e9dd62011-04-25 09:01:54 -0700204 private void syncManagedSettings() {
205 syncSharedSettings();
206 synchronized (mManagedSettings) {
207 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
208 while (iter.hasNext()) {
209 WeakReference<WebSettings> ref = iter.next();
210 WebSettings settings = ref.get();
211 if (settings == null) {
212 iter.remove();
213 continue;
214 }
215 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000216 }
John Reck35e9dd62011-04-25 09:01:54 -0700217 }
218 }
Ben Murdochef671652010-11-25 17:17:58 +0000219
John Reck35e9dd62011-04-25 09:01:54 -0700220 @Override
221 public void onSharedPreferenceChanged(
222 SharedPreferences sharedPreferences, String key) {
223 syncManagedSettings();
224 if (PREF_SEARCH_ENGINE.equals(key)) {
225 updateSearchEngine(false);
226 }
227 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
228 updateSearchEngine(true);
229 }
230 }
231
232 static String getFactoryResetHomeUrl(Context context) {
233 String url = context.getResources().getString(R.string.homepage_base);
234 if (url.indexOf("{CID}") != -1) {
235 url = url.replace("{CID}",
236 BrowserProvider.getClientId(context.getContentResolver()));
237 }
238 return url;
239 }
240
241 public LayoutAlgorithm getLayoutAlgorithm() {
242 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
243 if (autofitPages()) {
244 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
245 }
246 if (isDebugEnabled()) {
247 if (isSmallScreen()) {
248 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000249 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700250 if (isNormalLayout()) {
251 layoutAlgorithm = LayoutAlgorithm.NORMAL;
252 } else {
253 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
254 }
Ben Murdochef671652010-11-25 17:17:58 +0000255 }
John Reck35e9dd62011-04-25 09:01:54 -0700256 }
257 return layoutAlgorithm;
258 }
Ben Murdochef671652010-11-25 17:17:58 +0000259
John Reck35e9dd62011-04-25 09:01:54 -0700260 // TODO: Cache
261 public int getPageCacheCapacity() {
262 // the cost of one cached page is ~3M (measured using nytimes.com). For
263 // low end devices, we only cache one page. For high end devices, we try
264 // to cache more pages, currently choose 5.
265 if (ActivityManager.staticGetMemoryClass() > 16) {
266 return 5;
267 } else {
268 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800269 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800270 }
271
John Reck35e9dd62011-04-25 09:01:54 -0700272 public WebStorageSizeManager getWebStorageSizeManager() {
273 return mWebStorageSizeManager;
274 }
275
276 // TODO: Cache
277 private String getAppCachePath() {
278 return mContext.getDir("appcache", 0).getPath();
279 }
280
281 private void updateSearchEngine(boolean force) {
282 String searchEngineName = getSearchEngineName();
283 if (force || mSearchEngine == null ||
284 !mSearchEngine.getName().equals(searchEngineName)) {
285 if (mSearchEngine != null) {
286 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000287 // One or more tabs could have been in voice search mode.
288 // Clear it, since the new SearchEngine may not support
289 // it, or may handle it differently.
290 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
291 mController.getTabControl().getTab(i).revertVoiceSearchMode();
292 }
293 }
John Reck35e9dd62011-04-25 09:01:54 -0700294 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000295 }
John Reck35e9dd62011-04-25 09:01:54 -0700296 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000297
John Reck35e9dd62011-04-25 09:01:54 -0700298 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
299 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000300 }
301 }
302 }
303
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100304 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700305 if (mSearchEngine == null) {
306 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100307 }
John Reck35e9dd62011-04-25 09:01:54 -0700308 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100309 }
310
John Reck35e9dd62011-04-25 09:01:54 -0700311 public boolean isDebugEnabled() {
312 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100313 }
314
John Reck35e9dd62011-04-25 09:01:54 -0700315 public void setDebugEnabled(boolean value) {
316 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100317 }
318
John Reck35e9dd62011-04-25 09:01:54 -0700319 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800320 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700321 if (mController != null) {
322 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800323 if (current != null) {
324 current.clearCache(true);
325 }
326 }
327 }
328
John Reck35e9dd62011-04-25 09:01:54 -0700329 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800330 CookieManager.getInstance().removeAllCookie();
331 }
332
John Reck35e9dd62011-04-25 09:01:54 -0700333 public void clearHistory() {
334 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800335 Browser.clearHistory(resolver);
336 Browser.clearSearches(resolver);
337 }
338
John Reck35e9dd62011-04-25 09:01:54 -0700339 public void clearFormData() {
340 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700341 if (mController!= null) {
342 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100343 if (currentTopView != null) {
344 currentTopView.clearFormData();
345 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800346 }
347 }
348
John Reck35e9dd62011-04-25 09:01:54 -0700349 public void clearPasswords() {
350 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800351 db.clearUsernamePassword();
352 db.clearHttpAuthUsernamePassword();
353 }
354
John Reck35e9dd62011-04-25 09:01:54 -0700355 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100356 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100357 }
358
John Reck35e9dd62011-04-25 09:01:54 -0700359 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100360 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100361 }
362
John Reck35e9dd62011-04-25 09:01:54 -0700363 public void resetDefaultPreferences() {
364 mPrefs.edit().clear().apply();
365 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700366 }
367
John Reck35e9dd62011-04-25 09:01:54 -0700368 public AutoFillProfile getAutoFillProfile() {
369 mAutofillHandler.waitForLoad();
370 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800371 }
372
John Reck35e9dd62011-04-25 09:01:54 -0700373 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
374 mAutofillHandler.waitForLoad();
375 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800376 }
377
John Reck35e9dd62011-04-25 09:01:54 -0700378 public void toggleDebugSettings() {
379 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800380 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100381
John Reck35e9dd62011-04-25 09:01:54 -0700382 // -----------------------------
383 // getter/setters for accessibility_preferences.xml
384 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100385
John Reck35e9dd62011-04-25 09:01:54 -0700386 // TODO: Cache
387 public TextSize getTextSize() {
388 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
389 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100390 }
391
John Reck35e9dd62011-04-25 09:01:54 -0700392 public int getMinimumFontSize() {
393 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100394 }
395
John Reck92f25f82011-04-26 16:57:10 -0700396 public boolean forceEnableUserScalable() {
397 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
398 }
399
John Reck35e9dd62011-04-25 09:01:54 -0700400 // -----------------------------
401 // getter/setters for advanced_preferences.xml
402 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100403
John Reck35e9dd62011-04-25 09:01:54 -0700404 public String getSearchEngineName() {
405 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100406 }
John Reck63bb6872010-12-01 19:29:32 -0800407
John Reck35e9dd62011-04-25 09:01:54 -0700408 public boolean openInBackground() {
409 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800410 }
John Reck35e9dd62011-04-25 09:01:54 -0700411
412 public boolean enableJavascript() {
413 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
414 }
415
416 // TODO: Cache
417 public PluginState getPluginState() {
418 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
419 return PluginState.valueOf(state);
420 }
421
422 // TODO: Cache
423 public ZoomDensity getDefaultZoom() {
424 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
425 return ZoomDensity.valueOf(zoom);
426 }
427
428 public boolean loadPageInOverviewMode() {
429 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
430 }
431
432 public boolean autofitPages() {
433 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
434 }
435
436 public boolean blockPopupWindows() {
437 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
438 }
439
440 public boolean loadImages() {
441 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
442 }
443
444 public String getDefaultTextEncoding() {
445 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
446 }
447
448 // -----------------------------
449 // getter/setters for general_preferences.xml
450 // -----------------------------
451
452 public String getHomePage() {
453 if (useMostVisitedHomepage()) {
454 return HomeProvider.MOST_VISITED;
455 }
456 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
457 }
458
459 public void setHomePage(String value) {
460 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
461 }
462
463 public boolean isAutofillEnabled() {
464 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
465 }
466
467 public void setAutofillEnabled(boolean value) {
468 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
469 }
470
471 // -----------------------------
472 // getter/setters for debug_preferences.xml
473 // -----------------------------
474
475 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700476 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700477 return true;
478 }
479 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
480 }
481
482 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700483 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700484 return 0;
485 }
486 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
487 }
488
489 // -----------------------------
490 // getter/setters for hidden_debug_preferences.xml
491 // -----------------------------
492
493 public boolean enableVisualIndicator() {
494 if (!isDebugEnabled()) {
495 return false;
496 }
497 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
498 }
499
500 public boolean enableJavascriptConsole() {
501 if (!isDebugEnabled()) {
502 return false;
503 }
504 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
505 }
506
507 public boolean isSmallScreen() {
508 if (!isDebugEnabled()) {
509 return false;
510 }
511 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
512 }
513
514 public boolean isWideViewport() {
515 if (!isDebugEnabled()) {
516 return true;
517 }
518 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
519 }
520
521 public boolean isNormalLayout() {
522 if (!isDebugEnabled()) {
523 return false;
524 }
525 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
526 }
527
528 public boolean isTracing() {
529 if (!isDebugEnabled()) {
530 return false;
531 }
532 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
533 }
534
535 public boolean enableLightTouch() {
536 if (!isDebugEnabled()) {
537 return false;
538 }
539 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
540 }
541
542 public boolean enableNavDump() {
543 if (!isDebugEnabled()) {
544 return false;
545 }
546 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
547 }
548
549 public String getJsEngineFlags() {
550 if (!isDebugEnabled()) {
551 return "";
552 }
553 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
554 }
555
556 // -----------------------------
557 // getter/setters for lab_preferences.xml
558 // -----------------------------
559
560 public boolean useQuickControls() {
561 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
562 }
563
564 public boolean useMostVisitedHomepage() {
565 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
566 }
567
568 public boolean useInstantSearch() {
569 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
570 }
571
572 // -----------------------------
573 // getter/setters for privacy_security_preferences.xml
574 // -----------------------------
575
576 public boolean showSecurityWarnings() {
577 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
578 }
579
580 public boolean acceptCookies() {
581 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
582 }
583
584 public boolean saveFormdata() {
585 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
586 }
587
588 public boolean enableGeolocation() {
589 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
590 }
591
592 public boolean rememberPasswords() {
593 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
594 }
595
The Android Open Source Project0c908882009-03-03 19:32:16 -0800596}