blob: 5729e999bde03df12a55a9eaab00617a99a6944f [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);
Patrick Scott826a0812011-01-05 11:38:58 -0500281 // disable content url access
282 s.setAllowContentAccess(false);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100283
Andrei Popescu01068702009-08-03 16:03:24 +0100284 // HTML5 API flags
285 s.setAppCacheEnabled(b.appCacheEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100286 s.setDatabaseEnabled(b.databaseEnabled);
Ben Murdoch734a0662009-06-02 19:11:52 +0100287 s.setDomStorageEnabled(b.domStorageEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100288 s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
Steve Block97b08022009-08-21 10:26:25 +0100289 s.setGeolocationEnabled(b.geolocationEnabled);
Ben Murdoch092dd5d2009-04-22 12:34:12 +0100290
Andrei Popescu01068702009-08-03 16:03:24 +0100291 // HTML5 configuration parameters.
Andrei Popescu20634ce2009-07-22 16:46:55 +0100292 s.setAppCacheMaxSize(b.appCacheMaxSize);
Andrei Popescu01068702009-08-03 16:03:24 +0100293 s.setAppCachePath(b.appCachePath);
294 s.setDatabasePath(b.databasePath);
Steve Block5029cf02009-08-21 13:16:58 +0100295 s.setGeolocationDatabasePath(b.geolocationDatabasePath);
Ben Murdochbff2d602009-07-01 20:19:05 +0100296
Ben Murdoch0cb81892010-10-08 12:41:33 +0100297 // Active AutoFill profile data.
Ben Murdoch23da30e2010-10-26 15:18:44 +0100298 s.setAutoFillProfile(b.autoFillProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100299
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800300 b.updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800301 }
302 }
303
304 /**
Ben Murdochef671652010-11-25 17:17:58 +0000305 * Load settings from the browser app's database. It is performed in
306 * an AsyncTask as it involves plenty of slow disk IO.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800307 * NOTE: Strings used for the preferences must match those specified
Jeff Hamilton175ab302010-10-04 12:53:49 -0500308 * in the various preference XML files.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800309 * @param ctx A Context object used to query the browser's settings
310 * database. If the database exists, the saved settings will be
311 * stored in this BrowserSettings object. This will update all
312 * observers of this object.
313 */
Ben Murdochef671652010-11-25 17:17:58 +0000314 public void asyncLoadFromDb(final Context ctx) {
315 mLoadFromDbComplete = false;
316 // Run the initial settings load in an AsyncTask as it hits the
317 // disk multiple times through SharedPreferences and SQLite. We
318 // need to be certain though that this has completed before we start
319 // to load pages though, so in the worst case we will block waiting
320 // for it to finish in BrowserActivity.onCreate().
321 new LoadFromDbTask(ctx).execute();
322 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800323
Ben Murdochef671652010-11-25 17:17:58 +0000324 private class LoadFromDbTask extends AsyncTask<Void, Void, Void> {
325 private Context mContext;
326
327 public LoadFromDbTask(Context context) {
328 mContext = context;
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700329 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700330
Ben Murdochef671652010-11-25 17:17:58 +0000331 protected Void doInBackground(Void... unused) {
332 SharedPreferences p =
333 PreferenceManager.getDefaultSharedPreferences(mContext);
334 // Set the default value for the Application Caches path.
335 appCachePath = mContext.getDir("appcache", 0).getPath();
336 // Determine the maximum size of the application cache.
337 webStorageSizeManager = new WebStorageSizeManager(
338 mContext,
339 new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
340 new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
341 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
342 // Set the default value for the Database path.
343 databasePath = mContext.getDir("databases", 0).getPath();
344 // Set the default value for the Geolocation database path.
345 geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath();
346
John Reckef074262010-12-02 16:09:14 -0800347 if (p.getString(PREF_HOMEPAGE, null) == null) {
Ben Murdochef671652010-11-25 17:17:58 +0000348 // No home page preferences is set, set it to default.
349 setHomePage(mContext, getFactoryResetHomeUrl(mContext));
350 }
351
352 // the cost of one cached page is ~3M (measured using nytimes.com). For
353 // low end devices, we only cache one page. For high end devices, we try
354 // to cache more pages, currently choose 5.
355 ActivityManager am = (ActivityManager) mContext
356 .getSystemService(Context.ACTIVITY_SERVICE);
357 if (am.getMemoryClass() > 16) {
358 pageCacheCapacity = 5;
359 } else {
360 pageCacheCapacity = 1;
361 }
362
363 // Read the last active AutoFill profile id.
364 autoFillActiveProfileId = p.getInt(
365 PREF_AUTOFILL_ACTIVE_PROFILE_ID, autoFillActiveProfileId);
366
367 // Load the autofill profile data from the database. We use a database separate
368 // to the browser preference DB to make it easier to support multiple profiles
369 // and switching between them.
370 AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(mContext);
371 Cursor c = autoFillDb.getProfile(autoFillActiveProfileId);
372
373 if (c.getCount() > 0) {
374 c.moveToFirst();
375
376 String fullName = c.getString(c.getColumnIndex(
377 AutoFillProfileDatabase.Profiles.FULL_NAME));
378 String email = c.getString(c.getColumnIndex(
379 AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS));
380 String company = c.getString(c.getColumnIndex(
381 AutoFillProfileDatabase.Profiles.COMPANY_NAME));
382 String addressLine1 = c.getString(c.getColumnIndex(
383 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1));
384 String addressLine2 = c.getString(c.getColumnIndex(
385 AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2));
386 String city = c.getString(c.getColumnIndex(
387 AutoFillProfileDatabase.Profiles.CITY));
388 String state = c.getString(c.getColumnIndex(
389 AutoFillProfileDatabase.Profiles.STATE));
390 String zip = c.getString(c.getColumnIndex(
391 AutoFillProfileDatabase.Profiles.ZIP_CODE));
392 String country = c.getString(c.getColumnIndex(
393 AutoFillProfileDatabase.Profiles.COUNTRY));
394 String phone = c.getString(c.getColumnIndex(
395 AutoFillProfileDatabase.Profiles.PHONE_NUMBER));
396 autoFillProfile = new AutoFillProfile(autoFillActiveProfileId,
397 fullName, email, company, addressLine1, addressLine2, city,
398 state, zip, country, phone);
399 }
400 c.close();
401 autoFillDb.close();
402
403 // PreferenceManager.setDefaultValues is TOO SLOW, need to manually keep
404 // the defaults in sync
John Reck63bb6872010-12-01 19:29:32 -0800405 p.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
Ben Murdochef671652010-11-25 17:17:58 +0000406 syncSharedPreferences(mContext, p);
407
408 synchronized (sSingleton) {
409 mLoadFromDbComplete = true;
410 sSingleton.notify();
411 }
412 return null;
Grace Kloba9804c432009-12-02 11:07:40 -0800413 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800414 }
415
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100416 /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700417
The Android Open Source Project0c908882009-03-03 19:32:16 -0800418 homeUrl =
419 p.getString(PREF_HOMEPAGE, homeUrl);
Leon Scroggins III31306602010-09-17 11:10:29 -0400420 String searchEngineName = p.getString(PREF_SEARCH_ENGINE,
421 SearchEngine.GOOGLE);
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100422 if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) {
423 if (searchEngine != null) {
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400424 if (searchEngine.supportsVoiceSearch()) {
425 // One or more tabs could have been in voice search mode.
426 // Clear it, since the new SearchEngine may not support
427 // it, or may handle it differently.
Michael Kolb8233fac2010-10-26 16:08:53 -0700428 for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
429 mController.getTabControl().getTab(i).revertVoiceSearchMode();
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400430 }
431 }
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100432 searchEngine.close();
433 }
434 searchEngine = SearchEngines.get(ctx, searchEngineName);
435 }
436 Log.i(TAG, "Selected search engine: " + searchEngine);
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700437
The Android Open Source Project0c908882009-03-03 19:32:16 -0800438 loadsImagesAutomatically = p.getBoolean("load_images",
439 loadsImagesAutomatically);
440 javaScriptEnabled = p.getBoolean("enable_javascript",
441 javaScriptEnabled);
Patrick Scotte536b332010-03-22 10:19:32 -0400442 pluginState = WebSettings.PluginState.valueOf(
443 p.getString("plugin_state", pluginState.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800444 javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
445 "block_popup_windows",
446 !javaScriptCanOpenWindowsAutomatically);
447 showSecurityWarnings = p.getBoolean("show_security_warnings",
448 showSecurityWarnings);
449 rememberPasswords = p.getBoolean("remember_passwords",
450 rememberPasswords);
451 saveFormData = p.getBoolean("save_formdata",
452 saveFormData);
Ben Murdochaf554522010-09-10 22:09:30 +0100453 autoFillEnabled = p.getBoolean("autofill_enabled", autoFillEnabled);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800454 boolean accept_cookies = p.getBoolean("accept_cookies",
455 CookieManager.getInstance().acceptCookie());
456 CookieManager.getInstance().setAcceptCookie(accept_cookies);
457 openInBackground = p.getBoolean("open_in_background", openInBackground);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 textSize = WebSettings.TextSize.valueOf(
459 p.getString(PREF_TEXT_SIZE, textSize.name()));
Grace Kloba2f830682009-06-25 11:08:53 -0700460 zoomDensity = WebSettings.ZoomDensity.valueOf(
461 p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800462 autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
Grace Kloba5b4b8f12009-08-05 17:19:17 -0700463 loadsPageInOverviewMode = p.getBoolean("load_page",
464 loadsPageInOverviewMode);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800465 useWideViewPort = true; // use wide view port for either setting
466 if (autoFitPage) {
467 layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
468 } else {
469 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
470 }
471 defaultTextEncodingName =
472 p.getString(PREF_DEFAULT_TEXT_ENCODING,
473 defaultTextEncodingName);
474
475 showDebugSettings =
476 p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
477 // Debug menu items have precidence if the menu is visible
478 if (showDebugSettings) {
479 boolean small_screen = p.getBoolean("small_screen",
480 layoutAlgorithm ==
481 WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
482 if (small_screen) {
483 layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
484 } else {
485 boolean normal_layout = p.getBoolean("normal_layout",
486 layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
487 if (normal_layout) {
488 layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
489 } else {
490 layoutAlgorithm =
491 WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
492 }
493 }
494 useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
495 tracing = p.getBoolean("enable_tracing", tracing);
496 lightTouch = p.getBoolean("enable_light_touch", lightTouch);
497 navDump = p.getBoolean("enable_nav_dump", navDump);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800498 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500499
Michael Kolb376b5412010-12-15 11:52:57 -0800500 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
501
John Reck63bb6872010-12-01 19:29:32 -0800502 // Only set these on startup if it is a dev build
503 if (DEV_BUILD) {
504 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
505 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
506 }
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500507
Feng Qianb3c02da2009-06-29 15:58:08 -0700508 // JS flags is loaded from DB even if showDebugSettings is false,
509 // so that it can be set once and be effective all the time.
510 jsFlags = p.getString("js_engine_flags", "");
Ben Murdochbff2d602009-07-01 20:19:05 +0100511
512 // Read the setting for showing/hiding the JS Console always so that should the
513 // user enable debug settings, we already know if we should show the console.
514 // The user will never see the console unless they navigate to about:debug,
515 // regardless of the setting we read here. This setting is only used after debug
516 // is enabled.
517 showConsole = p.getBoolean("javascript_console", showConsole);
Grace Klobad9ee1392009-07-20 11:53:33 -0700518
Andrei Popescu01068702009-08-03 16:03:24 +0100519 // HTML5 API flags
520 appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
521 databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
522 domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100523 geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
Andrei Popescu01068702009-08-03 16:03:24 +0100524 workersEnabled = p.getBoolean("enable_workers", workersEnabled);
Steve Blockf344d032009-07-30 10:50:45 +0100525
Grace Klobad9ee1392009-07-20 11:53:33 -0700526 update();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800527 }
528
The Android Open Source Project0c908882009-03-03 19:32:16 -0800529 public String getHomePage() {
530 return homeUrl;
531 }
532
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100533 public SearchEngine getSearchEngine() {
534 return searchEngine;
535 }
536
Feng Qianb3c02da2009-06-29 15:58:08 -0700537 public String getJsFlags() {
538 return jsFlags;
539 }
540
Andrei Popescu79e82b72009-07-27 12:01:59 +0100541 public WebStorageSizeManager getWebStorageSizeManager() {
542 return webStorageSizeManager;
543 }
544
The Android Open Source Project0c908882009-03-03 19:32:16 -0800545 public void setHomePage(Context context, String url) {
546 Editor ed = PreferenceManager.
547 getDefaultSharedPreferences(context).edit();
548 ed.putString(PREF_HOMEPAGE, url);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700549 ed.apply();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800550 homeUrl = url;
551 }
552
The Android Open Source Project0c908882009-03-03 19:32:16 -0800553 public WebSettings.TextSize getTextSize() {
554 return textSize;
555 }
556
Grace Kloba2f830682009-06-25 11:08:53 -0700557 public WebSettings.ZoomDensity getDefaultZoom() {
558 return zoomDensity;
559 }
560
The Android Open Source Project0c908882009-03-03 19:32:16 -0800561 public boolean openInBackground() {
562 return openInBackground;
563 }
564
565 public boolean showSecurityWarnings() {
566 return showSecurityWarnings;
567 }
568
569 public boolean isTracing() {
570 return tracing;
571 }
572
573 public boolean isLightTouch() {
574 return lightTouch;
575 }
576
577 public boolean isNavDump() {
578 return navDump;
579 }
580
Derek Sollenbergerffa561e2010-11-16 14:19:01 -0500581 public boolean isHardwareAccelerated() {
582 return hardwareAccelerated;
583 }
584
Michael Kolb376b5412010-12-15 11:52:57 -0800585 public boolean useQuickControls() {
586 return quickControls;
587 }
588
The Android Open Source Project0c908882009-03-03 19:32:16 -0800589 public boolean showDebugSettings() {
590 return showDebugSettings;
591 }
592
593 public void toggleDebugSettings() {
594 showDebugSettings = !showDebugSettings;
595 navDump = showDebugSettings;
596 update();
597 }
598
Ben Murdoch23da30e2010-10-26 15:18:44 +0100599 public void setAutoFillProfile(Context ctx, AutoFillProfile profile, Message msg) {
600 if (profile != null) {
601 setActiveAutoFillProfileId(ctx, profile.getUniqueId());
602 // Update the AutoFill DB with the new profile.
603 new SaveProfileToDbTask(ctx, msg).execute(profile);
604 } else {
605 // Delete the current profile.
Ben Murdoche8a28332010-11-17 14:16:21 +0000606 if (autoFillProfile != null) {
607 new DeleteProfileFromDbTask(ctx, msg).execute(autoFillProfile.getUniqueId());
608 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
609 }
Ben Murdoch23da30e2010-10-26 15:18:44 +0100610 }
611 autoFillProfile = profile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100612 }
613
614 public AutoFillProfile getAutoFillProfile() {
Ben Murdoch23da30e2010-10-26 15:18:44 +0100615 return autoFillProfile;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100616 }
617
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100618 private void setActiveAutoFillProfileId(Context context, int activeProfileId) {
619 autoFillActiveProfileId = activeProfileId;
620 Editor ed = PreferenceManager.
621 getDefaultSharedPreferences(context).edit();
622 ed.putInt(PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId);
623 ed.apply();
624 }
625
Ben Murdoch8029a772010-11-16 11:58:21 +0000626 /* package */ void disableAutoFill(Context ctx) {
627 autoFillEnabled = false;
628 Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
629 ed.putBoolean(PREF_AUTOFILL_ENABLED, false);
630 ed.apply();
631 }
632
The Android Open Source Project0c908882009-03-03 19:32:16 -0800633 /**
634 * Add a WebSettings object to the list of observers that will be updated
635 * when update() is called.
636 *
637 * @param s A WebSettings object that is strictly tied to the life of a
638 * WebView.
639 */
640 public Observer addObserver(WebSettings s) {
641 Observer old = mWebSettingsToObservers.get(s);
642 if (old != null) {
643 super.deleteObserver(old);
644 }
645 Observer o = new Observer(s);
646 mWebSettingsToObservers.put(s, o);
647 super.addObserver(o);
648 return o;
649 }
650
651 /**
652 * Delete the given WebSettings observer from the list of observers.
653 * @param s The WebSettings object to be deleted.
654 */
655 public void deleteObserver(WebSettings s) {
656 Observer o = mWebSettingsToObservers.get(s);
657 if (o != null) {
658 mWebSettingsToObservers.remove(s);
659 super.deleteObserver(o);
660 }
661 }
662
663 /*
John Reck63bb6872010-12-01 19:29:32 -0800664 * Application level method for obtaining a single app instance of the
The Android Open Source Project0c908882009-03-03 19:32:16 -0800665 * BrowserSettings.
666 */
John Reck63bb6872010-12-01 19:29:32 -0800667 public static BrowserSettings getInstance() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800668 if (sSingleton == null ) {
669 sSingleton = new BrowserSettings();
670 }
671 return sSingleton;
672 }
673
674 /*
675 * Package level method for associating the BrowserSettings with TabControl
676 */
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 /* package */void setController(Controller ctrl) {
678 mController = ctrl;
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800679 updateTabControlSettings();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800680 }
681
682 /*
683 * Update all the observers of the object.
684 */
685 /*package*/ void update() {
686 setChanged();
687 notifyObservers();
688 }
689
690 /*package*/ void clearCache(Context context) {
691 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 if (mController != null) {
693 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800694 if (current != null) {
695 current.clearCache(true);
696 }
697 }
698 }
699
700 /*package*/ void clearCookies(Context context) {
701 CookieManager.getInstance().removeAllCookie();
702 }
703
704 /* package */void clearHistory(Context context) {
705 ContentResolver resolver = context.getContentResolver();
706 Browser.clearHistory(resolver);
707 Browser.clearSearches(resolver);
708 }
709
710 /* package */ void clearFormData(Context context) {
711 WebViewDatabase.getInstance(context).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 if (mController!= null) {
713 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100714 if (currentTopView != null) {
715 currentTopView.clearFormData();
716 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800717 }
718 }
719
720 /*package*/ void clearPasswords(Context context) {
721 WebViewDatabase db = WebViewDatabase.getInstance(context);
722 db.clearUsernamePassword();
723 db.clearHttpAuthUsernamePassword();
724 }
725
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800726 private void updateTabControlSettings() {
727 // Enable/disable the error console.
Michael Kolb8233fac2010-10-26 16:08:53 -0700728 mController.setShouldShowErrorConsole(
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800729 showDebugSettings && showConsole);
Shimeng (Simon) Wang161974f2010-03-09 14:30:07 -0800730 }
731
Nicolas Roard78a98e42009-05-11 13:34:17 +0100732 /*package*/ void clearDatabases(Context context) {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100733 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100734 }
735
736 /*package*/ void clearLocationAccess(Context context) {
737 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100738 }
739
Leon Scroggins9ac587d2009-04-20 12:53:46 -0400740 /*package*/ void resetDefaultPreferences(Context ctx) {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800741 reset();
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500742 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx);
Brad Fitzpatrick1a6e0e82010-09-01 16:29:03 -0700743 p.edit().clear().apply();
John Reck035a5642010-12-21 18:51:27 -0800744 PreferenceManager.setDefaultValues(ctx, R.xml.general_preferences, true);
745 PreferenceManager.setDefaultValues(ctx, R.xml.privacy_security_preferences, true);
Jeff Hamilton462b8e82010-09-23 14:33:43 -0500746 PreferenceManager.setDefaultValues(ctx, R.xml.advanced_preferences, true);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700747 // reset homeUrl
Grace Klobaa3f90f02009-05-26 11:32:53 -0700748 setHomePage(ctx, getFactoryResetHomeUrl(ctx));
Andrei Popescu79e82b72009-07-27 12:01:59 +0100749 // reset appcache max size
750 appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
Ben Murdoch23da30e2010-10-26 15:18:44 +0100751 setActiveAutoFillProfileId(ctx, NO_AUTOFILL_PROFILE_SET);
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700752 }
753
John Reck33bbb802010-10-26 17:13:42 -0700754 /*package*/ static String getFactoryResetHomeUrl(Context context) {
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700755 String url = context.getResources().getString(R.string.homepage_base);
756 if (url.indexOf("{CID}") != -1) {
Patrick Scott43914692010-02-19 10:10:10 -0500757 url = url.replace("{CID}",
758 BrowserProvider.getClientId(context.getContentResolver()));
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700759 }
760 return url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800761 }
762
The Android Open Source Project0c908882009-03-03 19:32:16 -0800763 // Private constructor that does nothing.
764 private BrowserSettings() {
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800765 reset();
766 }
767
768 private void reset() {
769 // Private variables for settings
770 // NOTE: these defaults need to be kept in sync with the XML
771 // until the performance of PreferenceManager.setDefaultValues()
772 // is improved.
773 loadsImagesAutomatically = true;
774 javaScriptEnabled = true;
Patrick Scotte536b332010-03-22 10:19:32 -0400775 pluginState = WebSettings.PluginState.ON;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800776 javaScriptCanOpenWindowsAutomatically = false;
777 showSecurityWarnings = true;
778 rememberPasswords = true;
779 saveFormData = true;
Ben Murdochdc62cb92010-11-23 15:11:29 +0000780 autoFillEnabled = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800781 openInBackground = false;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800782 autoFitPage = true;
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800783 loadsPageInOverviewMode = true;
784 showDebugSettings = false;
785 // HTML5 API flags
786 appCacheEnabled = true;
787 databaseEnabled = true;
788 domStorageEnabled = true;
789 geolocationEnabled = true;
790 workersEnabled = true; // only affects V8. JSC does not have a similar setting
The Android Open Source Project0c908882009-03-03 19:32:16 -0800791 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100792
Ben Murdoch23da30e2010-10-26 15:18:44 +0100793 private abstract class AutoFillProfileDbTask<T> extends AsyncTask<T, Void, Void> {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100794 Context mContext;
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100795 AutoFillProfileDatabase mAutoFillProfileDb;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100796 Message mCompleteMessage;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100797
Ben Murdoch23da30e2010-10-26 15:18:44 +0100798 public AutoFillProfileDbTask(Context ctx, Message msg) {
Ben Murdoch0cb81892010-10-08 12:41:33 +0100799 mContext = ctx;
Ben Murdoch23da30e2010-10-26 15:18:44 +0100800 mCompleteMessage = msg;
801 }
802
803 protected void onPostExecute(Void result) {
804 if (mCompleteMessage != null) {
805 mCompleteMessage.sendToTarget();
806 }
807 mAutoFillProfileDb.close();
808 }
809
810 abstract protected Void doInBackground(T... values);
811 }
812
813
814 private class SaveProfileToDbTask extends AutoFillProfileDbTask<AutoFillProfile> {
815 public SaveProfileToDbTask(Context ctx, Message msg) {
816 super(ctx, msg);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100817 }
818
819 protected Void doInBackground(AutoFillProfile... values) {
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100820 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100821 assert autoFillActiveProfileId != NO_AUTOFILL_PROFILE_SET;
822 AutoFillProfile newProfile = values[0];
823 mAutoFillProfileDb.addOrUpdateProfile(autoFillActiveProfileId, newProfile);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100824 return null;
825 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100826 }
827
Ben Murdoch23da30e2010-10-26 15:18:44 +0100828 private class DeleteProfileFromDbTask extends AutoFillProfileDbTask<Integer> {
829 public DeleteProfileFromDbTask(Context ctx, Message msg) {
830 super(ctx, msg);
831 }
832
833 protected Void doInBackground(Integer... values) {
834 mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext);
835 int id = values[0];
836 assert id > 0;
837 mAutoFillProfileDb.dropProfile(id);
838 return null;
839 }
840 }
John Reck63bb6872010-12-01 19:29:32 -0800841
842 @Override
843 public void onSharedPreferenceChanged(
844 SharedPreferences p, String key) {
845 if (PREF_HARDWARE_ACCEL.equals(key)) {
846 hardwareAccelerated = p.getBoolean(PREF_HARDWARE_ACCEL, hardwareAccelerated);
847 } else if (PREF_USER_AGENT.equals(key)) {
848 userAgent = Integer.parseInt(p.getString(PREF_USER_AGENT, "0"));
849 update();
Michael Kolb376b5412010-12-15 11:52:57 -0800850 } else if (PREF_QUICK_CONTROLS.equals(key)) {
851 quickControls = p.getBoolean(PREF_QUICK_CONTROLS, quickControls);
John Reck63bb6872010-12-01 19:29:32 -0800852 }
853 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800854}