blob: 267056e20ec000f777489a53da6f462aa743571d [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
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010020import com.android.browser.search.SearchEngine;
21import com.android.browser.search.SearchEngines;
22
Grace Kloba9804c432009-12-02 11:07:40 -080023import android.app.ActivityManager;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010024import android.content.ComponentName;
The Android Open Source Project0c908882009-03-03 19:32:16 -080025import android.content.ContentResolver;
26import android.content.Context;
John Reck63bb6872010-12-01 19:29:32 -080027import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.content.pm.ActivityInfo;
29import android.content.SharedPreferences;
30import android.content.SharedPreferences.Editor;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010031import android.database.ContentObserver;
Ben Murdoch0cb81892010-10-08 12:41:33 +010032import android.database.Cursor;
Jeff Davidson43610292010-07-16 16:03:58 -070033import android.net.Uri;
Ben Murdoch0cb81892010-10-08 12:41:33 +010034import android.os.AsyncTask;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010035import android.os.Handler;
Ben Murdoch23da30e2010-10-26 15:18:44 +010036import android.os.Message;
Nicolas Roard78a98e42009-05-11 13:34:17 +010037import android.preference.PreferenceActivity;
Ben Murdoch0cb81892010-10-08 12:41:33 +010038import android.preference.PreferenceManager;
Nicolas Roard78a98e42009-05-11 13:34:17 +010039import android.preference.PreferenceScreen;
Ben Murdoch0cb81892010-10-08 12:41:33 +010040import android.provider.Browser;
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010041import android.provider.Settings;
42import android.util.Log;
The Android Open Source Project0c908882009-03-03 19:32:16 -080043import android.webkit.CookieManager;
Steve Blockf344d032009-07-30 10:50:45 +010044import android.webkit.GeolocationPermissions;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010045import android.webkit.ValueCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046import android.webkit.WebView;
47import android.webkit.WebViewDatabase;
48import android.webkit.WebIconDatabase;
49import android.webkit.WebSettings;
Ben Murdoch0cb81892010-10-08 12:41:33 +010050import android.webkit.WebSettings.AutoFillProfile;
Nicolas Roard78a98e42009-05-11 13:34:17 +010051import android.webkit.WebStorage;
Ben Murdoch0cb81892010-10-08 12:41:33 +010052import android.widget.Toast;
The Android Open Source Project0c908882009-03-03 19:32:16 -080053
54import java.util.HashMap;
Nicolas Roard99b3ae12009-09-22 15:17:52 +010055import java.util.Map;
56import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080057import java.util.Observable;
58
59/*
60 * Package level class for storing various WebView and Browser settings. To use
61 * this class:
62 * BrowserSettings s = BrowserSettings.getInstance();
63 * s.addObserver(webView.getSettings());
64 * s.loadFromDb(context); // Only needed on app startup
65 * s.javaScriptEnabled = true;
66 * ... // set any other settings
67 * s.update(); // this will update all the observers
68 *
69 * To remove an observer:
70 * s.deleteObserver(webView.getSettings());
71 */
John Reck63bb6872010-12-01 19:29:32 -080072public class BrowserSettings extends Observable implements OnSharedPreferenceChangeListener {
Leon Scroggins9ac587d2009-04-20 12:53:46 -040073 // Private variables for settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080074 // NOTE: these defaults need to be kept in sync with the XML
75 // until the performance of PreferenceManager.setDefaultValues()
76 // is improved.
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080077 // Note: boolean variables are set inside reset function.
78 private boolean loadsImagesAutomatically;
79 private boolean javaScriptEnabled;
Patrick Scotte536b332010-03-22 10:19:32 -040080 private WebSettings.PluginState pluginState;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080081 private boolean javaScriptCanOpenWindowsAutomatically;
82 private boolean showSecurityWarnings;
83 private boolean rememberPasswords;
84 private boolean saveFormData;
Ben Murdochce549fc2010-09-09 10:28:08 +010085 private boolean autoFillEnabled;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080086 private boolean openInBackground;
The Android Open Source Project0c908882009-03-03 19:32:16 -080087 private String defaultTextEncodingName;
Grace Klobaf2c5c1b2009-05-26 10:48:31 -070088 private String homeUrl = "";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +010089 private SearchEngine searchEngine;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080090 private boolean autoFitPage;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080091 private boolean loadsPageInOverviewMode;
92 private boolean showDebugSettings;
Andrei Popescu01068702009-08-03 16:03:24 +010093 // HTML5 API flags
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -080094 private boolean appCacheEnabled;
95 private boolean databaseEnabled;
96 private boolean domStorageEnabled;
97 private boolean geolocationEnabled;
98 private boolean workersEnabled; // only affects V8. JSC does not have a similar setting
Andrei Popescu01068702009-08-03 16:03:24 +010099 // HTML5 API configuration params
100 private long appCacheMaxSize = Long.MAX_VALUE;
101 private String appCachePath; // default value set in loadFromDb().
102 private String databasePath; // default value set in loadFromDb()
Steve Block5029cf02009-08-21 13:16:58 +0100103 private String geolocationDatabasePath; // default value set in loadFromDb()
Andrei Popescu01068702009-08-03 16:03:24 +0100104 private WebStorageSizeManager webStorageSizeManager;
105
106 private String jsFlags = "";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800107
Nicolas Roard78a98e42009-05-11 13:34:17 +0100108 private final static String TAG = "BrowserSettings";
109
The Android Open Source Project0c908882009-03-03 19:32:16 -0800110 // Development settings
111 public WebSettings.LayoutAlgorithm layoutAlgorithm =
112 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
113 private boolean useWideViewPort = true;
114 private int userAgent = 0;
115 private boolean tracing = false;
116 private boolean lightTouch = false;
117 private boolean navDump = false;
Derek Sollenberger8de82852010-11-18 19:51:50 -0500118 private boolean hardwareAccelerated = true;
Feng Qianb3c02da2009-06-29 15:58:08 -0700119
Michael Kolb376b5412010-12-15 11:52:57 -0800120 // Lab settings
121 private boolean quickControls = false;
122
Ben Murdochbff2d602009-07-01 20:19:05 +0100123 // By default the error console is shown once the user navigates to about:debug.
124 // The setting can be then toggled from the settings menu.
125 private boolean showConsole = true;
126
The Android Open Source Project0c908882009-03-03 19:32:16 -0800127 // Private preconfigured values
Shimeng (Simon) Wangb4fb25c2010-07-13 15:18:10 -0700128 private static int minimumFontSize = 1;
129 private static int minimumLogicalFontSize = 1;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130 private static int defaultFontSize = 16;
131 private static int defaultFixedFontSize = 13;
132 private static WebSettings.TextSize textSize =
133 WebSettings.TextSize.NORMAL;
Grace Kloba2f830682009-06-25 11:08:53 -0700134 private static WebSettings.ZoomDensity zoomDensity =
135 WebSettings.ZoomDensity.MEDIUM;
Grace Kloba9804c432009-12-02 11:07:40 -0800136 private static int pageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800137
Ben Murdoch0cb81892010-10-08 12:41:33 +0100138
Ben Murdoch23da30e2010-10-26 15:18:44 +0100139 private AutoFillProfile autoFillProfile;
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100140 // Default to zero. In the case no profile is set up, the initial
141 // value will come from the AutoFillSettingsFragment when the user
142 // creates a profile. Otherwise, we'll read the ID of the last used
143 // profile from the prefs db.
144 private int autoFillActiveProfileId;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100145 private static final int NO_AUTOFILL_PROFILE_SET = 0;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100146
The Android Open Source Project0c908882009-03-03 19:32:16 -0800147 // Preference keys that are used outside this class
148 public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
149 public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies";
150 public final static String PREF_CLEAR_HISTORY = "privacy_clear_history";
151 public final static String PREF_HOMEPAGE = "homepage";
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100152 public final static String PREF_SEARCH_ENGINE = "search_engine";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800153 public final static String PREF_CLEAR_FORM_DATA =
154 "privacy_clear_form_data";
155 public final static String PREF_CLEAR_PASSWORDS =
156 "privacy_clear_passwords";
157 public final static String PREF_EXTRAS_RESET_DEFAULTS =
158 "reset_default_preferences";
159 public final static String PREF_DEBUG_SETTINGS = "debug_menu";
Nicolas Roarde46990e2009-06-19 16:27:49 +0100160 public final static String PREF_WEBSITE_SETTINGS = "website_settings";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800161 public final static String PREF_TEXT_SIZE = "text_size";
Grace Kloba2f830682009-06-25 11:08:53 -0700162 public final static String PREF_DEFAULT_ZOOM = "default_zoom";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800163 public final static String PREF_DEFAULT_TEXT_ENCODING =
164 "default_text_encoding";
Steve Blockc6f577f2009-08-20 18:11:08 +0100165 public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
166 "privacy_clear_geolocation_access";
Ben Murdochaf554522010-09-10 22:09:30 +0100167 public final static String PREF_AUTOFILL_ENABLED = "autofill_enabled";
168 public final static String PREF_AUTOFILL_PROFILE = "autofill_profile";
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100169 public final static String PREF_AUTOFILL_ACTIVE_PROFILE_ID = "autofill_active_profile_id";
John Reck63bb6872010-12-01 19:29:32 -0800170 public final static String PREF_HARDWARE_ACCEL = "enable_hardware_accel";
171 public final static String PREF_USER_AGENT = "user_agent";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800172
Michael Kolb376b5412010-12-15 11:52:57 -0800173 public final static String PREF_QUICK_CONTROLS = "enable_quick_controls";
174
The Android Open Source Project0c908882009-03-03 19:32:16 -0800175 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700176 "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
177 "like Gecko) Version/5.0 Safari/533.16";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800178
179 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
Bart Searsf6915fb2010-07-08 19:58:22 -0700180 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
181 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
182
183 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
184 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
185 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
186
187 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
188 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
189 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800190
191 // Value to truncate strings when adding them to a TextView within
192 // a ListView
193 public final static int MAX_TEXTVIEW_LEN = 80;
194
Jeff Davidson43610292010-07-16 16:03:58 -0700195 public static final String RLZ_PROVIDER = "com.google.android.partnersetup.rlzappprovider";
196
197 public static final Uri RLZ_PROVIDER_URI = Uri.parse("content://" + RLZ_PROVIDER + "/");
198
John Reck63bb6872010-12-01 19:29:32 -0800199 // Set to true to enable some of the about:debug options
200 public static final boolean DEV_BUILD = true;
201
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 private Controller mController;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800203
204 // Single instance of the BrowserSettings for use in the Browser app.
205 private static BrowserSettings sSingleton;
206
207 // Private map of WebSettings to Observer objects used when deleting an
208 // observer.
209 private HashMap<WebSettings,Observer> mWebSettingsToObservers =
210 new HashMap<WebSettings,Observer>();
211
Ben Murdochef671652010-11-25 17:17:58 +0000212 private boolean mLoadFromDbComplete;
213
214 public void waitForLoadFromDbToComplete() {
215 synchronized (sSingleton) {
216 while (!mLoadFromDbComplete) {
217 try {
218 sSingleton.wait();
219 } catch (InterruptedException e) { }
220 }
221 }
222 }
223
The Android Open Source Project0c908882009-03-03 19:32:16 -0800224 /*
225 * An observer wrapper for updating a WebSettings object with the new
226 * settings after a call to BrowserSettings.update().
227 */
228 static class Observer implements java.util.Observer {
229 // Private WebSettings object that will be updated.
230 private WebSettings mSettings;
231
232 Observer(WebSettings w) {
233 mSettings = w;
234 }
235
236 public void update(Observable o, Object arg) {
237 BrowserSettings b = (BrowserSettings)o;
238 WebSettings s = mSettings;
239
240 s.setLayoutAlgorithm(b.layoutAlgorithm);
241 if (b.userAgent == 0) {
242 // use the default ua string
243 s.setUserAgentString(null);
244 } else if (b.userAgent == 1) {
245 s.setUserAgentString(DESKTOP_USERAGENT);
246 } else if (b.userAgent == 2) {
247 s.setUserAgentString(IPHONE_USERAGENT);
Bart Searsf6915fb2010-07-08 19:58:22 -0700248 } else if (b.userAgent == 3) {
249 s.setUserAgentString(IPAD_USERAGENT);
250 } else if (b.userAgent == 4) {
251 s.setUserAgentString(FROYO_USERAGENT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800252 }
253 s.setUseWideViewPort(b.useWideViewPort);
254 s.setLoadsImagesAutomatically(b.loadsImagesAutomatically);
255 s.setJavaScriptEnabled(b.javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400256 s.setPluginState(b.pluginState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800257 s.setJavaScriptCanOpenWindowsAutomatically(
258 b.javaScriptCanOpenWindowsAutomatically);
259 s.setDefaultTextEncodingName(b.defaultTextEncodingName);
260 s.setMinimumFontSize(b.minimumFontSize);
261 s.setMinimumLogicalFontSize(b.minimumLogicalFontSize);
262 s.setDefaultFontSize(b.defaultFontSize);
263 s.setDefaultFixedFontSize(b.defaultFixedFontSize);
264 s.setNavDump(b.navDump);
265 s.setTextSize(b.textSize);
Grace Kloba2f830682009-06-25 11:08:53 -0700266 s.setDefaultZoom(b.zoomDensity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800267 s.setLightTouchEnabled(b.lightTouch);
268 s.setSaveFormData(b.saveFormData);
Ben Murdochce549fc2010-09-09 10:28:08 +0100269 s.setAutoFillEnabled(b.autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800270 s.setSavePassword(b.rememberPasswords);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700271 s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
Grace Kloba79565032009-11-24 14:23:39 -0800272 s.setPageCacheCapacity(pageCacheCapacity);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800273
274 // WebView inside Browser doesn't want initial focus to be set.
275 s.setNeedInitialFocus(false);
276 // Browser supports multiple windows
277 s.setSupportMultipleWindows(true);
Grace Kloba61fc77c2010-06-22 09:57:33 -0700278 // enable smooth transition for better performance during panning or
279 // zooming
280 s.setEnableSmoothTransition(true);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100281
Andrei Popescu01068702009-08-03 16:03:24 +0100282 // HTML5 API flags
283 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100284 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100285 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100286 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100287 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100288
Andrei Popescu01068702009-08-03 16:03:24 +0100289 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100290 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100291 s.setAppCachePath(b.appCachePath);
292 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100293 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100294
Ben Murdoch0cb81892010-10-08 12:41:33 +0100295 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100296 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100297
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800298 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800299 }
300 }
301
302 /**
Ben Murdochef671652010-11-25 17:17:58 +0000303 * Load settings from the browser app's database. It is performed in
304 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800305 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500306 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800307 * @param ctx A Context object used to query the browser's settings
308 * database. If the database exists, the saved settings will be
309 * stored in this BrowserSettings object. This will update all
310 * observers of this object.
311 */
Ben Murdochef671652010-11-25 17:17:58 +0000312 public void asyncLoadFromDb(final Context ctx) {
313 mLoadFromDbComplete = false;
314 // Run the initial settings load in an AsyncTask as it hits the
315 // disk multiple times through SharedPreferences and SQLite. We
316 // need to be certain though that this has completed before we start
317 // to load pages though, so in the worst case we will block waiting
318 // for it to finish in BrowserActivity.onCreate().
319 new LoadFromDbTask(ctx).execute();
320 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800321
Ben Murdochef671652010-11-25 17:17:58 +0000322 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
323 private Context mContext;
324
325 public LoadFromDbTask(Context context) {
326 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700327 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700328
Ben Murdochef671652010-11-25 17:17:58 +0000329 protected Void doInBackground(Void... unused) {
330 SharedPreferences p =
331 PreferenceManager.getDefaultSharedPreferences(mContext);
332 // Set the default value for the Application Caches path.
333 appCachePath = mContext.getDir("appcache", 0).getPath();
334 // Determine the maximum size of the application cache.
335 webStorageSizeManager = new WebStorageSizeManager(
336 mContext,
337 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
338 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
339 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
340 // Set the default value for the Database path.
341 databasePath = mContext.getDir("databases", 0).getPath();
342 // Set the default value for the Geolocation database path.
343 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
344
John Reckef074262010-12-02 16:09:14 -0800345 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000346 // No home page preferences is set, set it to default.
347 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
348 }
349
350 // the cost of one cached page is ~3M (measured using nytimes.com). For
351 // low end devices, we only cache one page. For high end devices, we try
352 // to cache more pages, currently choose 5.
353 ActivityManager am = (ActivityManager) mContext
354 .getSystemService(Context.ACTIVITY_SERVICE);
355 if (am.getMemoryClass() > 16) {
356 pageCacheCapacity = 5;
357 } else {
358 pageCacheCapacity = 1;
359 }
360
361 // Read the last active AutoFill profile id.
362 autoFillActiveProfileId = p.getInt(
363 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
364
365 // Load the autofill profile data from the database. We use a database separate
366 // to the browser preference DB to make it easier to support multiple profiles
367 // and switching between them.
368 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
369 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
370
371 if (c.getCount() > 0) {
372 c.moveToFirst();
373
374 String fullName = c.getString(c.getColumnIndex(
375 AutoFillProfileDatabase.Profiles.FULL_NAME));
376 String email = c.getString(c.getColumnIndex(
377 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
378 String company = c.getString(c.getColumnIndex(
379 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
380 String addressLine1 = c.getString(c.getColumnIndex(
381 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
382 String addressLine2 = c.getString(c.getColumnIndex(
383 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
384 String city = c.getString(c.getColumnIndex(
385 AutoFillProfileDatabase.Profiles.CITY));
386 String state = c.getString(c.getColumnIndex(
387 AutoFillProfileDatabase.Profiles.STATE));
388 String zip = c.getString(c.getColumnIndex(
389 AutoFillProfileDatabase.Profiles.ZIP_CODE));
390 String country = c.getString(c.getColumnIndex(
391 AutoFillProfileDatabase.Profiles.COUNTRY));
392 String phone = c.getString(c.getColumnIndex(
393 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
394 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
395 fullName, email, company, addressLine1, addressLine2, city,
396 state, zip, country, phone);
397 }
398 c.close();
399 autoFillDb.close();
400
401 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
402 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800403 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000404 syncSharedPreferences(mContext, p);
405
406 synchronized (sSingleton) {
407 mLoadFromDbComplete = true;
408 sSingleton.notify();
409 }
410 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800411 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800412 }
413
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100414 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700415
The Android Open Source Project0c908882009-03-03 19:32:16 -0800416 homeUrl =
417 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400418 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
419 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100420 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
421 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400422 if (searchEngine.supportsVoiceSearch()) {
423 // One or more tabs could have been in voice search mode.
424 // Clear it, since the new SearchEngine may not support
425 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
427 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400428 }
429 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100430 searchEngine.close();
431 }
432 searchEngine = SearchEngines.get(ctx, searchEngineName);
433 }
434 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700435
The Android Open Source Project0c908882009-03-03 19:32:16 -0800436 loadsImagesAutomatically = p.getBoolean("load_images",
437 loadsImagesAutomatically);
438 javaScriptEnabled = p.getBoolean("enable_javascript",
439 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400440 pluginState = WebSettings.PluginState.valueOf(
441 p.getString("plugin_state", pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800442 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
443 "block_popup_windows",
444 !javaScriptCanOpenWindowsAutomatically);
445 showSecurityWarnings = p.getBoolean("show_security_warnings",
446 showSecurityWarnings);
447 rememberPasswords = p.getBoolean("remember_passwords",
448 rememberPasswords);
449 saveFormData = p.getBoolean("save_formdata",
450 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100451 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800452 boolean accept_cookies = p.getBoolean("accept_cookies",
453 CookieManager.getInstance().acceptCookie());
454 CookieManager.getInstance().setAcceptCookie(accept_cookies);
455 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800456 textSize = WebSettings.TextSize.valueOf(
457 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700458 zoomDensity = WebSettings.ZoomDensity.valueOf(
459 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800460 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700461 loadsPageInOverviewMode = p.getBoolean("load_page",
462 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800463 useWideViewPort = true; // use wide view port for either setting
464 if (autoFitPage) {
465 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
466 } else {
467 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
468 }
469 defaultTextEncodingName =
470 p.getString(PREF_DEFAULT_TEXT_ENCODING,
471 defaultTextEncodingName);
472
473 showDebugSettings =
474 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
475 // Debug menu items have precidence if the menu is visible
476 if (showDebugSettings) {
477 boolean small_screen = p.getBoolean("small_screen",
478 layoutAlgorithm ==
479 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
480 if (small_screen) {
481 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
482 } else {
483 boolean normal_layout = p.getBoolean("normal_layout",
484 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
485 if (normal_layout) {
486 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
487 } else {
488 layoutAlgorithm =
489 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
490 }
491 }
492 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
493 tracing = p.getBoolean("enable_tracing", tracing);
494 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
495 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800496 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500497
Michael Kolb376b5412010-12-15 11:52:57 -0800498 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
499
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
Grace Klobad9ee1392009-07-20 11:53:33 -0700524 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800525 }
526
The Android Open Source Project0c908882009-03-03 19:32:16 -0800527 public String getHomePage() {
528 return homeUrl;
529 }
530
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100531 public SearchEngine getSearchEngine() {
532 return searchEngine;
533 }
534
Feng Qianb3c02da2009-06-29 15:58:08 -0700535 public String getJsFlags() {
536 return jsFlags;
537 }
538
Andrei Popescu79e82b72009-07-27 12:01:59 +0100539 public WebStorageSizeManager getWebStorageSizeManager() {
540 return webStorageSizeManager;
541 }
542
The Android Open Source Project0c908882009-03-03 19:32:16 -0800543 public void setHomePage(Context context, String url) {
544 Editor ed = PreferenceManager.
545 getDefaultSharedPreferences(context).edit();
546 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700547 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800548 homeUrl = url;
549 }
550
The Android Open Source Project0c908882009-03-03 19:32:16 -0800551 public WebSettings.TextSize getTextSize() {
552 return textSize;
553 }
554
Grace Kloba2f830682009-06-25 11:08:53 -0700555 public WebSettings.ZoomDensity getDefaultZoom() {
556 return zoomDensity;
557 }
558
The Android Open Source Project0c908882009-03-03 19:32:16 -0800559 public boolean openInBackground() {
560 return openInBackground;
561 }
562
563 public boolean showSecurityWarnings() {
564 return showSecurityWarnings;
565 }
566
567 public boolean isTracing() {
568 return tracing;
569 }
570
571 public boolean isLightTouch() {
572 return lightTouch;
573 }
574
575 public boolean isNavDump() {
576 return navDump;
577 }
578
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500579 public boolean isHardwareAccelerated() {
580 return hardwareAccelerated;
581 }
582
Michael Kolb376b5412010-12-15 11:52:57 -0800583 public boolean useQuickControls() {
584 return quickControls;
585 }
586
The Android Open Source Project0c908882009-03-03 19:32:16 -0800587 public boolean showDebugSettings() {
588 return showDebugSettings;
589 }
590
591 public void toggleDebugSettings() {
592 showDebugSettings = !showDebugSettings;
593 navDump = showDebugSettings;
594 update();
595 }
596
Ben Murdoch23da30e2010-10-26 15:18:44 +0100597 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
598 if (profile != null) {
599 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
600 // Update the AutoFill DB with the new profile.
601 new SaveProfileToDbTask(ctx, msg).execute(profile);
602 } else {
603 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000604 if (autoFillProfile != null) {
605 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
606 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
607 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100608 }
609 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100610 }
611
612 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100613 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100614 }
615
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100616 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
617 autoFillActiveProfileId = activeProfileId;
618 Editor ed = PreferenceManager.
619 getDefaultSharedPreferences(context).edit();
620 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
621 ed.apply();
622 }
623
Ben Murdoch8029a772010-11-16 11:58:21 +0000624 /* package */ void disableAutoFill(Context ctx) {
625 autoFillEnabled = false;
626 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
627 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
628 ed.apply();
629 }
630
The Android Open Source Project0c908882009-03-03 19:32:16 -0800631 /**
632 * Add a WebSettings object to the list of observers that will be updated
633 * when update() is called.
634 *
635 * @param s A WebSettings object that is strictly tied to the life of a
636 * WebView.
637 */
638 public Observer addObserver(WebSettings s) {
639 Observer old = mWebSettingsToObservers.get(s);
640 if (old != null) {
641 super.deleteObserver(old);
642 }
643 Observer o = new Observer(s);
644 mWebSettingsToObservers.put(s, o);
645 super.addObserver(o);
646 return o;
647 }
648
649 /**
650 * Delete the given WebSettings observer from the list of observers.
651 * @param s The WebSettings object to be deleted.
652 */
653 public void deleteObserver(WebSettings s) {
654 Observer o = mWebSettingsToObservers.get(s);
655 if (o != null) {
656 mWebSettingsToObservers.remove(s);
657 super.deleteObserver(o);
658 }
659 }
660
661 /*
John Reck63bb6872010-12-01 19:29:32 -0800662 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800663 * BrowserSettings.
664 */
John Reck63bb6872010-12-01 19:29:32 -0800665 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800666 if (sSingleton == null ) {
667 sSingleton = new BrowserSettings();
668 }
669 return sSingleton;
670 }
671
672 /*
673 * Package level method for associating the BrowserSettings with TabControl
674 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700675 /* package */void setController(Controller ctrl) {
676 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800677 updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800678 }
679
680 /*
681 * Update all the observers of the object.
682 */
683 /*package*/ void update() {
684 setChanged();
685 notifyObservers();
686 }
687
688 /*package*/ void clearCache(Context context) {
689 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700690 if (mController != null) {
691 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800692 if (current != null) {
693 current.clearCache(true);
694 }
695 }
696 }
697
698 /*package*/ void clearCookies(Context context) {
699 CookieManager.getInstance().removeAllCookie();
700 }
701
702 /* package */void clearHistory(Context context) {
703 ContentResolver resolver = context.getContentResolver();
704 Browser.clearHistory(resolver);
705 Browser.clearSearches(resolver);
706 }
707
708 /* package */ void clearFormData(Context context) {
709 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 if (mController!= null) {
711 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100712 if (currentTopView != null) {
713 currentTopView.clearFormData();
714 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800715 }
716 }
717
718 /*package*/ void clearPasswords(Context context) {
719 WebViewDatabase db = WebViewDatabase.getInstance(context);
720 db.clearUsernamePassword();
721 db.clearHttpAuthUsernamePassword();
722 }
723
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800724 private void updateTabControlSettings() {
725 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700726 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800727 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800728 }
729
Nicolas Roard78a98e42009-05-11 13:34:17 +0100730 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100731 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100732 }
733
734 /*package*/ void clearLocationAccess(Context context) {
735 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100736 }
737
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400738 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800739 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500740 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700741 p.edit().clear().apply();
John Reck035a5642010-12-21 18:51:27 -0800742 PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true);
743 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500744 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700745 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700746 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100747 // reset appcache max size
748 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100749 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700750 }
751
John Reck33bbb802010-10-26 17:13:42 -0700752 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700753 String url = context.getResources().getString(R.string.homepage_base);
754 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500755 url = url.replace("{CID}",
756 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700757 }
758 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800759 }
760
The Android Open Source Project0c908882009-03-03 19:32:16 -0800761 // Private constructor that does nothing.
762 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800763 reset();
764 }
765
766 private void reset() {
767 // Private variables for settings
768 // NOTE: these defaults need to be kept in sync with the XML
769 // until the performance of PreferenceManager.setDefaultValues()
770 // is improved.
771 loadsImagesAutomatically = true;
772 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400773 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800774 javaScriptCanOpenWindowsAutomatically = false;
775 showSecurityWarnings = true;
776 rememberPasswords = true;
777 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000778 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800779 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800780 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800781 loadsPageInOverviewMode = true;
782 showDebugSettings = false;
783 // HTML5 API flags
784 appCacheEnabled = true;
785 databaseEnabled = true;
786 domStorageEnabled = true;
787 geolocationEnabled = true;
788 workersEnabled = true; // only affects V8. JSC does not have a similar setting
The Android Open Source Project0c908882009-03-03 19:32:16 -0800789 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100790
Ben Murdoch23da30e2010-10-26 15:18:44 +0100791 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100792 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100793 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100794 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100795
Ben Murdoch23da30e2010-10-26 15:18:44 +0100796 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100797 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100798 mCompleteMessage = msg;
799 }
800
801 protected void onPostExecute(Void result) {
802 if (mCompleteMessage != null) {
803 mCompleteMessage.sendToTarget();
804 }
805 mAutoFillProfileDb.close();
806 }
807
808 abstract protected Void doInBackground(T... values);
809 }
810
811
812 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
813 public SaveProfileToDbTask(Context ctx, Message msg) {
814 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100815 }
816
817 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100818 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100819 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
820 AutoFillProfile newProfile = values[0];
821 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100822 return null;
823 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100824 }
825
Ben Murdoch23da30e2010-10-26 15:18:44 +0100826 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
827 public DeleteProfileFromDbTask(Context ctx, Message msg) {
828 super(ctx, msg);
829 }
830
831 protected Void doInBackground(Integer... values) {
832 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
833 int id = values[0];
834 assert id > 0;
835 mAutoFillProfileDb.dropProfile(id);
836 return null;
837 }
838 }
John Reck63bb6872010-12-01 19:29:32 -0800839
840 @Override
841 public void onSharedPreferenceChanged(
842 SharedPreferences p, String key) {
843 if (PREF_HARDWARE_ACCEL.equals(key)) {
844 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
845 } else if (PREF_USER_AGENT.equals(key)) {
846 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
847 update();
Michael Kolb376b5412010-12-15 11:52:57 -0800848 } else if (PREF_QUICK_CONTROLS.equals(key)) {
849 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reck63bb6872010-12-01 19:29:32 -0800850 }
851 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800852}