blob: 81af49d65862ae8f11dbd5f2c25c51534bfb4007 [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());
249 settings.setDefaultZoom(getDefaultZoom());
250 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);
262 settings.setAllowMediaDownloads(allowMediaDownloads());
263 setExtraHTTPRequestHeaders(settings);
John Reck2fd9d0e2011-07-15 11:13:48 -0700264
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800265 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800266 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
267 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
268 settingsClassic.setForceUserScalable(forceEnableUserScalable());
269 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
270 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800271
John Reckea17e782011-10-27 17:15:59 -0700272 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800273 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700274 useInverted ? "true" : "false");
275 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800276 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700277 Float.toString(getInvertedContrast()));
278 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700279
John Reckea17e782011-10-27 17:15:59 -0700280 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800281 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700282 enableCpuUploadPath() ? "true" : "false");
283 }
Victoria Lease96497832012-03-23 14:19:56 -0700284
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800285 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000286 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800287
Tarun Nainani8eb00912014-07-17 12:28:32 -0700288 private void setExtraHTTPRequestHeaders(WebSettings settings){
289 String headers = mContext.getResources().getString(R.string.def_extra_http_headers);
290 if (!TextUtils.isEmpty(headers)){
291 settings.setHTTPRequestHeaders(headers);
292 }
293 }
294
John Reck35e9dd62011-04-25 09:01:54 -0700295 /**
296 * Syncs all the settings that have no UI
297 * These cannot change, so we only need to set them once per WebSettings
298 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800299 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700300 settings.setDefaultFontSize(16);
301 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000302
John Reck35e9dd62011-04-25 09:01:54 -0700303 // WebView inside Browser doesn't want initial focus to be set.
304 settings.setNeedInitialFocus(false);
305 // Browser supports multiple windows
306 settings.setSupportMultipleWindows(true);
307 // enable smooth transition for better performance during panning or
308 // zooming
309 settings.setEnableSmoothTransition(true);
310 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700311 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700312
313 // HTML5 API flags
314 settings.setAppCacheEnabled(true);
315 settings.setDatabaseEnabled(true);
316 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700317
318 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700319 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700320 settings.setAppCachePath(getAppCachePath());
321 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
322 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700323 // origin policy for file access
324 settings.setAllowUniversalAccessFromFileURLs(false);
325 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700326 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800327
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800328 //if (!(settings instanceof WebSettingsClassic)) return;
329 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800330
331 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
332 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
333 // WebView should be preserving the memory as much as possible.
334 // However, apps like browser wish to turn on the performance mode which
335 // would require more memory.
336 // TODO: We need to dynamically allocate/deallocate temporary memory for
337 // apps which are trying to use minimal memory. Currently, double
338 // buffering is always turned on, which is unnecessary.
339 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
340 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800341 */
John Reck35e9dd62011-04-25 09:01:54 -0700342 }
343
344 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700345 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700346 CookieManager.getInstance().setAcceptCookie(acceptCookies());
John Reck35e9dd62011-04-25 09:01:54 -0700347 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700348
John Reck35e9dd62011-04-25 09:01:54 -0700349 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700350 if (!mEngineInitialized) {
351 mSyncManagedSettings = true;
352 return;
353 }
354 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700355 syncSharedSettings();
356 synchronized (mManagedSettings) {
357 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
358 while (iter.hasNext()) {
359 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800360 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700361 if (settings == null) {
362 iter.remove();
363 continue;
364 }
365 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000366 }
John Reck35e9dd62011-04-25 09:01:54 -0700367 }
368 }
Ben Murdochef671652010-11-25 17:17:58 +0000369
John Reck35e9dd62011-04-25 09:01:54 -0700370 @Override
371 public void onSharedPreferenceChanged(
372 SharedPreferences sharedPreferences, String key) {
373 syncManagedSettings();
374 if (PREF_SEARCH_ENGINE.equals(key)) {
375 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700376 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200377 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700378 mController.getUi().setFullscreen(useFullscreen());
379 }
Victoria Lease96497832012-03-23 14:19:56 -0700380 } else if (PREF_LINK_PREFETCH.equals(key)) {
381 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700382 }
John Reck35e9dd62011-04-25 09:01:54 -0700383 }
384
John Reck961d35d2011-06-23 09:45:54 -0700385 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100386 requireInitialization();
387 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700388 }
389
390 public LayoutAlgorithm getLayoutAlgorithm() {
391 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
392 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700393 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700394 }
395 if (isDebugEnabled()) {
396 if (isSmallScreen()) {
397 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000398 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700399 if (isNormalLayout()) {
400 layoutAlgorithm = LayoutAlgorithm.NORMAL;
401 } else {
402 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
403 }
Ben Murdochef671652010-11-25 17:17:58 +0000404 }
John Reck35e9dd62011-04-25 09:01:54 -0700405 }
406 return layoutAlgorithm;
407 }
Ben Murdochef671652010-11-25 17:17:58 +0000408
John Reck35e9dd62011-04-25 09:01:54 -0700409 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700410 requireInitialization();
411 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800412 }
413
John Reck35e9dd62011-04-25 09:01:54 -0700414 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700415 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700416 return mWebStorageSizeManager;
417 }
418
John Reck35e9dd62011-04-25 09:01:54 -0700419 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700420 if (mAppCachePath == null) {
421 mAppCachePath = mContext.getDir("appcache", 0).getPath();
422 }
423 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700424 }
425
426 private void updateSearchEngine(boolean force) {
427 String searchEngineName = getSearchEngineName();
428 if (force || mSearchEngine == null ||
429 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700430 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000431 }
432 }
433
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100434 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700435 if (mSearchEngine == null) {
436 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100437 }
John Reck35e9dd62011-04-25 09:01:54 -0700438 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100439 }
440
John Reck35e9dd62011-04-25 09:01:54 -0700441 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700442 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700443 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100444 }
445
John Reck35e9dd62011-04-25 09:01:54 -0700446 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700447 Editor edit = mPrefs.edit();
448 edit.putBoolean(PREF_DEBUG_MENU, value);
449 if (!value) {
450 // Reset to "safe" value
451 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
452 }
453 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100454 }
455
John Reck35e9dd62011-04-25 09:01:54 -0700456 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700457 if (mController != null) {
458 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459 if (current != null) {
460 current.clearCache(true);
461 }
462 }
463 }
464
John Reck35e9dd62011-04-25 09:01:54 -0700465 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800466 CookieManager.getInstance().removeAllCookie();
467 }
468
John Reck35e9dd62011-04-25 09:01:54 -0700469 public void clearHistory() {
470 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800471 Browser.clearHistory(resolver);
472 Browser.clearSearches(resolver);
473 }
474
John Reck35e9dd62011-04-25 09:01:54 -0700475 public void clearFormData() {
476 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700477 if (mController!= null) {
478 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100479 if (currentTopView != null) {
480 currentTopView.clearFormData();
481 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800482 }
483 }
484
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700485 public WebView getTopWebView(){
486 if (mController!= null)
487 return mController.getCurrentTopWebView();
488
489 return null;
490 }
491
John Reck35e9dd62011-04-25 09:01:54 -0700492 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700493 // Clear password store maintained by SWE engine
494 WebSettings settings = null;
495 // find a valid settings object
496 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
497 while (iter.hasNext()) {
498 WeakReference<WebSettings> ref = iter.next();
499 settings = (WebSettings)ref.get();
500 if (settings != null) {
501 break;
502 }
503 }
504 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700505 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700506 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700507
508 // Clear passwords in WebView database
509 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
510 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800511 }
512
John Reck35e9dd62011-04-25 09:01:54 -0700513 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100514 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100515 }
516
John Reck35e9dd62011-04-25 09:01:54 -0700517 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100518 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100519 }
520
John Reck35e9dd62011-04-25 09:01:54 -0700521 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700522 mPrefs.edit()
523 .clear()
John Reckbd315192011-07-29 10:05:47 -0700524 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200525 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700526 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700527 }
528
Björn Isakssonc885a242012-06-05 17:19:04 +0200529 private void resetCachedValues() {
530 updateSearchEngine(false);
531 }
532
John Reck35e9dd62011-04-25 09:01:54 -0700533 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800534 // query the profile from components autofill database 524
535 if (mAutofillHandler.mAutoFillProfile == null &&
536 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
537 WebSettings settings = null;
538 // find a valid settings object
539 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
540 while (iter.hasNext()) {
541 WeakReference<WebSettings> ref = iter.next();
542 settings = (WebSettings)ref.get();
543 if (settings != null) {
544 break;
545 }
546 }
547 if (settings != null) {
548 AutoFillProfile profile =
549 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
550 mAutofillHandler.setAutoFillProfile(profile);
551 }
552 }
John Reck35e9dd62011-04-25 09:01:54 -0700553 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800554 }
555
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800556 public String getAutoFillProfileId() {
557 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800558 }
559
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800560 public void updateAutoFillProfile(AutoFillProfile profile) {
561 syncAutoFillProfile(profile);
562 }
563
564 private void syncAutoFillProfile(AutoFillProfile profile) {
565 synchronized (mManagedSettings) {
566 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
567 while (iter.hasNext()) {
568 WeakReference<WebSettings> ref = iter.next();
569 WebSettings settings = (WebSettings)ref.get();
570 if (settings == null) {
571 iter.remove();
572 continue;
573 }
574 // update the profile only once.
575 settings.setAutoFillProfile(profile);
576 // Now we should have the guid
577 mAutofillHandler.setAutoFillProfile(profile);
578 break;
579 }
580 }
581 }
John Reck35e9dd62011-04-25 09:01:54 -0700582 public void toggleDebugSettings() {
583 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800584 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100585
John Reckb8b2af82011-05-20 15:58:33 -0700586 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800587 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700588 }
589
590 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700591 if (view == null) {
592 return;
593 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800594 if (hasDesktopUseragent(view))
595 view.setUseDesktopUserAgent(false, true);
596 else
597 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700598 }
599
John Reck7dc444b2011-06-16 17:44:29 -0700600 public static int getAdjustedMinimumFontSize(int rawValue) {
601 rawValue++; // Preference starts at 0, min font at 1
602 if (rawValue > 1) {
603 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
604 }
605 return rawValue;
606 }
607
John Reck5ba3c762011-09-14 15:00:15 -0700608 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700609 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700610 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700611 }
612
613 static int getRawTextZoom(int percent) {
614 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
615 }
616
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700617 public int getAdjustedDoubleTapZoom(int rawValue) {
618 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
619 return (int) ((rawValue + 100) * mFontSizeMult);
620 }
621
622 static int getRawDoubleTapZoom(int percent) {
623 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
624 }
625
John Reckcadae722011-07-25 11:36:17 -0700626 public SharedPreferences getPreferences() {
627 return mPrefs;
628 }
629
Victoria Lease96497832012-03-23 14:19:56 -0700630 // update connectivity-dependent options
631 public void updateConnectionType() {
632 ConnectivityManager cm = (ConnectivityManager)
633 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
634 String linkPrefetchPreference = getLinkPrefetchEnabled();
635 boolean linkPrefetchAllowed = linkPrefetchPreference.
636 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
637 NetworkInfo ni = cm.getActiveNetworkInfo();
638 if (ni != null) {
639 switch (ni.getType()) {
640 case ConnectivityManager.TYPE_WIFI:
641 case ConnectivityManager.TYPE_ETHERNET:
642 case ConnectivityManager.TYPE_BLUETOOTH:
643 linkPrefetchAllowed |= linkPrefetchPreference.
644 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
645 break;
646 case ConnectivityManager.TYPE_MOBILE:
647 case ConnectivityManager.TYPE_MOBILE_DUN:
648 case ConnectivityManager.TYPE_MOBILE_MMS:
649 case ConnectivityManager.TYPE_MOBILE_SUPL:
650 case ConnectivityManager.TYPE_WIMAX:
651 default:
652 break;
653 }
654 }
655 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
656 mLinkPrefetchAllowed = linkPrefetchAllowed;
657 syncManagedSettings();
658 }
659 }
660
luxiaol62677b02013-07-22 07:54:49 +0800661 public String getDownloadPath() {
662 return mPrefs.getString(PREF_DOWNLOAD_PATH,
663 DownloadHandler.getDefaultDownloadPath(mContext));
664 }
John Reck35e9dd62011-04-25 09:01:54 -0700665 // -----------------------------
666 // getter/setters for accessibility_preferences.xml
667 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100668
John Reck7dc444b2011-06-16 17:44:29 -0700669 @Deprecated
670 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700671 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
672 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100673 }
674
John Reck35e9dd62011-04-25 09:01:54 -0700675 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700676 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700677 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100678 }
679
John Reck92f25f82011-04-26 16:57:10 -0700680 public boolean forceEnableUserScalable() {
681 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
682 }
683
John Reck7dc444b2011-06-16 17:44:29 -0700684 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700685 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700686 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
687 return getAdjustedTextZoom(textZoom);
688 }
689
690 public void setTextZoom(int percent) {
691 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
692 }
693
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700694 public int getDoubleTapZoom() {
695 requireInitialization();
696 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
697 return getAdjustedDoubleTapZoom(doubleTapZoom);
698 }
699
700 public void setDoubleTapZoom(int percent) {
701 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
702 }
703
John Reck35e9dd62011-04-25 09:01:54 -0700704 // -----------------------------
705 // getter/setters for advanced_preferences.xml
706 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100707
John Reck35e9dd62011-04-25 09:01:54 -0700708 public String getSearchEngineName() {
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 public boolean allowMediaDownloads() {
Panos Thomas4bdb5252014-11-13 16:20:11 -0800733 // Return false if preference is not exposed to user
734 if (!BrowserConfig.getInstance(mContext)
735 .hasFeature(BrowserConfig.Feature.ALLOW_MEDIA_DOWNLOADS))
736 return false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700737
Panos Thomas4bdb5252014-11-13 16:20:11 -0800738 // Otherwise, look at default value
739 boolean defaultAllowMediaDownloadsValue = mController.getContext()
740 .getResources().getBoolean(R.bool.def_allow_media_downloads);
741
742 // If preference is not saved, save default value
743 if (!mPrefs.contains(PREF_ALLOW_MEDIA_DOWNLOADS)){
Tarun Nainani8eb00912014-07-17 12:28:32 -0700744 Editor edit = mPrefs.edit();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800745 edit.putBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700746 edit.apply();
747 }
748
Panos Thomas4bdb5252014-11-13 16:20:11 -0800749 return mPrefs.getBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700750 }
751
John Reck35e9dd62011-04-25 09:01:54 -0700752 // TODO: Cache
John Reck35e9dd62011-04-25 09:01:54 -0700753 public ZoomDensity getDefaultZoom() {
754 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800755 return ZoomDensity.valueOf(zoom);
John Reck35e9dd62011-04-25 09:01:54 -0700756 }
757
758 public boolean loadPageInOverviewMode() {
759 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
760 }
761
762 public boolean autofitPages() {
763 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
764 }
765
766 public boolean blockPopupWindows() {
767 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
768 }
769
770 public boolean loadImages() {
771 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
772 }
773
774 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800775 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
776 if(autoDetect.equalsIgnoreCase("auto")) {
777 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
778 }
779 return autoDetect;
John Reck35e9dd62011-04-25 09:01:54 -0700780 }
781
782 // -----------------------------
783 // getter/setters for general_preferences.xml
784 // -----------------------------
785
786 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700787 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
788 }
789
790 public void setHomePage(String value) {
791 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
792 }
793
794 public boolean isAutofillEnabled() {
795 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
796 }
797
798 public void setAutofillEnabled(boolean value) {
799 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
800 }
801
802 // -----------------------------
803 // getter/setters for debug_preferences.xml
804 // -----------------------------
805
806 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700807 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700808 return true;
809 }
810 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
811 }
812
Derek Sollenberger31adf672011-07-08 11:31:30 -0400813 public boolean isSkiaHardwareAccelerated() {
814 if (!isDebugEnabled()) {
815 return false;
816 }
817 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
818 }
819
John Reck35e9dd62011-04-25 09:01:54 -0700820 // -----------------------------
821 // getter/setters for hidden_debug_preferences.xml
822 // -----------------------------
823
824 public boolean enableVisualIndicator() {
825 if (!isDebugEnabled()) {
826 return false;
827 }
828 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
829 }
830
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700831 public boolean enableCpuUploadPath() {
832 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700833 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700834 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700835 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700836 }
837
John Reck35e9dd62011-04-25 09:01:54 -0700838 public boolean isSmallScreen() {
839 if (!isDebugEnabled()) {
840 return false;
841 }
842 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
843 }
844
845 public boolean isWideViewport() {
846 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800847 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700848 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800849 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700850 }
851
852 public boolean isNormalLayout() {
853 if (!isDebugEnabled()) {
854 return false;
855 }
856 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
857 }
858
859 public boolean isTracing() {
860 if (!isDebugEnabled()) {
861 return false;
862 }
863 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
864 }
865
866 public boolean enableLightTouch() {
867 if (!isDebugEnabled()) {
868 return false;
869 }
870 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
871 }
872
873 public boolean enableNavDump() {
874 if (!isDebugEnabled()) {
875 return false;
876 }
877 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
878 }
879
880 public String getJsEngineFlags() {
881 if (!isDebugEnabled()) {
882 return "";
883 }
884 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
885 }
886
887 // -----------------------------
888 // getter/setters for lab_preferences.xml
889 // -----------------------------
890
John Reck35e9dd62011-04-25 09:01:54 -0700891 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700892 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700893 }
894
Michael Kolbc38c6042011-04-27 10:46:06 -0700895 public boolean useFullscreen() {
896 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
897 }
898
John Reck2fd9d0e2011-07-15 11:13:48 -0700899 public boolean useInvertedRendering() {
900 return mPrefs.getBoolean(PREF_INVERTED, false);
901 }
902
Nicolas Roard5d513102011-08-03 15:35:34 -0700903 public float getInvertedContrast() {
904 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
905 }
906
John Reck35e9dd62011-04-25 09:01:54 -0700907 // -----------------------------
908 // getter/setters for privacy_security_preferences.xml
909 // -----------------------------
910
911 public boolean showSecurityWarnings() {
912 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
913 }
914
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700915 public boolean doNotTrack() {
916 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
917 }
918
John Reck35e9dd62011-04-25 09:01:54 -0700919 public boolean acceptCookies() {
920 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
921 }
922
923 public boolean saveFormdata() {
924 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
925 }
926
927 public boolean enableGeolocation() {
928 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
929 }
930
931 public boolean rememberPasswords() {
932 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
933 }
934
Michael Kolb14612442011-06-24 13:06:29 -0700935 // -----------------------------
936 // getter/setters for bandwidth_preferences.xml
937 // -----------------------------
938
Mathew Inwood467813f2011-09-02 15:43:17 +0100939 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
940 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700941 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100942
943 public static String getPreloadAlwaysPreferenceString(Context context) {
944 return context.getResources().getString(R.string.pref_data_preload_value_always);
945 }
946
Mathew Inwood825fba72011-10-04 14:52:52 +0100947 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
948 "browser_default_preload_setting";
949
950 public String getDefaultPreloadSetting() {
951 String preload = Settings.Secure.getString(mContext.getContentResolver(),
952 DEAULT_PRELOAD_SECURE_SETTING_KEY);
953 if (preload == null) {
954 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
955 }
956 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100957 }
958
959 public String getPreloadEnabled() {
960 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
961 }
962
Victoria Lease96497832012-03-23 14:19:56 -0700963 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
964 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
965 }
966
967 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
968 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
969 }
970
971 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
972 "browser_default_link_prefetch_setting";
973
974 public String getDefaultLinkPrefetchSetting() {
975 String preload = Settings.Secure.getString(mContext.getContentResolver(),
976 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
977 if (preload == null) {
978 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
979 }
980 return preload;
981 }
982
983 public String getLinkPrefetchEnabled() {
984 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
985 }
986
George Mount3636d0a2011-11-21 09:08:21 -0800987 // -----------------------------
988 // getter/setters for browser recovery
989 // -----------------------------
990 /**
991 * The last time browser was started.
992 * @return The last browser start time as System.currentTimeMillis. This
993 * can be 0 if this is the first time or the last tab was closed.
994 */
995 public long getLastRecovered() {
996 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
997 }
998
999 /**
1000 * Sets the last browser start time.
1001 * @param time The last time as System.currentTimeMillis that the browser
1002 * was started. This should be set to 0 if the last tab is closed.
1003 */
1004 public void setLastRecovered(long time) {
1005 mPrefs.edit()
1006 .putLong(KEY_LAST_RECOVERED, time)
1007 .apply();
1008 }
1009
1010 /**
1011 * Used to determine whether or not the previous browser run crashed. Once
1012 * the previous state has been determined, the value will be set to false
1013 * until a pause is received.
1014 * @return true if the last browser run was paused or false if it crashed.
1015 */
1016 public boolean wasLastRunPaused() {
1017 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1018 }
1019
1020 /**
1021 * Sets whether or not the last run was a pause or crash.
1022 * @param isPaused Set to true When a pause is received or false after
1023 * resuming.
1024 */
1025 public void setLastRunPaused(boolean isPaused) {
1026 mPrefs.edit()
1027 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1028 .apply();
1029 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001030}