blob: 101effa4d1205bd4fd1f9f008916d3c310706529 [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
Grace Kloba9804c432009-12-02 11:07:40 -080019import android.app.ActivityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.content.ContentResolver;
21import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.content.SharedPreferences;
John Reck812d2d62011-01-18 14:16:15 -080023import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
John Reckf48314f2011-04-27 17:52:17 -070024import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010025import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010026import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.provider.Browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010029import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030import android.webkit.WebIconDatabase;
31import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010032import android.webkit.WebSettings.AutoFillProfile;
John Reck35e9dd62011-04-25 09:01:54 -070033import android.webkit.WebSettings.LayoutAlgorithm;
34import android.webkit.WebSettings.PluginState;
35import android.webkit.WebSettings.TextSize;
36import android.webkit.WebSettings.ZoomDensity;
Nicolas Roard78a98e42009-05-11 13:34:17 +010037import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080038import android.webkit.WebView;
39import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080040
John Reck46500332011-06-07 14:36:10 -070041import com.android.browser.homepages.HomeProvider;
42import com.android.browser.provider.BrowserProvider;
43import com.android.browser.search.SearchEngine;
44import com.android.browser.search.SearchEngines;
45
John Reck35e9dd62011-04-25 09:01:54 -070046import java.lang.ref.WeakReference;
47import java.util.Iterator;
48import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070049import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080050
John Reck35e9dd62011-04-25 09:01:54 -070051/**
52 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080053 */
John Reck35e9dd62011-04-25 09:01:54 -070054public class BrowserSettings implements OnSharedPreferenceChangeListener,
55 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010056
John Reck35e9dd62011-04-25 09:01:54 -070057 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070058 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
59 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
60 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080061
62 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070063 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
64 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070065
66 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070067 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
68 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070069
70 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070071 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
72 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080073
John Reck7fd1e8f2011-04-27 18:22:57 -070074 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
75 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
76 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
77
John Reck35e9dd62011-04-25 09:01:54 -070078 private static final String USER_AGENTS[] = { null,
79 DESKTOP_USERAGENT,
80 IPHONE_USERAGENT,
81 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070082 FROYO_USERAGENT,
83 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070084 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080085
John Reck35e9dd62011-04-25 09:01:54 -070086 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070087
John Reck35e9dd62011-04-25 09:01:54 -070088 private Context mContext;
89 private SharedPreferences mPrefs;
90 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070091 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070092 private WebStorageSizeManager mWebStorageSizeManager;
93 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -070094 private WeakHashMap<WebSettings, String> mCustomUserAgents;
The Android Open Source Project0c908882009-03-03 19:32:16 -080095
John Reck35e9dd62011-04-25 09:01:54 -070096 // Cached settings
97 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080098
John Reck35e9dd62011-04-25 09:01:54 -070099 public static void initialize(final Context context) {
100 sInstance = new BrowserSettings(context);
101 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800102
John Reck35e9dd62011-04-25 09:01:54 -0700103 public static BrowserSettings getInstance() {
104 return sInstance;
105 }
Ben Murdochef671652010-11-25 17:17:58 +0000106
John Reck35e9dd62011-04-25 09:01:54 -0700107 private BrowserSettings(Context context) {
108 mContext = context;
109 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reckf48314f2011-04-27 17:52:17 -0700110 if (Build.VERSION.CODENAME.equals("REL")) {
111 // This is a release build, always startup with debug disabled
112 setDebugEnabled(false);
113 }
John Reck35e9dd62011-04-25 09:01:54 -0700114 mAutofillHandler = new AutofillHandler(mContext);
115 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700116 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reck35e9dd62011-04-25 09:01:54 -0700117 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
118 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
119 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
120 mPrefs.registerOnSharedPreferenceChangeListener(this);
121 mAutofillHandler.asyncLoadFromDb();
122 }
123
124 public void setController(Controller controller) {
125 mController = controller;
126 syncSharedSettings();
127
128 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
129 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000130 }
131 }
132
John Reck35e9dd62011-04-25 09:01:54 -0700133 public void startManagingSettings(WebSettings settings) {
134 synchronized (mManagedSettings) {
135 syncStaticSettings(settings);
136 syncSetting(settings);
137 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800138 }
139 }
140
141 /**
John Reck35e9dd62011-04-25 09:01:54 -0700142 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800143 */
John Reck35e9dd62011-04-25 09:01:54 -0700144 private void syncSetting(WebSettings settings) {
145 settings.setGeolocationEnabled(enableGeolocation());
146 settings.setJavaScriptEnabled(enableJavascript());
147 settings.setLightTouchEnabled(enableLightTouch());
148 settings.setNavDump(enableNavDump());
149 settings.setShowVisualIndicator(enableVisualIndicator());
150 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
151 settings.setDefaultZoom(getDefaultZoom());
152 settings.setMinimumFontSize(getMinimumFontSize());
153 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700154 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700155 settings.setPluginState(getPluginState());
156 settings.setTextSize(getTextSize());
John Reck35e9dd62011-04-25 09:01:54 -0700157 settings.setAutoFillEnabled(isAutofillEnabled());
158 settings.setLayoutAlgorithm(getLayoutAlgorithm());
159 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
160 settings.setLoadsImagesAutomatically(loadImages());
161 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
162 settings.setSavePassword(rememberPasswords());
163 settings.setSaveFormData(saveFormdata());
164 settings.setUseWideViewPort(isWideViewport());
165 settings.setAutoFillProfile(getAutoFillProfile());
John Reckb8b2af82011-05-20 15:58:33 -0700166
167 String ua = mCustomUserAgents.get(settings);
John Reck46500332011-06-07 14:36:10 -0700168 if (ua != null) {
John Reckb8b2af82011-05-20 15:58:33 -0700169 settings.setUserAgentString(ua);
170 } else {
171 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
172 }
Ben Murdochef671652010-11-25 17:17:58 +0000173 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800174
John Reck35e9dd62011-04-25 09:01:54 -0700175 /**
176 * Syncs all the settings that have no UI
177 * These cannot change, so we only need to set them once per WebSettings
178 */
179 private void syncStaticSettings(WebSettings settings) {
180 settings.setDefaultFontSize(16);
181 settings.setDefaultFixedFontSize(13);
182 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000183
John Reck35e9dd62011-04-25 09:01:54 -0700184 // WebView inside Browser doesn't want initial focus to be set.
185 settings.setNeedInitialFocus(false);
186 // Browser supports multiple windows
187 settings.setSupportMultipleWindows(true);
188 // enable smooth transition for better performance during panning or
189 // zooming
190 settings.setEnableSmoothTransition(true);
191 // disable content url access
192 settings.setAllowContentAccess(false);
193
194 // HTML5 API flags
195 settings.setAppCacheEnabled(true);
196 settings.setDatabaseEnabled(true);
197 settings.setDomStorageEnabled(true);
198 settings.setWorkersEnabled(true); // This only affects V8.
199
200 // HTML5 configuration parametersettings.
201 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
202 settings.setAppCachePath(getAppCachePath());
203 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
204 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
205 }
206
207 private void syncSharedSettings() {
208 CookieManager.getInstance().setAcceptCookie(acceptCookies());
209 if (mController != null) {
210 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700211 }
John Reck35e9dd62011-04-25 09:01:54 -0700212 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700213
John Reck35e9dd62011-04-25 09:01:54 -0700214 private void syncManagedSettings() {
215 syncSharedSettings();
216 synchronized (mManagedSettings) {
217 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
218 while (iter.hasNext()) {
219 WeakReference<WebSettings> ref = iter.next();
220 WebSettings settings = ref.get();
221 if (settings == null) {
222 iter.remove();
223 continue;
224 }
225 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000226 }
John Reck35e9dd62011-04-25 09:01:54 -0700227 }
228 }
Ben Murdochef671652010-11-25 17:17:58 +0000229
John Reck35e9dd62011-04-25 09:01:54 -0700230 @Override
231 public void onSharedPreferenceChanged(
232 SharedPreferences sharedPreferences, String key) {
233 syncManagedSettings();
234 if (PREF_SEARCH_ENGINE.equals(key)) {
235 updateSearchEngine(false);
236 }
237 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
238 updateSearchEngine(true);
239 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700240 if (PREF_FULLSCREEN.equals(key)) {
241 if (mController.getUi() != null) {
242 mController.getUi().setFullscreen(useFullscreen());
243 }
244 }
John Reck35e9dd62011-04-25 09:01:54 -0700245 }
246
247 static String getFactoryResetHomeUrl(Context context) {
248 String url = context.getResources().getString(R.string.homepage_base);
249 if (url.indexOf("{CID}") != -1) {
250 url = url.replace("{CID}",
251 BrowserProvider.getClientId(context.getContentResolver()));
252 }
253 return url;
254 }
255
256 public LayoutAlgorithm getLayoutAlgorithm() {
257 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
258 if (autofitPages()) {
259 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
260 }
261 if (isDebugEnabled()) {
262 if (isSmallScreen()) {
263 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000264 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700265 if (isNormalLayout()) {
266 layoutAlgorithm = LayoutAlgorithm.NORMAL;
267 } else {
268 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
269 }
Ben Murdochef671652010-11-25 17:17:58 +0000270 }
John Reck35e9dd62011-04-25 09:01:54 -0700271 }
272 return layoutAlgorithm;
273 }
Ben Murdochef671652010-11-25 17:17:58 +0000274
John Reck35e9dd62011-04-25 09:01:54 -0700275 // TODO: Cache
276 public int getPageCacheCapacity() {
277 // the cost of one cached page is ~3M (measured using nytimes.com). For
278 // low end devices, we only cache one page. For high end devices, we try
279 // to cache more pages, currently choose 5.
280 if (ActivityManager.staticGetMemoryClass() > 16) {
281 return 5;
282 } else {
283 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800284 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800285 }
286
John Reck35e9dd62011-04-25 09:01:54 -0700287 public WebStorageSizeManager getWebStorageSizeManager() {
288 return mWebStorageSizeManager;
289 }
290
291 // TODO: Cache
292 private String getAppCachePath() {
293 return mContext.getDir("appcache", 0).getPath();
294 }
295
296 private void updateSearchEngine(boolean force) {
297 String searchEngineName = getSearchEngineName();
298 if (force || mSearchEngine == null ||
299 !mSearchEngine.getName().equals(searchEngineName)) {
300 if (mSearchEngine != null) {
301 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000302 // One or more tabs could have been in voice search mode.
303 // Clear it, since the new SearchEngine may not support
304 // it, or may handle it differently.
305 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
306 mController.getTabControl().getTab(i).revertVoiceSearchMode();
307 }
308 }
John Reck35e9dd62011-04-25 09:01:54 -0700309 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000310 }
John Reck35e9dd62011-04-25 09:01:54 -0700311 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000312
John Reck35e9dd62011-04-25 09:01:54 -0700313 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
314 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000315 }
316 }
317 }
318
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100319 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700320 if (mSearchEngine == null) {
321 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100322 }
John Reck35e9dd62011-04-25 09:01:54 -0700323 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100324 }
325
John Reck35e9dd62011-04-25 09:01:54 -0700326 public boolean isDebugEnabled() {
327 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100328 }
329
John Reck35e9dd62011-04-25 09:01:54 -0700330 public void setDebugEnabled(boolean value) {
331 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100332 }
333
John Reck35e9dd62011-04-25 09:01:54 -0700334 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800335 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700336 if (mController != null) {
337 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800338 if (current != null) {
339 current.clearCache(true);
340 }
341 }
342 }
343
John Reck35e9dd62011-04-25 09:01:54 -0700344 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800345 CookieManager.getInstance().removeAllCookie();
346 }
347
John Reck35e9dd62011-04-25 09:01:54 -0700348 public void clearHistory() {
349 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800350 Browser.clearHistory(resolver);
351 Browser.clearSearches(resolver);
352 }
353
John Reck35e9dd62011-04-25 09:01:54 -0700354 public void clearFormData() {
355 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700356 if (mController!= null) {
357 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100358 if (currentTopView != null) {
359 currentTopView.clearFormData();
360 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800361 }
362 }
363
John Reck35e9dd62011-04-25 09:01:54 -0700364 public void clearPasswords() {
365 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800366 db.clearUsernamePassword();
367 db.clearHttpAuthUsernamePassword();
368 }
369
John Reck35e9dd62011-04-25 09:01:54 -0700370 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100371 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100372 }
373
John Reck35e9dd62011-04-25 09:01:54 -0700374 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100375 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100376 }
377
John Reck35e9dd62011-04-25 09:01:54 -0700378 public void resetDefaultPreferences() {
379 mPrefs.edit().clear().apply();
380 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700381 }
382
John Reck35e9dd62011-04-25 09:01:54 -0700383 public AutoFillProfile getAutoFillProfile() {
384 mAutofillHandler.waitForLoad();
385 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800386 }
387
John Reck35e9dd62011-04-25 09:01:54 -0700388 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
389 mAutofillHandler.waitForLoad();
390 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800391 }
392
John Reck35e9dd62011-04-25 09:01:54 -0700393 public void toggleDebugSettings() {
394 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800395 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100396
John Reckb8b2af82011-05-20 15:58:33 -0700397 public boolean hasDesktopUseragent(WebView view) {
398 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
399 }
400
401 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700402 if (view == null) {
403 return;
404 }
John Reckb8b2af82011-05-20 15:58:33 -0700405 WebSettings settings = view.getSettings();
406 if (mCustomUserAgents.get(settings) != null) {
407 mCustomUserAgents.remove(settings);
408 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
409 } else {
410 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
411 settings.setUserAgentString(DESKTOP_USERAGENT);
412 }
413 }
414
John Reck35e9dd62011-04-25 09:01:54 -0700415 // -----------------------------
416 // getter/setters for accessibility_preferences.xml
417 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100418
John Reck35e9dd62011-04-25 09:01:54 -0700419 // TODO: Cache
420 public TextSize getTextSize() {
421 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
422 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100423 }
424
John Reck35e9dd62011-04-25 09:01:54 -0700425 public int getMinimumFontSize() {
426 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100427 }
428
John Reck92f25f82011-04-26 16:57:10 -0700429 public boolean forceEnableUserScalable() {
430 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
431 }
432
John Reck35e9dd62011-04-25 09:01:54 -0700433 // -----------------------------
434 // getter/setters for advanced_preferences.xml
435 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100436
John Reck35e9dd62011-04-25 09:01:54 -0700437 public String getSearchEngineName() {
438 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100439 }
John Reck63bb6872010-12-01 19:29:32 -0800440
John Reck35e9dd62011-04-25 09:01:54 -0700441 public boolean openInBackground() {
442 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800443 }
John Reck35e9dd62011-04-25 09:01:54 -0700444
445 public boolean enableJavascript() {
446 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
447 }
448
449 // TODO: Cache
450 public PluginState getPluginState() {
451 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
452 return PluginState.valueOf(state);
453 }
454
455 // TODO: Cache
456 public ZoomDensity getDefaultZoom() {
457 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
458 return ZoomDensity.valueOf(zoom);
459 }
460
461 public boolean loadPageInOverviewMode() {
462 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
463 }
464
465 public boolean autofitPages() {
466 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
467 }
468
469 public boolean blockPopupWindows() {
470 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
471 }
472
473 public boolean loadImages() {
474 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
475 }
476
477 public String getDefaultTextEncoding() {
478 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
479 }
480
481 // -----------------------------
482 // getter/setters for general_preferences.xml
483 // -----------------------------
484
485 public String getHomePage() {
486 if (useMostVisitedHomepage()) {
487 return HomeProvider.MOST_VISITED;
488 }
489 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
490 }
491
492 public void setHomePage(String value) {
493 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
494 }
495
496 public boolean isAutofillEnabled() {
497 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
498 }
499
500 public void setAutofillEnabled(boolean value) {
501 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
502 }
503
504 // -----------------------------
505 // getter/setters for debug_preferences.xml
506 // -----------------------------
507
508 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700509 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700510 return true;
511 }
512 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
513 }
514
515 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700516 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700517 return 0;
518 }
519 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
520 }
521
522 // -----------------------------
523 // getter/setters for hidden_debug_preferences.xml
524 // -----------------------------
525
526 public boolean enableVisualIndicator() {
527 if (!isDebugEnabled()) {
528 return false;
529 }
530 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
531 }
532
533 public boolean enableJavascriptConsole() {
534 if (!isDebugEnabled()) {
535 return false;
536 }
537 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
538 }
539
540 public boolean isSmallScreen() {
541 if (!isDebugEnabled()) {
542 return false;
543 }
544 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
545 }
546
547 public boolean isWideViewport() {
548 if (!isDebugEnabled()) {
549 return true;
550 }
551 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
552 }
553
554 public boolean isNormalLayout() {
555 if (!isDebugEnabled()) {
556 return false;
557 }
558 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
559 }
560
561 public boolean isTracing() {
562 if (!isDebugEnabled()) {
563 return false;
564 }
565 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
566 }
567
568 public boolean enableLightTouch() {
569 if (!isDebugEnabled()) {
570 return false;
571 }
572 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
573 }
574
575 public boolean enableNavDump() {
576 if (!isDebugEnabled()) {
577 return false;
578 }
579 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
580 }
581
582 public String getJsEngineFlags() {
583 if (!isDebugEnabled()) {
584 return "";
585 }
586 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
587 }
588
589 // -----------------------------
590 // getter/setters for lab_preferences.xml
591 // -----------------------------
592
593 public boolean useQuickControls() {
594 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
595 }
596
597 public boolean useMostVisitedHomepage() {
598 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
599 }
600
601 public boolean useInstantSearch() {
602 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
603 }
604
Michael Kolbc38c6042011-04-27 10:46:06 -0700605 public boolean useFullscreen() {
606 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
607 }
608
John Reck35e9dd62011-04-25 09:01:54 -0700609 // -----------------------------
610 // getter/setters for privacy_security_preferences.xml
611 // -----------------------------
612
613 public boolean showSecurityWarnings() {
614 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
615 }
616
617 public boolean acceptCookies() {
618 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
619 }
620
621 public boolean saveFormdata() {
622 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
623 }
624
625 public boolean enableGeolocation() {
626 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
627 }
628
629 public boolean rememberPasswords() {
630 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
631 }
632
The Android Open Source Project0c908882009-03-03 19:32:16 -0800633}