blob: faf004234bab3704a7c175b5a56221dbed1de983 [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;
The Android Open Source Project0c908882009-03-03 19:32:16 -080025import android.content.ContentResolver;
26import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080027import android.content.SharedPreferences;
28import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080029import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Ben Murdoch0cb81892010-10-08 12:41:33 +010030import android.database.Cursor;
Jeff Davidson43610292010-07-16 16:03:58 -070031import android.net.Uri;
Ben Murdoch0cb81892010-10-08 12:41:33 +010032import android.os.AsyncTask;
Ben Murdoch23da30e2010-10-26 15:18:44 +010033import android.os.Message;
Ben Murdoch0cb81892010-10-08 12:41:33 +010034import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010035import android.provider.Browser;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010036import android.util.Log;
The Android Open Source Project0c908882009-03-03 19:32:16 -080037import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010038import android.webkit.GeolocationPermissions;
The Android Open Source Project0c908882009-03-03 19:32:16 -080039import android.webkit.WebIconDatabase;
40import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010041import android.webkit.WebSettings.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010042import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080043import android.webkit.WebView;
44import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080045
46import java.util.HashMap;
47import java.util.Observable;
48
49/*
50 * Package level class for storing various WebView and Browser settings. To use
51 * this class:
52 * BrowserSettings s = BrowserSettings.getInstance();
53 * s.addObserver(webView.getSettings());
54 * s.loadFromDb(context); // Only needed on app startup
55 * s.javaScriptEnabled = true;
56 * ... // set any other settings
57 * s.update(); // this will update all the observers
58 *
59 * To remove an observer:
60 * s.deleteObserver(webView.getSettings());
61 */
John Reck63bb6872010-12-01 19:29:32 -080062public class BrowserSettings extends Observable implements OnSharedPreferenceChangeListener {
Leon Scroggins9ac587d2009-04-20 12:53:46 -040063 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080064 // NOTE: these defaults need to be kept in sync with the XML
65 // until the performance of PreferenceManager.setDefaultValues()
66 // is improved.
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080067 // Note: boolean variables are set inside reset function.
68 private boolean loadsImagesAutomatically;
69 private boolean javaScriptEnabled;
Patrick Scotte536b332010-03-22 10:19:32 -040070 private WebSettings.PluginState pluginState;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080071 private boolean javaScriptCanOpenWindowsAutomatically;
72 private boolean showSecurityWarnings;
73 private boolean rememberPasswords;
74 private boolean saveFormData;
Ben Murdochce549fc2010-09-09 10:28:08 +010075 private boolean autoFillEnabled;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080076 private boolean openInBackground;
The Android Open Source Project0c908882009-03-03 19:32:16 -080077 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070078 private String homeUrl = "";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010079 private SearchEngine searchEngine;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080080 private boolean autoFitPage;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080081 private boolean loadsPageInOverviewMode;
82 private boolean showDebugSettings;
Andrei Popescu01068702009-08-03 16:03:24 +010083 // HTML5 API flags
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080084 private boolean appCacheEnabled;
85 private boolean databaseEnabled;
86 private boolean domStorageEnabled;
87 private boolean geolocationEnabled;
88 private boolean workersEnabled; // only affects V8. JSC does not have a similar setting
Andrei Popescu01068702009-08-03 16:03:24 +010089 // HTML5 API configuration params
90 private long appCacheMaxSize = Long.MAX_VALUE;
91 private String appCachePath; // default value set in loadFromDb().
92 private String databasePath; // default value set in loadFromDb()
Steve Block5029cf02009-08-21 13:16:58 +010093 private String geolocationDatabasePath; // default value set in loadFromDb()
Andrei Popescu01068702009-08-03 16:03:24 +010094 private WebStorageSizeManager webStorageSizeManager;
Patrick Scott539e2ec2011-01-13 11:27:38 -050095 // Autologin settings
96 private boolean autoLoginEnabled;
97 private String autoLoginAccount;
Andrei Popescu01068702009-08-03 16:03:24 +010098
99 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
Nicolas Roard78a98e42009-05-11 13:34:17 +0100101 private final static String TAG = "BrowserSettings";
102
The Android Open Source Project0c908882009-03-03 19:32:16 -0800103 // Development settings
104 public WebSettings.LayoutAlgorithm layoutAlgorithm =
105 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
106 private boolean useWideViewPort = true;
107 private int userAgent = 0;
108 private boolean tracing = false;
109 private boolean lightTouch = false;
110 private boolean navDump = false;
Derek Sollenberger8de82852010-11-18 19:51:50 -0500111 private boolean hardwareAccelerated = true;
Feng Qianb3c02da2009-06-29 15:58:08 -0700112
Michael Kolb376b5412010-12-15 11:52:57 -0800113 // Lab settings
114 private boolean quickControls = false;
John Reckbafe58a2011-01-11 10:26:02 -0800115 private boolean useMostVisitedHomepage = false;
Michael Kolb376b5412010-12-15 11:52:57 -0800116
Ben Murdochbff2d602009-07-01 20:19:05 +0100117 // By default the error console is shown once the user navigates to about:debug.
118 // The setting can be then toggled from the settings menu.
119 private boolean showConsole = true;
120
The Android Open Source Project0c908882009-03-03 19:32:16 -0800121 // Private preconfigured values
Shimeng (Simon) Wangb4fb25c2010-07-13 15:18:10 -0700122 private static int minimumFontSize = 1;
123 private static int minimumLogicalFontSize = 1;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124 private static int defaultFontSize = 16;
125 private static int defaultFixedFontSize = 13;
126 private static WebSettings.TextSize textSize =
127 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700128 private static WebSettings.ZoomDensity zoomDensity =
129 WebSettings.ZoomDensity.MEDIUM;
Grace Kloba9804c432009-12-02 11:07:40 -0800130 private static int pageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800131
Ben Murdoch0cb81892010-10-08 12:41:33 +0100132
Ben Murdoch23da30e2010-10-26 15:18:44 +0100133 private AutoFillProfile autoFillProfile;
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100134 // Default to zero. In the case no profile is set up, the initial
135 // value will come from the AutoFillSettingsFragment when the user
136 // creates a profile. Otherwise, we'll read the ID of the last used
137 // profile from the prefs db.
138 private int autoFillActiveProfileId;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100139 private static final int NO_AUTOFILL_PROFILE_SET = 0;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100140
The Android Open Source Project0c908882009-03-03 19:32:16 -0800141 // Preference keys that are used outside this class
142 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
143 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
144 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
145 public final static String PREF_HOMEPAGE = "homepage";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100146 public final static String PREF_SEARCH_ENGINE = "search_engine";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800147 public final static String PREF_CLEAR_FORM_DATA =
148 "privacy_clear_form_data";
149 public final static String PREF_CLEAR_PASSWORDS =
150 "privacy_clear_passwords";
151 public final static String PREF_EXTRAS_RESET_DEFAULTS =
152 "reset_default_preferences";
153 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100154 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800155 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700156 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800157 public final static String PREF_DEFAULT_TEXT_ENCODING =
158 "default_text_encoding";
Steve Blockc6f577f2009-08-20 18:11:08 +0100159 public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
160 "privacy_clear_geolocation_access";
Ben Murdochaf554522010-09-10 22:09:30 +0100161 public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled";
162 public final static String PREF_AUTOFILL_PROFILE = "autofill_profile";
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100163 public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id";
John Reck63bb6872010-12-01 19:29:32 -0800164 public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel";
165 public final static String PREF_USER_AGENT = "user_agent";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800166
Michael Kolb376b5412010-12-15 11:52:57 -0800167 public final static String PREF_QUICK_CONTROLS = "enable_quick_controls";
John Reckbafe58a2011-01-11 10:26:02 -0800168 public final static String PREF_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage";
Patrick Scott539e2ec2011-01-13 11:27:38 -0500169 public final static String PREF_AUTOLOGIN = "enable_autologin";
170 public final static String PREF_AUTOLOGIN_ACCOUNT = "autologin_account";
John Reck282431b2011-01-20 17:38:37 -0800171 public final static String PREF_PLUGIN_STATE = "plugin_state";
Michael Kolb376b5412010-12-15 11:52:57 -0800172
The Android Open Source Project0c908882009-03-03 19:32:16 -0800173 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700174 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
175 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800176
177 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700178 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
179 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
180
181 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
182 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
183 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
184
185 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
186 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
187 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800188
189 // Value to truncate strings when adding them to a TextView within
190 // a ListView
191 public final static int MAX_TEXTVIEW_LEN = 80;
192
Jeff Davidson43610292010-07-16 16:03:58 -0700193 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
194
195 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
196
John Reck63bb6872010-12-01 19:29:32 -0800197 // Set to true to enable some of the about:debug options
John Reck9eed0ef2011-01-11 17:11:37 -0800198 public static final boolean DEV_BUILD = false;
John Reck63bb6872010-12-01 19:29:32 -0800199
Michael Kolb8233fac2010-10-26 16:08:53 -0700200 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800201
202 // Single instance of the BrowserSettings for use in the Browser app.
203 private static BrowserSettings sSingleton;
204
205 // Private map of WebSettings to Observer objects used when deleting an
206 // observer.
207 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
208 new HashMap<WebSettings,Observer>();
209
Ben Murdochef671652010-11-25 17:17:58 +0000210 private boolean mLoadFromDbComplete;
211
212 public void waitForLoadFromDbToComplete() {
213 synchronized (sSingleton) {
214 while (!mLoadFromDbComplete) {
215 try {
216 sSingleton.wait();
217 } catch (InterruptedException e) { }
218 }
219 }
220 }
221
The Android Open Source Project0c908882009-03-03 19:32:16 -0800222 /*
223 * An observer wrapper for updating a WebSettings object with the new
224 * settings after a call to BrowserSettings.update().
225 */
226 static class Observer implements java.util.Observer {
227 // Private WebSettings object that will be updated.
228 private WebSettings mSettings;
229
230 Observer(WebSettings w) {
231 mSettings = w;
232 }
233
234 public void update(Observable o, Object arg) {
235 BrowserSettings b = (BrowserSettings)o;
236 WebSettings s = mSettings;
237
238 s.setLayoutAlgorithm(b.layoutAlgorithm);
239 if (b.userAgent == 0) {
240 // use the default ua string
241 s.setUserAgentString(null);
242 } else if (b.userAgent == 1) {
243 s.setUserAgentString(DESKTOP_USERAGENT);
244 } else if (b.userAgent == 2) {
245 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700246 } else if (b.userAgent == 3) {
247 s.setUserAgentString(IPAD_USERAGENT);
248 } else if (b.userAgent == 4) {
249 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800250 }
251 s.setUseWideViewPort(b.useWideViewPort);
252 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
253 s.setJavaScriptEnabled(b.javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400254 s.setPluginState(b.pluginState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800255 s.setJavaScriptCanOpenWindowsAutomatically(
256 b.javaScriptCanOpenWindowsAutomatically);
257 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
258 s.setMinimumFontSize(b.minimumFontSize);
259 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
260 s.setDefaultFontSize(b.defaultFontSize);
261 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
262 s.setNavDump(b.navDump);
263 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700264 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800265 s.setLightTouchEnabled(b.lightTouch);
266 s.setSaveFormData(b.saveFormData);
Ben Murdochce549fc2010-09-09 10:28:08 +0100267 s.setAutoFillEnabled(b.autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800268 s.setSavePassword(b.rememberPasswords);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700269 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
Grace Kloba79565032009-11-24 14:23:39 -0800270 s.setPageCacheCapacity(pageCacheCapacity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800271
272 // WebView inside Browser doesn't want initial focus to be set.
273 s.setNeedInitialFocus(false);
274 // Browser supports multiple windows
275 s.setSupportMultipleWindows(true);
Grace Kloba61fc77c2010-06-22 09:57:33 -0700276 // enable smooth transition for better performance during panning or
277 // zooming
278 s.setEnableSmoothTransition(true);
Patrick Scottb92bbb42011-01-05 11:38:58 -0500279 // disable content url access
280 s.setAllowContentAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100281
Andrei Popescu01068702009-08-03 16:03:24 +0100282 // HTML5 API flags
283 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100284 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100285 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100286 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100287 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100288
Andrei Popescu01068702009-08-03 16:03:24 +0100289 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100290 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100291 s.setAppCachePath(b.appCachePath);
292 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100293 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100294
Ben Murdoch0cb81892010-10-08 12:41:33 +0100295 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100296 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100297
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800298 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800299 }
300 }
301
302 /**
Ben Murdochef671652010-11-25 17:17:58 +0000303 * Load settings from the browser app's database. It is performed in
304 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800305 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500306 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800307 * @param ctx A Context object used to query the browser's settings
308 * database. If the database exists, the saved settings will be
309 * stored in this BrowserSettings object. This will update all
310 * observers of this object.
311 */
Ben Murdochef671652010-11-25 17:17:58 +0000312 public void asyncLoadFromDb(final Context ctx) {
313 mLoadFromDbComplete = false;
314 // Run the initial settings load in an AsyncTask as it hits the
315 // disk multiple times through SharedPreferences and SQLite. We
316 // need to be certain though that this has completed before we start
317 // to load pages though, so in the worst case we will block waiting
318 // for it to finish in BrowserActivity.onCreate().
319 new LoadFromDbTask(ctx).execute();
320 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800321
Ben Murdochef671652010-11-25 17:17:58 +0000322 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
323 private Context mContext;
324
325 public LoadFromDbTask(Context context) {
326 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700327 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700328
Ben Murdochef671652010-11-25 17:17:58 +0000329 protected Void doInBackground(Void... unused) {
330 SharedPreferences p =
331 PreferenceManager.getDefaultSharedPreferences(mContext);
332 // Set the default value for the Application Caches path.
333 appCachePath = mContext.getDir("appcache", 0).getPath();
334 // Determine the maximum size of the application cache.
335 webStorageSizeManager = new WebStorageSizeManager(
336 mContext,
337 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
338 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
339 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
340 // Set the default value for the Database path.
341 databasePath = mContext.getDir("databases", 0).getPath();
342 // Set the default value for the Geolocation database path.
343 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
344
John Reckef074262010-12-02 16:09:14 -0800345 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000346 // No home page preferences is set, set it to default.
347 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
348 }
349
350 // the cost of one cached page is ~3M (measured using nytimes.com). For
351 // low end devices, we only cache one page. For high end devices, we try
352 // to cache more pages, currently choose 5.
353 ActivityManager am = (ActivityManager) mContext
354 .getSystemService(Context.ACTIVITY_SERVICE);
355 if (am.getMemoryClass() > 16) {
356 pageCacheCapacity = 5;
357 } else {
358 pageCacheCapacity = 1;
359 }
360
361 // Read the last active AutoFill profile id.
362 autoFillActiveProfileId = p.getInt(
363 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
364
365 // Load the autofill profile data from the database. We use a database separate
366 // to the browser preference DB to make it easier to support multiple profiles
367 // and switching between them.
368 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
369 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
370
371 if (c.getCount() > 0) {
372 c.moveToFirst();
373
374 String fullName = c.getString(c.getColumnIndex(
375 AutoFillProfileDatabase.Profiles.FULL_NAME));
376 String email = c.getString(c.getColumnIndex(
377 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
378 String company = c.getString(c.getColumnIndex(
379 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
380 String addressLine1 = c.getString(c.getColumnIndex(
381 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
382 String addressLine2 = c.getString(c.getColumnIndex(
383 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
384 String city = c.getString(c.getColumnIndex(
385 AutoFillProfileDatabase.Profiles.CITY));
386 String state = c.getString(c.getColumnIndex(
387 AutoFillProfileDatabase.Profiles.STATE));
388 String zip = c.getString(c.getColumnIndex(
389 AutoFillProfileDatabase.Profiles.ZIP_CODE));
390 String country = c.getString(c.getColumnIndex(
391 AutoFillProfileDatabase.Profiles.COUNTRY));
392 String phone = c.getString(c.getColumnIndex(
393 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
394 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
395 fullName, email, company, addressLine1, addressLine2, city,
396 state, zip, country, phone);
397 }
398 c.close();
399 autoFillDb.close();
400
401 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
402 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800403 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000404 syncSharedPreferences(mContext, p);
405
406 synchronized (sSingleton) {
407 mLoadFromDbComplete = true;
408 sSingleton.notify();
409 }
410 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800411 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800412 }
413
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100414 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700415
The Android Open Source Project0c908882009-03-03 19:32:16 -0800416 homeUrl =
417 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400418 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
419 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100420 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
421 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400422 if (searchEngine.supportsVoiceSearch()) {
423 // One or more tabs could have been in voice search mode.
424 // Clear it, since the new SearchEngine may not support
425 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
427 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400428 }
429 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100430 searchEngine.close();
431 }
432 searchEngine = SearchEngines.get(ctx, searchEngineName);
433 }
434 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700435
The Android Open Source Project0c908882009-03-03 19:32:16 -0800436 loadsImagesAutomatically = p.getBoolean("load_images",
437 loadsImagesAutomatically);
438 javaScriptEnabled = p.getBoolean("enable_javascript",
439 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400440 pluginState = WebSettings.PluginState.valueOf(
John Reck282431b2011-01-20 17:38:37 -0800441 p.getString(PREF_PLUGIN_STATE, pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800442 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
443 "block_popup_windows",
444 !javaScriptCanOpenWindowsAutomatically);
445 showSecurityWarnings = p.getBoolean("show_security_warnings",
446 showSecurityWarnings);
447 rememberPasswords = p.getBoolean("remember_passwords",
448 rememberPasswords);
449 saveFormData = p.getBoolean("save_formdata",
450 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100451 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800452 boolean accept_cookies = p.getBoolean("accept_cookies",
453 CookieManager.getInstance().acceptCookie());
454 CookieManager.getInstance().setAcceptCookie(accept_cookies);
455 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800456 textSize = WebSettings.TextSize.valueOf(
457 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700458 zoomDensity = WebSettings.ZoomDensity.valueOf(
459 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800460 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700461 loadsPageInOverviewMode = p.getBoolean("load_page",
462 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800463 useWideViewPort = true; // use wide view port for either setting
464 if (autoFitPage) {
465 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
466 } else {
467 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
468 }
469 defaultTextEncodingName =
470 p.getString(PREF_DEFAULT_TEXT_ENCODING,
471 defaultTextEncodingName);
472
473 showDebugSettings =
474 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
475 // Debug menu items have precidence if the menu is visible
476 if (showDebugSettings) {
477 boolean small_screen = p.getBoolean("small_screen",
478 layoutAlgorithm ==
479 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
480 if (small_screen) {
481 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
482 } else {
483 boolean normal_layout = p.getBoolean("normal_layout",
484 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
485 if (normal_layout) {
486 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
487 } else {
488 layoutAlgorithm =
489 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
490 }
491 }
492 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
493 tracing = p.getBoolean("enable_tracing", tracing);
494 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
495 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800496 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500497
Michael Kolb376b5412010-12-15 11:52:57 -0800498 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800499 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
Michael Kolb376b5412010-12-15 11:52:57 -0800500
John Reck3db2e072011-01-24 14:57:18 -0800501 // Only set these if this is a dev build or debug is enabled
502 if (DEV_BUILD || showDebugSettings()) {
John Reck63bb6872010-12-01 19:29:32 -0800503 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
504 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
505 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500506
Feng Qianb3c02da2009-06-29 15:58:08 -0700507 // JS flags is loaded from DB even if showDebugSettings is false,
508 // so that it can be set once and be effective all the time.
509 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100510
511 // Read the setting for showing/hiding the JS Console always so that should the
512 // user enable debug settings, we already know if we should show the console.
513 // The user will never see the console unless they navigate to about:debug,
514 // regardless of the setting we read here. This setting is only used after debug
515 // is enabled.
516 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700517
Andrei Popescu01068702009-08-03 16:03:24 +0100518 // HTML5 API flags
519 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
520 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
521 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100522 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100523 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100524
Patrick Scott539e2ec2011-01-13 11:27:38 -0500525 // Autologin account settings. The account preference may be null until
526 // the user explicitly changes the account in the settings.
527 autoLoginEnabled = p.getBoolean(PREF_AUTOLOGIN, autoLoginEnabled);
528 autoLoginAccount = p.getString(PREF_AUTOLOGIN_ACCOUNT, autoLoginAccount);
529
Grace Klobad9ee1392009-07-20 11:53:33 -0700530 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800531 }
532
The Android Open Source Project0c908882009-03-03 19:32:16 -0800533 public String getHomePage() {
John Reckbafe58a2011-01-11 10:26:02 -0800534 if (useMostVisitedHomepage) {
535 return HomeProvider.MOST_VISITED;
536 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800537 return homeUrl;
538 }
539
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100540 public SearchEngine getSearchEngine() {
541 return searchEngine;
542 }
543
Feng Qianb3c02da2009-06-29 15:58:08 -0700544 public String getJsFlags() {
545 return jsFlags;
546 }
547
Andrei Popescu79e82b72009-07-27 12:01:59 +0100548 public WebStorageSizeManager getWebStorageSizeManager() {
549 return webStorageSizeManager;
550 }
551
The Android Open Source Project0c908882009-03-03 19:32:16 -0800552 public void setHomePage(Context context, String url) {
553 Editor ed = PreferenceManager.
554 getDefaultSharedPreferences(context).edit();
555 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700556 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800557 homeUrl = url;
558 }
559
The Android Open Source Project0c908882009-03-03 19:32:16 -0800560 public WebSettings.TextSize getTextSize() {
561 return textSize;
562 }
563
Grace Kloba2f830682009-06-25 11:08:53 -0700564 public WebSettings.ZoomDensity getDefaultZoom() {
565 return zoomDensity;
566 }
567
The Android Open Source Project0c908882009-03-03 19:32:16 -0800568 public boolean openInBackground() {
569 return openInBackground;
570 }
571
572 public boolean showSecurityWarnings() {
573 return showSecurityWarnings;
574 }
575
576 public boolean isTracing() {
577 return tracing;
578 }
579
580 public boolean isLightTouch() {
581 return lightTouch;
582 }
583
584 public boolean isNavDump() {
585 return navDump;
586 }
587
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500588 public boolean isHardwareAccelerated() {
589 return hardwareAccelerated;
590 }
591
Michael Kolb376b5412010-12-15 11:52:57 -0800592 public boolean useQuickControls() {
593 return quickControls;
594 }
595
John Reckbafe58a2011-01-11 10:26:02 -0800596 public boolean useMostVisitedHomepage() {
597 return useMostVisitedHomepage;
598 }
599
The Android Open Source Project0c908882009-03-03 19:32:16 -0800600 public boolean showDebugSettings() {
601 return showDebugSettings;
602 }
603
John Reck3db2e072011-01-24 14:57:18 -0800604 public void toggleDebugSettings(Context context) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800605 showDebugSettings = !showDebugSettings;
606 navDump = showDebugSettings;
John Reck3db2e072011-01-24 14:57:18 -0800607 syncSharedPreferences(context,
608 PreferenceManager.getDefaultSharedPreferences(context));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800609 update();
610 }
611
Patrick Scott539e2ec2011-01-13 11:27:38 -0500612 public boolean isAutoLoginEnabled() {
613 return autoLoginEnabled;
614 }
615
616 public String getAutoLoginAccount(Context context) {
617 // Each time we attempt to get the account, we need to verify that the
618 // account is still valid.
619 return GoogleAccountLogin.validateAccount(context, autoLoginAccount);
620 }
621
622 public void setAutoLoginAccount(Context context, String name) {
623 Editor ed = PreferenceManager.
624 getDefaultSharedPreferences(context).edit();
625 ed.putString(PREF_AUTOLOGIN_ACCOUNT, name);
626 ed.apply();
627 autoLoginAccount = name;
628 }
629
John Reck812d2d62011-01-18 14:16:15 -0800630 public void setAutoLoginEnabled(Context context, boolean enable) {
631 Editor ed = PreferenceManager.
632 getDefaultSharedPreferences(context).edit();
633 ed.putBoolean(PREF_AUTOLOGIN, enable);
634 ed.apply();
635 autoLoginEnabled = enable;
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}