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