blob: eadd57ed66201ac9a224399ecd20b438289a5416 [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 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700221 if (PREF_FULLSCREEN.equals(key)) {
222 if (mController.getUi() != null) {
223 mController.getUi().setFullscreen(useFullscreen());
224 }
225 }
John Reck35e9dd62011-04-25 09:01:54 -0700226 }
227
228 static String getFactoryResetHomeUrl(Context context) {
229 String url = context.getResources().getString(R.string.homepage_base);
230 if (url.indexOf("{CID}") != -1) {
231 url = url.replace("{CID}",
232 BrowserProvider.getClientId(context.getContentResolver()));
233 }
234 return url;
235 }
236
237 public LayoutAlgorithm getLayoutAlgorithm() {
238 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
239 if (autofitPages()) {
240 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
241 }
242 if (isDebugEnabled()) {
243 if (isSmallScreen()) {
244 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000245 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700246 if (isNormalLayout()) {
247 layoutAlgorithm = LayoutAlgorithm.NORMAL;
248 } else {
249 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
250 }
Ben Murdochef671652010-11-25 17:17:58 +0000251 }
John Reck35e9dd62011-04-25 09:01:54 -0700252 }
253 return layoutAlgorithm;
254 }
Ben Murdochef671652010-11-25 17:17:58 +0000255
John Reck35e9dd62011-04-25 09:01:54 -0700256 // TODO: Cache
257 public int getPageCacheCapacity() {
258 // the cost of one cached page is ~3M (measured using nytimes.com). For
259 // low end devices, we only cache one page. For high end devices, we try
260 // to cache more pages, currently choose 5.
261 if (ActivityManager.staticGetMemoryClass() > 16) {
262 return 5;
263 } else {
264 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800265 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800266 }
267
John Reck35e9dd62011-04-25 09:01:54 -0700268 public WebStorageSizeManager getWebStorageSizeManager() {
269 return mWebStorageSizeManager;
270 }
271
272 // TODO: Cache
273 private String getAppCachePath() {
274 return mContext.getDir("appcache", 0).getPath();
275 }
276
277 private void updateSearchEngine(boolean force) {
278 String searchEngineName = getSearchEngineName();
279 if (force || mSearchEngine == null ||
280 !mSearchEngine.getName().equals(searchEngineName)) {
281 if (mSearchEngine != null) {
282 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000283 // One or more tabs could have been in voice search mode.
284 // Clear it, since the new SearchEngine may not support
285 // it, or may handle it differently.
286 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
287 mController.getTabControl().getTab(i).revertVoiceSearchMode();
288 }
289 }
John Reck35e9dd62011-04-25 09:01:54 -0700290 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000291 }
John Reck35e9dd62011-04-25 09:01:54 -0700292 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000293
John Reck35e9dd62011-04-25 09:01:54 -0700294 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
295 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000296 }
297 }
298 }
299
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100300 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700301 if (mSearchEngine == null) {
302 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100303 }
John Reck35e9dd62011-04-25 09:01:54 -0700304 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100305 }
306
John Reck35e9dd62011-04-25 09:01:54 -0700307 public boolean isDebugEnabled() {
308 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100309 }
310
John Reck35e9dd62011-04-25 09:01:54 -0700311 public void setDebugEnabled(boolean value) {
312 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100313 }
314
John Reck35e9dd62011-04-25 09:01:54 -0700315 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800316 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700317 if (mController != null) {
318 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800319 if (current != null) {
320 current.clearCache(true);
321 }
322 }
323 }
324
John Reck35e9dd62011-04-25 09:01:54 -0700325 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800326 CookieManager.getInstance().removeAllCookie();
327 }
328
John Reck35e9dd62011-04-25 09:01:54 -0700329 public void clearHistory() {
330 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800331 Browser.clearHistory(resolver);
332 Browser.clearSearches(resolver);
333 }
334
John Reck35e9dd62011-04-25 09:01:54 -0700335 public void clearFormData() {
336 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700337 if (mController!= null) {
338 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100339 if (currentTopView != null) {
340 currentTopView.clearFormData();
341 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800342 }
343 }
344
John Reck35e9dd62011-04-25 09:01:54 -0700345 public void clearPasswords() {
346 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800347 db.clearUsernamePassword();
348 db.clearHttpAuthUsernamePassword();
349 }
350
John Reck35e9dd62011-04-25 09:01:54 -0700351 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100352 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100353 }
354
John Reck35e9dd62011-04-25 09:01:54 -0700355 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100356 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100357 }
358
John Reck35e9dd62011-04-25 09:01:54 -0700359 public void resetDefaultPreferences() {
360 mPrefs.edit().clear().apply();
361 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700362 }
363
John Reck35e9dd62011-04-25 09:01:54 -0700364 public AutoFillProfile getAutoFillProfile() {
365 mAutofillHandler.waitForLoad();
366 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800367 }
368
John Reck35e9dd62011-04-25 09:01:54 -0700369 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
370 mAutofillHandler.waitForLoad();
371 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800372 }
373
John Reck35e9dd62011-04-25 09:01:54 -0700374 public void toggleDebugSettings() {
375 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800376 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100377
John Reck35e9dd62011-04-25 09:01:54 -0700378 // -----------------------------
379 // getter/setters for accessibility_preferences.xml
380 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100381
John Reck35e9dd62011-04-25 09:01:54 -0700382 // TODO: Cache
383 public TextSize getTextSize() {
384 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
385 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100386 }
387
John Reck35e9dd62011-04-25 09:01:54 -0700388 public int getMinimumFontSize() {
389 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100390 }
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
Michael Kolbc38c6042011-04-27 10:46:06 -0700564 public boolean useFullscreen() {
565 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
566 }
567
John Reck35e9dd62011-04-25 09:01:54 -0700568 // -----------------------------
569 // getter/setters for privacy_security_preferences.xml
570 // -----------------------------
571
572 public boolean showSecurityWarnings() {
573 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
574 }
575
576 public boolean acceptCookies() {
577 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
578 }
579
580 public boolean saveFormdata() {
581 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
582 }
583
584 public boolean enableGeolocation() {
585 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
586 }
587
588 public boolean rememberPasswords() {
589 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
590 }
591
The Android Open Source Project0c908882009-03-03 19:32:16 -0800592}