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