The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 19 | import com.google.android.providers.GoogleSettings.Partner; |
| 20 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 21 | import android.content.ContentResolver; |
| 22 | import android.content.Context; |
| 23 | import android.content.pm.ActivityInfo; |
| 24 | import android.content.SharedPreferences; |
| 25 | import android.content.SharedPreferences.Editor; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 26 | import android.preference.PreferenceActivity; |
| 27 | import android.preference.PreferenceScreen; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 28 | import android.webkit.CookieManager; |
| 29 | import android.webkit.WebView; |
| 30 | import android.webkit.WebViewDatabase; |
| 31 | import android.webkit.WebIconDatabase; |
| 32 | import android.webkit.WebSettings; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 33 | import android.webkit.WebStorage; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 34 | import android.preference.PreferenceManager; |
| 35 | import android.provider.Browser; |
| 36 | |
| 37 | import java.util.HashMap; |
| 38 | import java.util.Observable; |
| 39 | |
| 40 | /* |
| 41 | * Package level class for storing various WebView and Browser settings. To use |
| 42 | * this class: |
| 43 | * BrowserSettings s = BrowserSettings.getInstance(); |
| 44 | * s.addObserver(webView.getSettings()); |
| 45 | * s.loadFromDb(context); // Only needed on app startup |
| 46 | * s.javaScriptEnabled = true; |
| 47 | * ... // set any other settings |
| 48 | * s.update(); // this will update all the observers |
| 49 | * |
| 50 | * To remove an observer: |
| 51 | * s.deleteObserver(webView.getSettings()); |
| 52 | */ |
| 53 | class BrowserSettings extends Observable { |
| 54 | |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 55 | // Private variables for settings |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 56 | // NOTE: these defaults need to be kept in sync with the XML |
| 57 | // until the performance of PreferenceManager.setDefaultValues() |
| 58 | // is improved. |
| 59 | private boolean loadsImagesAutomatically = true; |
| 60 | private boolean javaScriptEnabled = true; |
| 61 | private boolean pluginsEnabled = true; |
| 62 | private String pluginsPath; // default value set in loadFromDb(). |
| 63 | private boolean javaScriptCanOpenWindowsAutomatically = false; |
| 64 | private boolean showSecurityWarnings = true; |
| 65 | private boolean rememberPasswords = true; |
| 66 | private boolean saveFormData = true; |
| 67 | private boolean openInBackground = false; |
| 68 | private String defaultTextEncodingName; |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 69 | private String homeUrl = ""; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 70 | private boolean loginInitialized = false; |
| 71 | private boolean autoFitPage = true; |
Leon Scroggins | b0cd072 | 2009-03-31 14:31:22 -0700 | [diff] [blame] | 72 | private boolean landscapeOnly = false; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 73 | private boolean showDebugSettings = false; |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 74 | private String databasePath; // default value set in loadFromDb() |
| 75 | private boolean databaseEnabled = true; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 76 | private long webStorageDefaultQuota = 5 * 1024 * 1024; |
Andrei Popescu | 5151ac1 | 2009-04-17 10:43:07 +0100 | [diff] [blame] | 77 | // The Browser always enables Application Caches. |
| 78 | private boolean appCacheEnabled = true; |
| 79 | private String appCachePath; // default value set in loadFromDb(). |
Andrei Popescu | 20634ce | 2009-07-22 16:46:55 +0100 | [diff] [blame] | 80 | private long appCacheMaxSize = Long.MAX_VALUE; |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame^] | 81 | private WebStorageSizeManager webStorageSizeManager; |
Ben Murdoch | 734a066 | 2009-06-02 19:11:52 +0100 | [diff] [blame] | 82 | private boolean domStorageEnabled = true; |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 83 | private String jsFlags = ""; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 84 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 85 | private final static String TAG = "BrowserSettings"; |
| 86 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 87 | // Development settings |
| 88 | public WebSettings.LayoutAlgorithm layoutAlgorithm = |
| 89 | WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 90 | private boolean useWideViewPort = true; |
| 91 | private int userAgent = 0; |
| 92 | private boolean tracing = false; |
| 93 | private boolean lightTouch = false; |
| 94 | private boolean navDump = false; |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 95 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 96 | // By default the error console is shown once the user navigates to about:debug. |
| 97 | // The setting can be then toggled from the settings menu. |
| 98 | private boolean showConsole = true; |
| 99 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 100 | // Browser only settings |
| 101 | private boolean doFlick = false; |
| 102 | |
| 103 | // Private preconfigured values |
| 104 | private static int minimumFontSize = 8; |
| 105 | private static int minimumLogicalFontSize = 8; |
| 106 | private static int defaultFontSize = 16; |
| 107 | private static int defaultFixedFontSize = 13; |
| 108 | private static WebSettings.TextSize textSize = |
| 109 | WebSettings.TextSize.NORMAL; |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 110 | private static WebSettings.ZoomDensity zoomDensity = |
| 111 | WebSettings.ZoomDensity.MEDIUM; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 112 | |
| 113 | // Preference keys that are used outside this class |
| 114 | public final static String PREF_CLEAR_CACHE = "privacy_clear_cache"; |
| 115 | public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies"; |
| 116 | public final static String PREF_CLEAR_HISTORY = "privacy_clear_history"; |
| 117 | public final static String PREF_HOMEPAGE = "homepage"; |
| 118 | public final static String PREF_CLEAR_FORM_DATA = |
| 119 | "privacy_clear_form_data"; |
| 120 | public final static String PREF_CLEAR_PASSWORDS = |
| 121 | "privacy_clear_passwords"; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 122 | public final static String PREF_DEFAULT_QUOTA = |
| 123 | "webstorage_default_quota"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 124 | public final static String PREF_EXTRAS_RESET_DEFAULTS = |
| 125 | "reset_default_preferences"; |
| 126 | public final static String PREF_DEBUG_SETTINGS = "debug_menu"; |
| 127 | public final static String PREF_GEARS_SETTINGS = "gears_settings"; |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 128 | public final static String PREF_WEBSITE_SETTINGS = "website_settings"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 129 | public final static String PREF_TEXT_SIZE = "text_size"; |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 130 | public final static String PREF_DEFAULT_ZOOM = "default_zoom"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 131 | public final static String PREF_DEFAULT_TEXT_ENCODING = |
| 132 | "default_text_encoding"; |
| 133 | |
| 134 | private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " + |
Grace Kloba | a4fa6ee | 2009-06-26 00:34:46 -0700 | [diff] [blame] | 135 | "U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " + |
| 136 | "like Gecko) Version/4.0 Safari/530.17"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 137 | |
| 138 | private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + |
Grace Kloba | a4fa6ee | 2009-06-26 00:34:46 -0700 | [diff] [blame] | 139 | "CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 " + |
| 140 | "(KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 141 | |
| 142 | // Value to truncate strings when adding them to a TextView within |
| 143 | // a ListView |
| 144 | public final static int MAX_TEXTVIEW_LEN = 80; |
| 145 | |
| 146 | private TabControl mTabControl; |
| 147 | |
| 148 | // Single instance of the BrowserSettings for use in the Browser app. |
| 149 | private static BrowserSettings sSingleton; |
| 150 | |
| 151 | // Private map of WebSettings to Observer objects used when deleting an |
| 152 | // observer. |
| 153 | private HashMap<WebSettings,Observer> mWebSettingsToObservers = |
| 154 | new HashMap<WebSettings,Observer>(); |
| 155 | |
| 156 | /* |
| 157 | * An observer wrapper for updating a WebSettings object with the new |
| 158 | * settings after a call to BrowserSettings.update(). |
| 159 | */ |
| 160 | static class Observer implements java.util.Observer { |
| 161 | // Private WebSettings object that will be updated. |
| 162 | private WebSettings mSettings; |
| 163 | |
| 164 | Observer(WebSettings w) { |
| 165 | mSettings = w; |
| 166 | } |
| 167 | |
| 168 | public void update(Observable o, Object arg) { |
| 169 | BrowserSettings b = (BrowserSettings)o; |
| 170 | WebSettings s = mSettings; |
| 171 | |
| 172 | s.setLayoutAlgorithm(b.layoutAlgorithm); |
| 173 | if (b.userAgent == 0) { |
| 174 | // use the default ua string |
| 175 | s.setUserAgentString(null); |
| 176 | } else if (b.userAgent == 1) { |
| 177 | s.setUserAgentString(DESKTOP_USERAGENT); |
| 178 | } else if (b.userAgent == 2) { |
| 179 | s.setUserAgentString(IPHONE_USERAGENT); |
| 180 | } |
| 181 | s.setUseWideViewPort(b.useWideViewPort); |
| 182 | s.setLoadsImagesAutomatically(b.loadsImagesAutomatically); |
| 183 | s.setJavaScriptEnabled(b.javaScriptEnabled); |
| 184 | s.setPluginsEnabled(b.pluginsEnabled); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 185 | s.setJavaScriptCanOpenWindowsAutomatically( |
| 186 | b.javaScriptCanOpenWindowsAutomatically); |
| 187 | s.setDefaultTextEncodingName(b.defaultTextEncodingName); |
| 188 | s.setMinimumFontSize(b.minimumFontSize); |
| 189 | s.setMinimumLogicalFontSize(b.minimumLogicalFontSize); |
| 190 | s.setDefaultFontSize(b.defaultFontSize); |
| 191 | s.setDefaultFixedFontSize(b.defaultFixedFontSize); |
| 192 | s.setNavDump(b.navDump); |
| 193 | s.setTextSize(b.textSize); |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 194 | s.setDefaultZoom(b.zoomDensity); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 195 | s.setLightTouchEnabled(b.lightTouch); |
| 196 | s.setSaveFormData(b.saveFormData); |
| 197 | s.setSavePassword(b.rememberPasswords); |
| 198 | |
| 199 | // WebView inside Browser doesn't want initial focus to be set. |
| 200 | s.setNeedInitialFocus(false); |
| 201 | // Browser supports multiple windows |
| 202 | s.setSupportMultipleWindows(true); |
| 203 | // Turn off file access |
| 204 | s.setAllowFileAccess(false); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 205 | |
| 206 | s.setDatabasePath(b.databasePath); |
| 207 | s.setDatabaseEnabled(b.databaseEnabled); |
Ben Murdoch | 734a066 | 2009-06-02 19:11:52 +0100 | [diff] [blame] | 208 | s.setDomStorageEnabled(b.domStorageEnabled); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 209 | s.setWebStorageDefaultQuota(b.webStorageDefaultQuota); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 210 | |
Andrei Popescu | 5151ac1 | 2009-04-17 10:43:07 +0100 | [diff] [blame] | 211 | // Turn on Application Caches. |
| 212 | s.setAppCachePath(b.appCachePath); |
| 213 | s.setAppCacheEnabled(b.appCacheEnabled); |
Andrei Popescu | 20634ce | 2009-07-22 16:46:55 +0100 | [diff] [blame] | 214 | s.setAppCacheMaxSize(b.appCacheMaxSize); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 215 | |
| 216 | // Enable/Disable the error console. |
| 217 | b.mTabControl.getBrowserActivity().setShouldShowErrorConsole( |
| 218 | b.showDebugSettings && b.showConsole); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Load settings from the browser app's database. |
| 224 | * NOTE: Strings used for the preferences must match those specified |
| 225 | * in the browser_preferences.xml |
| 226 | * @param ctx A Context object used to query the browser's settings |
| 227 | * database. If the database exists, the saved settings will be |
| 228 | * stored in this BrowserSettings object. This will update all |
| 229 | * observers of this object. |
| 230 | */ |
| 231 | public void loadFromDb(Context ctx) { |
| 232 | SharedPreferences p = |
| 233 | PreferenceManager.getDefaultSharedPreferences(ctx); |
| 234 | |
| 235 | // Set the default value for the plugins path to the application's |
| 236 | // local directory. |
| 237 | pluginsPath = ctx.getDir("plugins", 0).getPath(); |
Andrei Popescu | 5151ac1 | 2009-04-17 10:43:07 +0100 | [diff] [blame] | 238 | // Set the default value for the Application Caches path. |
| 239 | appCachePath = ctx.getDir("appcache", 0).getPath(); |
Andrei Popescu | 20634ce | 2009-07-22 16:46:55 +0100 | [diff] [blame] | 240 | // Determine the maximum size of the application cache. |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame^] | 241 | webStorageSizeManager = WebStorageSizeManager.getInstance(appCachePath, |
| 242 | ctx); |
| 243 | appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 244 | // Set the default value for the Database path. |
| 245 | databasePath = ctx.getDir("databases", 0).getPath(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 246 | |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 247 | homeUrl = getFactoryResetHomeUrl(ctx); |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 248 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 249 | // Load the defaults from the xml |
| 250 | // This call is TOO SLOW, need to manually keep the defaults |
| 251 | // in sync |
| 252 | //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences); |
| 253 | syncSharedPreferences(p); |
| 254 | } |
| 255 | |
| 256 | /* package */ void syncSharedPreferences(SharedPreferences p) { |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 257 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 258 | homeUrl = |
| 259 | p.getString(PREF_HOMEPAGE, homeUrl); |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 260 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 261 | loadsImagesAutomatically = p.getBoolean("load_images", |
| 262 | loadsImagesAutomatically); |
| 263 | javaScriptEnabled = p.getBoolean("enable_javascript", |
| 264 | javaScriptEnabled); |
| 265 | pluginsEnabled = p.getBoolean("enable_plugins", |
| 266 | pluginsEnabled); |
| 267 | pluginsPath = p.getString("plugins_path", pluginsPath); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 268 | databasePath = p.getString("database_path", databasePath); |
| 269 | databaseEnabled = p.getBoolean("enable_database", databaseEnabled); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 270 | webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA, |
| 271 | String.valueOf(webStorageDefaultQuota))); |
Andrei Popescu | 5151ac1 | 2009-04-17 10:43:07 +0100 | [diff] [blame] | 272 | appCacheEnabled = p.getBoolean("enable_appcache", |
Ben Murdoch | 734a066 | 2009-06-02 19:11:52 +0100 | [diff] [blame] | 273 | appCacheEnabled); |
| 274 | domStorageEnabled = p.getBoolean("enable_domstorage", |
| 275 | domStorageEnabled); |
Andrei Popescu | 5151ac1 | 2009-04-17 10:43:07 +0100 | [diff] [blame] | 276 | appCachePath = p.getString("appcache_path", appCachePath); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 277 | javaScriptCanOpenWindowsAutomatically = !p.getBoolean( |
| 278 | "block_popup_windows", |
| 279 | !javaScriptCanOpenWindowsAutomatically); |
| 280 | showSecurityWarnings = p.getBoolean("show_security_warnings", |
| 281 | showSecurityWarnings); |
| 282 | rememberPasswords = p.getBoolean("remember_passwords", |
| 283 | rememberPasswords); |
| 284 | saveFormData = p.getBoolean("save_formdata", |
| 285 | saveFormData); |
| 286 | boolean accept_cookies = p.getBoolean("accept_cookies", |
| 287 | CookieManager.getInstance().acceptCookie()); |
| 288 | CookieManager.getInstance().setAcceptCookie(accept_cookies); |
| 289 | openInBackground = p.getBoolean("open_in_background", openInBackground); |
| 290 | loginInitialized = p.getBoolean("login_initialized", loginInitialized); |
| 291 | textSize = WebSettings.TextSize.valueOf( |
| 292 | p.getString(PREF_TEXT_SIZE, textSize.name())); |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 293 | zoomDensity = WebSettings.ZoomDensity.valueOf( |
| 294 | p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name())); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 295 | autoFitPage = p.getBoolean("autofit_pages", autoFitPage); |
Leon Scroggins | b0cd072 | 2009-03-31 14:31:22 -0700 | [diff] [blame] | 296 | boolean landscapeOnlyTemp = |
| 297 | p.getBoolean("landscape_only", landscapeOnly); |
| 298 | if (landscapeOnlyTemp != landscapeOnly) { |
| 299 | landscapeOnly = landscapeOnlyTemp; |
| 300 | mTabControl.getBrowserActivity().setRequestedOrientation( |
| 301 | landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE |
| 302 | : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 303 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 304 | useWideViewPort = true; // use wide view port for either setting |
| 305 | if (autoFitPage) { |
| 306 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 307 | } else { |
| 308 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; |
| 309 | } |
| 310 | defaultTextEncodingName = |
| 311 | p.getString(PREF_DEFAULT_TEXT_ENCODING, |
| 312 | defaultTextEncodingName); |
| 313 | |
| 314 | showDebugSettings = |
| 315 | p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings); |
| 316 | // Debug menu items have precidence if the menu is visible |
| 317 | if (showDebugSettings) { |
| 318 | boolean small_screen = p.getBoolean("small_screen", |
| 319 | layoutAlgorithm == |
| 320 | WebSettings.LayoutAlgorithm.SINGLE_COLUMN); |
| 321 | if (small_screen) { |
| 322 | layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN; |
| 323 | } else { |
| 324 | boolean normal_layout = p.getBoolean("normal_layout", |
| 325 | layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL); |
| 326 | if (normal_layout) { |
| 327 | layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; |
| 328 | } else { |
| 329 | layoutAlgorithm = |
| 330 | WebSettings.LayoutAlgorithm.NARROW_COLUMNS; |
| 331 | } |
| 332 | } |
| 333 | useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort); |
| 334 | tracing = p.getBoolean("enable_tracing", tracing); |
| 335 | lightTouch = p.getBoolean("enable_light_touch", lightTouch); |
| 336 | navDump = p.getBoolean("enable_nav_dump", navDump); |
| 337 | doFlick = p.getBoolean("enable_flick", doFlick); |
| 338 | userAgent = Integer.parseInt(p.getString("user_agent", "0")); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 339 | } |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 340 | // JS flags is loaded from DB even if showDebugSettings is false, |
| 341 | // so that it can be set once and be effective all the time. |
| 342 | jsFlags = p.getString("js_engine_flags", ""); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 343 | |
| 344 | // Read the setting for showing/hiding the JS Console always so that should the |
| 345 | // user enable debug settings, we already know if we should show the console. |
| 346 | // The user will never see the console unless they navigate to about:debug, |
| 347 | // regardless of the setting we read here. This setting is only used after debug |
| 348 | // is enabled. |
| 349 | showConsole = p.getBoolean("javascript_console", showConsole); |
| 350 | mTabControl.getBrowserActivity().setShouldShowErrorConsole( |
| 351 | showDebugSettings && showConsole); |
Grace Kloba | d9ee139 | 2009-07-20 11:53:33 -0700 | [diff] [blame] | 352 | |
| 353 | update(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | public String getPluginsPath() { |
| 357 | return pluginsPath; |
| 358 | } |
| 359 | |
| 360 | public String getHomePage() { |
| 361 | return homeUrl; |
| 362 | } |
| 363 | |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 364 | public String getJsFlags() { |
| 365 | return jsFlags; |
| 366 | } |
| 367 | |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame^] | 368 | public WebStorageSizeManager getWebStorageSizeManager() { |
| 369 | return webStorageSizeManager; |
| 370 | } |
| 371 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 372 | public void setHomePage(Context context, String url) { |
| 373 | Editor ed = PreferenceManager. |
| 374 | getDefaultSharedPreferences(context).edit(); |
| 375 | ed.putString(PREF_HOMEPAGE, url); |
| 376 | ed.commit(); |
| 377 | homeUrl = url; |
| 378 | } |
| 379 | |
| 380 | public boolean isLoginInitialized() { |
| 381 | return loginInitialized; |
| 382 | } |
| 383 | |
| 384 | public void setLoginInitialized(Context context) { |
| 385 | loginInitialized = true; |
| 386 | Editor ed = PreferenceManager. |
| 387 | getDefaultSharedPreferences(context).edit(); |
| 388 | ed.putBoolean("login_initialized", loginInitialized); |
| 389 | ed.commit(); |
| 390 | } |
| 391 | |
| 392 | public WebSettings.TextSize getTextSize() { |
| 393 | return textSize; |
| 394 | } |
| 395 | |
Grace Kloba | 2f83068 | 2009-06-25 11:08:53 -0700 | [diff] [blame] | 396 | public WebSettings.ZoomDensity getDefaultZoom() { |
| 397 | return zoomDensity; |
| 398 | } |
| 399 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 400 | public boolean openInBackground() { |
| 401 | return openInBackground; |
| 402 | } |
| 403 | |
| 404 | public boolean showSecurityWarnings() { |
| 405 | return showSecurityWarnings; |
| 406 | } |
| 407 | |
| 408 | public boolean isTracing() { |
| 409 | return tracing; |
| 410 | } |
| 411 | |
| 412 | public boolean isLightTouch() { |
| 413 | return lightTouch; |
| 414 | } |
| 415 | |
| 416 | public boolean isNavDump() { |
| 417 | return navDump; |
| 418 | } |
| 419 | |
| 420 | public boolean doFlick() { |
| 421 | return doFlick; |
| 422 | } |
| 423 | |
| 424 | public boolean showDebugSettings() { |
| 425 | return showDebugSettings; |
| 426 | } |
| 427 | |
| 428 | public void toggleDebugSettings() { |
| 429 | showDebugSettings = !showDebugSettings; |
| 430 | navDump = showDebugSettings; |
| 431 | update(); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Add a WebSettings object to the list of observers that will be updated |
| 436 | * when update() is called. |
| 437 | * |
| 438 | * @param s A WebSettings object that is strictly tied to the life of a |
| 439 | * WebView. |
| 440 | */ |
| 441 | public Observer addObserver(WebSettings s) { |
| 442 | Observer old = mWebSettingsToObservers.get(s); |
| 443 | if (old != null) { |
| 444 | super.deleteObserver(old); |
| 445 | } |
| 446 | Observer o = new Observer(s); |
| 447 | mWebSettingsToObservers.put(s, o); |
| 448 | super.addObserver(o); |
| 449 | return o; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Delete the given WebSettings observer from the list of observers. |
| 454 | * @param s The WebSettings object to be deleted. |
| 455 | */ |
| 456 | public void deleteObserver(WebSettings s) { |
| 457 | Observer o = mWebSettingsToObservers.get(s); |
| 458 | if (o != null) { |
| 459 | mWebSettingsToObservers.remove(s); |
| 460 | super.deleteObserver(o); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Package level method for obtaining a single app instance of the |
| 466 | * BrowserSettings. |
| 467 | */ |
| 468 | /*package*/ static BrowserSettings getInstance() { |
| 469 | if (sSingleton == null ) { |
| 470 | sSingleton = new BrowserSettings(); |
| 471 | } |
| 472 | return sSingleton; |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * Package level method for associating the BrowserSettings with TabControl |
| 477 | */ |
| 478 | /* package */void setTabControl(TabControl tabControl) { |
| 479 | mTabControl = tabControl; |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | * Update all the observers of the object. |
| 484 | */ |
| 485 | /*package*/ void update() { |
| 486 | setChanged(); |
| 487 | notifyObservers(); |
| 488 | } |
| 489 | |
| 490 | /*package*/ void clearCache(Context context) { |
| 491 | WebIconDatabase.getInstance().removeAllIcons(); |
| 492 | if (mTabControl != null) { |
| 493 | WebView current = mTabControl.getCurrentWebView(); |
| 494 | if (current != null) { |
| 495 | current.clearCache(true); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /*package*/ void clearCookies(Context context) { |
| 501 | CookieManager.getInstance().removeAllCookie(); |
| 502 | } |
| 503 | |
| 504 | /* package */void clearHistory(Context context) { |
| 505 | ContentResolver resolver = context.getContentResolver(); |
| 506 | Browser.clearHistory(resolver); |
| 507 | Browser.clearSearches(resolver); |
| 508 | } |
| 509 | |
| 510 | /* package */ void clearFormData(Context context) { |
| 511 | WebViewDatabase.getInstance(context).clearFormData(); |
| 512 | if (mTabControl != null) { |
| 513 | mTabControl.getCurrentTopWebView().clearFormData(); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /*package*/ void clearPasswords(Context context) { |
| 518 | WebViewDatabase db = WebViewDatabase.getInstance(context); |
| 519 | db.clearUsernamePassword(); |
| 520 | db.clearHttpAuthUsernamePassword(); |
| 521 | } |
| 522 | |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 523 | /*package*/ void clearDatabases(Context context) { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 524 | WebStorage.getInstance().deleteAllData(); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 525 | // Remove all listed databases from the preferences |
| 526 | PreferenceActivity activity = (PreferenceActivity) context; |
| 527 | PreferenceScreen screen = (PreferenceScreen) |
Nicolas Roard | e46990e | 2009-06-19 16:27:49 +0100 | [diff] [blame] | 528 | activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 529 | screen.removeAll(); |
Nicolas Roard | 6f48042 | 2009-05-12 16:31:33 +0100 | [diff] [blame] | 530 | screen.setEnabled(false); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 533 | /*package*/ void resetDefaultPreferences(Context ctx) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 534 | SharedPreferences p = |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 535 | PreferenceManager.getDefaultSharedPreferences(ctx); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 536 | p.edit().clear().commit(); |
Leon Scroggins | 9ac587d | 2009-04-20 12:53:46 -0400 | [diff] [blame] | 537 | PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 538 | true); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 539 | // reset homeUrl |
Grace Kloba | a3f90f0 | 2009-05-26 11:32:53 -0700 | [diff] [blame] | 540 | setHomePage(ctx, getFactoryResetHomeUrl(ctx)); |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame^] | 541 | // reset appcache max size |
| 542 | appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize(); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | private String getFactoryResetHomeUrl(Context context) { |
| 546 | String url = context.getResources().getString(R.string.homepage_base); |
| 547 | if (url.indexOf("{CID}") != -1) { |
| 548 | url = url.replace("{CID}", Partner.getString(context |
Ramanan Rajeswaran | 9768ac5 | 2009-06-03 19:34:58 -0700 | [diff] [blame] | 549 | .getContentResolver(), Partner.CLIENT_ID, "android-google")); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 550 | } |
| 551 | return url; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 552 | } |
| 553 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 554 | // Private constructor that does nothing. |
| 555 | private BrowserSettings() { |
| 556 | } |
| 557 | } |