Cary Clark | f2407c6 | 2009-09-04 12:25:10 -0400 | [diff] [blame] | 1 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 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 | |
| 18 | package com.android.browser; |
| 19 | |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 20 | import com.android.browser.homepages.HomeProvider; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 21 | import com.android.browser.search.SearchEngine; |
| 22 | import com.android.browser.search.SearchEngines; |
| 23 | |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 27 | import android.content.SharedPreferences; |
| 28 | import android.content.SharedPreferences.Editor; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 29 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 30 | import android.database.Cursor; |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 31 | import android.net.Uri; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 32 | import android.os.AsyncTask; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 33 | import android.os.Message; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 34 | import android.preference.PreferenceManager; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 35 | import android.provider.Browser; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 36 | import android.util.Log; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 37 | import android.webkit.CookieManager; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 38 | import android.webkit.GeolocationPermissions; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 39 | import android.webkit.WebIconDatabase; |
| 40 | import android.webkit.WebSettings; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 41 | import android.webkit.WebSettings.AutoFillProfile; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 42 | import android.webkit.WebStorage; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 43 | import android.webkit.WebView; |
| 44 | import android.webkit.WebViewDatabase; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 45 | |
| 46 | import java.util.HashMap; |
| 47 | import java.util.Observable; |
| 48 | |
| 49 | /* |
| 50 | * Package level class for storing various WebView and Browser settings. To use |
| 51 | * this class: |
| 52 | * BrowserSettings s = BrowserSettings.getInstance(); |
| 53 | * s.addObserver(webView.getSettings()); |
| 54 | * s.loadFromDb(context); // Only needed on app startup |
| 55 | * s.javaScriptEnabled = true; |
| 56 | * ... // set any other settings |
| 57 | * s.update(); // this will update all the observers |
| 58 | * |
| 59 | * To remove an observer: |
| 60 | * s.deleteObserver(webView.getSettings()); |
| 61 | */ |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 62 | public class BrowserSettings extends Observable implements OnSharedPreferenceChangeListener { |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 63 | // Private variables for settings |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 64 | // NOTE: these defaults need to be kept in sync with the XML |
| 65 | // until the performance of PreferenceManager.setDefaultValues() |
| 66 | // is improved. |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 67 | // Note: boolean variables are set inside reset function. |
| 68 | private boolean loadsImagesAutomatically; |
| 69 | private boolean javaScriptEnabled; |
Patrick Scott | e536b33 | 2010-03-22 10:19:32 -0400 | [diff] [blame] | 70 | private WebSettings.PluginState pluginState; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 71 | private boolean javaScriptCanOpenWindowsAutomatically; |
| 72 | private boolean showSecurityWarnings; |
| 73 | private boolean rememberPasswords; |
| 74 | private boolean saveFormData; |
Ben Murdoch | ce549fc | 2010-09-09 10:28:08 +0100 | [diff] [blame] | 75 | private boolean autoFillEnabled; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 76 | private boolean openInBackground; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 77 | private String defaultTextEncodingName; |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 78 | private String homeUrl = ""; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 79 | private SearchEngine searchEngine; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 80 | private boolean autoFitPage; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 81 | private boolean loadsPageInOverviewMode; |
| 82 | private boolean showDebugSettings; |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 83 | // HTML5 API flags |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 84 | private boolean appCacheEnabled; |
| 85 | private boolean databaseEnabled; |
| 86 | private boolean domStorageEnabled; |
| 87 | private boolean geolocationEnabled; |
| 88 | private boolean workersEnabled; // only affects V8. JSC does not have a similar setting |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 89 | // HTML5 API configuration params |
| 90 | private long appCacheMaxSize = Long.MAX_VALUE; |
| 91 | private String appCachePath; // default value set in loadFromDb(). |
| 92 | private String databasePath; // default value set in loadFromDb() |
Steve Block | 5029cf0 | 2009-08-21 13:16:58 +0100 | [diff] [blame] | 93 | private String geolocationDatabasePath; // default value set in loadFromDb() |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 94 | private WebStorageSizeManager webStorageSizeManager; |
Patrick Scott | 539e2ec | 2011-01-13 11:27:38 -0500 | [diff] [blame] | 95 | // Autologin settings |
| 96 | private boolean autoLoginEnabled; |
| 97 | private String autoLoginAccount; |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 98 | |
| 99 | private String jsFlags = ""; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 100 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 101 | private final static String TAG = "BrowserSettings"; |
| 102 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 103 | // Development settings |
| 104 | public WebSettings.LayoutAlgorithm layoutAlgorithm = |
| 105 | WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 106 | private boolean useWideViewPort = true; |
| 107 | private int userAgent = 0; |
| 108 | private boolean tracing = false; |
| 109 | private boolean lightTouch = false; |
| 110 | private boolean navDump = false; |
Derek Sollenberger | 8de8285 | 2010-11-18 19:51:50 -0500 | [diff] [blame] | 111 | private boolean hardwareAccelerated = true; |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 112 | private boolean showVisualIndicator = false; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 113 | // Lab settings |
| 114 | private boolean quickControls = false; |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 115 | private boolean useMostVisitedHomepage = false; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 116 | private boolean useInstant = false; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 117 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 118 | // By default the error console is shown once the user navigates to about:debug. |
| 119 | // The setting can be then toggled from the settings menu. |
| 120 | private boolean showConsole = true; |
| 121 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 122 | // Private preconfigured values |
Shimeng (Simon) Wang | b4fb25c | 2010-07-13 15:18:10 -0700 | [diff] [blame] | 123 | private static int minimumFontSize = 1; |
| 124 | private static int minimumLogicalFontSize = 1; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 125 | private static int defaultFontSize = 16; |
| 126 | private static int defaultFixedFontSize = 13; |
| 127 | private static WebSettings.TextSize textSize = |
| 128 | WebSettings.TextSize.NORMAL; |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 129 | private static WebSettings.ZoomDensity zoomDensity = |
| 130 | WebSettings.ZoomDensity.MEDIUM; |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 131 | private static int pageCacheCapacity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 132 | |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 133 | |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 134 | private AutoFillProfile autoFillProfile; |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 135 | // Default to zero. In the case no profile is set up, the initial |
| 136 | // value will come from the AutoFillSettingsFragment when the user |
| 137 | // creates a profile. Otherwise, we'll read the ID of the last used |
| 138 | // profile from the prefs db. |
| 139 | private int autoFillActiveProfileId; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 140 | private static final int NO_AUTOFILL_PROFILE_SET = 0; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 141 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 142 | // Preference keys that are used outside this class |
| 143 | public final static String PREF_CLEAR_CACHE = "privacy_clear_cache"; |
| 144 | public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies"; |
| 145 | public final static String PREF_CLEAR_HISTORY = "privacy_clear_history"; |
| 146 | public final static String PREF_HOMEPAGE = "homepage"; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 147 | public final static String PREF_SEARCH_ENGINE = "search_engine"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 148 | public final static String PREF_CLEAR_FORM_DATA = |
| 149 | "privacy_clear_form_data"; |
| 150 | public final static String PREF_CLEAR_PASSWORDS = |
| 151 | "privacy_clear_passwords"; |
| 152 | public final static String PREF_EXTRAS_RESET_DEFAULTS = |
| 153 | "reset_default_preferences"; |
| 154 | public final static String PREF_DEBUG_SETTINGS = "debug_menu"; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 155 | public final static String PREF_WEBSITE_SETTINGS = "website_settings"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 156 | public final static String PREF_TEXT_SIZE = "text_size"; |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 157 | public final static String PREF_DEFAULT_ZOOM = "default_zoom"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 158 | public final static String PREF_DEFAULT_TEXT_ENCODING = |
| 159 | "default_text_encoding"; |
Steve Block | c6f577f | 2009-08-20 18:11:08 +0100 | [diff] [blame] | 160 | public final static String PREF_CLEAR_GEOLOCATION_ACCESS = |
| 161 | "privacy_clear_geolocation_access"; |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 162 | public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled"; |
| 163 | public final static String PREF_AUTOFILL_PROFILE = "autofill_profile"; |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 164 | public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 165 | public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel"; |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 166 | public final static String PREF_VISUAL_INDICATOR = "enable_visual_indicator"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 167 | public final static String PREF_USER_AGENT = "user_agent"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 168 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 169 | public final static String PREF_QUICK_CONTROLS = "enable_quick_controls"; |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 170 | public final static String PREF_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage"; |
Patrick Scott | 539e2ec | 2011-01-13 11:27:38 -0500 | [diff] [blame] | 171 | public final static String PREF_AUTOLOGIN = "enable_autologin"; |
| 172 | public final static String PREF_AUTOLOGIN_ACCOUNT = "autologin_account"; |
John Reck | 282431b | 2011-01-20 17:38:37 -0800 | [diff] [blame] | 173 | public final static String PREF_PLUGIN_STATE = "plugin_state"; |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 174 | public final static String PREF_USE_INSTANT = "use_instant_search"; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 175 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 176 | private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " + |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 177 | "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " + |
| 178 | "like Gecko) Version/5.0 Safari/533.16"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 179 | |
| 180 | private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 181 | "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " + |
| 182 | "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; |
| 183 | |
| 184 | private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + |
| 185 | "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " + |
| 186 | "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"; |
| 187 | |
| 188 | private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
| 189 | "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + |
| 190 | "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 191 | |
| 192 | // Value to truncate strings when adding them to a TextView within |
| 193 | // a ListView |
| 194 | public final static int MAX_TEXTVIEW_LEN = 80; |
| 195 | |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 196 | public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider"; |
| 197 | |
| 198 | public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/"); |
| 199 | |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 200 | // Set to true to enable some of the about:debug options |
John Reck | 9eed0ef | 2011-01-11 17:11:37 -0800 | [diff] [blame] | 201 | public static final boolean DEV_BUILD = false; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 202 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 203 | private Controller mController; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 204 | |
| 205 | // Single instance of the BrowserSettings for use in the Browser app. |
| 206 | private static BrowserSettings sSingleton; |
| 207 | |
| 208 | // Private map of WebSettings to Observer objects used when deleting an |
| 209 | // observer. |
| 210 | private HashMap<WebSettings,Observer> mWebSettingsToObservers = |
| 211 | new HashMap<WebSettings,Observer>(); |
| 212 | |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 213 | private boolean mLoadFromDbComplete; |
| 214 | |
| 215 | public void waitForLoadFromDbToComplete() { |
| 216 | synchronized (sSingleton) { |
| 217 | while (!mLoadFromDbComplete) { |
| 218 | try { |
| 219 | sSingleton.wait(); |
| 220 | } catch (InterruptedException e) { } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 225 | /* |
| 226 | * An observer wrapper for updating a WebSettings object with the new |
| 227 | * settings after a call to BrowserSettings.update(). |
| 228 | */ |
| 229 | static class Observer implements java.util.Observer { |
| 230 | // Private WebSettings object that will be updated. |
| 231 | private WebSettings mSettings; |
| 232 | |
| 233 | Observer(WebSettings w) { |
| 234 | mSettings = w; |
| 235 | } |
| 236 | |
| 237 | public void update(Observable o, Object arg) { |
| 238 | BrowserSettings b = (BrowserSettings)o; |
| 239 | WebSettings s = mSettings; |
| 240 | |
| 241 | s.setLayoutAlgorithm(b.layoutAlgorithm); |
| 242 | if (b.userAgent == 0) { |
| 243 | // use the default ua string |
| 244 | s.setUserAgentString(null); |
| 245 | } else if (b.userAgent == 1) { |
| 246 | s.setUserAgentString(DESKTOP_USERAGENT); |
| 247 | } else if (b.userAgent == 2) { |
| 248 | s.setUserAgentString(IPHONE_USERAGENT); |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 249 | } else if (b.userAgent == 3) { |
| 250 | s.setUserAgentString(IPAD_USERAGENT); |
| 251 | } else if (b.userAgent == 4) { |
| 252 | s.setUserAgentString(FROYO_USERAGENT); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 253 | } |
| 254 | s.setUseWideViewPort(b.useWideViewPort); |
| 255 | s.setLoadsImagesAutomatically(b.loadsImagesAutomatically); |
| 256 | s.setJavaScriptEnabled(b.javaScriptEnabled); |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 257 | s.setShowVisualIndicator(b.showVisualIndicator); |
Patrick Scott | e536b33 | 2010-03-22 10:19:32 -0400 | [diff] [blame] | 258 | s.setPluginState(b.pluginState); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 259 | s.setJavaScriptCanOpenWindowsAutomatically( |
| 260 | b.javaScriptCanOpenWindowsAutomatically); |
| 261 | s.setDefaultTextEncodingName(b.defaultTextEncodingName); |
| 262 | s.setMinimumFontSize(b.minimumFontSize); |
| 263 | s.setMinimumLogicalFontSize(b.minimumLogicalFontSize); |
| 264 | s.setDefaultFontSize(b.defaultFontSize); |
| 265 | s.setDefaultFixedFontSize(b.defaultFixedFontSize); |
| 266 | s.setNavDump(b.navDump); |
| 267 | s.setTextSize(b.textSize); |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 268 | s.setDefaultZoom(b.zoomDensity); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 269 | s.setLightTouchEnabled(b.lightTouch); |
| 270 | s.setSaveFormData(b.saveFormData); |
Ben Murdoch | ce549fc | 2010-09-09 10:28:08 +0100 | [diff] [blame] | 271 | s.setAutoFillEnabled(b.autoFillEnabled); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 272 | s.setSavePassword(b.rememberPasswords); |
Grace Kloba | 5b4b8f1 | 2009-08-05 17:19:17 -0700 | [diff] [blame] | 273 | s.setLoadWithOverviewMode(b.loadsPageInOverviewMode); |
Grace Kloba | 7956503 | 2009-11-24 14:23:39 -0800 | [diff] [blame] | 274 | s.setPageCacheCapacity(pageCacheCapacity); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 275 | |
| 276 | // WebView inside Browser doesn't want initial focus to be set. |
| 277 | s.setNeedInitialFocus(false); |
| 278 | // Browser supports multiple windows |
| 279 | s.setSupportMultipleWindows(true); |
Grace Kloba | 61fc77c | 2010-06-22 09:57:33 -0700 | [diff] [blame] | 280 | // enable smooth transition for better performance during panning or |
| 281 | // zooming |
| 282 | s.setEnableSmoothTransition(true); |
Patrick Scott | b92bbb4 | 2011-01-05 11:38:58 -0500 | [diff] [blame] | 283 | // disable content url access |
| 284 | s.setAllowContentAccess(false); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 285 | |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 286 | // HTML5 API flags |
| 287 | s.setAppCacheEnabled(b.appCacheEnabled); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 288 | s.setDatabaseEnabled(b.databaseEnabled); |
Ben Murdoch | 734a066 | 2009-06-02 19:11:52 +0100 | [diff] [blame] | 289 | s.setDomStorageEnabled(b.domStorageEnabled); |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 290 | s.setWorkersEnabled(b.workersEnabled); // This only affects V8. |
Steve Block | 97b0802 | 2009-08-21 10:26:25 +0100 | [diff] [blame] | 291 | s.setGeolocationEnabled(b.geolocationEnabled); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 292 | |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 293 | // HTML5 configuration parameters. |
Andrei Popescu | 20634ce | 2009-07-22 16:46:55 +0100 | [diff] [blame] | 294 | s.setAppCacheMaxSize(b.appCacheMaxSize); |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 295 | s.setAppCachePath(b.appCachePath); |
| 296 | s.setDatabasePath(b.databasePath); |
Steve Block | 5029cf0 | 2009-08-21 13:16:58 +0100 | [diff] [blame] | 297 | s.setGeolocationDatabasePath(b.geolocationDatabasePath); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 298 | |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 299 | // Active AutoFill profile data. |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 300 | s.setAutoFillProfile(b.autoFillProfile); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 301 | |
Shimeng (Simon) Wang | 161974f | 2010-03-09 14:30:07 -0800 | [diff] [blame] | 302 | b.updateTabControlSettings(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | /** |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 307 | * Load settings from the browser app's database. It is performed in |
| 308 | * an AsyncTask as it involves plenty of slow disk IO. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 309 | * NOTE: Strings used for the preferences must match those specified |
Jeff Hamilton | 175ab30 | 2010-10-04 12:53:49 -0500 | [diff] [blame] | 310 | * in the various preference XML files. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 311 | * @param ctx A Context object used to query the browser's settings |
| 312 | * database. If the database exists, the saved settings will be |
| 313 | * stored in this BrowserSettings object. This will update all |
| 314 | * observers of this object. |
| 315 | */ |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 316 | public void asyncLoadFromDb(final Context ctx) { |
| 317 | mLoadFromDbComplete = false; |
| 318 | // Run the initial settings load in an AsyncTask as it hits the |
| 319 | // disk multiple times through SharedPreferences and SQLite. We |
| 320 | // need to be certain though that this has completed before we start |
| 321 | // to load pages though, so in the worst case we will block waiting |
| 322 | // for it to finish in BrowserActivity.onCreate(). |
| 323 | new LoadFromDbTask(ctx).execute(); |
| 324 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 325 | |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 326 | private class LoadFromDbTask extends AsyncTask<Void, Void, Void> { |
| 327 | private Context mContext; |
| 328 | |
| 329 | public LoadFromDbTask(Context context) { |
| 330 | mContext = context; |
Shimeng (Simon) Wang | e83e906 | 2010-03-29 16:13:09 -0700 | [diff] [blame] | 331 | } |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 332 | |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 333 | protected Void doInBackground(Void... unused) { |
| 334 | SharedPreferences p = |
| 335 | PreferenceManager.getDefaultSharedPreferences(mContext); |
| 336 | // Set the default value for the Application Caches path. |
| 337 | appCachePath = mContext.getDir("appcache", 0).getPath(); |
| 338 | // Determine the maximum size of the application cache. |
| 339 | webStorageSizeManager = new WebStorageSizeManager( |
| 340 | mContext, |
| 341 | new WebStorageSizeManager.StatFsDiskInfo(appCachePath), |
| 342 | new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath)); |
| 343 | appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); |
| 344 | // Set the default value for the Database path. |
| 345 | databasePath = mContext.getDir("databases", 0).getPath(); |
| 346 | // Set the default value for the Geolocation database path. |
| 347 | geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath(); |
| 348 | |
John Reck | ef07426 | 2010-12-02 16:09:14 -0800 | [diff] [blame] | 349 | if (p.getString(PREF_HOMEPAGE, null) == null) { |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 350 | // No home page preferences is set, set it to default. |
| 351 | setHomePage(mContext, getFactoryResetHomeUrl(mContext)); |
| 352 | } |
| 353 | |
| 354 | // the cost of one cached page is ~3M (measured using nytimes.com). For |
| 355 | // low end devices, we only cache one page. For high end devices, we try |
| 356 | // to cache more pages, currently choose 5. |
| 357 | ActivityManager am = (ActivityManager) mContext |
| 358 | .getSystemService(Context.ACTIVITY_SERVICE); |
| 359 | if (am.getMemoryClass() > 16) { |
| 360 | pageCacheCapacity = 5; |
| 361 | } else { |
| 362 | pageCacheCapacity = 1; |
| 363 | } |
| 364 | |
| 365 | // Read the last active AutoFill profile id. |
| 366 | autoFillActiveProfileId = p.getInt( |
| 367 | PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId); |
| 368 | |
| 369 | // Load the autofill profile data from the database. We use a database separate |
| 370 | // to the browser preference DB to make it easier to support multiple profiles |
| 371 | // and switching between them. |
| 372 | AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext); |
| 373 | Cursor c = autoFillDb.getProfile(autoFillActiveProfileId); |
| 374 | |
| 375 | if (c.getCount() > 0) { |
| 376 | c.moveToFirst(); |
| 377 | |
| 378 | String fullName = c.getString(c.getColumnIndex( |
| 379 | AutoFillProfileDatabase.Profiles.FULL_NAME)); |
| 380 | String email = c.getString(c.getColumnIndex( |
| 381 | AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS)); |
| 382 | String company = c.getString(c.getColumnIndex( |
| 383 | AutoFillProfileDatabase.Profiles.COMPANY_NAME)); |
| 384 | String addressLine1 = c.getString(c.getColumnIndex( |
| 385 | AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1)); |
| 386 | String addressLine2 = c.getString(c.getColumnIndex( |
| 387 | AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2)); |
| 388 | String city = c.getString(c.getColumnIndex( |
| 389 | AutoFillProfileDatabase.Profiles.CITY)); |
| 390 | String state = c.getString(c.getColumnIndex( |
| 391 | AutoFillProfileDatabase.Profiles.STATE)); |
| 392 | String zip = c.getString(c.getColumnIndex( |
| 393 | AutoFillProfileDatabase.Profiles.ZIP_CODE)); |
| 394 | String country = c.getString(c.getColumnIndex( |
| 395 | AutoFillProfileDatabase.Profiles.COUNTRY)); |
| 396 | String phone = c.getString(c.getColumnIndex( |
| 397 | AutoFillProfileDatabase.Profiles.PHONE_NUMBER)); |
| 398 | autoFillProfile = new AutoFillProfile(autoFillActiveProfileId, |
| 399 | fullName, email, company, addressLine1, addressLine2, city, |
| 400 | state, zip, country, phone); |
| 401 | } |
| 402 | c.close(); |
| 403 | autoFillDb.close(); |
| 404 | |
| 405 | // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep |
| 406 | // the defaults in sync |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 407 | p.registerOnSharedPreferenceChangeListener(BrowserSettings.this); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 408 | syncSharedPreferences(mContext, p); |
| 409 | |
| 410 | synchronized (sSingleton) { |
| 411 | mLoadFromDbComplete = true; |
| 412 | sSingleton.notify(); |
| 413 | } |
| 414 | return null; |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 415 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 418 | private void updateSearchEngine(Context ctx, String searchEngineName, boolean force) { |
| 419 | if (force || searchEngine == null || |
| 420 | !searchEngine.getName().equals(searchEngineName)) { |
| 421 | if (searchEngine != null) { |
| 422 | if (searchEngine.supportsVoiceSearch()) { |
| 423 | // One or more tabs could have been in voice search mode. |
| 424 | // Clear it, since the new SearchEngine may not support |
| 425 | // it, or may handle it differently. |
| 426 | for (int i = 0; i < mController.getTabControl().getTabCount(); i++) { |
| 427 | mController.getTabControl().getTab(i).revertVoiceSearchMode(); |
| 428 | } |
| 429 | } |
| 430 | searchEngine.close(); |
| 431 | } |
| 432 | searchEngine = SearchEngines.get(ctx, searchEngineName); |
| 433 | |
| 434 | if (mController != null && (searchEngine instanceof InstantSearchEngine)) { |
| 435 | ((InstantSearchEngine) searchEngine).setController(mController); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 440 | /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) { |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 442 | homeUrl = |
| 443 | p.getString(PREF_HOMEPAGE, homeUrl); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 444 | |
| 445 | useInstant = p.getBoolean(PREF_USE_INSTANT, useInstant); |
Leon Scroggins III | 3130660 | 2010-09-17 11:10:29 -0400 | [diff] [blame] | 446 | String searchEngineName = p.getString(PREF_SEARCH_ENGINE, |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 447 | SearchEngine.GOOGLE); |
| 448 | updateSearchEngine(ctx, searchEngineName, false); |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 449 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 450 | loadsImagesAutomatically = p.getBoolean("load_images", |
| 451 | loadsImagesAutomatically); |
| 452 | javaScriptEnabled = p.getBoolean("enable_javascript", |
| 453 | javaScriptEnabled); |
Patrick Scott | e536b33 | 2010-03-22 10:19:32 -0400 | [diff] [blame] | 454 | pluginState = WebSettings.PluginState.valueOf( |
John Reck | 282431b | 2011-01-20 17:38:37 -0800 | [diff] [blame] | 455 | p.getString(PREF_PLUGIN_STATE, pluginState.name())); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 456 | javaScriptCanOpenWindowsAutomatically = !p.getBoolean( |
| 457 | "block_popup_windows", |
| 458 | !javaScriptCanOpenWindowsAutomatically); |
| 459 | showSecurityWarnings = p.getBoolean("show_security_warnings", |
| 460 | showSecurityWarnings); |
| 461 | rememberPasswords = p.getBoolean("remember_passwords", |
| 462 | rememberPasswords); |
| 463 | saveFormData = p.getBoolean("save_formdata", |
| 464 | saveFormData); |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 465 | autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 466 | boolean accept_cookies = p.getBoolean("accept_cookies", |
| 467 | CookieManager.getInstance().acceptCookie()); |
| 468 | CookieManager.getInstance().setAcceptCookie(accept_cookies); |
| 469 | openInBackground = p.getBoolean("open_in_background", openInBackground); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 470 | textSize = WebSettings.TextSize.valueOf( |
| 471 | p.getString(PREF_TEXT_SIZE, textSize.name())); |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 472 | zoomDensity = WebSettings.ZoomDensity.valueOf( |
| 473 | p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name())); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 474 | autoFitPage = p.getBoolean("autofit_pages", autoFitPage); |
Grace Kloba | 5b4b8f1 | 2009-08-05 17:19:17 -0700 | [diff] [blame] | 475 | loadsPageInOverviewMode = p.getBoolean("load_page", |
| 476 | loadsPageInOverviewMode); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 477 | useWideViewPort = true; // use wide view port for either setting |
| 478 | if (autoFitPage) { |
| 479 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 480 | } else { |
| 481 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; |
| 482 | } |
| 483 | defaultTextEncodingName = |
| 484 | p.getString(PREF_DEFAULT_TEXT_ENCODING, |
| 485 | defaultTextEncodingName); |
| 486 | |
| 487 | showDebugSettings = |
| 488 | p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings); |
| 489 | // Debug menu items have precidence if the menu is visible |
| 490 | if (showDebugSettings) { |
| 491 | boolean small_screen = p.getBoolean("small_screen", |
| 492 | layoutAlgorithm == |
| 493 | WebSettings.LayoutAlgorithm.SINGLE_COLUMN); |
| 494 | if (small_screen) { |
| 495 | layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN; |
| 496 | } else { |
| 497 | boolean normal_layout = p.getBoolean("normal_layout", |
| 498 | layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL); |
| 499 | if (normal_layout) { |
| 500 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; |
| 501 | } else { |
| 502 | layoutAlgorithm = |
| 503 | WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 504 | } |
| 505 | } |
| 506 | useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort); |
| 507 | tracing = p.getBoolean("enable_tracing", tracing); |
| 508 | lightTouch = p.getBoolean("enable_light_touch", lightTouch); |
| 509 | navDump = p.getBoolean("enable_nav_dump", navDump); |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 510 | showVisualIndicator = p.getBoolean(PREF_VISUAL_INDICATOR, showVisualIndicator); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 511 | } |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame] | 512 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 513 | quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls); |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 514 | useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 515 | |
John Reck | 3db2e07 | 2011-01-24 14:57:18 -0800 | [diff] [blame] | 516 | // Only set these if this is a dev build or debug is enabled |
| 517 | if (DEV_BUILD || showDebugSettings()) { |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 518 | userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0")); |
| 519 | hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated); |
| 520 | } |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame] | 521 | |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 522 | // JS flags is loaded from DB even if showDebugSettings is false, |
| 523 | // so that it can be set once and be effective all the time. |
| 524 | jsFlags = p.getString("js_engine_flags", ""); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 525 | |
| 526 | // Read the setting for showing/hiding the JS Console always so that should the |
| 527 | // user enable debug settings, we already know if we should show the console. |
| 528 | // The user will never see the console unless they navigate to about:debug, |
| 529 | // regardless of the setting we read here. This setting is only used after debug |
| 530 | // is enabled. |
| 531 | showConsole = p.getBoolean("javascript_console", showConsole); |
Grace Kloba | d9ee139 | 2009-07-20 11:53:33 -0700 | [diff] [blame] | 532 | |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 533 | // HTML5 API flags |
| 534 | appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled); |
| 535 | databaseEnabled = p.getBoolean("enable_database", databaseEnabled); |
| 536 | domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 537 | geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled); |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 538 | workersEnabled = p.getBoolean("enable_workers", workersEnabled); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 539 | |
Patrick Scott | 539e2ec | 2011-01-13 11:27:38 -0500 | [diff] [blame] | 540 | // Autologin account settings. The account preference may be null until |
| 541 | // the user explicitly changes the account in the settings. |
| 542 | autoLoginEnabled = p.getBoolean(PREF_AUTOLOGIN, autoLoginEnabled); |
| 543 | autoLoginAccount = p.getString(PREF_AUTOLOGIN_ACCOUNT, autoLoginAccount); |
| 544 | |
Grace Kloba | d9ee139 | 2009-07-20 11:53:33 -0700 | [diff] [blame] | 545 | update(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 546 | } |
| 547 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 548 | public String getHomePage() { |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 549 | if (useMostVisitedHomepage) { |
| 550 | return HomeProvider.MOST_VISITED; |
| 551 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 552 | return homeUrl; |
| 553 | } |
| 554 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 555 | public SearchEngine getSearchEngine() { |
| 556 | return searchEngine; |
| 557 | } |
| 558 | |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 559 | public String getJsFlags() { |
| 560 | return jsFlags; |
| 561 | } |
| 562 | |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 563 | public WebStorageSizeManager getWebStorageSizeManager() { |
| 564 | return webStorageSizeManager; |
| 565 | } |
| 566 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 567 | public void setHomePage(Context context, String url) { |
| 568 | Editor ed = PreferenceManager. |
| 569 | getDefaultSharedPreferences(context).edit(); |
| 570 | ed.putString(PREF_HOMEPAGE, url); |
Brad Fitzpatrick | 1a6e0e8 | 2010-09-01 16:29:03 -0700 | [diff] [blame] | 571 | ed.apply(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 572 | homeUrl = url; |
| 573 | } |
| 574 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 575 | public WebSettings.TextSize getTextSize() { |
| 576 | return textSize; |
| 577 | } |
| 578 | |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 579 | public WebSettings.ZoomDensity getDefaultZoom() { |
| 580 | return zoomDensity; |
| 581 | } |
| 582 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 583 | public boolean openInBackground() { |
| 584 | return openInBackground; |
| 585 | } |
| 586 | |
| 587 | public boolean showSecurityWarnings() { |
| 588 | return showSecurityWarnings; |
| 589 | } |
| 590 | |
| 591 | public boolean isTracing() { |
| 592 | return tracing; |
| 593 | } |
| 594 | |
| 595 | public boolean isLightTouch() { |
| 596 | return lightTouch; |
| 597 | } |
| 598 | |
| 599 | public boolean isNavDump() { |
| 600 | return navDump; |
| 601 | } |
| 602 | |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame] | 603 | public boolean isHardwareAccelerated() { |
| 604 | return hardwareAccelerated; |
| 605 | } |
| 606 | |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 607 | public boolean showVisualIndicator() { |
| 608 | return showVisualIndicator; |
| 609 | } |
| 610 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 611 | public boolean useQuickControls() { |
| 612 | return quickControls; |
| 613 | } |
| 614 | |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 615 | public boolean useMostVisitedHomepage() { |
| 616 | return useMostVisitedHomepage; |
| 617 | } |
| 618 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 619 | public boolean useInstant() { |
| 620 | return useInstant; |
| 621 | } |
| 622 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 623 | public boolean showDebugSettings() { |
| 624 | return showDebugSettings; |
| 625 | } |
| 626 | |
John Reck | 3db2e07 | 2011-01-24 14:57:18 -0800 | [diff] [blame] | 627 | public void toggleDebugSettings(Context context) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 628 | showDebugSettings = !showDebugSettings; |
| 629 | navDump = showDebugSettings; |
John Reck | 3db2e07 | 2011-01-24 14:57:18 -0800 | [diff] [blame] | 630 | syncSharedPreferences(context, |
| 631 | PreferenceManager.getDefaultSharedPreferences(context)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 632 | update(); |
| 633 | } |
| 634 | |
Patrick Scott | 539e2ec | 2011-01-13 11:27:38 -0500 | [diff] [blame] | 635 | public boolean isAutoLoginEnabled() { |
| 636 | return autoLoginEnabled; |
| 637 | } |
| 638 | |
| 639 | public String getAutoLoginAccount(Context context) { |
| 640 | // Each time we attempt to get the account, we need to verify that the |
| 641 | // account is still valid. |
| 642 | return GoogleAccountLogin.validateAccount(context, autoLoginAccount); |
| 643 | } |
| 644 | |
| 645 | public void setAutoLoginAccount(Context context, String name) { |
| 646 | Editor ed = PreferenceManager. |
| 647 | getDefaultSharedPreferences(context).edit(); |
| 648 | ed.putString(PREF_AUTOLOGIN_ACCOUNT, name); |
| 649 | ed.apply(); |
| 650 | autoLoginAccount = name; |
| 651 | } |
| 652 | |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 653 | public void setAutoLoginEnabled(Context context, boolean enable) { |
| 654 | Editor ed = PreferenceManager. |
| 655 | getDefaultSharedPreferences(context).edit(); |
| 656 | ed.putBoolean(PREF_AUTOLOGIN, enable); |
| 657 | ed.apply(); |
| 658 | autoLoginEnabled = enable; |
| 659 | } |
| 660 | |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 661 | public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) { |
| 662 | if (profile != null) { |
| 663 | setActiveAutoFillProfileId(ctx, profile.getUniqueId()); |
| 664 | // Update the AutoFill DB with the new profile. |
| 665 | new SaveProfileToDbTask(ctx, msg).execute(profile); |
| 666 | } else { |
| 667 | // Delete the current profile. |
Ben Murdoch | e8a2833 | 2010-11-17 14:16:21 +0000 | [diff] [blame] | 668 | if (autoFillProfile != null) { |
| 669 | new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId()); |
| 670 | setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET); |
| 671 | } |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 672 | } |
| 673 | autoFillProfile = profile; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | public AutoFillProfile getAutoFillProfile() { |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 677 | return autoFillProfile; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 678 | } |
| 679 | |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 680 | private void setActiveAutoFillProfileId(Context context, int activeProfileId) { |
| 681 | autoFillActiveProfileId = activeProfileId; |
| 682 | Editor ed = PreferenceManager. |
| 683 | getDefaultSharedPreferences(context).edit(); |
| 684 | ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId); |
| 685 | ed.apply(); |
| 686 | } |
| 687 | |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 688 | /* package */ void disableAutoFill(Context ctx) { |
| 689 | autoFillEnabled = false; |
| 690 | Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit(); |
| 691 | ed.putBoolean(PREF_AUTOFILL_ENABLED, false); |
| 692 | ed.apply(); |
| 693 | } |
| 694 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 695 | /** |
| 696 | * Add a WebSettings object to the list of observers that will be updated |
| 697 | * when update() is called. |
| 698 | * |
| 699 | * @param s A WebSettings object that is strictly tied to the life of a |
| 700 | * WebView. |
| 701 | */ |
| 702 | public Observer addObserver(WebSettings s) { |
| 703 | Observer old = mWebSettingsToObservers.get(s); |
| 704 | if (old != null) { |
| 705 | super.deleteObserver(old); |
| 706 | } |
| 707 | Observer o = new Observer(s); |
| 708 | mWebSettingsToObservers.put(s, o); |
| 709 | super.addObserver(o); |
| 710 | return o; |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Delete the given WebSettings observer from the list of observers. |
| 715 | * @param s The WebSettings object to be deleted. |
| 716 | */ |
| 717 | public void deleteObserver(WebSettings s) { |
| 718 | Observer o = mWebSettingsToObservers.get(s); |
| 719 | if (o != null) { |
| 720 | mWebSettingsToObservers.remove(s); |
| 721 | super.deleteObserver(o); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | /* |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 726 | * Application level method for obtaining a single app instance of the |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 727 | * BrowserSettings. |
| 728 | */ |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 729 | public static BrowserSettings getInstance() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 730 | if (sSingleton == null ) { |
| 731 | sSingleton = new BrowserSettings(); |
| 732 | } |
| 733 | return sSingleton; |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * Package level method for associating the BrowserSettings with TabControl |
| 738 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 739 | /* package */void setController(Controller ctrl) { |
| 740 | mController = ctrl; |
Shimeng (Simon) Wang | 161974f | 2010-03-09 14:30:07 -0800 | [diff] [blame] | 741 | updateTabControlSettings(); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 742 | |
| 743 | if (mController != null && (searchEngine instanceof InstantSearchEngine)) { |
| 744 | ((InstantSearchEngine) searchEngine).setController(mController); |
| 745 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* |
| 749 | * Update all the observers of the object. |
| 750 | */ |
| 751 | /*package*/ void update() { |
| 752 | setChanged(); |
| 753 | notifyObservers(); |
| 754 | } |
| 755 | |
| 756 | /*package*/ void clearCache(Context context) { |
| 757 | WebIconDatabase.getInstance().removeAllIcons(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 758 | if (mController != null) { |
| 759 | WebView current = mController.getCurrentWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 760 | if (current != null) { |
| 761 | current.clearCache(true); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /*package*/ void clearCookies(Context context) { |
| 767 | CookieManager.getInstance().removeAllCookie(); |
| 768 | } |
| 769 | |
| 770 | /* package */void clearHistory(Context context) { |
| 771 | ContentResolver resolver = context.getContentResolver(); |
| 772 | Browser.clearHistory(resolver); |
| 773 | Browser.clearSearches(resolver); |
| 774 | } |
| 775 | |
| 776 | /* package */ void clearFormData(Context context) { |
| 777 | WebViewDatabase.getInstance(context).clearFormData(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 778 | if (mController!= null) { |
| 779 | WebView currentTopView = mController.getCurrentTopWebView(); |
Henrik Baard | 794dc72 | 2010-02-19 16:28:06 +0100 | [diff] [blame] | 780 | if (currentTopView != null) { |
| 781 | currentTopView.clearFormData(); |
| 782 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | /*package*/ void clearPasswords(Context context) { |
| 787 | WebViewDatabase db = WebViewDatabase.getInstance(context); |
| 788 | db.clearUsernamePassword(); |
| 789 | db.clearHttpAuthUsernamePassword(); |
| 790 | } |
| 791 | |
Shimeng (Simon) Wang | 161974f | 2010-03-09 14:30:07 -0800 | [diff] [blame] | 792 | private void updateTabControlSettings() { |
| 793 | // Enable/disable the error console. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 794 | mController.setShouldShowErrorConsole( |
Shimeng (Simon) Wang | 161974f | 2010-03-09 14:30:07 -0800 | [diff] [blame] | 795 | showDebugSettings && showConsole); |
Shimeng (Simon) Wang | 161974f | 2010-03-09 14:30:07 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 798 | /*package*/ void clearDatabases(Context context) { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 799 | WebStorage.getInstance().deleteAllData(); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /*package*/ void clearLocationAccess(Context context) { |
| 803 | GeolocationPermissions.getInstance().clearAll(); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 804 | } |
| 805 | |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 806 | /*package*/ void resetDefaultPreferences(Context ctx) { |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 807 | reset(); |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 808 | SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx); |
Brad Fitzpatrick | 1a6e0e8 | 2010-09-01 16:29:03 -0700 | [diff] [blame] | 809 | p.edit().clear().apply(); |
John Reck | 035a564 | 2010-12-21 18:51:27 -0800 | [diff] [blame] | 810 | PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true); |
| 811 | PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true); |
Jeff Hamilton | 462b8e8 | 2010-09-23 14:33:43 -0500 | [diff] [blame] | 812 | PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 813 | // reset homeUrl |
Grace Kloba | a3f90f0 | 2009-05-26 11:32:53 -0700 | [diff] [blame] | 814 | setHomePage(ctx, getFactoryResetHomeUrl(ctx)); |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 815 | // reset appcache max size |
| 816 | appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 817 | setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 818 | } |
| 819 | |
John Reck | 33bbb80 | 2010-10-26 17:13:42 -0700 | [diff] [blame] | 820 | /*package*/ static String getFactoryResetHomeUrl(Context context) { |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 821 | String url = context.getResources().getString(R.string.homepage_base); |
| 822 | if (url.indexOf("{CID}") != -1) { |
Patrick Scott | 4391469 | 2010-02-19 10:10:10 -0500 | [diff] [blame] | 823 | url = url.replace("{CID}", |
| 824 | BrowserProvider.getClientId(context.getContentResolver())); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 825 | } |
| 826 | return url; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 827 | } |
| 828 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 829 | // Private constructor that does nothing. |
| 830 | private BrowserSettings() { |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 831 | reset(); |
| 832 | } |
| 833 | |
| 834 | private void reset() { |
| 835 | // Private variables for settings |
| 836 | // NOTE: these defaults need to be kept in sync with the XML |
| 837 | // until the performance of PreferenceManager.setDefaultValues() |
| 838 | // is improved. |
| 839 | loadsImagesAutomatically = true; |
| 840 | javaScriptEnabled = true; |
Patrick Scott | e536b33 | 2010-03-22 10:19:32 -0400 | [diff] [blame] | 841 | pluginState = WebSettings.PluginState.ON; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 842 | javaScriptCanOpenWindowsAutomatically = false; |
| 843 | showSecurityWarnings = true; |
| 844 | rememberPasswords = true; |
| 845 | saveFormData = true; |
Ben Murdoch | dc62cb9 | 2010-11-23 15:11:29 +0000 | [diff] [blame] | 846 | autoFillEnabled = true; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 847 | openInBackground = false; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 848 | autoFitPage = true; |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 849 | loadsPageInOverviewMode = true; |
| 850 | showDebugSettings = false; |
| 851 | // HTML5 API flags |
| 852 | appCacheEnabled = true; |
| 853 | databaseEnabled = true; |
| 854 | domStorageEnabled = true; |
| 855 | geolocationEnabled = true; |
| 856 | workersEnabled = true; // only affects V8. JSC does not have a similar setting |
Patrick Scott | 539e2ec | 2011-01-13 11:27:38 -0500 | [diff] [blame] | 857 | // Autologin default is true. The account will be populated when |
| 858 | // reading from the DB as that is when a context is available. |
| 859 | autoLoginEnabled = true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 860 | } |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 861 | |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 862 | private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> { |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 863 | Context mContext; |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 864 | AutoFillProfileDatabase mAutoFillProfileDb; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 865 | Message mCompleteMessage; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 866 | |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 867 | public AutoFillProfileDbTask(Context ctx, Message msg) { |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 868 | mContext = ctx; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 869 | mCompleteMessage = msg; |
| 870 | } |
| 871 | |
| 872 | protected void onPostExecute(Void result) { |
| 873 | if (mCompleteMessage != null) { |
| 874 | mCompleteMessage.sendToTarget(); |
| 875 | } |
| 876 | mAutoFillProfileDb.close(); |
| 877 | } |
| 878 | |
| 879 | abstract protected Void doInBackground(T... values); |
| 880 | } |
| 881 | |
| 882 | |
| 883 | private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> { |
| 884 | public SaveProfileToDbTask(Context ctx, Message msg) { |
| 885 | super(ctx, msg); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | protected Void doInBackground(AutoFillProfile... values) { |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 889 | mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 890 | assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET; |
| 891 | AutoFillProfile newProfile = values[0]; |
| 892 | mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 893 | return null; |
| 894 | } |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 897 | private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> { |
| 898 | public DeleteProfileFromDbTask(Context ctx, Message msg) { |
| 899 | super(ctx, msg); |
| 900 | } |
| 901 | |
| 902 | protected Void doInBackground(Integer... values) { |
| 903 | mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext); |
| 904 | int id = values[0]; |
| 905 | assert id > 0; |
| 906 | mAutoFillProfileDb.dropProfile(id); |
| 907 | return null; |
| 908 | } |
| 909 | } |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 910 | |
| 911 | @Override |
| 912 | public void onSharedPreferenceChanged( |
| 913 | SharedPreferences p, String key) { |
| 914 | if (PREF_HARDWARE_ACCEL.equals(key)) { |
| 915 | hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated); |
Teng-Hui Zhu | 930ea22 | 2011-02-16 11:22:21 -0800 | [diff] [blame] | 916 | } else if (PREF_VISUAL_INDICATOR.equals(key)) { |
| 917 | showVisualIndicator = p.getBoolean(PREF_VISUAL_INDICATOR, showVisualIndicator); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 918 | } else if (PREF_USER_AGENT.equals(key)) { |
| 919 | userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0")); |
| 920 | update(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 921 | } else if (PREF_QUICK_CONTROLS.equals(key)) { |
| 922 | quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls); |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 923 | } else if (PREF_MOST_VISITED_HOMEPAGE.equals(key)) { |
| 924 | useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 925 | } else if (PREF_USE_INSTANT.equals(key)) { |
| 926 | useInstant = p.getBoolean(PREF_USE_INSTANT, useInstant); |
| 927 | updateSearchEngine(mController.getActivity(), SearchEngine.GOOGLE, true); |
| 928 | } else if (PREF_SEARCH_ENGINE.equals(key)) { |
| 929 | final String searchEngineName = p.getString(PREF_SEARCH_ENGINE, |
| 930 | SearchEngine.GOOGLE); |
| 931 | updateSearchEngine(mController.getActivity(), searchEngineName, false); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 932 | } |
| 933 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 934 | } |