blob: e3d1ee56fcd68cc19fb89767130c7f6d2738f642 [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;
Panos Thomasa9ff2c72014-12-17 22:15:23 -080035import com.android.browser.mdm.ProxyRestriction;
Panos Thomas64c77e02014-12-17 22:15:23 -080036import com.android.browser.mdm.SearchEngineRestriction;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070037import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070038import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070039import com.android.browser.search.SearchEngine;
40import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070041
John Reck35e9dd62011-04-25 09:01:54 -070042import java.lang.ref.WeakReference;
43import java.util.Iterator;
44import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070045import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080047import org.codeaurora.swe.AutoFillProfile;
48import org.codeaurora.swe.CookieManager;
49import org.codeaurora.swe.GeolocationPermissions;
50import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
51import org.codeaurora.swe.WebSettings.PluginState;
52import org.codeaurora.swe.WebSettings.TextSize;
53import org.codeaurora.swe.WebSettings.ZoomDensity;
54import org.codeaurora.swe.WebSettings;
55import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070056import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080057
John Reck35e9dd62011-04-25 09:01:54 -070058/**
59 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080060 */
John Reck35e9dd62011-04-25 09:01:54 -070061public class BrowserSettings implements OnSharedPreferenceChangeListener,
62 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010063
qqzhoue6ff8b42013-07-23 17:28:48 +080064 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070065 // The minimum min font size
66 // Aka, the lower bounds for the min font size range
67 // which is 1:5..24
68 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070069 // The initial value in the text zoom range
70 // This is what represents 100% in the SeekBarPreference range
71 private static final int TEXT_ZOOM_START_VAL = 10;
72 // The size of a single step in the text zoom range, in percent
73 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070074 // The initial value in the double tap zoom range
75 // This is what represents 100% in the SeekBarPreference range
76 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
77 // The size of a single step in the double tap zoom range, in percent
78 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070079
John Reck35e9dd62011-04-25 09:01:54 -070080 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070081
John Reck35e9dd62011-04-25 09:01:54 -070082 private Context mContext;
83 private SharedPreferences mPrefs;
84 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070085 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070086 private WebStorageSizeManager mWebStorageSizeManager;
87 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010088 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070089 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070090 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070091
Victoria Lease96497832012-03-23 14:19:56 -070092 // Current state of network-dependent settings
93 private boolean mLinkPrefetchAllowed = true;
94
John Reck78a6a1d2011-07-21 13:54:03 -070095 // Cached values
96 private int mPageCacheCapacity = 1;
97 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080098
John Reck35e9dd62011-04-25 09:01:54 -070099 // Cached settings
100 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800101
Ben Murdochaaa1f372011-07-25 15:40:58 +0100102 private static String sFactoryResetUrl;
103
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700104 private boolean mEngineInitialized = false;
105 private boolean mSyncManagedSettings = false;
106
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700107 public static synchronized void initialize(final Context context) {
108 if (sInstance == null)
109 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700110 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800111
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700112 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700113 return sInstance;
114 }
Ben Murdochef671652010-11-25 17:17:58 +0000115
John Reck35e9dd62011-04-25 09:01:54 -0700116 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100117 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700118 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700119 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700120 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700121 }
122
123 public void setController(Controller controller) {
124 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700125 mNeedsSharedSync = true;
126 }
127
128 public void onEngineInitializationComplete() {
129 mEngineInitialized = true;
130 mAutofillHandler = new AutofillHandler(mContext);
131 if (mSyncManagedSettings) {
132 syncManagedSettings();
133 }
134 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700135 syncSharedSettings();
136 }
Panos Thomasa9ff2c72014-12-17 22:15:23 -0800137 // Instantiate ProxyRestriction after engine initialization
138 // to ensure ProxyChangeListener is already created.
139 ProxyRestriction.getInstance();
Ben Murdochef671652010-11-25 17:17:58 +0000140 }
141
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800142 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800143
John Reckc477e712011-08-17 11:27:15 -0700144 if (mNeedsSharedSync) {
145 syncSharedSettings();
146 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800147
John Reck35e9dd62011-04-25 09:01:54 -0700148 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800149 syncStaticSettings(settings);
150 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700151 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800152 }
153 }
154
John Reckd1d87312012-03-08 13:25:00 -0800155 public void stopManagingSettings(WebSettings settings) {
156 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
157 while (iter.hasNext()) {
158 WeakReference<WebSettings> ref = iter.next();
159 if (ref.get() == settings) {
160 iter.remove();
161 return;
162 }
163 }
164 }
165
John Reckcadae722011-07-25 11:36:17 -0700166 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700167
168 @Override
169 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700170 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
171 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700172 // the cost of one cached page is ~3M (measured using nytimes.com). For
173 // low end devices, we only cache one page. For high end devices, we try
174 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800175
176 // SWE_TODO : assume a high-memory device
177 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700178 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800179 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700180 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
181 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
182 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700183 // Workaround b/5254577
184 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700185 if (Build.VERSION.CODENAME.equals("REL")) {
186 // This is a release build, always startup with debug disabled
187 setDebugEnabled(false);
188 }
189 if (mPrefs.contains(PREF_TEXT_SIZE)) {
190 /*
191 * Update from TextSize enum to zoom percent
192 * SMALLEST is 50%
193 * SMALLER is 75%
194 * NORMAL is 100%
195 * LARGER is 150%
196 * LARGEST is 200%
197 */
198 switch (getTextSize()) {
199 case SMALLEST:
200 setTextZoom(50);
201 break;
202 case SMALLER:
203 setTextZoom(75);
204 break;
205 case LARGER:
206 setTextZoom(150);
207 break;
208 case LARGEST:
209 setTextZoom(200);
210 break;
211 }
212 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
213 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100214
qqzhou8c5b0a32013-07-22 15:31:03 +0800215 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700216 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800217
kaiyizbf086ea2013-08-02 11:03:58 +0800218 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800219 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800220 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700221
Ben Murdochaaa1f372011-07-25 15:40:58 +0100222 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
223 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
224 BrowserProvider.getClientId(mContext.getContentResolver()));
225 }
226
Ben Murdochaaa1f372011-07-25 15:40:58 +0100227 synchronized (BrowserSettings.class) {
228 sInitialized = true;
229 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700230 }
231 }
232 };
233
Ben Murdochaaa1f372011-07-25 15:40:58 +0100234 private static void requireInitialization() {
235 synchronized (BrowserSettings.class) {
236 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700237 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100238 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700239 } catch (InterruptedException e) {
240 }
241 }
242 }
243 }
244
The Android Open Source Project0c908882009-03-03 19:32:16 -0800245 /**
John Reck35e9dd62011-04-25 09:01:54 -0700246 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800247 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800248 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700249 settings.setGeolocationEnabled(enableGeolocation());
250 settings.setJavaScriptEnabled(enableJavascript());
251 settings.setLightTouchEnabled(enableLightTouch());
252 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700253 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700254 settings.setMinimumFontSize(getMinimumFontSize());
255 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700256 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700257 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100258 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700259 settings.setLoadsImagesAutomatically(loadImages());
260 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
261 settings.setSavePassword(rememberPasswords());
262 settings.setSaveFormData(saveFormdata());
263 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700264 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700265 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700266
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800267 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800268 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
269 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
270 settingsClassic.setForceUserScalable(forceEnableUserScalable());
271 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
272 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800273
John Reckea17e782011-10-27 17:15:59 -0700274 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800275 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700276 useInverted ? "true" : "false");
277 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800278 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700279 Float.toString(getInvertedContrast()));
280 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700281
John Reckea17e782011-10-27 17:15:59 -0700282 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800283 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700284 enableCpuUploadPath() ? "true" : "false");
285 }
Victoria Lease96497832012-03-23 14:19:56 -0700286
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800287 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000288 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800289
Tarun Nainani8eb00912014-07-17 12:28:32 -0700290
John Reck35e9dd62011-04-25 09:01:54 -0700291 /**
292 * Syncs all the settings that have no UI
293 * These cannot change, so we only need to set them once per WebSettings
294 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800295 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700296 settings.setDefaultFontSize(16);
297 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000298
John Reck35e9dd62011-04-25 09:01:54 -0700299 // WebView inside Browser doesn't want initial focus to be set.
300 settings.setNeedInitialFocus(false);
301 // Browser supports multiple windows
302 settings.setSupportMultipleWindows(true);
303 // enable smooth transition for better performance during panning or
304 // zooming
305 settings.setEnableSmoothTransition(true);
306 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700307 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700308
309 // HTML5 API flags
310 settings.setAppCacheEnabled(true);
311 settings.setDatabaseEnabled(true);
312 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700313
314 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700315 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700316 settings.setAppCachePath(getAppCachePath());
317 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
318 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700319 // origin policy for file access
320 settings.setAllowUniversalAccessFromFileURLs(false);
321 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700322 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800323
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800324 //if (!(settings instanceof WebSettingsClassic)) return;
325 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800326
327 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
328 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
329 // WebView should be preserving the memory as much as possible.
330 // However, apps like browser wish to turn on the performance mode which
331 // would require more memory.
332 // TODO: We need to dynamically allocate/deallocate temporary memory for
333 // apps which are trying to use minimal memory. Currently, double
334 // buffering is always turned on, which is unnecessary.
335 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
336 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800337 */
John Reck35e9dd62011-04-25 09:01:54 -0700338 }
339
340 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700341 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700342 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800343
John Reck35e9dd62011-04-25 09:01:54 -0700344 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700345
John Reck35e9dd62011-04-25 09:01:54 -0700346 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700347 if (!mEngineInitialized) {
348 mSyncManagedSettings = true;
349 return;
350 }
351 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700352 syncSharedSettings();
353 synchronized (mManagedSettings) {
354 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
355 while (iter.hasNext()) {
356 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800357 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700358 if (settings == null) {
359 iter.remove();
360 continue;
361 }
362 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000363 }
John Reck35e9dd62011-04-25 09:01:54 -0700364 }
365 }
Ben Murdochef671652010-11-25 17:17:58 +0000366
John Reck35e9dd62011-04-25 09:01:54 -0700367 @Override
368 public void onSharedPreferenceChanged(
369 SharedPreferences sharedPreferences, String key) {
370 syncManagedSettings();
371 if (PREF_SEARCH_ENGINE.equals(key)) {
372 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700373 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200374 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700375 mController.getUi().setFullscreen(useFullscreen());
376 }
Victoria Lease96497832012-03-23 14:19:56 -0700377 } else if (PREF_LINK_PREFETCH.equals(key)) {
378 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700379 }
John Reck35e9dd62011-04-25 09:01:54 -0700380 }
381
John Reck961d35d2011-06-23 09:45:54 -0700382 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100383 requireInitialization();
384 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700385 }
386
387 public LayoutAlgorithm getLayoutAlgorithm() {
388 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
389 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700390 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700391 }
392 if (isDebugEnabled()) {
393 if (isSmallScreen()) {
394 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000395 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700396 if (isNormalLayout()) {
397 layoutAlgorithm = LayoutAlgorithm.NORMAL;
398 } else {
399 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
400 }
Ben Murdochef671652010-11-25 17:17:58 +0000401 }
John Reck35e9dd62011-04-25 09:01:54 -0700402 }
403 return layoutAlgorithm;
404 }
Ben Murdochef671652010-11-25 17:17:58 +0000405
John Reck35e9dd62011-04-25 09:01:54 -0700406 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700407 requireInitialization();
408 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800409 }
410
John Reck35e9dd62011-04-25 09:01:54 -0700411 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700412 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700413 return mWebStorageSizeManager;
414 }
415
John Reck35e9dd62011-04-25 09:01:54 -0700416 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700417 if (mAppCachePath == null) {
418 mAppCachePath = mContext.getDir("appcache", 0).getPath();
419 }
420 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700421 }
422
423 private void updateSearchEngine(boolean force) {
424 String searchEngineName = getSearchEngineName();
425 if (force || mSearchEngine == null ||
426 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700427 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000428 }
429 }
430
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100431 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700432 if (mSearchEngine == null) {
433 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100434 }
John Reck35e9dd62011-04-25 09:01:54 -0700435 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100436 }
437
John Reck35e9dd62011-04-25 09:01:54 -0700438 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700439 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700440 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100441 }
442
John Reck35e9dd62011-04-25 09:01:54 -0700443 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700444 Editor edit = mPrefs.edit();
445 edit.putBoolean(PREF_DEBUG_MENU, value);
446 if (!value) {
447 // Reset to "safe" value
448 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
449 }
450 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100451 }
452
John Reck35e9dd62011-04-25 09:01:54 -0700453 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700454 if (mController != null) {
455 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800456 if (current != null) {
457 current.clearCache(true);
458 }
459 }
460 }
461
John Reck35e9dd62011-04-25 09:01:54 -0700462 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800463 CookieManager.getInstance().removeAllCookie();
464 }
465
John Reck35e9dd62011-04-25 09:01:54 -0700466 public void clearHistory() {
467 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800468 Browser.clearHistory(resolver);
469 Browser.clearSearches(resolver);
470 }
471
John Reck35e9dd62011-04-25 09:01:54 -0700472 public void clearFormData() {
473 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700474 if (mController!= null) {
475 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100476 if (currentTopView != null) {
477 currentTopView.clearFormData();
478 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800479 }
480 }
481
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700482 public WebView getTopWebView(){
483 if (mController!= null)
484 return mController.getCurrentTopWebView();
485
486 return null;
487 }
488
John Reck35e9dd62011-04-25 09:01:54 -0700489 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700490 // Clear password store maintained by SWE engine
491 WebSettings settings = null;
492 // find a valid settings object
493 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
494 while (iter.hasNext()) {
495 WeakReference<WebSettings> ref = iter.next();
496 settings = (WebSettings)ref.get();
497 if (settings != null) {
498 break;
499 }
500 }
501 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700502 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700503 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700504
505 // Clear passwords in WebView database
506 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
507 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800508 }
509
John Reck35e9dd62011-04-25 09:01:54 -0700510 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100511 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100512 }
513
John Reck35e9dd62011-04-25 09:01:54 -0700514 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100515 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700516 if (GeolocationPermissions.isIncognitoCreated()) {
517 GeolocationPermissions.getIncognitoInstance().clearAll();
518 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100519 }
520
John Reck35e9dd62011-04-25 09:01:54 -0700521 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700522 mPrefs.edit()
523 .clear()
John Reckbd315192011-07-29 10:05:47 -0700524 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200525 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700526 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700527 }
528
Björn Isakssonc885a242012-06-05 17:19:04 +0200529 private void resetCachedValues() {
530 updateSearchEngine(false);
531 }
532
John Reck35e9dd62011-04-25 09:01:54 -0700533 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800534 // query the profile from components autofill database 524
535 if (mAutofillHandler.mAutoFillProfile == null &&
536 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
537 WebSettings settings = null;
538 // find a valid settings object
539 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
540 while (iter.hasNext()) {
541 WeakReference<WebSettings> ref = iter.next();
542 settings = (WebSettings)ref.get();
543 if (settings != null) {
544 break;
545 }
546 }
547 if (settings != null) {
548 AutoFillProfile profile =
549 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
550 mAutofillHandler.setAutoFillProfile(profile);
551 }
552 }
John Reck35e9dd62011-04-25 09:01:54 -0700553 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800554 }
555
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800556 public String getAutoFillProfileId() {
557 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800558 }
559
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800560 public void updateAutoFillProfile(AutoFillProfile profile) {
561 syncAutoFillProfile(profile);
562 }
563
564 private void syncAutoFillProfile(AutoFillProfile profile) {
565 synchronized (mManagedSettings) {
566 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
567 while (iter.hasNext()) {
568 WeakReference<WebSettings> ref = iter.next();
569 WebSettings settings = (WebSettings)ref.get();
570 if (settings == null) {
571 iter.remove();
572 continue;
573 }
574 // update the profile only once.
575 settings.setAutoFillProfile(profile);
576 // Now we should have the guid
577 mAutofillHandler.setAutoFillProfile(profile);
578 break;
579 }
580 }
581 }
John Reck35e9dd62011-04-25 09:01:54 -0700582 public void toggleDebugSettings() {
583 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800584 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100585
John Reckb8b2af82011-05-20 15:58:33 -0700586 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800587 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700588 }
589
590 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700591 if (view == null) {
592 return;
593 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800594 if (hasDesktopUseragent(view))
595 view.setUseDesktopUserAgent(false, true);
596 else
597 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700598 }
599
John Reck7dc444b2011-06-16 17:44:29 -0700600 public static int getAdjustedMinimumFontSize(int rawValue) {
601 rawValue++; // Preference starts at 0, min font at 1
602 if (rawValue > 1) {
603 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
604 }
605 return rawValue;
606 }
607
John Reck5ba3c762011-09-14 15:00:15 -0700608 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700609 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700610 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700611 }
612
613 static int getRawTextZoom(int percent) {
614 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
615 }
616
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700617 public int getAdjustedDoubleTapZoom(int rawValue) {
618 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
619 return (int) ((rawValue + 100) * mFontSizeMult);
620 }
621
622 static int getRawDoubleTapZoom(int percent) {
623 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
624 }
625
John Reckcadae722011-07-25 11:36:17 -0700626 public SharedPreferences getPreferences() {
627 return mPrefs;
628 }
629
Victoria Lease96497832012-03-23 14:19:56 -0700630 // update connectivity-dependent options
631 public void updateConnectionType() {
632 ConnectivityManager cm = (ConnectivityManager)
633 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
634 String linkPrefetchPreference = getLinkPrefetchEnabled();
635 boolean linkPrefetchAllowed = linkPrefetchPreference.
636 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
637 NetworkInfo ni = cm.getActiveNetworkInfo();
638 if (ni != null) {
639 switch (ni.getType()) {
640 case ConnectivityManager.TYPE_WIFI:
641 case ConnectivityManager.TYPE_ETHERNET:
642 case ConnectivityManager.TYPE_BLUETOOTH:
643 linkPrefetchAllowed |= linkPrefetchPreference.
644 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
645 break;
646 case ConnectivityManager.TYPE_MOBILE:
647 case ConnectivityManager.TYPE_MOBILE_DUN:
648 case ConnectivityManager.TYPE_MOBILE_MMS:
649 case ConnectivityManager.TYPE_MOBILE_SUPL:
650 case ConnectivityManager.TYPE_WIMAX:
651 default:
652 break;
653 }
654 }
655 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
656 mLinkPrefetchAllowed = linkPrefetchAllowed;
657 syncManagedSettings();
658 }
659 }
660
luxiaol62677b02013-07-22 07:54:49 +0800661 public String getDownloadPath() {
662 return mPrefs.getString(PREF_DOWNLOAD_PATH,
663 DownloadHandler.getDefaultDownloadPath(mContext));
664 }
John Reck35e9dd62011-04-25 09:01:54 -0700665 // -----------------------------
666 // getter/setters for accessibility_preferences.xml
667 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100668
John Reck7dc444b2011-06-16 17:44:29 -0700669 @Deprecated
670 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700671 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
672 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100673 }
674
John Reck35e9dd62011-04-25 09:01:54 -0700675 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700676 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700677 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100678 }
679
John Reck92f25f82011-04-26 16:57:10 -0700680 public boolean forceEnableUserScalable() {
681 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
682 }
683
John Reck7dc444b2011-06-16 17:44:29 -0700684 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700685 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700686 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
687 return getAdjustedTextZoom(textZoom);
688 }
689
690 public void setTextZoom(int percent) {
691 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
692 }
693
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700694 public int getDoubleTapZoom() {
695 requireInitialization();
696 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
697 return getAdjustedDoubleTapZoom(doubleTapZoom);
698 }
699
700 public void setDoubleTapZoom(int percent) {
701 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
702 }
703
John Reck35e9dd62011-04-25 09:01:54 -0700704 // -----------------------------
705 // getter/setters for advanced_preferences.xml
706 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100707
John Reck35e9dd62011-04-25 09:01:54 -0700708 public String getSearchEngineName() {
Panos Thomas64c77e02014-12-17 22:15:23 -0800709 // The following is a NOP if the SEARCH_ENGINE restriction has already been created. Otherwise,
710 // it creates the restriction and if enabled it sets the <default_search_engine_value>.
711 SearchEngineRestriction.getInstance();
712
luxiaol221b3932013-07-19 15:27:57 +0800713 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
714 if (defaultSearchEngineValue == null) {
715 defaultSearchEngineValue = SearchEngine.GOOGLE;
716 }
717 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100718 }
John Reck63bb6872010-12-01 19:29:32 -0800719
Michael Kolb8d772b02012-01-19 13:56:00 -0800720 public boolean allowAppTabs() {
721 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
722 }
723
John Reck35e9dd62011-04-25 09:01:54 -0700724 public boolean openInBackground() {
725 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800726 }
John Reck35e9dd62011-04-25 09:01:54 -0700727
728 public boolean enableJavascript() {
729 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
730 }
731
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800732 public boolean enableMemoryMonitor() {
733 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
734 }
735
Tarun Nainani8eb00912014-07-17 12:28:32 -0700736
John Reck35e9dd62011-04-25 09:01:54 -0700737 public boolean loadPageInOverviewMode() {
738 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
739 }
740
741 public boolean autofitPages() {
742 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
743 }
744
745 public boolean blockPopupWindows() {
746 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
747 }
748
749 public boolean loadImages() {
750 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
751 }
752
753 public String getDefaultTextEncoding() {
Tarun Nainani88381422015-04-02 19:47:21 -0700754 return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
John Reck35e9dd62011-04-25 09:01:54 -0700755 }
756
757 // -----------------------------
758 // getter/setters for general_preferences.xml
759 // -----------------------------
760
761 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700762 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
763 }
764
765 public void setHomePage(String value) {
766 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
767 }
768
769 public boolean isAutofillEnabled() {
770 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
771 }
772
773 public void setAutofillEnabled(boolean value) {
774 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
775 }
776
777 // -----------------------------
778 // getter/setters for debug_preferences.xml
779 // -----------------------------
780
781 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700782 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700783 return true;
784 }
785 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
786 }
787
Derek Sollenberger31adf672011-07-08 11:31:30 -0400788 public boolean isSkiaHardwareAccelerated() {
789 if (!isDebugEnabled()) {
790 return false;
791 }
792 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
793 }
794
John Reck35e9dd62011-04-25 09:01:54 -0700795 // -----------------------------
796 // getter/setters for hidden_debug_preferences.xml
797 // -----------------------------
798
799 public boolean enableVisualIndicator() {
800 if (!isDebugEnabled()) {
801 return false;
802 }
803 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
804 }
805
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700806 public boolean enableCpuUploadPath() {
807 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700808 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700809 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700810 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700811 }
812
John Reck35e9dd62011-04-25 09:01:54 -0700813 public boolean isSmallScreen() {
814 if (!isDebugEnabled()) {
815 return false;
816 }
817 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
818 }
819
820 public boolean isWideViewport() {
821 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800822 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700823 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800824 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700825 }
826
827 public boolean isNormalLayout() {
828 if (!isDebugEnabled()) {
829 return false;
830 }
831 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
832 }
833
834 public boolean isTracing() {
835 if (!isDebugEnabled()) {
836 return false;
837 }
838 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
839 }
840
841 public boolean enableLightTouch() {
842 if (!isDebugEnabled()) {
843 return false;
844 }
845 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
846 }
847
848 public boolean enableNavDump() {
849 if (!isDebugEnabled()) {
850 return false;
851 }
852 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
853 }
854
855 public String getJsEngineFlags() {
856 if (!isDebugEnabled()) {
857 return "";
858 }
859 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
860 }
861
862 // -----------------------------
863 // getter/setters for lab_preferences.xml
864 // -----------------------------
865
John Reck35e9dd62011-04-25 09:01:54 -0700866 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700867 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700868 }
869
Michael Kolbc38c6042011-04-27 10:46:06 -0700870 public boolean useFullscreen() {
871 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
872 }
873
John Reck2fd9d0e2011-07-15 11:13:48 -0700874 public boolean useInvertedRendering() {
875 return mPrefs.getBoolean(PREF_INVERTED, false);
876 }
877
Nicolas Roard5d513102011-08-03 15:35:34 -0700878 public float getInvertedContrast() {
879 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
880 }
881
John Reck35e9dd62011-04-25 09:01:54 -0700882 // -----------------------------
883 // getter/setters for privacy_security_preferences.xml
884 // -----------------------------
885
886 public boolean showSecurityWarnings() {
887 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
888 }
889
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700890 public boolean doNotTrack() {
891 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
892 }
893
John Reck35e9dd62011-04-25 09:01:54 -0700894 public boolean acceptCookies() {
895 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
896 }
897
898 public boolean saveFormdata() {
899 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
900 }
901
902 public boolean enableGeolocation() {
903 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
904 }
905
906 public boolean rememberPasswords() {
907 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
908 }
909
Michael Kolb14612442011-06-24 13:06:29 -0700910 // -----------------------------
911 // getter/setters for bandwidth_preferences.xml
912 // -----------------------------
913
Mathew Inwood467813f2011-09-02 15:43:17 +0100914 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
915 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700916 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100917
918 public static String getPreloadAlwaysPreferenceString(Context context) {
919 return context.getResources().getString(R.string.pref_data_preload_value_always);
920 }
921
Mathew Inwood825fba72011-10-04 14:52:52 +0100922 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
923 "browser_default_preload_setting";
924
925 public String getDefaultPreloadSetting() {
926 String preload = Settings.Secure.getString(mContext.getContentResolver(),
927 DEAULT_PRELOAD_SECURE_SETTING_KEY);
928 if (preload == null) {
929 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
930 }
931 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100932 }
933
934 public String getPreloadEnabled() {
935 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
936 }
937
Victoria Lease96497832012-03-23 14:19:56 -0700938 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
939 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
940 }
941
942 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
943 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
944 }
945
946 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
947 "browser_default_link_prefetch_setting";
948
949 public String getDefaultLinkPrefetchSetting() {
950 String preload = Settings.Secure.getString(mContext.getContentResolver(),
951 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
952 if (preload == null) {
953 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
954 }
955 return preload;
956 }
957
958 public String getLinkPrefetchEnabled() {
959 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
960 }
961
George Mount3636d0a2011-11-21 09:08:21 -0800962 // -----------------------------
963 // getter/setters for browser recovery
964 // -----------------------------
965 /**
966 * The last time browser was started.
967 * @return The last browser start time as System.currentTimeMillis. This
968 * can be 0 if this is the first time or the last tab was closed.
969 */
970 public long getLastRecovered() {
971 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
972 }
973
974 /**
975 * Sets the last browser start time.
976 * @param time The last time as System.currentTimeMillis that the browser
977 * was started. This should be set to 0 if the last tab is closed.
978 */
979 public void setLastRecovered(long time) {
980 mPrefs.edit()
981 .putLong(KEY_LAST_RECOVERED, time)
982 .apply();
983 }
984
985 /**
986 * Used to determine whether or not the previous browser run crashed. Once
987 * the previous state has been determined, the value will be set to false
988 * until a pause is received.
989 * @return true if the last browser run was paused or false if it crashed.
990 */
991 public boolean wasLastRunPaused() {
992 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
993 }
994
995 /**
996 * Sets whether or not the last run was a pause or crash.
997 * @param isPaused Set to true When a pause is received or false after
998 * resuming.
999 */
1000 public void setLastRunPaused(boolean isPaused) {
1001 mPrefs.edit()
1002 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1003 .apply();
1004 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001005}