blob: 9ba3c31ebae2f771172bb2f213f35b0843e864f9 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
John Reck35e9dd62011-04-25 09:01:54 -07002 * Copyright (C) 2011 The Android Open Source Project
The Android Open Source Project0c908882009-03-03 19:32:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.content.ContentResolver;
20import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.SharedPreferences;
John Reck1da81882011-10-04 17:21:10 -070022import android.content.SharedPreferences.Editor;
John Reck812d2d62011-01-18 14:16:15 -080023import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Victoria Lease96497832012-03-23 14:19:56 -070024import android.net.ConnectivityManager;
25import android.net.NetworkInfo;
John Reckf48314f2011-04-27 17:52:17 -070026import android.os.Build;
Ben Murdoch0cb81892010-10-08 12:41:33 +010027import android.preference.PreferenceManager;
Mathew Inwood825fba72011-10-04 14:52:52 +010028import android.provider.Settings;
Bijan Amirzadae75909d2014-05-06 14:18:54 -070029import android.text.TextUtils;
John Reck5ba3c762011-09-14 15:00:15 -070030import android.util.DisplayMetrics;
Nicolas Roard78a98e42009-05-11 13:34:17 +010031import android.webkit.WebStorage;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032
Bijan Amirzada41242f22014-03-21 12:12:18 -070033import com.android.browser.R;
34import com.android.browser.homepages.HomeProvider;
Bijan Amirzada3f04dc72014-06-25 11:48:36 -070035import com.android.browser.platformsupport.Browser;
Bijan Amirzada41242f22014-03-21 12:12:18 -070036import com.android.browser.provider.BrowserProvider;
Bijan Amirzada41242f22014-03-21 12:12:18 -070037import com.android.browser.search.SearchEngine;
38import com.android.browser.search.SearchEngines;
John Reck46500332011-06-07 14:36:10 -070039
John Reck35e9dd62011-04-25 09:01:54 -070040import java.lang.ref.WeakReference;
41import java.util.Iterator;
42import java.util.LinkedList;
John Reckb8b2af82011-05-20 15:58:33 -070043import java.util.WeakHashMap;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080045import org.codeaurora.swe.AutoFillProfile;
46import org.codeaurora.swe.CookieManager;
47import org.codeaurora.swe.GeolocationPermissions;
48import org.codeaurora.swe.WebSettings.LayoutAlgorithm;
49import org.codeaurora.swe.WebSettings.PluginState;
50import org.codeaurora.swe.WebSettings.TextSize;
51import org.codeaurora.swe.WebSettings.ZoomDensity;
52import org.codeaurora.swe.WebSettings;
53import org.codeaurora.swe.WebView;
Vivek Sekhare8a8ec22014-07-10 14:52:43 -070054import org.codeaurora.swe.WebViewDatabase;
Panos Thomas3f35d8d2014-11-08 22:40:23 -080055
John Reck35e9dd62011-04-25 09:01:54 -070056/**
57 * Class for managing settings
The Android Open Source Project0c908882009-03-03 19:32:16 -080058 */
John Reck35e9dd62011-04-25 09:01:54 -070059public class BrowserSettings implements OnSharedPreferenceChangeListener,
60 PreferenceKeys {
Andrei Popescu01068702009-08-03 16:03:24 +010061
qqzhoue6ff8b42013-07-23 17:28:48 +080062 private static final String TAG = "BrowserSettings";
John Reck8fc22a12011-06-16 14:57:41 -070063 // The minimum min font size
64 // Aka, the lower bounds for the min font size range
65 // which is 1:5..24
66 private static final int MIN_FONT_SIZE_OFFSET = 5;
John Reck7dc444b2011-06-16 17:44:29 -070067 // The initial value in the text zoom range
68 // This is what represents 100% in the SeekBarPreference range
69 private static final int TEXT_ZOOM_START_VAL = 10;
70 // The size of a single step in the text zoom range, in percent
71 private static final int TEXT_ZOOM_STEP = 5;
Mangesh Ghiware67f45c22011-10-12 14:43:32 -070072 // The initial value in the double tap zoom range
73 // This is what represents 100% in the SeekBarPreference range
74 private static final int DOUBLE_TAP_ZOOM_START_VAL = 5;
75 // The size of a single step in the double tap zoom range, in percent
76 private static final int DOUBLE_TAP_ZOOM_STEP = 5;
John Reck8fc22a12011-06-16 14:57:41 -070077
John Reck35e9dd62011-04-25 09:01:54 -070078 private static BrowserSettings sInstance;
Jeff Davidson43610292010-07-16 16:03:58 -070079
John Reck35e9dd62011-04-25 09:01:54 -070080 private Context mContext;
81 private SharedPreferences mPrefs;
82 private LinkedList<WeakReference<WebSettings>> mManagedSettings;
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private Controller mController;
John Reck35e9dd62011-04-25 09:01:54 -070084 private WebStorageSizeManager mWebStorageSizeManager;
85 private AutofillHandler mAutofillHandler;
Ben Murdochaaa1f372011-07-25 15:40:58 +010086 private static boolean sInitialized = false;
John Reckc477e712011-08-17 11:27:15 -070087 private boolean mNeedsSharedSync = true;
John Reck5ba3c762011-09-14 15:00:15 -070088 private float mFontSizeMult = 1.0f;
John Reck78a6a1d2011-07-21 13:54:03 -070089
Victoria Lease96497832012-03-23 14:19:56 -070090 // Current state of network-dependent settings
91 private boolean mLinkPrefetchAllowed = true;
92
John Reck78a6a1d2011-07-21 13:54:03 -070093 // Cached values
94 private int mPageCacheCapacity = 1;
95 private String mAppCachePath;
The Android Open Source Project0c908882009-03-03 19:32:16 -080096
John Reck35e9dd62011-04-25 09:01:54 -070097 // Cached settings
98 private SearchEngine mSearchEngine;
The Android Open Source Project0c908882009-03-03 19:32:16 -080099
Ben Murdochaaa1f372011-07-25 15:40:58 +0100100 private static String sFactoryResetUrl;
101
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700102 private boolean mEngineInitialized = false;
103 private boolean mSyncManagedSettings = false;
104
Bijan Amirzada3bb46302014-06-17 16:31:31 -0700105 public static synchronized void initialize(final Context context) {
106 if (sInstance == null)
107 sInstance = new BrowserSettings(context);
John Reck35e9dd62011-04-25 09:01:54 -0700108 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800109
Vivek Sekhar6f4f82a2014-03-21 19:24:51 -0700110 public static BrowserSettings getInstance() {
John Reck35e9dd62011-04-25 09:01:54 -0700111 return sInstance;
112 }
Ben Murdochef671652010-11-25 17:17:58 +0000113
John Reck35e9dd62011-04-25 09:01:54 -0700114 private BrowserSettings(Context context) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100115 mContext = context.getApplicationContext();
John Reck35e9dd62011-04-25 09:01:54 -0700116 mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
John Reck35e9dd62011-04-25 09:01:54 -0700117 mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
John Reckcadae722011-07-25 11:36:17 -0700118 BackgroundHandler.execute(mSetup);
John Reck35e9dd62011-04-25 09:01:54 -0700119 }
120
121 public void setController(Controller controller) {
122 mController = controller;
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700123 mNeedsSharedSync = true;
124 }
125
126 public void onEngineInitializationComplete() {
127 mEngineInitialized = true;
128 mAutofillHandler = new AutofillHandler(mContext);
129 if (mSyncManagedSettings) {
130 syncManagedSettings();
131 }
132 if (mNeedsSharedSync) {
John Reckc477e712011-08-17 11:27:15 -0700133 syncSharedSettings();
134 }
Ben Murdochef671652010-11-25 17:17:58 +0000135 }
136
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800137 public void startManagingSettings(final WebSettings settings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800138
John Reckc477e712011-08-17 11:27:15 -0700139 if (mNeedsSharedSync) {
140 syncSharedSettings();
141 }
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800142
John Reck35e9dd62011-04-25 09:01:54 -0700143 synchronized (mManagedSettings) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800144 syncStaticSettings(settings);
145 syncSetting(settings);
John Reck35e9dd62011-04-25 09:01:54 -0700146 mManagedSettings.add(new WeakReference<WebSettings>(settings));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800147 }
148 }
149
John Reckd1d87312012-03-08 13:25:00 -0800150 public void stopManagingSettings(WebSettings settings) {
151 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
152 while (iter.hasNext()) {
153 WeakReference<WebSettings> ref = iter.next();
154 if (ref.get() == settings) {
155 iter.remove();
156 return;
157 }
158 }
159 }
160
John Reckcadae722011-07-25 11:36:17 -0700161 private Runnable mSetup = new Runnable() {
John Reck78a6a1d2011-07-21 13:54:03 -0700162
163 @Override
164 public void run() {
John Reck5ba3c762011-09-14 15:00:15 -0700165 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
166 mFontSizeMult = metrics.scaledDensity / metrics.density;
John Reck78a6a1d2011-07-21 13:54:03 -0700167 // the cost of one cached page is ~3M (measured using nytimes.com). For
168 // low end devices, we only cache one page. For high end devices, we try
169 // to cache more pages, currently choose 5.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800170
171 // SWE_TODO : assume a high-memory device
172 //if (ActivityManager.staticGetMemoryClass() > 16) {
John Reck78a6a1d2011-07-21 13:54:03 -0700173 mPageCacheCapacity = 5;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800174 //}
John Reck78a6a1d2011-07-21 13:54:03 -0700175 mWebStorageSizeManager = new WebStorageSizeManager(mContext,
176 new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
177 new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
John Reck276b1352011-09-02 15:47:33 -0700178 // Workaround b/5254577
179 mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this);
John Reck78a6a1d2011-07-21 13:54:03 -0700180 if (Build.VERSION.CODENAME.equals("REL")) {
181 // This is a release build, always startup with debug disabled
182 setDebugEnabled(false);
183 }
184 if (mPrefs.contains(PREF_TEXT_SIZE)) {
185 /*
186 * Update from TextSize enum to zoom percent
187 * SMALLEST is 50%
188 * SMALLER is 75%
189 * NORMAL is 100%
190 * LARGER is 150%
191 * LARGEST is 200%
192 */
193 switch (getTextSize()) {
194 case SMALLEST:
195 setTextZoom(50);
196 break;
197 case SMALLER:
198 setTextZoom(75);
199 break;
200 case LARGER:
201 setTextZoom(150);
202 break;
203 case LARGEST:
204 setTextZoom(200);
205 break;
206 }
207 mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
208 }
Ben Murdochaaa1f372011-07-25 15:40:58 +0100209
qqzhou8c5b0a32013-07-22 15:31:03 +0800210 // add for carrier homepage feature
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700211 sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
qqzhou8c5b0a32013-07-22 15:31:03 +0800212
kaiyizbf086ea2013-08-02 11:03:58 +0800213 if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) {
Tarun Nainani95b79682014-12-09 09:38:04 -0800214 mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, "auto").apply();
kaiyizbf086ea2013-08-02 11:03:58 +0800215 }
Bijan Amirzadae75909d2014-05-06 14:18:54 -0700216
Ben Murdochaaa1f372011-07-25 15:40:58 +0100217 if (sFactoryResetUrl.indexOf("{CID}") != -1) {
218 sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
219 BrowserProvider.getClientId(mContext.getContentResolver()));
220 }
221
Ben Murdochaaa1f372011-07-25 15:40:58 +0100222 synchronized (BrowserSettings.class) {
223 sInitialized = true;
224 BrowserSettings.class.notifyAll();
John Reck78a6a1d2011-07-21 13:54:03 -0700225 }
226 }
227 };
228
Ben Murdochaaa1f372011-07-25 15:40:58 +0100229 private static void requireInitialization() {
230 synchronized (BrowserSettings.class) {
231 while (!sInitialized) {
John Reck78a6a1d2011-07-21 13:54:03 -0700232 try {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100233 BrowserSettings.class.wait();
John Reck78a6a1d2011-07-21 13:54:03 -0700234 } catch (InterruptedException e) {
235 }
236 }
237 }
238 }
239
The Android Open Source Project0c908882009-03-03 19:32:16 -0800240 /**
John Reck35e9dd62011-04-25 09:01:54 -0700241 * Syncs all the settings that have a Preference UI
The Android Open Source Project0c908882009-03-03 19:32:16 -0800242 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800243 private void syncSetting(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700244 settings.setGeolocationEnabled(enableGeolocation());
245 settings.setJavaScriptEnabled(enableJavascript());
246 settings.setLightTouchEnabled(enableLightTouch());
247 settings.setNavDump(enableNavDump());
John Reck35e9dd62011-04-25 09:01:54 -0700248 settings.setDefaultTextEncodingName(getDefaultTextEncoding());
John Reck35e9dd62011-04-25 09:01:54 -0700249 settings.setMinimumFontSize(getMinimumFontSize());
250 settings.setMinimumLogicalFontSize(getMinimumFontSize());
John Reck7dc444b2011-06-16 17:44:29 -0700251 settings.setTextZoom(getTextZoom());
John Reck35e9dd62011-04-25 09:01:54 -0700252 settings.setLayoutAlgorithm(getLayoutAlgorithm());
Steve Blockdc657fa2011-08-03 19:27:13 +0100253 settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows());
John Reck35e9dd62011-04-25 09:01:54 -0700254 settings.setLoadsImagesAutomatically(loadImages());
255 settings.setLoadWithOverviewMode(loadPageInOverviewMode());
256 settings.setSavePassword(rememberPasswords());
257 settings.setSaveFormData(saveFormdata());
258 settings.setUseWideViewPort(isWideViewport());
Panos Thomasb10bbda2014-06-23 10:18:36 -0700259 settings.setDoNotTrack(doNotTrack());
Tarun Nainani8eb00912014-07-17 12:28:32 -0700260 settings.setMediaPlaybackRequiresUserGesture(false);
261 settings.setAllowMediaDownloads(allowMediaDownloads());
262 setExtraHTTPRequestHeaders(settings);
John Reck2fd9d0e2011-07-15 11:13:48 -0700263
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800264 WebSettings settingsClassic = (WebSettings) settings;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800265 settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated());
266 settingsClassic.setShowVisualIndicator(enableVisualIndicator());
267 settingsClassic.setForceUserScalable(forceEnableUserScalable());
268 settingsClassic.setDoubleTapZoom(getDoubleTapZoom());
269 settingsClassic.setAutoFillEnabled(isAutofillEnabled());
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800270
John Reckea17e782011-10-27 17:15:59 -0700271 boolean useInverted = useInvertedRendering();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800272 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen,
John Reckea17e782011-10-27 17:15:59 -0700273 useInverted ? "true" : "false");
274 if (useInverted) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800275 settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast,
John Reckea17e782011-10-27 17:15:59 -0700276 Float.toString(getInvertedContrast()));
277 }
Nicolas Roard5d513102011-08-03 15:35:34 -0700278
John Reckea17e782011-10-27 17:15:59 -0700279 if (isDebugEnabled()) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800280 settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
John Reckea17e782011-10-27 17:15:59 -0700281 enableCpuUploadPath() ? "true" : "false");
282 }
Victoria Lease96497832012-03-23 14:19:56 -0700283
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800284 settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
Ben Murdochef671652010-11-25 17:17:58 +0000285 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800286
Tarun Nainani8eb00912014-07-17 12:28:32 -0700287 private void setExtraHTTPRequestHeaders(WebSettings settings){
288 String headers = mContext.getResources().getString(R.string.def_extra_http_headers);
289 if (!TextUtils.isEmpty(headers)){
290 settings.setHTTPRequestHeaders(headers);
291 }
292 }
293
John Reck35e9dd62011-04-25 09:01:54 -0700294 /**
295 * Syncs all the settings that have no UI
296 * These cannot change, so we only need to set them once per WebSettings
297 */
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800298 private void syncStaticSettings(WebSettings settings) {
John Reck35e9dd62011-04-25 09:01:54 -0700299 settings.setDefaultFontSize(16);
300 settings.setDefaultFixedFontSize(13);
Ben Murdochef671652010-11-25 17:17:58 +0000301
John Reck35e9dd62011-04-25 09:01:54 -0700302 // WebView inside Browser doesn't want initial focus to be set.
303 settings.setNeedInitialFocus(false);
304 // Browser supports multiple windows
305 settings.setSupportMultipleWindows(true);
306 // enable smooth transition for better performance during panning or
307 // zooming
308 settings.setEnableSmoothTransition(true);
309 // disable content url access
Bijan Amirzada59d4a342014-03-27 13:20:12 -0700310 settings.setAllowContentAccess(true);
John Reck35e9dd62011-04-25 09:01:54 -0700311
312 // HTML5 API flags
313 settings.setAppCacheEnabled(true);
314 settings.setDatabaseEnabled(true);
315 settings.setDomStorageEnabled(true);
John Reck35e9dd62011-04-25 09:01:54 -0700316
317 // HTML5 configuration parametersettings.
John Reck78a6a1d2011-07-21 13:54:03 -0700318 settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
John Reck35e9dd62011-04-25 09:01:54 -0700319 settings.setAppCachePath(getAppCachePath());
320 settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
321 settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
Selim Gurun37bf0442012-03-29 18:27:04 -0700322 // origin policy for file access
323 settings.setAllowUniversalAccessFromFileURLs(false);
324 settings.setAllowFileAccessFromFileURLs(false);
Sudheer Koganti24766882014-10-02 10:58:09 -0700325 settings.setFullscreenSupported(true);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800326
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800327 //if (!(settings instanceof WebSettingsClassic)) return;
328 /*
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800329
330 WebSettingsClassic settingsClassic = (WebSettingsClassic) settings;
331 settingsClassic.setPageCacheCapacity(getPageCacheCapacity());
332 // WebView should be preserving the memory as much as possible.
333 // However, apps like browser wish to turn on the performance mode which
334 // would require more memory.
335 // TODO: We need to dynamically allocate/deallocate temporary memory for
336 // apps which are trying to use minimal memory. Currently, double
337 // buffering is always turned on, which is unnecessary.
338 settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false");
339 settingsClassic.setWorkersEnabled(true); // This only affects V8.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800340 */
John Reck35e9dd62011-04-25 09:01:54 -0700341 }
342
343 private void syncSharedSettings() {
John Reckc477e712011-08-17 11:27:15 -0700344 mNeedsSharedSync = false;
Axesh R. Ajmera579c70c2014-04-17 13:24:56 -0700345 CookieManager.getInstance().setAcceptCookie(acceptCookies());
John Reck35e9dd62011-04-25 09:01:54 -0700346 }
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700347
John Reck35e9dd62011-04-25 09:01:54 -0700348 private void syncManagedSettings() {
Kulanthaivel Palanichamy77942682014-10-28 11:52:06 -0700349 if (!mEngineInitialized) {
350 mSyncManagedSettings = true;
351 return;
352 }
353 mSyncManagedSettings = false;
John Reck35e9dd62011-04-25 09:01:54 -0700354 syncSharedSettings();
355 synchronized (mManagedSettings) {
356 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
357 while (iter.hasNext()) {
358 WeakReference<WebSettings> ref = iter.next();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800359 WebSettings settings = (WebSettings)ref.get();
John Reck35e9dd62011-04-25 09:01:54 -0700360 if (settings == null) {
361 iter.remove();
362 continue;
363 }
364 syncSetting(settings);
Ben Murdochef671652010-11-25 17:17:58 +0000365 }
John Reck35e9dd62011-04-25 09:01:54 -0700366 }
367 }
Ben Murdochef671652010-11-25 17:17:58 +0000368
John Reck35e9dd62011-04-25 09:01:54 -0700369 @Override
370 public void onSharedPreferenceChanged(
371 SharedPreferences sharedPreferences, String key) {
372 syncManagedSettings();
373 if (PREF_SEARCH_ENGINE.equals(key)) {
374 updateSearchEngine(false);
Victoria Lease96497832012-03-23 14:19:56 -0700375 } else if (PREF_FULLSCREEN.equals(key)) {
Magnus Hallqvist47ed4b82012-08-31 13:30:39 +0200376 if (mController != null && mController.getUi() != null) {
Michael Kolbc38c6042011-04-27 10:46:06 -0700377 mController.getUi().setFullscreen(useFullscreen());
378 }
Victoria Lease96497832012-03-23 14:19:56 -0700379 } else if (PREF_LINK_PREFETCH.equals(key)) {
380 updateConnectionType();
Michael Kolbc38c6042011-04-27 10:46:06 -0700381 }
John Reck35e9dd62011-04-25 09:01:54 -0700382 }
383
John Reck961d35d2011-06-23 09:45:54 -0700384 public static String getFactoryResetHomeUrl(Context context) {
Ben Murdochaaa1f372011-07-25 15:40:58 +0100385 requireInitialization();
386 return sFactoryResetUrl;
John Reck35e9dd62011-04-25 09:01:54 -0700387 }
388
389 public LayoutAlgorithm getLayoutAlgorithm() {
390 LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
391 if (autofitPages()) {
Tarun Nainani003bec52014-07-02 02:20:34 -0700392 layoutAlgorithm = LayoutAlgorithm.TEXT_AUTOSIZING;
John Reck35e9dd62011-04-25 09:01:54 -0700393 }
394 if (isDebugEnabled()) {
395 if (isSmallScreen()) {
396 layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
Ben Murdochef671652010-11-25 17:17:58 +0000397 } else {
John Reck35e9dd62011-04-25 09:01:54 -0700398 if (isNormalLayout()) {
399 layoutAlgorithm = LayoutAlgorithm.NORMAL;
400 } else {
401 layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
402 }
Ben Murdochef671652010-11-25 17:17:58 +0000403 }
John Reck35e9dd62011-04-25 09:01:54 -0700404 }
405 return layoutAlgorithm;
406 }
Ben Murdochef671652010-11-25 17:17:58 +0000407
John Reck35e9dd62011-04-25 09:01:54 -0700408 public int getPageCacheCapacity() {
John Reck78a6a1d2011-07-21 13:54:03 -0700409 requireInitialization();
410 return mPageCacheCapacity;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800411 }
412
John Reck35e9dd62011-04-25 09:01:54 -0700413 public WebStorageSizeManager getWebStorageSizeManager() {
John Reck78a6a1d2011-07-21 13:54:03 -0700414 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700415 return mWebStorageSizeManager;
416 }
417
John Reck35e9dd62011-04-25 09:01:54 -0700418 private String getAppCachePath() {
John Reck78a6a1d2011-07-21 13:54:03 -0700419 if (mAppCachePath == null) {
420 mAppCachePath = mContext.getDir("appcache", 0).getPath();
421 }
422 return mAppCachePath;
John Reck35e9dd62011-04-25 09:01:54 -0700423 }
424
425 private void updateSearchEngine(boolean force) {
426 String searchEngineName = getSearchEngineName();
427 if (force || mSearchEngine == null ||
428 !mSearchEngine.getName().equals(searchEngineName)) {
John Reck35e9dd62011-04-25 09:01:54 -0700429 mSearchEngine = SearchEngines.get(mContext, searchEngineName);
Narayan Kamath5119edd2011-02-23 15:49:17 +0000430 }
431 }
432
Bjorn Bringertd69f51d2010-09-13 14:06:41 +0100433 public SearchEngine getSearchEngine() {
John Reck35e9dd62011-04-25 09:01:54 -0700434 if (mSearchEngine == null) {
435 updateSearchEngine(false);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100436 }
John Reck35e9dd62011-04-25 09:01:54 -0700437 return mSearchEngine;
Ben Murdoch0cb81892010-10-08 12:41:33 +0100438 }
439
John Reck35e9dd62011-04-25 09:01:54 -0700440 public boolean isDebugEnabled() {
John Reckc477e712011-08-17 11:27:15 -0700441 requireInitialization();
John Reck35e9dd62011-04-25 09:01:54 -0700442 return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100443 }
444
John Reck35e9dd62011-04-25 09:01:54 -0700445 public void setDebugEnabled(boolean value) {
John Reck1da81882011-10-04 17:21:10 -0700446 Editor edit = mPrefs.edit();
447 edit.putBoolean(PREF_DEBUG_MENU, value);
448 if (!value) {
449 // Reset to "safe" value
450 edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
451 }
452 edit.apply();
Ben Murdoch6fa32ba2010-10-20 14:01:25 +0100453 }
454
John Reck35e9dd62011-04-25 09:01:54 -0700455 public void clearCache() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700456 if (mController != null) {
457 WebView current = mController.getCurrentWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 if (current != null) {
459 current.clearCache(true);
460 }
461 }
462 }
463
John Reck35e9dd62011-04-25 09:01:54 -0700464 public void clearCookies() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800465 CookieManager.getInstance().removeAllCookie();
466 }
467
John Reck35e9dd62011-04-25 09:01:54 -0700468 public void clearHistory() {
469 ContentResolver resolver = mContext.getContentResolver();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800470 Browser.clearHistory(resolver);
471 Browser.clearSearches(resolver);
472 }
473
John Reck35e9dd62011-04-25 09:01:54 -0700474 public void clearFormData() {
475 WebViewDatabase.getInstance(mContext).clearFormData();
Michael Kolb8233fac2010-10-26 16:08:53 -0700476 if (mController!= null) {
477 WebView currentTopView = mController.getCurrentTopWebView();
Henrik Baard794dc722010-02-19 16:28:06 +0100478 if (currentTopView != null) {
479 currentTopView.clearFormData();
480 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800481 }
482 }
483
Bijan Amirzada3bbb3a42014-06-17 12:06:18 -0700484 public WebView getTopWebView(){
485 if (mController!= null)
486 return mController.getCurrentTopWebView();
487
488 return null;
489 }
490
John Reck35e9dd62011-04-25 09:01:54 -0700491 public void clearPasswords() {
Panos Thomasfa948b82014-03-09 03:42:42 -0700492 // Clear password store maintained by SWE engine
493 WebSettings settings = null;
494 // find a valid settings object
495 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
496 while (iter.hasNext()) {
497 WeakReference<WebSettings> ref = iter.next();
498 settings = (WebSettings)ref.get();
499 if (settings != null) {
500 break;
501 }
502 }
503 if (settings != null) {
Panos Thomasdbaea4e2014-05-22 06:48:47 -0700504 settings.clearPasswords();
Panos Thomasfa948b82014-03-09 03:42:42 -0700505 }
Vivek Sekhare8a8ec22014-07-10 14:52:43 -0700506
507 // Clear passwords in WebView database
508 WebViewDatabase db = WebViewDatabase.getInstance(mContext);
509 db.clearHttpAuthUsernamePassword();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800510 }
511
John Reck35e9dd62011-04-25 09:01:54 -0700512 public void clearDatabases() {
Andrei Popescu824faeb2009-07-21 18:24:06 +0100513 WebStorage.getInstance().deleteAllData();
Steve Blockf344d032009-07-30 10:50:45 +0100514 }
515
John Reck35e9dd62011-04-25 09:01:54 -0700516 public void clearLocationAccess() {
Steve Blockf344d032009-07-30 10:50:45 +0100517 GeolocationPermissions.getInstance().clearAll();
Panos Thomasb298aad2014-10-22 12:24:21 -0700518 if (GeolocationPermissions.isIncognitoCreated()) {
519 GeolocationPermissions.getIncognitoInstance().clearAll();
520 }
Nicolas Roard78a98e42009-05-11 13:34:17 +0100521 }
522
John Reck35e9dd62011-04-25 09:01:54 -0700523 public void resetDefaultPreferences() {
John Reckbd315192011-07-29 10:05:47 -0700524 mPrefs.edit()
525 .clear()
John Reckbd315192011-07-29 10:05:47 -0700526 .apply();
Björn Isakssonc885a242012-06-05 17:19:04 +0200527 resetCachedValues();
John Reck35e9dd62011-04-25 09:01:54 -0700528 syncManagedSettings();
Grace Klobaf2c5c1b2009-05-26 10:48:31 -0700529 }
530
Björn Isakssonc885a242012-06-05 17:19:04 +0200531 private void resetCachedValues() {
532 updateSearchEngine(false);
533 }
534
John Reck35e9dd62011-04-25 09:01:54 -0700535 public AutoFillProfile getAutoFillProfile() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800536 // query the profile from components autofill database 524
537 if (mAutofillHandler.mAutoFillProfile == null &&
538 !mAutofillHandler.mAutoFillActiveProfileId.equals("")) {
539 WebSettings settings = null;
540 // find a valid settings object
541 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
542 while (iter.hasNext()) {
543 WeakReference<WebSettings> ref = iter.next();
544 settings = (WebSettings)ref.get();
545 if (settings != null) {
546 break;
547 }
548 }
549 if (settings != null) {
550 AutoFillProfile profile =
551 settings.getAutoFillProfile(mAutofillHandler.mAutoFillActiveProfileId);
552 mAutofillHandler.setAutoFillProfile(profile);
553 }
554 }
John Reck35e9dd62011-04-25 09:01:54 -0700555 return mAutofillHandler.getAutoFillProfile();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800556 }
557
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800558 public String getAutoFillProfileId() {
559 return mAutofillHandler.getAutoFillProfileId();
Shimeng (Simon) Wangf7392712010-03-10 16:44:31 -0800560 }
561
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800562 public void updateAutoFillProfile(AutoFillProfile profile) {
563 syncAutoFillProfile(profile);
564 }
565
566 private void syncAutoFillProfile(AutoFillProfile profile) {
567 synchronized (mManagedSettings) {
568 Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
569 while (iter.hasNext()) {
570 WeakReference<WebSettings> ref = iter.next();
571 WebSettings settings = (WebSettings)ref.get();
572 if (settings == null) {
573 iter.remove();
574 continue;
575 }
576 // update the profile only once.
577 settings.setAutoFillProfile(profile);
578 // Now we should have the guid
579 mAutofillHandler.setAutoFillProfile(profile);
580 break;
581 }
582 }
583 }
John Reck35e9dd62011-04-25 09:01:54 -0700584 public void toggleDebugSettings() {
585 setDebugEnabled(!isDebugEnabled());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800586 }
Ben Murdoch0cb81892010-10-08 12:41:33 +0100587
John Reckb8b2af82011-05-20 15:58:33 -0700588 public boolean hasDesktopUseragent(WebView view) {
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800589 return view != null && view.getUseDesktopUserAgent();
John Reckb8b2af82011-05-20 15:58:33 -0700590 }
591
592 public void toggleDesktopUseragent(WebView view) {
John Reckb0a86db2011-05-24 14:05:58 -0700593 if (view == null) {
594 return;
595 }
Vivek Sekhar7b3d2da2014-11-13 16:20:11 -0800596 if (hasDesktopUseragent(view))
597 view.setUseDesktopUserAgent(false, true);
598 else
599 view.setUseDesktopUserAgent(true, true);
John Reckb8b2af82011-05-20 15:58:33 -0700600 }
601
John Reck7dc444b2011-06-16 17:44:29 -0700602 public static int getAdjustedMinimumFontSize(int rawValue) {
603 rawValue++; // Preference starts at 0, min font at 1
604 if (rawValue > 1) {
605 rawValue += (MIN_FONT_SIZE_OFFSET - 2);
606 }
607 return rawValue;
608 }
609
John Reck5ba3c762011-09-14 15:00:15 -0700610 public int getAdjustedTextZoom(int rawValue) {
John Reck7dc444b2011-06-16 17:44:29 -0700611 rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
John Reck5ba3c762011-09-14 15:00:15 -0700612 return (int) ((rawValue + 100) * mFontSizeMult);
John Reck7dc444b2011-06-16 17:44:29 -0700613 }
614
615 static int getRawTextZoom(int percent) {
616 return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
617 }
618
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700619 public int getAdjustedDoubleTapZoom(int rawValue) {
620 rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP;
621 return (int) ((rawValue + 100) * mFontSizeMult);
622 }
623
624 static int getRawDoubleTapZoom(int percent) {
625 return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL;
626 }
627
John Reckcadae722011-07-25 11:36:17 -0700628 public SharedPreferences getPreferences() {
629 return mPrefs;
630 }
631
Victoria Lease96497832012-03-23 14:19:56 -0700632 // update connectivity-dependent options
633 public void updateConnectionType() {
634 ConnectivityManager cm = (ConnectivityManager)
635 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
636 String linkPrefetchPreference = getLinkPrefetchEnabled();
637 boolean linkPrefetchAllowed = linkPrefetchPreference.
638 equals(getLinkPrefetchAlwaysPreferenceString(mContext));
639 NetworkInfo ni = cm.getActiveNetworkInfo();
640 if (ni != null) {
641 switch (ni.getType()) {
642 case ConnectivityManager.TYPE_WIFI:
643 case ConnectivityManager.TYPE_ETHERNET:
644 case ConnectivityManager.TYPE_BLUETOOTH:
645 linkPrefetchAllowed |= linkPrefetchPreference.
646 equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
647 break;
648 case ConnectivityManager.TYPE_MOBILE:
649 case ConnectivityManager.TYPE_MOBILE_DUN:
650 case ConnectivityManager.TYPE_MOBILE_MMS:
651 case ConnectivityManager.TYPE_MOBILE_SUPL:
652 case ConnectivityManager.TYPE_WIMAX:
653 default:
654 break;
655 }
656 }
657 if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
658 mLinkPrefetchAllowed = linkPrefetchAllowed;
659 syncManagedSettings();
660 }
661 }
662
luxiaol62677b02013-07-22 07:54:49 +0800663 public String getDownloadPath() {
664 return mPrefs.getString(PREF_DOWNLOAD_PATH,
665 DownloadHandler.getDefaultDownloadPath(mContext));
666 }
John Reck35e9dd62011-04-25 09:01:54 -0700667 // -----------------------------
668 // getter/setters for accessibility_preferences.xml
669 // -----------------------------
Ben Murdoch0cb81892010-10-08 12:41:33 +0100670
John Reck7dc444b2011-06-16 17:44:29 -0700671 @Deprecated
672 private TextSize getTextSize() {
John Reck35e9dd62011-04-25 09:01:54 -0700673 String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
674 return TextSize.valueOf(textSize);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100675 }
676
John Reck35e9dd62011-04-25 09:01:54 -0700677 public int getMinimumFontSize() {
John Reck8fc22a12011-06-16 14:57:41 -0700678 int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
John Reck7dc444b2011-06-16 17:44:29 -0700679 return getAdjustedMinimumFontSize(minFont);
Ben Murdoch0cb81892010-10-08 12:41:33 +0100680 }
681
John Reck92f25f82011-04-26 16:57:10 -0700682 public boolean forceEnableUserScalable() {
683 return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
684 }
685
John Reck7dc444b2011-06-16 17:44:29 -0700686 public int getTextZoom() {
John Reck78a6a1d2011-07-21 13:54:03 -0700687 requireInitialization();
John Reck7dc444b2011-06-16 17:44:29 -0700688 int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
689 return getAdjustedTextZoom(textZoom);
690 }
691
692 public void setTextZoom(int percent) {
693 mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
694 }
695
Mangesh Ghiware67f45c22011-10-12 14:43:32 -0700696 public int getDoubleTapZoom() {
697 requireInitialization();
698 int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5);
699 return getAdjustedDoubleTapZoom(doubleTapZoom);
700 }
701
702 public void setDoubleTapZoom(int percent) {
703 mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply();
704 }
705
John Reck35e9dd62011-04-25 09:01:54 -0700706 // -----------------------------
707 // getter/setters for advanced_preferences.xml
708 // -----------------------------
Ben Murdoch23da30e2010-10-26 15:18:44 +0100709
John Reck35e9dd62011-04-25 09:01:54 -0700710 public String getSearchEngineName() {
luxiaol221b3932013-07-19 15:27:57 +0800711 String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value);
712 if (defaultSearchEngineValue == null) {
713 defaultSearchEngineValue = SearchEngine.GOOGLE;
714 }
715 return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue);
Ben Murdoch23da30e2010-10-26 15:18:44 +0100716 }
John Reck63bb6872010-12-01 19:29:32 -0800717
Michael Kolb8d772b02012-01-19 13:56:00 -0800718 public boolean allowAppTabs() {
719 return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false);
720 }
721
John Reck35e9dd62011-04-25 09:01:54 -0700722 public boolean openInBackground() {
723 return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
John Reck63bb6872010-12-01 19:29:32 -0800724 }
John Reck35e9dd62011-04-25 09:01:54 -0700725
726 public boolean enableJavascript() {
727 return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
728 }
729
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800730 public boolean enableMemoryMonitor() {
731 return mPrefs.getBoolean(PREF_ENABLE_MEMORY_MONITOR, true);
732 }
733
Tarun Nainani8eb00912014-07-17 12:28:32 -0700734 public boolean allowMediaDownloads() {
Panos Thomas4bdb5252014-11-13 16:20:11 -0800735 // Return false if preference is not exposed to user
736 if (!BrowserConfig.getInstance(mContext)
737 .hasFeature(BrowserConfig.Feature.ALLOW_MEDIA_DOWNLOADS))
738 return false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700739
Panos Thomas4bdb5252014-11-13 16:20:11 -0800740 // Otherwise, look at default value
741 boolean defaultAllowMediaDownloadsValue = mController.getContext()
742 .getResources().getBoolean(R.bool.def_allow_media_downloads);
743
744 // If preference is not saved, save default value
745 if (!mPrefs.contains(PREF_ALLOW_MEDIA_DOWNLOADS)){
Tarun Nainani8eb00912014-07-17 12:28:32 -0700746 Editor edit = mPrefs.edit();
Panos Thomas4bdb5252014-11-13 16:20:11 -0800747 edit.putBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700748 edit.apply();
749 }
750
Panos Thomas4bdb5252014-11-13 16:20:11 -0800751 return mPrefs.getBoolean(PREF_ALLOW_MEDIA_DOWNLOADS, defaultAllowMediaDownloadsValue);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700752 }
753
John Reck35e9dd62011-04-25 09:01:54 -0700754 public boolean loadPageInOverviewMode() {
755 return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
756 }
757
758 public boolean autofitPages() {
759 return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
760 }
761
762 public boolean blockPopupWindows() {
763 return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
764 }
765
766 public boolean loadImages() {
767 return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
768 }
769
770 public String getDefaultTextEncoding() {
Tarun Nainani95b79682014-12-09 09:38:04 -0800771 String autoDetect = mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, "auto");
772 if(autoDetect.equalsIgnoreCase("auto")) {
773 return mContext.getResources().getString(R.string.pref_default_text_encoding_default);
774 }
775 return autoDetect;
John Reck35e9dd62011-04-25 09:01:54 -0700776 }
777
778 // -----------------------------
779 // getter/setters for general_preferences.xml
780 // -----------------------------
781
782 public String getHomePage() {
John Reck35e9dd62011-04-25 09:01:54 -0700783 return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
784 }
785
786 public void setHomePage(String value) {
787 mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
788 }
789
790 public boolean isAutofillEnabled() {
791 return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
792 }
793
794 public void setAutofillEnabled(boolean value) {
795 mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
796 }
797
798 // -----------------------------
799 // getter/setters for debug_preferences.xml
800 // -----------------------------
801
802 public boolean isHardwareAccelerated() {
John Reckf48314f2011-04-27 17:52:17 -0700803 if (!isDebugEnabled()) {
John Reck35e9dd62011-04-25 09:01:54 -0700804 return true;
805 }
806 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
807 }
808
Derek Sollenberger31adf672011-07-08 11:31:30 -0400809 public boolean isSkiaHardwareAccelerated() {
810 if (!isDebugEnabled()) {
811 return false;
812 }
813 return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false);
814 }
815
John Reck35e9dd62011-04-25 09:01:54 -0700816 // -----------------------------
817 // getter/setters for hidden_debug_preferences.xml
818 // -----------------------------
819
820 public boolean enableVisualIndicator() {
821 if (!isDebugEnabled()) {
822 return false;
823 }
824 return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
825 }
826
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700827 public boolean enableCpuUploadPath() {
828 if (!isDebugEnabled()) {
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700829 return false;
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700830 }
Teng-Hui Zhudbe001b2011-09-30 10:37:01 -0700831 return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false);
Teng-Hui Zhu85de57a2011-09-22 15:34:29 -0700832 }
833
John Reck35e9dd62011-04-25 09:01:54 -0700834 public boolean isSmallScreen() {
835 if (!isDebugEnabled()) {
836 return false;
837 }
838 return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
839 }
840
841 public boolean isWideViewport() {
842 if (!isDebugEnabled()) {
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800843 return true;
John Reck35e9dd62011-04-25 09:01:54 -0700844 }
Panos Thomas3f35d8d2014-11-08 22:40:23 -0800845 return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
John Reck35e9dd62011-04-25 09:01:54 -0700846 }
847
848 public boolean isNormalLayout() {
849 if (!isDebugEnabled()) {
850 return false;
851 }
852 return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
853 }
854
855 public boolean isTracing() {
856 if (!isDebugEnabled()) {
857 return false;
858 }
859 return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
860 }
861
862 public boolean enableLightTouch() {
863 if (!isDebugEnabled()) {
864 return false;
865 }
866 return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
867 }
868
869 public boolean enableNavDump() {
870 if (!isDebugEnabled()) {
871 return false;
872 }
873 return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
874 }
875
876 public String getJsEngineFlags() {
877 if (!isDebugEnabled()) {
878 return "";
879 }
880 return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
881 }
882
883 // -----------------------------
884 // getter/setters for lab_preferences.xml
885 // -----------------------------
886
John Reck35e9dd62011-04-25 09:01:54 -0700887 public boolean useMostVisitedHomepage() {
John Reck961d35d2011-06-23 09:45:54 -0700888 return HomeProvider.MOST_VISITED.equals(getHomePage());
John Reck35e9dd62011-04-25 09:01:54 -0700889 }
890
Michael Kolbc38c6042011-04-27 10:46:06 -0700891 public boolean useFullscreen() {
892 return mPrefs.getBoolean(PREF_FULLSCREEN, false);
893 }
894
John Reck2fd9d0e2011-07-15 11:13:48 -0700895 public boolean useInvertedRendering() {
896 return mPrefs.getBoolean(PREF_INVERTED, false);
897 }
898
Nicolas Roard5d513102011-08-03 15:35:34 -0700899 public float getInvertedContrast() {
900 return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f);
901 }
902
John Reck35e9dd62011-04-25 09:01:54 -0700903 // -----------------------------
904 // getter/setters for privacy_security_preferences.xml
905 // -----------------------------
906
907 public boolean showSecurityWarnings() {
908 return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
909 }
910
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700911 public boolean doNotTrack() {
912 return mPrefs.getBoolean(PREF_DO_NOT_TRACK, true);
913 }
914
John Reck35e9dd62011-04-25 09:01:54 -0700915 public boolean acceptCookies() {
916 return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
917 }
918
919 public boolean saveFormdata() {
920 return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
921 }
922
923 public boolean enableGeolocation() {
924 return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
925 }
926
927 public boolean rememberPasswords() {
928 return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
929 }
930
Michael Kolb14612442011-06-24 13:06:29 -0700931 // -----------------------------
932 // getter/setters for bandwidth_preferences.xml
933 // -----------------------------
934
Mathew Inwood467813f2011-09-02 15:43:17 +0100935 public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
936 return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
Michael Kolb14612442011-06-24 13:06:29 -0700937 }
Mathew Inwood467813f2011-09-02 15:43:17 +0100938
939 public static String getPreloadAlwaysPreferenceString(Context context) {
940 return context.getResources().getString(R.string.pref_data_preload_value_always);
941 }
942
Mathew Inwood825fba72011-10-04 14:52:52 +0100943 private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY =
944 "browser_default_preload_setting";
945
946 public String getDefaultPreloadSetting() {
947 String preload = Settings.Secure.getString(mContext.getContentResolver(),
948 DEAULT_PRELOAD_SECURE_SETTING_KEY);
949 if (preload == null) {
950 preload = mContext.getResources().getString(R.string.pref_data_preload_default_value);
951 }
952 return preload;
Mathew Inwood467813f2011-09-02 15:43:17 +0100953 }
954
955 public String getPreloadEnabled() {
956 return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
957 }
958
Victoria Lease96497832012-03-23 14:19:56 -0700959 public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
960 return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
961 }
962
963 public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
964 return context.getResources().getString(R.string.pref_link_prefetch_value_always);
965 }
966
967 private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
968 "browser_default_link_prefetch_setting";
969
970 public String getDefaultLinkPrefetchSetting() {
971 String preload = Settings.Secure.getString(mContext.getContentResolver(),
972 DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
973 if (preload == null) {
974 preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
975 }
976 return preload;
977 }
978
979 public String getLinkPrefetchEnabled() {
980 return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
981 }
982
George Mount3636d0a2011-11-21 09:08:21 -0800983 // -----------------------------
984 // getter/setters for browser recovery
985 // -----------------------------
986 /**
987 * The last time browser was started.
988 * @return The last browser start time as System.currentTimeMillis. This
989 * can be 0 if this is the first time or the last tab was closed.
990 */
991 public long getLastRecovered() {
992 return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
993 }
994
995 /**
996 * Sets the last browser start time.
997 * @param time The last time as System.currentTimeMillis that the browser
998 * was started. This should be set to 0 if the last tab is closed.
999 */
1000 public void setLastRecovered(long time) {
1001 mPrefs.edit()
1002 .putLong(KEY_LAST_RECOVERED, time)
1003 .apply();
1004 }
1005
1006 /**
1007 * Used to determine whether or not the previous browser run crashed. Once
1008 * the previous state has been determined, the value will be set to false
1009 * until a pause is received.
1010 * @return true if the last browser run was paused or false if it crashed.
1011 */
1012 public boolean wasLastRunPaused() {
1013 return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
1014 }
1015
1016 /**
1017 * Sets whether or not the last run was a pause or crash.
1018 * @param isPaused Set to true When a pause is received or false after
1019 * resuming.
1020 */
1021 public void setLastRunPaused(boolean isPaused) {
1022 mPrefs.edit()
1023 .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
1024 .apply();
1025 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001026}