blob: 7d64cfc490a6154cc95ef082a2056725d707b59b [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 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700230 if (PREF_FULLSCREEN.equals(key)) {
231 if (mController.getUi() != null) {
232 mController.getUi().setFullscreen(useFullscreen());
233 }
234 }
John Reck35e9dd62011-04-25 09:01:54 -0700235 }
236
237 static String getFactoryResetHomeUrl(Context context) {
238 String url = context.getResources().getString(R.string.homepage_base);
239 if (url.indexOf("{CID}") != -1) {
240 url = url.replace("{CID}",
241 BrowserProvider.getClientId(context.getContentResolver()));
242 }
243 return url;
244 }
245
246 public LayoutAlgorithm getLayoutAlgorithm() {
247 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
248 if (autofitPages()) {
249 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
250 }
251 if (isDebugEnabled()) {
252 if (isSmallScreen()) {
253 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000254 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700255 if (isNormalLayout()) {
256 layoutAlgorithm = LayoutAlgorithm.NORMAL;
257 } else {
258 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
259 }
Ben Murdochef671652010-11-25 17:17:58 +0000260 }
John Reck35e9dd62011-04-25 09:01:54 -0700261 }
262 return layoutAlgorithm;
263 }
Ben Murdochef671652010-11-25 17:17:58 +0000264
John Reck35e9dd62011-04-25 09:01:54 -0700265 // TODO: Cache
266 public int getPageCacheCapacity() {
267 // the cost of one cached page is ~3M (measured using nytimes.com). For
268 // low end devices, we only cache one page. For high end devices, we try
269 // to cache more pages, currently choose 5.
270 if (ActivityManager.staticGetMemoryClass() > 16) {
271 return 5;
272 } else {
273 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800274 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800275 }
276
John Reck35e9dd62011-04-25 09:01:54 -0700277 public WebStorageSizeManager getWebStorageSizeManager() {
278 return mWebStorageSizeManager;
279 }
280
281 // TODO: Cache
282 private String getAppCachePath() {
283 return mContext.getDir("appcache", 0).getPath();
284 }
285
286 private void updateSearchEngine(boolean force) {
287 String searchEngineName = getSearchEngineName();
288 if (force || mSearchEngine == null ||
289 !mSearchEngine.getName().equals(searchEngineName)) {
290 if (mSearchEngine != null) {
291 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000292 // One or more tabs could have been in voice search mode.
293 // Clear it, since the new SearchEngine may not support
294 // it, or may handle it differently.
295 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
296 mController.getTabControl().getTab(i).revertVoiceSearchMode();
297 }
298 }
John Reck35e9dd62011-04-25 09:01:54 -0700299 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000300 }
John Reck35e9dd62011-04-25 09:01:54 -0700301 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000302
John Reck35e9dd62011-04-25 09:01:54 -0700303 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
304 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000305 }
306 }
307 }
308
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100309 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700310 if (mSearchEngine == null) {
311 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100312 }
John Reck35e9dd62011-04-25 09:01:54 -0700313 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100314 }
315
John Reck35e9dd62011-04-25 09:01:54 -0700316 public boolean isDebugEnabled() {
317 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100318 }
319
John Reck35e9dd62011-04-25 09:01:54 -0700320 public void setDebugEnabled(boolean value) {
321 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100322 }
323
John Reck35e9dd62011-04-25 09:01:54 -0700324 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800325 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700326 if (mController != null) {
327 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800328 if (current != null) {
329 current.clearCache(true);
330 }
331 }
332 }
333
John Reck35e9dd62011-04-25 09:01:54 -0700334 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800335 CookieManager.getInstance().removeAllCookie();
336 }
337
John Reck35e9dd62011-04-25 09:01:54 -0700338 public void clearHistory() {
339 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800340 Browser.clearHistory(resolver);
341 Browser.clearSearches(resolver);
342 }
343
John Reck35e9dd62011-04-25 09:01:54 -0700344 public void clearFormData() {
345 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700346 if (mController!= null) {
347 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100348 if (currentTopView != null) {
349 currentTopView.clearFormData();
350 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800351 }
352 }
353
John Reck35e9dd62011-04-25 09:01:54 -0700354 public void clearPasswords() {
355 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800356 db.clearUsernamePassword();
357 db.clearHttpAuthUsernamePassword();
358 }
359
John Reck35e9dd62011-04-25 09:01:54 -0700360 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100361 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100362 }
363
John Reck35e9dd62011-04-25 09:01:54 -0700364 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100365 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100366 }
367
John Reck35e9dd62011-04-25 09:01:54 -0700368 public void resetDefaultPreferences() {
369 mPrefs.edit().clear().apply();
370 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700371 }
372
John Reck35e9dd62011-04-25 09:01:54 -0700373 public AutoFillProfile getAutoFillProfile() {
374 mAutofillHandler.waitForLoad();
375 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800376 }
377
John Reck35e9dd62011-04-25 09:01:54 -0700378 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
379 mAutofillHandler.waitForLoad();
380 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800381 }
382
John Reck35e9dd62011-04-25 09:01:54 -0700383 public void toggleDebugSettings() {
384 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800385 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100386
John Reck35e9dd62011-04-25 09:01:54 -0700387 // -----------------------------
388 // getter/setters for accessibility_preferences.xml
389 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100390
John Reck35e9dd62011-04-25 09:01:54 -0700391 // TODO: Cache
392 public TextSize getTextSize() {
393 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
394 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100395 }
396
John Reck35e9dd62011-04-25 09:01:54 -0700397 public int getMinimumFontSize() {
398 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100399 }
400
John Reck92f25f82011-04-26 16:57:10 -0700401 public boolean forceEnableUserScalable() {
402 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
403 }
404
John Reck35e9dd62011-04-25 09:01:54 -0700405 // -----------------------------
406 // getter/setters for advanced_preferences.xml
407 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100408
John Reck35e9dd62011-04-25 09:01:54 -0700409 public String getSearchEngineName() {
410 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100411 }
John Reck63bb6872010-12-01 19:29:32 -0800412
John Reck35e9dd62011-04-25 09:01:54 -0700413 public boolean openInBackground() {
414 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800415 }
John Reck35e9dd62011-04-25 09:01:54 -0700416
417 public boolean enableJavascript() {
418 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
419 }
420
421 // TODO: Cache
422 public PluginState getPluginState() {
423 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
424 return PluginState.valueOf(state);
425 }
426
427 // TODO: Cache
428 public ZoomDensity getDefaultZoom() {
429 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
430 return ZoomDensity.valueOf(zoom);
431 }
432
433 public boolean loadPageInOverviewMode() {
434 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
435 }
436
437 public boolean autofitPages() {
438 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
439 }
440
441 public boolean blockPopupWindows() {
442 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
443 }
444
445 public boolean loadImages() {
446 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
447 }
448
449 public String getDefaultTextEncoding() {
450 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
451 }
452
453 // -----------------------------
454 // getter/setters for general_preferences.xml
455 // -----------------------------
456
457 public String getHomePage() {
458 if (useMostVisitedHomepage()) {
459 return HomeProvider.MOST_VISITED;
460 }
461 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
462 }
463
464 public void setHomePage(String value) {
465 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
466 }
467
468 public boolean isAutofillEnabled() {
469 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
470 }
471
472 public void setAutofillEnabled(boolean value) {
473 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
474 }
475
476 // -----------------------------
477 // getter/setters for debug_preferences.xml
478 // -----------------------------
479
480 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700481 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700482 return true;
483 }
484 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
485 }
486
487 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700488 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700489 return 0;
490 }
491 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
492 }
493
494 // -----------------------------
495 // getter/setters for hidden_debug_preferences.xml
496 // -----------------------------
497
498 public boolean enableVisualIndicator() {
499 if (!isDebugEnabled()) {
500 return false;
501 }
502 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
503 }
504
505 public boolean enableJavascriptConsole() {
506 if (!isDebugEnabled()) {
507 return false;
508 }
509 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
510 }
511
512 public boolean isSmallScreen() {
513 if (!isDebugEnabled()) {
514 return false;
515 }
516 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
517 }
518
519 public boolean isWideViewport() {
520 if (!isDebugEnabled()) {
521 return true;
522 }
523 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
524 }
525
526 public boolean isNormalLayout() {
527 if (!isDebugEnabled()) {
528 return false;
529 }
530 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
531 }
532
533 public boolean isTracing() {
534 if (!isDebugEnabled()) {
535 return false;
536 }
537 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
538 }
539
540 public boolean enableLightTouch() {
541 if (!isDebugEnabled()) {
542 return false;
543 }
544 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
545 }
546
547 public boolean enableNavDump() {
548 if (!isDebugEnabled()) {
549 return false;
550 }
551 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
552 }
553
554 public String getJsEngineFlags() {
555 if (!isDebugEnabled()) {
556 return "";
557 }
558 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
559 }
560
561 // -----------------------------
562 // getter/setters for lab_preferences.xml
563 // -----------------------------
564
565 public boolean useQuickControls() {
566 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
567 }
568
569 public boolean useMostVisitedHomepage() {
570 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
571 }
572
573 public boolean useInstantSearch() {
574 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
575 }
576
Michael Kolbc38c6042011-04-27 10:46:06 -0700577 public boolean useFullscreen() {
578 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
579 }
580
John Reck35e9dd62011-04-25 09:01:54 -0700581 // -----------------------------
582 // getter/setters for privacy_security_preferences.xml
583 // -----------------------------
584
585 public boolean showSecurityWarnings() {
586 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
587 }
588
589 public boolean acceptCookies() {
590 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
591 }
592
593 public boolean saveFormdata() {
594 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
595 }
596
597 public boolean enableGeolocation() {
598 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
599 }
600
601 public boolean rememberPasswords() {
602 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
603 }
604
The Android Open Source Project0c908882009-03-03 19:32:16 -0800605}