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