blob: 357d1e907598ecfcdf9ba9743de8ee68e6c23a6c [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;
95
96 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -080097
Nicolas Roard78a98e42009-05-11 13:34:17 +010098 private final static String TAG = "BrowserSettings";
99
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100 // Development settings
101 public WebSettings.LayoutAlgorithm layoutAlgorithm =
102 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
103 private boolean useWideViewPort = true;
104 private int userAgent = 0;
105 private boolean tracing = false;
106 private boolean lightTouch = false;
107 private boolean navDump = false;
Derek Sollenberger8de82852010-11-18 19:51:50 -0500108 private boolean hardwareAccelerated = true;
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800109 private boolean showVisualIndicator = false;
Michael Kolb376b5412010-12-15 11:52:57 -0800110 // Lab settings
111 private boolean quickControls = false;
John Reckbafe58a2011-01-11 10:26:02 -0800112 private boolean useMostVisitedHomepage = false;
Narayan Kamath5119edd2011-02-23 15:49:17 +0000113 private boolean useInstant = false;
Michael Kolb376b5412010-12-15 11:52:57 -0800114
Ben Murdochbff2d602009-07-01 20:19:05 +0100115 // By default the error console is shown once the user navigates to about:debug.
116 // The setting can be then toggled from the settings menu.
117 private boolean showConsole = true;
118
The Android Open Source Project0c908882009-03-03 19:32:16 -0800119 // Private preconfigured values
Shimeng (Simon) Wangb4fb25c2010-07-13 15:18:10 -0700120 private static int minimumFontSize = 1;
121 private static int minimumLogicalFontSize = 1;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800122 private static int defaultFontSize = 16;
123 private static int defaultFixedFontSize = 13;
124 private static WebSettings.TextSize textSize =
125 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700126 private static WebSettings.ZoomDensity zoomDensity =
127 WebSettings.ZoomDensity.MEDIUM;
Grace Kloba9804c432009-12-02 11:07:40 -0800128 private static int pageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129
Ben Murdoch0cb81892010-10-08 12:41:33 +0100130
Ben Murdoch23da30e2010-10-26 15:18:44 +0100131 private AutoFillProfile autoFillProfile;
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100132 // Default to zero. In the case no profile is set up, the initial
133 // value will come from the AutoFillSettingsFragment when the user
134 // creates a profile. Otherwise, we'll read the ID of the last used
135 // profile from the prefs db.
136 private int autoFillActiveProfileId;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100137 private static final int NO_AUTOFILL_PROFILE_SET = 0;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100138
The Android Open Source Project0c908882009-03-03 19:32:16 -0800139 // Preference keys that are used outside this class
140 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
141 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
142 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
143 public final static String PREF_HOMEPAGE = "homepage";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100144 public final static String PREF_SEARCH_ENGINE = "search_engine";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800145 public final static String PREF_CLEAR_FORM_DATA =
146 "privacy_clear_form_data";
147 public final static String PREF_CLEAR_PASSWORDS =
148 "privacy_clear_passwords";
149 public final static String PREF_EXTRAS_RESET_DEFAULTS =
150 "reset_default_preferences";
151 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100152 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800153 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700154 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800155 public final static String PREF_DEFAULT_TEXT_ENCODING =
156 "default_text_encoding";
Steve Blockc6f577f2009-08-20 18:11:08 +0100157 public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
158 "privacy_clear_geolocation_access";
Ben Murdochaf554522010-09-10 22:09:30 +0100159 public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled";
160 public final static String PREF_AUTOFILL_PROFILE = "autofill_profile";
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100161 public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id";
John Reck63bb6872010-12-01 19:29:32 -0800162 public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel";
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800163 public final static String PREF_VISUAL_INDICATOR = "enable_visual_indicator";
John Reck63bb6872010-12-01 19:29:32 -0800164 public final static String PREF_USER_AGENT = "user_agent";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800165
Michael Kolb376b5412010-12-15 11:52:57 -0800166 public final static String PREF_QUICK_CONTROLS = "enable_quick_controls";
John Reckbafe58a2011-01-11 10:26:02 -0800167 public final static String PREF_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage";
John Reck282431b2011-01-20 17:38:37 -0800168 public final static String PREF_PLUGIN_STATE = "plugin_state";
Narayan Kamath5119edd2011-02-23 15:49:17 +0000169 public final static String PREF_USE_INSTANT = "use_instant_search";
Michael Kolb376b5412010-12-15 11:52:57 -0800170
The Android Open Source Project0c908882009-03-03 19:32:16 -0800171 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700172 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
173 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800174
175 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700176 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
177 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
178
179 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
180 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
181 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
182
183 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
184 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
185 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800186
187 // Value to truncate strings when adding them to a TextView within
188 // a ListView
189 public final static int MAX_TEXTVIEW_LEN = 80;
190
Jeff Davidson43610292010-07-16 16:03:58 -0700191 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
192
193 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
194
John Reck63bb6872010-12-01 19:29:32 -0800195 // Set to true to enable some of the about:debug options
John Reck9eed0ef2011-01-11 17:11:37 -0800196 public static final boolean DEV_BUILD = false;
John Reck63bb6872010-12-01 19:29:32 -0800197
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800199
200 // Single instance of the BrowserSettings for use in the Browser app.
201 private static BrowserSettings sSingleton;
202
203 // Private map of WebSettings to Observer objects used when deleting an
204 // observer.
205 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
206 new HashMap<WebSettings,Observer>();
207
Ben Murdochef671652010-11-25 17:17:58 +0000208 private boolean mLoadFromDbComplete;
209
210 public void waitForLoadFromDbToComplete() {
211 synchronized (sSingleton) {
212 while (!mLoadFromDbComplete) {
213 try {
214 sSingleton.wait();
215 } catch (InterruptedException e) { }
216 }
217 }
218 }
219
The Android Open Source Project0c908882009-03-03 19:32:16 -0800220 /*
221 * An observer wrapper for updating a WebSettings object with the new
222 * settings after a call to BrowserSettings.update().
223 */
224 static class Observer implements java.util.Observer {
225 // Private WebSettings object that will be updated.
226 private WebSettings mSettings;
227
228 Observer(WebSettings w) {
229 mSettings = w;
230 }
231
232 public void update(Observable o, Object arg) {
233 BrowserSettings b = (BrowserSettings)o;
234 WebSettings s = mSettings;
235
236 s.setLayoutAlgorithm(b.layoutAlgorithm);
237 if (b.userAgent == 0) {
238 // use the default ua string
239 s.setUserAgentString(null);
240 } else if (b.userAgent == 1) {
241 s.setUserAgentString(DESKTOP_USERAGENT);
242 } else if (b.userAgent == 2) {
243 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700244 } else if (b.userAgent == 3) {
245 s.setUserAgentString(IPAD_USERAGENT);
246 } else if (b.userAgent == 4) {
247 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800248 }
249 s.setUseWideViewPort(b.useWideViewPort);
250 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
251 s.setJavaScriptEnabled(b.javaScriptEnabled);
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800252 s.setShowVisualIndicator(b.showVisualIndicator);
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
Narayan Kamath5119edd2011-02-23 15:49:17 +0000413 private void updateSearchEngine(Context ctx, String searchEngineName, boolean force) {
414 if (force || searchEngine == null ||
415 !searchEngine.getName().equals(searchEngineName)) {
416 if (searchEngine != null) {
417 if (searchEngine.supportsVoiceSearch()) {
418 // One or more tabs could have been in voice search mode.
419 // Clear it, since the new SearchEngine may not support
420 // it, or may handle it differently.
421 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
422 mController.getTabControl().getTab(i).revertVoiceSearchMode();
423 }
424 }
425 searchEngine.close();
426 }
427 searchEngine = SearchEngines.get(ctx, searchEngineName);
428
429 if (mController != null && (searchEngine instanceof InstantSearchEngine)) {
430 ((InstantSearchEngine) searchEngine).setController(mController);
431 }
432 }
433 }
434
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100435 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700436
The Android Open Source Project0c908882009-03-03 19:32:16 -0800437 homeUrl =
438 p.getString(PREF_HOMEPAGE, homeUrl);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000439
440 useInstant = p.getBoolean(PREF_USE_INSTANT, useInstant);
Leon Scroggins III31306602010-09-17 11:10:29 -0400441 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
Narayan Kamath5119edd2011-02-23 15:49:17 +0000442 SearchEngine.GOOGLE);
443 updateSearchEngine(ctx, searchEngineName, false);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700444
The Android Open Source Project0c908882009-03-03 19:32:16 -0800445 loadsImagesAutomatically = p.getBoolean("load_images",
446 loadsImagesAutomatically);
447 javaScriptEnabled = p.getBoolean("enable_javascript",
448 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400449 pluginState = WebSettings.PluginState.valueOf(
John Reck282431b2011-01-20 17:38:37 -0800450 p.getString(PREF_PLUGIN_STATE, pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800451 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
452 "block_popup_windows",
453 !javaScriptCanOpenWindowsAutomatically);
454 showSecurityWarnings = p.getBoolean("show_security_warnings",
455 showSecurityWarnings);
456 rememberPasswords = p.getBoolean("remember_passwords",
457 rememberPasswords);
458 saveFormData = p.getBoolean("save_formdata",
459 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100460 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800461 boolean accept_cookies = p.getBoolean("accept_cookies",
462 CookieManager.getInstance().acceptCookie());
463 CookieManager.getInstance().setAcceptCookie(accept_cookies);
464 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800465 textSize = WebSettings.TextSize.valueOf(
466 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700467 zoomDensity = WebSettings.ZoomDensity.valueOf(
468 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800469 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700470 loadsPageInOverviewMode = p.getBoolean("load_page",
471 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800472 useWideViewPort = true; // use wide view port for either setting
473 if (autoFitPage) {
474 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
475 } else {
476 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
477 }
478 defaultTextEncodingName =
479 p.getString(PREF_DEFAULT_TEXT_ENCODING,
480 defaultTextEncodingName);
481
482 showDebugSettings =
483 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
484 // Debug menu items have precidence if the menu is visible
485 if (showDebugSettings) {
486 boolean small_screen = p.getBoolean("small_screen",
487 layoutAlgorithm ==
488 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
489 if (small_screen) {
490 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
491 } else {
492 boolean normal_layout = p.getBoolean("normal_layout",
493 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
494 if (normal_layout) {
495 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
496 } else {
497 layoutAlgorithm =
498 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
499 }
500 }
501 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
502 tracing = p.getBoolean("enable_tracing", tracing);
503 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
504 navDump = p.getBoolean("enable_nav_dump", navDump);
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800505 showVisualIndicator = p.getBoolean(PREF_VISUAL_INDICATOR, showVisualIndicator);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800506 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500507
Michael Kolb376b5412010-12-15 11:52:57 -0800508 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800509 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
Michael Kolb376b5412010-12-15 11:52:57 -0800510
John Reck3db2e072011-01-24 14:57:18 -0800511 // Only set these if this is a dev build or debug is enabled
512 if (DEV_BUILD || showDebugSettings()) {
John Reck63bb6872010-12-01 19:29:32 -0800513 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
514 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
515 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500516
Feng Qianb3c02da2009-06-29 15:58:08 -0700517 // JS flags is loaded from DB even if showDebugSettings is false,
518 // so that it can be set once and be effective all the time.
519 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100520
521 // Read the setting for showing/hiding the JS Console always so that should the
522 // user enable debug settings, we already know if we should show the console.
523 // The user will never see the console unless they navigate to about:debug,
524 // regardless of the setting we read here. This setting is only used after debug
525 // is enabled.
526 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700527
Andrei Popescu01068702009-08-03 16:03:24 +0100528 // HTML5 API flags
529 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
530 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
531 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100532 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100533 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100534
Grace Klobad9ee1392009-07-20 11:53:33 -0700535 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800536 }
537
The Android Open Source Project0c908882009-03-03 19:32:16 -0800538 public String getHomePage() {
John Reckbafe58a2011-01-11 10:26:02 -0800539 if (useMostVisitedHomepage) {
540 return HomeProvider.MOST_VISITED;
541 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800542 return homeUrl;
543 }
544
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100545 public SearchEngine getSearchEngine() {
546 return searchEngine;
547 }
548
Feng Qianb3c02da2009-06-29 15:58:08 -0700549 public String getJsFlags() {
550 return jsFlags;
551 }
552
Andrei Popescu79e82b72009-07-27 12:01:59 +0100553 public WebStorageSizeManager getWebStorageSizeManager() {
554 return webStorageSizeManager;
555 }
556
The Android Open Source Project0c908882009-03-03 19:32:16 -0800557 public void setHomePage(Context context, String url) {
558 Editor ed = PreferenceManager.
559 getDefaultSharedPreferences(context).edit();
560 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700561 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800562 homeUrl = url;
563 }
564
The Android Open Source Project0c908882009-03-03 19:32:16 -0800565 public WebSettings.TextSize getTextSize() {
566 return textSize;
567 }
568
Grace Kloba2f830682009-06-25 11:08:53 -0700569 public WebSettings.ZoomDensity getDefaultZoom() {
570 return zoomDensity;
571 }
572
The Android Open Source Project0c908882009-03-03 19:32:16 -0800573 public boolean openInBackground() {
574 return openInBackground;
575 }
576
577 public boolean showSecurityWarnings() {
578 return showSecurityWarnings;
579 }
580
581 public boolean isTracing() {
582 return tracing;
583 }
584
585 public boolean isLightTouch() {
586 return lightTouch;
587 }
588
589 public boolean isNavDump() {
590 return navDump;
591 }
592
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500593 public boolean isHardwareAccelerated() {
594 return hardwareAccelerated;
595 }
596
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800597 public boolean showVisualIndicator() {
598 return showVisualIndicator;
599 }
600
Michael Kolb376b5412010-12-15 11:52:57 -0800601 public boolean useQuickControls() {
602 return quickControls;
603 }
604
John Reckbafe58a2011-01-11 10:26:02 -0800605 public boolean useMostVisitedHomepage() {
606 return useMostVisitedHomepage;
607 }
608
Narayan Kamath5119edd2011-02-23 15:49:17 +0000609 public boolean useInstant() {
610 return useInstant;
611 }
612
The Android Open Source Project0c908882009-03-03 19:32:16 -0800613 public boolean showDebugSettings() {
614 return showDebugSettings;
615 }
616
John Reck3db2e072011-01-24 14:57:18 -0800617 public void toggleDebugSettings(Context context) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800618 showDebugSettings = !showDebugSettings;
619 navDump = showDebugSettings;
John Reck3db2e072011-01-24 14:57:18 -0800620 syncSharedPreferences(context,
621 PreferenceManager.getDefaultSharedPreferences(context));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800622 update();
623 }
624
Ben Murdoch23da30e2010-10-26 15:18:44 +0100625 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
626 if (profile != null) {
627 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
628 // Update the AutoFill DB with the new profile.
629 new SaveProfileToDbTask(ctx, msg).execute(profile);
630 } else {
631 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000632 if (autoFillProfile != null) {
633 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
634 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
635 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100636 }
637 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100638 }
639
640 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100641 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100642 }
643
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100644 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
645 autoFillActiveProfileId = activeProfileId;
646 Editor ed = PreferenceManager.
647 getDefaultSharedPreferences(context).edit();
648 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
649 ed.apply();
650 }
651
Ben Murdoch8029a772010-11-16 11:58:21 +0000652 /* package */ void disableAutoFill(Context ctx) {
653 autoFillEnabled = false;
654 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
655 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
656 ed.apply();
657 }
658
The Android Open Source Project0c908882009-03-03 19:32:16 -0800659 /**
660 * Add a WebSettings object to the list of observers that will be updated
661 * when update() is called.
662 *
663 * @param s A WebSettings object that is strictly tied to the life of a
664 * WebView.
665 */
666 public Observer addObserver(WebSettings s) {
667 Observer old = mWebSettingsToObservers.get(s);
668 if (old != null) {
669 super.deleteObserver(old);
670 }
671 Observer o = new Observer(s);
672 mWebSettingsToObservers.put(s, o);
673 super.addObserver(o);
674 return o;
675 }
676
677 /**
678 * Delete the given WebSettings observer from the list of observers.
679 * @param s The WebSettings object to be deleted.
680 */
681 public void deleteObserver(WebSettings s) {
682 Observer o = mWebSettingsToObservers.get(s);
683 if (o != null) {
684 mWebSettingsToObservers.remove(s);
685 super.deleteObserver(o);
686 }
687 }
688
689 /*
John Reck63bb6872010-12-01 19:29:32 -0800690 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800691 * BrowserSettings.
692 */
John Reck63bb6872010-12-01 19:29:32 -0800693 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800694 if (sSingleton == null ) {
695 sSingleton = new BrowserSettings();
696 }
697 return sSingleton;
698 }
699
700 /*
701 * Package level method for associating the BrowserSettings with TabControl
702 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 /* package */void setController(Controller ctrl) {
704 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800705 updateTabControlSettings();
Narayan Kamath5119edd2011-02-23 15:49:17 +0000706
707 if (mController != null && (searchEngine instanceof InstantSearchEngine)) {
708 ((InstantSearchEngine) searchEngine).setController(mController);
709 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800710 }
711
712 /*
713 * Update all the observers of the object.
714 */
715 /*package*/ void update() {
716 setChanged();
717 notifyObservers();
718 }
719
720 /*package*/ void clearCache(Context context) {
721 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700722 if (mController != null) {
723 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800724 if (current != null) {
725 current.clearCache(true);
726 }
727 }
728 }
729
730 /*package*/ void clearCookies(Context context) {
731 CookieManager.getInstance().removeAllCookie();
732 }
733
734 /* package */void clearHistory(Context context) {
735 ContentResolver resolver = context.getContentResolver();
736 Browser.clearHistory(resolver);
737 Browser.clearSearches(resolver);
738 }
739
740 /* package */ void clearFormData(Context context) {
741 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700742 if (mController!= null) {
743 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100744 if (currentTopView != null) {
745 currentTopView.clearFormData();
746 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800747 }
748 }
749
750 /*package*/ void clearPasswords(Context context) {
751 WebViewDatabase db = WebViewDatabase.getInstance(context);
752 db.clearUsernamePassword();
753 db.clearHttpAuthUsernamePassword();
754 }
755
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800756 private void updateTabControlSettings() {
757 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700758 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800759 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800760 }
761
Nicolas Roard78a98e42009-05-11 13:34:17 +0100762 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100763 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100764 }
765
766 /*package*/ void clearLocationAccess(Context context) {
767 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100768 }
769
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400770 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800771 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500772 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700773 p.edit().clear().apply();
John Reck035a5642010-12-21 18:51:27 -0800774 PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true);
775 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500776 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700777 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700778 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100779 // reset appcache max size
780 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100781 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700782 }
783
John Reck33bbb802010-10-26 17:13:42 -0700784 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700785 String url = context.getResources().getString(R.string.homepage_base);
786 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500787 url = url.replace("{CID}",
788 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700789 }
790 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800791 }
792
The Android Open Source Project0c908882009-03-03 19:32:16 -0800793 // Private constructor that does nothing.
794 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800795 reset();
796 }
797
798 private void reset() {
799 // Private variables for settings
800 // NOTE: these defaults need to be kept in sync with the XML
801 // until the performance of PreferenceManager.setDefaultValues()
802 // is improved.
803 loadsImagesAutomatically = true;
804 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400805 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800806 javaScriptCanOpenWindowsAutomatically = false;
807 showSecurityWarnings = true;
808 rememberPasswords = true;
809 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000810 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800811 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800812 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800813 loadsPageInOverviewMode = true;
814 showDebugSettings = false;
815 // HTML5 API flags
816 appCacheEnabled = true;
817 databaseEnabled = true;
818 domStorageEnabled = true;
819 geolocationEnabled = true;
820 workersEnabled = true; // only affects V8. JSC does not have a similar setting
The Android Open Source Project0c908882009-03-03 19:32:16 -0800821 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100822
Ben Murdoch23da30e2010-10-26 15:18:44 +0100823 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100824 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100825 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100826 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100827
Ben Murdoch23da30e2010-10-26 15:18:44 +0100828 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100829 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100830 mCompleteMessage = msg;
831 }
832
833 protected void onPostExecute(Void result) {
834 if (mCompleteMessage != null) {
835 mCompleteMessage.sendToTarget();
836 }
837 mAutoFillProfileDb.close();
838 }
839
840 abstract protected Void doInBackground(T... values);
841 }
842
843
844 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
845 public SaveProfileToDbTask(Context ctx, Message msg) {
846 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100847 }
848
849 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100850 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100851 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
852 AutoFillProfile newProfile = values[0];
853 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100854 return null;
855 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100856 }
857
Ben Murdoch23da30e2010-10-26 15:18:44 +0100858 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
859 public DeleteProfileFromDbTask(Context ctx, Message msg) {
860 super(ctx, msg);
861 }
862
863 protected Void doInBackground(Integer... values) {
864 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
865 int id = values[0];
866 assert id > 0;
867 mAutoFillProfileDb.dropProfile(id);
868 return null;
869 }
870 }
John Reck63bb6872010-12-01 19:29:32 -0800871
872 @Override
873 public void onSharedPreferenceChanged(
874 SharedPreferences p, String key) {
875 if (PREF_HARDWARE_ACCEL.equals(key)) {
876 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
Teng-Hui Zhu930ea222011-02-16 11:22:21 -0800877 } else if (PREF_VISUAL_INDICATOR.equals(key)) {
878 showVisualIndicator = p.getBoolean(PREF_VISUAL_INDICATOR, showVisualIndicator);
John Reck63bb6872010-12-01 19:29:32 -0800879 } else if (PREF_USER_AGENT.equals(key)) {
880 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
881 update();
Michael Kolb376b5412010-12-15 11:52:57 -0800882 } else if (PREF_QUICK_CONTROLS.equals(key)) {
883 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reckbafe58a2011-01-11 10:26:02 -0800884 } else if (PREF_MOST_VISITED_HOMEPAGE.equals(key)) {
885 useMostVisitedHomepage = p.getBoolean(PREF_MOST_VISITED_HOMEPAGE, useMostVisitedHomepage);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000886 } else if (PREF_USE_INSTANT.equals(key)) {
887 useInstant = p.getBoolean(PREF_USE_INSTANT, useInstant);
888 updateSearchEngine(mController.getActivity(), SearchEngine.GOOGLE, true);
889 } else if (PREF_SEARCH_ENGINE.equals(key)) {
890 final String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
891 SearchEngine.GOOGLE);
892 updateSearchEngine(mController.getActivity(), searchEngineName, false);
John Reck63bb6872010-12-01 19:29:32 -0800893 }
894 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800895}