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