blob: a60a1095f1743c52a748024311c6566a71c775b6 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.content.ContentResolver;
20import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070022import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080023import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070024import android.net.ConnectivityManager;
25import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070026import android.os.Build;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.preference.PreferenceManager;
Mathew Inwood825fba72011-10-04 14:52:52 +010028import android.provider.Settings;
Bijan Amirzadae75909d2014-05-06 14:18:54 -070029import android.text.TextUtils;
John Reck5ba3c762011-09-14 15:00:15 -070030import android.util.DisplayMetrics;
Nicolas Roard78a98e42009-05-11 13:34:17 +010031import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Bijan Amirzada41242f22014-03-21 12:12:18 -070033import com.android.browser.R;
34import com.android.browser.homepages.HomeProvider;
Dave Tharpb487d5d2015-05-15 15:54:08 -070035import com.android.browser.mdm.DoNotTrackRestriction;
Panos Thomasa9ff2c72014-12-17 22:15:23 -080036import com.android.browser.mdm.ProxyRestriction;
Panos Thomas64c77e02014-12-17 22:15:23 -080037import com.android.browser.mdm.SearchEngineRestriction;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070038import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070039import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070040import com.android.browser.search.SearchEngine;
41import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070042
John Reck35e9dd62011-04-25 09:01:54 -070043import java.lang.ref.WeakReference;
44import java.util.Iterator;
45import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070046import java.util.WeakHashMap;
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;
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -070051import org.codeaurora.swe.WebRefiner;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080052import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
53import org.codeaurora.swe.WebSettings.PluginState;
54import org.codeaurora.swe.WebSettings.TextSize;
55import org.codeaurora.swe.WebSettings.ZoomDensity;
56import org.codeaurora.swe.WebSettings;
57import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070058import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080059
John Reck35e9dd62011-04-25 09:01:54 -070060/**
61 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080062 */
John Reck35e9dd62011-04-25 09:01:54 -070063public class BrowserSettings implements OnSharedPreferenceChangeListener,
64 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010065
qqzhoue6ff8b42013-07-23 17:28:48 +080066 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070067 // The minimum min font size
68 // Aka, the lower bounds for the min font size range
69 // which is 1:5..24
70 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070071 // The initial value in the text zoom range
72 // This is what represents 100% in the SeekBarPreference range
73 private static final int TEXT_ZOOM_START_VAL = 10;
74 // The size of a single step in the text zoom range, in percent
75 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070076 // The initial value in the double tap zoom range
77 // This is what represents 100% in the SeekBarPreference range
78 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
79 // The size of a single step in the double tap zoom range, in percent
80 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070081
John Reck35e9dd62011-04-25 09:01:54 -070082 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070083
John Reck35e9dd62011-04-25 09:01:54 -070084 private Context mContext;
85 private SharedPreferences mPrefs;
86 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070087 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070088 private WebStorageSizeManager mWebStorageSizeManager;
89 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010090 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070091 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070092 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070093
Victoria Lease96497832012-03-23 14:19:56 -070094 // Current state of network-dependent settings
95 private boolean mLinkPrefetchAllowed = true;
96
John Reck78a6a1d2011-07-21 13:54:03 -070097 // Cached values
98 private int mPageCacheCapacity = 1;
99 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
John Reck35e9dd62011-04-25 09:01:54 -0700101 // Cached settings
102 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800103
Ben Murdochaaa1f372011-07-25 15:40:58 +0100104 private static String sFactoryResetUrl;
105
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700106 private boolean mEngineInitialized = false;
107 private boolean mSyncManagedSettings = false;
108
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700109 public static synchronized void initialize(final Context context) {
110 if (sInstance == null)
111 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700112 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800113
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700114 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700115 return sInstance;
116 }
Ben Murdochef671652010-11-25 17:17:58 +0000117
John Reck35e9dd62011-04-25 09:01:54 -0700118 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100119 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700120 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700121 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700122 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700123 }
124
125 public void setController(Controller controller) {
126 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700127 mNeedsSharedSync = true;
128 }
129
130 public void onEngineInitializationComplete() {
131 mEngineInitialized = true;
132 mAutofillHandler = new AutofillHandler(mContext);
133 if (mSyncManagedSettings) {
134 syncManagedSettings();
135 }
136 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700137 syncSharedSettings();
138 }
Panos Thomasa9ff2c72014-12-17 22:15:23 -0800139 // Instantiate ProxyRestriction after engine initialization
140 // to ensure ProxyChangeListener is already created.
141 ProxyRestriction.getInstance();
Ben Murdochef671652010-11-25 17:17:58 +0000142 }
143
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800144 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800145
John Reckc477e712011-08-17 11:27:15 -0700146 if (mNeedsSharedSync) {
147 syncSharedSettings();
148 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800149
John Reck35e9dd62011-04-25 09:01:54 -0700150 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800151 syncStaticSettings(settings);
152 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700153 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800154 }
155 }
156
John Reckd1d87312012-03-08 13:25:00 -0800157 public void stopManagingSettings(WebSettings settings) {
158 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
159 while (iter.hasNext()) {
160 WeakReference<WebSettings> ref = iter.next();
161 if (ref.get() == settings) {
162 iter.remove();
163 return;
164 }
165 }
166 }
167
John Reckcadae722011-07-25 11:36:17 -0700168 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700169
170 @Override
171 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700172 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
173 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700174 // the cost of one cached page is ~3M (measured using nytimes.com). For
175 // low end devices, we only cache one page. For high end devices, we try
176 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800177
178 // SWE_TODO : assume a high-memory device
179 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700180 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800181 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700182 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
183 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
184 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700185 // Workaround b/5254577
186 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700187 if (Build.VERSION.CODENAME.equals("REL")) {
188 // This is a release build, always startup with debug disabled
189 setDebugEnabled(false);
190 }
191 if (mPrefs.contains(PREF_TEXT_SIZE)) {
192 /*
193 * Update from TextSize enum to zoom percent
194 * SMALLEST is 50%
195 * SMALLER is 75%
196 * NORMAL is 100%
197 * LARGER is 150%
198 * LARGEST is 200%
199 */
200 switch (getTextSize()) {
201 case SMALLEST:
202 setTextZoom(50);
203 break;
204 case SMALLER:
205 setTextZoom(75);
206 break;
207 case LARGER:
208 setTextZoom(150);
209 break;
210 case LARGEST:
211 setTextZoom(200);
212 break;
213 }
214 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
215 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100216
qqzhou8c5b0a32013-07-22 15:31:03 +0800217 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700218 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800219
kaiyizbf086ea2013-08-02 11:03:58 +0800220 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800221 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800222 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700223
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700224 if (!mPrefs.contains(PREF_EDGE_SWIPE)) {
225 mPrefs.edit().putString(PREF_EDGE_SWIPE,
226 mContext.getResources().getString(
227 R.string.value_unknown_edge_swipe)).apply();
228 }
229
Ben Murdochaaa1f372011-07-25 15:40:58 +0100230 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
231 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
232 BrowserProvider.getClientId(mContext.getContentResolver()));
233 }
234
Ben Murdochaaa1f372011-07-25 15:40:58 +0100235 synchronized (BrowserSettings.class) {
236 sInitialized = true;
237 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700238 }
239 }
240 };
241
Ben Murdochaaa1f372011-07-25 15:40:58 +0100242 private static void requireInitialization() {
243 synchronized (BrowserSettings.class) {
244 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700245 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100246 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700247 } catch (InterruptedException e) {
248 }
249 }
250 }
251 }
252
The Android Open Source Project0c908882009-03-03 19:32:16 -0800253 /**
John Reck35e9dd62011-04-25 09:01:54 -0700254 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800255 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800256 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700257 settings.setGeolocationEnabled(enableGeolocation());
258 settings.setJavaScriptEnabled(enableJavascript());
259 settings.setLightTouchEnabled(enableLightTouch());
260 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700261 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700262 settings.setMinimumFontSize(getMinimumFontSize());
263 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700264 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700265 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100266 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700267 settings.setLoadsImagesAutomatically(loadImages());
268 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
269 settings.setSavePassword(rememberPasswords());
270 settings.setSaveFormData(saveFormdata());
271 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700272 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700273 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700274
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800275 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800276 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
277 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
278 settingsClassic.setForceUserScalable(forceEnableUserScalable());
279 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
280 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800281
John Reckea17e782011-10-27 17:15:59 -0700282 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800283 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700284 useInverted ? "true" : "false");
285 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800286 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700287 Float.toString(getInvertedContrast()));
288 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700289
John Reckea17e782011-10-27 17:15:59 -0700290 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800291 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700292 enableCpuUploadPath() ? "true" : "false");
293 }
Victoria Lease96497832012-03-23 14:19:56 -0700294
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800295 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000296 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800297
Tarun Nainani8eb00912014-07-17 12:28:32 -0700298
John Reck35e9dd62011-04-25 09:01:54 -0700299 /**
300 * Syncs all the settings that have no UI
301 * These cannot change, so we only need to set them once per WebSettings
302 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800303 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700304 settings.setDefaultFontSize(16);
305 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000306
John Reck35e9dd62011-04-25 09:01:54 -0700307 // WebView inside Browser doesn't want initial focus to be set.
308 settings.setNeedInitialFocus(false);
309 // Browser supports multiple windows
310 settings.setSupportMultipleWindows(true);
311 // enable smooth transition for better performance during panning or
312 // zooming
313 settings.setEnableSmoothTransition(true);
314 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700315 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700316
317 // HTML5 API flags
318 settings.setAppCacheEnabled(true);
319 settings.setDatabaseEnabled(true);
320 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700321
322 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700323 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700324 settings.setAppCachePath(getAppCachePath());
325 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
326 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700327 // origin policy for file access
328 settings.setAllowUniversalAccessFromFileURLs(false);
329 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700330 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800331
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800332 //if (!(settings instanceof WebSettingsClassic)) return;
333 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800334
335 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
336 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
337 // WebView should be preserving the memory as much as possible.
338 // However, apps like browser wish to turn on the performance mode which
339 // would require more memory.
340 // TODO: We need to dynamically allocate/deallocate temporary memory for
341 // apps which are trying to use minimal memory. Currently, double
342 // buffering is always turned on, which is unnecessary.
343 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
344 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800345 */
John Reck35e9dd62011-04-25 09:01:54 -0700346 }
347
348 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700349 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700350 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800351
John Reck35e9dd62011-04-25 09:01:54 -0700352 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700353
John Reck35e9dd62011-04-25 09:01:54 -0700354 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700355 if (!mEngineInitialized) {
356 mSyncManagedSettings = true;
357 return;
358 }
359 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700360 syncSharedSettings();
361 synchronized (mManagedSettings) {
362 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
363 while (iter.hasNext()) {
364 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800365 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700366 if (settings == null) {
367 iter.remove();
368 continue;
369 }
370 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000371 }
John Reck35e9dd62011-04-25 09:01:54 -0700372 }
373 }
Ben Murdochef671652010-11-25 17:17:58 +0000374
John Reck35e9dd62011-04-25 09:01:54 -0700375 @Override
376 public void onSharedPreferenceChanged(
377 SharedPreferences sharedPreferences, String key) {
378 syncManagedSettings();
379 if (PREF_SEARCH_ENGINE.equals(key)) {
380 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700381 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200382 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700383 mController.getUi().setFullscreen(useFullscreen());
384 }
Victoria Lease96497832012-03-23 14:19:56 -0700385 } else if (PREF_LINK_PREFETCH.equals(key)) {
386 updateConnectionType();
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700387 } else if (PREF_WEB_REFINER_ENABLED.equals(key)) {
388 if (WebRefiner.isInitialized())
389 WebRefiner.getInstance().setRulesEnabled(WebRefiner.CATEGORY_ALL, isWebRefinerEnabled());
Michael Kolbc38c6042011-04-27 10:46:06 -0700390 }
John Reck35e9dd62011-04-25 09:01:54 -0700391 }
392
John Reck961d35d2011-06-23 09:45:54 -0700393 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100394 requireInitialization();
395 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700396 }
397
398 public LayoutAlgorithm getLayoutAlgorithm() {
399 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
400 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700401 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700402 }
403 if (isDebugEnabled()) {
404 if (isSmallScreen()) {
405 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000406 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700407 if (isNormalLayout()) {
408 layoutAlgorithm = LayoutAlgorithm.NORMAL;
409 } else {
410 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
411 }
Ben Murdochef671652010-11-25 17:17:58 +0000412 }
John Reck35e9dd62011-04-25 09:01:54 -0700413 }
414 return layoutAlgorithm;
415 }
Ben Murdochef671652010-11-25 17:17:58 +0000416
John Reck35e9dd62011-04-25 09:01:54 -0700417 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700418 requireInitialization();
419 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800420 }
421
John Reck35e9dd62011-04-25 09:01:54 -0700422 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700423 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700424 return mWebStorageSizeManager;
425 }
426
John Reck35e9dd62011-04-25 09:01:54 -0700427 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700428 if (mAppCachePath == null) {
429 mAppCachePath = mContext.getDir("appcache", 0).getPath();
430 }
431 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700432 }
433
434 private void updateSearchEngine(boolean force) {
435 String searchEngineName = getSearchEngineName();
436 if (force || mSearchEngine == null ||
437 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700438 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000439 }
440 }
441
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100442 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700443 if (mSearchEngine == null) {
444 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100445 }
John Reck35e9dd62011-04-25 09:01:54 -0700446 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100447 }
448
John Reck35e9dd62011-04-25 09:01:54 -0700449 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700450 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700451 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100452 }
453
John Reck35e9dd62011-04-25 09:01:54 -0700454 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700455 Editor edit = mPrefs.edit();
456 edit.putBoolean(PREF_DEBUG_MENU, value);
457 if (!value) {
458 // Reset to "safe" value
459 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
460 }
461 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100462 }
463
John Reck35e9dd62011-04-25 09:01:54 -0700464 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 if (mController != null) {
466 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800467 if (current != null) {
468 current.clearCache(true);
469 }
470 }
471 }
472
John Reck35e9dd62011-04-25 09:01:54 -0700473 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800474 CookieManager.getInstance().removeAllCookie();
475 }
476
John Reck35e9dd62011-04-25 09:01:54 -0700477 public void clearHistory() {
478 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800479 Browser.clearHistory(resolver);
480 Browser.clearSearches(resolver);
481 }
482
John Reck35e9dd62011-04-25 09:01:54 -0700483 public void clearFormData() {
484 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 if (mController!= null) {
486 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100487 if (currentTopView != null) {
488 currentTopView.clearFormData();
489 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800490 }
491 }
492
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700493 public WebView getTopWebView(){
494 if (mController!= null)
495 return mController.getCurrentTopWebView();
496
497 return null;
498 }
499
John Reck35e9dd62011-04-25 09:01:54 -0700500 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700501 // Clear password store maintained by SWE engine
502 WebSettings settings = null;
503 // find a valid settings object
504 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
505 while (iter.hasNext()) {
506 WeakReference<WebSettings> ref = iter.next();
507 settings = (WebSettings)ref.get();
508 if (settings != null) {
509 break;
510 }
511 }
512 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700513 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700514 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700515
516 // Clear passwords in WebView database
517 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
518 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800519 }
520
John Reck35e9dd62011-04-25 09:01:54 -0700521 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100522 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100523 }
524
John Reck35e9dd62011-04-25 09:01:54 -0700525 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100526 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700527 if (GeolocationPermissions.isIncognitoCreated()) {
528 GeolocationPermissions.getIncognitoInstance().clearAll();
529 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100530 }
531
John Reck35e9dd62011-04-25 09:01:54 -0700532 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700533 mPrefs.edit()
534 .clear()
John Reckbd315192011-07-29 10:05:47 -0700535 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200536 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700537 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700538 }
539
Björn Isakssonc885a242012-06-05 17:19:04 +0200540 private void resetCachedValues() {
541 updateSearchEngine(false);
542 }
543
John Reck35e9dd62011-04-25 09:01:54 -0700544 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800545 // query the profile from components autofill database 524
546 if (mAutofillHandler.mAutoFillProfile == null &&
547 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
548 WebSettings settings = null;
549 // find a valid settings object
550 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
551 while (iter.hasNext()) {
552 WeakReference<WebSettings> ref = iter.next();
553 settings = (WebSettings)ref.get();
554 if (settings != null) {
555 break;
556 }
557 }
558 if (settings != null) {
559 AutoFillProfile profile =
560 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
561 mAutofillHandler.setAutoFillProfile(profile);
562 }
563 }
John Reck35e9dd62011-04-25 09:01:54 -0700564 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800565 }
566
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800567 public String getAutoFillProfileId() {
568 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800569 }
570
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800571 public void updateAutoFillProfile(AutoFillProfile profile) {
572 syncAutoFillProfile(profile);
573 }
574
575 private void syncAutoFillProfile(AutoFillProfile profile) {
576 synchronized (mManagedSettings) {
577 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
578 while (iter.hasNext()) {
579 WeakReference<WebSettings> ref = iter.next();
580 WebSettings settings = (WebSettings)ref.get();
581 if (settings == null) {
582 iter.remove();
583 continue;
584 }
585 // update the profile only once.
586 settings.setAutoFillProfile(profile);
587 // Now we should have the guid
588 mAutofillHandler.setAutoFillProfile(profile);
589 break;
590 }
591 }
592 }
John Reck35e9dd62011-04-25 09:01:54 -0700593 public void toggleDebugSettings() {
594 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800595 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100596
John Reckb8b2af82011-05-20 15:58:33 -0700597 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800598 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700599 }
600
601 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700602 if (view == null) {
603 return;
604 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800605 if (hasDesktopUseragent(view))
606 view.setUseDesktopUserAgent(false, true);
607 else
608 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700609 }
610
John Reck7dc444b2011-06-16 17:44:29 -0700611 public static int getAdjustedMinimumFontSize(int rawValue) {
612 rawValue++; // Preference starts at 0, min font at 1
613 if (rawValue > 1) {
614 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
615 }
616 return rawValue;
617 }
618
John Reck5ba3c762011-09-14 15:00:15 -0700619 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700620 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700621 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700622 }
623
624 static int getRawTextZoom(int percent) {
625 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
626 }
627
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700628 public int getAdjustedDoubleTapZoom(int rawValue) {
629 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
630 return (int) ((rawValue + 100) * mFontSizeMult);
631 }
632
633 static int getRawDoubleTapZoom(int percent) {
634 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
635 }
636
John Reckcadae722011-07-25 11:36:17 -0700637 public SharedPreferences getPreferences() {
638 return mPrefs;
639 }
640
Victoria Lease96497832012-03-23 14:19:56 -0700641 // update connectivity-dependent options
642 public void updateConnectionType() {
643 ConnectivityManager cm = (ConnectivityManager)
644 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
645 String linkPrefetchPreference = getLinkPrefetchEnabled();
646 boolean linkPrefetchAllowed = linkPrefetchPreference.
647 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
648 NetworkInfo ni = cm.getActiveNetworkInfo();
649 if (ni != null) {
650 switch (ni.getType()) {
651 case ConnectivityManager.TYPE_WIFI:
652 case ConnectivityManager.TYPE_ETHERNET:
653 case ConnectivityManager.TYPE_BLUETOOTH:
654 linkPrefetchAllowed |= linkPrefetchPreference.
655 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
656 break;
657 case ConnectivityManager.TYPE_MOBILE:
658 case ConnectivityManager.TYPE_MOBILE_DUN:
659 case ConnectivityManager.TYPE_MOBILE_MMS:
660 case ConnectivityManager.TYPE_MOBILE_SUPL:
661 case ConnectivityManager.TYPE_WIMAX:
662 default:
663 break;
664 }
665 }
666 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
667 mLinkPrefetchAllowed = linkPrefetchAllowed;
668 syncManagedSettings();
669 }
670 }
671
luxiaol62677b02013-07-22 07:54:49 +0800672 public String getDownloadPath() {
673 return mPrefs.getString(PREF_DOWNLOAD_PATH,
674 DownloadHandler.getDefaultDownloadPath(mContext));
675 }
John Reck35e9dd62011-04-25 09:01:54 -0700676 // -----------------------------
677 // getter/setters for accessibility_preferences.xml
678 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100679
John Reck7dc444b2011-06-16 17:44:29 -0700680 @Deprecated
681 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700682 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
683 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100684 }
685
John Reck35e9dd62011-04-25 09:01:54 -0700686 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700687 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700688 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100689 }
690
John Reck92f25f82011-04-26 16:57:10 -0700691 public boolean forceEnableUserScalable() {
692 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
693 }
694
John Reck7dc444b2011-06-16 17:44:29 -0700695 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700696 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700697 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
698 return getAdjustedTextZoom(textZoom);
699 }
700
701 public void setTextZoom(int percent) {
702 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
703 }
704
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700705 public int getDoubleTapZoom() {
706 requireInitialization();
707 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
708 return getAdjustedDoubleTapZoom(doubleTapZoom);
709 }
710
711 public void setDoubleTapZoom(int percent) {
712 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
713 }
714
John Reck35e9dd62011-04-25 09:01:54 -0700715 // -----------------------------
716 // getter/setters for advanced_preferences.xml
717 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100718
John Reck35e9dd62011-04-25 09:01:54 -0700719 public String getSearchEngineName() {
Panos Thomas64c77e02014-12-17 22:15:23 -0800720 // The following is a NOP if the SEARCH_ENGINE restriction has already been created. Otherwise,
721 // it creates the restriction and if enabled it sets the <default_search_engine_value>.
722 SearchEngineRestriction.getInstance();
723
luxiaol221b3932013-07-19 15:27:57 +0800724 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
725 if (defaultSearchEngineValue == null) {
726 defaultSearchEngineValue = SearchEngine.GOOGLE;
727 }
728 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100729 }
John Reck63bb6872010-12-01 19:29:32 -0800730
Michael Kolb8d772b02012-01-19 13:56:00 -0800731 public boolean allowAppTabs() {
732 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
733 }
734
John Reck35e9dd62011-04-25 09:01:54 -0700735 public boolean openInBackground() {
736 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800737 }
John Reck35e9dd62011-04-25 09:01:54 -0700738
739 public boolean enableJavascript() {
740 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
741 }
742
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800743 public boolean enableMemoryMonitor() {
744 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
745 }
746
Tarun Nainani8eb00912014-07-17 12:28:32 -0700747
John Reck35e9dd62011-04-25 09:01:54 -0700748 public boolean loadPageInOverviewMode() {
749 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
750 }
751
752 public boolean autofitPages() {
753 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
754 }
755
756 public boolean blockPopupWindows() {
757 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
758 }
759
760 public boolean loadImages() {
761 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
762 }
763
764 public String getDefaultTextEncoding() {
Tarun Nainani88381422015-04-02 19:47:21 -0700765 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
John Reck35e9dd62011-04-25 09:01:54 -0700766 }
767
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700768 public String getEdgeSwipeAction() {
769 return mPrefs.getString(PREF_EDGE_SWIPE,
770 mContext.getResources().getString(R.string.value_unknown_edge_swipe));
771 }
772
773 public void setEdgeSwipeTemporal() {
774 mPrefs.edit().putString(PREF_EDGE_SWIPE,
775 mContext.getResources().getString(R.string.value_temporal_edge_swipe)).apply();
776 }
777
778 public void setEdgeSwipeSpatial() {
779 mPrefs.edit().putString(PREF_EDGE_SWIPE,
780 mContext.getResources().getString(R.string.value_spatial_edge_swipe)).apply();
781 }
782
783 public void setEdgeSwipeDisabled() {
784 mPrefs.edit().putString(PREF_EDGE_SWIPE,
785 mContext.getResources().getString(R.string.value_disable_edge_swipe)).apply();
786 }
787
John Reck35e9dd62011-04-25 09:01:54 -0700788 // -----------------------------
789 // getter/setters for general_preferences.xml
790 // -----------------------------
791
792 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700793 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
794 }
795
796 public void setHomePage(String value) {
797 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
798 }
799
800 public boolean isAutofillEnabled() {
801 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
802 }
803
804 public void setAutofillEnabled(boolean value) {
805 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
806 }
807
Site Maoabb7bd32015-03-20 15:34:02 -0700808 public boolean isPowerSaveModeEnabled() {
809 return mPrefs.getBoolean(PREF_POWERSAVE_ENABLED, false);
810 }
811
812 public void setPowerSaveModeEnabled(boolean value) {
813 mPrefs.edit().putBoolean(PREF_POWERSAVE_ENABLED, value).apply();
814 }
815
Kulanthaivel Palanichamyf36e1db2015-04-08 16:11:06 -0700816 public boolean isWebRefinerEnabled() {
817 return mPrefs.getBoolean(PREF_WEB_REFINER_ENABLED, true);
818 }
819
820 public void setWebRefinerEnabled(boolean value) {
821 mPrefs.edit().putBoolean(PREF_WEB_REFINER_ENABLED, value).apply();
822 }
823
John Reck35e9dd62011-04-25 09:01:54 -0700824 // -----------------------------
825 // getter/setters for debug_preferences.xml
826 // -----------------------------
827
828 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700829 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700830 return true;
831 }
832 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
833 }
834
Derek Sollenberger31adf672011-07-08 11:31:30 -0400835 public boolean isSkiaHardwareAccelerated() {
836 if (!isDebugEnabled()) {
837 return false;
838 }
839 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
840 }
841
John Reck35e9dd62011-04-25 09:01:54 -0700842 // -----------------------------
843 // getter/setters for hidden_debug_preferences.xml
844 // -----------------------------
845
846 public boolean enableVisualIndicator() {
847 if (!isDebugEnabled()) {
848 return false;
849 }
850 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
851 }
852
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700853 public boolean enableCpuUploadPath() {
854 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700855 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700856 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700857 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700858 }
859
John Reck35e9dd62011-04-25 09:01:54 -0700860 public boolean isSmallScreen() {
861 if (!isDebugEnabled()) {
862 return false;
863 }
864 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
865 }
866
867 public boolean isWideViewport() {
868 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800869 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700870 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800871 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700872 }
873
874 public boolean isNormalLayout() {
875 if (!isDebugEnabled()) {
876 return false;
877 }
878 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
879 }
880
881 public boolean isTracing() {
882 if (!isDebugEnabled()) {
883 return false;
884 }
885 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
886 }
887
888 public boolean enableLightTouch() {
889 if (!isDebugEnabled()) {
890 return false;
891 }
892 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
893 }
894
895 public boolean enableNavDump() {
896 if (!isDebugEnabled()) {
897 return false;
898 }
899 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
900 }
901
902 public String getJsEngineFlags() {
903 if (!isDebugEnabled()) {
904 return "";
905 }
906 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
907 }
908
909 // -----------------------------
910 // getter/setters for lab_preferences.xml
911 // -----------------------------
912
John Reck35e9dd62011-04-25 09:01:54 -0700913 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700914 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700915 }
916
Michael Kolbc38c6042011-04-27 10:46:06 -0700917 public boolean useFullscreen() {
918 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
919 }
920
John Reck2fd9d0e2011-07-15 11:13:48 -0700921 public boolean useInvertedRendering() {
922 return mPrefs.getBoolean(PREF_INVERTED, false);
923 }
924
Nicolas Roard5d513102011-08-03 15:35:34 -0700925 public float getInvertedContrast() {
926 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
927 }
928
John Reck35e9dd62011-04-25 09:01:54 -0700929 // -----------------------------
930 // getter/setters for privacy_security_preferences.xml
931 // -----------------------------
932
933 public boolean showSecurityWarnings() {
934 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
935 }
936
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700937 public boolean doNotTrack() {
Dave Tharpb487d5d2015-05-15 15:54:08 -0700938 boolean dntVal;
939 if (DoNotTrackRestriction.getInstance().isEnabled()) {
940 dntVal = DoNotTrackRestriction.getInstance().getValue();
941 }
942 else {
943 dntVal = mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
944 }
945 return dntVal;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700946 }
947
John Reck35e9dd62011-04-25 09:01:54 -0700948 public boolean acceptCookies() {
949 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
950 }
951
952 public boolean saveFormdata() {
953 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
954 }
955
956 public boolean enableGeolocation() {
957 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
958 }
959
960 public boolean rememberPasswords() {
961 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
962 }
963
Michael Kolb14612442011-06-24 13:06:29 -0700964 // -----------------------------
965 // getter/setters for bandwidth_preferences.xml
966 // -----------------------------
967
Mathew Inwood467813f2011-09-02 15:43:17 +0100968 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
969 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700970 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100971
972 public static String getPreloadAlwaysPreferenceString(Context context) {
973 return context.getResources().getString(R.string.pref_data_preload_value_always);
974 }
975
Mathew Inwood825fba72011-10-04 14:52:52 +0100976 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
977 "browser_default_preload_setting";
978
979 public String getDefaultPreloadSetting() {
980 String preload = Settings.Secure.getString(mContext.getContentResolver(),
981 DEAULT_PRELOAD_SECURE_SETTING_KEY);
982 if (preload == null) {
983 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
984 }
985 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100986 }
987
988 public String getPreloadEnabled() {
989 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
990 }
991
Victoria Lease96497832012-03-23 14:19:56 -0700992 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
993 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
994 }
995
996 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
997 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
998 }
999
1000 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
1001 "browser_default_link_prefetch_setting";
1002
1003 public String getDefaultLinkPrefetchSetting() {
1004 String preload = Settings.Secure.getString(mContext.getContentResolver(),
1005 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
1006 if (preload == null) {
1007 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
1008 }
1009 return preload;
1010 }
1011
1012 public String getLinkPrefetchEnabled() {
1013 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
1014 }
1015
George Mount3636d0a2011-11-21 09:08:21 -08001016 // -----------------------------
1017 // getter/setters for browser recovery
1018 // -----------------------------
1019 /**
1020 * The last time browser was started.
1021 * @return The last browser start time as System.currentTimeMillis. This
1022 * can be 0 if this is the first time or the last tab was closed.
1023 */
1024 public long getLastRecovered() {
1025 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1026 }
1027
1028 /**
1029 * Sets the last browser start time.
1030 * @param time The last time as System.currentTimeMillis that the browser
1031 * was started. This should be set to 0 if the last tab is closed.
1032 */
1033 public void setLastRecovered(long time) {
1034 mPrefs.edit()
1035 .putLong(KEY_LAST_RECOVERED, time)
1036 .apply();
1037 }
1038
1039 /**
1040 * Used to determine whether or not the previous browser run crashed. Once
1041 * the previous state has been determined, the value will be set to false
1042 * until a pause is received.
1043 * @return true if the last browser run was paused or false if it crashed.
1044 */
1045 public boolean wasLastRunPaused() {
1046 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1047 }
1048
1049 /**
1050 * Sets whether or not the last run was a pause or crash.
1051 * @param isPaused Set to true When a pause is received or false after
1052 * resuming.
1053 */
1054 public void setLastRunPaused(boolean isPaused) {
1055 mPrefs.edit()
1056 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1057 .apply();
1058 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001059}