blob: 975ae89be291f5a00fb19e58f7a2dbd8ff86f95a [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());
347
John Reck35e9dd62011-04-25 09:01:54 -0700348 if (mController != null) {
349 mController.setShouldShowErrorConsole(enableJavascriptConsole());
Shimeng (Simon) Wange83e9062010-03-29 16:13:09 -0700350 }
John Reck35e9dd62011-04-25 09:01:54 -0700351 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700352
John Reck35e9dd62011-04-25 09:01:54 -0700353 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700354 if (!mEngineInitialized) {
355 mSyncManagedSettings = true;
356 return;
357 }
358 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700359 syncSharedSettings();
360 synchronized (mManagedSettings) {
361 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
362 while (iter.hasNext()) {
363 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800364 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700365 if (settings == null) {
366 iter.remove();
367 continue;
368 }
369 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000370 }
John Reck35e9dd62011-04-25 09:01:54 -0700371 }
372 }
Ben Murdochef671652010-11-25 17:17:58 +0000373
John Reck35e9dd62011-04-25 09:01:54 -0700374 @Override
375 public void onSharedPreferenceChanged(
376 SharedPreferences sharedPreferences, String key) {
377 syncManagedSettings();
378 if (PREF_SEARCH_ENGINE.equals(key)) {
379 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700380 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200381 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700382 mController.getUi().setFullscreen(useFullscreen());
383 }
Victoria Lease96497832012-03-23 14:19:56 -0700384 } else if (PREF_LINK_PREFETCH.equals(key)) {
385 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700386 }
John Reck35e9dd62011-04-25 09:01:54 -0700387 }
388
John Reck961d35d2011-06-23 09:45:54 -0700389 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100390 requireInitialization();
391 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700392 }
393
394 public LayoutAlgorithm getLayoutAlgorithm() {
395 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
396 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700397 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700398 }
399 if (isDebugEnabled()) {
400 if (isSmallScreen()) {
401 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000402 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700403 if (isNormalLayout()) {
404 layoutAlgorithm = LayoutAlgorithm.NORMAL;
405 } else {
406 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
407 }
Ben Murdochef671652010-11-25 17:17:58 +0000408 }
John Reck35e9dd62011-04-25 09:01:54 -0700409 }
410 return layoutAlgorithm;
411 }
Ben Murdochef671652010-11-25 17:17:58 +0000412
John Reck35e9dd62011-04-25 09:01:54 -0700413 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700414 requireInitialization();
415 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800416 }
417
John Reck35e9dd62011-04-25 09:01:54 -0700418 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700419 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700420 return mWebStorageSizeManager;
421 }
422
John Reck35e9dd62011-04-25 09:01:54 -0700423 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700424 if (mAppCachePath == null) {
425 mAppCachePath = mContext.getDir("appcache", 0).getPath();
426 }
427 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700428 }
429
430 private void updateSearchEngine(boolean force) {
431 String searchEngineName = getSearchEngineName();
432 if (force || mSearchEngine == null ||
433 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700434 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000435 }
436 }
437
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100438 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700439 if (mSearchEngine == null) {
440 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100441 }
John Reck35e9dd62011-04-25 09:01:54 -0700442 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100443 }
444
John Reck35e9dd62011-04-25 09:01:54 -0700445 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700446 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700447 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100448 }
449
John Reck35e9dd62011-04-25 09:01:54 -0700450 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700451 Editor edit = mPrefs.edit();
452 edit.putBoolean(PREF_DEBUG_MENU, value);
453 if (!value) {
454 // Reset to "safe" value
455 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
456 }
457 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100458 }
459
John Reck35e9dd62011-04-25 09:01:54 -0700460 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 if (mController != null) {
462 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800463 if (current != null) {
464 current.clearCache(true);
465 }
466 }
467 }
468
John Reck35e9dd62011-04-25 09:01:54 -0700469 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800470 CookieManager.getInstance().removeAllCookie();
471 }
472
John Reck35e9dd62011-04-25 09:01:54 -0700473 public void clearHistory() {
474 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800475 Browser.clearHistory(resolver);
476 Browser.clearSearches(resolver);
477 }
478
John Reck35e9dd62011-04-25 09:01:54 -0700479 public void clearFormData() {
480 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700481 if (mController!= null) {
482 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100483 if (currentTopView != null) {
484 currentTopView.clearFormData();
485 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800486 }
487 }
488
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700489 public WebView getTopWebView(){
490 if (mController!= null)
491 return mController.getCurrentTopWebView();
492
493 return null;
494 }
495
John Reck35e9dd62011-04-25 09:01:54 -0700496 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700497 // Clear password store maintained by SWE engine
498 WebSettings settings = null;
499 // find a valid settings object
500 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
501 while (iter.hasNext()) {
502 WeakReference<WebSettings> ref = iter.next();
503 settings = (WebSettings)ref.get();
504 if (settings != null) {
505 break;
506 }
507 }
508 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700509 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700510 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700511
512 // Clear passwords in WebView database
513 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
514 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800515 }
516
John Reck35e9dd62011-04-25 09:01:54 -0700517 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100518 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100519 }
520
John Reck35e9dd62011-04-25 09:01:54 -0700521 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100522 GeolocationPermissions.getInstance().clearAll();
Nicolas Roard78a98e42009-05-11 13:34:17 +0100523 }
524
John Reck35e9dd62011-04-25 09:01:54 -0700525 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700526 mPrefs.edit()
527 .clear()
John Reckbd315192011-07-29 10:05:47 -0700528 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200529 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700530 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700531 }
532
Björn Isakssonc885a242012-06-05 17:19:04 +0200533 private void resetCachedValues() {
534 updateSearchEngine(false);
535 }
536
John Reck35e9dd62011-04-25 09:01:54 -0700537 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800538 // query the profile from components autofill database 524
539 if (mAutofillHandler.mAutoFillProfile == null &&
540 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
541 WebSettings settings = null;
542 // find a valid settings object
543 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
544 while (iter.hasNext()) {
545 WeakReference<WebSettings> ref = iter.next();
546 settings = (WebSettings)ref.get();
547 if (settings != null) {
548 break;
549 }
550 }
551 if (settings != null) {
552 AutoFillProfile profile =
553 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
554 mAutofillHandler.setAutoFillProfile(profile);
555 }
556 }
John Reck35e9dd62011-04-25 09:01:54 -0700557 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800558 }
559
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800560 public String getAutoFillProfileId() {
561 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800562 }
563
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800564 public void updateAutoFillProfile(AutoFillProfile profile) {
565 syncAutoFillProfile(profile);
566 }
567
568 private void syncAutoFillProfile(AutoFillProfile profile) {
569 synchronized (mManagedSettings) {
570 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
571 while (iter.hasNext()) {
572 WeakReference<WebSettings> ref = iter.next();
573 WebSettings settings = (WebSettings)ref.get();
574 if (settings == null) {
575 iter.remove();
576 continue;
577 }
578 // update the profile only once.
579 settings.setAutoFillProfile(profile);
580 // Now we should have the guid
581 mAutofillHandler.setAutoFillProfile(profile);
582 break;
583 }
584 }
585 }
John Reck35e9dd62011-04-25 09:01:54 -0700586 public void toggleDebugSettings() {
587 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800588 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100589
John Reckb8b2af82011-05-20 15:58:33 -0700590 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800591 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700592 }
593
594 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700595 if (view == null) {
596 return;
597 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800598 if (hasDesktopUseragent(view))
599 view.setUseDesktopUserAgent(false, true);
600 else
601 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700602 }
603
John Reck7dc444b2011-06-16 17:44:29 -0700604 public static int getAdjustedMinimumFontSize(int rawValue) {
605 rawValue++; // Preference starts at 0, min font at 1
606 if (rawValue > 1) {
607 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
608 }
609 return rawValue;
610 }
611
John Reck5ba3c762011-09-14 15:00:15 -0700612 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700613 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700614 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700615 }
616
617 static int getRawTextZoom(int percent) {
618 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
619 }
620
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700621 public int getAdjustedDoubleTapZoom(int rawValue) {
622 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
623 return (int) ((rawValue + 100) * mFontSizeMult);
624 }
625
626 static int getRawDoubleTapZoom(int percent) {
627 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
628 }
629
John Reckcadae722011-07-25 11:36:17 -0700630 public SharedPreferences getPreferences() {
631 return mPrefs;
632 }
633
Victoria Lease96497832012-03-23 14:19:56 -0700634 // update connectivity-dependent options
635 public void updateConnectionType() {
636 ConnectivityManager cm = (ConnectivityManager)
637 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
638 String linkPrefetchPreference = getLinkPrefetchEnabled();
639 boolean linkPrefetchAllowed = linkPrefetchPreference.
640 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
641 NetworkInfo ni = cm.getActiveNetworkInfo();
642 if (ni != null) {
643 switch (ni.getType()) {
644 case ConnectivityManager.TYPE_WIFI:
645 case ConnectivityManager.TYPE_ETHERNET:
646 case ConnectivityManager.TYPE_BLUETOOTH:
647 linkPrefetchAllowed |= linkPrefetchPreference.
648 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
649 break;
650 case ConnectivityManager.TYPE_MOBILE:
651 case ConnectivityManager.TYPE_MOBILE_DUN:
652 case ConnectivityManager.TYPE_MOBILE_MMS:
653 case ConnectivityManager.TYPE_MOBILE_SUPL:
654 case ConnectivityManager.TYPE_WIMAX:
655 default:
656 break;
657 }
658 }
659 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
660 mLinkPrefetchAllowed = linkPrefetchAllowed;
661 syncManagedSettings();
662 }
663 }
664
luxiaol62677b02013-07-22 07:54:49 +0800665 public String getDownloadPath() {
666 return mPrefs.getString(PREF_DOWNLOAD_PATH,
667 DownloadHandler.getDefaultDownloadPath(mContext));
668 }
John Reck35e9dd62011-04-25 09:01:54 -0700669 // -----------------------------
670 // getter/setters for accessibility_preferences.xml
671 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100672
John Reck7dc444b2011-06-16 17:44:29 -0700673 @Deprecated
674 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700675 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
676 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100677 }
678
John Reck35e9dd62011-04-25 09:01:54 -0700679 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700680 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700681 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100682 }
683
John Reck92f25f82011-04-26 16:57:10 -0700684 public boolean forceEnableUserScalable() {
685 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
686 }
687
John Reck7dc444b2011-06-16 17:44:29 -0700688 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700689 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700690 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
691 return getAdjustedTextZoom(textZoom);
692 }
693
694 public void setTextZoom(int percent) {
695 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
696 }
697
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700698 public int getDoubleTapZoom() {
699 requireInitialization();
700 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
701 return getAdjustedDoubleTapZoom(doubleTapZoom);
702 }
703
704 public void setDoubleTapZoom(int percent) {
705 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
706 }
707
John Reck35e9dd62011-04-25 09:01:54 -0700708 // -----------------------------
709 // getter/setters for advanced_preferences.xml
710 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100711
John Reck35e9dd62011-04-25 09:01:54 -0700712 public String getSearchEngineName() {
luxiaol221b3932013-07-19 15:27:57 +0800713 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
714 if (defaultSearchEngineValue == null) {
715 defaultSearchEngineValue = SearchEngine.GOOGLE;
716 }
717 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100718 }
John Reck63bb6872010-12-01 19:29:32 -0800719
Michael Kolb8d772b02012-01-19 13:56:00 -0800720 public boolean allowAppTabs() {
721 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
722 }
723
John Reck35e9dd62011-04-25 09:01:54 -0700724 public boolean openInBackground() {
725 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800726 }
John Reck35e9dd62011-04-25 09:01:54 -0700727
728 public boolean enableJavascript() {
729 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
730 }
731
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800732 public boolean enableMemoryMonitor() {
733 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
734 }
735
Tarun Nainani8eb00912014-07-17 12:28:32 -0700736 public boolean allowMediaDownloads() {
Panos Thomas4bdb5252014-11-13 16:20:11 -0800737 // Return false if preference is not exposed to user
738 if (!BrowserConfig.getInstance(mContext)
739 .hasFeature(BrowserConfig.Feature.ALLOW_MEDIA_DOWNLOADS))
740 return false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700741
Panos Thomas4bdb5252014-11-13 16:20:11 -0800742 // Otherwise, look at default value
743 boolean defaultAllowMediaDownloadsValue = mController.getContext()
744 .getResources().getBoolean(R.bool.def_allow_media_downloads);
745
746 // If preference is not saved, save default value
747 if (!mPrefs.contains(PREF_ALLOW_MEDIA_DOWNLOADS)){
Tarun Nainani8eb00912014-07-17 12:28:32 -0700748 Editor edit = mPrefs.edit();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800749 edit.putBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700750 edit.apply();
751 }
752
Panos Thomas4bdb5252014-11-13 16:20:11 -0800753 return mPrefs.getBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700754 }
755
John Reck35e9dd62011-04-25 09:01:54 -0700756 // TODO: Cache
John Reck35e9dd62011-04-25 09:01:54 -0700757 public ZoomDensity getDefaultZoom() {
758 String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800759 return ZoomDensity.valueOf(zoom);
John Reck35e9dd62011-04-25 09:01:54 -0700760 }
761
762 public boolean loadPageInOverviewMode() {
763 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
764 }
765
766 public boolean autofitPages() {
767 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
768 }
769
770 public boolean blockPopupWindows() {
771 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
772 }
773
774 public boolean loadImages() {
775 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
776 }
777
778 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800779 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
780 if(autoDetect.equalsIgnoreCase("auto")) {
781 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
782 }
783 return autoDetect;
John Reck35e9dd62011-04-25 09:01:54 -0700784 }
785
786 // -----------------------------
787 // getter/setters for general_preferences.xml
788 // -----------------------------
789
790 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700791 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
792 }
793
794 public void setHomePage(String value) {
795 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
796 }
797
798 public boolean isAutofillEnabled() {
799 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
800 }
801
802 public void setAutofillEnabled(boolean value) {
803 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
804 }
805
806 // -----------------------------
807 // getter/setters for debug_preferences.xml
808 // -----------------------------
809
810 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700811 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700812 return true;
813 }
814 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
815 }
816
Derek Sollenberger31adf672011-07-08 11:31:30 -0400817 public boolean isSkiaHardwareAccelerated() {
818 if (!isDebugEnabled()) {
819 return false;
820 }
821 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
822 }
823
John Reck35e9dd62011-04-25 09:01:54 -0700824 // -----------------------------
825 // getter/setters for hidden_debug_preferences.xml
826 // -----------------------------
827
828 public boolean enableVisualIndicator() {
829 if (!isDebugEnabled()) {
830 return false;
831 }
832 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
833 }
834
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700835 public boolean enableCpuUploadPath() {
836 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700837 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700838 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700839 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700840 }
841
John Reck35e9dd62011-04-25 09:01:54 -0700842 public boolean enableJavascriptConsole() {
843 if (!isDebugEnabled()) {
844 return false;
845 }
846 return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
847 }
848
849 public boolean isSmallScreen() {
850 if (!isDebugEnabled()) {
851 return false;
852 }
853 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
854 }
855
856 public boolean isWideViewport() {
857 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800858 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700859 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800860 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700861 }
862
863 public boolean isNormalLayout() {
864 if (!isDebugEnabled()) {
865 return false;
866 }
867 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
868 }
869
870 public boolean isTracing() {
871 if (!isDebugEnabled()) {
872 return false;
873 }
874 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
875 }
876
877 public boolean enableLightTouch() {
878 if (!isDebugEnabled()) {
879 return false;
880 }
881 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
882 }
883
884 public boolean enableNavDump() {
885 if (!isDebugEnabled()) {
886 return false;
887 }
888 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
889 }
890
891 public String getJsEngineFlags() {
892 if (!isDebugEnabled()) {
893 return "";
894 }
895 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
896 }
897
898 // -----------------------------
899 // getter/setters for lab_preferences.xml
900 // -----------------------------
901
John Reck35e9dd62011-04-25 09:01:54 -0700902 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700903 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700904 }
905
Michael Kolbc38c6042011-04-27 10:46:06 -0700906 public boolean useFullscreen() {
907 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
908 }
909
John Reck2fd9d0e2011-07-15 11:13:48 -0700910 public boolean useInvertedRendering() {
911 return mPrefs.getBoolean(PREF_INVERTED, false);
912 }
913
Nicolas Roard5d513102011-08-03 15:35:34 -0700914 public float getInvertedContrast() {
915 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
916 }
917
John Reck35e9dd62011-04-25 09:01:54 -0700918 // -----------------------------
919 // getter/setters for privacy_security_preferences.xml
920 // -----------------------------
921
922 public boolean showSecurityWarnings() {
923 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
924 }
925
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700926 public boolean doNotTrack() {
927 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
928 }
929
John Reck35e9dd62011-04-25 09:01:54 -0700930 public boolean acceptCookies() {
931 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
932 }
933
934 public boolean saveFormdata() {
935 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
936 }
937
938 public boolean enableGeolocation() {
939 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
940 }
941
942 public boolean rememberPasswords() {
943 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
944 }
945
Michael Kolb14612442011-06-24 13:06:29 -0700946 // -----------------------------
947 // getter/setters for bandwidth_preferences.xml
948 // -----------------------------
949
Mathew Inwood467813f2011-09-02 15:43:17 +0100950 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
951 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700952 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100953
954 public static String getPreloadAlwaysPreferenceString(Context context) {
955 return context.getResources().getString(R.string.pref_data_preload_value_always);
956 }
957
Mathew Inwood825fba72011-10-04 14:52:52 +0100958 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
959 "browser_default_preload_setting";
960
961 public String getDefaultPreloadSetting() {
962 String preload = Settings.Secure.getString(mContext.getContentResolver(),
963 DEAULT_PRELOAD_SECURE_SETTING_KEY);
964 if (preload == null) {
965 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
966 }
967 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100968 }
969
970 public String getPreloadEnabled() {
971 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
972 }
973
Victoria Lease96497832012-03-23 14:19:56 -0700974 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
975 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
976 }
977
978 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
979 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
980 }
981
982 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
983 "browser_default_link_prefetch_setting";
984
985 public String getDefaultLinkPrefetchSetting() {
986 String preload = Settings.Secure.getString(mContext.getContentResolver(),
987 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
988 if (preload == null) {
989 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
990 }
991 return preload;
992 }
993
994 public String getLinkPrefetchEnabled() {
995 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
996 }
997
George Mount3636d0a2011-11-21 09:08:21 -0800998 // -----------------------------
999 // getter/setters for browser recovery
1000 // -----------------------------
1001 /**
1002 * The last time browser was started.
1003 * @return The last browser start time as System.currentTimeMillis. This
1004 * can be 0 if this is the first time or the last tab was closed.
1005 */
1006 public long getLastRecovered() {
1007 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
1008 }
1009
1010 /**
1011 * Sets the last browser start time.
1012 * @param time The last time as System.currentTimeMillis that the browser
1013 * was started. This should be set to 0 if the last tab is closed.
1014 */
1015 public void setLastRecovered(long time) {
1016 mPrefs.edit()
1017 .putLong(KEY_LAST_RECOVERED, time)
1018 .apply();
1019 }
1020
1021 /**
1022 * Used to determine whether or not the previous browser run crashed. Once
1023 * the previous state has been determined, the value will be set to false
1024 * until a pause is received.
1025 * @return true if the last browser run was paused or false if it crashed.
1026 */
1027 public boolean wasLastRunPaused() {
1028 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1029 }
1030
1031 /**
1032 * Sets whether or not the last run was a pause or crash.
1033 * @param isPaused Set to true When a pause is received or false after
1034 * resuming.
1035 */
1036 public void setLastRunPaused(boolean isPaused) {
1037 mPrefs.edit()
1038 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1039 .apply();
1040 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001041}