blob: e6bd7595c801ebc57ffb6f6982a38241061c25a3 [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;
John Reck87060082011-05-18 13:07:57 -070020import com.android.browser.provider.BrowserProvider;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010021import com.android.browser.search.SearchEngine;
22import com.android.browser.search.SearchEngines;
23
Grace Kloba9804c432009-12-02 11:07:40 -080024import android.app.ActivityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080025import android.content.ContentResolver;
26import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080027import android.content.SharedPreferences;
John Reck812d2d62011-01-18 14:16:15 -080028import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
John Reckf48314f2011-04-27 17:52:17 -070029import android.os.Build;
Ben Murdoch23da30e2010-10-26 15:18:44 +010030import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010031import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010032import android.provider.Browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010034import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035import android.webkit.WebIconDatabase;
36import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010037import android.webkit.WebSettings.AutoFillProfile;
John Reck35e9dd62011-04-25 09:01:54 -070038import android.webkit.WebSettings.LayoutAlgorithm;
39import android.webkit.WebSettings.PluginState;
40import android.webkit.WebSettings.TextSize;
41import android.webkit.WebSettings.ZoomDensity;
Nicolas Roard78a98e42009-05-11 13:34:17 +010042import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080043import android.webkit.WebView;
44import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080045
John Reck35e9dd62011-04-25 09:01:54 -070046import java.lang.ref.WeakReference;
47import java.util.Iterator;
48import java.util.LinkedList;
The Android Open Source Project0c908882009-03-03 19:32:16 -080049
John Reck35e9dd62011-04-25 09:01:54 -070050/**
51 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080052 */
John Reck35e9dd62011-04-25 09:01:54 -070053public class BrowserSettings implements OnSharedPreferenceChangeListener,
54 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010055
John Reck35e9dd62011-04-25 09:01:54 -070056 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070057 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
58 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
59 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080060
61 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070062 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
63 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070064
65 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070066 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
67 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070068
69 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070070 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
71 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080072
John Reck7fd1e8f2011-04-27 18:22:57 -070073 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
74 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
75 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
76
John Reck35e9dd62011-04-25 09:01:54 -070077 private static final String USER_AGENTS[] = { null,
78 DESKTOP_USERAGENT,
79 IPHONE_USERAGENT,
80 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070081 FROYO_USERAGENT,
82 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070083 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080084
John Reck35e9dd62011-04-25 09:01:54 -070085 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070086
John Reck35e9dd62011-04-25 09:01:54 -070087 private Context mContext;
88 private SharedPreferences mPrefs;
89 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070090 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070091 private WebStorageSizeManager mWebStorageSizeManager;
92 private AutofillHandler mAutofillHandler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080093
John Reck35e9dd62011-04-25 09:01:54 -070094 // Cached settings
95 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080096
John Reck35e9dd62011-04-25 09:01:54 -070097 public static void initialize(final Context context) {
98 sInstance = new BrowserSettings(context);
99 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
John Reck35e9dd62011-04-25 09:01:54 -0700101 public static BrowserSettings getInstance() {
102 return sInstance;
103 }
Ben Murdochef671652010-11-25 17:17:58 +0000104
John Reck35e9dd62011-04-25 09:01:54 -0700105 private BrowserSettings(Context context) {
106 mContext = context;
107 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reckf48314f2011-04-27 17:52:17 -0700108 if (Build.VERSION.CODENAME.equals("REL")) {
109 // This is a release build, always startup with debug disabled
110 setDebugEnabled(false);
111 }
John Reck35e9dd62011-04-25 09:01:54 -0700112 mAutofillHandler = new AutofillHandler(mContext);
113 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
114 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
115 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
116 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
117 mPrefs.registerOnSharedPreferenceChangeListener(this);
118 mAutofillHandler.asyncLoadFromDb();
119 }
120
121 public void setController(Controller controller) {
122 mController = controller;
123 syncSharedSettings();
124
125 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
126 ((InstantSearchEngine) mSearchEngine).setController(mController);
Ben Murdochef671652010-11-25 17:17:58 +0000127 }
128 }
129
John Reck35e9dd62011-04-25 09:01:54 -0700130 public void startManagingSettings(WebSettings settings) {
131 synchronized (mManagedSettings) {
132 syncStaticSettings(settings);
133 syncSetting(settings);
134 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135 }
136 }
137
138 /**
John Reck35e9dd62011-04-25 09:01:54 -0700139 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800140 */
John Reck35e9dd62011-04-25 09:01:54 -0700141 private void syncSetting(WebSettings settings) {
142 settings.setGeolocationEnabled(enableGeolocation());
143 settings.setJavaScriptEnabled(enableJavascript());
144 settings.setLightTouchEnabled(enableLightTouch());
145 settings.setNavDump(enableNavDump());
146 settings.setShowVisualIndicator(enableVisualIndicator());
147 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
148 settings.setDefaultZoom(getDefaultZoom());
149 settings.setMinimumFontSize(getMinimumFontSize());
150 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck92f25f82011-04-26 16:57:10 -0700151 settings.setForceUserScalable(forceEnableUserScalable());
John Reck35e9dd62011-04-25 09:01:54 -0700152 settings.setPluginState(getPluginState());
153 settings.setTextSize(getTextSize());
154 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
155 settings.setAutoFillEnabled(isAutofillEnabled());
156 settings.setLayoutAlgorithm(getLayoutAlgorithm());
157 settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
158 settings.setLoadsImagesAutomatically(loadImages());
159 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
160 settings.setSavePassword(rememberPasswords());
161 settings.setSaveFormData(saveFormdata());
162 settings.setUseWideViewPort(isWideViewport());
163 settings.setAutoFillProfile(getAutoFillProfile());
Ben Murdochef671652010-11-25 17:17:58 +0000164 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800165
John Reck35e9dd62011-04-25 09:01:54 -0700166 /**
167 * Syncs all the settings that have no UI
168 * These cannot change, so we only need to set them once per WebSettings
169 */
170 private void syncStaticSettings(WebSettings settings) {
171 settings.setDefaultFontSize(16);
172 settings.setDefaultFixedFontSize(13);
173 settings.setPageCacheCapacity(getPageCacheCapacity());
Ben Murdochef671652010-11-25 17:17:58 +0000174
John Reck35e9dd62011-04-25 09:01:54 -0700175 // WebView inside Browser doesn't want initial focus to be set.
176 settings.setNeedInitialFocus(false);
177 // Browser supports multiple windows
178 settings.setSupportMultipleWindows(true);
179 // enable smooth transition for better performance during panning or
180 // zooming
181 settings.setEnableSmoothTransition(true);
182 // disable content url access
183 settings.setAllowContentAccess(false);
184
185 // HTML5 API flags
186 settings.setAppCacheEnabled(true);
187 settings.setDatabaseEnabled(true);
188 settings.setDomStorageEnabled(true);
189 settings.setWorkersEnabled(true); // This only affects V8.
190
191 // HTML5 configuration parametersettings.
192 settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize());
193 settings.setAppCachePath(getAppCachePath());
194 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
195 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
196 }
197
198 private void syncSharedSettings() {
199 CookieManager.getInstance().setAcceptCookie(acceptCookies());
200 if (mController != null) {
201 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700202 }
John Reck35e9dd62011-04-25 09:01:54 -0700203 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700204
John Reck35e9dd62011-04-25 09:01:54 -0700205 private void syncManagedSettings() {
206 syncSharedSettings();
207 synchronized (mManagedSettings) {
208 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
209 while (iter.hasNext()) {
210 WeakReference<WebSettings> ref = iter.next();
211 WebSettings settings = ref.get();
212 if (settings == null) {
213 iter.remove();
214 continue;
215 }
216 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000217 }
John Reck35e9dd62011-04-25 09:01:54 -0700218 }
219 }
Ben Murdochef671652010-11-25 17:17:58 +0000220
John Reck35e9dd62011-04-25 09:01:54 -0700221 @Override
222 public void onSharedPreferenceChanged(
223 SharedPreferences sharedPreferences, String key) {
224 syncManagedSettings();
225 if (PREF_SEARCH_ENGINE.equals(key)) {
226 updateSearchEngine(false);
227 }
228 if (PREF_USE_INSTANT_SEARCH.equals(key)) {
229 updateSearchEngine(true);
230 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700231 if (PREF_FULLSCREEN.equals(key)) {
232 if (mController.getUi() != null) {
233 mController.getUi().setFullscreen(useFullscreen());
234 }
235 }
John Reck35e9dd62011-04-25 09:01:54 -0700236 }
237
238 static String getFactoryResetHomeUrl(Context context) {
239 String url = context.getResources().getString(R.string.homepage_base);
240 if (url.indexOf("{CID}") != -1) {
241 url = url.replace("{CID}",
242 BrowserProvider.getClientId(context.getContentResolver()));
243 }
244 return url;
245 }
246
247 public LayoutAlgorithm getLayoutAlgorithm() {
248 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
249 if (autofitPages()) {
250 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
251 }
252 if (isDebugEnabled()) {
253 if (isSmallScreen()) {
254 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000255 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700256 if (isNormalLayout()) {
257 layoutAlgorithm = LayoutAlgorithm.NORMAL;
258 } else {
259 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
260 }
Ben Murdochef671652010-11-25 17:17:58 +0000261 }
John Reck35e9dd62011-04-25 09:01:54 -0700262 }
263 return layoutAlgorithm;
264 }
Ben Murdochef671652010-11-25 17:17:58 +0000265
John Reck35e9dd62011-04-25 09:01:54 -0700266 // TODO: Cache
267 public int getPageCacheCapacity() {
268 // the cost of one cached page is ~3M (measured using nytimes.com). For
269 // low end devices, we only cache one page. For high end devices, we try
270 // to cache more pages, currently choose 5.
271 if (ActivityManager.staticGetMemoryClass() > 16) {
272 return 5;
273 } else {
274 return 1;
Grace Kloba9804c432009-12-02 11:07:40 -0800275 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800276 }
277
John Reck35e9dd62011-04-25 09:01:54 -0700278 public WebStorageSizeManager getWebStorageSizeManager() {
279 return mWebStorageSizeManager;
280 }
281
282 // TODO: Cache
283 private String getAppCachePath() {
284 return mContext.getDir("appcache", 0).getPath();
285 }
286
287 private void updateSearchEngine(boolean force) {
288 String searchEngineName = getSearchEngineName();
289 if (force || mSearchEngine == null ||
290 !mSearchEngine.getName().equals(searchEngineName)) {
291 if (mSearchEngine != null) {
292 if (mSearchEngine.supportsVoiceSearch()) {
Narayan Kamath5119edd2011-02-23 15:49:17 +0000293 // One or more tabs could have been in voice search mode.
294 // Clear it, since the new SearchEngine may not support
295 // it, or may handle it differently.
296 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
297 mController.getTabControl().getTab(i).revertVoiceSearchMode();
298 }
299 }
John Reck35e9dd62011-04-25 09:01:54 -0700300 mSearchEngine.close();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000301 }
John Reck35e9dd62011-04-25 09:01:54 -0700302 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000303
John Reck35e9dd62011-04-25 09:01:54 -0700304 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
305 ((InstantSearchEngine) mSearchEngine).setController(mController);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000306 }
307 }
308 }
309
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100310 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700311 if (mSearchEngine == null) {
312 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100313 }
John Reck35e9dd62011-04-25 09:01:54 -0700314 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100315 }
316
John Reck35e9dd62011-04-25 09:01:54 -0700317 public boolean isDebugEnabled() {
318 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100319 }
320
John Reck35e9dd62011-04-25 09:01:54 -0700321 public void setDebugEnabled(boolean value) {
322 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100323 }
324
John Reck35e9dd62011-04-25 09:01:54 -0700325 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800326 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700327 if (mController != null) {
328 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800329 if (current != null) {
330 current.clearCache(true);
331 }
332 }
333 }
334
John Reck35e9dd62011-04-25 09:01:54 -0700335 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800336 CookieManager.getInstance().removeAllCookie();
337 }
338
John Reck35e9dd62011-04-25 09:01:54 -0700339 public void clearHistory() {
340 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800341 Browser.clearHistory(resolver);
342 Browser.clearSearches(resolver);
343 }
344
John Reck35e9dd62011-04-25 09:01:54 -0700345 public void clearFormData() {
346 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700347 if (mController!= null) {
348 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100349 if (currentTopView != null) {
350 currentTopView.clearFormData();
351 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800352 }
353 }
354
John Reck35e9dd62011-04-25 09:01:54 -0700355 public void clearPasswords() {
356 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800357 db.clearUsernamePassword();
358 db.clearHttpAuthUsernamePassword();
359 }
360
John Reck35e9dd62011-04-25 09:01:54 -0700361 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100362 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100363 }
364
John Reck35e9dd62011-04-25 09:01:54 -0700365 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100366 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100367 }
368
John Reck35e9dd62011-04-25 09:01:54 -0700369 public void resetDefaultPreferences() {
370 mPrefs.edit().clear().apply();
371 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700372 }
373
John Reck35e9dd62011-04-25 09:01:54 -0700374 public AutoFillProfile getAutoFillProfile() {
375 mAutofillHandler.waitForLoad();
376 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800377 }
378
John Reck35e9dd62011-04-25 09:01:54 -0700379 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
380 mAutofillHandler.waitForLoad();
381 mAutofillHandler.setAutoFillProfile(profile, msg);
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800382 }
383
John Reck35e9dd62011-04-25 09:01:54 -0700384 public void toggleDebugSettings() {
385 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800386 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100387
John Reck35e9dd62011-04-25 09:01:54 -0700388 // -----------------------------
389 // getter/setters for accessibility_preferences.xml
390 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100391
John Reck35e9dd62011-04-25 09:01:54 -0700392 // TODO: Cache
393 public TextSize getTextSize() {
394 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
395 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100396 }
397
John Reck35e9dd62011-04-25 09:01:54 -0700398 public int getMinimumFontSize() {
399 return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100400 }
401
John Reck92f25f82011-04-26 16:57:10 -0700402 public boolean forceEnableUserScalable() {
403 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
404 }
405
John Reck35e9dd62011-04-25 09:01:54 -0700406 // -----------------------------
407 // getter/setters for advanced_preferences.xml
408 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100409
John Reck35e9dd62011-04-25 09:01:54 -0700410 public String getSearchEngineName() {
411 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100412 }
John Reck63bb6872010-12-01 19:29:32 -0800413
John Reck35e9dd62011-04-25 09:01:54 -0700414 public boolean openInBackground() {
415 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800416 }
John Reck35e9dd62011-04-25 09:01:54 -0700417
418 public boolean enableJavascript() {
419 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
420 }
421
422 // TODO: Cache
423 public PluginState getPluginState() {
424 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
425 return PluginState.valueOf(state);
426 }
427
428 // TODO: Cache
429 public ZoomDensity getDefaultZoom() {
430 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
431 return ZoomDensity.valueOf(zoom);
432 }
433
434 public boolean loadPageInOverviewMode() {
435 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
436 }
437
438 public boolean autofitPages() {
439 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
440 }
441
442 public boolean blockPopupWindows() {
443 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
444 }
445
446 public boolean loadImages() {
447 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
448 }
449
450 public String getDefaultTextEncoding() {
451 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
452 }
453
454 // -----------------------------
455 // getter/setters for general_preferences.xml
456 // -----------------------------
457
458 public String getHomePage() {
459 if (useMostVisitedHomepage()) {
460 return HomeProvider.MOST_VISITED;
461 }
462 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
463 }
464
465 public void setHomePage(String value) {
466 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
467 }
468
469 public boolean isAutofillEnabled() {
470 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
471 }
472
473 public void setAutofillEnabled(boolean value) {
474 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
475 }
476
477 // -----------------------------
478 // getter/setters for debug_preferences.xml
479 // -----------------------------
480
481 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700482 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700483 return true;
484 }
485 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
486 }
487
488 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700489 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700490 return 0;
491 }
492 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
493 }
494
495 // -----------------------------
496 // getter/setters for hidden_debug_preferences.xml
497 // -----------------------------
498
499 public boolean enableVisualIndicator() {
500 if (!isDebugEnabled()) {
501 return false;
502 }
503 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
504 }
505
506 public boolean enableJavascriptConsole() {
507 if (!isDebugEnabled()) {
508 return false;
509 }
510 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
511 }
512
513 public boolean isSmallScreen() {
514 if (!isDebugEnabled()) {
515 return false;
516 }
517 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
518 }
519
520 public boolean isWideViewport() {
521 if (!isDebugEnabled()) {
522 return true;
523 }
524 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
525 }
526
527 public boolean isNormalLayout() {
528 if (!isDebugEnabled()) {
529 return false;
530 }
531 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
532 }
533
534 public boolean isTracing() {
535 if (!isDebugEnabled()) {
536 return false;
537 }
538 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
539 }
540
541 public boolean enableLightTouch() {
542 if (!isDebugEnabled()) {
543 return false;
544 }
545 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
546 }
547
548 public boolean enableNavDump() {
549 if (!isDebugEnabled()) {
550 return false;
551 }
552 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
553 }
554
555 public String getJsEngineFlags() {
556 if (!isDebugEnabled()) {
557 return "";
558 }
559 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
560 }
561
562 // -----------------------------
563 // getter/setters for lab_preferences.xml
564 // -----------------------------
565
566 public boolean useQuickControls() {
567 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
568 }
569
570 public boolean useMostVisitedHomepage() {
571 return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false);
572 }
573
574 public boolean useInstantSearch() {
575 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
576 }
577
Michael Kolbc38c6042011-04-27 10:46:06 -0700578 public boolean useFullscreen() {
579 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
580 }
581
John Reck35e9dd62011-04-25 09:01:54 -0700582 // -----------------------------
583 // getter/setters for privacy_security_preferences.xml
584 // -----------------------------
585
586 public boolean showSecurityWarnings() {
587 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
588 }
589
590 public boolean acceptCookies() {
591 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
592 }
593
594 public boolean saveFormdata() {
595 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
596 }
597
598 public boolean enableGeolocation() {
599 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
600 }
601
602 public boolean rememberPasswords() {
603 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
604 }
605
The Android Open Source Project0c908882009-03-03 19:32:16 -0800606}