BrowserSettings.java revision dc657fa17179878ecf536ad1cb6e8891c4aab29e
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 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 19import android.app.ActivityManager; 20import android.content.ContentResolver; 21import android.content.Context; 22import android.content.SharedPreferences; 23import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 24import android.os.Build; 25import android.os.Message; 26import android.preference.PreferenceManager; 27import android.provider.Browser; 28import android.webkit.CookieManager; 29import android.webkit.GeolocationPermissions; 30import android.webkit.WebIconDatabase; 31import android.webkit.WebSettings; 32import android.webkit.WebSettings.AutoFillProfile; 33import android.webkit.WebSettings.LayoutAlgorithm; 34import android.webkit.WebSettings.PluginState; 35import android.webkit.WebSettings.TextSize; 36import android.webkit.WebSettings.ZoomDensity; 37import android.webkit.WebStorage; 38import android.webkit.WebView; 39import android.webkit.WebViewDatabase; 40 41import com.android.browser.homepages.HomeProvider; 42import com.android.browser.provider.BrowserProvider; 43import com.android.browser.search.SearchEngine; 44import com.android.browser.search.SearchEngines; 45 46import java.lang.ref.WeakReference; 47import java.util.Iterator; 48import java.util.LinkedList; 49import java.util.WeakHashMap; 50 51/** 52 * Class for managing settings 53 */ 54public class BrowserSettings implements OnSharedPreferenceChangeListener, 55 PreferenceKeys { 56 57 // TODO: Do something with this UserAgent stuff 58 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"; 61 62 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + 63 "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"; 65 66 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + 67 "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"; 69 70 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + 71 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + 72 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; 73 74 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 78 private static final String USER_AGENTS[] = { null, 79 DESKTOP_USERAGENT, 80 IPHONE_USERAGENT, 81 IPAD_USERAGENT, 82 FROYO_USERAGENT, 83 HONEYCOMB_USERAGENT, 84 }; 85 86 // 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 // The initial value in the text zoom range 91 // This is what represents 100% in the SeekBarPreference range 92 private static final int TEXT_ZOOM_START_VAL = 10; 93 // The size of a single step in the text zoom range, in percent 94 private static final int TEXT_ZOOM_STEP = 5; 95 96 private static BrowserSettings sInstance; 97 98 private Context mContext; 99 private SharedPreferences mPrefs; 100 private LinkedList<WeakReference<WebSettings>> mManagedSettings; 101 private Controller mController; 102 private WebStorageSizeManager mWebStorageSizeManager; 103 private AutofillHandler mAutofillHandler; 104 private WeakHashMap<WebSettings, String> mCustomUserAgents; 105 private static boolean sInitialized = false; 106 107 // Cached values 108 private int mPageCacheCapacity = 1; 109 private String mAppCachePath; 110 111 // Cached settings 112 private SearchEngine mSearchEngine; 113 114 private static String sFactoryResetUrl; 115 116 public static void initialize(final Context context) { 117 sInstance = new BrowserSettings(context); 118 } 119 120 public static BrowserSettings getInstance() { 121 return sInstance; 122 } 123 124 private BrowserSettings(Context context) { 125 mContext = context.getApplicationContext(); 126 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); 127 mAutofillHandler = new AutofillHandler(mContext); 128 mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); 129 mCustomUserAgents = new WeakHashMap<WebSettings, String>(); 130 mPrefs.registerOnSharedPreferenceChangeListener(this); 131 mAutofillHandler.asyncLoadFromDb(); 132 BackgroundHandler.execute(mSetup); 133 } 134 135 public void setController(Controller controller) { 136 mController = controller; 137 syncSharedSettings(); 138 139 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { 140 ((InstantSearchEngine) mSearchEngine).setController(mController); 141 } 142 } 143 144 public void startManagingSettings(WebSettings settings) { 145 synchronized (mManagedSettings) { 146 syncStaticSettings(settings); 147 syncSetting(settings); 148 mManagedSettings.add(new WeakReference<WebSettings>(settings)); 149 } 150 } 151 152 private Runnable mSetup = new Runnable() { 153 154 @Override 155 public void run() { 156 // the cost of one cached page is ~3M (measured using nytimes.com). For 157 // low end devices, we only cache one page. For high end devices, we try 158 // to cache more pages, currently choose 5. 159 if (ActivityManager.staticGetMemoryClass() > 16) { 160 mPageCacheCapacity = 5; 161 } 162 mWebStorageSizeManager = new WebStorageSizeManager(mContext, 163 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), 164 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); 165 if (Build.VERSION.CODENAME.equals("REL")) { 166 // This is a release build, always startup with debug disabled 167 setDebugEnabled(false); 168 } 169 if (mPrefs.contains(PREF_TEXT_SIZE)) { 170 /* 171 * Update from TextSize enum to zoom percent 172 * SMALLEST is 50% 173 * SMALLER is 75% 174 * NORMAL is 100% 175 * LARGER is 150% 176 * LARGEST is 200% 177 */ 178 switch (getTextSize()) { 179 case SMALLEST: 180 setTextZoom(50); 181 break; 182 case SMALLER: 183 setTextZoom(75); 184 break; 185 case LARGER: 186 setTextZoom(150); 187 break; 188 case LARGEST: 189 setTextZoom(200); 190 break; 191 } 192 mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); 193 } 194 195 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base); 196 if (sFactoryResetUrl.indexOf("{CID}") != -1) { 197 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}", 198 BrowserProvider.getClientId(mContext.getContentResolver())); 199 } 200 201 synchronized (BrowserSettings.class) { 202 sInitialized = true; 203 BrowserSettings.class.notifyAll(); 204 } 205 } 206 }; 207 208 private static void requireInitialization() { 209 synchronized (BrowserSettings.class) { 210 while (!sInitialized) { 211 try { 212 BrowserSettings.class.wait(); 213 } catch (InterruptedException e) { 214 } 215 } 216 } 217 } 218 219 /** 220 * Syncs all the settings that have a Preference UI 221 */ 222 private void syncSetting(WebSettings settings) { 223 settings.setGeolocationEnabled(enableGeolocation()); 224 settings.setJavaScriptEnabled(enableJavascript()); 225 settings.setLightTouchEnabled(enableLightTouch()); 226 settings.setNavDump(enableNavDump()); 227 settings.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated()); 228 settings.setShowVisualIndicator(enableVisualIndicator()); 229 settings.setDefaultTextEncodingName(getDefaultTextEncoding()); 230 settings.setDefaultZoom(getDefaultZoom()); 231 settings.setMinimumFontSize(getMinimumFontSize()); 232 settings.setMinimumLogicalFontSize(getMinimumFontSize()); 233 settings.setForceUserScalable(forceEnableUserScalable()); 234 settings.setPluginState(getPluginState()); 235 settings.setTextZoom(getTextZoom()); 236 settings.setAutoFillEnabled(isAutofillEnabled()); 237 settings.setLayoutAlgorithm(getLayoutAlgorithm()); 238 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows()); 239 settings.setLoadsImagesAutomatically(loadImages()); 240 settings.setLoadWithOverviewMode(loadPageInOverviewMode()); 241 settings.setSavePassword(rememberPasswords()); 242 settings.setSaveFormData(saveFormdata()); 243 settings.setUseWideViewPort(isWideViewport()); 244 settings.setAutoFillProfile(getAutoFillProfile()); 245 246 String ua = mCustomUserAgents.get(settings); 247 if (ua != null) { 248 settings.setUserAgentString(ua); 249 } else { 250 settings.setUserAgentString(USER_AGENTS[getUserAgent()]); 251 } 252 253 settings.setProperty("gfxInvertedScreen", 254 useInvertedRendering() ? "true" : "false"); 255 } 256 257 /** 258 * Syncs all the settings that have no UI 259 * These cannot change, so we only need to set them once per WebSettings 260 */ 261 private void syncStaticSettings(WebSettings settings) { 262 settings.setDefaultFontSize(16); 263 settings.setDefaultFixedFontSize(13); 264 settings.setPageCacheCapacity(getPageCacheCapacity()); 265 266 // WebView inside Browser doesn't want initial focus to be set. 267 settings.setNeedInitialFocus(false); 268 // Browser supports multiple windows 269 settings.setSupportMultipleWindows(true); 270 // enable smooth transition for better performance during panning or 271 // zooming 272 settings.setEnableSmoothTransition(true); 273 // disable content url access 274 settings.setAllowContentAccess(false); 275 276 // HTML5 API flags 277 settings.setAppCacheEnabled(true); 278 settings.setDatabaseEnabled(true); 279 settings.setDomStorageEnabled(true); 280 settings.setWorkersEnabled(true); // This only affects V8. 281 282 // HTML5 configuration parametersettings. 283 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize()); 284 settings.setAppCachePath(getAppCachePath()); 285 settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); 286 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); 287 } 288 289 private void syncSharedSettings() { 290 CookieManager.getInstance().setAcceptCookie(acceptCookies()); 291 if (mController != null) { 292 mController.setShouldShowErrorConsole(enableJavascriptConsole()); 293 } 294 } 295 296 private void syncManagedSettings() { 297 syncSharedSettings(); 298 synchronized (mManagedSettings) { 299 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator(); 300 while (iter.hasNext()) { 301 WeakReference<WebSettings> ref = iter.next(); 302 WebSettings settings = ref.get(); 303 if (settings == null) { 304 iter.remove(); 305 continue; 306 } 307 syncSetting(settings); 308 } 309 } 310 } 311 312 @Override 313 public void onSharedPreferenceChanged( 314 SharedPreferences sharedPreferences, String key) { 315 syncManagedSettings(); 316 if (PREF_SEARCH_ENGINE.equals(key)) { 317 updateSearchEngine(false); 318 } 319 if (PREF_USE_INSTANT_SEARCH.equals(key)) { 320 updateSearchEngine(true); 321 } 322 if (PREF_FULLSCREEN.equals(key)) { 323 if (mController.getUi() != null) { 324 mController.getUi().setFullscreen(useFullscreen()); 325 } 326 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) { 327 if (mController.getUi() != null) { 328 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false)); 329 } 330 } 331 } 332 333 public static String getFactoryResetHomeUrl(Context context) { 334 requireInitialization(); 335 return sFactoryResetUrl; 336 } 337 338 public LayoutAlgorithm getLayoutAlgorithm() { 339 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL; 340 if (autofitPages()) { 341 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; 342 } 343 if (isDebugEnabled()) { 344 if (isSmallScreen()) { 345 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN; 346 } else { 347 if (isNormalLayout()) { 348 layoutAlgorithm = LayoutAlgorithm.NORMAL; 349 } else { 350 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; 351 } 352 } 353 } 354 return layoutAlgorithm; 355 } 356 357 public int getPageCacheCapacity() { 358 requireInitialization(); 359 return mPageCacheCapacity; 360 } 361 362 public WebStorageSizeManager getWebStorageSizeManager() { 363 requireInitialization(); 364 return mWebStorageSizeManager; 365 } 366 367 private String getAppCachePath() { 368 if (mAppCachePath == null) { 369 mAppCachePath = mContext.getDir("appcache", 0).getPath(); 370 } 371 return mAppCachePath; 372 } 373 374 private void updateSearchEngine(boolean force) { 375 String searchEngineName = getSearchEngineName(); 376 if (force || mSearchEngine == null || 377 !mSearchEngine.getName().equals(searchEngineName)) { 378 if (mSearchEngine != null) { 379 if (mSearchEngine.supportsVoiceSearch()) { 380 // One or more tabs could have been in voice search mode. 381 // Clear it, since the new SearchEngine may not support 382 // it, or may handle it differently. 383 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) { 384 mController.getTabControl().getTab(i).revertVoiceSearchMode(); 385 } 386 } 387 mSearchEngine.close(); 388 } 389 mSearchEngine = SearchEngines.get(mContext, searchEngineName); 390 391 if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { 392 ((InstantSearchEngine) mSearchEngine).setController(mController); 393 } 394 } 395 } 396 397 public SearchEngine getSearchEngine() { 398 if (mSearchEngine == null) { 399 updateSearchEngine(false); 400 } 401 return mSearchEngine; 402 } 403 404 public boolean isDebugEnabled() { 405 requireInitialization(); 406 return mPrefs.getBoolean(PREF_DEBUG_MENU, false); 407 } 408 409 public void setDebugEnabled(boolean value) { 410 mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply(); 411 } 412 413 public void clearCache() { 414 WebIconDatabase.getInstance().removeAllIcons(); 415 if (mController != null) { 416 WebView current = mController.getCurrentWebView(); 417 if (current != null) { 418 current.clearCache(true); 419 } 420 } 421 } 422 423 public void clearCookies() { 424 CookieManager.getInstance().removeAllCookie(); 425 } 426 427 public void clearHistory() { 428 ContentResolver resolver = mContext.getContentResolver(); 429 Browser.clearHistory(resolver); 430 Browser.clearSearches(resolver); 431 } 432 433 public void clearFormData() { 434 WebViewDatabase.getInstance(mContext).clearFormData(); 435 if (mController!= null) { 436 WebView currentTopView = mController.getCurrentTopWebView(); 437 if (currentTopView != null) { 438 currentTopView.clearFormData(); 439 } 440 } 441 } 442 443 public void clearPasswords() { 444 WebViewDatabase db = WebViewDatabase.getInstance(mContext); 445 db.clearUsernamePassword(); 446 db.clearHttpAuthUsernamePassword(); 447 } 448 449 public void clearDatabases() { 450 WebStorage.getInstance().deleteAllData(); 451 } 452 453 public void clearLocationAccess() { 454 GeolocationPermissions.getInstance().clearAll(); 455 } 456 457 public void resetDefaultPreferences() { 458 // Preserve autologin setting 459 long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1); 460 mPrefs.edit() 461 .clear() 462 .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal) 463 .apply(); 464 syncManagedSettings(); 465 } 466 467 public AutoFillProfile getAutoFillProfile() { 468 mAutofillHandler.waitForLoad(); 469 return mAutofillHandler.getAutoFillProfile(); 470 } 471 472 public void setAutoFillProfile(AutoFillProfile profile, Message msg) { 473 mAutofillHandler.waitForLoad(); 474 mAutofillHandler.setAutoFillProfile(profile, msg); 475 // Auto-fill will reuse the same profile ID when making edits to the profile, 476 // so we need to force a settings sync (otherwise the SharedPreferences 477 // manager will optimise out the call to onSharedPreferenceChanged(), as 478 // it thinks nothing has changed). 479 syncManagedSettings(); 480 } 481 482 public void toggleDebugSettings() { 483 setDebugEnabled(!isDebugEnabled()); 484 } 485 486 public boolean hasDesktopUseragent(WebView view) { 487 return view != null && mCustomUserAgents.get(view.getSettings()) != null; 488 } 489 490 public void toggleDesktopUseragent(WebView view) { 491 if (view == null) { 492 return; 493 } 494 WebSettings settings = view.getSettings(); 495 if (mCustomUserAgents.get(settings) != null) { 496 mCustomUserAgents.remove(settings); 497 settings.setUserAgentString(USER_AGENTS[getUserAgent()]); 498 } else { 499 mCustomUserAgents.put(settings, DESKTOP_USERAGENT); 500 settings.setUserAgentString(DESKTOP_USERAGENT); 501 } 502 } 503 504 public static int getAdjustedMinimumFontSize(int rawValue) { 505 rawValue++; // Preference starts at 0, min font at 1 506 if (rawValue > 1) { 507 rawValue += (MIN_FONT_SIZE_OFFSET - 2); 508 } 509 return rawValue; 510 } 511 512 public static int getAdjustedTextZoom(int rawValue) { 513 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP; 514 return rawValue + 100; 515 } 516 517 static int getRawTextZoom(int percent) { 518 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL; 519 } 520 521 public SharedPreferences getPreferences() { 522 return mPrefs; 523 } 524 525 // ----------------------------- 526 // getter/setters for accessibility_preferences.xml 527 // ----------------------------- 528 529 @Deprecated 530 private TextSize getTextSize() { 531 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL"); 532 return TextSize.valueOf(textSize); 533 } 534 535 public int getMinimumFontSize() { 536 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0); 537 return getAdjustedMinimumFontSize(minFont); 538 } 539 540 public boolean forceEnableUserScalable() { 541 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false); 542 } 543 544 public int getTextZoom() { 545 requireInitialization(); 546 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10); 547 return getAdjustedTextZoom(textZoom); 548 } 549 550 public void setTextZoom(int percent) { 551 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply(); 552 } 553 554 // ----------------------------- 555 // getter/setters for advanced_preferences.xml 556 // ----------------------------- 557 558 public String getSearchEngineName() { 559 return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE); 560 } 561 562 public boolean openInBackground() { 563 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false); 564 } 565 566 public boolean enableJavascript() { 567 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true); 568 } 569 570 // TODO: Cache 571 public PluginState getPluginState() { 572 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON"); 573 return PluginState.valueOf(state); 574 } 575 576 // TODO: Cache 577 public ZoomDensity getDefaultZoom() { 578 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM"); 579 return ZoomDensity.valueOf(zoom); 580 } 581 582 public boolean loadPageInOverviewMode() { 583 return mPrefs.getBoolean(PREF_LOAD_PAGE, true); 584 } 585 586 public boolean autofitPages() { 587 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true); 588 } 589 590 public boolean blockPopupWindows() { 591 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true); 592 } 593 594 public boolean loadImages() { 595 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true); 596 } 597 598 public String getDefaultTextEncoding() { 599 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null); 600 } 601 602 // ----------------------------- 603 // getter/setters for general_preferences.xml 604 // ----------------------------- 605 606 public String getHomePage() { 607 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext)); 608 } 609 610 public void setHomePage(String value) { 611 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply(); 612 } 613 614 public boolean isAutofillEnabled() { 615 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true); 616 } 617 618 public void setAutofillEnabled(boolean value) { 619 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply(); 620 } 621 622 // ----------------------------- 623 // getter/setters for debug_preferences.xml 624 // ----------------------------- 625 626 public boolean isHardwareAccelerated() { 627 if (!isDebugEnabled()) { 628 return true; 629 } 630 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true); 631 } 632 633 public boolean isSkiaHardwareAccelerated() { 634 if (!isDebugEnabled()) { 635 return false; 636 } 637 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false); 638 } 639 640 public int getUserAgent() { 641 if (!isDebugEnabled()) { 642 return 0; 643 } 644 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0")); 645 } 646 647 // ----------------------------- 648 // getter/setters for hidden_debug_preferences.xml 649 // ----------------------------- 650 651 public boolean enableVisualIndicator() { 652 if (!isDebugEnabled()) { 653 return false; 654 } 655 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false); 656 } 657 658 public boolean enableJavascriptConsole() { 659 if (!isDebugEnabled()) { 660 return false; 661 } 662 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true); 663 } 664 665 public boolean isSmallScreen() { 666 if (!isDebugEnabled()) { 667 return false; 668 } 669 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false); 670 } 671 672 public boolean isWideViewport() { 673 if (!isDebugEnabled()) { 674 return true; 675 } 676 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true); 677 } 678 679 public boolean isNormalLayout() { 680 if (!isDebugEnabled()) { 681 return false; 682 } 683 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false); 684 } 685 686 public boolean isTracing() { 687 if (!isDebugEnabled()) { 688 return false; 689 } 690 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false); 691 } 692 693 public boolean enableLightTouch() { 694 if (!isDebugEnabled()) { 695 return false; 696 } 697 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false); 698 } 699 700 public boolean enableNavDump() { 701 if (!isDebugEnabled()) { 702 return false; 703 } 704 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false); 705 } 706 707 public String getJsEngineFlags() { 708 if (!isDebugEnabled()) { 709 return ""; 710 } 711 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, ""); 712 } 713 714 // ----------------------------- 715 // getter/setters for lab_preferences.xml 716 // ----------------------------- 717 718 public boolean useQuickControls() { 719 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false); 720 } 721 722 public boolean useMostVisitedHomepage() { 723 return HomeProvider.MOST_VISITED.equals(getHomePage()); 724 } 725 726 public boolean useInstantSearch() { 727 return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false); 728 } 729 730 public boolean useFullscreen() { 731 return mPrefs.getBoolean(PREF_FULLSCREEN, false); 732 } 733 734 public boolean useInvertedRendering() { 735 return mPrefs.getBoolean(PREF_INVERTED, false); 736 } 737 738 // ----------------------------- 739 // getter/setters for privacy_security_preferences.xml 740 // ----------------------------- 741 742 public boolean showSecurityWarnings() { 743 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true); 744 } 745 746 public boolean acceptCookies() { 747 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true); 748 } 749 750 public boolean saveFormdata() { 751 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true); 752 } 753 754 public boolean enableGeolocation() { 755 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true); 756 } 757 758 public boolean rememberPasswords() { 759 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true); 760 } 761 762 // ----------------------------- 763 // getter/setters for bandwidth_preferences.xml 764 // ----------------------------- 765 766 public boolean isPreloadEnabled() { 767 return mPrefs.getBoolean(PREF_DATA_PRELOAD, false); 768 } 769} 770