blob: 3393c4fc540b442a203143befb5c84fc57fed6e0 [file] [log] [blame]
Cary Clarkf2407c62009-09-04 12:25:10 -04001
The Android Open Source Project0c908882009-03-03 19:32:16 -08002/*
3 * Copyright (C) 2007 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.browser;
19
John Reckbafe58a2011-01-11 10:26:02 -080020import com.android.browser.homepages.HomeProvider;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010021import com.android.browser.search.SearchEngine;
22import com.android.browser.search.SearchEngines;
23
Grace Kloba9804c432009-12-02 11:07:40 -080024import android.app.ActivityManager;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010025import android.content.ComponentName;
The Android Open Source Project0c908882009-03-03 19:32:16 -080026import android.content.ContentResolver;
27import android.content.Context;
John Reck63bb6872010-12-01 19:29:32 -080028import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
The Android Open Source Project0c908882009-03-03 19:32:16 -080029import android.content.pm.ActivityInfo;
30import android.content.SharedPreferences;
31import android.content.SharedPreferences.Editor;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010032import android.database.ContentObserver;
Ben Murdoch0cb81892010-10-08 12:41:33 +010033import android.database.Cursor;
Jeff Davidson43610292010-07-16 16:03:58 -070034import android.net.Uri;
Ben Murdoch0cb81892010-10-08 12:41:33 +010035import android.os.AsyncTask;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010036import android.os.Handler;
Ben Murdoch23da30e2010-10-26 15:18:44 +010037import android.os.Message;
Nicolas Roard78a98e42009-05-11 13:34:17 +010038import android.preference.PreferenceActivity;
Ben Murdoch0cb81892010-10-08 12:41:33 +010039import android.preference.PreferenceManager;
Nicolas Roard78a98e42009-05-11 13:34:17 +010040import android.preference.PreferenceScreen;
Ben Murdoch0cb81892010-10-08 12:41:33 +010041import android.provider.Browser;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010042import android.provider.Settings;
43import android.util.Log;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010045import android.webkit.GeolocationPermissions;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010046import android.webkit.ValueCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -080047import android.webkit.WebView;
48import android.webkit.WebViewDatabase;
49import android.webkit.WebIconDatabase;
50import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010051import android.webkit.WebSettings.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010052import android.webkit.WebStorage;
Ben Murdoch0cb81892010-10-08 12:41:33 +010053import android.widget.Toast;
The Android Open Source Project0c908882009-03-03 19:32:16 -080054
55import java.util.HashMap;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010056import java.util.Map;
57import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080058import java.util.Observable;
59
60/*
61 * Package level class for storing various WebView and Browser settings. To use
62 * this class:
63 * BrowserSettings s = BrowserSettings.getInstance();
64 * s.addObserver(webView.getSettings());
65 * s.loadFromDb(context); // Only needed on app startup
66 * s.javaScriptEnabled = true;
67 * ... // set any other settings
68 * s.update(); // this will update all the observers
69 *
70 * To remove an observer:
71 * s.deleteObserver(webView.getSettings());
72 */
John Reck63bb6872010-12-01 19:29:32 -080073public class BrowserSettings extends Observable implements OnSharedPreferenceChangeListener {
Leon Scroggins9ac587d2009-04-20 12:53:46 -040074 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080075 // NOTE: these defaults need to be kept in sync with the XML
76 // until the performance of PreferenceManager.setDefaultValues()
77 // is improved.
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080078 // Note: boolean variables are set inside reset function.
79 private boolean loadsImagesAutomatically;
80 private boolean javaScriptEnabled;
Patrick Scotte536b332010-03-22 10:19:32 -040081 private WebSettings.PluginState pluginState;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080082 private boolean javaScriptCanOpenWindowsAutomatically;
83 private boolean showSecurityWarnings;
84 private boolean rememberPasswords;
85 private boolean saveFormData;
Ben Murdochce549fc2010-09-09 10:28:08 +010086 private boolean autoFillEnabled;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080087 private boolean openInBackground;
The Android Open Source Project0c908882009-03-03 19:32:16 -080088 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070089 private String homeUrl = "";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010090 private SearchEngine searchEngine;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080091 private boolean autoFitPage;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080092 private boolean loadsPageInOverviewMode;
93 private boolean showDebugSettings;
Andrei Popescu01068702009-08-03 16:03:24 +010094 // HTML5 API flags
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080095 private boolean appCacheEnabled;
96 private boolean databaseEnabled;
97 private boolean domStorageEnabled;
98 private boolean geolocationEnabled;
99 private boolean workersEnabled; // only affects V8. JSC does not have a similar setting
Andrei Popescu01068702009-08-03 16:03:24 +0100100 // HTML5 API configuration params
101 private long appCacheMaxSize = Long.MAX_VALUE;
102 private String appCachePath; // default value set in loadFromDb().
103 private String databasePath; // default value set in loadFromDb()
Steve Block5029cf02009-08-21 13:16:58 +0100104 private String geolocationDatabasePath; // default value set in loadFromDb()
Andrei Popescu01068702009-08-03 16:03:24 +0100105 private WebStorageSizeManager webStorageSizeManager;
Patrick Scott539e2ec2011-01-13 11:27:38 -0500106 // Autologin settings
107 private boolean autoLoginEnabled;
108 private String autoLoginAccount;
Andrei Popescu01068702009-08-03 16:03:24 +0100109
110 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800111
Nicolas Roard78a98e42009-05-11 13:34:17 +0100112 private final static String TAG = "BrowserSettings";
113
The Android Open Source Project0c908882009-03-03 19:32:16 -0800114 // Development settings
115 public WebSettings.LayoutAlgorithm layoutAlgorithm =
116 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
117 private boolean useWideViewPort = true;
118 private int userAgent = 0;
119 private boolean tracing = false;
120 private boolean lightTouch = false;
121 private boolean navDump = false;
Derek Sollenberger8de82852010-11-18 19:51:50 -0500122 private boolean hardwareAccelerated = true;
Feng Qianb3c02da2009-06-29 15:58:08 -0700123
Michael Kolb376b5412010-12-15 11:52:57 -0800124 // Lab settings
125 private boolean quickControls = false;
John Reckbafe58a2011-01-11 10:26:02 -0800126 private boolean useMostVisitedHomepage = false;
Michael Kolb376b5412010-12-15 11:52:57 -0800127
Ben Murdochbff2d602009-07-01 20:19:05 +0100128 // By default the error console is shown once the user navigates to about:debug.
129 // The setting can be then toggled from the settings menu.
130 private boolean showConsole = true;
131
The Android Open Source Project0c908882009-03-03 19:32:16 -0800132 // Private preconfigured values
Shimeng (Simon) Wangb4fb25c2010-07-13 15:18:10 -0700133 private static int minimumFontSize = 1;
134 private static int minimumLogicalFontSize = 1;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135 private static int defaultFontSize = 16;
136 private static int defaultFixedFontSize = 13;
137 private static WebSettings.TextSize textSize =
138 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700139 private static WebSettings.ZoomDensity zoomDensity =
140 WebSettings.ZoomDensity.MEDIUM;
Grace Kloba9804c432009-12-02 11:07:40 -0800141 private static int pageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800142
Ben Murdoch0cb81892010-10-08 12:41:33 +0100143
Ben Murdoch23da30e2010-10-26 15:18:44 +0100144 private AutoFillProfile autoFillProfile;
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100145 // Default to zero. In the case no profile is set up, the initial
146 // value will come from the AutoFillSettingsFragment when the user
147 // creates a profile. Otherwise, we'll read the ID of the last used
148 // profile from the prefs db.
149 private int autoFillActiveProfileId;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100150 private static final int NO_AUTOFILL_PROFILE_SET = 0;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100151
The Android Open Source Project0c908882009-03-03 19:32:16 -0800152 // Preference keys that are used outside this class
153 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
154 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
155 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
156 public final static String PREF_HOMEPAGE = "homepage";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100157 public final static String PREF_SEARCH_ENGINE = "search_engine";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800158 public final static String PREF_CLEAR_FORM_DATA =
159 "privacy_clear_form_data";
160 public final static String PREF_CLEAR_PASSWORDS =
161 "privacy_clear_passwords";
162 public final static String PREF_EXTRAS_RESET_DEFAULTS =
163 "reset_default_preferences";
164 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100165 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800166 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700167 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800168 public final static String PREF_DEFAULT_TEXT_ENCODING =
169 "default_text_encoding";
Steve Blockc6f577f2009-08-20 18:11:08 +0100170 public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
171 "privacy_clear_geolocation_access";
Ben Murdochaf554522010-09-10 22:09:30 +0100172 public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled";
173 public final static String PREF_AUTOFILL_PROFILE = "autofill_profile";
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100174 public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id";
John Reck63bb6872010-12-01 19:29:32 -0800175 public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel";
176 public final static String PREF_USER_AGENT = "user_agent";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800177
Michael Kolb376b5412010-12-15 11:52:57 -0800178 public final static String PREF_QUICK_CONTROLS = "enable_quick_controls";
John Reckbafe58a2011-01-11 10:26:02 -0800179 public final static String PREF_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage";
Patrick Scott539e2ec2011-01-13 11:27:38 -0500180 public final static String PREF_AUTOLOGIN = "enable_autologin";
181 public final static String PREF_AUTOLOGIN_ACCOUNT = "autologin_account";
Michael Kolb376b5412010-12-15 11:52:57 -0800182
The Android Open Source Project0c908882009-03-03 19:32:16 -0800183 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700184 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
185 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800186
187 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700188 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
189 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
190
191 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
192 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
193 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
194
195 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
196 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
197 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800198
199 // Value to truncate strings when adding them to a TextView within
200 // a ListView
201 public final static int MAX_TEXTVIEW_LEN = 80;
202
Jeff Davidson43610292010-07-16 16:03:58 -0700203 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
204
205 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
206
John Reck63bb6872010-12-01 19:29:32 -0800207 // Set to true to enable some of the about:debug options
John Reck9eed0ef2011-01-11 17:11:37 -0800208 public static final boolean DEV_BUILD = false;
John Reck63bb6872010-12-01 19:29:32 -0800209
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800211
212 // Single instance of the BrowserSettings for use in the Browser app.
213 private static BrowserSettings sSingleton;
214
215 // Private map of WebSettings to Observer objects used when deleting an
216 // observer.
217 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
218 new HashMap<WebSettings,Observer>();
219
Ben Murdochef671652010-11-25 17:17:58 +0000220 private boolean mLoadFromDbComplete;
221
222 public void waitForLoadFromDbToComplete() {
223 synchronized (sSingleton) {
224 while (!mLoadFromDbComplete) {
225 try {
226 sSingleton.wait();
227 } catch (InterruptedException e) { }
228 }
229 }
230 }
231
The Android Open Source Project0c908882009-03-03 19:32:16 -0800232 /*
233 * An observer wrapper for updating a WebSettings object with the new
234 * settings after a call to BrowserSettings.update().
235 */
236 static class Observer implements java.util.Observer {
237 // Private WebSettings object that will be updated.
238 private WebSettings mSettings;
239
240 Observer(WebSettings w) {
241 mSettings = w;
242 }
243
244 public void update(Observable o, Object arg) {
245 BrowserSettings b = (BrowserSettings)o;
246 WebSettings s = mSettings;
247
248 s.setLayoutAlgorithm(b.layoutAlgorithm);
249 if (b.userAgent == 0) {
250 // use the default ua string
251 s.setUserAgentString(null);
252 } else if (b.userAgent == 1) {
253 s.setUserAgentString(DESKTOP_USERAGENT);
254 } else if (b.userAgent == 2) {
255 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700256 } else if (b.userAgent == 3) {
257 s.setUserAgentString(IPAD_USERAGENT);
258 } else if (b.userAgent == 4) {
259 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800260 }
261 s.setUseWideViewPort(b.useWideViewPort);
262 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
263 s.setJavaScriptEnabled(b.javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400264 s.setPluginState(b.pluginState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800265 s.setJavaScriptCanOpenWindowsAutomatically(
266 b.javaScriptCanOpenWindowsAutomatically);
267 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
268 s.setMinimumFontSize(b.minimumFontSize);
269 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
270 s.setDefaultFontSize(b.defaultFontSize);
271 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
272 s.setNavDump(b.navDump);
273 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700274 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800275 s.setLightTouchEnabled(b.lightTouch);
276 s.setSaveFormData(b.saveFormData);
Ben Murdochce549fc2010-09-09 10:28:08 +0100277 s.setAutoFillEnabled(b.autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800278 s.setSavePassword(b.rememberPasswords);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700279 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
Grace Kloba79565032009-11-24 14:23:39 -0800280 s.setPageCacheCapacity(pageCacheCapacity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800281
282 // WebView inside Browser doesn't want initial focus to be set.
283 s.setNeedInitialFocus(false);
284 // Browser supports multiple windows
285 s.setSupportMultipleWindows(true);
Grace Kloba61fc77c2010-06-22 09:57:33 -0700286 // enable smooth transition for better performance during panning or
287 // zooming
288 s.setEnableSmoothTransition(true);
Patrick Scottb92bbb42011-01-05 11:38:58 -0500289 // disable content url access
290 s.setAllowContentAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100291
Andrei Popescu01068702009-08-03 16:03:24 +0100292 // HTML5 API flags
293 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100294 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100295 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100296 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100297 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100298
Andrei Popescu01068702009-08-03 16:03:24 +0100299 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100300 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100301 s.setAppCachePath(b.appCachePath);
302 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100303 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100304
Ben Murdoch0cb81892010-10-08 12:41:33 +0100305 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100306 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100307
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800308 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800309 }
310 }
311
312 /**
Ben Murdochef671652010-11-25 17:17:58 +0000313 * Load settings from the browser app's database. It is performed in
314 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800315 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500316 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800317 * @param ctx A Context object used to query the browser's settings
318 * database. If the database exists, the saved settings will be
319 * stored in this BrowserSettings object. This will update all
320 * observers of this object.
321 */
Ben Murdochef671652010-11-25 17:17:58 +0000322 public void asyncLoadFromDb(final Context ctx) {
323 mLoadFromDbComplete = false;
324 // Run the initial settings load in an AsyncTask as it hits the
325 // disk multiple times through SharedPreferences and SQLite. We
326 // need to be certain though that this has completed before we start
327 // to load pages though, so in the worst case we will block waiting
328 // for it to finish in BrowserActivity.onCreate().
329 new LoadFromDbTask(ctx).execute();
330 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800331
Ben Murdochef671652010-11-25 17:17:58 +0000332 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
333 private Context mContext;
334
335 public LoadFromDbTask(Context context) {
336 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700337 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700338
Ben Murdochef671652010-11-25 17:17:58 +0000339 protected Void doInBackground(Void... unused) {
340 SharedPreferences p =
341 PreferenceManager.getDefaultSharedPreferences(mContext);
342 // Set the default value for the Application Caches path.
343 appCachePath = mContext.getDir("appcache", 0).getPath();
344 // Determine the maximum size of the application cache.
345 webStorageSizeManager = new WebStorageSizeManager(
346 mContext,
347 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
348 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
349 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
350 // Set the default value for the Database path.
351 databasePath = mContext.getDir("databases", 0).getPath();
352 // Set the default value for the Geolocation database path.
353 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
354
John Reckef074262010-12-02 16:09:14 -0800355 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000356 // No home page preferences is set, set it to default.
357 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
358 }
359
360 // the cost of one cached page is ~3M (measured using nytimes.com). For
361 // low end devices, we only cache one page. For high end devices, we try
362 // to cache more pages, currently choose 5.
363 ActivityManager am = (ActivityManager) mContext
364 .getSystemService(Context.ACTIVITY_SERVICE);
365 if (am.getMemoryClass() > 16) {
366 pageCacheCapacity = 5;
367 } else {
368 pageCacheCapacity = 1;
369 }
370
371 // Read the last active AutoFill profile id.
372 autoFillActiveProfileId = p.getInt(
373 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
374
375 // Load the autofill profile data from the database. We use a database separate
376 // to the browser preference DB to make it easier to support multiple profiles
377 // and switching between them.
378 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
379 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
380
381 if (c.getCount() > 0) {
382 c.moveToFirst();
383
384 String fullName = c.getString(c.getColumnIndex(
385 AutoFillProfileDatabase.Profiles.FULL_NAME));
386 String email = c.getString(c.getColumnIndex(
387 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
388 String company = c.getString(c.getColumnIndex(
389 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
390 String addressLine1 = c.getString(c.getColumnIndex(
391 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
392 String addressLine2 = c.getString(c.getColumnIndex(
393 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
394 String city = c.getString(c.getColumnIndex(
395 AutoFillProfileDatabase.Profiles.CITY));
396 String state = c.getString(c.getColumnIndex(
397 AutoFillProfileDatabase.Profiles.STATE));
398 String zip = c.getString(c.getColumnIndex(
399 AutoFillProfileDatabase.Profiles.ZIP_CODE));
400 String country = c.getString(c.getColumnIndex(
401 AutoFillProfileDatabase.Profiles.COUNTRY));
402 String phone = c.getString(c.getColumnIndex(
403 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
404 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
405 fullName, email, company, addressLine1, addressLine2, city,
406 state, zip, country, phone);
407 }
408 c.close();
409 autoFillDb.close();
410
411 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
412 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800413 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000414 syncSharedPreferences(mContext, p);
415
416 synchronized (sSingleton) {
417 mLoadFromDbComplete = true;
418 sSingleton.notify();
419 }
420 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800421 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800422 }
423
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100424 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700425
The Android Open Source Project0c908882009-03-03 19:32:16 -0800426 homeUrl =
427 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400428 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
429 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100430 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
431 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400432 if (searchEngine.supportsVoiceSearch()) {
433 // One or more tabs could have been in voice search mode.
434 // Clear it, since the new SearchEngine may not support
435 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700436 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
437 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400438 }
439 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100440 searchEngine.close();
441 }
442 searchEngine = SearchEngines.get(ctx, searchEngineName);
443 }
444 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700445
The Android Open Source Project0c908882009-03-03 19:32:16 -0800446 loadsImagesAutomatically = p.getBoolean("load_images",
447 loadsImagesAutomatically);
448 javaScriptEnabled = p.getBoolean("enable_javascript",
449 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400450 pluginState = WebSettings.PluginState.valueOf(
451 p.getString("plugin_state", pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800452 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
453 "block_popup_windows",
454 !javaScriptCanOpenWindowsAutomatically);
455 showSecurityWarnings = p.getBoolean("show_security_warnings",
456 showSecurityWarnings);
457 rememberPasswords = p.getBoolean("remember_passwords",
458 rememberPasswords);
459 saveFormData = p.getBoolean("save_formdata",
460 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100461 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800462 boolean accept_cookies = p.getBoolean("accept_cookies",
463 CookieManager.getInstance().acceptCookie());
464 CookieManager.getInstance().setAcceptCookie(accept_cookies);
465 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800466 textSize = WebSettings.TextSize.valueOf(
467 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700468 zoomDensity = WebSettings.ZoomDensity.valueOf(
469 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800470 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700471 loadsPageInOverviewMode = p.getBoolean("load_page",
472 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800473 useWideViewPort = true; // use wide view port for either setting
474 if (autoFitPage) {
475 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
476 } else {
477 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
478 }
479 defaultTextEncodingName =
480 p.getString(PREF_DEFAULT_TEXT_ENCODING,
481 defaultTextEncodingName);
482
483 showDebugSettings =
484 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
485 // Debug menu items have precidence if the menu is visible
486 if (showDebugSettings) {
487 boolean small_screen = p.getBoolean("small_screen",
488 layoutAlgorithm ==
489 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
490 if (small_screen) {
491 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
492 } else {
493 boolean normal_layout = p.getBoolean("normal_layout",
494 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
495 if (normal_layout) {
496 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
497 } else {
498 layoutAlgorithm =
499 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
500 }
501 }
502 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
503 tracing = p.getBoolean("enable_tracing", tracing);
504 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
505 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800506 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500507
Michael Kolb376b5412010-12-15 11:52:57 -0800508 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800509 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
Michael Kolb376b5412010-12-15 11:52:57 -0800510
John Reck63bb6872010-12-01 19:29:32 -0800511 // Only set these on startup if it is a dev build
512 if (DEV_BUILD) {
513 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
514 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
515 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500516
Feng Qianb3c02da2009-06-29 15:58:08 -0700517 // JS flags is loaded from DB even if showDebugSettings is false,
518 // so that it can be set once and be effective all the time.
519 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100520
521 // Read the setting for showing/hiding the JS Console always so that should the
522 // user enable debug settings, we already know if we should show the console.
523 // The user will never see the console unless they navigate to about:debug,
524 // regardless of the setting we read here. This setting is only used after debug
525 // is enabled.
526 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700527
Andrei Popescu01068702009-08-03 16:03:24 +0100528 // HTML5 API flags
529 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
530 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
531 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100532 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100533 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100534
Patrick Scott539e2ec2011-01-13 11:27:38 -0500535 // Autologin account settings. The account preference may be null until
536 // the user explicitly changes the account in the settings.
537 autoLoginEnabled = p.getBoolean(PREF_AUTOLOGIN, autoLoginEnabled);
538 autoLoginAccount = p.getString(PREF_AUTOLOGIN_ACCOUNT, autoLoginAccount);
539
Grace Klobad9ee1392009-07-20 11:53:33 -0700540 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800541 }
542
The Android Open Source Project0c908882009-03-03 19:32:16 -0800543 public String getHomePage() {
John Reckbafe58a2011-01-11 10:26:02 -0800544 if (useMostVisitedHomepage) {
545 return HomeProvider.MOST_VISITED;
546 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800547 return homeUrl;
548 }
549
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100550 public SearchEngine getSearchEngine() {
551 return searchEngine;
552 }
553
Feng Qianb3c02da2009-06-29 15:58:08 -0700554 public String getJsFlags() {
555 return jsFlags;
556 }
557
Andrei Popescu79e82b72009-07-27 12:01:59 +0100558 public WebStorageSizeManager getWebStorageSizeManager() {
559 return webStorageSizeManager;
560 }
561
The Android Open Source Project0c908882009-03-03 19:32:16 -0800562 public void setHomePage(Context context, String url) {
563 Editor ed = PreferenceManager.
564 getDefaultSharedPreferences(context).edit();
565 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700566 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800567 homeUrl = url;
568 }
569
The Android Open Source Project0c908882009-03-03 19:32:16 -0800570 public WebSettings.TextSize getTextSize() {
571 return textSize;
572 }
573
Grace Kloba2f830682009-06-25 11:08:53 -0700574 public WebSettings.ZoomDensity getDefaultZoom() {
575 return zoomDensity;
576 }
577
The Android Open Source Project0c908882009-03-03 19:32:16 -0800578 public boolean openInBackground() {
579 return openInBackground;
580 }
581
582 public boolean showSecurityWarnings() {
583 return showSecurityWarnings;
584 }
585
586 public boolean isTracing() {
587 return tracing;
588 }
589
590 public boolean isLightTouch() {
591 return lightTouch;
592 }
593
594 public boolean isNavDump() {
595 return navDump;
596 }
597
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500598 public boolean isHardwareAccelerated() {
599 return hardwareAccelerated;
600 }
601
Michael Kolb376b5412010-12-15 11:52:57 -0800602 public boolean useQuickControls() {
603 return quickControls;
604 }
605
John Reckbafe58a2011-01-11 10:26:02 -0800606 public boolean useMostVisitedHomepage() {
607 return useMostVisitedHomepage;
608 }
609
The Android Open Source Project0c908882009-03-03 19:32:16 -0800610 public boolean showDebugSettings() {
611 return showDebugSettings;
612 }
613
614 public void toggleDebugSettings() {
615 showDebugSettings = !showDebugSettings;
616 navDump = showDebugSettings;
617 update();
618 }
619
Patrick Scott539e2ec2011-01-13 11:27:38 -0500620 public boolean isAutoLoginEnabled() {
621 return autoLoginEnabled;
622 }
623
624 public String getAutoLoginAccount(Context context) {
625 // Each time we attempt to get the account, we need to verify that the
626 // account is still valid.
627 return GoogleAccountLogin.validateAccount(context, autoLoginAccount);
628 }
629
630 public void setAutoLoginAccount(Context context, String name) {
631 Editor ed = PreferenceManager.
632 getDefaultSharedPreferences(context).edit();
633 ed.putString(PREF_AUTOLOGIN_ACCOUNT, name);
634 ed.apply();
635 autoLoginAccount = name;
636 }
637
Ben Murdoch23da30e2010-10-26 15:18:44 +0100638 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
639 if (profile != null) {
640 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
641 // Update the AutoFill DB with the new profile.
642 new SaveProfileToDbTask(ctx, msg).execute(profile);
643 } else {
644 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000645 if (autoFillProfile != null) {
646 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
647 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
648 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100649 }
650 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100651 }
652
653 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100654 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100655 }
656
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100657 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
658 autoFillActiveProfileId = activeProfileId;
659 Editor ed = PreferenceManager.
660 getDefaultSharedPreferences(context).edit();
661 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
662 ed.apply();
663 }
664
Ben Murdoch8029a772010-11-16 11:58:21 +0000665 /* package */ void disableAutoFill(Context ctx) {
666 autoFillEnabled = false;
667 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
668 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
669 ed.apply();
670 }
671
The Android Open Source Project0c908882009-03-03 19:32:16 -0800672 /**
673 * Add a WebSettings object to the list of observers that will be updated
674 * when update() is called.
675 *
676 * @param s A WebSettings object that is strictly tied to the life of a
677 * WebView.
678 */
679 public Observer addObserver(WebSettings s) {
680 Observer old = mWebSettingsToObservers.get(s);
681 if (old != null) {
682 super.deleteObserver(old);
683 }
684 Observer o = new Observer(s);
685 mWebSettingsToObservers.put(s, o);
686 super.addObserver(o);
687 return o;
688 }
689
690 /**
691 * Delete the given WebSettings observer from the list of observers.
692 * @param s The WebSettings object to be deleted.
693 */
694 public void deleteObserver(WebSettings s) {
695 Observer o = mWebSettingsToObservers.get(s);
696 if (o != null) {
697 mWebSettingsToObservers.remove(s);
698 super.deleteObserver(o);
699 }
700 }
701
702 /*
John Reck63bb6872010-12-01 19:29:32 -0800703 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800704 * BrowserSettings.
705 */
John Reck63bb6872010-12-01 19:29:32 -0800706 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800707 if (sSingleton == null ) {
708 sSingleton = new BrowserSettings();
709 }
710 return sSingleton;
711 }
712
713 /*
714 * Package level method for associating the BrowserSettings with TabControl
715 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 /* package */void setController(Controller ctrl) {
717 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800718 updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800719 }
720
721 /*
722 * Update all the observers of the object.
723 */
724 /*package*/ void update() {
725 setChanged();
726 notifyObservers();
727 }
728
729 /*package*/ void clearCache(Context context) {
730 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 if (mController != null) {
732 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800733 if (current != null) {
734 current.clearCache(true);
735 }
736 }
737 }
738
739 /*package*/ void clearCookies(Context context) {
740 CookieManager.getInstance().removeAllCookie();
741 }
742
743 /* package */void clearHistory(Context context) {
744 ContentResolver resolver = context.getContentResolver();
745 Browser.clearHistory(resolver);
746 Browser.clearSearches(resolver);
747 }
748
749 /* package */ void clearFormData(Context context) {
750 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700751 if (mController!= null) {
752 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100753 if (currentTopView != null) {
754 currentTopView.clearFormData();
755 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800756 }
757 }
758
759 /*package*/ void clearPasswords(Context context) {
760 WebViewDatabase db = WebViewDatabase.getInstance(context);
761 db.clearUsernamePassword();
762 db.clearHttpAuthUsernamePassword();
763 }
764
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800765 private void updateTabControlSettings() {
766 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800768 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800769 }
770
Nicolas Roard78a98e42009-05-11 13:34:17 +0100771 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100772 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100773 }
774
775 /*package*/ void clearLocationAccess(Context context) {
776 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100777 }
778
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400779 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800780 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500781 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700782 p.edit().clear().apply();
John Reck035a5642010-12-21 18:51:27 -0800783 PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true);
784 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500785 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700786 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700787 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100788 // reset appcache max size
789 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100790 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700791 }
792
John Reck33bbb802010-10-26 17:13:42 -0700793 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700794 String url = context.getResources().getString(R.string.homepage_base);
795 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500796 url = url.replace("{CID}",
797 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700798 }
799 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800800 }
801
The Android Open Source Project0c908882009-03-03 19:32:16 -0800802 // Private constructor that does nothing.
803 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800804 reset();
805 }
806
807 private void reset() {
808 // Private variables for settings
809 // NOTE: these defaults need to be kept in sync with the XML
810 // until the performance of PreferenceManager.setDefaultValues()
811 // is improved.
812 loadsImagesAutomatically = true;
813 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400814 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800815 javaScriptCanOpenWindowsAutomatically = false;
816 showSecurityWarnings = true;
817 rememberPasswords = true;
818 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000819 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800820 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800821 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800822 loadsPageInOverviewMode = true;
823 showDebugSettings = false;
824 // HTML5 API flags
825 appCacheEnabled = true;
826 databaseEnabled = true;
827 domStorageEnabled = true;
828 geolocationEnabled = true;
829 workersEnabled = true; // only affects V8. JSC does not have a similar setting
Patrick Scott539e2ec2011-01-13 11:27:38 -0500830 // Autologin default is true. The account will be populated when
831 // reading from the DB as that is when a context is available.
832 autoLoginEnabled = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800833 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100834
Ben Murdoch23da30e2010-10-26 15:18:44 +0100835 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100836 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100837 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100838 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100839
Ben Murdoch23da30e2010-10-26 15:18:44 +0100840 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100841 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100842 mCompleteMessage = msg;
843 }
844
845 protected void onPostExecute(Void result) {
846 if (mCompleteMessage != null) {
847 mCompleteMessage.sendToTarget();
848 }
849 mAutoFillProfileDb.close();
850 }
851
852 abstract protected Void doInBackground(T... values);
853 }
854
855
856 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
857 public SaveProfileToDbTask(Context ctx, Message msg) {
858 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100859 }
860
861 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100862 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100863 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
864 AutoFillProfile newProfile = values[0];
865 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100866 return null;
867 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100868 }
869
Ben Murdoch23da30e2010-10-26 15:18:44 +0100870 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
871 public DeleteProfileFromDbTask(Context ctx, Message msg) {
872 super(ctx, msg);
873 }
874
875 protected Void doInBackground(Integer... values) {
876 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
877 int id = values[0];
878 assert id > 0;
879 mAutoFillProfileDb.dropProfile(id);
880 return null;
881 }
882 }
John Reck63bb6872010-12-01 19:29:32 -0800883
884 @Override
885 public void onSharedPreferenceChanged(
886 SharedPreferences p, String key) {
887 if (PREF_HARDWARE_ACCEL.equals(key)) {
888 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
889 } else if (PREF_USER_AGENT.equals(key)) {
890 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
891 update();
Michael Kolb376b5412010-12-15 11:52:57 -0800892 } else if (PREF_QUICK_CONTROLS.equals(key)) {
893 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800894 } else if (PREF_MOST_VISITED_HOMEPAGE.equals(key)) {
895 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
John Reck63bb6872010-12-01 19:29:32 -0800896 }
897 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800898}