blob: 9456561409cbe7c4a90f25f8c4d501f4728e2f5e [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;
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;
The Android Open Source Project0c908882009-03-03 19:32:16 -080031import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010032import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.webkit.WebIconDatabase;
34import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010035import android.webkit.WebSettings.AutoFillProfile;
John Reck35e9dd62011-04-25 09:01:54 -070036import android.webkit.WebSettings.LayoutAlgorithm;
37import android.webkit.WebSettings.PluginState;
38import android.webkit.WebSettings.TextSize;
39import android.webkit.WebSettings.ZoomDensity;
Nicolas Roard78a98e42009-05-11 13:34:17 +010040import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080041import android.webkit.WebView;
42import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080043
John Reck35e9dd62011-04-25 09:01:54 -070044import java.lang.ref.WeakReference;
45import java.util.Iterator;
46import java.util.LinkedList;
The Android Open Source Project0c908882009-03-03 19:32:16 -080047
John Reck35e9dd62011-04-25 09:01:54 -070048/**
49 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080050 */
John Reck35e9dd62011-04-25 09:01:54 -070051public class BrowserSettings implements OnSharedPreferenceChangeListener,
52 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010053
John Reck35e9dd62011-04-25 09:01:54 -070054 // TODO: Do something with this UserAgent stuff
The Android Open Source Project0c908882009-03-03 19:32:16 -080055 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
John Reck35e9dd62011-04-25 09:01:54 -070056 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
57 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -080058
59 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070060 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
61 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070062
63 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070064 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
65 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070066
67 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070068 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
69 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080070
John Reck35e9dd62011-04-25 09:01:54 -070071 private static final String USER_AGENTS[] = { null,
72 DESKTOP_USERAGENT,
73 IPHONE_USERAGENT,
74 IPAD_USERAGENT,
75 FROYO_USERAGENT
76 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080077
John Reck35e9dd62011-04-25 09:01:54 -070078 public static boolean DEV_BUILD = true;
Jeff Davidson43610292010-07-16 16:03:58 -070079
John Reck35e9dd62011-04-25 09:01:54 -070080 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070081
John Reck35e9dd62011-04-25 09:01:54 -070082 private Context mContext;
83 private SharedPreferences mPrefs;
84 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070085 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070086 private WebStorageSizeManager mWebStorageSizeManager;
87 private AutofillHandler mAutofillHandler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080088
John Reck35e9dd62011-04-25 09:01:54 -070089 // Cached settings
90 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080091
John Reck35e9dd62011-04-25 09:01:54 -070092 public static void initialize(final Context context) {
93 sInstance = new BrowserSettings(context);
94 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080095
John Reck35e9dd62011-04-25 09:01:54 -070096 public static BrowserSettings getInstance() {
97 return sInstance;
98 }
Ben Murdochef671652010-11-25 17:17:58 +000099
John Reck35e9dd62011-04-25 09:01:54 -0700100 private BrowserSettings(Context context) {
101 mContext = context;
102 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
103 mAutofillHandler = new AutofillHandler(mContext);
104 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
105 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
106 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
107 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
108 mPrefs.registerOnSharedPreferenceChangeListener(this);
109 mAutofillHandler.asyncLoadFromDb();
110 }
111
112 public void setController(Controller controller) {
113 mController = controller;
114 syncSharedSettings();
115
116 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
117 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000118 }
119 }
120
John Reck35e9dd62011-04-25 09:01:54 -0700121 public void startManagingSettings(WebSettings settings) {
122 synchronized (mManagedSettings) {
123 syncStaticSettings(settings);
124 syncSetting(settings);
125 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800126 }
127 }
128
129 /**
John Reck35e9dd62011-04-25 09:01:54 -0700130 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800131 */
John Reck35e9dd62011-04-25 09:01:54 -0700132 private void syncSetting(WebSettings settings) {
133 settings.setGeolocationEnabled(enableGeolocation());
134 settings.setJavaScriptEnabled(enableJavascript());
135 settings.setLightTouchEnabled(enableLightTouch());
136 settings.setNavDump(enableNavDump());
137 settings.setShowVisualIndicator(enableVisualIndicator());
138 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
139 settings.setDefaultZoom(getDefaultZoom());
140 settings.setMinimumFontSize(getMinimumFontSize());
141 settings.setMinimumLogicalFontSize(getMinimumFontSize());
142 settings.setPluginState(getPluginState());
143 settings.setTextSize(getTextSize());
144 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
145 settings.setAutoFillEnabled(isAutofillEnabled());
146 settings.setLayoutAlgorithm(getLayoutAlgorithm());
147 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
148 settings.setLoadsImagesAutomatically(loadImages());
149 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
150 settings.setSavePassword(rememberPasswords());
151 settings.setSaveFormData(saveFormdata());
152 settings.setUseWideViewPort(isWideViewport());
153 settings.setAutoFillProfile(getAutoFillProfile());
Ben Murdochef671652010-11-25 17:17:58 +0000154 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800155
John Reck35e9dd62011-04-25 09:01:54 -0700156 /**
157 * Syncs all the settings that have no UI
158 * These cannot change, so we only need to set them once per WebSettings
159 */
160 private void syncStaticSettings(WebSettings settings) {
161 settings.setDefaultFontSize(16);
162 settings.setDefaultFixedFontSize(13);
163 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000164
John Reck35e9dd62011-04-25 09:01:54 -0700165 // WebView inside Browser doesn't want initial focus to be set.
166 settings.setNeedInitialFocus(false);
167 // Browser supports multiple windows
168 settings.setSupportMultipleWindows(true);
169 // enable smooth transition for better performance during panning or
170 // zooming
171 settings.setEnableSmoothTransition(true);
172 // disable content url access
173 settings.setAllowContentAccess(false);
174
175 // HTML5 API flags
176 settings.setAppCacheEnabled(true);
177 settings.setDatabaseEnabled(true);
178 settings.setDomStorageEnabled(true);
179 settings.setWorkersEnabled(true); // This only affects V8.
180
181 // HTML5 configuration parametersettings.
182 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
183 settings.setAppCachePath(getAppCachePath());
184 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
185 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
186 }
187
188 private void syncSharedSettings() {
189 CookieManager.getInstance().setAcceptCookie(acceptCookies());
190 if (mController != null) {
191 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700192 }
John Reck35e9dd62011-04-25 09:01:54 -0700193 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700194
John Reck35e9dd62011-04-25 09:01:54 -0700195 private void syncManagedSettings() {
196 syncSharedSettings();
197 synchronized (mManagedSettings) {
198 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
199 while (iter.hasNext()) {
200 WeakReference<WebSettings> ref = iter.next();
201 WebSettings settings = ref.get();
202 if (settings == null) {
203 iter.remove();
204 continue;
205 }
206 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000207 }
John Reck35e9dd62011-04-25 09:01:54 -0700208 }
209 }
Ben Murdochef671652010-11-25 17:17:58 +0000210
John Reck35e9dd62011-04-25 09:01:54 -0700211 @Override
212 public void onSharedPreferenceChanged(
213 SharedPreferences sharedPreferences, String key) {
214 syncManagedSettings();
215 if (PREF_SEARCH_ENGINE.equals(key)) {
216 updateSearchEngine(false);
217 }
218 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
219 updateSearchEngine(true);
220 }
221 }
222
223 static String getFactoryResetHomeUrl(Context context) {
224 String url = context.getResources().getString(R.string.homepage_base);
225 if (url.indexOf("{CID}") != -1) {
226 url = url.replace("{CID}",
227 BrowserProvider.getClientId(context.getContentResolver()));
228 }
229 return url;
230 }
231
232 public LayoutAlgorithm getLayoutAlgorithm() {
233 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
234 if (autofitPages()) {
235 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
236 }
237 if (isDebugEnabled()) {
238 if (isSmallScreen()) {
239 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000240 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700241 if (isNormalLayout()) {
242 layoutAlgorithm = LayoutAlgorithm.NORMAL;
243 } else {
244 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
245 }
Ben Murdochef671652010-11-25 17:17:58 +0000246 }
John Reck35e9dd62011-04-25 09:01:54 -0700247 }
248 return layoutAlgorithm;
249 }
Ben Murdochef671652010-11-25 17:17:58 +0000250
John Reck35e9dd62011-04-25 09:01:54 -0700251 // TODO: Cache
252 public int getPageCacheCapacity() {
253 // the cost of one cached page is ~3M (measured using nytimes.com). For
254 // low end devices, we only cache one page. For high end devices, we try
255 // to cache more pages, currently choose 5.
256 if (ActivityManager.staticGetMemoryClass() > 16) {
257 return 5;
258 } else {
259 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800260 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800261 }
262
John Reck35e9dd62011-04-25 09:01:54 -0700263 public WebStorageSizeManager getWebStorageSizeManager() {
264 return mWebStorageSizeManager;
265 }
266
267 // TODO: Cache
268 private String getAppCachePath() {
269 return mContext.getDir("appcache", 0).getPath();
270 }
271
272 private void updateSearchEngine(boolean force) {
273 String searchEngineName = getSearchEngineName();
274 if (force || mSearchEngine == null ||
275 !mSearchEngine.getName().equals(searchEngineName)) {
276 if (mSearchEngine != null) {
277 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000278 // One or more tabs could have been in voice search mode.
279 // Clear it, since the new SearchEngine may not support
280 // it, or may handle it differently.
281 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
282 mController.getTabControl().getTab(i).revertVoiceSearchMode();
283 }
284 }
John Reck35e9dd62011-04-25 09:01:54 -0700285 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000286 }
John Reck35e9dd62011-04-25 09:01:54 -0700287 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000288
John Reck35e9dd62011-04-25 09:01:54 -0700289 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
290 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000291 }
292 }
293 }
294
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100295 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700296 if (mSearchEngine == null) {
297 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100298 }
John Reck35e9dd62011-04-25 09:01:54 -0700299 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100300 }
301
John Reck35e9dd62011-04-25 09:01:54 -0700302 public boolean isDebugEnabled() {
303 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100304 }
305
John Reck35e9dd62011-04-25 09:01:54 -0700306 public void setDebugEnabled(boolean value) {
307 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100308 }
309
John Reck35e9dd62011-04-25 09:01:54 -0700310 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800311 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700312 if (mController != null) {
313 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800314 if (current != null) {
315 current.clearCache(true);
316 }
317 }
318 }
319
John Reck35e9dd62011-04-25 09:01:54 -0700320 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800321 CookieManager.getInstance().removeAllCookie();
322 }
323
John Reck35e9dd62011-04-25 09:01:54 -0700324 public void clearHistory() {
325 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800326 Browser.clearHistory(resolver);
327 Browser.clearSearches(resolver);
328 }
329
John Reck35e9dd62011-04-25 09:01:54 -0700330 public void clearFormData() {
331 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 if (mController!= null) {
333 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100334 if (currentTopView != null) {
335 currentTopView.clearFormData();
336 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800337 }
338 }
339
John Reck35e9dd62011-04-25 09:01:54 -0700340 public void clearPasswords() {
341 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800342 db.clearUsernamePassword();
343 db.clearHttpAuthUsernamePassword();
344 }
345
John Reck35e9dd62011-04-25 09:01:54 -0700346 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100347 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100348 }
349
John Reck35e9dd62011-04-25 09:01:54 -0700350 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100351 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100352 }
353
John Reck35e9dd62011-04-25 09:01:54 -0700354 public void resetDefaultPreferences() {
355 mPrefs.edit().clear().apply();
356 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700357 }
358
John Reck35e9dd62011-04-25 09:01:54 -0700359 public AutoFillProfile getAutoFillProfile() {
360 mAutofillHandler.waitForLoad();
361 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800362 }
363
John Reck35e9dd62011-04-25 09:01:54 -0700364 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
365 mAutofillHandler.waitForLoad();
366 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800367 }
368
John Reck35e9dd62011-04-25 09:01:54 -0700369 public void toggleDebugSettings() {
370 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800371 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100372
John Reck35e9dd62011-04-25 09:01:54 -0700373 // -----------------------------
374 // getter/setters for accessibility_preferences.xml
375 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100376
John Reck35e9dd62011-04-25 09:01:54 -0700377 // TODO: Cache
378 public TextSize getTextSize() {
379 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
380 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100381 }
382
John Reck35e9dd62011-04-25 09:01:54 -0700383 public int getMinimumFontSize() {
384 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100385 }
386
John Reck35e9dd62011-04-25 09:01:54 -0700387 // -----------------------------
388 // getter/setters for advanced_preferences.xml
389 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100390
John Reck35e9dd62011-04-25 09:01:54 -0700391 public String getSearchEngineName() {
392 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100393 }
John Reck63bb6872010-12-01 19:29:32 -0800394
John Reck35e9dd62011-04-25 09:01:54 -0700395 public boolean openInBackground() {
396 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800397 }
John Reck35e9dd62011-04-25 09:01:54 -0700398
399 public boolean enableJavascript() {
400 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
401 }
402
403 // TODO: Cache
404 public PluginState getPluginState() {
405 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
406 return PluginState.valueOf(state);
407 }
408
409 // TODO: Cache
410 public ZoomDensity getDefaultZoom() {
411 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
412 return ZoomDensity.valueOf(zoom);
413 }
414
415 public boolean loadPageInOverviewMode() {
416 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
417 }
418
419 public boolean autofitPages() {
420 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
421 }
422
423 public boolean blockPopupWindows() {
424 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
425 }
426
427 public boolean loadImages() {
428 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
429 }
430
431 public String getDefaultTextEncoding() {
432 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
433 }
434
435 // -----------------------------
436 // getter/setters for general_preferences.xml
437 // -----------------------------
438
439 public String getHomePage() {
440 if (useMostVisitedHomepage()) {
441 return HomeProvider.MOST_VISITED;
442 }
443 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
444 }
445
446 public void setHomePage(String value) {
447 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
448 }
449
450 public boolean isAutofillEnabled() {
451 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
452 }
453
454 public void setAutofillEnabled(boolean value) {
455 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
456 }
457
458 // -----------------------------
459 // getter/setters for debug_preferences.xml
460 // -----------------------------
461
462 public boolean isHardwareAccelerated() {
463 if (!isDebugEnabled() && !DEV_BUILD) {
464 return true;
465 }
466 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
467 }
468
469 public int getUserAgent() {
470 if (!isDebugEnabled() && !DEV_BUILD) {
471 return 0;
472 }
473 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
474 }
475
476 // -----------------------------
477 // getter/setters for hidden_debug_preferences.xml
478 // -----------------------------
479
480 public boolean enableVisualIndicator() {
481 if (!isDebugEnabled()) {
482 return false;
483 }
484 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
485 }
486
487 public boolean enableJavascriptConsole() {
488 if (!isDebugEnabled()) {
489 return false;
490 }
491 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
492 }
493
494 public boolean isSmallScreen() {
495 if (!isDebugEnabled()) {
496 return false;
497 }
498 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
499 }
500
501 public boolean isWideViewport() {
502 if (!isDebugEnabled()) {
503 return true;
504 }
505 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
506 }
507
508 public boolean isNormalLayout() {
509 if (!isDebugEnabled()) {
510 return false;
511 }
512 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
513 }
514
515 public boolean isTracing() {
516 if (!isDebugEnabled()) {
517 return false;
518 }
519 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
520 }
521
522 public boolean enableLightTouch() {
523 if (!isDebugEnabled()) {
524 return false;
525 }
526 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
527 }
528
529 public boolean enableNavDump() {
530 if (!isDebugEnabled()) {
531 return false;
532 }
533 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
534 }
535
536 public String getJsEngineFlags() {
537 if (!isDebugEnabled()) {
538 return "";
539 }
540 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
541 }
542
543 // -----------------------------
544 // getter/setters for lab_preferences.xml
545 // -----------------------------
546
547 public boolean useQuickControls() {
548 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
549 }
550
551 public boolean useMostVisitedHomepage() {
552 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
553 }
554
555 public boolean useInstantSearch() {
556 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
557 }
558
559 // -----------------------------
560 // getter/setters for privacy_security_preferences.xml
561 // -----------------------------
562
563 public boolean showSecurityWarnings() {
564 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
565 }
566
567 public boolean acceptCookies() {
568 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
569 }
570
571 public boolean saveFormdata() {
572 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
573 }
574
575 public boolean enableGeolocation() {
576 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
577 }
578
579 public boolean rememberPasswords() {
580 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
581 }
582
The Android Open Source Project0c908882009-03-03 19:32:16 -0800583}