blob: 79deb61561a1881fa07e0170a77cee0b353d2a0e [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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
17package com.android.browser;
18
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -070019import com.google.android.providers.GoogleSettings.Partner;
20
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.ContentResolver;
22import android.content.Context;
23import android.content.pm.ActivityInfo;
24import android.content.SharedPreferences;
25import android.content.SharedPreferences.Editor;
Nicolas Roard78a98e42009-05-11 13:34:17 +010026import android.preference.PreferenceActivity;
27import android.preference.PreferenceScreen;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.webkit.CookieManager;
29import android.webkit.WebView;
30import android.webkit.WebViewDatabase;
31import android.webkit.WebIconDatabase;
32import android.webkit.WebSettings;
Nicolas Roard78a98e42009-05-11 13:34:17 +010033import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080034import android.preference.PreferenceManager;
35import android.provider.Browser;
36
37import java.util.HashMap;
38import 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 */
53class BrowserSettings extends Observable {
54
Leon Scroggins9ac587d2009-04-20 12:53:46 -040055 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080056 // 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 Klobaf2c5c1b2009-05-26 10:48:31 -070069 private String homeUrl = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080070 private boolean loginInitialized = false;
71 private boolean autoFitPage = true;
Leon Scrogginsb0cd0722009-03-31 14:31:22 -070072 private boolean landscapeOnly = false;
The Android Open Source Project0c908882009-03-03 19:32:16 -080073 private boolean showDebugSettings = false;
Ben Murdoch092dd5d2009-04-22 12:34:12 +010074 private String databasePath; // default value set in loadFromDb()
75 private boolean databaseEnabled = true;
Nicolas Roard78a98e42009-05-11 13:34:17 +010076 private long webStorageDefaultQuota = 5 * 1024 * 1024;
Andrei Popescu5151ac12009-04-17 10:43:07 +010077 // The Browser always enables Application Caches.
78 private boolean appCacheEnabled = true;
79 private String appCachePath; // default value set in loadFromDb().
Andrei Popescu20634ce2009-07-22 16:46:55 +010080 private long appCacheMaxSize = Long.MAX_VALUE;
Andrei Popescu79e82b72009-07-27 12:01:59 +010081 private WebStorageSizeManager webStorageSizeManager;
Ben Murdoch734a0662009-06-02 19:11:52 +010082 private boolean domStorageEnabled = true;
Feng Qianb3c02da2009-06-29 15:58:08 -070083 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080084
Nicolas Roard78a98e42009-05-11 13:34:17 +010085 private final static String TAG = "BrowserSettings";
86
The Android Open Source Project0c908882009-03-03 19:32:16 -080087 // 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 Qianb3c02da2009-06-29 15:58:08 -070095
Ben Murdochbff2d602009-07-01 20:19:05 +010096 // 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 Project0c908882009-03-03 19:32:16 -0800100 // 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 Kloba2f830682009-06-25 11:08:53 -0700110 private static WebSettings.ZoomDensity zoomDensity =
111 WebSettings.ZoomDensity.MEDIUM;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800112
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 Roard78a98e42009-05-11 13:34:17 +0100122 public final static String PREF_DEFAULT_QUOTA =
123 "webstorage_default_quota";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124 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 Roarde46990e2009-06-19 16:27:49 +0100128 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700130 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800131 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 Klobaa4fa6ee2009-06-26 00:34:46 -0700135 "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 Project0c908882009-03-03 19:32:16 -0800137
138 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700139 "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 Project0c908882009-03-03 19:32:16 -0800141
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 Project0c908882009-03-03 19:32:16 -0800185 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 Kloba2f830682009-06-25 11:08:53 -0700194 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800195 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 Murdoch092dd5d2009-04-22 12:34:12 +0100205
206 s.setDatabasePath(b.databasePath);
207 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100208 s.setDomStorageEnabled(b.domStorageEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100209 s.setWebStorageDefaultQuota(b.webStorageDefaultQuota);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100210
Andrei Popescu5151ac12009-04-17 10:43:07 +0100211 // Turn on Application Caches.
212 s.setAppCachePath(b.appCachePath);
213 s.setAppCacheEnabled(b.appCacheEnabled);
Andrei Popescu20634ce2009-07-22 16:46:55 +0100214 s.setAppCacheMaxSize(b.appCacheMaxSize);
Ben Murdochbff2d602009-07-01 20:19:05 +0100215
216 // Enable/Disable the error console.
217 b.mTabControl.getBrowserActivity().setShouldShowErrorConsole(
218 b.showDebugSettings && b.showConsole);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800219 }
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 Popescu5151ac12009-04-17 10:43:07 +0100238 // Set the default value for the Application Caches path.
239 appCachePath = ctx.getDir("appcache", 0).getPath();
Andrei Popescu20634ce2009-07-22 16:46:55 +0100240 // Determine the maximum size of the application cache.
Andrei Popescu907c5762009-07-29 14:44:24 +0100241 webStorageSizeManager = new WebStorageSizeManager(
242 ctx,
243 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
244 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100245 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100246 // Set the default value for the Database path.
247 databasePath = ctx.getDir("databases", 0).getPath();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800248
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700249 homeUrl = getFactoryResetHomeUrl(ctx);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700250
The Android Open Source Project0c908882009-03-03 19:32:16 -0800251 // Load the defaults from the xml
252 // This call is TOO SLOW, need to manually keep the defaults
253 // in sync
254 //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences);
255 syncSharedPreferences(p);
256 }
257
258 /* package */ void syncSharedPreferences(SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700259
The Android Open Source Project0c908882009-03-03 19:32:16 -0800260 homeUrl =
261 p.getString(PREF_HOMEPAGE, homeUrl);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700262
The Android Open Source Project0c908882009-03-03 19:32:16 -0800263 loadsImagesAutomatically = p.getBoolean("load_images",
264 loadsImagesAutomatically);
265 javaScriptEnabled = p.getBoolean("enable_javascript",
266 javaScriptEnabled);
267 pluginsEnabled = p.getBoolean("enable_plugins",
268 pluginsEnabled);
269 pluginsPath = p.getString("plugins_path", pluginsPath);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100270 databasePath = p.getString("database_path", databasePath);
271 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100272 webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
273 String.valueOf(webStorageDefaultQuota)));
Andrei Popescu5151ac12009-04-17 10:43:07 +0100274 appCacheEnabled = p.getBoolean("enable_appcache",
Ben Murdoch734a0662009-06-02 19:11:52 +0100275 appCacheEnabled);
276 domStorageEnabled = p.getBoolean("enable_domstorage",
277 domStorageEnabled);
Andrei Popescu5151ac12009-04-17 10:43:07 +0100278 appCachePath = p.getString("appcache_path", appCachePath);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800279 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
280 "block_popup_windows",
281 !javaScriptCanOpenWindowsAutomatically);
282 showSecurityWarnings = p.getBoolean("show_security_warnings",
283 showSecurityWarnings);
284 rememberPasswords = p.getBoolean("remember_passwords",
285 rememberPasswords);
286 saveFormData = p.getBoolean("save_formdata",
287 saveFormData);
288 boolean accept_cookies = p.getBoolean("accept_cookies",
289 CookieManager.getInstance().acceptCookie());
290 CookieManager.getInstance().setAcceptCookie(accept_cookies);
291 openInBackground = p.getBoolean("open_in_background", openInBackground);
292 loginInitialized = p.getBoolean("login_initialized", loginInitialized);
293 textSize = WebSettings.TextSize.valueOf(
294 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700295 zoomDensity = WebSettings.ZoomDensity.valueOf(
296 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800297 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Leon Scrogginsb0cd0722009-03-31 14:31:22 -0700298 boolean landscapeOnlyTemp =
299 p.getBoolean("landscape_only", landscapeOnly);
300 if (landscapeOnlyTemp != landscapeOnly) {
301 landscapeOnly = landscapeOnlyTemp;
302 mTabControl.getBrowserActivity().setRequestedOrientation(
303 landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
304 : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
305 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800306 useWideViewPort = true; // use wide view port for either setting
307 if (autoFitPage) {
308 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
309 } else {
310 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
311 }
312 defaultTextEncodingName =
313 p.getString(PREF_DEFAULT_TEXT_ENCODING,
314 defaultTextEncodingName);
315
316 showDebugSettings =
317 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
318 // Debug menu items have precidence if the menu is visible
319 if (showDebugSettings) {
320 boolean small_screen = p.getBoolean("small_screen",
321 layoutAlgorithm ==
322 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
323 if (small_screen) {
324 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
325 } else {
326 boolean normal_layout = p.getBoolean("normal_layout",
327 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
328 if (normal_layout) {
329 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
330 } else {
331 layoutAlgorithm =
332 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
333 }
334 }
335 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
336 tracing = p.getBoolean("enable_tracing", tracing);
337 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
338 navDump = p.getBoolean("enable_nav_dump", navDump);
339 doFlick = p.getBoolean("enable_flick", doFlick);
340 userAgent = Integer.parseInt(p.getString("user_agent", "0"));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800341 }
Feng Qianb3c02da2009-06-29 15:58:08 -0700342 // JS flags is loaded from DB even if showDebugSettings is false,
343 // so that it can be set once and be effective all the time.
344 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100345
346 // Read the setting for showing/hiding the JS Console always so that should the
347 // user enable debug settings, we already know if we should show the console.
348 // The user will never see the console unless they navigate to about:debug,
349 // regardless of the setting we read here. This setting is only used after debug
350 // is enabled.
351 showConsole = p.getBoolean("javascript_console", showConsole);
352 mTabControl.getBrowserActivity().setShouldShowErrorConsole(
353 showDebugSettings && showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700354
355 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800356 }
357
358 public String getPluginsPath() {
359 return pluginsPath;
360 }
361
362 public String getHomePage() {
363 return homeUrl;
364 }
365
Feng Qianb3c02da2009-06-29 15:58:08 -0700366 public String getJsFlags() {
367 return jsFlags;
368 }
369
Andrei Popescu79e82b72009-07-27 12:01:59 +0100370 public WebStorageSizeManager getWebStorageSizeManager() {
371 return webStorageSizeManager;
372 }
373
The Android Open Source Project0c908882009-03-03 19:32:16 -0800374 public void setHomePage(Context context, String url) {
375 Editor ed = PreferenceManager.
376 getDefaultSharedPreferences(context).edit();
377 ed.putString(PREF_HOMEPAGE, url);
378 ed.commit();
379 homeUrl = url;
380 }
381
382 public boolean isLoginInitialized() {
383 return loginInitialized;
384 }
385
386 public void setLoginInitialized(Context context) {
387 loginInitialized = true;
388 Editor ed = PreferenceManager.
389 getDefaultSharedPreferences(context).edit();
390 ed.putBoolean("login_initialized", loginInitialized);
391 ed.commit();
392 }
393
394 public WebSettings.TextSize getTextSize() {
395 return textSize;
396 }
397
Grace Kloba2f830682009-06-25 11:08:53 -0700398 public WebSettings.ZoomDensity getDefaultZoom() {
399 return zoomDensity;
400 }
401
The Android Open Source Project0c908882009-03-03 19:32:16 -0800402 public boolean openInBackground() {
403 return openInBackground;
404 }
405
406 public boolean showSecurityWarnings() {
407 return showSecurityWarnings;
408 }
409
410 public boolean isTracing() {
411 return tracing;
412 }
413
414 public boolean isLightTouch() {
415 return lightTouch;
416 }
417
418 public boolean isNavDump() {
419 return navDump;
420 }
421
422 public boolean doFlick() {
423 return doFlick;
424 }
425
426 public boolean showDebugSettings() {
427 return showDebugSettings;
428 }
429
430 public void toggleDebugSettings() {
431 showDebugSettings = !showDebugSettings;
432 navDump = showDebugSettings;
433 update();
434 }
435
436 /**
437 * Add a WebSettings object to the list of observers that will be updated
438 * when update() is called.
439 *
440 * @param s A WebSettings object that is strictly tied to the life of a
441 * WebView.
442 */
443 public Observer addObserver(WebSettings s) {
444 Observer old = mWebSettingsToObservers.get(s);
445 if (old != null) {
446 super.deleteObserver(old);
447 }
448 Observer o = new Observer(s);
449 mWebSettingsToObservers.put(s, o);
450 super.addObserver(o);
451 return o;
452 }
453
454 /**
455 * Delete the given WebSettings observer from the list of observers.
456 * @param s The WebSettings object to be deleted.
457 */
458 public void deleteObserver(WebSettings s) {
459 Observer o = mWebSettingsToObservers.get(s);
460 if (o != null) {
461 mWebSettingsToObservers.remove(s);
462 super.deleteObserver(o);
463 }
464 }
465
466 /*
467 * Package level method for obtaining a single app instance of the
468 * BrowserSettings.
469 */
470 /*package*/ static BrowserSettings getInstance() {
471 if (sSingleton == null ) {
472 sSingleton = new BrowserSettings();
473 }
474 return sSingleton;
475 }
476
477 /*
478 * Package level method for associating the BrowserSettings with TabControl
479 */
480 /* package */void setTabControl(TabControl tabControl) {
481 mTabControl = tabControl;
482 }
483
484 /*
485 * Update all the observers of the object.
486 */
487 /*package*/ void update() {
488 setChanged();
489 notifyObservers();
490 }
491
492 /*package*/ void clearCache(Context context) {
493 WebIconDatabase.getInstance().removeAllIcons();
494 if (mTabControl != null) {
495 WebView current = mTabControl.getCurrentWebView();
496 if (current != null) {
497 current.clearCache(true);
498 }
499 }
500 }
501
502 /*package*/ void clearCookies(Context context) {
503 CookieManager.getInstance().removeAllCookie();
504 }
505
506 /* package */void clearHistory(Context context) {
507 ContentResolver resolver = context.getContentResolver();
508 Browser.clearHistory(resolver);
509 Browser.clearSearches(resolver);
510 }
511
512 /* package */ void clearFormData(Context context) {
513 WebViewDatabase.getInstance(context).clearFormData();
514 if (mTabControl != null) {
515 mTabControl.getCurrentTopWebView().clearFormData();
516 }
517 }
518
519 /*package*/ void clearPasswords(Context context) {
520 WebViewDatabase db = WebViewDatabase.getInstance(context);
521 db.clearUsernamePassword();
522 db.clearHttpAuthUsernamePassword();
523 }
524
Nicolas Roard78a98e42009-05-11 13:34:17 +0100525 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100526 WebStorage.getInstance().deleteAllData();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100527 // Remove all listed databases from the preferences
528 PreferenceActivity activity = (PreferenceActivity) context;
529 PreferenceScreen screen = (PreferenceScreen)
Nicolas Roarde46990e2009-06-19 16:27:49 +0100530 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100531 screen.removeAll();
Nicolas Roard6f480422009-05-12 16:31:33 +0100532 screen.setEnabled(false);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100533 }
534
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400535 /*package*/ void resetDefaultPreferences(Context ctx) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800536 SharedPreferences p =
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400537 PreferenceManager.getDefaultSharedPreferences(ctx);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800538 p.edit().clear().commit();
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400539 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800540 true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700541 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700542 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100543 // reset appcache max size
544 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700545 }
546
547 private String getFactoryResetHomeUrl(Context context) {
548 String url = context.getResources().getString(R.string.homepage_base);
549 if (url.indexOf("{CID}") != -1) {
550 url = url.replace("{CID}", Partner.getString(context
Ramanan Rajeswaran9768ac52009-06-03 19:34:58 -0700551 .getContentResolver(), Partner.CLIENT_ID, "android-google"));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700552 }
553 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800554 }
555
The Android Open Source Project0c908882009-03-03 19:32:16 -0800556 // Private constructor that does nothing.
557 private BrowserSettings() {
558 }
559}