blob: 23012896709f0ceb7bc7ca6d113aaa276fa369fb [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().
Ben Murdoch734a0662009-06-02 19:11:52 +010080 private boolean domStorageEnabled = true;
Feng Qianb3c02da2009-06-29 15:58:08 -070081 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080082
Nicolas Roard78a98e42009-05-11 13:34:17 +010083 private final static String TAG = "BrowserSettings";
84
The Android Open Source Project0c908882009-03-03 19:32:16 -080085 // Development settings
86 public WebSettings.LayoutAlgorithm layoutAlgorithm =
87 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
88 private boolean useWideViewPort = true;
89 private int userAgent = 0;
90 private boolean tracing = false;
91 private boolean lightTouch = false;
92 private boolean navDump = false;
Feng Qianb3c02da2009-06-29 15:58:08 -070093
Ben Murdochbff2d602009-07-01 20:19:05 +010094 // By default the error console is shown once the user navigates to about:debug.
95 // The setting can be then toggled from the settings menu.
96 private boolean showConsole = true;
97
The Android Open Source Project0c908882009-03-03 19:32:16 -080098 // Browser only settings
99 private boolean doFlick = false;
100
101 // Private preconfigured values
102 private static int minimumFontSize = 8;
103 private static int minimumLogicalFontSize = 8;
104 private static int defaultFontSize = 16;
105 private static int defaultFixedFontSize = 13;
106 private static WebSettings.TextSize textSize =
107 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700108 private static WebSettings.ZoomDensity zoomDensity =
109 WebSettings.ZoomDensity.MEDIUM;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800110
111 // Preference keys that are used outside this class
112 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
113 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
114 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
115 public final static String PREF_HOMEPAGE = "homepage";
116 public final static String PREF_CLEAR_FORM_DATA =
117 "privacy_clear_form_data";
118 public final static String PREF_CLEAR_PASSWORDS =
119 "privacy_clear_passwords";
Nicolas Roard78a98e42009-05-11 13:34:17 +0100120 public final static String PREF_DEFAULT_QUOTA =
121 "webstorage_default_quota";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800122 public final static String PREF_EXTRAS_RESET_DEFAULTS =
123 "reset_default_preferences";
124 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
125 public final static String PREF_GEARS_SETTINGS = "gears_settings";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100126 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800127 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700128 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129 public final static String PREF_DEFAULT_TEXT_ENCODING =
130 "default_text_encoding";
131
132 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700133 "U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " +
134 "like Gecko) Version/4.0 Safari/530.17";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135
136 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Grace Klobaa4fa6ee2009-06-26 00:34:46 -0700137 "CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 " +
138 "(KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800139
140 // Value to truncate strings when adding them to a TextView within
141 // a ListView
142 public final static int MAX_TEXTVIEW_LEN = 80;
143
144 private TabControl mTabControl;
145
146 // Single instance of the BrowserSettings for use in the Browser app.
147 private static BrowserSettings sSingleton;
148
149 // Private map of WebSettings to Observer objects used when deleting an
150 // observer.
151 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
152 new HashMap<WebSettings,Observer>();
153
154 /*
155 * An observer wrapper for updating a WebSettings object with the new
156 * settings after a call to BrowserSettings.update().
157 */
158 static class Observer implements java.util.Observer {
159 // Private WebSettings object that will be updated.
160 private WebSettings mSettings;
161
162 Observer(WebSettings w) {
163 mSettings = w;
164 }
165
166 public void update(Observable o, Object arg) {
167 BrowserSettings b = (BrowserSettings)o;
168 WebSettings s = mSettings;
169
170 s.setLayoutAlgorithm(b.layoutAlgorithm);
171 if (b.userAgent == 0) {
172 // use the default ua string
173 s.setUserAgentString(null);
174 } else if (b.userAgent == 1) {
175 s.setUserAgentString(DESKTOP_USERAGENT);
176 } else if (b.userAgent == 2) {
177 s.setUserAgentString(IPHONE_USERAGENT);
178 }
179 s.setUseWideViewPort(b.useWideViewPort);
180 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
181 s.setJavaScriptEnabled(b.javaScriptEnabled);
182 s.setPluginsEnabled(b.pluginsEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800183 s.setJavaScriptCanOpenWindowsAutomatically(
184 b.javaScriptCanOpenWindowsAutomatically);
185 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
186 s.setMinimumFontSize(b.minimumFontSize);
187 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
188 s.setDefaultFontSize(b.defaultFontSize);
189 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
190 s.setNavDump(b.navDump);
191 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700192 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800193 s.setLightTouchEnabled(b.lightTouch);
194 s.setSaveFormData(b.saveFormData);
195 s.setSavePassword(b.rememberPasswords);
196
197 // WebView inside Browser doesn't want initial focus to be set.
198 s.setNeedInitialFocus(false);
199 // Browser supports multiple windows
200 s.setSupportMultipleWindows(true);
201 // Turn off file access
202 s.setAllowFileAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100203
204 s.setDatabasePath(b.databasePath);
205 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100206 s.setDomStorageEnabled(b.domStorageEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100207 s.setWebStorageDefaultQuota(b.webStorageDefaultQuota);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100208
Andrei Popescu5151ac12009-04-17 10:43:07 +0100209 // Turn on Application Caches.
210 s.setAppCachePath(b.appCachePath);
211 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdochbff2d602009-07-01 20:19:05 +0100212
213 // Enable/Disable the error console.
214 b.mTabControl.getBrowserActivity().setShouldShowErrorConsole(
215 b.showDebugSettings && b.showConsole);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800216 }
217 }
218
219 /**
220 * Load settings from the browser app's database.
221 * NOTE: Strings used for the preferences must match those specified
222 * in the browser_preferences.xml
223 * @param ctx A Context object used to query the browser's settings
224 * database. If the database exists, the saved settings will be
225 * stored in this BrowserSettings object. This will update all
226 * observers of this object.
227 */
228 public void loadFromDb(Context ctx) {
229 SharedPreferences p =
230 PreferenceManager.getDefaultSharedPreferences(ctx);
231
232 // Set the default value for the plugins path to the application's
233 // local directory.
234 pluginsPath = ctx.getDir("plugins", 0).getPath();
Andrei Popescu5151ac12009-04-17 10:43:07 +0100235 // Set the default value for the Application Caches path.
236 appCachePath = ctx.getDir("appcache", 0).getPath();
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100237 // Set the default value for the Database path.
238 databasePath = ctx.getDir("databases", 0).getPath();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800239
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700240 homeUrl = getFactoryResetHomeUrl(ctx);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700241
The Android Open Source Project0c908882009-03-03 19:32:16 -0800242 // Load the defaults from the xml
243 // This call is TOO SLOW, need to manually keep the defaults
244 // in sync
245 //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences);
246 syncSharedPreferences(p);
247 }
248
249 /* package */ void syncSharedPreferences(SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700250
The Android Open Source Project0c908882009-03-03 19:32:16 -0800251 homeUrl =
252 p.getString(PREF_HOMEPAGE, homeUrl);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700253
The Android Open Source Project0c908882009-03-03 19:32:16 -0800254 loadsImagesAutomatically = p.getBoolean("load_images",
255 loadsImagesAutomatically);
256 javaScriptEnabled = p.getBoolean("enable_javascript",
257 javaScriptEnabled);
258 pluginsEnabled = p.getBoolean("enable_plugins",
259 pluginsEnabled);
260 pluginsPath = p.getString("plugins_path", pluginsPath);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100261 databasePath = p.getString("database_path", databasePath);
262 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100263 webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
264 String.valueOf(webStorageDefaultQuota)));
Andrei Popescu5151ac12009-04-17 10:43:07 +0100265 appCacheEnabled = p.getBoolean("enable_appcache",
Ben Murdoch734a0662009-06-02 19:11:52 +0100266 appCacheEnabled);
267 domStorageEnabled = p.getBoolean("enable_domstorage",
268 domStorageEnabled);
Andrei Popescu5151ac12009-04-17 10:43:07 +0100269 appCachePath = p.getString("appcache_path", appCachePath);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800270 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
271 "block_popup_windows",
272 !javaScriptCanOpenWindowsAutomatically);
273 showSecurityWarnings = p.getBoolean("show_security_warnings",
274 showSecurityWarnings);
275 rememberPasswords = p.getBoolean("remember_passwords",
276 rememberPasswords);
277 saveFormData = p.getBoolean("save_formdata",
278 saveFormData);
279 boolean accept_cookies = p.getBoolean("accept_cookies",
280 CookieManager.getInstance().acceptCookie());
281 CookieManager.getInstance().setAcceptCookie(accept_cookies);
282 openInBackground = p.getBoolean("open_in_background", openInBackground);
283 loginInitialized = p.getBoolean("login_initialized", loginInitialized);
284 textSize = WebSettings.TextSize.valueOf(
285 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700286 zoomDensity = WebSettings.ZoomDensity.valueOf(
287 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800288 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Leon Scrogginsb0cd0722009-03-31 14:31:22 -0700289 boolean landscapeOnlyTemp =
290 p.getBoolean("landscape_only", landscapeOnly);
291 if (landscapeOnlyTemp != landscapeOnly) {
292 landscapeOnly = landscapeOnlyTemp;
293 mTabControl.getBrowserActivity().setRequestedOrientation(
294 landscapeOnly ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
295 : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
296 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800297 useWideViewPort = true; // use wide view port for either setting
298 if (autoFitPage) {
299 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
300 } else {
301 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
302 }
303 defaultTextEncodingName =
304 p.getString(PREF_DEFAULT_TEXT_ENCODING,
305 defaultTextEncodingName);
306
307 showDebugSettings =
308 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
309 // Debug menu items have precidence if the menu is visible
310 if (showDebugSettings) {
311 boolean small_screen = p.getBoolean("small_screen",
312 layoutAlgorithm ==
313 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
314 if (small_screen) {
315 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
316 } else {
317 boolean normal_layout = p.getBoolean("normal_layout",
318 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
319 if (normal_layout) {
320 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
321 } else {
322 layoutAlgorithm =
323 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
324 }
325 }
326 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
327 tracing = p.getBoolean("enable_tracing", tracing);
328 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
329 navDump = p.getBoolean("enable_nav_dump", navDump);
330 doFlick = p.getBoolean("enable_flick", doFlick);
331 userAgent = Integer.parseInt(p.getString("user_agent", "0"));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800332 }
Feng Qianb3c02da2009-06-29 15:58:08 -0700333 // JS flags is loaded from DB even if showDebugSettings is false,
334 // so that it can be set once and be effective all the time.
335 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100336
337 // Read the setting for showing/hiding the JS Console always so that should the
338 // user enable debug settings, we already know if we should show the console.
339 // The user will never see the console unless they navigate to about:debug,
340 // regardless of the setting we read here. This setting is only used after debug
341 // is enabled.
342 showConsole = p.getBoolean("javascript_console", showConsole);
343 mTabControl.getBrowserActivity().setShouldShowErrorConsole(
344 showDebugSettings && showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700345
346 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800347 }
348
349 public String getPluginsPath() {
350 return pluginsPath;
351 }
352
353 public String getHomePage() {
354 return homeUrl;
355 }
356
Feng Qianb3c02da2009-06-29 15:58:08 -0700357 public String getJsFlags() {
358 return jsFlags;
359 }
360
The Android Open Source Project0c908882009-03-03 19:32:16 -0800361 public void setHomePage(Context context, String url) {
362 Editor ed = PreferenceManager.
363 getDefaultSharedPreferences(context).edit();
364 ed.putString(PREF_HOMEPAGE, url);
365 ed.commit();
366 homeUrl = url;
367 }
368
369 public boolean isLoginInitialized() {
370 return loginInitialized;
371 }
372
373 public void setLoginInitialized(Context context) {
374 loginInitialized = true;
375 Editor ed = PreferenceManager.
376 getDefaultSharedPreferences(context).edit();
377 ed.putBoolean("login_initialized", loginInitialized);
378 ed.commit();
379 }
380
381 public WebSettings.TextSize getTextSize() {
382 return textSize;
383 }
384
Grace Kloba2f830682009-06-25 11:08:53 -0700385 public WebSettings.ZoomDensity getDefaultZoom() {
386 return zoomDensity;
387 }
388
The Android Open Source Project0c908882009-03-03 19:32:16 -0800389 public boolean openInBackground() {
390 return openInBackground;
391 }
392
393 public boolean showSecurityWarnings() {
394 return showSecurityWarnings;
395 }
396
397 public boolean isTracing() {
398 return tracing;
399 }
400
401 public boolean isLightTouch() {
402 return lightTouch;
403 }
404
405 public boolean isNavDump() {
406 return navDump;
407 }
408
409 public boolean doFlick() {
410 return doFlick;
411 }
412
413 public boolean showDebugSettings() {
414 return showDebugSettings;
415 }
416
417 public void toggleDebugSettings() {
418 showDebugSettings = !showDebugSettings;
419 navDump = showDebugSettings;
420 update();
421 }
422
423 /**
424 * Add a WebSettings object to the list of observers that will be updated
425 * when update() is called.
426 *
427 * @param s A WebSettings object that is strictly tied to the life of a
428 * WebView.
429 */
430 public Observer addObserver(WebSettings s) {
431 Observer old = mWebSettingsToObservers.get(s);
432 if (old != null) {
433 super.deleteObserver(old);
434 }
435 Observer o = new Observer(s);
436 mWebSettingsToObservers.put(s, o);
437 super.addObserver(o);
438 return o;
439 }
440
441 /**
442 * Delete the given WebSettings observer from the list of observers.
443 * @param s The WebSettings object to be deleted.
444 */
445 public void deleteObserver(WebSettings s) {
446 Observer o = mWebSettingsToObservers.get(s);
447 if (o != null) {
448 mWebSettingsToObservers.remove(s);
449 super.deleteObserver(o);
450 }
451 }
452
453 /*
454 * Package level method for obtaining a single app instance of the
455 * BrowserSettings.
456 */
457 /*package*/ static BrowserSettings getInstance() {
458 if (sSingleton == null ) {
459 sSingleton = new BrowserSettings();
460 }
461 return sSingleton;
462 }
463
464 /*
465 * Package level method for associating the BrowserSettings with TabControl
466 */
467 /* package */void setTabControl(TabControl tabControl) {
468 mTabControl = tabControl;
469 }
470
471 /*
472 * Update all the observers of the object.
473 */
474 /*package*/ void update() {
475 setChanged();
476 notifyObservers();
477 }
478
479 /*package*/ void clearCache(Context context) {
480 WebIconDatabase.getInstance().removeAllIcons();
481 if (mTabControl != null) {
482 WebView current = mTabControl.getCurrentWebView();
483 if (current != null) {
484 current.clearCache(true);
485 }
486 }
487 }
488
489 /*package*/ void clearCookies(Context context) {
490 CookieManager.getInstance().removeAllCookie();
491 }
492
493 /* package */void clearHistory(Context context) {
494 ContentResolver resolver = context.getContentResolver();
495 Browser.clearHistory(resolver);
496 Browser.clearSearches(resolver);
497 }
498
499 /* package */ void clearFormData(Context context) {
500 WebViewDatabase.getInstance(context).clearFormData();
501 if (mTabControl != null) {
502 mTabControl.getCurrentTopWebView().clearFormData();
503 }
504 }
505
506 /*package*/ void clearPasswords(Context context) {
507 WebViewDatabase db = WebViewDatabase.getInstance(context);
508 db.clearUsernamePassword();
509 db.clearHttpAuthUsernamePassword();
510 }
511
Nicolas Roard78a98e42009-05-11 13:34:17 +0100512 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100513 WebStorage.getInstance().deleteAllData();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100514 // Remove all listed databases from the preferences
515 PreferenceActivity activity = (PreferenceActivity) context;
516 PreferenceScreen screen = (PreferenceScreen)
Nicolas Roarde46990e2009-06-19 16:27:49 +0100517 activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100518 screen.removeAll();
Nicolas Roard6f480422009-05-12 16:31:33 +0100519 screen.setEnabled(false);
Nicolas Roard78a98e42009-05-11 13:34:17 +0100520 }
521
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400522 /*package*/ void resetDefaultPreferences(Context ctx) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800523 SharedPreferences p =
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400524 PreferenceManager.getDefaultSharedPreferences(ctx);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800525 p.edit().clear().commit();
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400526 PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800527 true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700528 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700529 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700530 }
531
532 private String getFactoryResetHomeUrl(Context context) {
533 String url = context.getResources().getString(R.string.homepage_base);
534 if (url.indexOf("{CID}") != -1) {
535 url = url.replace("{CID}", Partner.getString(context
Ramanan Rajeswaran9768ac52009-06-03 19:34:58 -0700536 .getContentResolver(), Partner.CLIENT_ID, "android-google"));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700537 }
538 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800539 }
540
541 // Private constructor that does nothing.
542 private BrowserSettings() {
543 }
544}