2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.browser;
19 import android.app.ActivityManager;
20 import android.content.ContentResolver;
21 import android.content.Context;
22 import android.content.SharedPreferences;
23 import android.content.SharedPreferences.Editor;
24 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
25 import android.os.Build;
26 import android.os.Message;
27 import android.preference.PreferenceManager;
28 import android.provider.Browser;
29 import android.provider.Settings;
30 import android.util.DisplayMetrics;
31 import android.webkit.CookieManager;
32 import android.webkit.GeolocationPermissions;
33 import android.webkit.WebIconDatabase;
34 import android.webkit.WebSettings;
35 import android.webkit.WebSettings.AutoFillProfile;
36 import android.webkit.WebSettings.LayoutAlgorithm;
37 import android.webkit.WebSettings.PluginState;
38 import android.webkit.WebSettings.TextSize;
39 import android.webkit.WebSettings.ZoomDensity;
40 import android.webkit.WebStorage;
41 import android.webkit.WebView;
42 import android.webkit.WebViewDatabase;
44 import com.android.browser.homepages.HomeProvider;
45 import com.android.browser.provider.BrowserProvider;
46 import com.android.browser.search.SearchEngine;
47 import com.android.browser.search.SearchEngines;
49 import java.lang.ref.WeakReference;
50 import java.util.Iterator;
51 import java.util.LinkedList;
52 import java.util.WeakHashMap;
55 * Class for managing settings
57 public class BrowserSettings implements OnSharedPreferenceChangeListener,
60 // TODO: Do something with this UserAgent stuff
61 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
62 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
63 "Chrome/11.0.696.34 Safari/534.24";
65 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
66 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
67 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
69 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
70 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
71 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
73 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
74 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
75 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
77 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
78 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
79 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
81 private static final String USER_AGENTS[] = { null,
89 // The minimum min font size
90 // Aka, the lower bounds for the min font size range
92 private static final int MIN_FONT_SIZE_OFFSET = 5;
93 // The initial value in the text zoom range
94 // This is what represents 100% in the SeekBarPreference range
95 private static final int TEXT_ZOOM_START_VAL = 10;
96 // The size of a single step in the text zoom range, in percent
97 private static final int TEXT_ZOOM_STEP = 5;
98 // The initial value in the double tap zoom range
99 // This is what represents 100% in the SeekBarPreference range
100 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
101 // The size of a single step in the double tap zoom range, in percent
102 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
104 private static BrowserSettings sInstance;
106 private Context mContext;
107 private SharedPreferences mPrefs;
108 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
109 private Controller mController;
110 private WebStorageSizeManager mWebStorageSizeManager;
111 private AutofillHandler mAutofillHandler;
112 private WeakHashMap<WebSettings, String> mCustomUserAgents;
113 private static boolean sInitialized = false;
114 private boolean mNeedsSharedSync = true;
115 private float mFontSizeMult = 1.0f;
118 private int mPageCacheCapacity = 1;
119 private String mAppCachePath;
122 private SearchEngine mSearchEngine;
124 private static String sFactoryResetUrl;
126 public static void initialize(final Context context) {
127 sInstance = new BrowserSettings(context);
130 public static BrowserSettings getInstance() {
134 private BrowserSettings(Context context) {
135 mContext = context.getApplicationContext();
136 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
137 mAutofillHandler = new AutofillHandler(mContext);
138 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
139 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
140 mAutofillHandler.asyncLoadFromDb();
141 BackgroundHandler.execute(mSetup);
144 public void setController(Controller controller) {
145 mController = controller;
147 syncSharedSettings();
151 public void startManagingSettings(WebSettings settings) {
152 if (mNeedsSharedSync) {
153 syncSharedSettings();
155 synchronized (mManagedSettings) {
156 syncStaticSettings(settings);
157 syncSetting(settings);
158 mManagedSettings.add(new WeakReference<WebSettings>(settings));
162 private Runnable mSetup = new Runnable() {
166 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
167 mFontSizeMult = metrics.scaledDensity / metrics.density;
168 // the cost of one cached page is ~3M (measured using nytimes.com). For
169 // low end devices, we only cache one page. For high end devices, we try
170 // to cache more pages, currently choose 5.
171 if (ActivityManager.staticGetMemoryClass() > 16) {
172 mPageCacheCapacity = 5;
174 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
175 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
176 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
177 // Workaround b/5253777
178 CookieManager.getInstance().acceptCookie();
179 // Workaround b/5254577
180 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
181 if (Build.VERSION.CODENAME.equals("REL")) {
182 // This is a release build, always startup with debug disabled
183 setDebugEnabled(false);
185 if (mPrefs.contains(PREF_TEXT_SIZE)) {
187 * Update from TextSize enum to zoom percent
194 switch (getTextSize()) {
208 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
211 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
212 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
213 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
214 BrowserProvider.getClientId(mContext.getContentResolver()));
217 synchronized (BrowserSettings.class) {
219 BrowserSettings.class.notifyAll();
224 private static void requireInitialization() {
225 synchronized (BrowserSettings.class) {
226 while (!sInitialized) {
228 BrowserSettings.class.wait();
229 } catch (InterruptedException e) {
236 * Syncs all the settings that have a Preference UI
238 private void syncSetting(WebSettings settings) {
239 settings.setGeolocationEnabled(enableGeolocation());
240 settings.setJavaScriptEnabled(enableJavascript());
241 settings.setLightTouchEnabled(enableLightTouch());
242 settings.setNavDump(enableNavDump());
243 settings.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
244 settings.setShowVisualIndicator(enableVisualIndicator());
245 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
246 settings.setDefaultZoom(getDefaultZoom());
247 settings.setMinimumFontSize(getMinimumFontSize());
248 settings.setMinimumLogicalFontSize(getMinimumFontSize());
249 settings.setForceUserScalable(forceEnableUserScalable());
250 settings.setPluginState(getPluginState());
251 settings.setTextZoom(getTextZoom());
252 settings.setDoubleTapZoom(getDoubleTapZoom());
253 settings.setAutoFillEnabled(isAutofillEnabled());
254 settings.setLayoutAlgorithm(getLayoutAlgorithm());
255 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
256 settings.setLoadsImagesAutomatically(loadImages());
257 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
258 settings.setSavePassword(rememberPasswords());
259 settings.setSaveFormData(saveFormdata());
260 settings.setUseWideViewPort(isWideViewport());
261 settings.setAutoFillProfile(getAutoFillProfile());
263 String ua = mCustomUserAgents.get(settings);
265 settings.setUserAgentString(ua);
267 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
270 boolean useInverted = useInvertedRendering();
271 settings.setProperty(WebViewProperties.gfxInvertedScreen,
272 useInverted ? "true" : "false");
274 settings.setProperty(WebViewProperties.gfxInvertedScreenContrast,
275 Float.toString(getInvertedContrast()));
278 if (isDebugEnabled()) {
279 settings.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
280 enableCpuUploadPath() ? "true" : "false");
285 * Syncs all the settings that have no UI
286 * These cannot change, so we only need to set them once per WebSettings
288 private void syncStaticSettings(WebSettings settings) {
289 settings.setDefaultFontSize(16);
290 settings.setDefaultFixedFontSize(13);
291 settings.setPageCacheCapacity(getPageCacheCapacity());
293 // WebView inside Browser doesn't want initial focus to be set.
294 settings.setNeedInitialFocus(false);
295 // Browser supports multiple windows
296 settings.setSupportMultipleWindows(true);
297 // enable smooth transition for better performance during panning or
299 settings.setEnableSmoothTransition(true);
300 // WebView should be preserving the memory as much as possible.
301 // However, apps like browser wish to turn on the performance mode which
302 // would require more memory.
303 // TODO: We need to dynamically allocate/deallocate temporary memory for
304 // apps which are trying to use minimal memory. Currently, double
305 // buffering is always turned on, which is unnecessary.
306 settings.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
307 // disable content url access
308 settings.setAllowContentAccess(false);
311 settings.setAppCacheEnabled(true);
312 settings.setDatabaseEnabled(true);
313 settings.setDomStorageEnabled(true);
314 settings.setWorkersEnabled(true); // This only affects V8.
316 // HTML5 configuration parametersettings.
317 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
318 settings.setAppCachePath(getAppCachePath());
319 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
320 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
323 private void syncSharedSettings() {
324 mNeedsSharedSync = false;
325 CookieManager.getInstance().setAcceptCookie(acceptCookies());
326 if (mController != null) {
327 mController.setShouldShowErrorConsole(enableJavascriptConsole());
331 private void syncManagedSettings() {
332 syncSharedSettings();
333 synchronized (mManagedSettings) {
334 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
335 while (iter.hasNext()) {
336 WeakReference<WebSettings> ref = iter.next();
337 WebSettings settings = ref.get();
338 if (settings == null) {
342 syncSetting(settings);
348 public void onSharedPreferenceChanged(
349 SharedPreferences sharedPreferences, String key) {
350 syncManagedSettings();
351 if (PREF_SEARCH_ENGINE.equals(key)) {
352 updateSearchEngine(false);
354 if (PREF_FULLSCREEN.equals(key)) {
355 if (mController.getUi() != null) {
356 mController.getUi().setFullscreen(useFullscreen());
358 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
359 if (mController.getUi() != null) {
360 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
362 } else if (PREF_ENABLE_QUICK_CONTROLS_EXT.equals(key)) {
363 if (mController.getUi() != null) {
364 mController.getUi().setUseQuickControlsExt(sharedPreferences.getBoolean(key, false));
369 public static String getFactoryResetHomeUrl(Context context) {
370 requireInitialization();
371 return sFactoryResetUrl;
374 public LayoutAlgorithm getLayoutAlgorithm() {
375 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
376 if (autofitPages()) {
377 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
379 if (isDebugEnabled()) {
380 if (isSmallScreen()) {
381 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
383 if (isNormalLayout()) {
384 layoutAlgorithm = LayoutAlgorithm.NORMAL;
386 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
390 return layoutAlgorithm;
393 public int getPageCacheCapacity() {
394 requireInitialization();
395 return mPageCacheCapacity;
398 public WebStorageSizeManager getWebStorageSizeManager() {
399 requireInitialization();
400 return mWebStorageSizeManager;
403 private String getAppCachePath() {
404 if (mAppCachePath == null) {
405 mAppCachePath = mContext.getDir("appcache", 0).getPath();
407 return mAppCachePath;
410 private void updateSearchEngine(boolean force) {
411 String searchEngineName = getSearchEngineName();
412 if (force || mSearchEngine == null ||
413 !mSearchEngine.getName().equals(searchEngineName)) {
414 if (mSearchEngine != null) {
415 if (mSearchEngine.supportsVoiceSearch()) {
416 // One or more tabs could have been in voice search mode.
417 // Clear it, since the new SearchEngine may not support
418 // it, or may handle it differently.
419 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
420 mController.getTabControl().getTab(i).revertVoiceSearchMode();
423 mSearchEngine.close();
425 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
429 public SearchEngine getSearchEngine() {
430 if (mSearchEngine == null) {
431 updateSearchEngine(false);
433 return mSearchEngine;
436 public boolean isDebugEnabled() {
437 requireInitialization();
438 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
441 public void setDebugEnabled(boolean value) {
442 Editor edit = mPrefs.edit();
443 edit.putBoolean(PREF_DEBUG_MENU, value);
445 // Reset to "safe" value
446 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
451 public void clearCache() {
452 WebIconDatabase.getInstance().removeAllIcons();
453 if (mController != null) {
454 WebView current = mController.getCurrentWebView();
455 if (current != null) {
456 current.clearCache(true);
461 public void clearCookies() {
462 CookieManager.getInstance().removeAllCookie();
465 public void clearHistory() {
466 ContentResolver resolver = mContext.getContentResolver();
467 Browser.clearHistory(resolver);
468 Browser.clearSearches(resolver);
471 public void clearFormData() {
472 WebViewDatabase.getInstance(mContext).clearFormData();
473 if (mController!= null) {
474 WebView currentTopView = mController.getCurrentTopWebView();
475 if (currentTopView != null) {
476 currentTopView.clearFormData();
481 public void clearPasswords() {
482 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
483 db.clearUsernamePassword();
484 db.clearHttpAuthUsernamePassword();
487 public void clearDatabases() {
488 WebStorage.getInstance().deleteAllData();
491 public void clearLocationAccess() {
492 GeolocationPermissions.getInstance().clearAll();
495 public void resetDefaultPreferences() {
496 // Preserve autologin setting
497 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1);
500 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal)
502 syncManagedSettings();
505 public AutoFillProfile getAutoFillProfile() {
506 mAutofillHandler.waitForLoad();
507 return mAutofillHandler.getAutoFillProfile();
510 public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
511 mAutofillHandler.waitForLoad();
512 mAutofillHandler.setAutoFillProfile(profile, msg);
513 // Auto-fill will reuse the same profile ID when making edits to the profile,
514 // so we need to force a settings sync (otherwise the SharedPreferences
515 // manager will optimise out the call to onSharedPreferenceChanged(), as
516 // it thinks nothing has changed).
517 syncManagedSettings();
520 public void toggleDebugSettings() {
521 setDebugEnabled(!isDebugEnabled());
524 public boolean hasDesktopUseragent(WebView view) {
525 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
528 public void toggleDesktopUseragent(WebView view) {
532 WebSettings settings = view.getSettings();
533 if (mCustomUserAgents.get(settings) != null) {
534 mCustomUserAgents.remove(settings);
535 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
537 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
538 settings.setUserAgentString(DESKTOP_USERAGENT);
542 public static int getAdjustedMinimumFontSize(int rawValue) {
543 rawValue++; // Preference starts at 0, min font at 1
545 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
550 public int getAdjustedTextZoom(int rawValue) {
551 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
552 return (int) ((rawValue + 100) * mFontSizeMult);
555 static int getRawTextZoom(int percent) {
556 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
559 public int getAdjustedDoubleTapZoom(int rawValue) {
560 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
561 return (int) ((rawValue + 100) * mFontSizeMult);
564 static int getRawDoubleTapZoom(int percent) {
565 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
568 public SharedPreferences getPreferences() {
572 // -----------------------------
573 // getter/setters for accessibility_preferences.xml
574 // -----------------------------
577 private TextSize getTextSize() {
578 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
579 return TextSize.valueOf(textSize);
582 public int getMinimumFontSize() {
583 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
584 return getAdjustedMinimumFontSize(minFont);
587 public boolean forceEnableUserScalable() {
588 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
591 public int getTextZoom() {
592 requireInitialization();
593 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
594 return getAdjustedTextZoom(textZoom);
597 public void setTextZoom(int percent) {
598 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
601 public int getDoubleTapZoom() {
602 requireInitialization();
603 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
604 return getAdjustedDoubleTapZoom(doubleTapZoom);
607 public void setDoubleTapZoom(int percent) {
608 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
611 // -----------------------------
612 // getter/setters for advanced_preferences.xml
613 // -----------------------------
615 public String getSearchEngineName() {
616 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
619 public boolean openInBackground() {
620 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
623 public boolean enableJavascript() {
624 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
628 public PluginState getPluginState() {
629 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
630 return PluginState.valueOf(state);
634 public ZoomDensity getDefaultZoom() {
635 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
636 return ZoomDensity.valueOf(zoom);
639 public boolean loadPageInOverviewMode() {
640 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
643 public boolean autofitPages() {
644 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
647 public boolean blockPopupWindows() {
648 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
651 public boolean loadImages() {
652 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
655 public String getDefaultTextEncoding() {
656 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
659 // -----------------------------
660 // getter/setters for general_preferences.xml
661 // -----------------------------
663 public String getHomePage() {
664 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
667 public void setHomePage(String value) {
668 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
671 public boolean isAutofillEnabled() {
672 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
675 public void setAutofillEnabled(boolean value) {
676 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
679 // -----------------------------
680 // getter/setters for debug_preferences.xml
681 // -----------------------------
683 public boolean isHardwareAccelerated() {
684 if (!isDebugEnabled()) {
687 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
690 public boolean isSkiaHardwareAccelerated() {
691 if (!isDebugEnabled()) {
694 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
697 public int getUserAgent() {
698 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
701 // -----------------------------
702 // getter/setters for hidden_debug_preferences.xml
703 // -----------------------------
705 public boolean enableVisualIndicator() {
706 if (!isDebugEnabled()) {
709 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
712 public boolean enableCpuUploadPath() {
713 if (!isDebugEnabled()) {
716 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
719 public boolean enableJavascriptConsole() {
720 if (!isDebugEnabled()) {
723 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
726 public boolean isSmallScreen() {
727 if (!isDebugEnabled()) {
730 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
733 public boolean isWideViewport() {
734 if (!isDebugEnabled()) {
737 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
740 public boolean isNormalLayout() {
741 if (!isDebugEnabled()) {
744 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
747 public boolean isTracing() {
748 if (!isDebugEnabled()) {
751 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
754 public boolean enableLightTouch() {
755 if (!isDebugEnabled()) {
758 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
761 public boolean enableNavDump() {
762 if (!isDebugEnabled()) {
765 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
768 public String getJsEngineFlags() {
769 if (!isDebugEnabled()) {
772 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
775 // -----------------------------
776 // getter/setters for lab_preferences.xml
777 // -----------------------------
779 public boolean useQuickControls() {
780 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
783 public boolean useQuickControlsExt() {
784 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS_EXT, false);
787 public boolean useMostVisitedHomepage() {
788 return HomeProvider.MOST_VISITED.equals(getHomePage());
791 public boolean useFullscreen() {
792 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
795 public boolean useInvertedRendering() {
796 return mPrefs.getBoolean(PREF_INVERTED, false);
799 public float getInvertedContrast() {
800 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
803 // -----------------------------
804 // getter/setters for privacy_security_preferences.xml
805 // -----------------------------
807 public boolean showSecurityWarnings() {
808 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
811 public boolean showSearchSuggestions() {
812 return mPrefs.getBoolean(PREF_SHOW_SEARCH_SUGGESTIONS, false);
815 public boolean acceptCookies() {
816 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
819 public boolean saveFormdata() {
820 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
823 public boolean enableGeolocation() {
824 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
827 public boolean rememberPasswords() {
828 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
831 // -----------------------------
832 // getter/setters for bandwidth_preferences.xml
833 // -----------------------------
835 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
836 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
839 public static String getPreloadAlwaysPreferenceString(Context context) {
840 return context.getResources().getString(R.string.pref_data_preload_value_always);
843 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
844 "browser_default_preload_setting";
846 public String getDefaultPreloadSetting() {
847 String preload = Settings.Secure.getString(mContext.getContentResolver(),
848 DEAULT_PRELOAD_SECURE_SETTING_KEY);
849 if (preload == null) {
850 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
855 public String getPreloadEnabled() {
856 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());