blob: 0281167879024d885c722e60c6da36635471680c [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.content.ContentResolver;
20import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070022import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080023import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070024import android.net.ConnectivityManager;
25import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070026import android.os.Build;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.preference.PreferenceManager;
Ben Murdoch0cb81892010-10-08 12:41:33 +010028import android.provider.Browser;
Mathew Inwood825fba72011-10-04 14:52:52 +010029import android.provider.Settings;
Bijan Amirzadae75909d2014-05-06 14:18:54 -070030import android.text.TextUtils;
John Reck5ba3c762011-09-14 15:00:15 -070031import android.util.DisplayMetrics;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032import android.webkit.WebIconDatabase;
Nicolas Roard78a98e42009-05-11 13:34:17 +010033import android.webkit.WebStorage;
John Reck812d2d62011-01-18 14:16:15 -080034import android.webkit.WebViewDatabase;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035
Bijan Amirzada41242f22014-03-21 12:12:18 -070036import com.android.browser.R;
37import com.android.browser.homepages.HomeProvider;
38import com.android.browser.provider.BrowserProvider;
39import com.android.browser.reflect.ReflectHelper;
40import com.android.browser.search.SearchEngine;
41import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070042
John Reck35e9dd62011-04-25 09:01:54 -070043import java.lang.ref.WeakReference;
44import java.util.Iterator;
45import java.util.LinkedList;
qqzhou8c5b0a32013-07-22 15:31:03 +080046import java.util.Locale;
John Reckb8b2af82011-05-20 15:58:33 -070047import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080048
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080049import org.codeaurora.swe.AutoFillProfile;
50import org.codeaurora.swe.CookieManager;
51import org.codeaurora.swe.GeolocationPermissions;
52import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
53import org.codeaurora.swe.WebSettings.PluginState;
54import org.codeaurora.swe.WebSettings.TextSize;
55import org.codeaurora.swe.WebSettings.ZoomDensity;
56import org.codeaurora.swe.WebSettings;
57import org.codeaurora.swe.WebView;
58
John Reck35e9dd62011-04-25 09:01:54 -070059/**
60 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080061 */
John Reck35e9dd62011-04-25 09:01:54 -070062public class BrowserSettings implements OnSharedPreferenceChangeListener,
63 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010064
John Reck35e9dd62011-04-25 09:01:54 -070065 // TODO: Do something with this UserAgent stuff
John Reck7fd1e8f2011-04-27 18:22:57 -070066 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
67 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
68 "Chrome/11.0.696.34 Safari/534.24";
The Android Open Source Project0c908882009-03-03 19:32:16 -080069
70 private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070071 "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
72 "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
Bart Searsf6915fb2010-07-08 19:58:22 -070073
74 private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070075 "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
76 "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
Bart Searsf6915fb2010-07-08 19:58:22 -070077
78 private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
John Reck35e9dd62011-04-25 09:01:54 -070079 "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
80 "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
The Android Open Source Project0c908882009-03-03 19:32:16 -080081
John Reck7fd1e8f2011-04-27 18:22:57 -070082 private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
83 "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
84 "(KHTML, like Gecko) Version/4.0 Safari/534.13";
85
John Reck35e9dd62011-04-25 09:01:54 -070086 private static final String USER_AGENTS[] = { null,
87 DESKTOP_USERAGENT,
88 IPHONE_USERAGENT,
89 IPAD_USERAGENT,
John Reck7fd1e8f2011-04-27 18:22:57 -070090 FROYO_USERAGENT,
91 HONEYCOMB_USERAGENT,
John Reck35e9dd62011-04-25 09:01:54 -070092 };
The Android Open Source Project0c908882009-03-03 19:32:16 -080093
qqzhoue6ff8b42013-07-23 17:28:48 +080094 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070095 // The minimum min font size
96 // Aka, the lower bounds for the min font size range
97 // which is 1:5..24
98 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070099 // The initial value in the text zoom range
100 // This is what represents 100% in the SeekBarPreference range
101 private static final int TEXT_ZOOM_START_VAL = 10;
102 // The size of a single step in the text zoom range, in percent
103 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700104 // The initial value in the double tap zoom range
105 // This is what represents 100% in the SeekBarPreference range
106 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
107 // The size of a single step in the double tap zoom range, in percent
108 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -0700109
John Reck35e9dd62011-04-25 09:01:54 -0700110 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -0700111
John Reck35e9dd62011-04-25 09:01:54 -0700112 private Context mContext;
113 private SharedPreferences mPrefs;
114 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -0700115 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -0700116 private WebStorageSizeManager mWebStorageSizeManager;
117 private AutofillHandler mAutofillHandler;
John Reckb8b2af82011-05-20 15:58:33 -0700118 private WeakHashMap<WebSettings, String> mCustomUserAgents;
Ben Murdochaaa1f372011-07-25 15:40:58 +0100119 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -0700120 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -0700121 private float mFontSizeMult = 1.0f;
Tarun Nainanic8e6dda2014-04-17 13:11:25 -0700122 private boolean enableWideViewport = true;
John Reck78a6a1d2011-07-21 13:54:03 -0700123
Victoria Lease96497832012-03-23 14:19:56 -0700124 // Current state of network-dependent settings
125 private boolean mLinkPrefetchAllowed = true;
126
John Reck78a6a1d2011-07-21 13:54:03 -0700127 // Cached values
128 private int mPageCacheCapacity = 1;
129 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130
John Reck35e9dd62011-04-25 09:01:54 -0700131 // Cached settings
132 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800133
Ben Murdochaaa1f372011-07-25 15:40:58 +0100134 private static String sFactoryResetUrl;
135
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700136 public static void initialize(final Context context) {
John Reck35e9dd62011-04-25 09:01:54 -0700137 sInstance = new BrowserSettings(context);
138 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800139
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700140 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700141 return sInstance;
142 }
Ben Murdochef671652010-11-25 17:17:58 +0000143
John Reck35e9dd62011-04-25 09:01:54 -0700144 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100145 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700146 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
147 mAutofillHandler = new AutofillHandler(mContext);
148 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckb8b2af82011-05-20 15:58:33 -0700149 mCustomUserAgents = new WeakHashMap<WebSettings, String>();
John Reckcadae722011-07-25 11:36:17 -0700150 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700151 }
152
153 public void setController(Controller controller) {
154 mController = controller;
John Reckc477e712011-08-17 11:27:15 -0700155 if (sInitialized) {
156 syncSharedSettings();
157 }
Ben Murdochef671652010-11-25 17:17:58 +0000158 }
159
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800160 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800161
John Reckc477e712011-08-17 11:27:15 -0700162 if (mNeedsSharedSync) {
163 syncSharedSettings();
164 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800165
John Reck35e9dd62011-04-25 09:01:54 -0700166 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800167 syncStaticSettings(settings);
168 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700169 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800170 }
171 }
172
John Reckd1d87312012-03-08 13:25:00 -0800173 public void stopManagingSettings(WebSettings settings) {
174 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
175 while (iter.hasNext()) {
176 WeakReference<WebSettings> ref = iter.next();
177 if (ref.get() == settings) {
178 iter.remove();
179 return;
180 }
181 }
182 }
183
John Reckcadae722011-07-25 11:36:17 -0700184 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700185
186 @Override
187 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700188 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
189 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700190 // the cost of one cached page is ~3M (measured using nytimes.com). For
191 // low end devices, we only cache one page. For high end devices, we try
192 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800193
194 // SWE_TODO : assume a high-memory device
195 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700196 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800197 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700198 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
199 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
200 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700201 // Workaround b/5254577
202 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700203 if (Build.VERSION.CODENAME.equals("REL")) {
204 // This is a release build, always startup with debug disabled
205 setDebugEnabled(false);
206 }
207 if (mPrefs.contains(PREF_TEXT_SIZE)) {
208 /*
209 * Update from TextSize enum to zoom percent
210 * SMALLEST is 50%
211 * SMALLER is 75%
212 * NORMAL is 100%
213 * LARGER is 150%
214 * LARGEST is 200%
215 */
216 switch (getTextSize()) {
217 case SMALLEST:
218 setTextZoom(50);
219 break;
220 case SMALLER:
221 setTextZoom(75);
222 break;
223 case LARGER:
224 setTextZoom(150);
225 break;
226 case LARGEST:
227 setTextZoom(200);
228 break;
229 }
230 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
231 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100232
qqzhou8c5b0a32013-07-22 15:31:03 +0800233 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700234 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800235
kaiyizbf086ea2013-08-02 11:03:58 +0800236 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700237 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "UTF-8").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800238 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700239
Ben Murdochaaa1f372011-07-25 15:40:58 +0100240 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
241 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
242 BrowserProvider.getClientId(mContext.getContentResolver()));
243 }
244
Ben Murdochaaa1f372011-07-25 15:40:58 +0100245 synchronized (BrowserSettings.class) {
246 sInitialized = true;
247 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700248 }
249 }
250 };
251
Ben Murdochaaa1f372011-07-25 15:40:58 +0100252 private static void requireInitialization() {
253 synchronized (BrowserSettings.class) {
254 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700255 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100256 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700257 } catch (InterruptedException e) {
258 }
259 }
260 }
261 }
262
The Android Open Source Project0c908882009-03-03 19:32:16 -0800263 /**
John Reck35e9dd62011-04-25 09:01:54 -0700264 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800265 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800266 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700267 settings.setGeolocationEnabled(enableGeolocation());
268 settings.setJavaScriptEnabled(enableJavascript());
269 settings.setLightTouchEnabled(enableLightTouch());
270 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700271 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
272 settings.setDefaultZoom(getDefaultZoom());
273 settings.setMinimumFontSize(getMinimumFontSize());
274 settings.setMinimumLogicalFontSize(getMinimumFontSize());
275 settings.setPluginState(getPluginState());
John Reck7dc444b2011-06-16 17:44:29 -0700276 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700277 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100278 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700279 settings.setLoadsImagesAutomatically(loadImages());
280 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
281 settings.setSavePassword(rememberPasswords());
282 settings.setSaveFormData(saveFormdata());
283 settings.setUseWideViewPort(isWideViewport());
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700284 setUserAgent(settings);
John Reck2fd9d0e2011-07-15 11:13:48 -0700285
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800286 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800287 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
288 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
289 settingsClassic.setForceUserScalable(forceEnableUserScalable());
290 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
291 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800292
John Reckea17e782011-10-27 17:15:59 -0700293 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800294 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700295 useInverted ? "true" : "false");
296 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800297 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700298 Float.toString(getInvertedContrast()));
299 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700300
John Reckea17e782011-10-27 17:15:59 -0700301 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800302 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700303 enableCpuUploadPath() ? "true" : "false");
304 }
Victoria Lease96497832012-03-23 14:19:56 -0700305
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800306 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000307 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800308
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700309 private void setUserAgent(WebSettings settings){
310 String ua = mContext.getResources().getString(R.string.def_useragent);
311
312 if (!TextUtils.isEmpty(ua))
313 ua = constructUserAgent(ua);
314
315 if (TextUtils.isEmpty(ua))
316 ua = mCustomUserAgents.get(settings);
317
318 if (!TextUtils.isEmpty(ua)){
319 settings.setUserAgentString(ua);
320 } else {
321 settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
322 }
323 }
324
325 private String constructUserAgent(String userAgent) {
326 try {
327 userAgent = userAgent.replaceAll("<%build_model>", Build.MODEL);
328 userAgent = userAgent.replaceAll("<%build_version>", Build.VERSION.RELEASE);
329 userAgent = userAgent.replaceAll("<%build_id>", Build.ID);
330 userAgent = userAgent.replaceAll("<%language>", Locale.getDefault().getLanguage());
331 userAgent = userAgent.replaceAll("<%country>", Locale.getDefault().getCountry());
332 return userAgent;
333 } catch (Exception ex) {
334 return null;
335 }
336 }
337
John Reck35e9dd62011-04-25 09:01:54 -0700338 /**
339 * Syncs all the settings that have no UI
340 * These cannot change, so we only need to set them once per WebSettings
341 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800342 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700343 settings.setDefaultFontSize(16);
344 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000345
John Reck35e9dd62011-04-25 09:01:54 -0700346 // WebView inside Browser doesn't want initial focus to be set.
347 settings.setNeedInitialFocus(false);
348 // Browser supports multiple windows
349 settings.setSupportMultipleWindows(true);
350 // enable smooth transition for better performance during panning or
351 // zooming
352 settings.setEnableSmoothTransition(true);
353 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700354 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700355
356 // HTML5 API flags
357 settings.setAppCacheEnabled(true);
358 settings.setDatabaseEnabled(true);
359 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700360
361 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700362 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700363 settings.setAppCachePath(getAppCachePath());
364 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
365 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700366 // origin policy for file access
367 settings.setAllowUniversalAccessFromFileURLs(false);
368 settings.setAllowFileAccessFromFileURLs(false);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800369
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800370 //if (!(settings instanceof WebSettingsClassic)) return;
371 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800372
373 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
374 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
375 // WebView should be preserving the memory as much as possible.
376 // However, apps like browser wish to turn on the performance mode which
377 // would require more memory.
378 // TODO: We need to dynamically allocate/deallocate temporary memory for
379 // apps which are trying to use minimal memory. Currently, double
380 // buffering is always turned on, which is unnecessary.
381 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
382 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800383 */
John Reck35e9dd62011-04-25 09:01:54 -0700384 }
385
386 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700387 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700388 CookieManager.getInstance().setAcceptCookie(acceptCookies());
389
John Reck35e9dd62011-04-25 09:01:54 -0700390 if (mController != null) {
391 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700392 }
John Reck35e9dd62011-04-25 09:01:54 -0700393 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700394
John Reck35e9dd62011-04-25 09:01:54 -0700395 private void syncManagedSettings() {
396 syncSharedSettings();
397 synchronized (mManagedSettings) {
398 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
399 while (iter.hasNext()) {
400 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800401 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700402 if (settings == null) {
403 iter.remove();
404 continue;
405 }
406 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000407 }
John Reck35e9dd62011-04-25 09:01:54 -0700408 }
409 }
Ben Murdochef671652010-11-25 17:17:58 +0000410
John Reck35e9dd62011-04-25 09:01:54 -0700411 @Override
412 public void onSharedPreferenceChanged(
413 SharedPreferences sharedPreferences, String key) {
414 syncManagedSettings();
415 if (PREF_SEARCH_ENGINE.equals(key)) {
416 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700417 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200418 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700419 mController.getUi().setFullscreen(useFullscreen());
420 }
Michael Kolb0241e752011-07-07 14:58:50 -0700421 } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200422 if (mController != null && mController.getUi() != null) {
Michael Kolb0241e752011-07-07 14:58:50 -0700423 mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
424 }
Victoria Lease96497832012-03-23 14:19:56 -0700425 } else if (PREF_LINK_PREFETCH.equals(key)) {
426 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700427 }
John Reck35e9dd62011-04-25 09:01:54 -0700428 }
429
John Reck961d35d2011-06-23 09:45:54 -0700430 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100431 requireInitialization();
432 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700433 }
434
435 public LayoutAlgorithm getLayoutAlgorithm() {
436 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
437 if (autofitPages()) {
438 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
439 }
440 if (isDebugEnabled()) {
441 if (isSmallScreen()) {
442 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000443 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700444 if (isNormalLayout()) {
445 layoutAlgorithm = LayoutAlgorithm.NORMAL;
446 } else {
447 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
448 }
Ben Murdochef671652010-11-25 17:17:58 +0000449 }
John Reck35e9dd62011-04-25 09:01:54 -0700450 }
451 return layoutAlgorithm;
452 }
Ben Murdochef671652010-11-25 17:17:58 +0000453
John Reck35e9dd62011-04-25 09:01:54 -0700454 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700455 requireInitialization();
456 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800457 }
458
John Reck35e9dd62011-04-25 09:01:54 -0700459 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700460 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700461 return mWebStorageSizeManager;
462 }
463
John Reck35e9dd62011-04-25 09:01:54 -0700464 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700465 if (mAppCachePath == null) {
466 mAppCachePath = mContext.getDir("appcache", 0).getPath();
467 }
468 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700469 }
470
471 private void updateSearchEngine(boolean force) {
472 String searchEngineName = getSearchEngineName();
473 if (force || mSearchEngine == null ||
474 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700475 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000476 }
477 }
478
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100479 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700480 if (mSearchEngine == null) {
481 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100482 }
John Reck35e9dd62011-04-25 09:01:54 -0700483 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100484 }
485
John Reck35e9dd62011-04-25 09:01:54 -0700486 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700487 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700488 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100489 }
490
John Reck35e9dd62011-04-25 09:01:54 -0700491 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700492 Editor edit = mPrefs.edit();
493 edit.putBoolean(PREF_DEBUG_MENU, value);
494 if (!value) {
495 // Reset to "safe" value
496 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
497 }
498 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100499 }
500
John Reck35e9dd62011-04-25 09:01:54 -0700501 public void clearCache() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800502 WebIconDatabase.getInstance().removeAllIcons();
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 if (mController != null) {
504 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800505 if (current != null) {
506 current.clearCache(true);
507 }
508 }
509 }
510
John Reck35e9dd62011-04-25 09:01:54 -0700511 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800512 CookieManager.getInstance().removeAllCookie();
513 }
514
John Reck35e9dd62011-04-25 09:01:54 -0700515 public void clearHistory() {
516 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800517 Browser.clearHistory(resolver);
518 Browser.clearSearches(resolver);
519 }
520
John Reck35e9dd62011-04-25 09:01:54 -0700521 public void clearFormData() {
522 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700523 if (mController!= null) {
524 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100525 if (currentTopView != null) {
526 currentTopView.clearFormData();
527 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800528 }
529 }
530
John Reck35e9dd62011-04-25 09:01:54 -0700531 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700532 // Clear password store maintained by SWE engine
533 WebSettings settings = null;
534 // find a valid settings object
535 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
536 while (iter.hasNext()) {
537 WeakReference<WebSettings> ref = iter.next();
538 settings = (WebSettings)ref.get();
539 if (settings != null) {
540 break;
541 }
542 }
543 if (settings != null) {
544 settings.clearPasswords();
545 }
546
547 // Clear passwords in WebView database
John Reck35e9dd62011-04-25 09:01:54 -0700548 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800549 db.clearUsernamePassword();
550 db.clearHttpAuthUsernamePassword();
551 }
552
John Reck35e9dd62011-04-25 09:01:54 -0700553 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100554 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100555 }
556
John Reck35e9dd62011-04-25 09:01:54 -0700557 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100558 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100559 }
560
John Reck35e9dd62011-04-25 09:01:54 -0700561 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700562 mPrefs.edit()
563 .clear()
John Reckbd315192011-07-29 10:05:47 -0700564 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200565 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700566 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700567 }
568
Björn Isakssonc885a242012-06-05 17:19:04 +0200569 private void resetCachedValues() {
570 updateSearchEngine(false);
571 }
572
John Reck35e9dd62011-04-25 09:01:54 -0700573 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800574 // query the profile from components autofill database 524
575 if (mAutofillHandler.mAutoFillProfile == null &&
576 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
577 WebSettings settings = null;
578 // find a valid settings object
579 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
580 while (iter.hasNext()) {
581 WeakReference<WebSettings> ref = iter.next();
582 settings = (WebSettings)ref.get();
583 if (settings != null) {
584 break;
585 }
586 }
587 if (settings != null) {
588 AutoFillProfile profile =
589 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
590 mAutofillHandler.setAutoFillProfile(profile);
591 }
592 }
John Reck35e9dd62011-04-25 09:01:54 -0700593 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800594 }
595
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800596 public String getAutoFillProfileId() {
597 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800598 }
599
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800600 public void updateAutoFillProfile(AutoFillProfile profile) {
601 syncAutoFillProfile(profile);
602 }
603
604 private void syncAutoFillProfile(AutoFillProfile profile) {
605 synchronized (mManagedSettings) {
606 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
607 while (iter.hasNext()) {
608 WeakReference<WebSettings> ref = iter.next();
609 WebSettings settings = (WebSettings)ref.get();
610 if (settings == null) {
611 iter.remove();
612 continue;
613 }
614 // update the profile only once.
615 settings.setAutoFillProfile(profile);
616 // Now we should have the guid
617 mAutofillHandler.setAutoFillProfile(profile);
618 break;
619 }
620 }
621 }
John Reck35e9dd62011-04-25 09:01:54 -0700622 public void toggleDebugSettings() {
623 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800624 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100625
John Reckb8b2af82011-05-20 15:58:33 -0700626 public boolean hasDesktopUseragent(WebView view) {
627 return view != null && mCustomUserAgents.get(view.getSettings()) != null;
628 }
629
630 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700631 if (view == null) {
632 return;
633 }
John Reckb8b2af82011-05-20 15:58:33 -0700634 WebSettings settings = view.getSettings();
635 if (mCustomUserAgents.get(settings) != null) {
636 mCustomUserAgents.remove(settings);
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700637 setUserAgent(settings);
John Reckb8b2af82011-05-20 15:58:33 -0700638 } else {
639 mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
640 settings.setUserAgentString(DESKTOP_USERAGENT);
641 }
642 }
643
John Reck7dc444b2011-06-16 17:44:29 -0700644 public static int getAdjustedMinimumFontSize(int rawValue) {
645 rawValue++; // Preference starts at 0, min font at 1
646 if (rawValue > 1) {
647 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
648 }
649 return rawValue;
650 }
651
John Reck5ba3c762011-09-14 15:00:15 -0700652 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700653 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700654 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700655 }
656
657 static int getRawTextZoom(int percent) {
658 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
659 }
660
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700661 public int getAdjustedDoubleTapZoom(int rawValue) {
662 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
663 return (int) ((rawValue + 100) * mFontSizeMult);
664 }
665
666 static int getRawDoubleTapZoom(int percent) {
667 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
668 }
669
John Reckcadae722011-07-25 11:36:17 -0700670 public SharedPreferences getPreferences() {
671 return mPrefs;
672 }
673
Victoria Lease96497832012-03-23 14:19:56 -0700674 // update connectivity-dependent options
675 public void updateConnectionType() {
676 ConnectivityManager cm = (ConnectivityManager)
677 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
678 String linkPrefetchPreference = getLinkPrefetchEnabled();
679 boolean linkPrefetchAllowed = linkPrefetchPreference.
680 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
681 NetworkInfo ni = cm.getActiveNetworkInfo();
682 if (ni != null) {
683 switch (ni.getType()) {
684 case ConnectivityManager.TYPE_WIFI:
685 case ConnectivityManager.TYPE_ETHERNET:
686 case ConnectivityManager.TYPE_BLUETOOTH:
687 linkPrefetchAllowed |= linkPrefetchPreference.
688 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
689 break;
690 case ConnectivityManager.TYPE_MOBILE:
691 case ConnectivityManager.TYPE_MOBILE_DUN:
692 case ConnectivityManager.TYPE_MOBILE_MMS:
693 case ConnectivityManager.TYPE_MOBILE_SUPL:
694 case ConnectivityManager.TYPE_WIMAX:
695 default:
696 break;
697 }
698 }
699 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
700 mLinkPrefetchAllowed = linkPrefetchAllowed;
701 syncManagedSettings();
702 }
703 }
704
luxiaol62677b02013-07-22 07:54:49 +0800705 public String getDownloadPath() {
706 return mPrefs.getString(PREF_DOWNLOAD_PATH,
707 DownloadHandler.getDefaultDownloadPath(mContext));
708 }
John Reck35e9dd62011-04-25 09:01:54 -0700709 // -----------------------------
710 // getter/setters for accessibility_preferences.xml
711 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100712
John Reck7dc444b2011-06-16 17:44:29 -0700713 @Deprecated
714 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700715 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
716 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100717 }
718
John Reck35e9dd62011-04-25 09:01:54 -0700719 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700720 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700721 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100722 }
723
John Reck92f25f82011-04-26 16:57:10 -0700724 public boolean forceEnableUserScalable() {
725 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
726 }
727
John Reck7dc444b2011-06-16 17:44:29 -0700728 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700729 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700730 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
731 return getAdjustedTextZoom(textZoom);
732 }
733
734 public void setTextZoom(int percent) {
735 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
736 }
737
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700738 public int getDoubleTapZoom() {
739 requireInitialization();
740 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
741 return getAdjustedDoubleTapZoom(doubleTapZoom);
742 }
743
744 public void setDoubleTapZoom(int percent) {
745 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
746 }
747
John Reck35e9dd62011-04-25 09:01:54 -0700748 // -----------------------------
749 // getter/setters for advanced_preferences.xml
750 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100751
John Reck35e9dd62011-04-25 09:01:54 -0700752 public String getSearchEngineName() {
luxiaol221b3932013-07-19 15:27:57 +0800753 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
754 if (defaultSearchEngineValue == null) {
755 defaultSearchEngineValue = SearchEngine.GOOGLE;
756 }
757 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100758 }
John Reck63bb6872010-12-01 19:29:32 -0800759
Michael Kolb8d772b02012-01-19 13:56:00 -0800760 public boolean allowAppTabs() {
761 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
762 }
763
John Reck35e9dd62011-04-25 09:01:54 -0700764 public boolean openInBackground() {
765 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800766 }
John Reck35e9dd62011-04-25 09:01:54 -0700767
768 public boolean enableJavascript() {
769 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
770 }
771
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800772 public boolean enableMemoryMonitor() {
773 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
774 }
775
John Reck35e9dd62011-04-25 09:01:54 -0700776 // TODO: Cache
777 public PluginState getPluginState() {
778 String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
779 return PluginState.valueOf(state);
780 }
781
782 // TODO: Cache
783 public ZoomDensity getDefaultZoom() {
784 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
Tarun Nainanic8e6dda2014-04-17 13:11:25 -0700785 ZoomDensity zoomDensity = ZoomDensity.valueOf(zoom);
786 //SWE: If zoomDensity is not MEDIUM, set enableWideViewport to false.
787 if(zoomDensity != ZoomDensity.MEDIUM)
788 enableWideViewport = false;
789 else
790 enableWideViewport = true;
791 return zoomDensity;
John Reck35e9dd62011-04-25 09:01:54 -0700792 }
793
794 public boolean loadPageInOverviewMode() {
795 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
796 }
797
798 public boolean autofitPages() {
799 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
800 }
801
802 public boolean blockPopupWindows() {
803 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
804 }
805
806 public boolean loadImages() {
807 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
808 }
809
810 public String getDefaultTextEncoding() {
811 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
812 }
813
814 // -----------------------------
815 // getter/setters for general_preferences.xml
816 // -----------------------------
817
818 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700819 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
820 }
821
822 public void setHomePage(String value) {
823 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
824 }
825
826 public boolean isAutofillEnabled() {
827 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
828 }
829
830 public void setAutofillEnabled(boolean value) {
831 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
832 }
833
834 // -----------------------------
835 // getter/setters for debug_preferences.xml
836 // -----------------------------
837
838 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700839 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700840 return true;
841 }
842 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
843 }
844
Derek Sollenberger31adf672011-07-08 11:31:30 -0400845 public boolean isSkiaHardwareAccelerated() {
846 if (!isDebugEnabled()) {
847 return false;
848 }
849 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
850 }
851
John Reck35e9dd62011-04-25 09:01:54 -0700852 public int getUserAgent() {
John Reckf48314f2011-04-27 17:52:17 -0700853 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700854 return 0;
855 }
856 return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
857 }
858
859 // -----------------------------
860 // getter/setters for hidden_debug_preferences.xml
861 // -----------------------------
862
863 public boolean enableVisualIndicator() {
864 if (!isDebugEnabled()) {
865 return false;
866 }
867 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
868 }
869
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700870 public boolean enableCpuUploadPath() {
871 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700872 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700873 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700874 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700875 }
876
John Reck35e9dd62011-04-25 09:01:54 -0700877 public boolean enableJavascriptConsole() {
878 if (!isDebugEnabled()) {
879 return false;
880 }
881 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
882 }
883
884 public boolean isSmallScreen() {
885 if (!isDebugEnabled()) {
886 return false;
887 }
888 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
889 }
890
891 public boolean isWideViewport() {
892 if (!isDebugEnabled()) {
Tarun Nainanic8e6dda2014-04-17 13:11:25 -0700893 return enableWideViewport;
John Reck35e9dd62011-04-25 09:01:54 -0700894 }
Tarun Nainanic8e6dda2014-04-17 13:11:25 -0700895 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, enableWideViewport);
John Reck35e9dd62011-04-25 09:01:54 -0700896 }
897
898 public boolean isNormalLayout() {
899 if (!isDebugEnabled()) {
900 return false;
901 }
902 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
903 }
904
905 public boolean isTracing() {
906 if (!isDebugEnabled()) {
907 return false;
908 }
909 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
910 }
911
912 public boolean enableLightTouch() {
913 if (!isDebugEnabled()) {
914 return false;
915 }
916 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
917 }
918
919 public boolean enableNavDump() {
920 if (!isDebugEnabled()) {
921 return false;
922 }
923 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
924 }
925
926 public String getJsEngineFlags() {
927 if (!isDebugEnabled()) {
928 return "";
929 }
930 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
931 }
932
933 // -----------------------------
934 // getter/setters for lab_preferences.xml
935 // -----------------------------
936
937 public boolean useQuickControls() {
938 return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
939 }
940
941 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700942 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700943 }
944
Michael Kolbc38c6042011-04-27 10:46:06 -0700945 public boolean useFullscreen() {
946 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
947 }
948
John Reck2fd9d0e2011-07-15 11:13:48 -0700949 public boolean useInvertedRendering() {
950 return mPrefs.getBoolean(PREF_INVERTED, false);
951 }
952
Nicolas Roard5d513102011-08-03 15:35:34 -0700953 public float getInvertedContrast() {
954 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
955 }
956
John Reck35e9dd62011-04-25 09:01:54 -0700957 // -----------------------------
958 // getter/setters for privacy_security_preferences.xml
959 // -----------------------------
960
961 public boolean showSecurityWarnings() {
962 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
963 }
964
965 public boolean acceptCookies() {
966 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
967 }
968
969 public boolean saveFormdata() {
970 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
971 }
972
973 public boolean enableGeolocation() {
974 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
975 }
976
977 public boolean rememberPasswords() {
978 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
979 }
980
Michael Kolb14612442011-06-24 13:06:29 -0700981 // -----------------------------
982 // getter/setters for bandwidth_preferences.xml
983 // -----------------------------
984
Mathew Inwood467813f2011-09-02 15:43:17 +0100985 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
986 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700987 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100988
989 public static String getPreloadAlwaysPreferenceString(Context context) {
990 return context.getResources().getString(R.string.pref_data_preload_value_always);
991 }
992
Mathew Inwood825fba72011-10-04 14:52:52 +0100993 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
994 "browser_default_preload_setting";
995
996 public String getDefaultPreloadSetting() {
997 String preload = Settings.Secure.getString(mContext.getContentResolver(),
998 DEAULT_PRELOAD_SECURE_SETTING_KEY);
999 if (preload == null) {
1000 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
1001 }
1002 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +01001003 }
1004
1005 public String getPreloadEnabled() {
1006 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
1007 }
1008
Victoria Lease96497832012-03-23 14:19:56 -07001009 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
1010 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
1011 }
1012
1013 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
1014 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
1015 }
1016
1017 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
1018 "browser_default_link_prefetch_setting";
1019
1020 public String getDefaultLinkPrefetchSetting() {
1021 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1022 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
1023 if (preload == null) {
1024 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
1025 }
1026 return preload;
1027 }
1028
1029 public String getLinkPrefetchEnabled() {
1030 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
1031 }
1032
George Mount3636d0a2011-11-21 09:08:21 -08001033 // -----------------------------
1034 // getter/setters for browser recovery
1035 // -----------------------------
1036 /**
1037 * The last time browser was started.
1038 * @return The last browser start time as System.currentTimeMillis. This
1039 * can be 0 if this is the first time or the last tab was closed.
1040 */
1041 public long getLastRecovered() {
1042 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1043 }
1044
1045 /**
1046 * Sets the last browser start time.
1047 * @param time The last time as System.currentTimeMillis that the browser
1048 * was started. This should be set to 0 if the last tab is closed.
1049 */
1050 public void setLastRecovered(long time) {
1051 mPrefs.edit()
1052 .putLong(KEY_LAST_RECOVERED, time)
1053 .apply();
1054 }
1055
1056 /**
1057 * Used to determine whether or not the previous browser run crashed. Once
1058 * the previous state has been determined, the value will be set to false
1059 * until a pause is received.
1060 * @return true if the last browser run was paused or false if it crashed.
1061 */
1062 public boolean wasLastRunPaused() {
1063 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1064 }
1065
1066 /**
1067 * Sets whether or not the last run was a pause or crash.
1068 * @param isPaused Set to true When a pause is received or false after
1069 * resuming.
1070 */
1071 public void setLastRunPaused(boolean isPaused) {
1072 mPrefs.edit()
1073 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1074 .apply();
1075 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001076}