blob: 5bb085cb143cf8a684e0517e35e8eb6d31e33135 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.content.ContentResolver;
20import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070022import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080023import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070024import android.net.ConnectivityManager;
25import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070026import android.os.Build;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.preference.PreferenceManager;
Mathew Inwood825fba72011-10-04 14:52:52 +010028import android.provider.Settings;
Bijan Amirzadae75909d2014-05-06 14:18:54 -070029import android.text.TextUtils;
John Reck5ba3c762011-09-14 15:00:15 -070030import android.util.DisplayMetrics;
Nicolas Roard78a98e42009-05-11 13:34:17 +010031import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Bijan Amirzada41242f22014-03-21 12:12:18 -070033import com.android.browser.R;
34import com.android.browser.homepages.HomeProvider;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070035import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070036import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.search.SearchEngine;
38import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070039
John Reck35e9dd62011-04-25 09:01:54 -070040import java.lang.ref.WeakReference;
41import java.util.Iterator;
42import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070043import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080045import org.codeaurora.swe.AutoFillProfile;
46import org.codeaurora.swe.CookieManager;
47import org.codeaurora.swe.GeolocationPermissions;
48import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
49import org.codeaurora.swe.WebSettings.PluginState;
50import org.codeaurora.swe.WebSettings.TextSize;
51import org.codeaurora.swe.WebSettings.ZoomDensity;
52import org.codeaurora.swe.WebSettings;
53import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070054import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080055
John Reck35e9dd62011-04-25 09:01:54 -070056/**
57 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080058 */
John Reck35e9dd62011-04-25 09:01:54 -070059public class BrowserSettings implements OnSharedPreferenceChangeListener,
60 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010061
qqzhoue6ff8b42013-07-23 17:28:48 +080062 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070063 // The minimum min font size
64 // Aka, the lower bounds for the min font size range
65 // which is 1:5..24
66 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070067 // The initial value in the text zoom range
68 // This is what represents 100% in the SeekBarPreference range
69 private static final int TEXT_ZOOM_START_VAL = 10;
70 // The size of a single step in the text zoom range, in percent
71 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070072 // The initial value in the double tap zoom range
73 // This is what represents 100% in the SeekBarPreference range
74 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
75 // The size of a single step in the double tap zoom range, in percent
76 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070077
John Reck35e9dd62011-04-25 09:01:54 -070078 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070079
John Reck35e9dd62011-04-25 09:01:54 -070080 private Context mContext;
81 private SharedPreferences mPrefs;
82 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070084 private WebStorageSizeManager mWebStorageSizeManager;
85 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010086 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070087 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070088 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070089
Victoria Lease96497832012-03-23 14:19:56 -070090 // Current state of network-dependent settings
91 private boolean mLinkPrefetchAllowed = true;
92
John Reck78a6a1d2011-07-21 13:54:03 -070093 // Cached values
94 private int mPageCacheCapacity = 1;
95 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080096
John Reck35e9dd62011-04-25 09:01:54 -070097 // Cached settings
98 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080099
Ben Murdochaaa1f372011-07-25 15:40:58 +0100100 private static String sFactoryResetUrl;
101
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700102 private boolean mEngineInitialized = false;
103 private boolean mSyncManagedSettings = false;
104
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700105 public static synchronized void initialize(final Context context) {
106 if (sInstance == null)
107 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700108 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800109
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700110 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700111 return sInstance;
112 }
Ben Murdochef671652010-11-25 17:17:58 +0000113
John Reck35e9dd62011-04-25 09:01:54 -0700114 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100115 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700116 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700117 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700118 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700119 }
120
121 public void setController(Controller controller) {
122 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700123 mNeedsSharedSync = true;
124 }
125
126 public void onEngineInitializationComplete() {
127 mEngineInitialized = true;
128 mAutofillHandler = new AutofillHandler(mContext);
129 if (mSyncManagedSettings) {
130 syncManagedSettings();
131 }
132 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700133 syncSharedSettings();
134 }
Ben Murdochef671652010-11-25 17:17:58 +0000135 }
136
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800137 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800138
John Reckc477e712011-08-17 11:27:15 -0700139 if (mNeedsSharedSync) {
140 syncSharedSettings();
141 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800142
John Reck35e9dd62011-04-25 09:01:54 -0700143 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800144 syncStaticSettings(settings);
145 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700146 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800147 }
148 }
149
John Reckd1d87312012-03-08 13:25:00 -0800150 public void stopManagingSettings(WebSettings settings) {
151 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
152 while (iter.hasNext()) {
153 WeakReference<WebSettings> ref = iter.next();
154 if (ref.get() == settings) {
155 iter.remove();
156 return;
157 }
158 }
159 }
160
John Reckcadae722011-07-25 11:36:17 -0700161 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700162
163 @Override
164 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700165 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
166 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700167 // the cost of one cached page is ~3M (measured using nytimes.com). For
168 // low end devices, we only cache one page. For high end devices, we try
169 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800170
171 // SWE_TODO : assume a high-memory device
172 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700173 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800174 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700175 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
176 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
177 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700178 // Workaround b/5254577
179 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700180 if (Build.VERSION.CODENAME.equals("REL")) {
181 // This is a release build, always startup with debug disabled
182 setDebugEnabled(false);
183 }
184 if (mPrefs.contains(PREF_TEXT_SIZE)) {
185 /*
186 * Update from TextSize enum to zoom percent
187 * SMALLEST is 50%
188 * SMALLER is 75%
189 * NORMAL is 100%
190 * LARGER is 150%
191 * LARGEST is 200%
192 */
193 switch (getTextSize()) {
194 case SMALLEST:
195 setTextZoom(50);
196 break;
197 case SMALLER:
198 setTextZoom(75);
199 break;
200 case LARGER:
201 setTextZoom(150);
202 break;
203 case LARGEST:
204 setTextZoom(200);
205 break;
206 }
207 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
208 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100209
qqzhou8c5b0a32013-07-22 15:31:03 +0800210 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700211 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800212
kaiyizbf086ea2013-08-02 11:03:58 +0800213 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800214 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800215 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700216
Ben Murdochaaa1f372011-07-25 15:40:58 +0100217 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
218 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
219 BrowserProvider.getClientId(mContext.getContentResolver()));
220 }
221
Ben Murdochaaa1f372011-07-25 15:40:58 +0100222 synchronized (BrowserSettings.class) {
223 sInitialized = true;
224 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700225 }
226 }
227 };
228
Ben Murdochaaa1f372011-07-25 15:40:58 +0100229 private static void requireInitialization() {
230 synchronized (BrowserSettings.class) {
231 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700232 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100233 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700234 } catch (InterruptedException e) {
235 }
236 }
237 }
238 }
239
The Android Open Source Project0c908882009-03-03 19:32:16 -0800240 /**
John Reck35e9dd62011-04-25 09:01:54 -0700241 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800242 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800243 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700244 settings.setGeolocationEnabled(enableGeolocation());
245 settings.setJavaScriptEnabled(enableJavascript());
246 settings.setLightTouchEnabled(enableLightTouch());
247 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700248 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700249 settings.setMinimumFontSize(getMinimumFontSize());
250 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700251 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700252 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100253 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700254 settings.setLoadsImagesAutomatically(loadImages());
255 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
256 settings.setSavePassword(rememberPasswords());
257 settings.setSaveFormData(saveFormdata());
258 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700259 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700260 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700261
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800262 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800263 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
264 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
265 settingsClassic.setForceUserScalable(forceEnableUserScalable());
266 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
267 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800268
John Reckea17e782011-10-27 17:15:59 -0700269 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800270 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700271 useInverted ? "true" : "false");
272 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800273 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700274 Float.toString(getInvertedContrast()));
275 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700276
John Reckea17e782011-10-27 17:15:59 -0700277 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800278 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700279 enableCpuUploadPath() ? "true" : "false");
280 }
Victoria Lease96497832012-03-23 14:19:56 -0700281
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800282 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000283 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800284
Tarun Nainani8eb00912014-07-17 12:28:32 -0700285
John Reck35e9dd62011-04-25 09:01:54 -0700286 /**
287 * Syncs all the settings that have no UI
288 * These cannot change, so we only need to set them once per WebSettings
289 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800290 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700291 settings.setDefaultFontSize(16);
292 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000293
John Reck35e9dd62011-04-25 09:01:54 -0700294 // WebView inside Browser doesn't want initial focus to be set.
295 settings.setNeedInitialFocus(false);
296 // Browser supports multiple windows
297 settings.setSupportMultipleWindows(true);
298 // enable smooth transition for better performance during panning or
299 // zooming
300 settings.setEnableSmoothTransition(true);
301 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700302 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700303
304 // HTML5 API flags
305 settings.setAppCacheEnabled(true);
306 settings.setDatabaseEnabled(true);
307 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700308
309 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700310 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700311 settings.setAppCachePath(getAppCachePath());
312 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
313 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700314 // origin policy for file access
315 settings.setAllowUniversalAccessFromFileURLs(false);
316 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700317 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800318
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800319 //if (!(settings instanceof WebSettingsClassic)) return;
320 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800321
322 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
323 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
324 // WebView should be preserving the memory as much as possible.
325 // However, apps like browser wish to turn on the performance mode which
326 // would require more memory.
327 // TODO: We need to dynamically allocate/deallocate temporary memory for
328 // apps which are trying to use minimal memory. Currently, double
329 // buffering is always turned on, which is unnecessary.
330 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
331 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800332 */
John Reck35e9dd62011-04-25 09:01:54 -0700333 }
334
335 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700336 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700337 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800338
John Reck35e9dd62011-04-25 09:01:54 -0700339 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700340
John Reck35e9dd62011-04-25 09:01:54 -0700341 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700342 if (!mEngineInitialized) {
343 mSyncManagedSettings = true;
344 return;
345 }
346 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700347 syncSharedSettings();
348 synchronized (mManagedSettings) {
349 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
350 while (iter.hasNext()) {
351 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800352 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700353 if (settings == null) {
354 iter.remove();
355 continue;
356 }
357 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000358 }
John Reck35e9dd62011-04-25 09:01:54 -0700359 }
360 }
Ben Murdochef671652010-11-25 17:17:58 +0000361
John Reck35e9dd62011-04-25 09:01:54 -0700362 @Override
363 public void onSharedPreferenceChanged(
364 SharedPreferences sharedPreferences, String key) {
365 syncManagedSettings();
366 if (PREF_SEARCH_ENGINE.equals(key)) {
367 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700368 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200369 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700370 mController.getUi().setFullscreen(useFullscreen());
371 }
Victoria Lease96497832012-03-23 14:19:56 -0700372 } else if (PREF_LINK_PREFETCH.equals(key)) {
373 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700374 }
John Reck35e9dd62011-04-25 09:01:54 -0700375 }
376
John Reck961d35d2011-06-23 09:45:54 -0700377 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100378 requireInitialization();
379 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700380 }
381
382 public LayoutAlgorithm getLayoutAlgorithm() {
383 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
384 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700385 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700386 }
387 if (isDebugEnabled()) {
388 if (isSmallScreen()) {
389 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000390 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700391 if (isNormalLayout()) {
392 layoutAlgorithm = LayoutAlgorithm.NORMAL;
393 } else {
394 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
395 }
Ben Murdochef671652010-11-25 17:17:58 +0000396 }
John Reck35e9dd62011-04-25 09:01:54 -0700397 }
398 return layoutAlgorithm;
399 }
Ben Murdochef671652010-11-25 17:17:58 +0000400
John Reck35e9dd62011-04-25 09:01:54 -0700401 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700402 requireInitialization();
403 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800404 }
405
John Reck35e9dd62011-04-25 09:01:54 -0700406 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700407 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700408 return mWebStorageSizeManager;
409 }
410
John Reck35e9dd62011-04-25 09:01:54 -0700411 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700412 if (mAppCachePath == null) {
413 mAppCachePath = mContext.getDir("appcache", 0).getPath();
414 }
415 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700416 }
417
418 private void updateSearchEngine(boolean force) {
419 String searchEngineName = getSearchEngineName();
420 if (force || mSearchEngine == null ||
421 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700422 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000423 }
424 }
425
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100426 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700427 if (mSearchEngine == null) {
428 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100429 }
John Reck35e9dd62011-04-25 09:01:54 -0700430 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100431 }
432
John Reck35e9dd62011-04-25 09:01:54 -0700433 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700434 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700435 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100436 }
437
John Reck35e9dd62011-04-25 09:01:54 -0700438 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700439 Editor edit = mPrefs.edit();
440 edit.putBoolean(PREF_DEBUG_MENU, value);
441 if (!value) {
442 // Reset to "safe" value
443 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
444 }
445 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100446 }
447
John Reck35e9dd62011-04-25 09:01:54 -0700448 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700449 if (mController != null) {
450 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800451 if (current != null) {
452 current.clearCache(true);
453 }
454 }
455 }
456
John Reck35e9dd62011-04-25 09:01:54 -0700457 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 CookieManager.getInstance().removeAllCookie();
459 }
460
John Reck35e9dd62011-04-25 09:01:54 -0700461 public void clearHistory() {
462 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800463 Browser.clearHistory(resolver);
464 Browser.clearSearches(resolver);
465 }
466
John Reck35e9dd62011-04-25 09:01:54 -0700467 public void clearFormData() {
468 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700469 if (mController!= null) {
470 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100471 if (currentTopView != null) {
472 currentTopView.clearFormData();
473 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800474 }
475 }
476
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700477 public WebView getTopWebView(){
478 if (mController!= null)
479 return mController.getCurrentTopWebView();
480
481 return null;
482 }
483
John Reck35e9dd62011-04-25 09:01:54 -0700484 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700485 // Clear password store maintained by SWE engine
486 WebSettings settings = null;
487 // find a valid settings object
488 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
489 while (iter.hasNext()) {
490 WeakReference<WebSettings> ref = iter.next();
491 settings = (WebSettings)ref.get();
492 if (settings != null) {
493 break;
494 }
495 }
496 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700497 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700498 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700499
500 // Clear passwords in WebView database
501 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
502 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800503 }
504
John Reck35e9dd62011-04-25 09:01:54 -0700505 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100506 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100507 }
508
John Reck35e9dd62011-04-25 09:01:54 -0700509 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100510 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700511 if (GeolocationPermissions.isIncognitoCreated()) {
512 GeolocationPermissions.getIncognitoInstance().clearAll();
513 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100514 }
515
John Reck35e9dd62011-04-25 09:01:54 -0700516 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700517 mPrefs.edit()
518 .clear()
John Reckbd315192011-07-29 10:05:47 -0700519 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200520 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700521 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700522 }
523
Björn Isakssonc885a242012-06-05 17:19:04 +0200524 private void resetCachedValues() {
525 updateSearchEngine(false);
526 }
527
John Reck35e9dd62011-04-25 09:01:54 -0700528 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800529 // query the profile from components autofill database 524
530 if (mAutofillHandler.mAutoFillProfile == null &&
531 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
532 WebSettings settings = null;
533 // find a valid settings object
534 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
535 while (iter.hasNext()) {
536 WeakReference<WebSettings> ref = iter.next();
537 settings = (WebSettings)ref.get();
538 if (settings != null) {
539 break;
540 }
541 }
542 if (settings != null) {
543 AutoFillProfile profile =
544 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
545 mAutofillHandler.setAutoFillProfile(profile);
546 }
547 }
John Reck35e9dd62011-04-25 09:01:54 -0700548 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800549 }
550
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800551 public String getAutoFillProfileId() {
552 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800553 }
554
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800555 public void updateAutoFillProfile(AutoFillProfile profile) {
556 syncAutoFillProfile(profile);
557 }
558
559 private void syncAutoFillProfile(AutoFillProfile profile) {
560 synchronized (mManagedSettings) {
561 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
562 while (iter.hasNext()) {
563 WeakReference<WebSettings> ref = iter.next();
564 WebSettings settings = (WebSettings)ref.get();
565 if (settings == null) {
566 iter.remove();
567 continue;
568 }
569 // update the profile only once.
570 settings.setAutoFillProfile(profile);
571 // Now we should have the guid
572 mAutofillHandler.setAutoFillProfile(profile);
573 break;
574 }
575 }
576 }
John Reck35e9dd62011-04-25 09:01:54 -0700577 public void toggleDebugSettings() {
578 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800579 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100580
John Reckb8b2af82011-05-20 15:58:33 -0700581 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800582 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700583 }
584
585 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700586 if (view == null) {
587 return;
588 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800589 if (hasDesktopUseragent(view))
590 view.setUseDesktopUserAgent(false, true);
591 else
592 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700593 }
594
John Reck7dc444b2011-06-16 17:44:29 -0700595 public static int getAdjustedMinimumFontSize(int rawValue) {
596 rawValue++; // Preference starts at 0, min font at 1
597 if (rawValue > 1) {
598 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
599 }
600 return rawValue;
601 }
602
John Reck5ba3c762011-09-14 15:00:15 -0700603 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700604 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700605 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700606 }
607
608 static int getRawTextZoom(int percent) {
609 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
610 }
611
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700612 public int getAdjustedDoubleTapZoom(int rawValue) {
613 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
614 return (int) ((rawValue + 100) * mFontSizeMult);
615 }
616
617 static int getRawDoubleTapZoom(int percent) {
618 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
619 }
620
John Reckcadae722011-07-25 11:36:17 -0700621 public SharedPreferences getPreferences() {
622 return mPrefs;
623 }
624
Victoria Lease96497832012-03-23 14:19:56 -0700625 // update connectivity-dependent options
626 public void updateConnectionType() {
627 ConnectivityManager cm = (ConnectivityManager)
628 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
629 String linkPrefetchPreference = getLinkPrefetchEnabled();
630 boolean linkPrefetchAllowed = linkPrefetchPreference.
631 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
632 NetworkInfo ni = cm.getActiveNetworkInfo();
633 if (ni != null) {
634 switch (ni.getType()) {
635 case ConnectivityManager.TYPE_WIFI:
636 case ConnectivityManager.TYPE_ETHERNET:
637 case ConnectivityManager.TYPE_BLUETOOTH:
638 linkPrefetchAllowed |= linkPrefetchPreference.
639 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
640 break;
641 case ConnectivityManager.TYPE_MOBILE:
642 case ConnectivityManager.TYPE_MOBILE_DUN:
643 case ConnectivityManager.TYPE_MOBILE_MMS:
644 case ConnectivityManager.TYPE_MOBILE_SUPL:
645 case ConnectivityManager.TYPE_WIMAX:
646 default:
647 break;
648 }
649 }
650 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
651 mLinkPrefetchAllowed = linkPrefetchAllowed;
652 syncManagedSettings();
653 }
654 }
655
luxiaol62677b02013-07-22 07:54:49 +0800656 public String getDownloadPath() {
657 return mPrefs.getString(PREF_DOWNLOAD_PATH,
658 DownloadHandler.getDefaultDownloadPath(mContext));
659 }
John Reck35e9dd62011-04-25 09:01:54 -0700660 // -----------------------------
661 // getter/setters for accessibility_preferences.xml
662 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100663
John Reck7dc444b2011-06-16 17:44:29 -0700664 @Deprecated
665 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700666 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
667 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100668 }
669
John Reck35e9dd62011-04-25 09:01:54 -0700670 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700671 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700672 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100673 }
674
John Reck92f25f82011-04-26 16:57:10 -0700675 public boolean forceEnableUserScalable() {
676 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
677 }
678
John Reck7dc444b2011-06-16 17:44:29 -0700679 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700680 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700681 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
682 return getAdjustedTextZoom(textZoom);
683 }
684
685 public void setTextZoom(int percent) {
686 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
687 }
688
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700689 public int getDoubleTapZoom() {
690 requireInitialization();
691 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
692 return getAdjustedDoubleTapZoom(doubleTapZoom);
693 }
694
695 public void setDoubleTapZoom(int percent) {
696 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
697 }
698
John Reck35e9dd62011-04-25 09:01:54 -0700699 // -----------------------------
700 // getter/setters for advanced_preferences.xml
701 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100702
John Reck35e9dd62011-04-25 09:01:54 -0700703 public String getSearchEngineName() {
luxiaol221b3932013-07-19 15:27:57 +0800704 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
705 if (defaultSearchEngineValue == null) {
706 defaultSearchEngineValue = SearchEngine.GOOGLE;
707 }
708 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100709 }
John Reck63bb6872010-12-01 19:29:32 -0800710
Michael Kolb8d772b02012-01-19 13:56:00 -0800711 public boolean allowAppTabs() {
712 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
713 }
714
John Reck35e9dd62011-04-25 09:01:54 -0700715 public boolean openInBackground() {
716 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800717 }
John Reck35e9dd62011-04-25 09:01:54 -0700718
719 public boolean enableJavascript() {
720 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
721 }
722
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800723 public boolean enableMemoryMonitor() {
724 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
725 }
726
Tarun Nainani8eb00912014-07-17 12:28:32 -0700727
John Reck35e9dd62011-04-25 09:01:54 -0700728 public boolean loadPageInOverviewMode() {
729 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
730 }
731
732 public boolean autofitPages() {
733 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
734 }
735
736 public boolean blockPopupWindows() {
737 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
738 }
739
740 public boolean loadImages() {
741 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
742 }
743
744 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800745 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
746 if(autoDetect.equalsIgnoreCase("auto")) {
747 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
748 }
749 return autoDetect;
John Reck35e9dd62011-04-25 09:01:54 -0700750 }
751
752 // -----------------------------
753 // getter/setters for general_preferences.xml
754 // -----------------------------
755
756 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700757 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
758 }
759
760 public void setHomePage(String value) {
761 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
762 }
763
764 public boolean isAutofillEnabled() {
765 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
766 }
767
768 public void setAutofillEnabled(boolean value) {
769 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
770 }
771
772 // -----------------------------
773 // getter/setters for debug_preferences.xml
774 // -----------------------------
775
776 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700777 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700778 return true;
779 }
780 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
781 }
782
Derek Sollenberger31adf672011-07-08 11:31:30 -0400783 public boolean isSkiaHardwareAccelerated() {
784 if (!isDebugEnabled()) {
785 return false;
786 }
787 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
788 }
789
John Reck35e9dd62011-04-25 09:01:54 -0700790 // -----------------------------
791 // getter/setters for hidden_debug_preferences.xml
792 // -----------------------------
793
794 public boolean enableVisualIndicator() {
795 if (!isDebugEnabled()) {
796 return false;
797 }
798 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
799 }
800
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700801 public boolean enableCpuUploadPath() {
802 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700803 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700804 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700805 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700806 }
807
John Reck35e9dd62011-04-25 09:01:54 -0700808 public boolean isSmallScreen() {
809 if (!isDebugEnabled()) {
810 return false;
811 }
812 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
813 }
814
815 public boolean isWideViewport() {
816 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800817 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700818 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800819 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700820 }
821
822 public boolean isNormalLayout() {
823 if (!isDebugEnabled()) {
824 return false;
825 }
826 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
827 }
828
829 public boolean isTracing() {
830 if (!isDebugEnabled()) {
831 return false;
832 }
833 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
834 }
835
836 public boolean enableLightTouch() {
837 if (!isDebugEnabled()) {
838 return false;
839 }
840 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
841 }
842
843 public boolean enableNavDump() {
844 if (!isDebugEnabled()) {
845 return false;
846 }
847 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
848 }
849
850 public String getJsEngineFlags() {
851 if (!isDebugEnabled()) {
852 return "";
853 }
854 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
855 }
856
857 // -----------------------------
858 // getter/setters for lab_preferences.xml
859 // -----------------------------
860
John Reck35e9dd62011-04-25 09:01:54 -0700861 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700862 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700863 }
864
Michael Kolbc38c6042011-04-27 10:46:06 -0700865 public boolean useFullscreen() {
866 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
867 }
868
John Reck2fd9d0e2011-07-15 11:13:48 -0700869 public boolean useInvertedRendering() {
870 return mPrefs.getBoolean(PREF_INVERTED, false);
871 }
872
Nicolas Roard5d513102011-08-03 15:35:34 -0700873 public float getInvertedContrast() {
874 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
875 }
876
John Reck35e9dd62011-04-25 09:01:54 -0700877 // -----------------------------
878 // getter/setters for privacy_security_preferences.xml
879 // -----------------------------
880
881 public boolean showSecurityWarnings() {
882 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
883 }
884
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700885 public boolean doNotTrack() {
886 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
887 }
888
John Reck35e9dd62011-04-25 09:01:54 -0700889 public boolean acceptCookies() {
890 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
891 }
892
893 public boolean saveFormdata() {
894 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
895 }
896
897 public boolean enableGeolocation() {
898 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
899 }
900
901 public boolean rememberPasswords() {
902 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
903 }
904
Michael Kolb14612442011-06-24 13:06:29 -0700905 // -----------------------------
906 // getter/setters for bandwidth_preferences.xml
907 // -----------------------------
908
Mathew Inwood467813f2011-09-02 15:43:17 +0100909 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
910 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700911 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100912
913 public static String getPreloadAlwaysPreferenceString(Context context) {
914 return context.getResources().getString(R.string.pref_data_preload_value_always);
915 }
916
Mathew Inwood825fba72011-10-04 14:52:52 +0100917 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
918 "browser_default_preload_setting";
919
920 public String getDefaultPreloadSetting() {
921 String preload = Settings.Secure.getString(mContext.getContentResolver(),
922 DEAULT_PRELOAD_SECURE_SETTING_KEY);
923 if (preload == null) {
924 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
925 }
926 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100927 }
928
929 public String getPreloadEnabled() {
930 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
931 }
932
Victoria Lease96497832012-03-23 14:19:56 -0700933 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
934 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
935 }
936
937 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
938 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
939 }
940
941 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
942 "browser_default_link_prefetch_setting";
943
944 public String getDefaultLinkPrefetchSetting() {
945 String preload = Settings.Secure.getString(mContext.getContentResolver(),
946 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
947 if (preload == null) {
948 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
949 }
950 return preload;
951 }
952
953 public String getLinkPrefetchEnabled() {
954 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
955 }
956
George Mount3636d0a2011-11-21 09:08:21 -0800957 // -----------------------------
958 // getter/setters for browser recovery
959 // -----------------------------
960 /**
961 * The last time browser was started.
962 * @return The last browser start time as System.currentTimeMillis. This
963 * can be 0 if this is the first time or the last tab was closed.
964 */
965 public long getLastRecovered() {
966 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
967 }
968
969 /**
970 * Sets the last browser start time.
971 * @param time The last time as System.currentTimeMillis that the browser
972 * was started. This should be set to 0 if the last tab is closed.
973 */
974 public void setLastRecovered(long time) {
975 mPrefs.edit()
976 .putLong(KEY_LAST_RECOVERED, time)
977 .apply();
978 }
979
980 /**
981 * Used to determine whether or not the previous browser run crashed. Once
982 * the previous state has been determined, the value will be set to false
983 * until a pause is received.
984 * @return true if the last browser run was paused or false if it crashed.
985 */
986 public boolean wasLastRunPaused() {
987 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
988 }
989
990 /**
991 * Sets whether or not the last run was a pause or crash.
992 * @param isPaused Set to true When a pause is received or false after
993 * resuming.
994 */
995 public void setLastRunPaused(boolean isPaused) {
996 mPrefs.edit()
997 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
998 .apply();
999 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001000}