blob: 0d3bc482f9374305bd5134e57a3c5b8ddf3486c0 [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";
Michael Kolb376b5412010-12-15 11:52:57 -0800171
The Android Open Source Project0c908882009-03-03 19:32:16 -0800172 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700173 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
174 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800175
176 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700177 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
178 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
179
180 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
181 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
182 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
183
184 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
185 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
186 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800187
188 // Value to truncate strings when adding them to a TextView within
189 // a ListView
190 public final static int MAX_TEXTVIEW_LEN = 80;
191
Jeff Davidson43610292010-07-16 16:03:58 -0700192 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
193
194 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
195
John Reck63bb6872010-12-01 19:29:32 -0800196 // Set to true to enable some of the about:debug options
John Reck9eed0ef2011-01-11 17:11:37 -0800197 public static final boolean DEV_BUILD = false;
John Reck63bb6872010-12-01 19:29:32 -0800198
Michael Kolb8233fac2010-10-26 16:08:53 -0700199 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800200
201 // Single instance of the BrowserSettings for use in the Browser app.
202 private static BrowserSettings sSingleton;
203
204 // Private map of WebSettings to Observer objects used when deleting an
205 // observer.
206 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
207 new HashMap<WebSettings,Observer>();
208
Ben Murdochef671652010-11-25 17:17:58 +0000209 private boolean mLoadFromDbComplete;
210
211 public void waitForLoadFromDbToComplete() {
212 synchronized (sSingleton) {
213 while (!mLoadFromDbComplete) {
214 try {
215 sSingleton.wait();
216 } catch (InterruptedException e) { }
217 }
218 }
219 }
220
The Android Open Source Project0c908882009-03-03 19:32:16 -0800221 /*
222 * An observer wrapper for updating a WebSettings object with the new
223 * settings after a call to BrowserSettings.update().
224 */
225 static class Observer implements java.util.Observer {
226 // Private WebSettings object that will be updated.
227 private WebSettings mSettings;
228
229 Observer(WebSettings w) {
230 mSettings = w;
231 }
232
233 public void update(Observable o, Object arg) {
234 BrowserSettings b = (BrowserSettings)o;
235 WebSettings s = mSettings;
236
237 s.setLayoutAlgorithm(b.layoutAlgorithm);
238 if (b.userAgent == 0) {
239 // use the default ua string
240 s.setUserAgentString(null);
241 } else if (b.userAgent == 1) {
242 s.setUserAgentString(DESKTOP_USERAGENT);
243 } else if (b.userAgent == 2) {
244 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700245 } else if (b.userAgent == 3) {
246 s.setUserAgentString(IPAD_USERAGENT);
247 } else if (b.userAgent == 4) {
248 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800249 }
250 s.setUseWideViewPort(b.useWideViewPort);
251 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
252 s.setJavaScriptEnabled(b.javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400253 s.setPluginState(b.pluginState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800254 s.setJavaScriptCanOpenWindowsAutomatically(
255 b.javaScriptCanOpenWindowsAutomatically);
256 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
257 s.setMinimumFontSize(b.minimumFontSize);
258 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
259 s.setDefaultFontSize(b.defaultFontSize);
260 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
261 s.setNavDump(b.navDump);
262 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700263 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800264 s.setLightTouchEnabled(b.lightTouch);
265 s.setSaveFormData(b.saveFormData);
Ben Murdochce549fc2010-09-09 10:28:08 +0100266 s.setAutoFillEnabled(b.autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800267 s.setSavePassword(b.rememberPasswords);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700268 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
Grace Kloba79565032009-11-24 14:23:39 -0800269 s.setPageCacheCapacity(pageCacheCapacity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800270
271 // WebView inside Browser doesn't want initial focus to be set.
272 s.setNeedInitialFocus(false);
273 // Browser supports multiple windows
274 s.setSupportMultipleWindows(true);
Grace Kloba61fc77c2010-06-22 09:57:33 -0700275 // enable smooth transition for better performance during panning or
276 // zooming
277 s.setEnableSmoothTransition(true);
Patrick Scottb92bbb42011-01-05 11:38:58 -0500278 // disable content url access
279 s.setAllowContentAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100280
Andrei Popescu01068702009-08-03 16:03:24 +0100281 // HTML5 API flags
282 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100283 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100284 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100285 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100286 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100287
Andrei Popescu01068702009-08-03 16:03:24 +0100288 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100289 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100290 s.setAppCachePath(b.appCachePath);
291 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100292 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100293
Ben Murdoch0cb81892010-10-08 12:41:33 +0100294 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100295 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100296
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800297 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800298 }
299 }
300
301 /**
Ben Murdochef671652010-11-25 17:17:58 +0000302 * Load settings from the browser app's database. It is performed in
303 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800304 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500305 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800306 * @param ctx A Context object used to query the browser's settings
307 * database. If the database exists, the saved settings will be
308 * stored in this BrowserSettings object. This will update all
309 * observers of this object.
310 */
Ben Murdochef671652010-11-25 17:17:58 +0000311 public void asyncLoadFromDb(final Context ctx) {
312 mLoadFromDbComplete = false;
313 // Run the initial settings load in an AsyncTask as it hits the
314 // disk multiple times through SharedPreferences and SQLite. We
315 // need to be certain though that this has completed before we start
316 // to load pages though, so in the worst case we will block waiting
317 // for it to finish in BrowserActivity.onCreate().
318 new LoadFromDbTask(ctx).execute();
319 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800320
Ben Murdochef671652010-11-25 17:17:58 +0000321 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
322 private Context mContext;
323
324 public LoadFromDbTask(Context context) {
325 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700326 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700327
Ben Murdochef671652010-11-25 17:17:58 +0000328 protected Void doInBackground(Void... unused) {
329 SharedPreferences p =
330 PreferenceManager.getDefaultSharedPreferences(mContext);
331 // Set the default value for the Application Caches path.
332 appCachePath = mContext.getDir("appcache", 0).getPath();
333 // Determine the maximum size of the application cache.
334 webStorageSizeManager = new WebStorageSizeManager(
335 mContext,
336 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
337 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
338 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
339 // Set the default value for the Database path.
340 databasePath = mContext.getDir("databases", 0).getPath();
341 // Set the default value for the Geolocation database path.
342 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
343
John Reckef074262010-12-02 16:09:14 -0800344 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000345 // No home page preferences is set, set it to default.
346 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
347 }
348
349 // the cost of one cached page is ~3M (measured using nytimes.com). For
350 // low end devices, we only cache one page. For high end devices, we try
351 // to cache more pages, currently choose 5.
352 ActivityManager am = (ActivityManager) mContext
353 .getSystemService(Context.ACTIVITY_SERVICE);
354 if (am.getMemoryClass() > 16) {
355 pageCacheCapacity = 5;
356 } else {
357 pageCacheCapacity = 1;
358 }
359
360 // Read the last active AutoFill profile id.
361 autoFillActiveProfileId = p.getInt(
362 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
363
364 // Load the autofill profile data from the database. We use a database separate
365 // to the browser preference DB to make it easier to support multiple profiles
366 // and switching between them.
367 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
368 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
369
370 if (c.getCount() > 0) {
371 c.moveToFirst();
372
373 String fullName = c.getString(c.getColumnIndex(
374 AutoFillProfileDatabase.Profiles.FULL_NAME));
375 String email = c.getString(c.getColumnIndex(
376 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
377 String company = c.getString(c.getColumnIndex(
378 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
379 String addressLine1 = c.getString(c.getColumnIndex(
380 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
381 String addressLine2 = c.getString(c.getColumnIndex(
382 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
383 String city = c.getString(c.getColumnIndex(
384 AutoFillProfileDatabase.Profiles.CITY));
385 String state = c.getString(c.getColumnIndex(
386 AutoFillProfileDatabase.Profiles.STATE));
387 String zip = c.getString(c.getColumnIndex(
388 AutoFillProfileDatabase.Profiles.ZIP_CODE));
389 String country = c.getString(c.getColumnIndex(
390 AutoFillProfileDatabase.Profiles.COUNTRY));
391 String phone = c.getString(c.getColumnIndex(
392 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
393 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
394 fullName, email, company, addressLine1, addressLine2, city,
395 state, zip, country, phone);
396 }
397 c.close();
398 autoFillDb.close();
399
400 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
401 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800402 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000403 syncSharedPreferences(mContext, p);
404
405 synchronized (sSingleton) {
406 mLoadFromDbComplete = true;
407 sSingleton.notify();
408 }
409 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800410 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800411 }
412
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100413 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700414
The Android Open Source Project0c908882009-03-03 19:32:16 -0800415 homeUrl =
416 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400417 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
418 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100419 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
420 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400421 if (searchEngine.supportsVoiceSearch()) {
422 // One or more tabs could have been in voice search mode.
423 // Clear it, since the new SearchEngine may not support
424 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
426 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400427 }
428 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100429 searchEngine.close();
430 }
431 searchEngine = SearchEngines.get(ctx, searchEngineName);
432 }
433 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700434
The Android Open Source Project0c908882009-03-03 19:32:16 -0800435 loadsImagesAutomatically = p.getBoolean("load_images",
436 loadsImagesAutomatically);
437 javaScriptEnabled = p.getBoolean("enable_javascript",
438 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400439 pluginState = WebSettings.PluginState.valueOf(
440 p.getString("plugin_state", pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800441 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
442 "block_popup_windows",
443 !javaScriptCanOpenWindowsAutomatically);
444 showSecurityWarnings = p.getBoolean("show_security_warnings",
445 showSecurityWarnings);
446 rememberPasswords = p.getBoolean("remember_passwords",
447 rememberPasswords);
448 saveFormData = p.getBoolean("save_formdata",
449 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100450 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800451 boolean accept_cookies = p.getBoolean("accept_cookies",
452 CookieManager.getInstance().acceptCookie());
453 CookieManager.getInstance().setAcceptCookie(accept_cookies);
454 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800455 textSize = WebSettings.TextSize.valueOf(
456 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700457 zoomDensity = WebSettings.ZoomDensity.valueOf(
458 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700460 loadsPageInOverviewMode = p.getBoolean("load_page",
461 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800462 useWideViewPort = true; // use wide view port for either setting
463 if (autoFitPage) {
464 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
465 } else {
466 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
467 }
468 defaultTextEncodingName =
469 p.getString(PREF_DEFAULT_TEXT_ENCODING,
470 defaultTextEncodingName);
471
472 showDebugSettings =
473 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
474 // Debug menu items have precidence if the menu is visible
475 if (showDebugSettings) {
476 boolean small_screen = p.getBoolean("small_screen",
477 layoutAlgorithm ==
478 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
479 if (small_screen) {
480 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
481 } else {
482 boolean normal_layout = p.getBoolean("normal_layout",
483 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
484 if (normal_layout) {
485 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
486 } else {
487 layoutAlgorithm =
488 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
489 }
490 }
491 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
492 tracing = p.getBoolean("enable_tracing", tracing);
493 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
494 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800495 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500496
Michael Kolb376b5412010-12-15 11:52:57 -0800497 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800498 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
Michael Kolb376b5412010-12-15 11:52:57 -0800499
John Reck63bb6872010-12-01 19:29:32 -0800500 // Only set these on startup if it is a dev build
501 if (DEV_BUILD) {
502 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
503 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
504 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500505
Feng Qianb3c02da2009-06-29 15:58:08 -0700506 // JS flags is loaded from DB even if showDebugSettings is false,
507 // so that it can be set once and be effective all the time.
508 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100509
510 // Read the setting for showing/hiding the JS Console always so that should the
511 // user enable debug settings, we already know if we should show the console.
512 // The user will never see the console unless they navigate to about:debug,
513 // regardless of the setting we read here. This setting is only used after debug
514 // is enabled.
515 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700516
Andrei Popescu01068702009-08-03 16:03:24 +0100517 // HTML5 API flags
518 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
519 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
520 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100521 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100522 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100523
Patrick Scott539e2ec2011-01-13 11:27:38 -0500524 // Autologin account settings. The account preference may be null until
525 // the user explicitly changes the account in the settings.
526 autoLoginEnabled = p.getBoolean(PREF_AUTOLOGIN, autoLoginEnabled);
527 autoLoginAccount = p.getString(PREF_AUTOLOGIN_ACCOUNT, autoLoginAccount);
528
Grace Klobad9ee1392009-07-20 11:53:33 -0700529 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800530 }
531
The Android Open Source Project0c908882009-03-03 19:32:16 -0800532 public String getHomePage() {
John Reckbafe58a2011-01-11 10:26:02 -0800533 if (useMostVisitedHomepage) {
534 return HomeProvider.MOST_VISITED;
535 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800536 return homeUrl;
537 }
538
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100539 public SearchEngine getSearchEngine() {
540 return searchEngine;
541 }
542
Feng Qianb3c02da2009-06-29 15:58:08 -0700543 public String getJsFlags() {
544 return jsFlags;
545 }
546
Andrei Popescu79e82b72009-07-27 12:01:59 +0100547 public WebStorageSizeManager getWebStorageSizeManager() {
548 return webStorageSizeManager;
549 }
550
The Android Open Source Project0c908882009-03-03 19:32:16 -0800551 public void setHomePage(Context context, String url) {
552 Editor ed = PreferenceManager.
553 getDefaultSharedPreferences(context).edit();
554 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700555 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800556 homeUrl = url;
557 }
558
The Android Open Source Project0c908882009-03-03 19:32:16 -0800559 public WebSettings.TextSize getTextSize() {
560 return textSize;
561 }
562
Grace Kloba2f830682009-06-25 11:08:53 -0700563 public WebSettings.ZoomDensity getDefaultZoom() {
564 return zoomDensity;
565 }
566
The Android Open Source Project0c908882009-03-03 19:32:16 -0800567 public boolean openInBackground() {
568 return openInBackground;
569 }
570
571 public boolean showSecurityWarnings() {
572 return showSecurityWarnings;
573 }
574
575 public boolean isTracing() {
576 return tracing;
577 }
578
579 public boolean isLightTouch() {
580 return lightTouch;
581 }
582
583 public boolean isNavDump() {
584 return navDump;
585 }
586
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500587 public boolean isHardwareAccelerated() {
588 return hardwareAccelerated;
589 }
590
Michael Kolb376b5412010-12-15 11:52:57 -0800591 public boolean useQuickControls() {
592 return quickControls;
593 }
594
John Reckbafe58a2011-01-11 10:26:02 -0800595 public boolean useMostVisitedHomepage() {
596 return useMostVisitedHomepage;
597 }
598
The Android Open Source Project0c908882009-03-03 19:32:16 -0800599 public boolean showDebugSettings() {
600 return showDebugSettings;
601 }
602
603 public void toggleDebugSettings() {
604 showDebugSettings = !showDebugSettings;
605 navDump = showDebugSettings;
606 update();
607 }
608
Patrick Scott539e2ec2011-01-13 11:27:38 -0500609 public boolean isAutoLoginEnabled() {
610 return autoLoginEnabled;
611 }
612
613 public String getAutoLoginAccount(Context context) {
614 // Each time we attempt to get the account, we need to verify that the
615 // account is still valid.
616 return GoogleAccountLogin.validateAccount(context, autoLoginAccount);
617 }
618
619 public void setAutoLoginAccount(Context context, String name) {
620 Editor ed = PreferenceManager.
621 getDefaultSharedPreferences(context).edit();
622 ed.putString(PREF_AUTOLOGIN_ACCOUNT, name);
623 ed.apply();
624 autoLoginAccount = name;
625 }
626
John Reck812d2d62011-01-18 14:16:15 -0800627 public void setAutoLoginEnabled(Context context, boolean enable) {
628 Editor ed = PreferenceManager.
629 getDefaultSharedPreferences(context).edit();
630 ed.putBoolean(PREF_AUTOLOGIN, enable);
631 ed.apply();
632 autoLoginEnabled = enable;
633 }
634
Ben Murdoch23da30e2010-10-26 15:18:44 +0100635 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
636 if (profile != null) {
637 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
638 // Update the AutoFill DB with the new profile.
639 new SaveProfileToDbTask(ctx, msg).execute(profile);
640 } else {
641 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000642 if (autoFillProfile != null) {
643 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
644 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
645 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100646 }
647 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100648 }
649
650 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100651 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100652 }
653
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100654 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
655 autoFillActiveProfileId = activeProfileId;
656 Editor ed = PreferenceManager.
657 getDefaultSharedPreferences(context).edit();
658 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
659 ed.apply();
660 }
661
Ben Murdoch8029a772010-11-16 11:58:21 +0000662 /* package */ void disableAutoFill(Context ctx) {
663 autoFillEnabled = false;
664 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
665 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
666 ed.apply();
667 }
668
The Android Open Source Project0c908882009-03-03 19:32:16 -0800669 /**
670 * Add a WebSettings object to the list of observers that will be updated
671 * when update() is called.
672 *
673 * @param s A WebSettings object that is strictly tied to the life of a
674 * WebView.
675 */
676 public Observer addObserver(WebSettings s) {
677 Observer old = mWebSettingsToObservers.get(s);
678 if (old != null) {
679 super.deleteObserver(old);
680 }
681 Observer o = new Observer(s);
682 mWebSettingsToObservers.put(s, o);
683 super.addObserver(o);
684 return o;
685 }
686
687 /**
688 * Delete the given WebSettings observer from the list of observers.
689 * @param s The WebSettings object to be deleted.
690 */
691 public void deleteObserver(WebSettings s) {
692 Observer o = mWebSettingsToObservers.get(s);
693 if (o != null) {
694 mWebSettingsToObservers.remove(s);
695 super.deleteObserver(o);
696 }
697 }
698
699 /*
John Reck63bb6872010-12-01 19:29:32 -0800700 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800701 * BrowserSettings.
702 */
John Reck63bb6872010-12-01 19:29:32 -0800703 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800704 if (sSingleton == null ) {
705 sSingleton = new BrowserSettings();
706 }
707 return sSingleton;
708 }
709
710 /*
711 * Package level method for associating the BrowserSettings with TabControl
712 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700713 /* package */void setController(Controller ctrl) {
714 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800715 updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800716 }
717
718 /*
719 * Update all the observers of the object.
720 */
721 /*package*/ void update() {
722 setChanged();
723 notifyObservers();
724 }
725
726 /*package*/ void clearCache(Context context) {
727 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700728 if (mController != null) {
729 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800730 if (current != null) {
731 current.clearCache(true);
732 }
733 }
734 }
735
736 /*package*/ void clearCookies(Context context) {
737 CookieManager.getInstance().removeAllCookie();
738 }
739
740 /* package */void clearHistory(Context context) {
741 ContentResolver resolver = context.getContentResolver();
742 Browser.clearHistory(resolver);
743 Browser.clearSearches(resolver);
744 }
745
746 /* package */ void clearFormData(Context context) {
747 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700748 if (mController!= null) {
749 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100750 if (currentTopView != null) {
751 currentTopView.clearFormData();
752 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800753 }
754 }
755
756 /*package*/ void clearPasswords(Context context) {
757 WebViewDatabase db = WebViewDatabase.getInstance(context);
758 db.clearUsernamePassword();
759 db.clearHttpAuthUsernamePassword();
760 }
761
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800762 private void updateTabControlSettings() {
763 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700764 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800765 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800766 }
767
Nicolas Roard78a98e42009-05-11 13:34:17 +0100768 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100769 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100770 }
771
772 /*package*/ void clearLocationAccess(Context context) {
773 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100774 }
775
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400776 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800777 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500778 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700779 p.edit().clear().apply();
John Reck035a5642010-12-21 18:51:27 -0800780 PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true);
781 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500782 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700783 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700784 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100785 // reset appcache max size
786 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100787 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700788 }
789
John Reck33bbb802010-10-26 17:13:42 -0700790 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700791 String url = context.getResources().getString(R.string.homepage_base);
792 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500793 url = url.replace("{CID}",
794 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700795 }
796 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800797 }
798
The Android Open Source Project0c908882009-03-03 19:32:16 -0800799 // Private constructor that does nothing.
800 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800801 reset();
802 }
803
804 private void reset() {
805 // Private variables for settings
806 // NOTE: these defaults need to be kept in sync with the XML
807 // until the performance of PreferenceManager.setDefaultValues()
808 // is improved.
809 loadsImagesAutomatically = true;
810 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400811 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800812 javaScriptCanOpenWindowsAutomatically = false;
813 showSecurityWarnings = true;
814 rememberPasswords = true;
815 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000816 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800817 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800818 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800819 loadsPageInOverviewMode = true;
820 showDebugSettings = false;
821 // HTML5 API flags
822 appCacheEnabled = true;
823 databaseEnabled = true;
824 domStorageEnabled = true;
825 geolocationEnabled = true;
826 workersEnabled = true; // only affects V8. JSC does not have a similar setting
Patrick Scott539e2ec2011-01-13 11:27:38 -0500827 // Autologin default is true. The account will be populated when
828 // reading from the DB as that is when a context is available.
829 autoLoginEnabled = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800830 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100831
Ben Murdoch23da30e2010-10-26 15:18:44 +0100832 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100833 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100834 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100835 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100836
Ben Murdoch23da30e2010-10-26 15:18:44 +0100837 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100838 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100839 mCompleteMessage = msg;
840 }
841
842 protected void onPostExecute(Void result) {
843 if (mCompleteMessage != null) {
844 mCompleteMessage.sendToTarget();
845 }
846 mAutoFillProfileDb.close();
847 }
848
849 abstract protected Void doInBackground(T... values);
850 }
851
852
853 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
854 public SaveProfileToDbTask(Context ctx, Message msg) {
855 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100856 }
857
858 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100859 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100860 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
861 AutoFillProfile newProfile = values[0];
862 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100863 return null;
864 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100865 }
866
Ben Murdoch23da30e2010-10-26 15:18:44 +0100867 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
868 public DeleteProfileFromDbTask(Context ctx, Message msg) {
869 super(ctx, msg);
870 }
871
872 protected Void doInBackground(Integer... values) {
873 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
874 int id = values[0];
875 assert id > 0;
876 mAutoFillProfileDb.dropProfile(id);
877 return null;
878 }
879 }
John Reck63bb6872010-12-01 19:29:32 -0800880
881 @Override
882 public void onSharedPreferenceChanged(
883 SharedPreferences p, String key) {
884 if (PREF_HARDWARE_ACCEL.equals(key)) {
885 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
886 } else if (PREF_USER_AGENT.equals(key)) {
887 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
888 update();
Michael Kolb376b5412010-12-15 11:52:57 -0800889 } else if (PREF_QUICK_CONTROLS.equals(key)) {
890 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800891 } else if (PREF_MOST_VISITED_HOMEPAGE.equals(key)) {
892 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
John Reck63bb6872010-12-01 19:29:32 -0800893 }
894 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800895}