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