BrowserSettings.java revision ce549fcaf3a29b22d8ec1f2d45146c4b484e0068
1 2/* 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.browser; 19 20import com.android.browser.search.SearchEngine; 21import com.android.browser.search.SearchEngines; 22 23import android.app.ActivityManager; 24import android.content.ComponentName; 25import android.content.ContentResolver; 26import android.content.Context; 27import android.content.pm.ActivityInfo; 28import android.content.SharedPreferences; 29import android.content.SharedPreferences.Editor; 30import android.database.ContentObserver; 31import android.net.Uri; 32import android.os.Handler; 33import android.preference.PreferenceActivity; 34import android.preference.PreferenceScreen; 35import android.provider.Settings; 36import android.util.Log; 37import android.webkit.CookieManager; 38import android.webkit.GeolocationPermissions; 39import android.webkit.ValueCallback; 40import android.webkit.WebView; 41import android.webkit.WebViewDatabase; 42import android.webkit.WebIconDatabase; 43import android.webkit.WebSettings; 44import android.webkit.WebStorage; 45import android.preference.PreferenceManager; 46import android.provider.Browser; 47 48import java.util.HashMap; 49import java.util.Map; 50import java.util.Set; 51import java.util.Observable; 52 53/* 54 * Package level class for storing various WebView and Browser settings. To use 55 * this class: 56 * BrowserSettings s = BrowserSettings.getInstance(); 57 * s.addObserver(webView.getSettings()); 58 * s.loadFromDb(context); // Only needed on app startup 59 * s.javaScriptEnabled = true; 60 * ... // set any other settings 61 * s.update(); // this will update all the observers 62 * 63 * To remove an observer: 64 * s.deleteObserver(webView.getSettings()); 65 */ 66class BrowserSettings extends Observable { 67 68 // Private variables for settings 69 // NOTE: these defaults need to be kept in sync with the XML 70 // until the performance of PreferenceManager.setDefaultValues() 71 // is improved. 72 // Note: boolean variables are set inside reset function. 73 private boolean loadsImagesAutomatically; 74 private boolean javaScriptEnabled; 75 private WebSettings.PluginState pluginState; 76 private boolean javaScriptCanOpenWindowsAutomatically; 77 private boolean showSecurityWarnings; 78 private boolean rememberPasswords; 79 private boolean saveFormData; 80 private boolean autoFillEnabled; 81 private boolean openInBackground; 82 private String defaultTextEncodingName; 83 private String homeUrl = ""; 84 private SearchEngine searchEngine; 85 private boolean autoFitPage; 86 private boolean landscapeOnly; 87 private boolean loadsPageInOverviewMode; 88 private boolean showDebugSettings; 89 // HTML5 API flags 90 private boolean appCacheEnabled; 91 private boolean databaseEnabled; 92 private boolean domStorageEnabled; 93 private boolean geolocationEnabled; 94 private boolean workersEnabled; // only affects V8. JSC does not have a similar setting 95 // HTML5 API configuration params 96 private long appCacheMaxSize = Long.MAX_VALUE; 97 private String appCachePath; // default value set in loadFromDb(). 98 private String databasePath; // default value set in loadFromDb() 99 private String geolocationDatabasePath; // default value set in loadFromDb() 100 private WebStorageSizeManager webStorageSizeManager; 101 102 private String jsFlags = ""; 103 104 private final static String TAG = "BrowserSettings"; 105 106 // Development settings 107 public WebSettings.LayoutAlgorithm layoutAlgorithm = 108 WebSettings.LayoutAlgorithm.NARROW_COLUMNS; 109 private boolean useWideViewPort = true; 110 private int userAgent = 0; 111 private boolean tracing = false; 112 private boolean lightTouch = false; 113 private boolean navDump = false; 114 115 // By default the error console is shown once the user navigates to about:debug. 116 // The setting can be then toggled from the settings menu. 117 private boolean showConsole = true; 118 119 // Private preconfigured values 120 private static int minimumFontSize = 1; 121 private static int minimumLogicalFontSize = 1; 122 private static int defaultFontSize = 16; 123 private static int defaultFixedFontSize = 13; 124 private static WebSettings.TextSize textSize = 125 WebSettings.TextSize.NORMAL; 126 private static WebSettings.ZoomDensity zoomDensity = 127 WebSettings.ZoomDensity.MEDIUM; 128 private static int pageCacheCapacity; 129 130 // Preference keys that are used outside this class 131 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache"; 132 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies"; 133 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history"; 134 public final static String PREF_HOMEPAGE = "homepage"; 135 public final static String PREF_SEARCH_ENGINE = "search_engine"; 136 public final static String PREF_CLEAR_FORM_DATA = 137 "privacy_clear_form_data"; 138 public final static String PREF_CLEAR_PASSWORDS = 139 "privacy_clear_passwords"; 140 public final static String PREF_EXTRAS_RESET_DEFAULTS = 141 "reset_default_preferences"; 142 public final static String PREF_DEBUG_SETTINGS = "debug_menu"; 143 public final static String PREF_WEBSITE_SETTINGS = "website_settings"; 144 public final static String PREF_TEXT_SIZE = "text_size"; 145 public final static String PREF_DEFAULT_ZOOM = "default_zoom"; 146 public final static String PREF_DEFAULT_TEXT_ENCODING = 147 "default_text_encoding"; 148 public final static String PREF_CLEAR_GEOLOCATION_ACCESS = 149 "privacy_clear_geolocation_access"; 150 151 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " + 152 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " + 153 "like Gecko) Version/5.0 Safari/533.16"; 154 155 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + 156 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " + 157 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; 158 159 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + 160 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " + 161 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"; 162 163 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + 164 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + 165 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; 166 167 // Value to truncate strings when adding them to a TextView within 168 // a ListView 169 public final static int MAX_TEXTVIEW_LEN = 80; 170 171 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider"; 172 173 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/"); 174 175 private TabControl mTabControl; 176 177 // Single instance of the BrowserSettings for use in the Browser app. 178 private static BrowserSettings sSingleton; 179 180 // Private map of WebSettings to Observer objects used when deleting an 181 // observer. 182 private HashMap<WebSettings,Observer> mWebSettingsToObservers = 183 new HashMap<WebSettings,Observer>(); 184 185 /* 186 * An observer wrapper for updating a WebSettings object with the new 187 * settings after a call to BrowserSettings.update(). 188 */ 189 static class Observer implements java.util.Observer { 190 // Private WebSettings object that will be updated. 191 private WebSettings mSettings; 192 193 Observer(WebSettings w) { 194 mSettings = w; 195 } 196 197 public void update(Observable o, Object arg) { 198 BrowserSettings b = (BrowserSettings)o; 199 WebSettings s = mSettings; 200 201 s.setLayoutAlgorithm(b.layoutAlgorithm); 202 if (b.userAgent == 0) { 203 // use the default ua string 204 s.setUserAgentString(null); 205 } else if (b.userAgent == 1) { 206 s.setUserAgentString(DESKTOP_USERAGENT); 207 } else if (b.userAgent == 2) { 208 s.setUserAgentString(IPHONE_USERAGENT); 209 } else if (b.userAgent == 3) { 210 s.setUserAgentString(IPAD_USERAGENT); 211 } else if (b.userAgent == 4) { 212 s.setUserAgentString(FROYO_USERAGENT); 213 } 214 s.setUseWideViewPort(b.useWideViewPort); 215 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically); 216 s.setJavaScriptEnabled(b.javaScriptEnabled); 217 s.setPluginState(b.pluginState); 218 s.setJavaScriptCanOpenWindowsAutomatically( 219 b.javaScriptCanOpenWindowsAutomatically); 220 s.setDefaultTextEncodingName(b.defaultTextEncodingName); 221 s.setMinimumFontSize(b.minimumFontSize); 222 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize); 223 s.setDefaultFontSize(b.defaultFontSize); 224 s.setDefaultFixedFontSize(b.defaultFixedFontSize); 225 s.setNavDump(b.navDump); 226 s.setTextSize(b.textSize); 227 s.setDefaultZoom(b.zoomDensity); 228 s.setLightTouchEnabled(b.lightTouch); 229 s.setSaveFormData(b.saveFormData); 230 s.setAutoFillEnabled(b.autoFillEnabled); 231 s.setSavePassword(b.rememberPasswords); 232 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode); 233 s.setPageCacheCapacity(pageCacheCapacity); 234 235 // WebView inside Browser doesn't want initial focus to be set. 236 s.setNeedInitialFocus(false); 237 // Browser supports multiple windows 238 s.setSupportMultipleWindows(true); 239 // enable smooth transition for better performance during panning or 240 // zooming 241 s.setEnableSmoothTransition(true); 242 243 // HTML5 API flags 244 s.setAppCacheEnabled(b.appCacheEnabled); 245 s.setDatabaseEnabled(b.databaseEnabled); 246 s.setDomStorageEnabled(b.domStorageEnabled); 247 s.setWorkersEnabled(b.workersEnabled); // This only affects V8. 248 s.setGeolocationEnabled(b.geolocationEnabled); 249 250 // HTML5 configuration parameters. 251 s.setAppCacheMaxSize(b.appCacheMaxSize); 252 s.setAppCachePath(b.appCachePath); 253 s.setDatabasePath(b.databasePath); 254 s.setGeolocationDatabasePath(b.geolocationDatabasePath); 255 256 b.updateTabControlSettings(); 257 } 258 } 259 260 /** 261 * Load settings from the browser app's database. 262 * NOTE: Strings used for the preferences must match those specified 263 * in the browser_preferences.xml 264 * @param ctx A Context object used to query the browser's settings 265 * database. If the database exists, the saved settings will be 266 * stored in this BrowserSettings object. This will update all 267 * observers of this object. 268 */ 269 public void loadFromDb(final Context ctx) { 270 SharedPreferences p = 271 PreferenceManager.getDefaultSharedPreferences(ctx); 272 // Set the default value for the Application Caches path. 273 appCachePath = ctx.getDir("appcache", 0).getPath(); 274 // Determine the maximum size of the application cache. 275 webStorageSizeManager = new WebStorageSizeManager( 276 ctx, 277 new WebStorageSizeManager.StatFsDiskInfo(appCachePath), 278 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath)); 279 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); 280 // Set the default value for the Database path. 281 databasePath = ctx.getDir("databases", 0).getPath(); 282 // Set the default value for the Geolocation database path. 283 geolocationDatabasePath = ctx.getDir("geolocation", 0).getPath(); 284 285 if (p.getString(PREF_HOMEPAGE, "") == "") { 286 // No home page preferences is set, set it to default. 287 setHomePage(ctx, getFactoryResetHomeUrl(ctx)); 288 } 289 290 // the cost of one cached page is ~3M (measured using nytimes.com). For 291 // low end devices, we only cache one page. For high end devices, we try 292 // to cache more pages, currently choose 5. 293 ActivityManager am = (ActivityManager) ctx 294 .getSystemService(Context.ACTIVITY_SERVICE); 295 if (am.getMemoryClass() > 16) { 296 pageCacheCapacity = 5; 297 } else { 298 pageCacheCapacity = 1; 299 } 300 301 // Load the defaults from the xml 302 // This call is TOO SLOW, need to manually keep the defaults 303 // in sync 304 //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences); 305 syncSharedPreferences(ctx, p); 306 } 307 308 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) { 309 310 homeUrl = 311 p.getString(PREF_HOMEPAGE, homeUrl); 312 String searchEngineName = p.getString(PREF_SEARCH_ENGINE, 313 SearchEngine.GOOGLE); 314 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) { 315 if (searchEngine != null) { 316 if (searchEngine.supportsVoiceSearch()) { 317 // One or more tabs could have been in voice search mode. 318 // Clear it, since the new SearchEngine may not support 319 // it, or may handle it differently. 320 for (int i = 0; i < mTabControl.getTabCount(); i++) { 321 mTabControl.getTab(i).revertVoiceSearchMode(); 322 } 323 } 324 searchEngine.close(); 325 } 326 searchEngine = SearchEngines.get(ctx, searchEngineName); 327 } 328 Log.i(TAG, "Selected search engine: " + searchEngine); 329 330 loadsImagesAutomatically = p.getBoolean("load_images", 331 loadsImagesAutomatically); 332 javaScriptEnabled = p.getBoolean("enable_javascript", 333 javaScriptEnabled); 334 pluginState = WebSettings.PluginState.valueOf( 335 p.getString("plugin_state", pluginState.name())); 336 javaScriptCanOpenWindowsAutomatically = !p.getBoolean( 337 "block_popup_windows", 338 !javaScriptCanOpenWindowsAutomatically); 339 showSecurityWarnings = p.getBoolean("show_security_warnings", 340 showSecurityWarnings); 341 rememberPasswords = p.getBoolean("remember_passwords", 342 rememberPasswords); 343 saveFormData = p.getBoolean("save_formdata", 344 saveFormData); 345 autoFillEnabled = p.getBoolean("autoFill_enabled", autoFillEnabled); 346 boolean accept_cookies = p.getBoolean("accept_cookies", 347 CookieManager.getInstance().acceptCookie()); 348 CookieManager.getInstance().setAcceptCookie(accept_cookies); 349 openInBackground = p.getBoolean("open_in_background", openInBackground); 350 textSize = WebSettings.TextSize.valueOf( 351 p.getString(PREF_TEXT_SIZE, textSize.name())); 352 zoomDensity = WebSettings.ZoomDensity.valueOf( 353 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name())); 354 autoFitPage = p.getBoolean("autofit_pages", autoFitPage); 355 loadsPageInOverviewMode = p.getBoolean("load_page", 356 loadsPageInOverviewMode); 357 boolean landscapeOnlyTemp = 358 p.getBoolean("landscape_only", landscapeOnly); 359 if (landscapeOnlyTemp != landscapeOnly) { 360 landscapeOnly = landscapeOnlyTemp; 361 } 362 useWideViewPort = true; // use wide view port for either setting 363 if (autoFitPage) { 364 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS; 365 } else { 366 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; 367 } 368 defaultTextEncodingName = 369 p.getString(PREF_DEFAULT_TEXT_ENCODING, 370 defaultTextEncodingName); 371 372 showDebugSettings = 373 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings); 374 // Debug menu items have precidence if the menu is visible 375 if (showDebugSettings) { 376 boolean small_screen = p.getBoolean("small_screen", 377 layoutAlgorithm == 378 WebSettings.LayoutAlgorithm.SINGLE_COLUMN); 379 if (small_screen) { 380 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN; 381 } else { 382 boolean normal_layout = p.getBoolean("normal_layout", 383 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL); 384 if (normal_layout) { 385 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; 386 } else { 387 layoutAlgorithm = 388 WebSettings.LayoutAlgorithm.NARROW_COLUMNS; 389 } 390 } 391 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort); 392 tracing = p.getBoolean("enable_tracing", tracing); 393 lightTouch = p.getBoolean("enable_light_touch", lightTouch); 394 navDump = p.getBoolean("enable_nav_dump", navDump); 395 userAgent = Integer.parseInt(p.getString("user_agent", "0")); 396 } 397 // JS flags is loaded from DB even if showDebugSettings is false, 398 // so that it can be set once and be effective all the time. 399 jsFlags = p.getString("js_engine_flags", ""); 400 401 // Read the setting for showing/hiding the JS Console always so that should the 402 // user enable debug settings, we already know if we should show the console. 403 // The user will never see the console unless they navigate to about:debug, 404 // regardless of the setting we read here. This setting is only used after debug 405 // is enabled. 406 showConsole = p.getBoolean("javascript_console", showConsole); 407 408 // HTML5 API flags 409 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled); 410 databaseEnabled = p.getBoolean("enable_database", databaseEnabled); 411 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled); 412 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled); 413 workersEnabled = p.getBoolean("enable_workers", workersEnabled); 414 415 update(); 416 } 417 418 public String getHomePage() { 419 return homeUrl; 420 } 421 422 public SearchEngine getSearchEngine() { 423 return searchEngine; 424 } 425 426 public String getJsFlags() { 427 return jsFlags; 428 } 429 430 public WebStorageSizeManager getWebStorageSizeManager() { 431 return webStorageSizeManager; 432 } 433 434 public void setHomePage(Context context, String url) { 435 Editor ed = PreferenceManager. 436 getDefaultSharedPreferences(context).edit(); 437 ed.putString(PREF_HOMEPAGE, url); 438 ed.apply(); 439 homeUrl = url; 440 } 441 442 public WebSettings.TextSize getTextSize() { 443 return textSize; 444 } 445 446 public WebSettings.ZoomDensity getDefaultZoom() { 447 return zoomDensity; 448 } 449 450 public boolean openInBackground() { 451 return openInBackground; 452 } 453 454 public boolean showSecurityWarnings() { 455 return showSecurityWarnings; 456 } 457 458 public boolean isTracing() { 459 return tracing; 460 } 461 462 public boolean isLightTouch() { 463 return lightTouch; 464 } 465 466 public boolean isNavDump() { 467 return navDump; 468 } 469 470 public boolean showDebugSettings() { 471 return showDebugSettings; 472 } 473 474 public void toggleDebugSettings() { 475 showDebugSettings = !showDebugSettings; 476 navDump = showDebugSettings; 477 update(); 478 } 479 480 /** 481 * Add a WebSettings object to the list of observers that will be updated 482 * when update() is called. 483 * 484 * @param s A WebSettings object that is strictly tied to the life of a 485 * WebView. 486 */ 487 public Observer addObserver(WebSettings s) { 488 Observer old = mWebSettingsToObservers.get(s); 489 if (old != null) { 490 super.deleteObserver(old); 491 } 492 Observer o = new Observer(s); 493 mWebSettingsToObservers.put(s, o); 494 super.addObserver(o); 495 return o; 496 } 497 498 /** 499 * Delete the given WebSettings observer from the list of observers. 500 * @param s The WebSettings object to be deleted. 501 */ 502 public void deleteObserver(WebSettings s) { 503 Observer o = mWebSettingsToObservers.get(s); 504 if (o != null) { 505 mWebSettingsToObservers.remove(s); 506 super.deleteObserver(o); 507 } 508 } 509 510 /* 511 * Package level method for obtaining a single app instance of the 512 * BrowserSettings. 513 */ 514 /*package*/ static BrowserSettings getInstance() { 515 if (sSingleton == null ) { 516 sSingleton = new BrowserSettings(); 517 } 518 return sSingleton; 519 } 520 521 /* 522 * Package level method for associating the BrowserSettings with TabControl 523 */ 524 /* package */void setTabControl(TabControl tabControl) { 525 mTabControl = tabControl; 526 updateTabControlSettings(); 527 } 528 529 /* 530 * Update all the observers of the object. 531 */ 532 /*package*/ void update() { 533 setChanged(); 534 notifyObservers(); 535 } 536 537 /*package*/ void clearCache(Context context) { 538 WebIconDatabase.getInstance().removeAllIcons(); 539 if (mTabControl != null) { 540 WebView current = mTabControl.getCurrentWebView(); 541 if (current != null) { 542 current.clearCache(true); 543 } 544 } 545 } 546 547 /*package*/ void clearCookies(Context context) { 548 CookieManager.getInstance().removeAllCookie(); 549 } 550 551 /* package */void clearHistory(Context context) { 552 ContentResolver resolver = context.getContentResolver(); 553 Browser.clearHistory(resolver); 554 Browser.clearSearches(resolver); 555 } 556 557 /* package */ void clearFormData(Context context) { 558 WebViewDatabase.getInstance(context).clearFormData(); 559 if (mTabControl != null) { 560 WebView currentTopView = mTabControl.getCurrentTopWebView(); 561 if (currentTopView != null) { 562 currentTopView.clearFormData(); 563 } 564 } 565 } 566 567 /*package*/ void clearPasswords(Context context) { 568 WebViewDatabase db = WebViewDatabase.getInstance(context); 569 db.clearUsernamePassword(); 570 db.clearHttpAuthUsernamePassword(); 571 } 572 573 private void updateTabControlSettings() { 574 // Enable/disable the error console. 575 mTabControl.getBrowserActivity().setShouldShowErrorConsole( 576 showDebugSettings && showConsole); 577 mTabControl.getBrowserActivity().setRequestedOrientation( 578 landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE 579 : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 580 } 581 582 private void maybeDisableWebsiteSettings(Context context) { 583 PreferenceActivity activity = (PreferenceActivity) context; 584 final PreferenceScreen screen = (PreferenceScreen) 585 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS); 586 screen.setEnabled(false); 587 WebStorage.getInstance().getOrigins(new ValueCallback<Map>() { 588 public void onReceiveValue(Map webStorageOrigins) { 589 if ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) { 590 screen.setEnabled(true); 591 } 592 } 593 }); 594 595 GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set<String> >() { 596 public void onReceiveValue(Set<String> geolocationOrigins) { 597 if ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()) { 598 screen.setEnabled(true); 599 } 600 } 601 }); 602 } 603 604 /*package*/ void clearDatabases(Context context) { 605 WebStorage.getInstance().deleteAllData(); 606 maybeDisableWebsiteSettings(context); 607 } 608 609 /*package*/ void clearLocationAccess(Context context) { 610 GeolocationPermissions.getInstance().clearAll(); 611 maybeDisableWebsiteSettings(context); 612 } 613 614 /*package*/ void resetDefaultPreferences(Context ctx) { 615 reset(); 616 SharedPreferences p = 617 PreferenceManager.getDefaultSharedPreferences(ctx); 618 p.edit().clear().apply(); 619 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences, 620 true); 621 // reset homeUrl 622 setHomePage(ctx, getFactoryResetHomeUrl(ctx)); 623 // reset appcache max size 624 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); 625 } 626 627 private String getFactoryResetHomeUrl(Context context) { 628 String url = context.getResources().getString(R.string.homepage_base); 629 if (url.indexOf("{CID}") != -1) { 630 url = url.replace("{CID}", 631 BrowserProvider.getClientId(context.getContentResolver())); 632 } 633 return url; 634 } 635 636 // Private constructor that does nothing. 637 private BrowserSettings() { 638 reset(); 639 } 640 641 private void reset() { 642 // Private variables for settings 643 // NOTE: these defaults need to be kept in sync with the XML 644 // until the performance of PreferenceManager.setDefaultValues() 645 // is improved. 646 loadsImagesAutomatically = true; 647 javaScriptEnabled = true; 648 pluginState = WebSettings.PluginState.ON; 649 javaScriptCanOpenWindowsAutomatically = false; 650 showSecurityWarnings = true; 651 rememberPasswords = true; 652 saveFormData = true; 653 autoFillEnabled = false; 654 openInBackground = false; 655 autoFitPage = true; 656 landscapeOnly = false; 657 loadsPageInOverviewMode = true; 658 showDebugSettings = false; 659 // HTML5 API flags 660 appCacheEnabled = true; 661 databaseEnabled = true; 662 domStorageEnabled = true; 663 geolocationEnabled = true; 664 workersEnabled = true; // only affects V8. JSC does not have a similar setting 665 } 666} 667