blob: 3aef08f2ef94fc7e0548bf62ea74f9122ddc5b05 [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 Reck8fc22a12011-06-16 14:57:41 -070086 // The minimum min font size
87 // Aka, the lower bounds for the min font size range
88 // which is 1:5..24
89 private static final int MIN_FONT_SIZE_OFFSET = 5;
90
John Reck35e9dd62011-04-25 09:01:54 -070091 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070092
John Reck35e9dd62011-04-25 09:01:54 -070093 private Context mContext;
94 private SharedPreferences mPrefs;
95 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070096 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070097 private WebStorageSizeManager mWebStorageSizeManager;
98 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -070099 private WeakHashMap<WebSettings, String> mCustomUserAgents;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
John Reck35e9dd62011-04-25 09:01:54 -0700101 // Cached settings
102 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800103
John Reck35e9dd62011-04-25 09:01:54 -0700104 public static void initialize(final Context context) {
105 sInstance = new BrowserSettings(context);
106 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800107
John Reck35e9dd62011-04-25 09:01:54 -0700108 public static BrowserSettings getInstance() {
109 return sInstance;
110 }
Ben Murdochef671652010-11-25 17:17:58 +0000111
John Reck35e9dd62011-04-25 09:01:54 -0700112 private BrowserSettings(Context context) {
113 mContext = context;
114 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reckf48314f2011-04-27 17:52:17 -0700115 if (Build.VERSION.CODENAME.equals("REL")) {
116 // This is a release build, always startup with debug disabled
117 setDebugEnabled(false);
118 }
John Reck35e9dd62011-04-25 09:01:54 -0700119 mAutofillHandler = new AutofillHandler(mContext);
120 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700121 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reck35e9dd62011-04-25 09:01:54 -0700122 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
123 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
124 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
125 mPrefs.registerOnSharedPreferenceChangeListener(this);
126 mAutofillHandler.asyncLoadFromDb();
127 }
128
129 public void setController(Controller controller) {
130 mController = controller;
131 syncSharedSettings();
132
133 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
134 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000135 }
136 }
137
John Reck35e9dd62011-04-25 09:01:54 -0700138 public void startManagingSettings(WebSettings settings) {
139 synchronized (mManagedSettings) {
140 syncStaticSettings(settings);
141 syncSetting(settings);
142 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800143 }
144 }
145
146 /**
John Reck35e9dd62011-04-25 09:01:54 -0700147 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800148 */
John Reck35e9dd62011-04-25 09:01:54 -0700149 private void syncSetting(WebSettings settings) {
150 settings.setGeolocationEnabled(enableGeolocation());
151 settings.setJavaScriptEnabled(enableJavascript());
152 settings.setLightTouchEnabled(enableLightTouch());
153 settings.setNavDump(enableNavDump());
154 settings.setShowVisualIndicator(enableVisualIndicator());
155 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
156 settings.setDefaultZoom(getDefaultZoom());
157 settings.setMinimumFontSize(getMinimumFontSize());
158 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700159 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700160 settings.setPluginState(getPluginState());
161 settings.setTextSize(getTextSize());
John Reck35e9dd62011-04-25 09:01:54 -0700162 settings.setAutoFillEnabled(isAutofillEnabled());
163 settings.setLayoutAlgorithm(getLayoutAlgorithm());
164 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
165 settings.setLoadsImagesAutomatically(loadImages());
166 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
167 settings.setSavePassword(rememberPasswords());
168 settings.setSaveFormData(saveFormdata());
169 settings.setUseWideViewPort(isWideViewport());
170 settings.setAutoFillProfile(getAutoFillProfile());
John Reckb8b2af82011-05-20 15:58:33 -0700171
172 String ua = mCustomUserAgents.get(settings);
John Reck46500332011-06-07 14:36:10 -0700173 if (ua != null) {
John Reckb8b2af82011-05-20 15:58:33 -0700174 settings.setUserAgentString(ua);
175 } else {
176 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
177 }
Ben Murdochef671652010-11-25 17:17:58 +0000178 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800179
John Reck35e9dd62011-04-25 09:01:54 -0700180 /**
181 * Syncs all the settings that have no UI
182 * These cannot change, so we only need to set them once per WebSettings
183 */
184 private void syncStaticSettings(WebSettings settings) {
185 settings.setDefaultFontSize(16);
186 settings.setDefaultFixedFontSize(13);
187 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000188
John Reck35e9dd62011-04-25 09:01:54 -0700189 // WebView inside Browser doesn't want initial focus to be set.
190 settings.setNeedInitialFocus(false);
191 // Browser supports multiple windows
192 settings.setSupportMultipleWindows(true);
193 // enable smooth transition for better performance during panning or
194 // zooming
195 settings.setEnableSmoothTransition(true);
196 // disable content url access
197 settings.setAllowContentAccess(false);
198
199 // HTML5 API flags
200 settings.setAppCacheEnabled(true);
201 settings.setDatabaseEnabled(true);
202 settings.setDomStorageEnabled(true);
203 settings.setWorkersEnabled(true); // This only affects V8.
204
205 // HTML5 configuration parametersettings.
206 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
207 settings.setAppCachePath(getAppCachePath());
208 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
209 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
210 }
211
212 private void syncSharedSettings() {
213 CookieManager.getInstance().setAcceptCookie(acceptCookies());
214 if (mController != null) {
215 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700216 }
John Reck35e9dd62011-04-25 09:01:54 -0700217 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700218
John Reck35e9dd62011-04-25 09:01:54 -0700219 private void syncManagedSettings() {
220 syncSharedSettings();
221 synchronized (mManagedSettings) {
222 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
223 while (iter.hasNext()) {
224 WeakReference<WebSettings> ref = iter.next();
225 WebSettings settings = ref.get();
226 if (settings == null) {
227 iter.remove();
228 continue;
229 }
230 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000231 }
John Reck35e9dd62011-04-25 09:01:54 -0700232 }
233 }
Ben Murdochef671652010-11-25 17:17:58 +0000234
John Reck35e9dd62011-04-25 09:01:54 -0700235 @Override
236 public void onSharedPreferenceChanged(
237 SharedPreferences sharedPreferences, String key) {
238 syncManagedSettings();
239 if (PREF_SEARCH_ENGINE.equals(key)) {
240 updateSearchEngine(false);
241 }
242 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
243 updateSearchEngine(true);
244 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700245 if (PREF_FULLSCREEN.equals(key)) {
246 if (mController.getUi() != null) {
247 mController.getUi().setFullscreen(useFullscreen());
248 }
249 }
John Reck35e9dd62011-04-25 09:01:54 -0700250 }
251
252 static String getFactoryResetHomeUrl(Context context) {
253 String url = context.getResources().getString(R.string.homepage_base);
254 if (url.indexOf("{CID}") != -1) {
255 url = url.replace("{CID}",
256 BrowserProvider.getClientId(context.getContentResolver()));
257 }
258 return url;
259 }
260
261 public LayoutAlgorithm getLayoutAlgorithm() {
262 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
263 if (autofitPages()) {
264 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
265 }
266 if (isDebugEnabled()) {
267 if (isSmallScreen()) {
268 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000269 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700270 if (isNormalLayout()) {
271 layoutAlgorithm = LayoutAlgorithm.NORMAL;
272 } else {
273 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
274 }
Ben Murdochef671652010-11-25 17:17:58 +0000275 }
John Reck35e9dd62011-04-25 09:01:54 -0700276 }
277 return layoutAlgorithm;
278 }
Ben Murdochef671652010-11-25 17:17:58 +0000279
John Reck35e9dd62011-04-25 09:01:54 -0700280 // TODO: Cache
281 public int getPageCacheCapacity() {
282 // the cost of one cached page is ~3M (measured using nytimes.com). For
283 // low end devices, we only cache one page. For high end devices, we try
284 // to cache more pages, currently choose 5.
285 if (ActivityManager.staticGetMemoryClass() > 16) {
286 return 5;
287 } else {
288 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800289 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800290 }
291
John Reck35e9dd62011-04-25 09:01:54 -0700292 public WebStorageSizeManager getWebStorageSizeManager() {
293 return mWebStorageSizeManager;
294 }
295
296 // TODO: Cache
297 private String getAppCachePath() {
298 return mContext.getDir("appcache", 0).getPath();
299 }
300
301 private void updateSearchEngine(boolean force) {
302 String searchEngineName = getSearchEngineName();
303 if (force || mSearchEngine == null ||
304 !mSearchEngine.getName().equals(searchEngineName)) {
305 if (mSearchEngine != null) {
306 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000307 // One or more tabs could have been in voice search mode.
308 // Clear it, since the new SearchEngine may not support
309 // it, or may handle it differently.
310 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
311 mController.getTabControl().getTab(i).revertVoiceSearchMode();
312 }
313 }
John Reck35e9dd62011-04-25 09:01:54 -0700314 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000315 }
John Reck35e9dd62011-04-25 09:01:54 -0700316 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000317
John Reck35e9dd62011-04-25 09:01:54 -0700318 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
319 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000320 }
321 }
322 }
323
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100324 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700325 if (mSearchEngine == null) {
326 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100327 }
John Reck35e9dd62011-04-25 09:01:54 -0700328 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100329 }
330
John Reck35e9dd62011-04-25 09:01:54 -0700331 public boolean isDebugEnabled() {
332 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100333 }
334
John Reck35e9dd62011-04-25 09:01:54 -0700335 public void setDebugEnabled(boolean value) {
336 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100337 }
338
John Reck35e9dd62011-04-25 09:01:54 -0700339 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800340 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700341 if (mController != null) {
342 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800343 if (current != null) {
344 current.clearCache(true);
345 }
346 }
347 }
348
John Reck35e9dd62011-04-25 09:01:54 -0700349 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800350 CookieManager.getInstance().removeAllCookie();
351 }
352
John Reck35e9dd62011-04-25 09:01:54 -0700353 public void clearHistory() {
354 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800355 Browser.clearHistory(resolver);
356 Browser.clearSearches(resolver);
357 }
358
John Reck35e9dd62011-04-25 09:01:54 -0700359 public void clearFormData() {
360 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 if (mController!= null) {
362 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100363 if (currentTopView != null) {
364 currentTopView.clearFormData();
365 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800366 }
367 }
368
John Reck35e9dd62011-04-25 09:01:54 -0700369 public void clearPasswords() {
370 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800371 db.clearUsernamePassword();
372 db.clearHttpAuthUsernamePassword();
373 }
374
John Reck35e9dd62011-04-25 09:01:54 -0700375 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100376 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100377 }
378
John Reck35e9dd62011-04-25 09:01:54 -0700379 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100380 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100381 }
382
John Reck35e9dd62011-04-25 09:01:54 -0700383 public void resetDefaultPreferences() {
384 mPrefs.edit().clear().apply();
385 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700386 }
387
John Reck35e9dd62011-04-25 09:01:54 -0700388 public AutoFillProfile getAutoFillProfile() {
389 mAutofillHandler.waitForLoad();
390 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800391 }
392
John Reck35e9dd62011-04-25 09:01:54 -0700393 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
394 mAutofillHandler.waitForLoad();
395 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800396 }
397
John Reck35e9dd62011-04-25 09:01:54 -0700398 public void toggleDebugSettings() {
399 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800400 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100401
John Reckb8b2af82011-05-20 15:58:33 -0700402 public boolean hasDesktopUseragent(WebView view) {
403 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
404 }
405
406 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700407 if (view == null) {
408 return;
409 }
John Reckb8b2af82011-05-20 15:58:33 -0700410 WebSettings settings = view.getSettings();
411 if (mCustomUserAgents.get(settings) != null) {
412 mCustomUserAgents.remove(settings);
413 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
414 } else {
415 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
416 settings.setUserAgentString(DESKTOP_USERAGENT);
417 }
418 }
419
John Reck35e9dd62011-04-25 09:01:54 -0700420 // -----------------------------
421 // getter/setters for accessibility_preferences.xml
422 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100423
John Reck35e9dd62011-04-25 09:01:54 -0700424 // TODO: Cache
425 public TextSize getTextSize() {
426 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
427 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100428 }
429
John Reck35e9dd62011-04-25 09:01:54 -0700430 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700431 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
432 minFont++; // Preference starts at 0, min font at 1
433 if (minFont > 1) {
434 minFont += MIN_FONT_SIZE_OFFSET;
435 }
436 return minFont;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100437 }
438
John Reck92f25f82011-04-26 16:57:10 -0700439 public boolean forceEnableUserScalable() {
440 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
441 }
442
John Reck35e9dd62011-04-25 09:01:54 -0700443 // -----------------------------
444 // getter/setters for advanced_preferences.xml
445 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100446
John Reck35e9dd62011-04-25 09:01:54 -0700447 public String getSearchEngineName() {
448 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100449 }
John Reck63bb6872010-12-01 19:29:32 -0800450
John Reck35e9dd62011-04-25 09:01:54 -0700451 public boolean openInBackground() {
452 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800453 }
John Reck35e9dd62011-04-25 09:01:54 -0700454
455 public boolean enableJavascript() {
456 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
457 }
458
459 // TODO: Cache
460 public PluginState getPluginState() {
461 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
462 return PluginState.valueOf(state);
463 }
464
465 // TODO: Cache
466 public ZoomDensity getDefaultZoom() {
467 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
468 return ZoomDensity.valueOf(zoom);
469 }
470
471 public boolean loadPageInOverviewMode() {
472 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
473 }
474
475 public boolean autofitPages() {
476 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
477 }
478
479 public boolean blockPopupWindows() {
480 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
481 }
482
483 public boolean loadImages() {
484 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
485 }
486
487 public String getDefaultTextEncoding() {
488 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
489 }
490
491 // -----------------------------
492 // getter/setters for general_preferences.xml
493 // -----------------------------
494
495 public String getHomePage() {
496 if (useMostVisitedHomepage()) {
497 return HomeProvider.MOST_VISITED;
498 }
499 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
500 }
501
502 public void setHomePage(String value) {
503 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
504 }
505
506 public boolean isAutofillEnabled() {
507 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
508 }
509
510 public void setAutofillEnabled(boolean value) {
511 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
512 }
513
514 // -----------------------------
515 // getter/setters for debug_preferences.xml
516 // -----------------------------
517
518 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700519 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700520 return true;
521 }
522 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
523 }
524
525 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700526 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700527 return 0;
528 }
529 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
530 }
531
532 // -----------------------------
533 // getter/setters for hidden_debug_preferences.xml
534 // -----------------------------
535
536 public boolean enableVisualIndicator() {
537 if (!isDebugEnabled()) {
538 return false;
539 }
540 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
541 }
542
543 public boolean enableJavascriptConsole() {
544 if (!isDebugEnabled()) {
545 return false;
546 }
547 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
548 }
549
550 public boolean isSmallScreen() {
551 if (!isDebugEnabled()) {
552 return false;
553 }
554 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
555 }
556
557 public boolean isWideViewport() {
558 if (!isDebugEnabled()) {
559 return true;
560 }
561 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
562 }
563
564 public boolean isNormalLayout() {
565 if (!isDebugEnabled()) {
566 return false;
567 }
568 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
569 }
570
571 public boolean isTracing() {
572 if (!isDebugEnabled()) {
573 return false;
574 }
575 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
576 }
577
578 public boolean enableLightTouch() {
579 if (!isDebugEnabled()) {
580 return false;
581 }
582 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
583 }
584
585 public boolean enableNavDump() {
586 if (!isDebugEnabled()) {
587 return false;
588 }
589 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
590 }
591
592 public String getJsEngineFlags() {
593 if (!isDebugEnabled()) {
594 return "";
595 }
596 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
597 }
598
599 // -----------------------------
600 // getter/setters for lab_preferences.xml
601 // -----------------------------
602
603 public boolean useQuickControls() {
604 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
605 }
606
607 public boolean useMostVisitedHomepage() {
608 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
609 }
610
611 public boolean useInstantSearch() {
612 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
613 }
614
Michael Kolbc38c6042011-04-27 10:46:06 -0700615 public boolean useFullscreen() {
616 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
617 }
618
John Reck35e9dd62011-04-25 09:01:54 -0700619 // -----------------------------
620 // getter/setters for privacy_security_preferences.xml
621 // -----------------------------
622
623 public boolean showSecurityWarnings() {
624 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
625 }
626
627 public boolean acceptCookies() {
628 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
629 }
630
631 public boolean saveFormdata() {
632 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
633 }
634
635 public boolean enableGeolocation() {
636 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
637 }
638
639 public boolean rememberPasswords() {
640 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
641 }
642
The Android Open Source Project0c908882009-03-03 19:32:16 -0800643}