blob: 3074d2b51f360f087adb2d6694a153722e198e76 [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 Popescu79e82b72009-07-27 12:01:59 +0100241 webStorageSizeManager = WebStorageSizeManager.getInstance(appCachePath,
242 ctx);
243 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100244 // Set the default value for the Database path.
245 databasePath = ctx.getDir("databases", 0).getPath();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800246
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700247 homeUrl = getFactoryResetHomeUrl(ctx);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700248
The Android Open Source Project0c908882009-03-03 19:32:16 -0800249 // 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 Rajeswarandd4f4292009-03-24 20:41:19 -0700257
The Android Open Source Project0c908882009-03-03 19:32:16 -0800258 homeUrl =
259 p.getString(PREF_HOMEPAGE, homeUrl);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700260
The Android Open Source Project0c908882009-03-03 19:32:16 -0800261 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 Murdoch092dd5d2009-04-22 12:34:12 +0100268 databasePath = p.getString("database_path", databasePath);
269 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100270 webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
271 String.valueOf(webStorageDefaultQuota)));
Andrei Popescu5151ac12009-04-17 10:43:07 +0100272 appCacheEnabled = p.getBoolean("enable_appcache",
Ben Murdoch734a0662009-06-02 19:11:52 +0100273 appCacheEnabled);
274 domStorageEnabled = p.getBoolean("enable_domstorage",
275 domStorageEnabled);
Andrei Popescu5151ac12009-04-17 10:43:07 +0100276 appCachePath = p.getString("appcache_path", appCachePath);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800277 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 Kloba2f830682009-06-25 11:08:53 -0700293 zoomDensity = WebSettings.ZoomDensity.valueOf(
294 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800295 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Leon Scrogginsb0cd0722009-03-31 14:31:22 -0700296 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 Project0c908882009-03-03 19:32:16 -0800304 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 Project0c908882009-03-03 19:32:16 -0800339 }
Feng Qianb3c02da2009-06-29 15:58:08 -0700340 // 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 Murdochbff2d602009-07-01 20:19:05 +0100343
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 Klobad9ee1392009-07-20 11:53:33 -0700352
353 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800354 }
355
356 public String getPluginsPath() {
357 return pluginsPath;
358 }
359
360 public String getHomePage() {
361 return homeUrl;
362 }
363
Feng Qianb3c02da2009-06-29 15:58:08 -0700364 public String getJsFlags() {
365 return jsFlags;
366 }
367
Andrei Popescu79e82b72009-07-27 12:01:59 +0100368 public WebStorageSizeManager getWebStorageSizeManager() {
369 return webStorageSizeManager;
370 }
371
The Android Open Source Project0c908882009-03-03 19:32:16 -0800372 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 Kloba2f830682009-06-25 11:08:53 -0700396 public WebSettings.ZoomDensity getDefaultZoom() {
397 return zoomDensity;
398 }
399
The Android Open Source Project0c908882009-03-03 19:32:16 -0800400 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 Roard78a98e42009-05-11 13:34:17 +0100523 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100524 WebStorage.getInstance().deleteAllData();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100525 // Remove all listed databases from the preferences
526 PreferenceActivity activity = (PreferenceActivity) context;
527 PreferenceScreen screen = (PreferenceScreen)
Nicolas Roarde46990e2009-06-19 16:27:49 +0100528 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100529 screen.removeAll();
Nicolas Roard6f480422009-05-12 16:31:33 +0100530 screen.setEnabled(false);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100531 }
532
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400533 /*package*/ void resetDefaultPreferences(Context ctx) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800534 SharedPreferences p =
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400535 PreferenceManager.getDefaultSharedPreferences(ctx);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800536 p.edit().clear().commit();
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400537 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800538 true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700539 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700540 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100541 // reset appcache max size
542 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700543 }
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 Rajeswaran9768ac52009-06-03 19:34:58 -0700549 .getContentResolver(), Partner.CLIENT_ID, "android-google"));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700550 }
551 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800552 }
553
The Android Open Source Project0c908882009-03-03 19:32:16 -0800554 // Private constructor that does nothing.
555 private BrowserSettings() {
556 }
557}