blob: ca5c283be53a931c8208d3eddb68bb57a0d78f48 [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;
John Reck5ba3c762011-09-14 15:00:15 -070029import android.util.DisplayMetrics;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -070030import android.webkit.ValueCallback;
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.homepages.HomeProvider;
Dave Tharpb487d5d2015-05-15 15:54:08 -070034import com.android.browser.mdm.DoNotTrackRestriction;
Panos Thomasa9ff2c72014-12-17 22:15:23 -080035import com.android.browser.mdm.ProxyRestriction;
Panos Thomas64c77e02014-12-17 22:15:23 -080036import com.android.browser.mdm.SearchEngineRestriction;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070037import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070038import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070039import com.android.browser.search.SearchEngine;
40import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070041
John Reck35e9dd62011-04-25 09:01:54 -070042import java.lang.ref.WeakReference;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -070043import java.util.ArrayList;
John Reck35e9dd62011-04-25 09:01:54 -070044import java.util.Iterator;
45import java.util.LinkedList;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -070046import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080047
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080048import org.codeaurora.swe.AutoFillProfile;
49import org.codeaurora.swe.CookieManager;
50import org.codeaurora.swe.GeolocationPermissions;
Pankaj Garg32e1b942015-06-03 18:13:24 -070051import org.codeaurora.swe.PermissionsServiceFactory;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070052import org.codeaurora.swe.WebRefiner;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080053import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080054import org.codeaurora.swe.WebSettings.TextSize;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080055import org.codeaurora.swe.WebSettings;
56import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070057import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080058
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
qqzhoue6ff8b42013-07-23 17:28:48 +080065 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070066 // The minimum min font size
67 // Aka, the lower bounds for the min font size range
68 // which is 1:5..24
69 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070070 // The initial value in the text zoom range
71 // This is what represents 100% in the SeekBarPreference range
72 private static final int TEXT_ZOOM_START_VAL = 10;
73 // The size of a single step in the text zoom range, in percent
74 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070075 // The initial value in the double tap zoom range
76 // This is what represents 100% in the SeekBarPreference range
77 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
78 // The size of a single step in the double tap zoom range, in percent
79 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070080
John Reck35e9dd62011-04-25 09:01:54 -070081 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070082
John Reck35e9dd62011-04-25 09:01:54 -070083 private Context mContext;
84 private SharedPreferences mPrefs;
85 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070086 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070087 private WebStorageSizeManager mWebStorageSizeManager;
88 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010089 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070090 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070091 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070092
Victoria Lease96497832012-03-23 14:19:56 -070093 // Current state of network-dependent settings
94 private boolean mLinkPrefetchAllowed = true;
95
John Reck78a6a1d2011-07-21 13:54:03 -070096 // Cached values
97 private int mPageCacheCapacity = 1;
98 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080099
John Reck35e9dd62011-04-25 09:01:54 -0700100 // Cached settings
101 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800102
Ben Murdochaaa1f372011-07-25 15:40:58 +0100103 private static String sFactoryResetUrl;
104
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700105 private boolean mEngineInitialized = false;
106 private boolean mSyncManagedSettings = false;
107
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700108 public static synchronized void initialize(final Context context) {
109 if (sInstance == null)
110 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700111 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800112
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700113 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700114 return sInstance;
115 }
Ben Murdochef671652010-11-25 17:17:58 +0000116
John Reck35e9dd62011-04-25 09:01:54 -0700117 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100118 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700119 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700120 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700121 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700122 }
123
124 public void setController(Controller controller) {
125 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700126 mNeedsSharedSync = true;
127 }
128
129 public void onEngineInitializationComplete() {
130 mEngineInitialized = true;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -0700131
132 // Intialize Web Refiner only once
133 final WebRefiner refiner = WebRefiner.getInstance();
134 if (refiner != null) {
135 refiner.setRulesEnabled(WebRefiner.CATEGORY_ALL,
136 PermissionsServiceFactory.getDefaultPermissions(
137 PermissionsServiceFactory.PermissionType.WEBREFINER));
138
139 PermissionsServiceFactory.getPermissionsService(
140 new ValueCallback<PermissionsServiceFactory.PermissionsService>() {
141 @Override
142 public void onReceiveValue(
143 PermissionsServiceFactory.PermissionsService value) {
144 Set<String> origins = value.getOrigins();
145 ArrayList<String> allowList = new ArrayList<>();
146 ArrayList<String> blockList = new ArrayList<>();
147 for (String origin : origins) {
148 PermissionsServiceFactory.PermissionsService.OriginInfo
149 info = value.getOriginInfo(origin);
150 int perm = info.getPermission(
151 PermissionsServiceFactory.PermissionType.WEBREFINER);
152 if (perm == PermissionsServiceFactory.Permission.ALLOW) {
153 allowList.add(origin);
154 } else if (perm == PermissionsServiceFactory.Permission.BLOCK) {
155 blockList.add(origin);
156 }
157 }
158 if (!allowList.isEmpty()) {
159 refiner.enableRulesForDomains(WebRefiner.CATEGORY_ALL,
160 allowList.toArray(new String[allowList.size()]));
161 }
162
163 if (!blockList.isEmpty()) {
164 refiner.disableRulesForDomains(WebRefiner.CATEGORY_ALL,
165 blockList.toArray(new String[blockList.size()]));
166 }
167 }
168 }
169 );
170 }
171
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700172 mAutofillHandler = new AutofillHandler(mContext);
173 if (mSyncManagedSettings) {
174 syncManagedSettings();
175 }
176 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700177 syncSharedSettings();
178 }
Panos Thomasa9ff2c72014-12-17 22:15:23 -0800179 // Instantiate ProxyRestriction after engine initialization
180 // to ensure ProxyChangeListener is already created.
181 ProxyRestriction.getInstance();
Ben Murdochef671652010-11-25 17:17:58 +0000182 }
183
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800184 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800185
John Reckc477e712011-08-17 11:27:15 -0700186 if (mNeedsSharedSync) {
187 syncSharedSettings();
188 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800189
John Reck35e9dd62011-04-25 09:01:54 -0700190 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800191 syncStaticSettings(settings);
192 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700193 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800194 }
195 }
196
John Reckd1d87312012-03-08 13:25:00 -0800197 public void stopManagingSettings(WebSettings settings) {
198 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
199 while (iter.hasNext()) {
200 WeakReference<WebSettings> ref = iter.next();
201 if (ref.get() == settings) {
202 iter.remove();
203 return;
204 }
205 }
206 }
207
John Reckcadae722011-07-25 11:36:17 -0700208 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700209
210 @Override
211 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700212 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
213 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700214 // the cost of one cached page is ~3M (measured using nytimes.com). For
215 // low end devices, we only cache one page. For high end devices, we try
216 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800217
218 // SWE_TODO : assume a high-memory device
219 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700220 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800221 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700222 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
223 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
224 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700225 // Workaround b/5254577
226 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700227 if (Build.VERSION.CODENAME.equals("REL")) {
228 // This is a release build, always startup with debug disabled
229 setDebugEnabled(false);
230 }
231 if (mPrefs.contains(PREF_TEXT_SIZE)) {
232 /*
233 * Update from TextSize enum to zoom percent
234 * SMALLEST is 50%
235 * SMALLER is 75%
236 * NORMAL is 100%
237 * LARGER is 150%
238 * LARGEST is 200%
239 */
240 switch (getTextSize()) {
241 case SMALLEST:
242 setTextZoom(50);
243 break;
244 case SMALLER:
245 setTextZoom(75);
246 break;
247 case LARGER:
248 setTextZoom(150);
249 break;
250 case LARGEST:
251 setTextZoom(200);
252 break;
253 }
254 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
255 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100256
qqzhou8c5b0a32013-07-22 15:31:03 +0800257 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700258 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800259
kaiyizbf086ea2013-08-02 11:03:58 +0800260 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800261 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800262 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700263
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700264 if (!mPrefs.contains(PREF_EDGE_SWIPE)) {
265 mPrefs.edit().putString(PREF_EDGE_SWIPE,
266 mContext.getResources().getString(
267 R.string.value_unknown_edge_swipe)).apply();
268 }
269
Ben Murdochaaa1f372011-07-25 15:40:58 +0100270 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
271 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
272 BrowserProvider.getClientId(mContext.getContentResolver()));
273 }
274
Ben Murdochaaa1f372011-07-25 15:40:58 +0100275 synchronized (BrowserSettings.class) {
276 sInitialized = true;
277 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700278 }
279 }
280 };
281
Ben Murdochaaa1f372011-07-25 15:40:58 +0100282 private static void requireInitialization() {
283 synchronized (BrowserSettings.class) {
284 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700285 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100286 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700287 } catch (InterruptedException e) {
288 }
289 }
290 }
291 }
292
The Android Open Source Project0c908882009-03-03 19:32:16 -0800293 /**
John Reck35e9dd62011-04-25 09:01:54 -0700294 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800295 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800296 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700297 settings.setGeolocationEnabled(enableGeolocation());
298 settings.setJavaScriptEnabled(enableJavascript());
299 settings.setLightTouchEnabled(enableLightTouch());
300 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700301 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700302 settings.setMinimumFontSize(getMinimumFontSize());
303 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700304 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700305 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100306 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700307 settings.setLoadsImagesAutomatically(loadImages());
308 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
309 settings.setSavePassword(rememberPasswords());
310 settings.setSaveFormData(saveFormdata());
311 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700312 settings.setDoNotTrack(doNotTrack());
Yida Wang078425c2015-06-02 14:14:06 -0400313 settings.setNightModeEnabled(isNightModeEnabled());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700314 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700315
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800316 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800317 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
318 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
319 settingsClassic.setForceUserScalable(forceEnableUserScalable());
320 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
321 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800322
John Reckea17e782011-10-27 17:15:59 -0700323 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800324 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700325 useInverted ? "true" : "false");
326 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800327 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700328 Float.toString(getInvertedContrast()));
329 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700330
John Reckea17e782011-10-27 17:15:59 -0700331 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800332 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700333 enableCpuUploadPath() ? "true" : "false");
334 }
Victoria Lease96497832012-03-23 14:19:56 -0700335
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800336 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000337 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800338
Tarun Nainani8eb00912014-07-17 12:28:32 -0700339
John Reck35e9dd62011-04-25 09:01:54 -0700340 /**
341 * Syncs all the settings that have no UI
342 * These cannot change, so we only need to set them once per WebSettings
343 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800344 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700345 settings.setDefaultFontSize(16);
346 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000347
John Reck35e9dd62011-04-25 09:01:54 -0700348 // WebView inside Browser doesn't want initial focus to be set.
349 settings.setNeedInitialFocus(false);
350 // Browser supports multiple windows
351 settings.setSupportMultipleWindows(true);
352 // enable smooth transition for better performance during panning or
353 // zooming
354 settings.setEnableSmoothTransition(true);
355 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700356 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700357
358 // HTML5 API flags
359 settings.setAppCacheEnabled(true);
360 settings.setDatabaseEnabled(true);
361 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700362
363 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700364 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700365 settings.setAppCachePath(getAppCachePath());
366 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
367 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700368 // origin policy for file access
369 settings.setAllowUniversalAccessFromFileURLs(false);
370 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700371 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800372
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800373 //if (!(settings instanceof WebSettingsClassic)) return;
374 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800375
376 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
377 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
378 // WebView should be preserving the memory as much as possible.
379 // However, apps like browser wish to turn on the performance mode which
380 // would require more memory.
381 // TODO: We need to dynamically allocate/deallocate temporary memory for
382 // apps which are trying to use minimal memory. Currently, double
383 // buffering is always turned on, which is unnecessary.
384 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
385 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800386 */
John Reck35e9dd62011-04-25 09:01:54 -0700387 }
388
389 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700390 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700391 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800392
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() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700396 if (!mEngineInitialized) {
397 mSyncManagedSettings = true;
398 return;
399 }
400 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700401 syncSharedSettings();
402 synchronized (mManagedSettings) {
403 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
404 while (iter.hasNext()) {
405 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800406 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700407 if (settings == null) {
408 iter.remove();
409 continue;
410 }
411 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000412 }
John Reck35e9dd62011-04-25 09:01:54 -0700413 }
414 }
Ben Murdochef671652010-11-25 17:17:58 +0000415
John Reck35e9dd62011-04-25 09:01:54 -0700416 @Override
417 public void onSharedPreferenceChanged(
418 SharedPreferences sharedPreferences, String key) {
419 syncManagedSettings();
420 if (PREF_SEARCH_ENGINE.equals(key)) {
421 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700422 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200423 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700424 mController.getUi().setFullscreen(useFullscreen());
425 }
Victoria Lease96497832012-03-23 14:19:56 -0700426 } else if (PREF_LINK_PREFETCH.equals(key)) {
427 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700428 }
John Reck35e9dd62011-04-25 09:01:54 -0700429 }
430
John Reck961d35d2011-06-23 09:45:54 -0700431 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100432 requireInitialization();
433 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700434 }
435
436 public LayoutAlgorithm getLayoutAlgorithm() {
437 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
438 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700439 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700440 }
441 if (isDebugEnabled()) {
442 if (isSmallScreen()) {
443 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000444 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700445 if (isNormalLayout()) {
446 layoutAlgorithm = LayoutAlgorithm.NORMAL;
447 } else {
448 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
449 }
Ben Murdochef671652010-11-25 17:17:58 +0000450 }
John Reck35e9dd62011-04-25 09:01:54 -0700451 }
452 return layoutAlgorithm;
453 }
Ben Murdochef671652010-11-25 17:17:58 +0000454
John Reck35e9dd62011-04-25 09:01:54 -0700455 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700456 requireInitialization();
457 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 }
459
John Reck35e9dd62011-04-25 09:01:54 -0700460 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700461 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700462 return mWebStorageSizeManager;
463 }
464
John Reck35e9dd62011-04-25 09:01:54 -0700465 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700466 if (mAppCachePath == null) {
467 mAppCachePath = mContext.getDir("appcache", 0).getPath();
468 }
469 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700470 }
471
472 private void updateSearchEngine(boolean force) {
473 String searchEngineName = getSearchEngineName();
474 if (force || mSearchEngine == null ||
475 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700476 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000477 }
478 }
479
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100480 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700481 if (mSearchEngine == null) {
482 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100483 }
John Reck35e9dd62011-04-25 09:01:54 -0700484 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100485 }
486
John Reck35e9dd62011-04-25 09:01:54 -0700487 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700488 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700489 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100490 }
491
John Reck35e9dd62011-04-25 09:01:54 -0700492 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700493 Editor edit = mPrefs.edit();
494 edit.putBoolean(PREF_DEBUG_MENU, value);
495 if (!value) {
496 // Reset to "safe" value
497 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
498 }
499 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100500 }
501
John Reck35e9dd62011-04-25 09:01:54 -0700502 public void clearCache() {
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
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700531 public WebView getTopWebView(){
532 if (mController!= null)
533 return mController.getCurrentTopWebView();
534
535 return null;
536 }
537
John Reck35e9dd62011-04-25 09:01:54 -0700538 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700539 // Clear password store maintained by SWE engine
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) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700551 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700552 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700553
554 // Clear passwords in WebView database
555 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
556 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800557 }
558
John Reck35e9dd62011-04-25 09:01:54 -0700559 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100560 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100561 }
562
John Reck35e9dd62011-04-25 09:01:54 -0700563 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100564 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700565 if (GeolocationPermissions.isIncognitoCreated()) {
566 GeolocationPermissions.getIncognitoInstance().clearAll();
567 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100568 }
569
John Reck35e9dd62011-04-25 09:01:54 -0700570 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700571 mPrefs.edit()
572 .clear()
John Reckbd315192011-07-29 10:05:47 -0700573 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200574 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700575 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700576 }
577
Björn Isakssonc885a242012-06-05 17:19:04 +0200578 private void resetCachedValues() {
579 updateSearchEngine(false);
580 }
581
John Reck35e9dd62011-04-25 09:01:54 -0700582 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800583 // query the profile from components autofill database 524
584 if (mAutofillHandler.mAutoFillProfile == null &&
585 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
586 WebSettings settings = null;
587 // find a valid settings object
588 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
589 while (iter.hasNext()) {
590 WeakReference<WebSettings> ref = iter.next();
591 settings = (WebSettings)ref.get();
592 if (settings != null) {
593 break;
594 }
595 }
596 if (settings != null) {
597 AutoFillProfile profile =
598 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
599 mAutofillHandler.setAutoFillProfile(profile);
600 }
601 }
John Reck35e9dd62011-04-25 09:01:54 -0700602 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800603 }
604
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800605 public String getAutoFillProfileId() {
606 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800607 }
608
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800609 public void updateAutoFillProfile(AutoFillProfile profile) {
610 syncAutoFillProfile(profile);
611 }
612
613 private void syncAutoFillProfile(AutoFillProfile profile) {
614 synchronized (mManagedSettings) {
615 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
616 while (iter.hasNext()) {
617 WeakReference<WebSettings> ref = iter.next();
618 WebSettings settings = (WebSettings)ref.get();
619 if (settings == null) {
620 iter.remove();
621 continue;
622 }
623 // update the profile only once.
624 settings.setAutoFillProfile(profile);
625 // Now we should have the guid
626 mAutofillHandler.setAutoFillProfile(profile);
627 break;
628 }
629 }
630 }
John Reck35e9dd62011-04-25 09:01:54 -0700631 public void toggleDebugSettings() {
632 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800633 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100634
John Reckb8b2af82011-05-20 15:58:33 -0700635 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800636 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700637 }
638
639 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700640 if (view == null) {
641 return;
642 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800643 if (hasDesktopUseragent(view))
644 view.setUseDesktopUserAgent(false, true);
645 else
646 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700647 }
648
John Reck7dc444b2011-06-16 17:44:29 -0700649 public static int getAdjustedMinimumFontSize(int rawValue) {
650 rawValue++; // Preference starts at 0, min font at 1
651 if (rawValue > 1) {
652 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
653 }
654 return rawValue;
655 }
656
John Reck5ba3c762011-09-14 15:00:15 -0700657 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700658 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700659 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700660 }
661
662 static int getRawTextZoom(int percent) {
663 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
664 }
665
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700666 public int getAdjustedDoubleTapZoom(int rawValue) {
667 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
668 return (int) ((rawValue + 100) * mFontSizeMult);
669 }
670
671 static int getRawDoubleTapZoom(int percent) {
672 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
673 }
674
John Reckcadae722011-07-25 11:36:17 -0700675 public SharedPreferences getPreferences() {
676 return mPrefs;
677 }
678
Victoria Lease96497832012-03-23 14:19:56 -0700679 // update connectivity-dependent options
680 public void updateConnectionType() {
681 ConnectivityManager cm = (ConnectivityManager)
682 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
683 String linkPrefetchPreference = getLinkPrefetchEnabled();
684 boolean linkPrefetchAllowed = linkPrefetchPreference.
685 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
686 NetworkInfo ni = cm.getActiveNetworkInfo();
687 if (ni != null) {
688 switch (ni.getType()) {
689 case ConnectivityManager.TYPE_WIFI:
690 case ConnectivityManager.TYPE_ETHERNET:
691 case ConnectivityManager.TYPE_BLUETOOTH:
692 linkPrefetchAllowed |= linkPrefetchPreference.
693 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
694 break;
695 case ConnectivityManager.TYPE_MOBILE:
696 case ConnectivityManager.TYPE_MOBILE_DUN:
697 case ConnectivityManager.TYPE_MOBILE_MMS:
698 case ConnectivityManager.TYPE_MOBILE_SUPL:
699 case ConnectivityManager.TYPE_WIMAX:
700 default:
701 break;
702 }
703 }
704 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
705 mLinkPrefetchAllowed = linkPrefetchAllowed;
706 syncManagedSettings();
707 }
708 }
709
luxiaol62677b02013-07-22 07:54:49 +0800710 public String getDownloadPath() {
711 return mPrefs.getString(PREF_DOWNLOAD_PATH,
712 DownloadHandler.getDefaultDownloadPath(mContext));
713 }
John Reck35e9dd62011-04-25 09:01:54 -0700714 // -----------------------------
715 // getter/setters for accessibility_preferences.xml
716 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100717
John Reck7dc444b2011-06-16 17:44:29 -0700718 @Deprecated
719 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700720 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
721 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100722 }
723
John Reck35e9dd62011-04-25 09:01:54 -0700724 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700725 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700726 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100727 }
728
John Reck92f25f82011-04-26 16:57:10 -0700729 public boolean forceEnableUserScalable() {
730 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
731 }
732
John Reck7dc444b2011-06-16 17:44:29 -0700733 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700734 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700735 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
736 return getAdjustedTextZoom(textZoom);
737 }
738
739 public void setTextZoom(int percent) {
740 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
741 }
742
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700743 public int getDoubleTapZoom() {
744 requireInitialization();
745 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
746 return getAdjustedDoubleTapZoom(doubleTapZoom);
747 }
748
749 public void setDoubleTapZoom(int percent) {
750 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
751 }
752
John Reck35e9dd62011-04-25 09:01:54 -0700753 // -----------------------------
754 // getter/setters for advanced_preferences.xml
755 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100756
John Reck35e9dd62011-04-25 09:01:54 -0700757 public String getSearchEngineName() {
Panos Thomas64c77e02014-12-17 22:15:23 -0800758 // The following is a NOP if the SEARCH_ENGINE restriction has already been created. Otherwise,
759 // it creates the restriction and if enabled it sets the <default_search_engine_value>.
760 SearchEngineRestriction.getInstance();
761
luxiaol221b3932013-07-19 15:27:57 +0800762 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
763 if (defaultSearchEngineValue == null) {
764 defaultSearchEngineValue = SearchEngine.GOOGLE;
765 }
766 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100767 }
John Reck63bb6872010-12-01 19:29:32 -0800768
Michael Kolb8d772b02012-01-19 13:56:00 -0800769 public boolean allowAppTabs() {
770 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
771 }
772
John Reck35e9dd62011-04-25 09:01:54 -0700773 public boolean openInBackground() {
774 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800775 }
John Reck35e9dd62011-04-25 09:01:54 -0700776
777 public boolean enableJavascript() {
778 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
779 }
780
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800781 public boolean enableMemoryMonitor() {
782 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
783 }
784
Tarun Nainani8eb00912014-07-17 12:28:32 -0700785
John Reck35e9dd62011-04-25 09:01:54 -0700786 public boolean loadPageInOverviewMode() {
787 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
788 }
789
790 public boolean autofitPages() {
791 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
792 }
793
794 public boolean blockPopupWindows() {
Pankaj Garg32e1b942015-06-03 18:13:24 -0700795 return !mPrefs.getBoolean(PREF_POPUP_WINDOWS, false);
John Reck35e9dd62011-04-25 09:01:54 -0700796 }
797
798 public boolean loadImages() {
799 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
800 }
801
802 public String getDefaultTextEncoding() {
Tarun Nainani88381422015-04-02 19:47:21 -0700803 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
John Reck35e9dd62011-04-25 09:01:54 -0700804 }
805
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700806 public String getEdgeSwipeAction() {
807 return mPrefs.getString(PREF_EDGE_SWIPE,
808 mContext.getResources().getString(R.string.value_unknown_edge_swipe));
809 }
810
811 public void setEdgeSwipeTemporal() {
812 mPrefs.edit().putString(PREF_EDGE_SWIPE,
813 mContext.getResources().getString(R.string.value_temporal_edge_swipe)).apply();
814 }
815
816 public void setEdgeSwipeSpatial() {
817 mPrefs.edit().putString(PREF_EDGE_SWIPE,
818 mContext.getResources().getString(R.string.value_spatial_edge_swipe)).apply();
819 }
820
821 public void setEdgeSwipeDisabled() {
822 mPrefs.edit().putString(PREF_EDGE_SWIPE,
823 mContext.getResources().getString(R.string.value_disable_edge_swipe)).apply();
824 }
825
John Reck35e9dd62011-04-25 09:01:54 -0700826 // -----------------------------
827 // getter/setters for general_preferences.xml
828 // -----------------------------
829
830 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700831 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
832 }
833
834 public void setHomePage(String value) {
835 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
836 }
837
838 public boolean isAutofillEnabled() {
839 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
840 }
841
842 public void setAutofillEnabled(boolean value) {
843 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
844 }
845
Site Maoabb7bd32015-03-20 15:34:02 -0700846 public boolean isPowerSaveModeEnabled() {
847 return mPrefs.getBoolean(PREF_POWERSAVE_ENABLED, false);
848 }
849
850 public void setPowerSaveModeEnabled(boolean value) {
851 mPrefs.edit().putBoolean(PREF_POWERSAVE_ENABLED, value).apply();
852 }
853
Yida Wang078425c2015-06-02 14:14:06 -0400854 public boolean isNightModeEnabled() {
855 return mPrefs.getBoolean(PREF_NIGHTMODE_ENABLED, false);
856 }
857
858 public void setNightModeEnabled(boolean value) {
859 mPrefs.edit().putBoolean(PREF_NIGHTMODE_ENABLED, value).apply();
860 }
861
John Reck35e9dd62011-04-25 09:01:54 -0700862 // -----------------------------
863 // getter/setters for debug_preferences.xml
864 // -----------------------------
865
866 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700867 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700868 return true;
869 }
870 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
871 }
872
Derek Sollenberger31adf672011-07-08 11:31:30 -0400873 public boolean isSkiaHardwareAccelerated() {
874 if (!isDebugEnabled()) {
875 return false;
876 }
877 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
878 }
879
John Reck35e9dd62011-04-25 09:01:54 -0700880 // -----------------------------
881 // getter/setters for hidden_debug_preferences.xml
882 // -----------------------------
883
884 public boolean enableVisualIndicator() {
885 if (!isDebugEnabled()) {
886 return false;
887 }
888 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
889 }
890
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700891 public boolean enableCpuUploadPath() {
892 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700893 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700894 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700895 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700896 }
897
John Reck35e9dd62011-04-25 09:01:54 -0700898 public boolean isSmallScreen() {
899 if (!isDebugEnabled()) {
900 return false;
901 }
902 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
903 }
904
905 public boolean isWideViewport() {
906 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800907 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700908 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800909 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700910 }
911
912 public boolean isNormalLayout() {
913 if (!isDebugEnabled()) {
914 return false;
915 }
916 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
917 }
918
919 public boolean isTracing() {
920 if (!isDebugEnabled()) {
921 return false;
922 }
923 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
924 }
925
926 public boolean enableLightTouch() {
927 if (!isDebugEnabled()) {
928 return false;
929 }
930 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
931 }
932
933 public boolean enableNavDump() {
934 if (!isDebugEnabled()) {
935 return false;
936 }
937 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
938 }
939
940 public String getJsEngineFlags() {
941 if (!isDebugEnabled()) {
942 return "";
943 }
944 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
945 }
946
947 // -----------------------------
948 // getter/setters for lab_preferences.xml
949 // -----------------------------
950
John Reck35e9dd62011-04-25 09:01:54 -0700951 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700952 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700953 }
954
Michael Kolbc38c6042011-04-27 10:46:06 -0700955 public boolean useFullscreen() {
956 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
957 }
958
John Reck2fd9d0e2011-07-15 11:13:48 -0700959 public boolean useInvertedRendering() {
960 return mPrefs.getBoolean(PREF_INVERTED, false);
961 }
962
Nicolas Roard5d513102011-08-03 15:35:34 -0700963 public float getInvertedContrast() {
964 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
965 }
966
John Reck35e9dd62011-04-25 09:01:54 -0700967 // -----------------------------
968 // getter/setters for privacy_security_preferences.xml
969 // -----------------------------
970
971 public boolean showSecurityWarnings() {
972 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
973 }
974
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700975 public boolean doNotTrack() {
Dave Tharpb487d5d2015-05-15 15:54:08 -0700976 boolean dntVal;
977 if (DoNotTrackRestriction.getInstance().isEnabled()) {
978 dntVal = DoNotTrackRestriction.getInstance().getValue();
979 }
980 else {
981 dntVal = mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
982 }
983 return dntVal;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700984 }
985
John Reck35e9dd62011-04-25 09:01:54 -0700986 public boolean acceptCookies() {
Pankaj Garg32e1b942015-06-03 18:13:24 -0700987 return PermissionsServiceFactory.getDefaultPermissions(
988 PermissionsServiceFactory.PermissionType.COOKIE);
John Reck35e9dd62011-04-25 09:01:54 -0700989 }
990
991 public boolean saveFormdata() {
992 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
993 }
994
995 public boolean enableGeolocation() {
996 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
997 }
998
999 public boolean rememberPasswords() {
1000 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
1001 }
1002
Michael Kolb14612442011-06-24 13:06:29 -07001003 // -----------------------------
1004 // getter/setters for bandwidth_preferences.xml
1005 // -----------------------------
1006
Mathew Inwood467813f2011-09-02 15:43:17 +01001007 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
1008 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -07001009 }
Mathew Inwood467813f2011-09-02 15:43:17 +01001010
1011 public static String getPreloadAlwaysPreferenceString(Context context) {
1012 return context.getResources().getString(R.string.pref_data_preload_value_always);
1013 }
1014
Mathew Inwood825fba72011-10-04 14:52:52 +01001015 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
1016 "browser_default_preload_setting";
1017
1018 public String getDefaultPreloadSetting() {
1019 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1020 DEAULT_PRELOAD_SECURE_SETTING_KEY);
1021 if (preload == null) {
1022 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
1023 }
1024 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +01001025 }
1026
1027 public String getPreloadEnabled() {
1028 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
1029 }
1030
Victoria Lease96497832012-03-23 14:19:56 -07001031 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
1032 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
1033 }
1034
1035 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
1036 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
1037 }
1038
1039 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
1040 "browser_default_link_prefetch_setting";
1041
1042 public String getDefaultLinkPrefetchSetting() {
1043 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1044 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
1045 if (preload == null) {
1046 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
1047 }
1048 return preload;
1049 }
1050
1051 public String getLinkPrefetchEnabled() {
1052 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
1053 }
1054
George Mount3636d0a2011-11-21 09:08:21 -08001055 // -----------------------------
1056 // getter/setters for browser recovery
1057 // -----------------------------
1058 /**
1059 * The last time browser was started.
1060 * @return The last browser start time as System.currentTimeMillis. This
1061 * can be 0 if this is the first time or the last tab was closed.
1062 */
1063 public long getLastRecovered() {
1064 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1065 }
1066
1067 /**
1068 * Sets the last browser start time.
1069 * @param time The last time as System.currentTimeMillis that the browser
1070 * was started. This should be set to 0 if the last tab is closed.
1071 */
1072 public void setLastRecovered(long time) {
1073 mPrefs.edit()
1074 .putLong(KEY_LAST_RECOVERED, time)
1075 .apply();
1076 }
1077
1078 /**
1079 * Used to determine whether or not the previous browser run crashed. Once
1080 * the previous state has been determined, the value will be set to false
1081 * until a pause is received.
1082 * @return true if the last browser run was paused or false if it crashed.
1083 */
1084 public boolean wasLastRunPaused() {
1085 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1086 }
1087
1088 /**
1089 * Sets whether or not the last run was a pause or crash.
1090 * @param isPaused Set to true When a pause is received or false after
1091 * resuming.
1092 */
1093 public void setLastRunPaused(boolean isPaused) {
1094 mPrefs.edit()
1095 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1096 .apply();
1097 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001098}