The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 20 | import android.content.ContentResolver; |
| 21 | import android.content.Context; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 22 | import android.content.SharedPreferences; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 23 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 24 | import android.os.Build; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 25 | import android.os.Message; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 26 | import android.preference.PreferenceManager; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 27 | import android.provider.Browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 28 | import android.webkit.CookieManager; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 29 | import android.webkit.GeolocationPermissions; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 30 | import android.webkit.WebIconDatabase; |
| 31 | import android.webkit.WebSettings; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 32 | import android.webkit.WebSettings.AutoFillProfile; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 33 | import android.webkit.WebSettings.LayoutAlgorithm; |
| 34 | import android.webkit.WebSettings.PluginState; |
| 35 | import android.webkit.WebSettings.TextSize; |
| 36 | import android.webkit.WebSettings.ZoomDensity; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 37 | import android.webkit.WebStorage; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 38 | import android.webkit.WebView; |
| 39 | import android.webkit.WebViewDatabase; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 40 | |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 41 | import com.android.browser.homepages.HomeProvider; |
| 42 | import com.android.browser.provider.BrowserProvider; |
| 43 | import com.android.browser.search.SearchEngine; |
| 44 | import com.android.browser.search.SearchEngines; |
| 45 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 46 | import java.lang.ref.WeakReference; |
| 47 | import java.util.Iterator; |
| 48 | import java.util.LinkedList; |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 49 | import java.util.WeakHashMap; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 50 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Class for managing settings |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 53 | */ |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 54 | public class BrowserSettings implements OnSharedPreferenceChangeListener, |
| 55 | PreferenceKeys { |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 56 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 57 | // TODO: Do something with this UserAgent stuff |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 58 | private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " + |
| 59 | "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " + |
| 60 | "Chrome/11.0.696.34 Safari/534.24"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 61 | |
| 62 | private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 63 | "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " + |
| 64 | "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 65 | |
| 66 | private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 67 | "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " + |
| 68 | "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"; |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 69 | |
| 70 | private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 71 | "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + |
| 72 | "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 73 | |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 74 | private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
| 75 | "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " + |
| 76 | "(KHTML, like Gecko) Version/4.0 Safari/534.13"; |
| 77 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 78 | private static final String USER_AGENTS[] = { null, |
| 79 | DESKTOP_USERAGENT, |
| 80 | IPHONE_USERAGENT, |
| 81 | IPAD_USERAGENT, |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 82 | FROYO_USERAGENT, |
| 83 | HONEYCOMB_USERAGENT, |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 84 | }; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 85 | |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 86 | // The minimum min font size |
| 87 | // Aka, the lower bounds for the min font size range |
| 88 | // which is 1:5..24 |
| 89 | private static final int MIN_FONT_SIZE_OFFSET = 5; |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 90 | // The initial value in the text zoom range |
| 91 | // This is what represents 100% in the SeekBarPreference range |
| 92 | private static final int TEXT_ZOOM_START_VAL = 10; |
| 93 | // The size of a single step in the text zoom range, in percent |
| 94 | private static final int TEXT_ZOOM_STEP = 5; |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 95 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 96 | private static BrowserSettings sInstance; |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 97 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 98 | private Context mContext; |
| 99 | private SharedPreferences mPrefs; |
| 100 | private LinkedList<WeakReference<WebSettings>> mManagedSettings; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 101 | private Controller mController; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 102 | private WebStorageSizeManager mWebStorageSizeManager; |
| 103 | private AutofillHandler mAutofillHandler; |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 104 | private WeakHashMap<WebSettings, String> mCustomUserAgents; |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 105 | private static boolean sInitialized = false; |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 106 | |
| 107 | // Cached values |
| 108 | private int mPageCacheCapacity = 1; |
| 109 | private String mAppCachePath; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 110 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 111 | // Cached settings |
| 112 | private SearchEngine mSearchEngine; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 113 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 114 | private static String sFactoryResetUrl; |
| 115 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 116 | public static void initialize(final Context context) { |
| 117 | sInstance = new BrowserSettings(context); |
| 118 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 119 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 120 | public static BrowserSettings getInstance() { |
| 121 | return sInstance; |
| 122 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 123 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 124 | private BrowserSettings(Context context) { |
Ben Murdoch | 914c559 | 2011-08-01 13:58:47 +0100 | [diff] [blame] | 125 | mContext = context.getApplicationContext(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 126 | mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 127 | mAutofillHandler = new AutofillHandler(mContext); |
| 128 | mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 129 | mCustomUserAgents = new WeakHashMap<WebSettings, String>(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 130 | mPrefs.registerOnSharedPreferenceChangeListener(this); |
| 131 | mAutofillHandler.asyncLoadFromDb(); |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 132 | BackgroundHandler.execute(mSetup); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | public void setController(Controller controller) { |
| 136 | mController = controller; |
| 137 | syncSharedSettings(); |
| 138 | |
| 139 | if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { |
| 140 | ((InstantSearchEngine) mSearchEngine).setController(mController); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 144 | public void startManagingSettings(WebSettings settings) { |
| 145 | synchronized (mManagedSettings) { |
| 146 | syncStaticSettings(settings); |
| 147 | syncSetting(settings); |
| 148 | mManagedSettings.add(new WeakReference<WebSettings>(settings)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 152 | private Runnable mSetup = new Runnable() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 153 | |
| 154 | @Override |
| 155 | public void run() { |
| 156 | // the cost of one cached page is ~3M (measured using nytimes.com). For |
| 157 | // low end devices, we only cache one page. For high end devices, we try |
| 158 | // to cache more pages, currently choose 5. |
| 159 | if (ActivityManager.staticGetMemoryClass() > 16) { |
| 160 | mPageCacheCapacity = 5; |
| 161 | } |
| 162 | mWebStorageSizeManager = new WebStorageSizeManager(mContext, |
| 163 | new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), |
| 164 | new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); |
| 165 | if (Build.VERSION.CODENAME.equals("REL")) { |
| 166 | // This is a release build, always startup with debug disabled |
| 167 | setDebugEnabled(false); |
| 168 | } |
| 169 | if (mPrefs.contains(PREF_TEXT_SIZE)) { |
| 170 | /* |
| 171 | * Update from TextSize enum to zoom percent |
| 172 | * SMALLEST is 50% |
| 173 | * SMALLER is 75% |
| 174 | * NORMAL is 100% |
| 175 | * LARGER is 150% |
| 176 | * LARGEST is 200% |
| 177 | */ |
| 178 | switch (getTextSize()) { |
| 179 | case SMALLEST: |
| 180 | setTextZoom(50); |
| 181 | break; |
| 182 | case SMALLER: |
| 183 | setTextZoom(75); |
| 184 | break; |
| 185 | case LARGER: |
| 186 | setTextZoom(150); |
| 187 | break; |
| 188 | case LARGEST: |
| 189 | setTextZoom(200); |
| 190 | break; |
| 191 | } |
| 192 | mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); |
| 193 | } |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 194 | |
| 195 | sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base); |
| 196 | if (sFactoryResetUrl.indexOf("{CID}") != -1) { |
| 197 | sFactoryResetUrl = sFactoryResetUrl.replace("{CID}", |
| 198 | BrowserProvider.getClientId(mContext.getContentResolver())); |
| 199 | } |
| 200 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 201 | synchronized (BrowserSettings.class) { |
| 202 | sInitialized = true; |
| 203 | BrowserSettings.class.notifyAll(); |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | }; |
| 207 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 208 | private static void requireInitialization() { |
| 209 | synchronized (BrowserSettings.class) { |
| 210 | while (!sInitialized) { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 211 | try { |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 212 | BrowserSettings.class.wait(); |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 213 | } catch (InterruptedException e) { |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 219 | /** |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 220 | * Syncs all the settings that have a Preference UI |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 221 | */ |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 222 | private void syncSetting(WebSettings settings) { |
| 223 | settings.setGeolocationEnabled(enableGeolocation()); |
| 224 | settings.setJavaScriptEnabled(enableJavascript()); |
| 225 | settings.setLightTouchEnabled(enableLightTouch()); |
| 226 | settings.setNavDump(enableNavDump()); |
Derek Sollenberger | 31adf67 | 2011-07-08 11:31:30 -0400 | [diff] [blame] | 227 | settings.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 228 | settings.setShowVisualIndicator(enableVisualIndicator()); |
| 229 | settings.setDefaultTextEncodingName(getDefaultTextEncoding()); |
| 230 | settings.setDefaultZoom(getDefaultZoom()); |
| 231 | settings.setMinimumFontSize(getMinimumFontSize()); |
| 232 | settings.setMinimumLogicalFontSize(getMinimumFontSize()); |
John Reck | 92f25f8 | 2011-04-26 16:57:10 -0700 | [diff] [blame] | 233 | settings.setForceUserScalable(forceEnableUserScalable()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 234 | settings.setPluginState(getPluginState()); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 235 | settings.setTextZoom(getTextZoom()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 236 | settings.setAutoFillEnabled(isAutofillEnabled()); |
| 237 | settings.setLayoutAlgorithm(getLayoutAlgorithm()); |
Steve Block | dc657fa | 2011-08-03 19:27:13 +0100 | [diff] [blame] | 238 | settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 239 | settings.setLoadsImagesAutomatically(loadImages()); |
| 240 | settings.setLoadWithOverviewMode(loadPageInOverviewMode()); |
| 241 | settings.setSavePassword(rememberPasswords()); |
| 242 | settings.setSaveFormData(saveFormdata()); |
| 243 | settings.setUseWideViewPort(isWideViewport()); |
| 244 | settings.setAutoFillProfile(getAutoFillProfile()); |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 245 | |
| 246 | String ua = mCustomUserAgents.get(settings); |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 247 | if (ua != null) { |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 248 | settings.setUserAgentString(ua); |
| 249 | } else { |
| 250 | settings.setUserAgentString(USER_AGENTS[getUserAgent()]); |
| 251 | } |
John Reck | 2fd9d0e | 2011-07-15 11:13:48 -0700 | [diff] [blame] | 252 | |
John Reck | eabe5da | 2011-08-08 13:24:13 -0700 | [diff] [blame] | 253 | settings.setProperty(WebViewProperties.gfxInvertedScreen, |
John Reck | 2fd9d0e | 2011-07-15 11:13:48 -0700 | [diff] [blame] | 254 | useInvertedRendering() ? "true" : "false"); |
Nicolas Roard | 5d51310 | 2011-08-03 15:35:34 -0700 | [diff] [blame] | 255 | |
John Reck | eabe5da | 2011-08-08 13:24:13 -0700 | [diff] [blame] | 256 | settings.setProperty(WebViewProperties.gfxInvertedScreenContrast, |
Nicolas Roard | 5d51310 | 2011-08-03 15:35:34 -0700 | [diff] [blame] | 257 | Float.toString(getInvertedContrast())); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 258 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 259 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 260 | /** |
| 261 | * Syncs all the settings that have no UI |
| 262 | * These cannot change, so we only need to set them once per WebSettings |
| 263 | */ |
| 264 | private void syncStaticSettings(WebSettings settings) { |
| 265 | settings.setDefaultFontSize(16); |
| 266 | settings.setDefaultFixedFontSize(13); |
| 267 | settings.setPageCacheCapacity(getPageCacheCapacity()); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 268 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 269 | // WebView inside Browser doesn't want initial focus to be set. |
| 270 | settings.setNeedInitialFocus(false); |
| 271 | // Browser supports multiple windows |
| 272 | settings.setSupportMultipleWindows(true); |
| 273 | // enable smooth transition for better performance during panning or |
| 274 | // zooming |
| 275 | settings.setEnableSmoothTransition(true); |
| 276 | // disable content url access |
| 277 | settings.setAllowContentAccess(false); |
| 278 | |
| 279 | // HTML5 API flags |
| 280 | settings.setAppCacheEnabled(true); |
| 281 | settings.setDatabaseEnabled(true); |
| 282 | settings.setDomStorageEnabled(true); |
| 283 | settings.setWorkersEnabled(true); // This only affects V8. |
| 284 | |
| 285 | // HTML5 configuration parametersettings. |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 286 | settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 287 | settings.setAppCachePath(getAppCachePath()); |
| 288 | settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); |
| 289 | settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); |
| 290 | } |
| 291 | |
| 292 | private void syncSharedSettings() { |
| 293 | CookieManager.getInstance().setAcceptCookie(acceptCookies()); |
| 294 | if (mController != null) { |
| 295 | mController.setShouldShowErrorConsole(enableJavascriptConsole()); |
Shimeng (Simon) Wang | e83e906 | 2010-03-29 16:13:09 -0700 | [diff] [blame] | 296 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 297 | } |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 298 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 299 | private void syncManagedSettings() { |
| 300 | syncSharedSettings(); |
| 301 | synchronized (mManagedSettings) { |
| 302 | Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator(); |
| 303 | while (iter.hasNext()) { |
| 304 | WeakReference<WebSettings> ref = iter.next(); |
| 305 | WebSettings settings = ref.get(); |
| 306 | if (settings == null) { |
| 307 | iter.remove(); |
| 308 | continue; |
| 309 | } |
| 310 | syncSetting(settings); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 311 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 314 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 315 | @Override |
| 316 | public void onSharedPreferenceChanged( |
| 317 | SharedPreferences sharedPreferences, String key) { |
| 318 | syncManagedSettings(); |
| 319 | if (PREF_SEARCH_ENGINE.equals(key)) { |
| 320 | updateSearchEngine(false); |
| 321 | } |
| 322 | if (PREF_USE_INSTANT_SEARCH.equals(key)) { |
| 323 | updateSearchEngine(true); |
| 324 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 325 | if (PREF_FULLSCREEN.equals(key)) { |
| 326 | if (mController.getUi() != null) { |
| 327 | mController.getUi().setFullscreen(useFullscreen()); |
| 328 | } |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 329 | } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) { |
| 330 | if (mController.getUi() != null) { |
| 331 | mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false)); |
| 332 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 333 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 334 | } |
| 335 | |
John Reck | 961d35d | 2011-06-23 09:45:54 -0700 | [diff] [blame] | 336 | public static String getFactoryResetHomeUrl(Context context) { |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 337 | requireInitialization(); |
| 338 | return sFactoryResetUrl; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | public LayoutAlgorithm getLayoutAlgorithm() { |
| 342 | LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 343 | if (autofitPages()) { |
| 344 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 345 | } |
| 346 | if (isDebugEnabled()) { |
| 347 | if (isSmallScreen()) { |
| 348 | layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN; |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 349 | } else { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 350 | if (isNormalLayout()) { |
| 351 | layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 352 | } else { |
| 353 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 354 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 355 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 356 | } |
| 357 | return layoutAlgorithm; |
| 358 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 359 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 360 | public int getPageCacheCapacity() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 361 | requireInitialization(); |
| 362 | return mPageCacheCapacity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 363 | } |
| 364 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 365 | public WebStorageSizeManager getWebStorageSizeManager() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 366 | requireInitialization(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 367 | return mWebStorageSizeManager; |
| 368 | } |
| 369 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 370 | private String getAppCachePath() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 371 | if (mAppCachePath == null) { |
| 372 | mAppCachePath = mContext.getDir("appcache", 0).getPath(); |
| 373 | } |
| 374 | return mAppCachePath; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | private void updateSearchEngine(boolean force) { |
| 378 | String searchEngineName = getSearchEngineName(); |
| 379 | if (force || mSearchEngine == null || |
| 380 | !mSearchEngine.getName().equals(searchEngineName)) { |
| 381 | if (mSearchEngine != null) { |
| 382 | if (mSearchEngine.supportsVoiceSearch()) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 383 | // One or more tabs could have been in voice search mode. |
| 384 | // Clear it, since the new SearchEngine may not support |
| 385 | // it, or may handle it differently. |
| 386 | for (int i = 0; i < mController.getTabControl().getTabCount(); i++) { |
| 387 | mController.getTabControl().getTab(i).revertVoiceSearchMode(); |
| 388 | } |
| 389 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 390 | mSearchEngine.close(); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 391 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 392 | mSearchEngine = SearchEngines.get(mContext, searchEngineName); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 393 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 394 | if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { |
| 395 | ((InstantSearchEngine) mSearchEngine).setController(mController); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 400 | public SearchEngine getSearchEngine() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 401 | if (mSearchEngine == null) { |
| 402 | updateSearchEngine(false); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 403 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 404 | return mSearchEngine; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 405 | } |
| 406 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 407 | public boolean isDebugEnabled() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 408 | requireInitialization(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 409 | return mPrefs.getBoolean(PREF_DEBUG_MENU, false); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 410 | } |
| 411 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 412 | public void setDebugEnabled(boolean value) { |
| 413 | mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply(); |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 414 | } |
| 415 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 416 | public void clearCache() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 417 | WebIconDatabase.getInstance().removeAllIcons(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 418 | if (mController != null) { |
| 419 | WebView current = mController.getCurrentWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 420 | if (current != null) { |
| 421 | current.clearCache(true); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 426 | public void clearCookies() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 427 | CookieManager.getInstance().removeAllCookie(); |
| 428 | } |
| 429 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 430 | public void clearHistory() { |
| 431 | ContentResolver resolver = mContext.getContentResolver(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 432 | Browser.clearHistory(resolver); |
| 433 | Browser.clearSearches(resolver); |
| 434 | } |
| 435 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 436 | public void clearFormData() { |
| 437 | WebViewDatabase.getInstance(mContext).clearFormData(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 438 | if (mController!= null) { |
| 439 | WebView currentTopView = mController.getCurrentTopWebView(); |
Henrik Baard | 794dc72 | 2010-02-19 16:28:06 +0100 | [diff] [blame] | 440 | if (currentTopView != null) { |
| 441 | currentTopView.clearFormData(); |
| 442 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 446 | public void clearPasswords() { |
| 447 | WebViewDatabase db = WebViewDatabase.getInstance(mContext); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 448 | db.clearUsernamePassword(); |
| 449 | db.clearHttpAuthUsernamePassword(); |
| 450 | } |
| 451 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 452 | public void clearDatabases() { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 453 | WebStorage.getInstance().deleteAllData(); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 454 | } |
| 455 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 456 | public void clearLocationAccess() { |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 457 | GeolocationPermissions.getInstance().clearAll(); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 458 | } |
| 459 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 460 | public void resetDefaultPreferences() { |
John Reck | bd31519 | 2011-07-29 10:05:47 -0700 | [diff] [blame] | 461 | // Preserve autologin setting |
| 462 | long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1); |
| 463 | mPrefs.edit() |
| 464 | .clear() |
| 465 | .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal) |
| 466 | .apply(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 467 | syncManagedSettings(); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 468 | } |
| 469 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 470 | public AutoFillProfile getAutoFillProfile() { |
| 471 | mAutofillHandler.waitForLoad(); |
| 472 | return mAutofillHandler.getAutoFillProfile(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 473 | } |
| 474 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 475 | public void setAutoFillProfile(AutoFillProfile profile, Message msg) { |
| 476 | mAutofillHandler.waitForLoad(); |
| 477 | mAutofillHandler.setAutoFillProfile(profile, msg); |
Ben Murdoch | 273330a | 2011-07-08 18:37:22 +0100 | [diff] [blame] | 478 | // Auto-fill will reuse the same profile ID when making edits to the profile, |
| 479 | // so we need to force a settings sync (otherwise the SharedPreferences |
| 480 | // manager will optimise out the call to onSharedPreferenceChanged(), as |
| 481 | // it thinks nothing has changed). |
| 482 | syncManagedSettings(); |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 483 | } |
| 484 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 485 | public void toggleDebugSettings() { |
| 486 | setDebugEnabled(!isDebugEnabled()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 487 | } |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 488 | |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 489 | public boolean hasDesktopUseragent(WebView view) { |
| 490 | return view != null && mCustomUserAgents.get(view.getSettings()) != null; |
| 491 | } |
| 492 | |
| 493 | public void toggleDesktopUseragent(WebView view) { |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 494 | if (view == null) { |
| 495 | return; |
| 496 | } |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 497 | WebSettings settings = view.getSettings(); |
| 498 | if (mCustomUserAgents.get(settings) != null) { |
| 499 | mCustomUserAgents.remove(settings); |
| 500 | settings.setUserAgentString(USER_AGENTS[getUserAgent()]); |
| 501 | } else { |
| 502 | mCustomUserAgents.put(settings, DESKTOP_USERAGENT); |
| 503 | settings.setUserAgentString(DESKTOP_USERAGENT); |
| 504 | } |
| 505 | } |
| 506 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 507 | public static int getAdjustedMinimumFontSize(int rawValue) { |
| 508 | rawValue++; // Preference starts at 0, min font at 1 |
| 509 | if (rawValue > 1) { |
| 510 | rawValue += (MIN_FONT_SIZE_OFFSET - 2); |
| 511 | } |
| 512 | return rawValue; |
| 513 | } |
| 514 | |
| 515 | public static int getAdjustedTextZoom(int rawValue) { |
| 516 | rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP; |
| 517 | return rawValue + 100; |
| 518 | } |
| 519 | |
| 520 | static int getRawTextZoom(int percent) { |
| 521 | return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL; |
| 522 | } |
| 523 | |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 524 | public SharedPreferences getPreferences() { |
| 525 | return mPrefs; |
| 526 | } |
| 527 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 528 | // ----------------------------- |
| 529 | // getter/setters for accessibility_preferences.xml |
| 530 | // ----------------------------- |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 531 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 532 | @Deprecated |
| 533 | private TextSize getTextSize() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 534 | String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL"); |
| 535 | return TextSize.valueOf(textSize); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 536 | } |
| 537 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 538 | public int getMinimumFontSize() { |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 539 | int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 540 | return getAdjustedMinimumFontSize(minFont); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 541 | } |
| 542 | |
John Reck | 92f25f8 | 2011-04-26 16:57:10 -0700 | [diff] [blame] | 543 | public boolean forceEnableUserScalable() { |
| 544 | return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false); |
| 545 | } |
| 546 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 547 | public int getTextZoom() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 548 | requireInitialization(); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 549 | int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10); |
| 550 | return getAdjustedTextZoom(textZoom); |
| 551 | } |
| 552 | |
| 553 | public void setTextZoom(int percent) { |
| 554 | mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply(); |
| 555 | } |
| 556 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 557 | // ----------------------------- |
| 558 | // getter/setters for advanced_preferences.xml |
| 559 | // ----------------------------- |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 560 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 561 | public String getSearchEngineName() { |
| 562 | return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 563 | } |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 564 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 565 | public boolean openInBackground() { |
| 566 | return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 567 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 568 | |
| 569 | public boolean enableJavascript() { |
| 570 | return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true); |
| 571 | } |
| 572 | |
| 573 | // TODO: Cache |
| 574 | public PluginState getPluginState() { |
| 575 | String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON"); |
| 576 | return PluginState.valueOf(state); |
| 577 | } |
| 578 | |
| 579 | // TODO: Cache |
| 580 | public ZoomDensity getDefaultZoom() { |
| 581 | String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM"); |
| 582 | return ZoomDensity.valueOf(zoom); |
| 583 | } |
| 584 | |
| 585 | public boolean loadPageInOverviewMode() { |
| 586 | return mPrefs.getBoolean(PREF_LOAD_PAGE, true); |
| 587 | } |
| 588 | |
| 589 | public boolean autofitPages() { |
| 590 | return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true); |
| 591 | } |
| 592 | |
| 593 | public boolean blockPopupWindows() { |
| 594 | return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true); |
| 595 | } |
| 596 | |
| 597 | public boolean loadImages() { |
| 598 | return mPrefs.getBoolean(PREF_LOAD_IMAGES, true); |
| 599 | } |
| 600 | |
| 601 | public String getDefaultTextEncoding() { |
| 602 | return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null); |
| 603 | } |
| 604 | |
| 605 | // ----------------------------- |
| 606 | // getter/setters for general_preferences.xml |
| 607 | // ----------------------------- |
| 608 | |
| 609 | public String getHomePage() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 610 | return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext)); |
| 611 | } |
| 612 | |
| 613 | public void setHomePage(String value) { |
| 614 | mPrefs.edit().putString(PREF_HOMEPAGE, value).apply(); |
| 615 | } |
| 616 | |
| 617 | public boolean isAutofillEnabled() { |
| 618 | return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true); |
| 619 | } |
| 620 | |
| 621 | public void setAutofillEnabled(boolean value) { |
| 622 | mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply(); |
| 623 | } |
| 624 | |
| 625 | // ----------------------------- |
| 626 | // getter/setters for debug_preferences.xml |
| 627 | // ----------------------------- |
| 628 | |
| 629 | public boolean isHardwareAccelerated() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 630 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 631 | return true; |
| 632 | } |
| 633 | return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true); |
| 634 | } |
| 635 | |
Derek Sollenberger | 31adf67 | 2011-07-08 11:31:30 -0400 | [diff] [blame] | 636 | public boolean isSkiaHardwareAccelerated() { |
| 637 | if (!isDebugEnabled()) { |
| 638 | return false; |
| 639 | } |
| 640 | return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false); |
| 641 | } |
| 642 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 643 | public int getUserAgent() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 644 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0")); |
| 648 | } |
| 649 | |
| 650 | // ----------------------------- |
| 651 | // getter/setters for hidden_debug_preferences.xml |
| 652 | // ----------------------------- |
| 653 | |
| 654 | public boolean enableVisualIndicator() { |
| 655 | if (!isDebugEnabled()) { |
| 656 | return false; |
| 657 | } |
| 658 | return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false); |
| 659 | } |
| 660 | |
| 661 | public boolean enableJavascriptConsole() { |
| 662 | if (!isDebugEnabled()) { |
| 663 | return false; |
| 664 | } |
| 665 | return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true); |
| 666 | } |
| 667 | |
| 668 | public boolean isSmallScreen() { |
| 669 | if (!isDebugEnabled()) { |
| 670 | return false; |
| 671 | } |
| 672 | return mPrefs.getBoolean(PREF_SMALL_SCREEN, false); |
| 673 | } |
| 674 | |
| 675 | public boolean isWideViewport() { |
| 676 | if (!isDebugEnabled()) { |
| 677 | return true; |
| 678 | } |
| 679 | return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true); |
| 680 | } |
| 681 | |
| 682 | public boolean isNormalLayout() { |
| 683 | if (!isDebugEnabled()) { |
| 684 | return false; |
| 685 | } |
| 686 | return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false); |
| 687 | } |
| 688 | |
| 689 | public boolean isTracing() { |
| 690 | if (!isDebugEnabled()) { |
| 691 | return false; |
| 692 | } |
| 693 | return mPrefs.getBoolean(PREF_ENABLE_TRACING, false); |
| 694 | } |
| 695 | |
| 696 | public boolean enableLightTouch() { |
| 697 | if (!isDebugEnabled()) { |
| 698 | return false; |
| 699 | } |
| 700 | return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false); |
| 701 | } |
| 702 | |
| 703 | public boolean enableNavDump() { |
| 704 | if (!isDebugEnabled()) { |
| 705 | return false; |
| 706 | } |
| 707 | return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false); |
| 708 | } |
| 709 | |
| 710 | public String getJsEngineFlags() { |
| 711 | if (!isDebugEnabled()) { |
| 712 | return ""; |
| 713 | } |
| 714 | return mPrefs.getString(PREF_JS_ENGINE_FLAGS, ""); |
| 715 | } |
| 716 | |
| 717 | // ----------------------------- |
| 718 | // getter/setters for lab_preferences.xml |
| 719 | // ----------------------------- |
| 720 | |
| 721 | public boolean useQuickControls() { |
| 722 | return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false); |
| 723 | } |
| 724 | |
| 725 | public boolean useMostVisitedHomepage() { |
John Reck | 961d35d | 2011-06-23 09:45:54 -0700 | [diff] [blame] | 726 | return HomeProvider.MOST_VISITED.equals(getHomePage()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | public boolean useInstantSearch() { |
| 730 | return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false); |
| 731 | } |
| 732 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 733 | public boolean useFullscreen() { |
| 734 | return mPrefs.getBoolean(PREF_FULLSCREEN, false); |
| 735 | } |
| 736 | |
John Reck | 2fd9d0e | 2011-07-15 11:13:48 -0700 | [diff] [blame] | 737 | public boolean useInvertedRendering() { |
| 738 | return mPrefs.getBoolean(PREF_INVERTED, false); |
| 739 | } |
| 740 | |
Nicolas Roard | 5d51310 | 2011-08-03 15:35:34 -0700 | [diff] [blame] | 741 | public float getInvertedContrast() { |
| 742 | return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f); |
| 743 | } |
| 744 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 745 | // ----------------------------- |
| 746 | // getter/setters for privacy_security_preferences.xml |
| 747 | // ----------------------------- |
| 748 | |
| 749 | public boolean showSecurityWarnings() { |
| 750 | return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true); |
| 751 | } |
| 752 | |
| 753 | public boolean acceptCookies() { |
| 754 | return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true); |
| 755 | } |
| 756 | |
| 757 | public boolean saveFormdata() { |
| 758 | return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true); |
| 759 | } |
| 760 | |
| 761 | public boolean enableGeolocation() { |
| 762 | return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true); |
| 763 | } |
| 764 | |
| 765 | public boolean rememberPasswords() { |
| 766 | return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true); |
| 767 | } |
| 768 | |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 769 | // ----------------------------- |
| 770 | // getter/setters for bandwidth_preferences.xml |
| 771 | // ----------------------------- |
| 772 | |
| 773 | public boolean isPreloadEnabled() { |
| 774 | return mPrefs.getBoolean(PREF_DATA_PRELOAD, false); |
| 775 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 776 | } |