blob: 642fd18f62f1bb8e11795761b98ba835e28982fa [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());
John Reck92f25f82011-04-26 16:57:10 -0700142 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700143 settings.setPluginState(getPluginState());
144 settings.setTextSize(getTextSize());
145 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
146 settings.setAutoFillEnabled(isAutofillEnabled());
147 settings.setLayoutAlgorithm(getLayoutAlgorithm());
148 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
149 settings.setLoadsImagesAutomatically(loadImages());
150 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
151 settings.setSavePassword(rememberPasswords());
152 settings.setSaveFormData(saveFormdata());
153 settings.setUseWideViewPort(isWideViewport());
154 settings.setAutoFillProfile(getAutoFillProfile());
Ben Murdochef671652010-11-25 17:17:58 +0000155 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800156
John Reck35e9dd62011-04-25 09:01:54 -0700157 /**
158 * Syncs all the settings that have no UI
159 * These cannot change, so we only need to set them once per WebSettings
160 */
161 private void syncStaticSettings(WebSettings settings) {
162 settings.setDefaultFontSize(16);
163 settings.setDefaultFixedFontSize(13);
164 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000165
John Reck35e9dd62011-04-25 09:01:54 -0700166 // WebView inside Browser doesn't want initial focus to be set.
167 settings.setNeedInitialFocus(false);
168 // Browser supports multiple windows
169 settings.setSupportMultipleWindows(true);
170 // enable smooth transition for better performance during panning or
171 // zooming
172 settings.setEnableSmoothTransition(true);
173 // disable content url access
174 settings.setAllowContentAccess(false);
175
176 // HTML5 API flags
177 settings.setAppCacheEnabled(true);
178 settings.setDatabaseEnabled(true);
179 settings.setDomStorageEnabled(true);
180 settings.setWorkersEnabled(true); // This only affects V8.
181
182 // HTML5 configuration parametersettings.
183 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
184 settings.setAppCachePath(getAppCachePath());
185 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
186 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
187 }
188
189 private void syncSharedSettings() {
190 CookieManager.getInstance().setAcceptCookie(acceptCookies());
191 if (mController != null) {
192 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700193 }
John Reck35e9dd62011-04-25 09:01:54 -0700194 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700195
John Reck35e9dd62011-04-25 09:01:54 -0700196 private void syncManagedSettings() {
197 syncSharedSettings();
198 synchronized (mManagedSettings) {
199 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
200 while (iter.hasNext()) {
201 WeakReference<WebSettings> ref = iter.next();
202 WebSettings settings = ref.get();
203 if (settings == null) {
204 iter.remove();
205 continue;
206 }
207 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000208 }
John Reck35e9dd62011-04-25 09:01:54 -0700209 }
210 }
Ben Murdochef671652010-11-25 17:17:58 +0000211
John Reck35e9dd62011-04-25 09:01:54 -0700212 @Override
213 public void onSharedPreferenceChanged(
214 SharedPreferences sharedPreferences, String key) {
215 syncManagedSettings();
216 if (PREF_SEARCH_ENGINE.equals(key)) {
217 updateSearchEngine(false);
218 }
219 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
220 updateSearchEngine(true);
221 }
222 }
223
224 static String getFactoryResetHomeUrl(Context context) {
225 String url = context.getResources().getString(R.string.homepage_base);
226 if (url.indexOf("{CID}") != -1) {
227 url = url.replace("{CID}",
228 BrowserProvider.getClientId(context.getContentResolver()));
229 }
230 return url;
231 }
232
233 public LayoutAlgorithm getLayoutAlgorithm() {
234 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
235 if (autofitPages()) {
236 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
237 }
238 if (isDebugEnabled()) {
239 if (isSmallScreen()) {
240 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000241 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700242 if (isNormalLayout()) {
243 layoutAlgorithm = LayoutAlgorithm.NORMAL;
244 } else {
245 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
246 }
Ben Murdochef671652010-11-25 17:17:58 +0000247 }
John Reck35e9dd62011-04-25 09:01:54 -0700248 }
249 return layoutAlgorithm;
250 }
Ben Murdochef671652010-11-25 17:17:58 +0000251
John Reck35e9dd62011-04-25 09:01:54 -0700252 // TODO: Cache
253 public int getPageCacheCapacity() {
254 // the cost of one cached page is ~3M (measured using nytimes.com). For
255 // low end devices, we only cache one page. For high end devices, we try
256 // to cache more pages, currently choose 5.
257 if (ActivityManager.staticGetMemoryClass() > 16) {
258 return 5;
259 } else {
260 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800261 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800262 }
263
John Reck35e9dd62011-04-25 09:01:54 -0700264 public WebStorageSizeManager getWebStorageSizeManager() {
265 return mWebStorageSizeManager;
266 }
267
268 // TODO: Cache
269 private String getAppCachePath() {
270 return mContext.getDir("appcache", 0).getPath();
271 }
272
273 private void updateSearchEngine(boolean force) {
274 String searchEngineName = getSearchEngineName();
275 if (force || mSearchEngine == null ||
276 !mSearchEngine.getName().equals(searchEngineName)) {
277 if (mSearchEngine != null) {
278 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000279 // One or more tabs could have been in voice search mode.
280 // Clear it, since the new SearchEngine may not support
281 // it, or may handle it differently.
282 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
283 mController.getTabControl().getTab(i).revertVoiceSearchMode();
284 }
285 }
John Reck35e9dd62011-04-25 09:01:54 -0700286 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000287 }
John Reck35e9dd62011-04-25 09:01:54 -0700288 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000289
John Reck35e9dd62011-04-25 09:01:54 -0700290 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
291 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000292 }
293 }
294 }
295
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100296 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700297 if (mSearchEngine == null) {
298 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100299 }
John Reck35e9dd62011-04-25 09:01:54 -0700300 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100301 }
302
John Reck35e9dd62011-04-25 09:01:54 -0700303 public boolean isDebugEnabled() {
304 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100305 }
306
John Reck35e9dd62011-04-25 09:01:54 -0700307 public void setDebugEnabled(boolean value) {
308 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100309 }
310
John Reck35e9dd62011-04-25 09:01:54 -0700311 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800312 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700313 if (mController != null) {
314 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800315 if (current != null) {
316 current.clearCache(true);
317 }
318 }
319 }
320
John Reck35e9dd62011-04-25 09:01:54 -0700321 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800322 CookieManager.getInstance().removeAllCookie();
323 }
324
John Reck35e9dd62011-04-25 09:01:54 -0700325 public void clearHistory() {
326 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800327 Browser.clearHistory(resolver);
328 Browser.clearSearches(resolver);
329 }
330
John Reck35e9dd62011-04-25 09:01:54 -0700331 public void clearFormData() {
332 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700333 if (mController!= null) {
334 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100335 if (currentTopView != null) {
336 currentTopView.clearFormData();
337 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800338 }
339 }
340
John Reck35e9dd62011-04-25 09:01:54 -0700341 public void clearPasswords() {
342 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800343 db.clearUsernamePassword();
344 db.clearHttpAuthUsernamePassword();
345 }
346
John Reck35e9dd62011-04-25 09:01:54 -0700347 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100348 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100349 }
350
John Reck35e9dd62011-04-25 09:01:54 -0700351 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100352 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100353 }
354
John Reck35e9dd62011-04-25 09:01:54 -0700355 public void resetDefaultPreferences() {
356 mPrefs.edit().clear().apply();
357 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700358 }
359
John Reck35e9dd62011-04-25 09:01:54 -0700360 public AutoFillProfile getAutoFillProfile() {
361 mAutofillHandler.waitForLoad();
362 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800363 }
364
John Reck35e9dd62011-04-25 09:01:54 -0700365 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
366 mAutofillHandler.waitForLoad();
367 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800368 }
369
John Reck35e9dd62011-04-25 09:01:54 -0700370 public void toggleDebugSettings() {
371 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800372 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100373
John Reck35e9dd62011-04-25 09:01:54 -0700374 // -----------------------------
375 // getter/setters for accessibility_preferences.xml
376 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100377
John Reck35e9dd62011-04-25 09:01:54 -0700378 // TODO: Cache
379 public TextSize getTextSize() {
380 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
381 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100382 }
383
John Reck35e9dd62011-04-25 09:01:54 -0700384 public int getMinimumFontSize() {
385 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100386 }
387
John Reck92f25f82011-04-26 16:57:10 -0700388 public boolean forceEnableUserScalable() {
389 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
390 }
391
John Reck35e9dd62011-04-25 09:01:54 -0700392 // -----------------------------
393 // getter/setters for advanced_preferences.xml
394 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100395
John Reck35e9dd62011-04-25 09:01:54 -0700396 public String getSearchEngineName() {
397 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100398 }
John Reck63bb6872010-12-01 19:29:32 -0800399
John Reck35e9dd62011-04-25 09:01:54 -0700400 public boolean openInBackground() {
401 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800402 }
John Reck35e9dd62011-04-25 09:01:54 -0700403
404 public boolean enableJavascript() {
405 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
406 }
407
408 // TODO: Cache
409 public PluginState getPluginState() {
410 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
411 return PluginState.valueOf(state);
412 }
413
414 // TODO: Cache
415 public ZoomDensity getDefaultZoom() {
416 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
417 return ZoomDensity.valueOf(zoom);
418 }
419
420 public boolean loadPageInOverviewMode() {
421 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
422 }
423
424 public boolean autofitPages() {
425 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
426 }
427
428 public boolean blockPopupWindows() {
429 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
430 }
431
432 public boolean loadImages() {
433 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
434 }
435
436 public String getDefaultTextEncoding() {
437 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
438 }
439
440 // -----------------------------
441 // getter/setters for general_preferences.xml
442 // -----------------------------
443
444 public String getHomePage() {
445 if (useMostVisitedHomepage()) {
446 return HomeProvider.MOST_VISITED;
447 }
448 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
449 }
450
451 public void setHomePage(String value) {
452 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
453 }
454
455 public boolean isAutofillEnabled() {
456 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
457 }
458
459 public void setAutofillEnabled(boolean value) {
460 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
461 }
462
463 // -----------------------------
464 // getter/setters for debug_preferences.xml
465 // -----------------------------
466
467 public boolean isHardwareAccelerated() {
468 if (!isDebugEnabled() && !DEV_BUILD) {
469 return true;
470 }
471 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
472 }
473
474 public int getUserAgent() {
475 if (!isDebugEnabled() && !DEV_BUILD) {
476 return 0;
477 }
478 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
479 }
480
481 // -----------------------------
482 // getter/setters for hidden_debug_preferences.xml
483 // -----------------------------
484
485 public boolean enableVisualIndicator() {
486 if (!isDebugEnabled()) {
487 return false;
488 }
489 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
490 }
491
492 public boolean enableJavascriptConsole() {
493 if (!isDebugEnabled()) {
494 return false;
495 }
496 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
497 }
498
499 public boolean isSmallScreen() {
500 if (!isDebugEnabled()) {
501 return false;
502 }
503 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
504 }
505
506 public boolean isWideViewport() {
507 if (!isDebugEnabled()) {
508 return true;
509 }
510 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
511 }
512
513 public boolean isNormalLayout() {
514 if (!isDebugEnabled()) {
515 return false;
516 }
517 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
518 }
519
520 public boolean isTracing() {
521 if (!isDebugEnabled()) {
522 return false;
523 }
524 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
525 }
526
527 public boolean enableLightTouch() {
528 if (!isDebugEnabled()) {
529 return false;
530 }
531 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
532 }
533
534 public boolean enableNavDump() {
535 if (!isDebugEnabled()) {
536 return false;
537 }
538 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
539 }
540
541 public String getJsEngineFlags() {
542 if (!isDebugEnabled()) {
543 return "";
544 }
545 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
546 }
547
548 // -----------------------------
549 // getter/setters for lab_preferences.xml
550 // -----------------------------
551
552 public boolean useQuickControls() {
553 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
554 }
555
556 public boolean useMostVisitedHomepage() {
557 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
558 }
559
560 public boolean useInstantSearch() {
561 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
562 }
563
564 // -----------------------------
565 // getter/setters for privacy_security_preferences.xml
566 // -----------------------------
567
568 public boolean showSecurityWarnings() {
569 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
570 }
571
572 public boolean acceptCookies() {
573 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
574 }
575
576 public boolean saveFormdata() {
577 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
578 }
579
580 public boolean enableGeolocation() {
581 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
582 }
583
584 public boolean rememberPasswords() {
585 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
586 }
587
The Android Open Source Project0c908882009-03-03 19:32:16 -0800588}