blob: 753b1c8534c43e2f9bf6788d2fe761137c26dbd5 [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 Tharp4a2c8942015-07-10 14:10:51 -070034import com.android.browser.mdm.AutoFillRestriction;
35import com.android.browser.mdm.DevToolsRestriction;
Dave Tharpb487d5d2015-05-15 15:54:08 -070036import com.android.browser.mdm.DoNotTrackRestriction;
Dave Tharp4a2c8942015-07-10 14:10:51 -070037import com.android.browser.mdm.EditBookmarksRestriction;
38import com.android.browser.mdm.IncognitoRestriction;
39import com.android.browser.mdm.ManagedBookmarksRestriction;
Panos Thomasa9ff2c72014-12-17 22:15:23 -080040import com.android.browser.mdm.ProxyRestriction;
Panos Thomas64c77e02014-12-17 22:15:23 -080041import com.android.browser.mdm.SearchEngineRestriction;
Dave Tharp4a2c8942015-07-10 14:10:51 -070042import com.android.browser.mdm.ThirdPartyCookiesRestriction;
43import com.android.browser.mdm.URLFilterRestriction;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070044import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070045import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070046import com.android.browser.search.SearchEngine;
47import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070048
John Reck35e9dd62011-04-25 09:01:54 -070049import java.lang.ref.WeakReference;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -070050import java.util.ArrayList;
John Reck35e9dd62011-04-25 09:01:54 -070051import java.util.Iterator;
52import java.util.LinkedList;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -070053import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -080054
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080055import org.codeaurora.swe.AutoFillProfile;
56import org.codeaurora.swe.CookieManager;
57import org.codeaurora.swe.GeolocationPermissions;
Pankaj Garg32e1b942015-06-03 18:13:24 -070058import org.codeaurora.swe.PermissionsServiceFactory;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070059import org.codeaurora.swe.WebRefiner;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080060import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import org.codeaurora.swe.WebSettings.TextSize;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080062import org.codeaurora.swe.WebSettings;
63import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070064import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080065
John Reck35e9dd62011-04-25 09:01:54 -070066/**
67 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080068 */
John Reck35e9dd62011-04-25 09:01:54 -070069public class BrowserSettings implements OnSharedPreferenceChangeListener,
70 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010071
qqzhoue6ff8b42013-07-23 17:28:48 +080072 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070073 // The minimum min font size
74 // Aka, the lower bounds for the min font size range
75 // which is 1:5..24
76 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070077 // The initial value in the text zoom range
78 // This is what represents 100% in the SeekBarPreference range
79 private static final int TEXT_ZOOM_START_VAL = 10;
80 // The size of a single step in the text zoom range, in percent
81 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070082 // The initial value in the double tap zoom range
83 // This is what represents 100% in the SeekBarPreference range
84 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
85 // The size of a single step in the double tap zoom range, in percent
86 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070087
John Reck35e9dd62011-04-25 09:01:54 -070088 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070089
John Reck35e9dd62011-04-25 09:01:54 -070090 private Context mContext;
91 private SharedPreferences mPrefs;
92 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070093 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070094 private WebStorageSizeManager mWebStorageSizeManager;
95 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010096 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070097 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070098 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070099
Victoria Lease96497832012-03-23 14:19:56 -0700100 // Current state of network-dependent settings
101 private boolean mLinkPrefetchAllowed = true;
102
John Reck78a6a1d2011-07-21 13:54:03 -0700103 // Cached values
104 private int mPageCacheCapacity = 1;
105 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800106
John Reck35e9dd62011-04-25 09:01:54 -0700107 // Cached settings
108 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800109
Ben Murdochaaa1f372011-07-25 15:40:58 +0100110 private static String sFactoryResetUrl;
111
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700112 private boolean mEngineInitialized = false;
113 private boolean mSyncManagedSettings = false;
114
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700115 public static synchronized void initialize(final Context context) {
116 if (sInstance == null)
117 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700118 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800119
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700120 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700121 return sInstance;
122 }
Ben Murdochef671652010-11-25 17:17:58 +0000123
John Reck35e9dd62011-04-25 09:01:54 -0700124 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100125 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700126 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700127 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700128 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700129 }
130
131 public void setController(Controller controller) {
132 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700133 mNeedsSharedSync = true;
134 }
135
136 public void onEngineInitializationComplete() {
137 mEngineInitialized = true;
Axesh R. Ajmerab7b86b92015-06-25 20:25:24 -0700138
139 // Intialize Web Refiner only once
140 final WebRefiner refiner = WebRefiner.getInstance();
141 if (refiner != null) {
142 refiner.setRulesEnabled(WebRefiner.CATEGORY_ALL,
143 PermissionsServiceFactory.getDefaultPermissions(
144 PermissionsServiceFactory.PermissionType.WEBREFINER));
145
146 PermissionsServiceFactory.getPermissionsService(
147 new ValueCallback<PermissionsServiceFactory.PermissionsService>() {
148 @Override
149 public void onReceiveValue(
150 PermissionsServiceFactory.PermissionsService value) {
151 Set<String> origins = value.getOrigins();
152 ArrayList<String> allowList = new ArrayList<>();
153 ArrayList<String> blockList = new ArrayList<>();
154 for (String origin : origins) {
155 PermissionsServiceFactory.PermissionsService.OriginInfo
156 info = value.getOriginInfo(origin);
157 int perm = info.getPermission(
158 PermissionsServiceFactory.PermissionType.WEBREFINER);
159 if (perm == PermissionsServiceFactory.Permission.ALLOW) {
160 allowList.add(origin);
161 } else if (perm == PermissionsServiceFactory.Permission.BLOCK) {
162 blockList.add(origin);
163 }
164 }
165 if (!allowList.isEmpty()) {
166 refiner.enableRulesForDomains(WebRefiner.CATEGORY_ALL,
167 allowList.toArray(new String[allowList.size()]));
168 }
169
170 if (!blockList.isEmpty()) {
171 refiner.disableRulesForDomains(WebRefiner.CATEGORY_ALL,
172 blockList.toArray(new String[blockList.size()]));
173 }
174 }
175 }
176 );
177 }
178
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700179 mAutofillHandler = new AutofillHandler(mContext);
180 if (mSyncManagedSettings) {
181 syncManagedSettings();
182 }
183 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700184 syncSharedSettings();
185 }
Dave Tharp4a2c8942015-07-10 14:10:51 -0700186
187 // Instantiate all MDM Restriction Singletons.
188 AutoFillRestriction.getInstance();
189 DevToolsRestriction.getInstance();
190 DoNotTrackRestriction.getInstance();
191 EditBookmarksRestriction.getInstance();
192 IncognitoRestriction.getInstance();
193 ManagedBookmarksRestriction.getInstance();
Panos Thomasa9ff2c72014-12-17 22:15:23 -0800194 ProxyRestriction.getInstance();
Dave Tharp4a2c8942015-07-10 14:10:51 -0700195 SearchEngineRestriction.getInstance();
196 ThirdPartyCookiesRestriction.getInstance();
197 URLFilterRestriction.getInstance();
Ben Murdochef671652010-11-25 17:17:58 +0000198 }
199
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800200 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800201
John Reckc477e712011-08-17 11:27:15 -0700202 if (mNeedsSharedSync) {
203 syncSharedSettings();
204 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800205
John Reck35e9dd62011-04-25 09:01:54 -0700206 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800207 syncStaticSettings(settings);
208 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700209 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800210 }
211 }
212
John Reckd1d87312012-03-08 13:25:00 -0800213 public void stopManagingSettings(WebSettings settings) {
214 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
215 while (iter.hasNext()) {
216 WeakReference<WebSettings> ref = iter.next();
217 if (ref.get() == settings) {
218 iter.remove();
219 return;
220 }
221 }
222 }
223
John Reckcadae722011-07-25 11:36:17 -0700224 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700225
226 @Override
227 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700228 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
229 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700230 // the cost of one cached page is ~3M (measured using nytimes.com). For
231 // low end devices, we only cache one page. For high end devices, we try
232 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800233
234 // SWE_TODO : assume a high-memory device
235 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700236 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800237 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700238 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
239 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
240 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700241 // Workaround b/5254577
242 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700243 if (Build.VERSION.CODENAME.equals("REL")) {
244 // This is a release build, always startup with debug disabled
245 setDebugEnabled(false);
246 }
247 if (mPrefs.contains(PREF_TEXT_SIZE)) {
248 /*
249 * Update from TextSize enum to zoom percent
250 * SMALLEST is 50%
251 * SMALLER is 75%
252 * NORMAL is 100%
253 * LARGER is 150%
254 * LARGEST is 200%
255 */
256 switch (getTextSize()) {
257 case SMALLEST:
258 setTextZoom(50);
259 break;
260 case SMALLER:
261 setTextZoom(75);
262 break;
263 case LARGER:
264 setTextZoom(150);
265 break;
266 case LARGEST:
267 setTextZoom(200);
268 break;
269 }
270 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
271 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100272
qqzhou8c5b0a32013-07-22 15:31:03 +0800273 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700274 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800275
kaiyizbf086ea2013-08-02 11:03:58 +0800276 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800277 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800278 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700279
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700280 if (!mPrefs.contains(PREF_EDGE_SWIPE)) {
281 mPrefs.edit().putString(PREF_EDGE_SWIPE,
282 mContext.getResources().getString(
283 R.string.value_unknown_edge_swipe)).apply();
284 }
285
Ben Murdochaaa1f372011-07-25 15:40:58 +0100286 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
287 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
288 BrowserProvider.getClientId(mContext.getContentResolver()));
289 }
290
Ben Murdochaaa1f372011-07-25 15:40:58 +0100291 synchronized (BrowserSettings.class) {
292 sInitialized = true;
293 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700294 }
295 }
296 };
297
Ben Murdochaaa1f372011-07-25 15:40:58 +0100298 private static void requireInitialization() {
299 synchronized (BrowserSettings.class) {
300 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700301 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100302 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700303 } catch (InterruptedException e) {
304 }
305 }
306 }
307 }
308
The Android Open Source Project0c908882009-03-03 19:32:16 -0800309 /**
John Reck35e9dd62011-04-25 09:01:54 -0700310 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800311 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800312 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700313 settings.setGeolocationEnabled(enableGeolocation());
314 settings.setJavaScriptEnabled(enableJavascript());
315 settings.setLightTouchEnabled(enableLightTouch());
316 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700317 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700318 settings.setMinimumFontSize(getMinimumFontSize());
319 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700320 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700321 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100322 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700323 settings.setLoadsImagesAutomatically(loadImages());
324 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
325 settings.setSavePassword(rememberPasswords());
326 settings.setSaveFormData(saveFormdata());
327 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700328 settings.setDoNotTrack(doNotTrack());
Yida Wang078425c2015-06-02 14:14:06 -0400329 settings.setNightModeEnabled(isNightModeEnabled());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700330 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700331
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800332 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800333 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
334 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
335 settingsClassic.setForceUserScalable(forceEnableUserScalable());
336 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
337 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800338
John Reckea17e782011-10-27 17:15:59 -0700339 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800340 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700341 useInverted ? "true" : "false");
342 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800343 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700344 Float.toString(getInvertedContrast()));
345 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700346
John Reckea17e782011-10-27 17:15:59 -0700347 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800348 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700349 enableCpuUploadPath() ? "true" : "false");
350 }
Victoria Lease96497832012-03-23 14:19:56 -0700351
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800352 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000353 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800354
Tarun Nainani8eb00912014-07-17 12:28:32 -0700355
John Reck35e9dd62011-04-25 09:01:54 -0700356 /**
357 * Syncs all the settings that have no UI
358 * These cannot change, so we only need to set them once per WebSettings
359 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800360 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700361 settings.setDefaultFontSize(16);
362 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000363
John Reck35e9dd62011-04-25 09:01:54 -0700364 // WebView inside Browser doesn't want initial focus to be set.
365 settings.setNeedInitialFocus(false);
366 // Browser supports multiple windows
367 settings.setSupportMultipleWindows(true);
368 // enable smooth transition for better performance during panning or
369 // zooming
370 settings.setEnableSmoothTransition(true);
371 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700372 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700373
374 // HTML5 API flags
375 settings.setAppCacheEnabled(true);
376 settings.setDatabaseEnabled(true);
377 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700378
379 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700380 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700381 settings.setAppCachePath(getAppCachePath());
382 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
383 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700384 // origin policy for file access
385 settings.setAllowUniversalAccessFromFileURLs(false);
386 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700387 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800388
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800389 //if (!(settings instanceof WebSettingsClassic)) return;
390 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800391
392 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
393 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
394 // WebView should be preserving the memory as much as possible.
395 // However, apps like browser wish to turn on the performance mode which
396 // would require more memory.
397 // TODO: We need to dynamically allocate/deallocate temporary memory for
398 // apps which are trying to use minimal memory. Currently, double
399 // buffering is always turned on, which is unnecessary.
400 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
401 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800402 */
John Reck35e9dd62011-04-25 09:01:54 -0700403 }
404
405 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700406 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700407 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800408
John Reck35e9dd62011-04-25 09:01:54 -0700409 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700410
John Reck35e9dd62011-04-25 09:01:54 -0700411 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700412 if (!mEngineInitialized) {
413 mSyncManagedSettings = true;
414 return;
415 }
416 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700417 syncSharedSettings();
418 synchronized (mManagedSettings) {
419 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
420 while (iter.hasNext()) {
421 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800422 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700423 if (settings == null) {
424 iter.remove();
425 continue;
426 }
427 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000428 }
John Reck35e9dd62011-04-25 09:01:54 -0700429 }
430 }
Ben Murdochef671652010-11-25 17:17:58 +0000431
John Reck35e9dd62011-04-25 09:01:54 -0700432 @Override
433 public void onSharedPreferenceChanged(
434 SharedPreferences sharedPreferences, String key) {
435 syncManagedSettings();
436 if (PREF_SEARCH_ENGINE.equals(key)) {
437 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700438 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200439 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700440 mController.getUi().setFullscreen(useFullscreen());
441 }
Victoria Lease96497832012-03-23 14:19:56 -0700442 } else if (PREF_LINK_PREFETCH.equals(key)) {
443 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700444 }
John Reck35e9dd62011-04-25 09:01:54 -0700445 }
446
John Reck961d35d2011-06-23 09:45:54 -0700447 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100448 requireInitialization();
449 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700450 }
451
452 public LayoutAlgorithm getLayoutAlgorithm() {
453 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
454 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700455 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700456 }
457 if (isDebugEnabled()) {
458 if (isSmallScreen()) {
459 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000460 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700461 if (isNormalLayout()) {
462 layoutAlgorithm = LayoutAlgorithm.NORMAL;
463 } else {
464 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
465 }
Ben Murdochef671652010-11-25 17:17:58 +0000466 }
John Reck35e9dd62011-04-25 09:01:54 -0700467 }
468 return layoutAlgorithm;
469 }
Ben Murdochef671652010-11-25 17:17:58 +0000470
John Reck35e9dd62011-04-25 09:01:54 -0700471 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700472 requireInitialization();
473 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800474 }
475
John Reck35e9dd62011-04-25 09:01:54 -0700476 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700477 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700478 return mWebStorageSizeManager;
479 }
480
John Reck35e9dd62011-04-25 09:01:54 -0700481 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700482 if (mAppCachePath == null) {
483 mAppCachePath = mContext.getDir("appcache", 0).getPath();
484 }
485 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700486 }
487
488 private void updateSearchEngine(boolean force) {
489 String searchEngineName = getSearchEngineName();
490 if (force || mSearchEngine == null ||
491 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700492 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000493 }
494 }
495
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100496 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700497 if (mSearchEngine == null) {
498 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100499 }
John Reck35e9dd62011-04-25 09:01:54 -0700500 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100501 }
502
John Reck35e9dd62011-04-25 09:01:54 -0700503 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700504 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700505 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100506 }
507
John Reck35e9dd62011-04-25 09:01:54 -0700508 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700509 Editor edit = mPrefs.edit();
510 edit.putBoolean(PREF_DEBUG_MENU, value);
511 if (!value) {
512 // Reset to "safe" value
513 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
514 }
515 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100516 }
517
John Reck35e9dd62011-04-25 09:01:54 -0700518 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700519 if (mController != null) {
520 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800521 if (current != null) {
522 current.clearCache(true);
523 }
524 }
525 }
526
John Reck35e9dd62011-04-25 09:01:54 -0700527 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800528 CookieManager.getInstance().removeAllCookie();
529 }
530
John Reck35e9dd62011-04-25 09:01:54 -0700531 public void clearHistory() {
532 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800533 Browser.clearHistory(resolver);
534 Browser.clearSearches(resolver);
535 }
536
John Reck35e9dd62011-04-25 09:01:54 -0700537 public void clearFormData() {
538 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700539 if (mController!= null) {
540 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100541 if (currentTopView != null) {
542 currentTopView.clearFormData();
543 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800544 }
545 }
546
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700547 public WebView getTopWebView(){
548 if (mController!= null)
549 return mController.getCurrentTopWebView();
550
551 return null;
552 }
553
John Reck35e9dd62011-04-25 09:01:54 -0700554 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700555 // Clear password store maintained by SWE engine
556 WebSettings settings = null;
557 // find a valid settings object
558 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
559 while (iter.hasNext()) {
560 WeakReference<WebSettings> ref = iter.next();
561 settings = (WebSettings)ref.get();
562 if (settings != null) {
563 break;
564 }
565 }
566 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700567 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700568 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700569
570 // Clear passwords in WebView database
571 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
572 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800573 }
574
John Reck35e9dd62011-04-25 09:01:54 -0700575 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100576 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100577 }
578
John Reck35e9dd62011-04-25 09:01:54 -0700579 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100580 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700581 if (GeolocationPermissions.isIncognitoCreated()) {
582 GeolocationPermissions.getIncognitoInstance().clearAll();
583 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100584 }
585
John Reck35e9dd62011-04-25 09:01:54 -0700586 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700587 mPrefs.edit()
588 .clear()
John Reckbd315192011-07-29 10:05:47 -0700589 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200590 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700591 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700592 }
593
Björn Isakssonc885a242012-06-05 17:19:04 +0200594 private void resetCachedValues() {
595 updateSearchEngine(false);
596 }
597
John Reck35e9dd62011-04-25 09:01:54 -0700598 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800599 // query the profile from components autofill database 524
600 if (mAutofillHandler.mAutoFillProfile == null &&
601 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
602 WebSettings settings = null;
603 // find a valid settings object
604 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
605 while (iter.hasNext()) {
606 WeakReference<WebSettings> ref = iter.next();
607 settings = (WebSettings)ref.get();
608 if (settings != null) {
609 break;
610 }
611 }
612 if (settings != null) {
613 AutoFillProfile profile =
614 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
615 mAutofillHandler.setAutoFillProfile(profile);
616 }
617 }
John Reck35e9dd62011-04-25 09:01:54 -0700618 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800619 }
620
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800621 public String getAutoFillProfileId() {
622 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800623 }
624
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800625 public void updateAutoFillProfile(AutoFillProfile profile) {
626 syncAutoFillProfile(profile);
627 }
628
629 private void syncAutoFillProfile(AutoFillProfile profile) {
630 synchronized (mManagedSettings) {
631 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
632 while (iter.hasNext()) {
633 WeakReference<WebSettings> ref = iter.next();
634 WebSettings settings = (WebSettings)ref.get();
635 if (settings == null) {
636 iter.remove();
637 continue;
638 }
639 // update the profile only once.
640 settings.setAutoFillProfile(profile);
641 // Now we should have the guid
642 mAutofillHandler.setAutoFillProfile(profile);
643 break;
644 }
645 }
646 }
John Reck35e9dd62011-04-25 09:01:54 -0700647 public void toggleDebugSettings() {
648 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800649 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100650
John Reckb8b2af82011-05-20 15:58:33 -0700651 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800652 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700653 }
654
655 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700656 if (view == null) {
657 return;
658 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800659 if (hasDesktopUseragent(view))
660 view.setUseDesktopUserAgent(false, true);
661 else
662 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700663 }
664
John Reck7dc444b2011-06-16 17:44:29 -0700665 public static int getAdjustedMinimumFontSize(int rawValue) {
666 rawValue++; // Preference starts at 0, min font at 1
667 if (rawValue > 1) {
668 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
669 }
670 return rawValue;
671 }
672
John Reck5ba3c762011-09-14 15:00:15 -0700673 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700674 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700675 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700676 }
677
678 static int getRawTextZoom(int percent) {
679 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
680 }
681
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700682 public int getAdjustedDoubleTapZoom(int rawValue) {
683 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
684 return (int) ((rawValue + 100) * mFontSizeMult);
685 }
686
687 static int getRawDoubleTapZoom(int percent) {
688 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
689 }
690
John Reckcadae722011-07-25 11:36:17 -0700691 public SharedPreferences getPreferences() {
692 return mPrefs;
693 }
694
Victoria Lease96497832012-03-23 14:19:56 -0700695 // update connectivity-dependent options
696 public void updateConnectionType() {
697 ConnectivityManager cm = (ConnectivityManager)
698 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
699 String linkPrefetchPreference = getLinkPrefetchEnabled();
700 boolean linkPrefetchAllowed = linkPrefetchPreference.
701 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
702 NetworkInfo ni = cm.getActiveNetworkInfo();
703 if (ni != null) {
704 switch (ni.getType()) {
705 case ConnectivityManager.TYPE_WIFI:
706 case ConnectivityManager.TYPE_ETHERNET:
707 case ConnectivityManager.TYPE_BLUETOOTH:
708 linkPrefetchAllowed |= linkPrefetchPreference.
709 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
710 break;
711 case ConnectivityManager.TYPE_MOBILE:
712 case ConnectivityManager.TYPE_MOBILE_DUN:
713 case ConnectivityManager.TYPE_MOBILE_MMS:
714 case ConnectivityManager.TYPE_MOBILE_SUPL:
715 case ConnectivityManager.TYPE_WIMAX:
716 default:
717 break;
718 }
719 }
720 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
721 mLinkPrefetchAllowed = linkPrefetchAllowed;
722 syncManagedSettings();
723 }
724 }
725
luxiaol62677b02013-07-22 07:54:49 +0800726 public String getDownloadPath() {
727 return mPrefs.getString(PREF_DOWNLOAD_PATH,
728 DownloadHandler.getDefaultDownloadPath(mContext));
729 }
John Reck35e9dd62011-04-25 09:01:54 -0700730 // -----------------------------
731 // getter/setters for accessibility_preferences.xml
732 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100733
John Reck7dc444b2011-06-16 17:44:29 -0700734 @Deprecated
735 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700736 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
737 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100738 }
739
John Reck35e9dd62011-04-25 09:01:54 -0700740 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700741 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700742 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100743 }
744
John Reck92f25f82011-04-26 16:57:10 -0700745 public boolean forceEnableUserScalable() {
746 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
747 }
748
John Reck7dc444b2011-06-16 17:44:29 -0700749 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700750 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700751 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
752 return getAdjustedTextZoom(textZoom);
753 }
754
755 public void setTextZoom(int percent) {
756 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
757 }
758
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700759 public int getDoubleTapZoom() {
760 requireInitialization();
761 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
762 return getAdjustedDoubleTapZoom(doubleTapZoom);
763 }
764
765 public void setDoubleTapZoom(int percent) {
766 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
767 }
768
John Reck35e9dd62011-04-25 09:01:54 -0700769 // -----------------------------
770 // getter/setters for advanced_preferences.xml
771 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100772
John Reck35e9dd62011-04-25 09:01:54 -0700773 public String getSearchEngineName() {
Panos Thomas64c77e02014-12-17 22:15:23 -0800774 // The following is a NOP if the SEARCH_ENGINE restriction has already been created. Otherwise,
775 // it creates the restriction and if enabled it sets the <default_search_engine_value>.
776 SearchEngineRestriction.getInstance();
777
luxiaol221b3932013-07-19 15:27:57 +0800778 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
779 if (defaultSearchEngineValue == null) {
780 defaultSearchEngineValue = SearchEngine.GOOGLE;
781 }
782 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100783 }
John Reck63bb6872010-12-01 19:29:32 -0800784
Michael Kolb8d772b02012-01-19 13:56:00 -0800785 public boolean allowAppTabs() {
786 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
787 }
788
John Reck35e9dd62011-04-25 09:01:54 -0700789 public boolean openInBackground() {
790 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800791 }
John Reck35e9dd62011-04-25 09:01:54 -0700792
793 public boolean enableJavascript() {
794 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
795 }
796
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800797 public boolean enableMemoryMonitor() {
798 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
799 }
800
Tarun Nainani8eb00912014-07-17 12:28:32 -0700801
John Reck35e9dd62011-04-25 09:01:54 -0700802 public boolean loadPageInOverviewMode() {
803 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
804 }
805
806 public boolean autofitPages() {
807 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
808 }
809
810 public boolean blockPopupWindows() {
Pankaj Garg11015212015-07-06 14:38:43 -0700811 return !PermissionsServiceFactory.getDefaultPermissions(
812 PermissionsServiceFactory.PermissionType.POPUP);
John Reck35e9dd62011-04-25 09:01:54 -0700813 }
814
815 public boolean loadImages() {
816 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
817 }
818
819 public String getDefaultTextEncoding() {
Tarun Nainani88381422015-04-02 19:47:21 -0700820 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
John Reck35e9dd62011-04-25 09:01:54 -0700821 }
822
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700823 public String getEdgeSwipeAction() {
824 return mPrefs.getString(PREF_EDGE_SWIPE,
825 mContext.getResources().getString(R.string.value_unknown_edge_swipe));
826 }
827
828 public void setEdgeSwipeTemporal() {
829 mPrefs.edit().putString(PREF_EDGE_SWIPE,
830 mContext.getResources().getString(R.string.value_temporal_edge_swipe)).apply();
831 }
832
833 public void setEdgeSwipeSpatial() {
834 mPrefs.edit().putString(PREF_EDGE_SWIPE,
835 mContext.getResources().getString(R.string.value_spatial_edge_swipe)).apply();
836 }
837
838 public void setEdgeSwipeDisabled() {
839 mPrefs.edit().putString(PREF_EDGE_SWIPE,
840 mContext.getResources().getString(R.string.value_disable_edge_swipe)).apply();
841 }
842
John Reck35e9dd62011-04-25 09:01:54 -0700843 // -----------------------------
844 // getter/setters for general_preferences.xml
845 // -----------------------------
846
847 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700848 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
849 }
850
851 public void setHomePage(String value) {
852 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
853 }
854
855 public boolean isAutofillEnabled() {
856 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
857 }
858
859 public void setAutofillEnabled(boolean value) {
860 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
861 }
862
Site Maoabb7bd32015-03-20 15:34:02 -0700863 public boolean isPowerSaveModeEnabled() {
864 return mPrefs.getBoolean(PREF_POWERSAVE_ENABLED, false);
865 }
866
867 public void setPowerSaveModeEnabled(boolean value) {
868 mPrefs.edit().putBoolean(PREF_POWERSAVE_ENABLED, value).apply();
869 }
870
Yida Wang078425c2015-06-02 14:14:06 -0400871 public boolean isNightModeEnabled() {
872 return mPrefs.getBoolean(PREF_NIGHTMODE_ENABLED, false);
873 }
874
875 public void setNightModeEnabled(boolean value) {
876 mPrefs.edit().putBoolean(PREF_NIGHTMODE_ENABLED, value).apply();
877 }
878
John Reck35e9dd62011-04-25 09:01:54 -0700879 // -----------------------------
880 // getter/setters for debug_preferences.xml
881 // -----------------------------
882
883 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700884 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700885 return true;
886 }
887 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
888 }
889
Derek Sollenberger31adf672011-07-08 11:31:30 -0400890 public boolean isSkiaHardwareAccelerated() {
891 if (!isDebugEnabled()) {
892 return false;
893 }
894 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
895 }
896
John Reck35e9dd62011-04-25 09:01:54 -0700897 // -----------------------------
898 // getter/setters for hidden_debug_preferences.xml
899 // -----------------------------
900
901 public boolean enableVisualIndicator() {
902 if (!isDebugEnabled()) {
903 return false;
904 }
905 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
906 }
907
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700908 public boolean enableCpuUploadPath() {
909 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700910 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700911 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700912 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700913 }
914
John Reck35e9dd62011-04-25 09:01:54 -0700915 public boolean isSmallScreen() {
916 if (!isDebugEnabled()) {
917 return false;
918 }
919 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
920 }
921
922 public boolean isWideViewport() {
923 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800924 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700925 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800926 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700927 }
928
929 public boolean isNormalLayout() {
930 if (!isDebugEnabled()) {
931 return false;
932 }
933 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
934 }
935
936 public boolean isTracing() {
937 if (!isDebugEnabled()) {
938 return false;
939 }
940 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
941 }
942
943 public boolean enableLightTouch() {
944 if (!isDebugEnabled()) {
945 return false;
946 }
947 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
948 }
949
950 public boolean enableNavDump() {
951 if (!isDebugEnabled()) {
952 return false;
953 }
954 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
955 }
956
957 public String getJsEngineFlags() {
958 if (!isDebugEnabled()) {
959 return "";
960 }
961 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
962 }
963
964 // -----------------------------
965 // getter/setters for lab_preferences.xml
966 // -----------------------------
967
John Reck35e9dd62011-04-25 09:01:54 -0700968 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700969 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700970 }
971
Michael Kolbc38c6042011-04-27 10:46:06 -0700972 public boolean useFullscreen() {
973 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
974 }
975
John Reck2fd9d0e2011-07-15 11:13:48 -0700976 public boolean useInvertedRendering() {
977 return mPrefs.getBoolean(PREF_INVERTED, false);
978 }
979
Nicolas Roard5d513102011-08-03 15:35:34 -0700980 public float getInvertedContrast() {
981 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
982 }
983
John Reck35e9dd62011-04-25 09:01:54 -0700984 // -----------------------------
985 // getter/setters for privacy_security_preferences.xml
986 // -----------------------------
987
988 public boolean showSecurityWarnings() {
989 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
990 }
991
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700992 public boolean doNotTrack() {
Dave Tharpb487d5d2015-05-15 15:54:08 -0700993 boolean dntVal;
994 if (DoNotTrackRestriction.getInstance().isEnabled()) {
995 dntVal = DoNotTrackRestriction.getInstance().getValue();
996 }
997 else {
998 dntVal = mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
999 }
1000 return dntVal;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001001 }
1002
John Reck35e9dd62011-04-25 09:01:54 -07001003 public boolean acceptCookies() {
Pankaj Garg32e1b942015-06-03 18:13:24 -07001004 return PermissionsServiceFactory.getDefaultPermissions(
1005 PermissionsServiceFactory.PermissionType.COOKIE);
John Reck35e9dd62011-04-25 09:01:54 -07001006 }
1007
1008 public boolean saveFormdata() {
1009 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
1010 }
1011
1012 public boolean enableGeolocation() {
1013 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
1014 }
1015
1016 public boolean rememberPasswords() {
1017 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
1018 }
1019
Michael Kolb14612442011-06-24 13:06:29 -07001020 // -----------------------------
1021 // getter/setters for bandwidth_preferences.xml
1022 // -----------------------------
1023
Mathew Inwood467813f2011-09-02 15:43:17 +01001024 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
1025 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -07001026 }
Mathew Inwood467813f2011-09-02 15:43:17 +01001027
1028 public static String getPreloadAlwaysPreferenceString(Context context) {
1029 return context.getResources().getString(R.string.pref_data_preload_value_always);
1030 }
1031
Mathew Inwood825fba72011-10-04 14:52:52 +01001032 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
1033 "browser_default_preload_setting";
1034
1035 public String getDefaultPreloadSetting() {
1036 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1037 DEAULT_PRELOAD_SECURE_SETTING_KEY);
1038 if (preload == null) {
1039 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
1040 }
1041 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +01001042 }
1043
1044 public String getPreloadEnabled() {
1045 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
1046 }
1047
Victoria Lease96497832012-03-23 14:19:56 -07001048 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
1049 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
1050 }
1051
1052 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
1053 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
1054 }
1055
1056 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
1057 "browser_default_link_prefetch_setting";
1058
1059 public String getDefaultLinkPrefetchSetting() {
1060 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1061 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
1062 if (preload == null) {
1063 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
1064 }
1065 return preload;
1066 }
1067
1068 public String getLinkPrefetchEnabled() {
1069 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
1070 }
1071
George Mount3636d0a2011-11-21 09:08:21 -08001072 // -----------------------------
1073 // getter/setters for browser recovery
1074 // -----------------------------
1075 /**
1076 * The last time browser was started.
1077 * @return The last browser start time as System.currentTimeMillis. This
1078 * can be 0 if this is the first time or the last tab was closed.
1079 */
1080 public long getLastRecovered() {
1081 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1082 }
1083
1084 /**
1085 * Sets the last browser start time.
1086 * @param time The last time as System.currentTimeMillis that the browser
1087 * was started. This should be set to 0 if the last tab is closed.
1088 */
1089 public void setLastRecovered(long time) {
1090 mPrefs.edit()
1091 .putLong(KEY_LAST_RECOVERED, time)
1092 .apply();
1093 }
1094
1095 /**
1096 * Used to determine whether or not the previous browser run crashed. Once
1097 * the previous state has been determined, the value will be set to false
1098 * until a pause is received.
1099 * @return true if the last browser run was paused or false if it crashed.
1100 */
1101 public boolean wasLastRunPaused() {
1102 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1103 }
1104
1105 /**
1106 * Sets whether or not the last run was a pause or crash.
1107 * @param isPaused Set to true When a pause is received or false after
1108 * resuming.
1109 */
1110 public void setLastRunPaused(boolean isPaused) {
1111 mPrefs.edit()
1112 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1113 .apply();
1114 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001115}