blob: b5db3af75eb45c1a5ed46594b13d77161aee3027 [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 Thomas64c77e02014-12-17 22:15:23 -080035import com.android.browser.mdm.SearchEngineRestriction;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070036import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070038import com.android.browser.search.SearchEngine;
39import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070040
John Reck35e9dd62011-04-25 09:01:54 -070041import java.lang.ref.WeakReference;
42import java.util.Iterator;
43import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070044import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080045
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080046import org.codeaurora.swe.AutoFillProfile;
47import org.codeaurora.swe.CookieManager;
48import org.codeaurora.swe.GeolocationPermissions;
49import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
50import org.codeaurora.swe.WebSettings.PluginState;
51import org.codeaurora.swe.WebSettings.TextSize;
52import org.codeaurora.swe.WebSettings.ZoomDensity;
53import org.codeaurora.swe.WebSettings;
54import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070055import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080056
John Reck35e9dd62011-04-25 09:01:54 -070057/**
58 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080059 */
John Reck35e9dd62011-04-25 09:01:54 -070060public class BrowserSettings implements OnSharedPreferenceChangeListener,
61 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010062
qqzhoue6ff8b42013-07-23 17:28:48 +080063 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070064 // The minimum min font size
65 // Aka, the lower bounds for the min font size range
66 // which is 1:5..24
67 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070068 // The initial value in the text zoom range
69 // This is what represents 100% in the SeekBarPreference range
70 private static final int TEXT_ZOOM_START_VAL = 10;
71 // The size of a single step in the text zoom range, in percent
72 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070073 // The initial value in the double tap zoom range
74 // This is what represents 100% in the SeekBarPreference range
75 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
76 // The size of a single step in the double tap zoom range, in percent
77 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070078
John Reck35e9dd62011-04-25 09:01:54 -070079 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070080
John Reck35e9dd62011-04-25 09:01:54 -070081 private Context mContext;
82 private SharedPreferences mPrefs;
83 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070084 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070085 private WebStorageSizeManager mWebStorageSizeManager;
86 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010087 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070088 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070089 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070090
Victoria Lease96497832012-03-23 14:19:56 -070091 // Current state of network-dependent settings
92 private boolean mLinkPrefetchAllowed = true;
93
John Reck78a6a1d2011-07-21 13:54:03 -070094 // Cached values
95 private int mPageCacheCapacity = 1;
96 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080097
John Reck35e9dd62011-04-25 09:01:54 -070098 // Cached settings
99 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
Ben Murdochaaa1f372011-07-25 15:40:58 +0100101 private static String sFactoryResetUrl;
102
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700103 private boolean mEngineInitialized = false;
104 private boolean mSyncManagedSettings = false;
105
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700106 public static synchronized void initialize(final Context context) {
107 if (sInstance == null)
108 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700109 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800110
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700111 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700112 return sInstance;
113 }
Ben Murdochef671652010-11-25 17:17:58 +0000114
John Reck35e9dd62011-04-25 09:01:54 -0700115 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100116 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700117 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700118 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700119 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700120 }
121
122 public void setController(Controller controller) {
123 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700124 mNeedsSharedSync = true;
125 }
126
127 public void onEngineInitializationComplete() {
128 mEngineInitialized = true;
129 mAutofillHandler = new AutofillHandler(mContext);
130 if (mSyncManagedSettings) {
131 syncManagedSettings();
132 }
133 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700134 syncSharedSettings();
135 }
Ben Murdochef671652010-11-25 17:17:58 +0000136 }
137
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800138 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800139
John Reckc477e712011-08-17 11:27:15 -0700140 if (mNeedsSharedSync) {
141 syncSharedSettings();
142 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800143
John Reck35e9dd62011-04-25 09:01:54 -0700144 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800145 syncStaticSettings(settings);
146 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700147 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800148 }
149 }
150
John Reckd1d87312012-03-08 13:25:00 -0800151 public void stopManagingSettings(WebSettings settings) {
152 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
153 while (iter.hasNext()) {
154 WeakReference<WebSettings> ref = iter.next();
155 if (ref.get() == settings) {
156 iter.remove();
157 return;
158 }
159 }
160 }
161
John Reckcadae722011-07-25 11:36:17 -0700162 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700163
164 @Override
165 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700166 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
167 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700168 // the cost of one cached page is ~3M (measured using nytimes.com). For
169 // low end devices, we only cache one page. For high end devices, we try
170 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800171
172 // SWE_TODO : assume a high-memory device
173 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700174 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800175 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700176 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
177 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
178 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700179 // Workaround b/5254577
180 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700181 if (Build.VERSION.CODENAME.equals("REL")) {
182 // This is a release build, always startup with debug disabled
183 setDebugEnabled(false);
184 }
185 if (mPrefs.contains(PREF_TEXT_SIZE)) {
186 /*
187 * Update from TextSize enum to zoom percent
188 * SMALLEST is 50%
189 * SMALLER is 75%
190 * NORMAL is 100%
191 * LARGER is 150%
192 * LARGEST is 200%
193 */
194 switch (getTextSize()) {
195 case SMALLEST:
196 setTextZoom(50);
197 break;
198 case SMALLER:
199 setTextZoom(75);
200 break;
201 case LARGER:
202 setTextZoom(150);
203 break;
204 case LARGEST:
205 setTextZoom(200);
206 break;
207 }
208 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
209 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100210
qqzhou8c5b0a32013-07-22 15:31:03 +0800211 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700212 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800213
kaiyizbf086ea2013-08-02 11:03:58 +0800214 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800215 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800216 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700217
Ben Murdochaaa1f372011-07-25 15:40:58 +0100218 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
219 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
220 BrowserProvider.getClientId(mContext.getContentResolver()));
221 }
222
Ben Murdochaaa1f372011-07-25 15:40:58 +0100223 synchronized (BrowserSettings.class) {
224 sInitialized = true;
225 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700226 }
227 }
228 };
229
Ben Murdochaaa1f372011-07-25 15:40:58 +0100230 private static void requireInitialization() {
231 synchronized (BrowserSettings.class) {
232 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700233 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100234 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700235 } catch (InterruptedException e) {
236 }
237 }
238 }
239 }
240
The Android Open Source Project0c908882009-03-03 19:32:16 -0800241 /**
John Reck35e9dd62011-04-25 09:01:54 -0700242 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800243 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800244 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700245 settings.setGeolocationEnabled(enableGeolocation());
246 settings.setJavaScriptEnabled(enableJavascript());
247 settings.setLightTouchEnabled(enableLightTouch());
248 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700249 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700250 settings.setMinimumFontSize(getMinimumFontSize());
251 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700252 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700253 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100254 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700255 settings.setLoadsImagesAutomatically(loadImages());
256 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
257 settings.setSavePassword(rememberPasswords());
258 settings.setSaveFormData(saveFormdata());
259 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700260 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700261 settings.setMediaPlaybackRequiresUserGesture(false);
John Reck2fd9d0e2011-07-15 11:13:48 -0700262
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800263 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800264 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
265 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
266 settingsClassic.setForceUserScalable(forceEnableUserScalable());
267 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
268 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800269
John Reckea17e782011-10-27 17:15:59 -0700270 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800271 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700272 useInverted ? "true" : "false");
273 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800274 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700275 Float.toString(getInvertedContrast()));
276 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700277
John Reckea17e782011-10-27 17:15:59 -0700278 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800279 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700280 enableCpuUploadPath() ? "true" : "false");
281 }
Victoria Lease96497832012-03-23 14:19:56 -0700282
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800283 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000284 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800285
Tarun Nainani8eb00912014-07-17 12:28:32 -0700286
John Reck35e9dd62011-04-25 09:01:54 -0700287 /**
288 * Syncs all the settings that have no UI
289 * These cannot change, so we only need to set them once per WebSettings
290 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800291 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700292 settings.setDefaultFontSize(16);
293 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000294
John Reck35e9dd62011-04-25 09:01:54 -0700295 // WebView inside Browser doesn't want initial focus to be set.
296 settings.setNeedInitialFocus(false);
297 // Browser supports multiple windows
298 settings.setSupportMultipleWindows(true);
299 // enable smooth transition for better performance during panning or
300 // zooming
301 settings.setEnableSmoothTransition(true);
302 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700303 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700304
305 // HTML5 API flags
306 settings.setAppCacheEnabled(true);
307 settings.setDatabaseEnabled(true);
308 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700309
310 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700311 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700312 settings.setAppCachePath(getAppCachePath());
313 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
314 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700315 // origin policy for file access
316 settings.setAllowUniversalAccessFromFileURLs(false);
317 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700318 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800319
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800320 //if (!(settings instanceof WebSettingsClassic)) return;
321 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800322
323 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
324 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
325 // WebView should be preserving the memory as much as possible.
326 // However, apps like browser wish to turn on the performance mode which
327 // would require more memory.
328 // TODO: We need to dynamically allocate/deallocate temporary memory for
329 // apps which are trying to use minimal memory. Currently, double
330 // buffering is always turned on, which is unnecessary.
331 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
332 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800333 */
John Reck35e9dd62011-04-25 09:01:54 -0700334 }
335
336 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700337 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700338 CookieManager.getInstance().setAcceptCookie(acceptCookies());
Vivek Sekhared791da2015-02-22 12:39:05 -0800339
John Reck35e9dd62011-04-25 09:01:54 -0700340 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700341
John Reck35e9dd62011-04-25 09:01:54 -0700342 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700343 if (!mEngineInitialized) {
344 mSyncManagedSettings = true;
345 return;
346 }
347 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700348 syncSharedSettings();
349 synchronized (mManagedSettings) {
350 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
351 while (iter.hasNext()) {
352 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800353 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700354 if (settings == null) {
355 iter.remove();
356 continue;
357 }
358 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000359 }
John Reck35e9dd62011-04-25 09:01:54 -0700360 }
361 }
Ben Murdochef671652010-11-25 17:17:58 +0000362
John Reck35e9dd62011-04-25 09:01:54 -0700363 @Override
364 public void onSharedPreferenceChanged(
365 SharedPreferences sharedPreferences, String key) {
366 syncManagedSettings();
367 if (PREF_SEARCH_ENGINE.equals(key)) {
368 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700369 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200370 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700371 mController.getUi().setFullscreen(useFullscreen());
372 }
Victoria Lease96497832012-03-23 14:19:56 -0700373 } else if (PREF_LINK_PREFETCH.equals(key)) {
374 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700375 }
John Reck35e9dd62011-04-25 09:01:54 -0700376 }
377
John Reck961d35d2011-06-23 09:45:54 -0700378 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100379 requireInitialization();
380 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700381 }
382
383 public LayoutAlgorithm getLayoutAlgorithm() {
384 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
385 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700386 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700387 }
388 if (isDebugEnabled()) {
389 if (isSmallScreen()) {
390 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000391 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700392 if (isNormalLayout()) {
393 layoutAlgorithm = LayoutAlgorithm.NORMAL;
394 } else {
395 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
396 }
Ben Murdochef671652010-11-25 17:17:58 +0000397 }
John Reck35e9dd62011-04-25 09:01:54 -0700398 }
399 return layoutAlgorithm;
400 }
Ben Murdochef671652010-11-25 17:17:58 +0000401
John Reck35e9dd62011-04-25 09:01:54 -0700402 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700403 requireInitialization();
404 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800405 }
406
John Reck35e9dd62011-04-25 09:01:54 -0700407 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700408 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700409 return mWebStorageSizeManager;
410 }
411
John Reck35e9dd62011-04-25 09:01:54 -0700412 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700413 if (mAppCachePath == null) {
414 mAppCachePath = mContext.getDir("appcache", 0).getPath();
415 }
416 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700417 }
418
419 private void updateSearchEngine(boolean force) {
420 String searchEngineName = getSearchEngineName();
421 if (force || mSearchEngine == null ||
422 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700423 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000424 }
425 }
426
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100427 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700428 if (mSearchEngine == null) {
429 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100430 }
John Reck35e9dd62011-04-25 09:01:54 -0700431 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100432 }
433
John Reck35e9dd62011-04-25 09:01:54 -0700434 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700435 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700436 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100437 }
438
John Reck35e9dd62011-04-25 09:01:54 -0700439 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700440 Editor edit = mPrefs.edit();
441 edit.putBoolean(PREF_DEBUG_MENU, value);
442 if (!value) {
443 // Reset to "safe" value
444 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
445 }
446 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100447 }
448
John Reck35e9dd62011-04-25 09:01:54 -0700449 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700450 if (mController != null) {
451 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800452 if (current != null) {
453 current.clearCache(true);
454 }
455 }
456 }
457
John Reck35e9dd62011-04-25 09:01:54 -0700458 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459 CookieManager.getInstance().removeAllCookie();
460 }
461
John Reck35e9dd62011-04-25 09:01:54 -0700462 public void clearHistory() {
463 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800464 Browser.clearHistory(resolver);
465 Browser.clearSearches(resolver);
466 }
467
John Reck35e9dd62011-04-25 09:01:54 -0700468 public void clearFormData() {
469 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700470 if (mController!= null) {
471 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100472 if (currentTopView != null) {
473 currentTopView.clearFormData();
474 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800475 }
476 }
477
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700478 public WebView getTopWebView(){
479 if (mController!= null)
480 return mController.getCurrentTopWebView();
481
482 return null;
483 }
484
John Reck35e9dd62011-04-25 09:01:54 -0700485 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700486 // Clear password store maintained by SWE engine
487 WebSettings settings = null;
488 // find a valid settings object
489 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
490 while (iter.hasNext()) {
491 WeakReference<WebSettings> ref = iter.next();
492 settings = (WebSettings)ref.get();
493 if (settings != null) {
494 break;
495 }
496 }
497 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700498 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700499 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700500
501 // Clear passwords in WebView database
502 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
503 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800504 }
505
John Reck35e9dd62011-04-25 09:01:54 -0700506 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100507 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100508 }
509
John Reck35e9dd62011-04-25 09:01:54 -0700510 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100511 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700512 if (GeolocationPermissions.isIncognitoCreated()) {
513 GeolocationPermissions.getIncognitoInstance().clearAll();
514 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100515 }
516
John Reck35e9dd62011-04-25 09:01:54 -0700517 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700518 mPrefs.edit()
519 .clear()
John Reckbd315192011-07-29 10:05:47 -0700520 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200521 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700522 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700523 }
524
Björn Isakssonc885a242012-06-05 17:19:04 +0200525 private void resetCachedValues() {
526 updateSearchEngine(false);
527 }
528
John Reck35e9dd62011-04-25 09:01:54 -0700529 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800530 // query the profile from components autofill database 524
531 if (mAutofillHandler.mAutoFillProfile == null &&
532 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
533 WebSettings settings = null;
534 // find a valid settings object
535 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
536 while (iter.hasNext()) {
537 WeakReference<WebSettings> ref = iter.next();
538 settings = (WebSettings)ref.get();
539 if (settings != null) {
540 break;
541 }
542 }
543 if (settings != null) {
544 AutoFillProfile profile =
545 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
546 mAutofillHandler.setAutoFillProfile(profile);
547 }
548 }
John Reck35e9dd62011-04-25 09:01:54 -0700549 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800550 }
551
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800552 public String getAutoFillProfileId() {
553 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800554 }
555
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800556 public void updateAutoFillProfile(AutoFillProfile profile) {
557 syncAutoFillProfile(profile);
558 }
559
560 private void syncAutoFillProfile(AutoFillProfile profile) {
561 synchronized (mManagedSettings) {
562 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
563 while (iter.hasNext()) {
564 WeakReference<WebSettings> ref = iter.next();
565 WebSettings settings = (WebSettings)ref.get();
566 if (settings == null) {
567 iter.remove();
568 continue;
569 }
570 // update the profile only once.
571 settings.setAutoFillProfile(profile);
572 // Now we should have the guid
573 mAutofillHandler.setAutoFillProfile(profile);
574 break;
575 }
576 }
577 }
John Reck35e9dd62011-04-25 09:01:54 -0700578 public void toggleDebugSettings() {
579 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800580 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100581
John Reckb8b2af82011-05-20 15:58:33 -0700582 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800583 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700584 }
585
586 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700587 if (view == null) {
588 return;
589 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800590 if (hasDesktopUseragent(view))
591 view.setUseDesktopUserAgent(false, true);
592 else
593 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700594 }
595
John Reck7dc444b2011-06-16 17:44:29 -0700596 public static int getAdjustedMinimumFontSize(int rawValue) {
597 rawValue++; // Preference starts at 0, min font at 1
598 if (rawValue > 1) {
599 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
600 }
601 return rawValue;
602 }
603
John Reck5ba3c762011-09-14 15:00:15 -0700604 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700605 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700606 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700607 }
608
609 static int getRawTextZoom(int percent) {
610 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
611 }
612
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700613 public int getAdjustedDoubleTapZoom(int rawValue) {
614 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
615 return (int) ((rawValue + 100) * mFontSizeMult);
616 }
617
618 static int getRawDoubleTapZoom(int percent) {
619 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
620 }
621
John Reckcadae722011-07-25 11:36:17 -0700622 public SharedPreferences getPreferences() {
623 return mPrefs;
624 }
625
Victoria Lease96497832012-03-23 14:19:56 -0700626 // update connectivity-dependent options
627 public void updateConnectionType() {
628 ConnectivityManager cm = (ConnectivityManager)
629 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
630 String linkPrefetchPreference = getLinkPrefetchEnabled();
631 boolean linkPrefetchAllowed = linkPrefetchPreference.
632 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
633 NetworkInfo ni = cm.getActiveNetworkInfo();
634 if (ni != null) {
635 switch (ni.getType()) {
636 case ConnectivityManager.TYPE_WIFI:
637 case ConnectivityManager.TYPE_ETHERNET:
638 case ConnectivityManager.TYPE_BLUETOOTH:
639 linkPrefetchAllowed |= linkPrefetchPreference.
640 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
641 break;
642 case ConnectivityManager.TYPE_MOBILE:
643 case ConnectivityManager.TYPE_MOBILE_DUN:
644 case ConnectivityManager.TYPE_MOBILE_MMS:
645 case ConnectivityManager.TYPE_MOBILE_SUPL:
646 case ConnectivityManager.TYPE_WIMAX:
647 default:
648 break;
649 }
650 }
651 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
652 mLinkPrefetchAllowed = linkPrefetchAllowed;
653 syncManagedSettings();
654 }
655 }
656
luxiaol62677b02013-07-22 07:54:49 +0800657 public String getDownloadPath() {
658 return mPrefs.getString(PREF_DOWNLOAD_PATH,
659 DownloadHandler.getDefaultDownloadPath(mContext));
660 }
John Reck35e9dd62011-04-25 09:01:54 -0700661 // -----------------------------
662 // getter/setters for accessibility_preferences.xml
663 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100664
John Reck7dc444b2011-06-16 17:44:29 -0700665 @Deprecated
666 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700667 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
668 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100669 }
670
John Reck35e9dd62011-04-25 09:01:54 -0700671 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700672 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700673 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100674 }
675
John Reck92f25f82011-04-26 16:57:10 -0700676 public boolean forceEnableUserScalable() {
677 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
678 }
679
John Reck7dc444b2011-06-16 17:44:29 -0700680 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700681 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700682 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
683 return getAdjustedTextZoom(textZoom);
684 }
685
686 public void setTextZoom(int percent) {
687 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
688 }
689
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700690 public int getDoubleTapZoom() {
691 requireInitialization();
692 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
693 return getAdjustedDoubleTapZoom(doubleTapZoom);
694 }
695
696 public void setDoubleTapZoom(int percent) {
697 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
698 }
699
John Reck35e9dd62011-04-25 09:01:54 -0700700 // -----------------------------
701 // getter/setters for advanced_preferences.xml
702 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100703
John Reck35e9dd62011-04-25 09:01:54 -0700704 public String getSearchEngineName() {
Panos Thomas64c77e02014-12-17 22:15:23 -0800705 // The following is a NOP if the SEARCH_ENGINE restriction has already been created. Otherwise,
706 // it creates the restriction and if enabled it sets the <default_search_engine_value>.
707 SearchEngineRestriction.getInstance();
708
luxiaol221b3932013-07-19 15:27:57 +0800709 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
710 if (defaultSearchEngineValue == null) {
711 defaultSearchEngineValue = SearchEngine.GOOGLE;
712 }
713 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100714 }
John Reck63bb6872010-12-01 19:29:32 -0800715
Michael Kolb8d772b02012-01-19 13:56:00 -0800716 public boolean allowAppTabs() {
717 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
718 }
719
John Reck35e9dd62011-04-25 09:01:54 -0700720 public boolean openInBackground() {
721 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800722 }
John Reck35e9dd62011-04-25 09:01:54 -0700723
724 public boolean enableJavascript() {
725 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
726 }
727
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800728 public boolean enableMemoryMonitor() {
729 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
730 }
731
Tarun Nainani8eb00912014-07-17 12:28:32 -0700732
John Reck35e9dd62011-04-25 09:01:54 -0700733 public boolean loadPageInOverviewMode() {
734 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
735 }
736
737 public boolean autofitPages() {
738 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
739 }
740
741 public boolean blockPopupWindows() {
742 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
743 }
744
745 public boolean loadImages() {
746 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
747 }
748
749 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800750 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
751 if(autoDetect.equalsIgnoreCase("auto")) {
752 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
753 }
754 return autoDetect;
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}