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