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