blob: 7d6e3f92c92fae5b1e003e20e1f05ecbedba9971 [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;
Mathew Inwood825fba72011-10-04 14:52:52 +010028import android.provider.Settings;
Bijan Amirzadae75909d2014-05-06 14:18:54 -070029import android.text.TextUtils;
John Reck5ba3c762011-09-14 15:00:15 -070030import android.util.DisplayMetrics;
Nicolas Roard78a98e42009-05-11 13:34:17 +010031import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Bijan Amirzada41242f22014-03-21 12:12:18 -070033import com.android.browser.R;
34import com.android.browser.homepages.HomeProvider;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070035import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070036import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.search.SearchEngine;
38import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070039
John Reck35e9dd62011-04-25 09:01:54 -070040import java.lang.ref.WeakReference;
41import java.util.Iterator;
42import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070043import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080045import org.codeaurora.swe.AutoFillProfile;
46import org.codeaurora.swe.CookieManager;
47import org.codeaurora.swe.GeolocationPermissions;
48import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
49import org.codeaurora.swe.WebSettings.PluginState;
50import org.codeaurora.swe.WebSettings.TextSize;
51import org.codeaurora.swe.WebSettings.ZoomDensity;
52import org.codeaurora.swe.WebSettings;
53import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070054import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080055
John Reck35e9dd62011-04-25 09:01:54 -070056/**
57 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080058 */
John Reck35e9dd62011-04-25 09:01:54 -070059public class BrowserSettings implements OnSharedPreferenceChangeListener,
60 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010061
qqzhoue6ff8b42013-07-23 17:28:48 +080062 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070063 // The minimum min font size
64 // Aka, the lower bounds for the min font size range
65 // which is 1:5..24
66 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070067 // The initial value in the text zoom range
68 // This is what represents 100% in the SeekBarPreference range
69 private static final int TEXT_ZOOM_START_VAL = 10;
70 // The size of a single step in the text zoom range, in percent
71 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070072 // The initial value in the double tap zoom range
73 // This is what represents 100% in the SeekBarPreference range
74 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
75 // The size of a single step in the double tap zoom range, in percent
76 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070077
John Reck35e9dd62011-04-25 09:01:54 -070078 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070079
John Reck35e9dd62011-04-25 09:01:54 -070080 private Context mContext;
81 private SharedPreferences mPrefs;
82 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070084 private WebStorageSizeManager mWebStorageSizeManager;
85 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010086 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070087 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070088 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070089
Victoria Lease96497832012-03-23 14:19:56 -070090 // Current state of network-dependent settings
91 private boolean mLinkPrefetchAllowed = true;
92
John Reck78a6a1d2011-07-21 13:54:03 -070093 // Cached values
94 private int mPageCacheCapacity = 1;
95 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080096
John Reck35e9dd62011-04-25 09:01:54 -070097 // Cached settings
98 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080099
Ben Murdochaaa1f372011-07-25 15:40:58 +0100100 private static String sFactoryResetUrl;
101
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700102 private boolean mEngineInitialized = false;
103 private boolean mSyncManagedSettings = false;
104
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700105 public static synchronized void initialize(final Context context) {
106 if (sInstance == null)
107 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700108 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800109
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700110 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700111 return sInstance;
112 }
Ben Murdochef671652010-11-25 17:17:58 +0000113
John Reck35e9dd62011-04-25 09:01:54 -0700114 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100115 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700116 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700117 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700118 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700119 }
120
121 public void setController(Controller controller) {
122 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700123 mNeedsSharedSync = true;
124 }
125
126 public void onEngineInitializationComplete() {
127 mEngineInitialized = true;
128 mAutofillHandler = new AutofillHandler(mContext);
129 if (mSyncManagedSettings) {
130 syncManagedSettings();
131 }
132 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700133 syncSharedSettings();
134 }
Ben Murdochef671652010-11-25 17:17:58 +0000135 }
136
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800137 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800138
John Reckc477e712011-08-17 11:27:15 -0700139 if (mNeedsSharedSync) {
140 syncSharedSettings();
141 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800142
John Reck35e9dd62011-04-25 09:01:54 -0700143 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800144 syncStaticSettings(settings);
145 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700146 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800147 }
148 }
149
John Reckd1d87312012-03-08 13:25:00 -0800150 public void stopManagingSettings(WebSettings settings) {
151 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
152 while (iter.hasNext()) {
153 WeakReference<WebSettings> ref = iter.next();
154 if (ref.get() == settings) {
155 iter.remove();
156 return;
157 }
158 }
159 }
160
John Reckcadae722011-07-25 11:36:17 -0700161 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700162
163 @Override
164 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700165 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
166 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700167 // the cost of one cached page is ~3M (measured using nytimes.com). For
168 // low end devices, we only cache one page. For high end devices, we try
169 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800170
171 // SWE_TODO : assume a high-memory device
172 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700173 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800174 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700175 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
176 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
177 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700178 // Workaround b/5254577
179 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700180 if (Build.VERSION.CODENAME.equals("REL")) {
181 // This is a release build, always startup with debug disabled
182 setDebugEnabled(false);
183 }
184 if (mPrefs.contains(PREF_TEXT_SIZE)) {
185 /*
186 * Update from TextSize enum to zoom percent
187 * SMALLEST is 50%
188 * SMALLER is 75%
189 * NORMAL is 100%
190 * LARGER is 150%
191 * LARGEST is 200%
192 */
193 switch (getTextSize()) {
194 case SMALLEST:
195 setTextZoom(50);
196 break;
197 case SMALLER:
198 setTextZoom(75);
199 break;
200 case LARGER:
201 setTextZoom(150);
202 break;
203 case LARGEST:
204 setTextZoom(200);
205 break;
206 }
207 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
208 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100209
qqzhou8c5b0a32013-07-22 15:31:03 +0800210 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700211 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800212
kaiyizbf086ea2013-08-02 11:03:58 +0800213 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800214 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800215 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700216
Ben Murdochaaa1f372011-07-25 15:40:58 +0100217 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
218 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
219 BrowserProvider.getClientId(mContext.getContentResolver()));
220 }
221
Ben Murdochaaa1f372011-07-25 15:40:58 +0100222 synchronized (BrowserSettings.class) {
223 sInitialized = true;
224 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700225 }
226 }
227 };
228
Ben Murdochaaa1f372011-07-25 15:40:58 +0100229 private static void requireInitialization() {
230 synchronized (BrowserSettings.class) {
231 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700232 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100233 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700234 } catch (InterruptedException e) {
235 }
236 }
237 }
238 }
239
The Android Open Source Project0c908882009-03-03 19:32:16 -0800240 /**
John Reck35e9dd62011-04-25 09:01:54 -0700241 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800242 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800243 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700244 settings.setGeolocationEnabled(enableGeolocation());
245 settings.setJavaScriptEnabled(enableJavascript());
246 settings.setLightTouchEnabled(enableLightTouch());
247 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700248 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
249 settings.setDefaultZoom(getDefaultZoom());
250 settings.setMinimumFontSize(getMinimumFontSize());
251 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700252 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700253 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100254 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700255 settings.setLoadsImagesAutomatically(loadImages());
256 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
257 settings.setSavePassword(rememberPasswords());
258 settings.setSaveFormData(saveFormdata());
259 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700260 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700261 settings.setMediaPlaybackRequiresUserGesture(false);
262 settings.setAllowMediaDownloads(allowMediaDownloads());
263 setExtraHTTPRequestHeaders(settings);
John Reck2fd9d0e2011-07-15 11:13:48 -0700264
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800265 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800266 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
267 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
268 settingsClassic.setForceUserScalable(forceEnableUserScalable());
269 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
270 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800271
John Reckea17e782011-10-27 17:15:59 -0700272 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800273 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700274 useInverted ? "true" : "false");
275 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800276 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700277 Float.toString(getInvertedContrast()));
278 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700279
John Reckea17e782011-10-27 17:15:59 -0700280 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800281 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700282 enableCpuUploadPath() ? "true" : "false");
283 }
Victoria Lease96497832012-03-23 14:19:56 -0700284
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800285 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000286 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800287
Tarun Nainani8eb00912014-07-17 12:28:32 -0700288 private void setExtraHTTPRequestHeaders(WebSettings settings){
289 String headers = mContext.getResources().getString(R.string.def_extra_http_headers);
290 if (!TextUtils.isEmpty(headers)){
291 settings.setHTTPRequestHeaders(headers);
292 }
293 }
294
John Reck35e9dd62011-04-25 09:01:54 -0700295 /**
296 * Syncs all the settings that have no UI
297 * These cannot change, so we only need to set them once per WebSettings
298 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800299 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700300 settings.setDefaultFontSize(16);
301 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000302
John Reck35e9dd62011-04-25 09:01:54 -0700303 // WebView inside Browser doesn't want initial focus to be set.
304 settings.setNeedInitialFocus(false);
305 // Browser supports multiple windows
306 settings.setSupportMultipleWindows(true);
307 // enable smooth transition for better performance during panning or
308 // zooming
309 settings.setEnableSmoothTransition(true);
310 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700311 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700312
313 // HTML5 API flags
314 settings.setAppCacheEnabled(true);
315 settings.setDatabaseEnabled(true);
316 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700317
318 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700319 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700320 settings.setAppCachePath(getAppCachePath());
321 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
322 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700323 // origin policy for file access
324 settings.setAllowUniversalAccessFromFileURLs(false);
325 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700326 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800327
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800328 //if (!(settings instanceof WebSettingsClassic)) return;
329 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800330
331 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
332 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
333 // WebView should be preserving the memory as much as possible.
334 // However, apps like browser wish to turn on the performance mode which
335 // would require more memory.
336 // TODO: We need to dynamically allocate/deallocate temporary memory for
337 // apps which are trying to use minimal memory. Currently, double
338 // buffering is always turned on, which is unnecessary.
339 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
340 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800341 */
John Reck35e9dd62011-04-25 09:01:54 -0700342 }
343
344 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700345 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700346 CookieManager.getInstance().setAcceptCookie(acceptCookies());
John Reck35e9dd62011-04-25 09:01:54 -0700347 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700348
John Reck35e9dd62011-04-25 09:01:54 -0700349 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700350 if (!mEngineInitialized) {
351 mSyncManagedSettings = true;
352 return;
353 }
354 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700355 syncSharedSettings();
356 synchronized (mManagedSettings) {
357 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
358 while (iter.hasNext()) {
359 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800360 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700361 if (settings == null) {
362 iter.remove();
363 continue;
364 }
365 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000366 }
John Reck35e9dd62011-04-25 09:01:54 -0700367 }
368 }
Ben Murdochef671652010-11-25 17:17:58 +0000369
John Reck35e9dd62011-04-25 09:01:54 -0700370 @Override
371 public void onSharedPreferenceChanged(
372 SharedPreferences sharedPreferences, String key) {
373 syncManagedSettings();
374 if (PREF_SEARCH_ENGINE.equals(key)) {
375 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700376 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200377 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700378 mController.getUi().setFullscreen(useFullscreen());
379 }
Victoria Lease96497832012-03-23 14:19:56 -0700380 } else if (PREF_LINK_PREFETCH.equals(key)) {
381 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700382 }
John Reck35e9dd62011-04-25 09:01:54 -0700383 }
384
John Reck961d35d2011-06-23 09:45:54 -0700385 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100386 requireInitialization();
387 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700388 }
389
390 public LayoutAlgorithm getLayoutAlgorithm() {
391 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
392 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700393 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700394 }
395 if (isDebugEnabled()) {
396 if (isSmallScreen()) {
397 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000398 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700399 if (isNormalLayout()) {
400 layoutAlgorithm = LayoutAlgorithm.NORMAL;
401 } else {
402 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
403 }
Ben Murdochef671652010-11-25 17:17:58 +0000404 }
John Reck35e9dd62011-04-25 09:01:54 -0700405 }
406 return layoutAlgorithm;
407 }
Ben Murdochef671652010-11-25 17:17:58 +0000408
John Reck35e9dd62011-04-25 09:01:54 -0700409 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700410 requireInitialization();
411 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800412 }
413
John Reck35e9dd62011-04-25 09:01:54 -0700414 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700415 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700416 return mWebStorageSizeManager;
417 }
418
John Reck35e9dd62011-04-25 09:01:54 -0700419 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700420 if (mAppCachePath == null) {
421 mAppCachePath = mContext.getDir("appcache", 0).getPath();
422 }
423 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700424 }
425
426 private void updateSearchEngine(boolean force) {
427 String searchEngineName = getSearchEngineName();
428 if (force || mSearchEngine == null ||
429 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700430 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000431 }
432 }
433
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100434 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700435 if (mSearchEngine == null) {
436 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100437 }
John Reck35e9dd62011-04-25 09:01:54 -0700438 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100439 }
440
John Reck35e9dd62011-04-25 09:01:54 -0700441 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700442 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700443 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100444 }
445
John Reck35e9dd62011-04-25 09:01:54 -0700446 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700447 Editor edit = mPrefs.edit();
448 edit.putBoolean(PREF_DEBUG_MENU, value);
449 if (!value) {
450 // Reset to "safe" value
451 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
452 }
453 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100454 }
455
John Reck35e9dd62011-04-25 09:01:54 -0700456 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700457 if (mController != null) {
458 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459 if (current != null) {
460 current.clearCache(true);
461 }
462 }
463 }
464
John Reck35e9dd62011-04-25 09:01:54 -0700465 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800466 CookieManager.getInstance().removeAllCookie();
467 }
468
John Reck35e9dd62011-04-25 09:01:54 -0700469 public void clearHistory() {
470 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800471 Browser.clearHistory(resolver);
472 Browser.clearSearches(resolver);
473 }
474
John Reck35e9dd62011-04-25 09:01:54 -0700475 public void clearFormData() {
476 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700477 if (mController!= null) {
478 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100479 if (currentTopView != null) {
480 currentTopView.clearFormData();
481 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800482 }
483 }
484
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700485 public WebView getTopWebView(){
486 if (mController!= null)
487 return mController.getCurrentTopWebView();
488
489 return null;
490 }
491
John Reck35e9dd62011-04-25 09:01:54 -0700492 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700493 // Clear password store maintained by SWE engine
494 WebSettings settings = null;
495 // find a valid settings object
496 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
497 while (iter.hasNext()) {
498 WeakReference<WebSettings> ref = iter.next();
499 settings = (WebSettings)ref.get();
500 if (settings != null) {
501 break;
502 }
503 }
504 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700505 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700506 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700507
508 // Clear passwords in WebView database
509 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
510 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800511 }
512
John Reck35e9dd62011-04-25 09:01:54 -0700513 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100514 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100515 }
516
John Reck35e9dd62011-04-25 09:01:54 -0700517 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100518 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700519 if (GeolocationPermissions.isIncognitoCreated()) {
520 GeolocationPermissions.getIncognitoInstance().clearAll();
521 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100522 }
523
John Reck35e9dd62011-04-25 09:01:54 -0700524 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700525 mPrefs.edit()
526 .clear()
John Reckbd315192011-07-29 10:05:47 -0700527 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200528 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700529 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700530 }
531
Björn Isakssonc885a242012-06-05 17:19:04 +0200532 private void resetCachedValues() {
533 updateSearchEngine(false);
534 }
535
John Reck35e9dd62011-04-25 09:01:54 -0700536 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800537 // query the profile from components autofill database 524
538 if (mAutofillHandler.mAutoFillProfile == null &&
539 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
540 WebSettings settings = null;
541 // find a valid settings object
542 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
543 while (iter.hasNext()) {
544 WeakReference<WebSettings> ref = iter.next();
545 settings = (WebSettings)ref.get();
546 if (settings != null) {
547 break;
548 }
549 }
550 if (settings != null) {
551 AutoFillProfile profile =
552 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
553 mAutofillHandler.setAutoFillProfile(profile);
554 }
555 }
John Reck35e9dd62011-04-25 09:01:54 -0700556 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800557 }
558
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800559 public String getAutoFillProfileId() {
560 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800561 }
562
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800563 public void updateAutoFillProfile(AutoFillProfile profile) {
564 syncAutoFillProfile(profile);
565 }
566
567 private void syncAutoFillProfile(AutoFillProfile profile) {
568 synchronized (mManagedSettings) {
569 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
570 while (iter.hasNext()) {
571 WeakReference<WebSettings> ref = iter.next();
572 WebSettings settings = (WebSettings)ref.get();
573 if (settings == null) {
574 iter.remove();
575 continue;
576 }
577 // update the profile only once.
578 settings.setAutoFillProfile(profile);
579 // Now we should have the guid
580 mAutofillHandler.setAutoFillProfile(profile);
581 break;
582 }
583 }
584 }
John Reck35e9dd62011-04-25 09:01:54 -0700585 public void toggleDebugSettings() {
586 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800587 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100588
John Reckb8b2af82011-05-20 15:58:33 -0700589 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800590 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700591 }
592
593 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700594 if (view == null) {
595 return;
596 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800597 if (hasDesktopUseragent(view))
598 view.setUseDesktopUserAgent(false, true);
599 else
600 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700601 }
602
John Reck7dc444b2011-06-16 17:44:29 -0700603 public static int getAdjustedMinimumFontSize(int rawValue) {
604 rawValue++; // Preference starts at 0, min font at 1
605 if (rawValue > 1) {
606 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
607 }
608 return rawValue;
609 }
610
John Reck5ba3c762011-09-14 15:00:15 -0700611 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700612 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700613 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700614 }
615
616 static int getRawTextZoom(int percent) {
617 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
618 }
619
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700620 public int getAdjustedDoubleTapZoom(int rawValue) {
621 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
622 return (int) ((rawValue + 100) * mFontSizeMult);
623 }
624
625 static int getRawDoubleTapZoom(int percent) {
626 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
627 }
628
John Reckcadae722011-07-25 11:36:17 -0700629 public SharedPreferences getPreferences() {
630 return mPrefs;
631 }
632
Victoria Lease96497832012-03-23 14:19:56 -0700633 // update connectivity-dependent options
634 public void updateConnectionType() {
635 ConnectivityManager cm = (ConnectivityManager)
636 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
637 String linkPrefetchPreference = getLinkPrefetchEnabled();
638 boolean linkPrefetchAllowed = linkPrefetchPreference.
639 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
640 NetworkInfo ni = cm.getActiveNetworkInfo();
641 if (ni != null) {
642 switch (ni.getType()) {
643 case ConnectivityManager.TYPE_WIFI:
644 case ConnectivityManager.TYPE_ETHERNET:
645 case ConnectivityManager.TYPE_BLUETOOTH:
646 linkPrefetchAllowed |= linkPrefetchPreference.
647 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
648 break;
649 case ConnectivityManager.TYPE_MOBILE:
650 case ConnectivityManager.TYPE_MOBILE_DUN:
651 case ConnectivityManager.TYPE_MOBILE_MMS:
652 case ConnectivityManager.TYPE_MOBILE_SUPL:
653 case ConnectivityManager.TYPE_WIMAX:
654 default:
655 break;
656 }
657 }
658 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
659 mLinkPrefetchAllowed = linkPrefetchAllowed;
660 syncManagedSettings();
661 }
662 }
663
luxiaol62677b02013-07-22 07:54:49 +0800664 public String getDownloadPath() {
665 return mPrefs.getString(PREF_DOWNLOAD_PATH,
666 DownloadHandler.getDefaultDownloadPath(mContext));
667 }
John Reck35e9dd62011-04-25 09:01:54 -0700668 // -----------------------------
669 // getter/setters for accessibility_preferences.xml
670 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100671
John Reck7dc444b2011-06-16 17:44:29 -0700672 @Deprecated
673 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700674 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
675 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100676 }
677
John Reck35e9dd62011-04-25 09:01:54 -0700678 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700679 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700680 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100681 }
682
John Reck92f25f82011-04-26 16:57:10 -0700683 public boolean forceEnableUserScalable() {
684 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
685 }
686
John Reck7dc444b2011-06-16 17:44:29 -0700687 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700688 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700689 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
690 return getAdjustedTextZoom(textZoom);
691 }
692
693 public void setTextZoom(int percent) {
694 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
695 }
696
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700697 public int getDoubleTapZoom() {
698 requireInitialization();
699 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
700 return getAdjustedDoubleTapZoom(doubleTapZoom);
701 }
702
703 public void setDoubleTapZoom(int percent) {
704 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
705 }
706
John Reck35e9dd62011-04-25 09:01:54 -0700707 // -----------------------------
708 // getter/setters for advanced_preferences.xml
709 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100710
John Reck35e9dd62011-04-25 09:01:54 -0700711 public String getSearchEngineName() {
luxiaol221b3932013-07-19 15:27:57 +0800712 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
713 if (defaultSearchEngineValue == null) {
714 defaultSearchEngineValue = SearchEngine.GOOGLE;
715 }
716 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100717 }
John Reck63bb6872010-12-01 19:29:32 -0800718
Michael Kolb8d772b02012-01-19 13:56:00 -0800719 public boolean allowAppTabs() {
720 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
721 }
722
John Reck35e9dd62011-04-25 09:01:54 -0700723 public boolean openInBackground() {
724 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800725 }
John Reck35e9dd62011-04-25 09:01:54 -0700726
727 public boolean enableJavascript() {
728 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
729 }
730
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800731 public boolean enableMemoryMonitor() {
732 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
733 }
734
Tarun Nainani8eb00912014-07-17 12:28:32 -0700735 public boolean allowMediaDownloads() {
Panos Thomas4bdb5252014-11-13 16:20:11 -0800736 // Return false if preference is not exposed to user
737 if (!BrowserConfig.getInstance(mContext)
738 .hasFeature(BrowserConfig.Feature.ALLOW_MEDIA_DOWNLOADS))
739 return false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700740
Panos Thomas4bdb5252014-11-13 16:20:11 -0800741 // Otherwise, look at default value
742 boolean defaultAllowMediaDownloadsValue = mController.getContext()
743 .getResources().getBoolean(R.bool.def_allow_media_downloads);
744
745 // If preference is not saved, save default value
746 if (!mPrefs.contains(PREF_ALLOW_MEDIA_DOWNLOADS)){
Tarun Nainani8eb00912014-07-17 12:28:32 -0700747 Editor edit = mPrefs.edit();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800748 edit.putBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700749 edit.apply();
750 }
751
Panos Thomas4bdb5252014-11-13 16:20:11 -0800752 return mPrefs.getBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700753 }
754
John Reck35e9dd62011-04-25 09:01:54 -0700755 // TODO: Cache
John Reck35e9dd62011-04-25 09:01:54 -0700756 public ZoomDensity getDefaultZoom() {
757 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800758 return ZoomDensity.valueOf(zoom);
John Reck35e9dd62011-04-25 09:01:54 -0700759 }
760
761 public boolean loadPageInOverviewMode() {
762 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
763 }
764
765 public boolean autofitPages() {
766 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
767 }
768
769 public boolean blockPopupWindows() {
770 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
771 }
772
773 public boolean loadImages() {
774 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
775 }
776
777 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800778 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
779 if(autoDetect.equalsIgnoreCase("auto")) {
780 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
781 }
782 return autoDetect;
John Reck35e9dd62011-04-25 09:01:54 -0700783 }
784
785 // -----------------------------
786 // getter/setters for general_preferences.xml
787 // -----------------------------
788
789 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700790 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
791 }
792
793 public void setHomePage(String value) {
794 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
795 }
796
797 public boolean isAutofillEnabled() {
798 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
799 }
800
801 public void setAutofillEnabled(boolean value) {
802 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
803 }
804
805 // -----------------------------
806 // getter/setters for debug_preferences.xml
807 // -----------------------------
808
809 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700810 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700811 return true;
812 }
813 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
814 }
815
Derek Sollenberger31adf672011-07-08 11:31:30 -0400816 public boolean isSkiaHardwareAccelerated() {
817 if (!isDebugEnabled()) {
818 return false;
819 }
820 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
821 }
822
John Reck35e9dd62011-04-25 09:01:54 -0700823 // -----------------------------
824 // getter/setters for hidden_debug_preferences.xml
825 // -----------------------------
826
827 public boolean enableVisualIndicator() {
828 if (!isDebugEnabled()) {
829 return false;
830 }
831 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
832 }
833
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700834 public boolean enableCpuUploadPath() {
835 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700836 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700837 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700838 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700839 }
840
John Reck35e9dd62011-04-25 09:01:54 -0700841 public boolean isSmallScreen() {
842 if (!isDebugEnabled()) {
843 return false;
844 }
845 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
846 }
847
848 public boolean isWideViewport() {
849 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800850 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700851 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800852 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700853 }
854
855 public boolean isNormalLayout() {
856 if (!isDebugEnabled()) {
857 return false;
858 }
859 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
860 }
861
862 public boolean isTracing() {
863 if (!isDebugEnabled()) {
864 return false;
865 }
866 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
867 }
868
869 public boolean enableLightTouch() {
870 if (!isDebugEnabled()) {
871 return false;
872 }
873 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
874 }
875
876 public boolean enableNavDump() {
877 if (!isDebugEnabled()) {
878 return false;
879 }
880 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
881 }
882
883 public String getJsEngineFlags() {
884 if (!isDebugEnabled()) {
885 return "";
886 }
887 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
888 }
889
890 // -----------------------------
891 // getter/setters for lab_preferences.xml
892 // -----------------------------
893
John Reck35e9dd62011-04-25 09:01:54 -0700894 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700895 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700896 }
897
Michael Kolbc38c6042011-04-27 10:46:06 -0700898 public boolean useFullscreen() {
899 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
900 }
901
John Reck2fd9d0e2011-07-15 11:13:48 -0700902 public boolean useInvertedRendering() {
903 return mPrefs.getBoolean(PREF_INVERTED, false);
904 }
905
Nicolas Roard5d513102011-08-03 15:35:34 -0700906 public float getInvertedContrast() {
907 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
908 }
909
John Reck35e9dd62011-04-25 09:01:54 -0700910 // -----------------------------
911 // getter/setters for privacy_security_preferences.xml
912 // -----------------------------
913
914 public boolean showSecurityWarnings() {
915 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
916 }
917
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700918 public boolean doNotTrack() {
919 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
920 }
921
John Reck35e9dd62011-04-25 09:01:54 -0700922 public boolean acceptCookies() {
923 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
924 }
925
926 public boolean saveFormdata() {
927 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
928 }
929
930 public boolean enableGeolocation() {
931 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
932 }
933
934 public boolean rememberPasswords() {
935 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
936 }
937
Michael Kolb14612442011-06-24 13:06:29 -0700938 // -----------------------------
939 // getter/setters for bandwidth_preferences.xml
940 // -----------------------------
941
Mathew Inwood467813f2011-09-02 15:43:17 +0100942 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
943 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700944 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100945
946 public static String getPreloadAlwaysPreferenceString(Context context) {
947 return context.getResources().getString(R.string.pref_data_preload_value_always);
948 }
949
Mathew Inwood825fba72011-10-04 14:52:52 +0100950 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
951 "browser_default_preload_setting";
952
953 public String getDefaultPreloadSetting() {
954 String preload = Settings.Secure.getString(mContext.getContentResolver(),
955 DEAULT_PRELOAD_SECURE_SETTING_KEY);
956 if (preload == null) {
957 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
958 }
959 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100960 }
961
962 public String getPreloadEnabled() {
963 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
964 }
965
Victoria Lease96497832012-03-23 14:19:56 -0700966 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
967 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
968 }
969
970 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
971 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
972 }
973
974 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
975 "browser_default_link_prefetch_setting";
976
977 public String getDefaultLinkPrefetchSetting() {
978 String preload = Settings.Secure.getString(mContext.getContentResolver(),
979 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
980 if (preload == null) {
981 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
982 }
983 return preload;
984 }
985
986 public String getLinkPrefetchEnabled() {
987 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
988 }
989
George Mount3636d0a2011-11-21 09:08:21 -0800990 // -----------------------------
991 // getter/setters for browser recovery
992 // -----------------------------
993 /**
994 * The last time browser was started.
995 * @return The last browser start time as System.currentTimeMillis. This
996 * can be 0 if this is the first time or the last tab was closed.
997 */
998 public long getLastRecovered() {
999 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1000 }
1001
1002 /**
1003 * Sets the last browser start time.
1004 * @param time The last time as System.currentTimeMillis that the browser
1005 * was started. This should be set to 0 if the last tab is closed.
1006 */
1007 public void setLastRecovered(long time) {
1008 mPrefs.edit()
1009 .putLong(KEY_LAST_RECOVERED, time)
1010 .apply();
1011 }
1012
1013 /**
1014 * Used to determine whether or not the previous browser run crashed. Once
1015 * the previous state has been determined, the value will be set to false
1016 * until a pause is received.
1017 * @return true if the last browser run was paused or false if it crashed.
1018 */
1019 public boolean wasLastRunPaused() {
1020 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1021 }
1022
1023 /**
1024 * Sets whether or not the last run was a pause or crash.
1025 * @param isPaused Set to true When a pause is received or false after
1026 * resuming.
1027 */
1028 public void setLastRunPaused(boolean isPaused) {
1029 mPrefs.edit()
1030 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1031 .apply();
1032 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001033}