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