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; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 25 | import android.content.res.AssetManager; |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 26 | import android.net.ConnectivityManager; |
| 27 | import android.net.NetworkInfo; |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 28 | import android.os.Build; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 29 | import android.os.Message; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 30 | import android.os.SystemProperties; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 31 | import android.preference.PreferenceManager; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 32 | import android.provider.Browser; |
Mathew Inwood | 825fba7 | 2011-10-04 14:52:52 +0100 | [diff] [blame] | 33 | import android.provider.Settings; |
John Reck | 5ba3c76 | 2011-09-14 15:00:15 -0700 | [diff] [blame] | 34 | import android.util.DisplayMetrics; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 35 | import android.util.Log; |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 36 | import android.util.Log; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 37 | import android.webkit.CookieManager; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 38 | import android.webkit.GeolocationPermissions; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 39 | import android.webkit.WebIconDatabase; |
| 40 | import android.webkit.WebSettings; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 41 | import android.webkit.WebSettings.LayoutAlgorithm; |
| 42 | import android.webkit.WebSettings.PluginState; |
| 43 | import android.webkit.WebSettings.TextSize; |
| 44 | import android.webkit.WebSettings.ZoomDensity; |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame] | 45 | import android.webkit.WebSettingsClassic; |
| 46 | import android.webkit.WebSettingsClassic.AutoFillProfile; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 47 | import android.webkit.WebStorage; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 48 | import android.webkit.WebView; |
| 49 | import android.webkit.WebViewDatabase; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 50 | |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 51 | import com.android.browser.homepages.HomeProvider; |
| 52 | import com.android.browser.provider.BrowserProvider; |
| 53 | import com.android.browser.search.SearchEngine; |
| 54 | import com.android.browser.search.SearchEngines; |
| 55 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 56 | import java.io.InputStream; |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 57 | import java.lang.Class; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 58 | import java.lang.ref.WeakReference; |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 59 | import java.lang.reflect.Method; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 60 | import java.util.Iterator; |
| 61 | import java.util.LinkedList; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 62 | import java.util.Locale; |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 63 | import java.util.WeakHashMap; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 64 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Class for managing settings |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 67 | */ |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 68 | public class BrowserSettings implements OnSharedPreferenceChangeListener, |
| 69 | PreferenceKeys { |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 70 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 71 | // TODO: Do something with this UserAgent stuff |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 72 | private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " + |
| 73 | "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " + |
| 74 | "Chrome/11.0.696.34 Safari/534.24"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 75 | |
| 76 | private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 77 | "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " + |
| 78 | "(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] | 79 | |
| 80 | private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 81 | "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " + |
| 82 | "(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] | 83 | |
| 84 | private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 85 | "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + |
| 86 | "(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] | 87 | |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 88 | private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
| 89 | "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " + |
| 90 | "(KHTML, like Gecko) Version/4.0 Safari/534.13"; |
| 91 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 92 | private static final String USER_AGENTS[] = { null, |
| 93 | DESKTOP_USERAGENT, |
| 94 | IPHONE_USERAGENT, |
| 95 | IPAD_USERAGENT, |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 96 | FROYO_USERAGENT, |
| 97 | HONEYCOMB_USERAGENT, |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 98 | }; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 99 | |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 100 | private static final String TAG = "BrowserSettings"; |
| 101 | |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 102 | // The minimum min font size |
| 103 | // Aka, the lower bounds for the min font size range |
| 104 | // which is 1:5..24 |
| 105 | private static final int MIN_FONT_SIZE_OFFSET = 5; |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 106 | // The initial value in the text zoom range |
| 107 | // This is what represents 100% in the SeekBarPreference range |
| 108 | private static final int TEXT_ZOOM_START_VAL = 10; |
| 109 | // The size of a single step in the text zoom range, in percent |
| 110 | private static final int TEXT_ZOOM_STEP = 5; |
Mangesh Ghiware | 67f45c2 | 2011-10-12 14:43:32 -0700 | [diff] [blame] | 111 | // The initial value in the double tap zoom range |
| 112 | // This is what represents 100% in the SeekBarPreference range |
| 113 | private static final int DOUBLE_TAP_ZOOM_START_VAL = 5; |
| 114 | // The size of a single step in the double tap zoom range, in percent |
| 115 | private static final int DOUBLE_TAP_ZOOM_STEP = 5; |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 116 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 117 | private static BrowserSettings sInstance; |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 118 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 119 | private Context mContext; |
| 120 | private SharedPreferences mPrefs; |
| 121 | private LinkedList<WeakReference<WebSettings>> mManagedSettings; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 122 | private Controller mController; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 123 | private WebStorageSizeManager mWebStorageSizeManager; |
| 124 | private AutofillHandler mAutofillHandler; |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 125 | private WeakHashMap<WebSettings, String> mCustomUserAgents; |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 126 | private static boolean sInitialized = false; |
John Reck | c477e71 | 2011-08-17 11:27:15 -0700 | [diff] [blame] | 127 | private boolean mNeedsSharedSync = true; |
John Reck | 5ba3c76 | 2011-09-14 15:00:15 -0700 | [diff] [blame] | 128 | private float mFontSizeMult = 1.0f; |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 129 | |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 130 | // Current state of network-dependent settings |
| 131 | private boolean mLinkPrefetchAllowed = true; |
| 132 | |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 133 | // Cached values |
| 134 | private int mPageCacheCapacity = 1; |
| 135 | private String mAppCachePath; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 136 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 137 | // Cached settings |
| 138 | private SearchEngine mSearchEngine; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 139 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 140 | private static String sFactoryResetUrl; |
| 141 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 142 | // add for carrier feature |
| 143 | private static Context sResPackageCtx; |
| 144 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 145 | public static void initialize(final Context context) { |
| 146 | sInstance = new BrowserSettings(context); |
| 147 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 148 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 149 | public static BrowserSettings getInstance() { |
| 150 | return sInstance; |
| 151 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 152 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 153 | private BrowserSettings(Context context) { |
Ben Murdoch | 914c559 | 2011-08-01 13:58:47 +0100 | [diff] [blame] | 154 | mContext = context.getApplicationContext(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 155 | mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 156 | mAutofillHandler = new AutofillHandler(mContext); |
| 157 | mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 158 | mCustomUserAgents = new WeakHashMap<WebSettings, String>(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 159 | mAutofillHandler.asyncLoadFromDb(); |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 160 | |
| 161 | // add for carrier feature |
| 162 | try { |
| 163 | sResPackageCtx = context.createPackageContext( |
| 164 | "com.android.browser.res", |
| 165 | Context.CONTEXT_IGNORE_SECURITY); |
| 166 | } catch (Exception e) { |
| 167 | Log.e("Res_Update", "Create Res Apk Failed"); |
| 168 | } |
| 169 | |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 170 | BackgroundHandler.execute(mSetup); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | public void setController(Controller controller) { |
| 174 | mController = controller; |
John Reck | c477e71 | 2011-08-17 11:27:15 -0700 | [diff] [blame] | 175 | if (sInitialized) { |
| 176 | syncSharedSettings(); |
| 177 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 178 | } |
| 179 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 180 | public void startManagingSettings(WebSettings settings) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 181 | |
John Reck | c477e71 | 2011-08-17 11:27:15 -0700 | [diff] [blame] | 182 | if (mNeedsSharedSync) { |
| 183 | syncSharedSettings(); |
| 184 | } |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 185 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 186 | synchronized (mManagedSettings) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 187 | syncStaticSettings(settings); |
| 188 | syncSetting(settings); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 189 | mManagedSettings.add(new WeakReference<WebSettings>(settings)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
John Reck | d1d8731 | 2012-03-08 13:25:00 -0800 | [diff] [blame] | 193 | public void stopManagingSettings(WebSettings settings) { |
| 194 | Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator(); |
| 195 | while (iter.hasNext()) { |
| 196 | WeakReference<WebSettings> ref = iter.next(); |
| 197 | if (ref.get() == settings) { |
| 198 | iter.remove(); |
| 199 | return; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 204 | private Runnable mSetup = new Runnable() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 205 | |
| 206 | @Override |
| 207 | public void run() { |
John Reck | 5ba3c76 | 2011-09-14 15:00:15 -0700 | [diff] [blame] | 208 | DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); |
| 209 | mFontSizeMult = metrics.scaledDensity / metrics.density; |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 210 | // the cost of one cached page is ~3M (measured using nytimes.com). For |
| 211 | // low end devices, we only cache one page. For high end devices, we try |
| 212 | // to cache more pages, currently choose 5. |
| 213 | if (ActivityManager.staticGetMemoryClass() > 16) { |
| 214 | mPageCacheCapacity = 5; |
| 215 | } |
| 216 | mWebStorageSizeManager = new WebStorageSizeManager(mContext, |
| 217 | new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), |
| 218 | new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); |
John Reck | 276b135 | 2011-09-02 15:47:33 -0700 | [diff] [blame] | 219 | // Workaround b/5254577 |
| 220 | mPrefs.registerOnSharedPreferenceChangeListener(BrowserSettings.this); |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 221 | if (Build.VERSION.CODENAME.equals("REL")) { |
| 222 | // This is a release build, always startup with debug disabled |
| 223 | setDebugEnabled(false); |
| 224 | } |
| 225 | if (mPrefs.contains(PREF_TEXT_SIZE)) { |
| 226 | /* |
| 227 | * Update from TextSize enum to zoom percent |
| 228 | * SMALLEST is 50% |
| 229 | * SMALLER is 75% |
| 230 | * NORMAL is 100% |
| 231 | * LARGER is 150% |
| 232 | * LARGEST is 200% |
| 233 | */ |
| 234 | switch (getTextSize()) { |
| 235 | case SMALLEST: |
| 236 | setTextZoom(50); |
| 237 | break; |
| 238 | case SMALLER: |
| 239 | setTextZoom(75); |
| 240 | break; |
| 241 | case LARGER: |
| 242 | setTextZoom(150); |
| 243 | break; |
| 244 | case LARGEST: |
| 245 | setTextZoom(200); |
| 246 | break; |
| 247 | } |
| 248 | mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); |
| 249 | } |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 250 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 251 | |
| 252 | // add for carrier homepage feature |
| 253 | String browserRes = SystemProperties.get("persist.env.c.browser.resource", "default"); |
| 254 | if ("cu".equals(browserRes)) { |
| 255 | int resID = sResPackageCtx.getResources().getIdentifier( |
| 256 | "homepage_base", "string", "com.android.browser.res"); |
| 257 | sFactoryResetUrl = sResPackageCtx.getResources().getString(resID); |
| 258 | } else if ("ct".equals(browserRes)) { |
| 259 | int resID = sResPackageCtx.getResources().getIdentifier( |
| 260 | "homepage_base", "string", "com.android.browser.res"); |
| 261 | sFactoryResetUrl = sResPackageCtx.getResources().getString(resID); |
| 262 | |
| 263 | int pathID = sResPackageCtx.getResources().getIdentifier( |
| 264 | "homepage_path", "string", "com.android.browser.res"); |
| 265 | String path = sResPackageCtx.getResources().getString(pathID); |
| 266 | Locale locale = Locale.getDefault(); |
| 267 | path = path.replace("%y", locale.getLanguage().toLowerCase()); |
| 268 | path = path.replace("%z", '_'+locale.getCountry().toLowerCase()); |
| 269 | boolean useCountry = true; |
| 270 | boolean useLanguage = true; |
| 271 | InputStream is = null; |
| 272 | AssetManager am = mContext.getAssets(); |
| 273 | try { |
| 274 | is = am.open(path); |
| 275 | } catch (Exception ignored) { |
| 276 | useCountry = false; |
| 277 | path = sResPackageCtx.getResources().getString(pathID); |
| 278 | path = path.replace("%y", locale.getLanguage().toLowerCase()); |
| 279 | path = path.replace("%z", ""); |
| 280 | try { |
| 281 | is = am.open(path); |
| 282 | } catch (Exception ignoredlanguage) { |
| 283 | useLanguage = false; |
| 284 | } |
| 285 | } finally { |
| 286 | if (is != null) { |
| 287 | try { |
| 288 | is.close(); |
| 289 | } catch (Exception ignored) {} |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (!useCountry && !useLanguage) { |
| 294 | sFactoryResetUrl = sFactoryResetUrl.replace("%y%z", "en"); |
| 295 | } else { |
| 296 | sFactoryResetUrl = sFactoryResetUrl.replace("%y", |
| 297 | locale.getLanguage().toLowerCase()); |
| 298 | sFactoryResetUrl = sFactoryResetUrl.replace("%z", useCountry ? |
| 299 | '_' + locale.getCountry().toLowerCase() : ""); |
| 300 | } |
| 301 | } else { |
| 302 | sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base); |
| 303 | } |
| 304 | |
kaiyiz | bf086ea | 2013-08-02 11:03:58 +0800 | [diff] [blame] | 305 | if (!mPrefs.contains(PREF_DEFAULT_TEXT_ENCODING)) { |
| 306 | if (!"default".equals(browserRes)) { |
| 307 | mPrefs.edit().putString(PREF_DEFAULT_TEXT_ENCODING, |
| 308 | "GBK").apply(); |
| 309 | } |
| 310 | } |
| 311 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 312 | if (sFactoryResetUrl.indexOf("{CID}") != -1) { |
| 313 | sFactoryResetUrl = sFactoryResetUrl.replace("{CID}", |
| 314 | BrowserProvider.getClientId(mContext.getContentResolver())); |
| 315 | } |
| 316 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 317 | synchronized (BrowserSettings.class) { |
| 318 | sInitialized = true; |
| 319 | BrowserSettings.class.notifyAll(); |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | }; |
| 323 | |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 324 | private static void requireInitialization() { |
| 325 | synchronized (BrowserSettings.class) { |
| 326 | while (!sInitialized) { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 327 | try { |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 328 | BrowserSettings.class.wait(); |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 329 | } catch (InterruptedException e) { |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 335 | /** |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 336 | * Syncs all the settings that have a Preference UI |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 337 | */ |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 338 | private void syncSetting(WebSettings settings) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 339 | settings.setGeolocationEnabled(enableGeolocation()); |
| 340 | settings.setJavaScriptEnabled(enableJavascript()); |
| 341 | settings.setLightTouchEnabled(enableLightTouch()); |
| 342 | settings.setNavDump(enableNavDump()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 343 | settings.setDefaultTextEncodingName(getDefaultTextEncoding()); |
| 344 | settings.setDefaultZoom(getDefaultZoom()); |
| 345 | settings.setMinimumFontSize(getMinimumFontSize()); |
| 346 | settings.setMinimumLogicalFontSize(getMinimumFontSize()); |
| 347 | settings.setPluginState(getPluginState()); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 348 | settings.setTextZoom(getTextZoom()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 349 | settings.setLayoutAlgorithm(getLayoutAlgorithm()); |
Steve Block | dc657fa | 2011-08-03 19:27:13 +0100 | [diff] [blame] | 350 | settings.setJavaScriptCanOpenWindowsAutomatically(!blockPopupWindows()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 351 | settings.setLoadsImagesAutomatically(loadImages()); |
| 352 | settings.setLoadWithOverviewMode(loadPageInOverviewMode()); |
| 353 | settings.setSavePassword(rememberPasswords()); |
| 354 | settings.setSaveFormData(saveFormdata()); |
| 355 | settings.setUseWideViewPort(isWideViewport()); |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 356 | |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 357 | // add for carrier useragent feature |
| 358 | String ua = null; |
| 359 | try { |
| 360 | Class c = Class.forName("com.qrd.useragent.UserAgentHandler"); |
| 361 | Object cObj = c.newInstance(); |
| 362 | Method m = c.getDeclaredMethod("getUAString", Context.class); |
| 363 | ua = (String)m.invoke(cObj, mContext); |
| 364 | } catch (Exception e) { |
| 365 | Log.e(TAG, "plug in Load failed, err " + e); |
| 366 | ua = mCustomUserAgents.get(settings); |
| 367 | } |
| 368 | |
John Reck | 4650033 | 2011-06-07 14:36:10 -0700 | [diff] [blame] | 369 | if (ua != null) { |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 370 | settings.setUserAgentString(ua); |
| 371 | } else { |
| 372 | settings.setUserAgentString(USER_AGENTS[getUserAgent()]); |
| 373 | } |
John Reck | 2fd9d0e | 2011-07-15 11:13:48 -0700 | [diff] [blame] | 374 | |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 375 | if (!(settings instanceof WebSettingsClassic)) return; |
| 376 | |
| 377 | WebSettingsClassic settingsClassic = (WebSettingsClassic) settings; |
| 378 | settingsClassic.setHardwareAccelSkiaEnabled(isSkiaHardwareAccelerated()); |
| 379 | settingsClassic.setShowVisualIndicator(enableVisualIndicator()); |
| 380 | settingsClassic.setForceUserScalable(forceEnableUserScalable()); |
| 381 | settingsClassic.setDoubleTapZoom(getDoubleTapZoom()); |
| 382 | settingsClassic.setAutoFillEnabled(isAutofillEnabled()); |
| 383 | settingsClassic.setAutoFillProfile(getAutoFillProfile()); |
| 384 | |
John Reck | ea17e78 | 2011-10-27 17:15:59 -0700 | [diff] [blame] | 385 | boolean useInverted = useInvertedRendering(); |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 386 | settingsClassic.setProperty(WebViewProperties.gfxInvertedScreen, |
John Reck | ea17e78 | 2011-10-27 17:15:59 -0700 | [diff] [blame] | 387 | useInverted ? "true" : "false"); |
| 388 | if (useInverted) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 389 | settingsClassic.setProperty(WebViewProperties.gfxInvertedScreenContrast, |
John Reck | ea17e78 | 2011-10-27 17:15:59 -0700 | [diff] [blame] | 390 | Float.toString(getInvertedContrast())); |
| 391 | } |
Nicolas Roard | 5d51310 | 2011-08-03 15:35:34 -0700 | [diff] [blame] | 392 | |
John Reck | ea17e78 | 2011-10-27 17:15:59 -0700 | [diff] [blame] | 393 | if (isDebugEnabled()) { |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 394 | settingsClassic.setProperty(WebViewProperties.gfxEnableCpuUploadPath, |
John Reck | ea17e78 | 2011-10-27 17:15:59 -0700 | [diff] [blame] | 395 | enableCpuUploadPath() ? "true" : "false"); |
| 396 | } |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 397 | |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 398 | settingsClassic.setLinkPrefetchEnabled(mLinkPrefetchAllowed); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 399 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 400 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 401 | /** |
| 402 | * Syncs all the settings that have no UI |
| 403 | * These cannot change, so we only need to set them once per WebSettings |
| 404 | */ |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 405 | private void syncStaticSettings(WebSettings settings) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 406 | settings.setDefaultFontSize(16); |
| 407 | settings.setDefaultFixedFontSize(13); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 408 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 409 | // WebView inside Browser doesn't want initial focus to be set. |
| 410 | settings.setNeedInitialFocus(false); |
| 411 | // Browser supports multiple windows |
| 412 | settings.setSupportMultipleWindows(true); |
| 413 | // enable smooth transition for better performance during panning or |
| 414 | // zooming |
| 415 | settings.setEnableSmoothTransition(true); |
| 416 | // disable content url access |
| 417 | settings.setAllowContentAccess(false); |
| 418 | |
| 419 | // HTML5 API flags |
| 420 | settings.setAppCacheEnabled(true); |
| 421 | settings.setDatabaseEnabled(true); |
| 422 | settings.setDomStorageEnabled(true); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 423 | |
| 424 | // HTML5 configuration parametersettings. |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 425 | settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 426 | settings.setAppCachePath(getAppCachePath()); |
| 427 | settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); |
| 428 | settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); |
Selim Gurun | 37bf044 | 2012-03-29 18:27:04 -0700 | [diff] [blame] | 429 | // origin policy for file access |
| 430 | settings.setAllowUniversalAccessFromFileURLs(false); |
| 431 | settings.setAllowFileAccessFromFileURLs(false); |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 432 | |
| 433 | if (!(settings instanceof WebSettingsClassic)) return; |
| 434 | |
| 435 | WebSettingsClassic settingsClassic = (WebSettingsClassic) settings; |
| 436 | settingsClassic.setPageCacheCapacity(getPageCacheCapacity()); |
| 437 | // WebView should be preserving the memory as much as possible. |
| 438 | // However, apps like browser wish to turn on the performance mode which |
| 439 | // would require more memory. |
| 440 | // TODO: We need to dynamically allocate/deallocate temporary memory for |
| 441 | // apps which are trying to use minimal memory. Currently, double |
| 442 | // buffering is always turned on, which is unnecessary. |
| 443 | settingsClassic.setProperty(WebViewProperties.gfxUseMinimalMemory, "false"); |
| 444 | settingsClassic.setWorkersEnabled(true); // This only affects V8. |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | private void syncSharedSettings() { |
John Reck | c477e71 | 2011-08-17 11:27:15 -0700 | [diff] [blame] | 448 | mNeedsSharedSync = false; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 449 | CookieManager.getInstance().setAcceptCookie(acceptCookies()); |
| 450 | if (mController != null) { |
| 451 | mController.setShouldShowErrorConsole(enableJavascriptConsole()); |
Shimeng (Simon) Wang | e83e906 | 2010-03-29 16:13:09 -0700 | [diff] [blame] | 452 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 453 | } |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 454 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 455 | private void syncManagedSettings() { |
| 456 | syncSharedSettings(); |
| 457 | synchronized (mManagedSettings) { |
| 458 | Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator(); |
| 459 | while (iter.hasNext()) { |
| 460 | WeakReference<WebSettings> ref = iter.next(); |
Jonathan Dixon | e1d6dfc | 2012-12-17 13:39:17 -0800 | [diff] [blame] | 461 | WebSettings settings = ref.get(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 462 | if (settings == null) { |
| 463 | iter.remove(); |
| 464 | continue; |
| 465 | } |
| 466 | syncSetting(settings); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 467 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 470 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 471 | @Override |
| 472 | public void onSharedPreferenceChanged( |
| 473 | SharedPreferences sharedPreferences, String key) { |
| 474 | syncManagedSettings(); |
| 475 | if (PREF_SEARCH_ENGINE.equals(key)) { |
| 476 | updateSearchEngine(false); |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 477 | } else if (PREF_FULLSCREEN.equals(key)) { |
Magnus Hallqvist | 47ed4b8 | 2012-08-31 13:30:39 +0200 | [diff] [blame] | 478 | if (mController != null && mController.getUi() != null) { |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 479 | mController.getUi().setFullscreen(useFullscreen()); |
| 480 | } |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 481 | } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) { |
Magnus Hallqvist | 47ed4b8 | 2012-08-31 13:30:39 +0200 | [diff] [blame] | 482 | if (mController != null && mController.getUi() != null) { |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 483 | mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false)); |
| 484 | } |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 485 | } else if (PREF_LINK_PREFETCH.equals(key)) { |
| 486 | updateConnectionType(); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 487 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 488 | } |
| 489 | |
John Reck | 961d35d | 2011-06-23 09:45:54 -0700 | [diff] [blame] | 490 | public static String getFactoryResetHomeUrl(Context context) { |
Ben Murdoch | aaa1f37 | 2011-07-25 15:40:58 +0100 | [diff] [blame] | 491 | requireInitialization(); |
| 492 | return sFactoryResetUrl; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | public LayoutAlgorithm getLayoutAlgorithm() { |
| 496 | LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 497 | if (autofitPages()) { |
| 498 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 499 | } |
| 500 | if (isDebugEnabled()) { |
| 501 | if (isSmallScreen()) { |
| 502 | layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN; |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 503 | } else { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 504 | if (isNormalLayout()) { |
| 505 | layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 506 | } else { |
| 507 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 508 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 509 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 510 | } |
| 511 | return layoutAlgorithm; |
| 512 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 513 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 514 | public int getPageCacheCapacity() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 515 | requireInitialization(); |
| 516 | return mPageCacheCapacity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 517 | } |
| 518 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 519 | public WebStorageSizeManager getWebStorageSizeManager() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 520 | requireInitialization(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 521 | return mWebStorageSizeManager; |
| 522 | } |
| 523 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 524 | private String getAppCachePath() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 525 | if (mAppCachePath == null) { |
| 526 | mAppCachePath = mContext.getDir("appcache", 0).getPath(); |
| 527 | } |
| 528 | return mAppCachePath; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | private void updateSearchEngine(boolean force) { |
| 532 | String searchEngineName = getSearchEngineName(); |
| 533 | if (force || mSearchEngine == null || |
| 534 | !mSearchEngine.getName().equals(searchEngineName)) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 535 | mSearchEngine = SearchEngines.get(mContext, searchEngineName); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 539 | public SearchEngine getSearchEngine() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 540 | if (mSearchEngine == null) { |
| 541 | updateSearchEngine(false); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 542 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 543 | return mSearchEngine; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 544 | } |
| 545 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 546 | public boolean isDebugEnabled() { |
John Reck | c477e71 | 2011-08-17 11:27:15 -0700 | [diff] [blame] | 547 | requireInitialization(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 548 | return mPrefs.getBoolean(PREF_DEBUG_MENU, false); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 549 | } |
| 550 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 551 | public void setDebugEnabled(boolean value) { |
John Reck | 1da8188 | 2011-10-04 17:21:10 -0700 | [diff] [blame] | 552 | Editor edit = mPrefs.edit(); |
| 553 | edit.putBoolean(PREF_DEBUG_MENU, value); |
| 554 | if (!value) { |
| 555 | // Reset to "safe" value |
| 556 | edit.putBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false); |
| 557 | } |
| 558 | edit.apply(); |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 559 | } |
| 560 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 561 | public void clearCache() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 562 | WebIconDatabase.getInstance().removeAllIcons(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 563 | if (mController != null) { |
| 564 | WebView current = mController.getCurrentWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 565 | if (current != null) { |
| 566 | current.clearCache(true); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 571 | public void clearCookies() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 572 | CookieManager.getInstance().removeAllCookie(); |
| 573 | } |
| 574 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 575 | public void clearHistory() { |
| 576 | ContentResolver resolver = mContext.getContentResolver(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 577 | Browser.clearHistory(resolver); |
| 578 | Browser.clearSearches(resolver); |
| 579 | } |
| 580 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 581 | public void clearFormData() { |
| 582 | WebViewDatabase.getInstance(mContext).clearFormData(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 583 | if (mController!= null) { |
| 584 | WebView currentTopView = mController.getCurrentTopWebView(); |
Henrik Baard | 794dc72 | 2010-02-19 16:28:06 +0100 | [diff] [blame] | 585 | if (currentTopView != null) { |
| 586 | currentTopView.clearFormData(); |
| 587 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 591 | public void clearPasswords() { |
| 592 | WebViewDatabase db = WebViewDatabase.getInstance(mContext); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 593 | db.clearUsernamePassword(); |
| 594 | db.clearHttpAuthUsernamePassword(); |
| 595 | } |
| 596 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 597 | public void clearDatabases() { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 598 | WebStorage.getInstance().deleteAllData(); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 599 | } |
| 600 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 601 | public void clearLocationAccess() { |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 602 | GeolocationPermissions.getInstance().clearAll(); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 603 | } |
| 604 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 605 | public void resetDefaultPreferences() { |
John Reck | bd31519 | 2011-07-29 10:05:47 -0700 | [diff] [blame] | 606 | // Preserve autologin setting |
| 607 | long gal = mPrefs.getLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, -1); |
| 608 | mPrefs.edit() |
| 609 | .clear() |
| 610 | .putLong(GoogleAccountLogin.PREF_AUTOLOGIN_TIME, gal) |
| 611 | .apply(); |
Björn Isaksson | c885a24 | 2012-06-05 17:19:04 +0200 | [diff] [blame] | 612 | resetCachedValues(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 613 | syncManagedSettings(); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Björn Isaksson | c885a24 | 2012-06-05 17:19:04 +0200 | [diff] [blame] | 616 | private void resetCachedValues() { |
| 617 | updateSearchEngine(false); |
| 618 | } |
| 619 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 620 | public AutoFillProfile getAutoFillProfile() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 621 | return mAutofillHandler.getAutoFillProfile(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 622 | } |
| 623 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 624 | public void setAutoFillProfile(AutoFillProfile profile, Message msg) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 625 | mAutofillHandler.setAutoFillProfile(profile, msg); |
Ben Murdoch | 273330a | 2011-07-08 18:37:22 +0100 | [diff] [blame] | 626 | // Auto-fill will reuse the same profile ID when making edits to the profile, |
| 627 | // so we need to force a settings sync (otherwise the SharedPreferences |
| 628 | // manager will optimise out the call to onSharedPreferenceChanged(), as |
| 629 | // it thinks nothing has changed). |
| 630 | syncManagedSettings(); |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 631 | } |
| 632 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 633 | public void toggleDebugSettings() { |
| 634 | setDebugEnabled(!isDebugEnabled()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 635 | } |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 636 | |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 637 | public boolean hasDesktopUseragent(WebView view) { |
| 638 | return view != null && mCustomUserAgents.get(view.getSettings()) != null; |
| 639 | } |
| 640 | |
| 641 | public void toggleDesktopUseragent(WebView view) { |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 642 | if (view == null) { |
| 643 | return; |
| 644 | } |
John Reck | b8b2af8 | 2011-05-20 15:58:33 -0700 | [diff] [blame] | 645 | WebSettings settings = view.getSettings(); |
| 646 | if (mCustomUserAgents.get(settings) != null) { |
| 647 | mCustomUserAgents.remove(settings); |
| 648 | settings.setUserAgentString(USER_AGENTS[getUserAgent()]); |
| 649 | } else { |
| 650 | mCustomUserAgents.put(settings, DESKTOP_USERAGENT); |
| 651 | settings.setUserAgentString(DESKTOP_USERAGENT); |
| 652 | } |
| 653 | } |
| 654 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 655 | public static int getAdjustedMinimumFontSize(int rawValue) { |
| 656 | rawValue++; // Preference starts at 0, min font at 1 |
| 657 | if (rawValue > 1) { |
| 658 | rawValue += (MIN_FONT_SIZE_OFFSET - 2); |
| 659 | } |
| 660 | return rawValue; |
| 661 | } |
| 662 | |
John Reck | 5ba3c76 | 2011-09-14 15:00:15 -0700 | [diff] [blame] | 663 | public int getAdjustedTextZoom(int rawValue) { |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 664 | rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP; |
John Reck | 5ba3c76 | 2011-09-14 15:00:15 -0700 | [diff] [blame] | 665 | return (int) ((rawValue + 100) * mFontSizeMult); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int getRawTextZoom(int percent) { |
| 669 | return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL; |
| 670 | } |
| 671 | |
Mangesh Ghiware | 67f45c2 | 2011-10-12 14:43:32 -0700 | [diff] [blame] | 672 | public int getAdjustedDoubleTapZoom(int rawValue) { |
| 673 | rawValue = (rawValue - DOUBLE_TAP_ZOOM_START_VAL) * DOUBLE_TAP_ZOOM_STEP; |
| 674 | return (int) ((rawValue + 100) * mFontSizeMult); |
| 675 | } |
| 676 | |
| 677 | static int getRawDoubleTapZoom(int percent) { |
| 678 | return (percent - 100) / DOUBLE_TAP_ZOOM_STEP + DOUBLE_TAP_ZOOM_START_VAL; |
| 679 | } |
| 680 | |
John Reck | cadae72 | 2011-07-25 11:36:17 -0700 | [diff] [blame] | 681 | public SharedPreferences getPreferences() { |
| 682 | return mPrefs; |
| 683 | } |
| 684 | |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 685 | // update connectivity-dependent options |
| 686 | public void updateConnectionType() { |
| 687 | ConnectivityManager cm = (ConnectivityManager) |
| 688 | mContext.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 689 | String linkPrefetchPreference = getLinkPrefetchEnabled(); |
| 690 | boolean linkPrefetchAllowed = linkPrefetchPreference. |
| 691 | equals(getLinkPrefetchAlwaysPreferenceString(mContext)); |
| 692 | NetworkInfo ni = cm.getActiveNetworkInfo(); |
| 693 | if (ni != null) { |
| 694 | switch (ni.getType()) { |
| 695 | case ConnectivityManager.TYPE_WIFI: |
| 696 | case ConnectivityManager.TYPE_ETHERNET: |
| 697 | case ConnectivityManager.TYPE_BLUETOOTH: |
| 698 | linkPrefetchAllowed |= linkPrefetchPreference. |
| 699 | equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext)); |
| 700 | break; |
| 701 | case ConnectivityManager.TYPE_MOBILE: |
| 702 | case ConnectivityManager.TYPE_MOBILE_DUN: |
| 703 | case ConnectivityManager.TYPE_MOBILE_MMS: |
| 704 | case ConnectivityManager.TYPE_MOBILE_SUPL: |
| 705 | case ConnectivityManager.TYPE_WIMAX: |
| 706 | default: |
| 707 | break; |
| 708 | } |
| 709 | } |
| 710 | if (mLinkPrefetchAllowed != linkPrefetchAllowed) { |
| 711 | mLinkPrefetchAllowed = linkPrefetchAllowed; |
| 712 | syncManagedSettings(); |
| 713 | } |
| 714 | } |
| 715 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 716 | // ----------------------------- |
| 717 | // getter/setters for accessibility_preferences.xml |
| 718 | // ----------------------------- |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 719 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 720 | @Deprecated |
| 721 | private TextSize getTextSize() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 722 | String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL"); |
| 723 | return TextSize.valueOf(textSize); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 724 | } |
| 725 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 726 | public int getMinimumFontSize() { |
John Reck | 8fc22a1 | 2011-06-16 14:57:41 -0700 | [diff] [blame] | 727 | int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 728 | return getAdjustedMinimumFontSize(minFont); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 729 | } |
| 730 | |
John Reck | 92f25f8 | 2011-04-26 16:57:10 -0700 | [diff] [blame] | 731 | public boolean forceEnableUserScalable() { |
| 732 | return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false); |
| 733 | } |
| 734 | |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 735 | public int getTextZoom() { |
John Reck | 78a6a1d | 2011-07-21 13:54:03 -0700 | [diff] [blame] | 736 | requireInitialization(); |
John Reck | 7dc444b | 2011-06-16 17:44:29 -0700 | [diff] [blame] | 737 | int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10); |
| 738 | return getAdjustedTextZoom(textZoom); |
| 739 | } |
| 740 | |
| 741 | public void setTextZoom(int percent) { |
| 742 | mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply(); |
| 743 | } |
| 744 | |
Mangesh Ghiware | 67f45c2 | 2011-10-12 14:43:32 -0700 | [diff] [blame] | 745 | public int getDoubleTapZoom() { |
| 746 | requireInitialization(); |
| 747 | int doubleTapZoom = mPrefs.getInt(PREF_DOUBLE_TAP_ZOOM, 5); |
| 748 | return getAdjustedDoubleTapZoom(doubleTapZoom); |
| 749 | } |
| 750 | |
| 751 | public void setDoubleTapZoom(int percent) { |
| 752 | mPrefs.edit().putInt(PREF_DOUBLE_TAP_ZOOM, getRawDoubleTapZoom(percent)).apply(); |
| 753 | } |
| 754 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 755 | // ----------------------------- |
| 756 | // getter/setters for advanced_preferences.xml |
| 757 | // ----------------------------- |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 758 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 759 | public String getSearchEngineName() { |
luxiaol | 221b393 | 2013-07-19 15:27:57 +0800 | [diff] [blame^] | 760 | String defaultSearchEngineValue = mContext.getString(R.string.default_search_engine_value); |
| 761 | if (defaultSearchEngineValue == null) { |
| 762 | defaultSearchEngineValue = SearchEngine.GOOGLE; |
| 763 | } |
| 764 | return mPrefs.getString(PREF_SEARCH_ENGINE, defaultSearchEngineValue); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 765 | } |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 766 | |
Michael Kolb | 8d772b0 | 2012-01-19 13:56:00 -0800 | [diff] [blame] | 767 | public boolean allowAppTabs() { |
| 768 | return mPrefs.getBoolean(PREF_ALLOW_APP_TABS, false); |
| 769 | } |
| 770 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 771 | public boolean openInBackground() { |
| 772 | return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 773 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 774 | |
| 775 | public boolean enableJavascript() { |
| 776 | return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true); |
| 777 | } |
| 778 | |
| 779 | // TODO: Cache |
| 780 | public PluginState getPluginState() { |
| 781 | String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON"); |
| 782 | return PluginState.valueOf(state); |
| 783 | } |
| 784 | |
| 785 | // TODO: Cache |
| 786 | public ZoomDensity getDefaultZoom() { |
| 787 | String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM"); |
| 788 | return ZoomDensity.valueOf(zoom); |
| 789 | } |
| 790 | |
| 791 | public boolean loadPageInOverviewMode() { |
| 792 | return mPrefs.getBoolean(PREF_LOAD_PAGE, true); |
| 793 | } |
| 794 | |
| 795 | public boolean autofitPages() { |
| 796 | return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true); |
| 797 | } |
| 798 | |
| 799 | public boolean blockPopupWindows() { |
| 800 | return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true); |
| 801 | } |
| 802 | |
| 803 | public boolean loadImages() { |
| 804 | return mPrefs.getBoolean(PREF_LOAD_IMAGES, true); |
| 805 | } |
| 806 | |
| 807 | public String getDefaultTextEncoding() { |
| 808 | return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null); |
| 809 | } |
| 810 | |
| 811 | // ----------------------------- |
| 812 | // getter/setters for general_preferences.xml |
| 813 | // ----------------------------- |
| 814 | |
| 815 | public String getHomePage() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 816 | return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext)); |
| 817 | } |
| 818 | |
| 819 | public void setHomePage(String value) { |
| 820 | mPrefs.edit().putString(PREF_HOMEPAGE, value).apply(); |
| 821 | } |
| 822 | |
| 823 | public boolean isAutofillEnabled() { |
| 824 | return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true); |
| 825 | } |
| 826 | |
| 827 | public void setAutofillEnabled(boolean value) { |
| 828 | mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply(); |
| 829 | } |
| 830 | |
| 831 | // ----------------------------- |
| 832 | // getter/setters for debug_preferences.xml |
| 833 | // ----------------------------- |
| 834 | |
| 835 | public boolean isHardwareAccelerated() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 836 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 837 | return true; |
| 838 | } |
| 839 | return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true); |
| 840 | } |
| 841 | |
Derek Sollenberger | 31adf67 | 2011-07-08 11:31:30 -0400 | [diff] [blame] | 842 | public boolean isSkiaHardwareAccelerated() { |
| 843 | if (!isDebugEnabled()) { |
| 844 | return false; |
| 845 | } |
| 846 | return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL_SKIA, false); |
| 847 | } |
| 848 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 849 | public int getUserAgent() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 850 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0")); |
| 854 | } |
| 855 | |
| 856 | // ----------------------------- |
| 857 | // getter/setters for hidden_debug_preferences.xml |
| 858 | // ----------------------------- |
| 859 | |
| 860 | public boolean enableVisualIndicator() { |
| 861 | if (!isDebugEnabled()) { |
| 862 | return false; |
| 863 | } |
| 864 | return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false); |
| 865 | } |
| 866 | |
Teng-Hui Zhu | 85de57a | 2011-09-22 15:34:29 -0700 | [diff] [blame] | 867 | public boolean enableCpuUploadPath() { |
| 868 | if (!isDebugEnabled()) { |
Teng-Hui Zhu | dbe001b | 2011-09-30 10:37:01 -0700 | [diff] [blame] | 869 | return false; |
Teng-Hui Zhu | 85de57a | 2011-09-22 15:34:29 -0700 | [diff] [blame] | 870 | } |
Teng-Hui Zhu | dbe001b | 2011-09-30 10:37:01 -0700 | [diff] [blame] | 871 | return mPrefs.getBoolean(PREF_ENABLE_CPU_UPLOAD_PATH, false); |
Teng-Hui Zhu | 85de57a | 2011-09-22 15:34:29 -0700 | [diff] [blame] | 872 | } |
| 873 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 874 | public boolean enableJavascriptConsole() { |
| 875 | if (!isDebugEnabled()) { |
| 876 | return false; |
| 877 | } |
| 878 | return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true); |
| 879 | } |
| 880 | |
| 881 | public boolean isSmallScreen() { |
| 882 | if (!isDebugEnabled()) { |
| 883 | return false; |
| 884 | } |
| 885 | return mPrefs.getBoolean(PREF_SMALL_SCREEN, false); |
| 886 | } |
| 887 | |
| 888 | public boolean isWideViewport() { |
| 889 | if (!isDebugEnabled()) { |
| 890 | return true; |
| 891 | } |
| 892 | return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true); |
| 893 | } |
| 894 | |
| 895 | public boolean isNormalLayout() { |
| 896 | if (!isDebugEnabled()) { |
| 897 | return false; |
| 898 | } |
| 899 | return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false); |
| 900 | } |
| 901 | |
| 902 | public boolean isTracing() { |
| 903 | if (!isDebugEnabled()) { |
| 904 | return false; |
| 905 | } |
| 906 | return mPrefs.getBoolean(PREF_ENABLE_TRACING, false); |
| 907 | } |
| 908 | |
| 909 | public boolean enableLightTouch() { |
| 910 | if (!isDebugEnabled()) { |
| 911 | return false; |
| 912 | } |
| 913 | return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false); |
| 914 | } |
| 915 | |
| 916 | public boolean enableNavDump() { |
| 917 | if (!isDebugEnabled()) { |
| 918 | return false; |
| 919 | } |
| 920 | return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false); |
| 921 | } |
| 922 | |
| 923 | public String getJsEngineFlags() { |
| 924 | if (!isDebugEnabled()) { |
| 925 | return ""; |
| 926 | } |
| 927 | return mPrefs.getString(PREF_JS_ENGINE_FLAGS, ""); |
| 928 | } |
| 929 | |
| 930 | // ----------------------------- |
| 931 | // getter/setters for lab_preferences.xml |
| 932 | // ----------------------------- |
| 933 | |
| 934 | public boolean useQuickControls() { |
| 935 | return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false); |
| 936 | } |
| 937 | |
| 938 | public boolean useMostVisitedHomepage() { |
John Reck | 961d35d | 2011-06-23 09:45:54 -0700 | [diff] [blame] | 939 | return HomeProvider.MOST_VISITED.equals(getHomePage()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 942 | public boolean useFullscreen() { |
| 943 | return mPrefs.getBoolean(PREF_FULLSCREEN, false); |
| 944 | } |
| 945 | |
John Reck | 2fd9d0e | 2011-07-15 11:13:48 -0700 | [diff] [blame] | 946 | public boolean useInvertedRendering() { |
| 947 | return mPrefs.getBoolean(PREF_INVERTED, false); |
| 948 | } |
| 949 | |
Nicolas Roard | 5d51310 | 2011-08-03 15:35:34 -0700 | [diff] [blame] | 950 | public float getInvertedContrast() { |
| 951 | return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f); |
| 952 | } |
| 953 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 954 | // ----------------------------- |
| 955 | // getter/setters for privacy_security_preferences.xml |
| 956 | // ----------------------------- |
| 957 | |
| 958 | public boolean showSecurityWarnings() { |
| 959 | return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true); |
| 960 | } |
| 961 | |
| 962 | public boolean acceptCookies() { |
| 963 | return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true); |
| 964 | } |
| 965 | |
| 966 | public boolean saveFormdata() { |
| 967 | return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true); |
| 968 | } |
| 969 | |
| 970 | public boolean enableGeolocation() { |
| 971 | return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true); |
| 972 | } |
| 973 | |
| 974 | public boolean rememberPasswords() { |
| 975 | return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true); |
| 976 | } |
| 977 | |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 978 | // ----------------------------- |
| 979 | // getter/setters for bandwidth_preferences.xml |
| 980 | // ----------------------------- |
| 981 | |
Mathew Inwood | 467813f | 2011-09-02 15:43:17 +0100 | [diff] [blame] | 982 | public static String getPreloadOnWifiOnlyPreferenceString(Context context) { |
| 983 | return context.getResources().getString(R.string.pref_data_preload_value_wifi_only); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 984 | } |
Mathew Inwood | 467813f | 2011-09-02 15:43:17 +0100 | [diff] [blame] | 985 | |
| 986 | public static String getPreloadAlwaysPreferenceString(Context context) { |
| 987 | return context.getResources().getString(R.string.pref_data_preload_value_always); |
| 988 | } |
| 989 | |
Mathew Inwood | 825fba7 | 2011-10-04 14:52:52 +0100 | [diff] [blame] | 990 | private static final String DEAULT_PRELOAD_SECURE_SETTING_KEY = |
| 991 | "browser_default_preload_setting"; |
| 992 | |
| 993 | public String getDefaultPreloadSetting() { |
| 994 | String preload = Settings.Secure.getString(mContext.getContentResolver(), |
| 995 | DEAULT_PRELOAD_SECURE_SETTING_KEY); |
| 996 | if (preload == null) { |
| 997 | preload = mContext.getResources().getString(R.string.pref_data_preload_default_value); |
| 998 | } |
| 999 | return preload; |
Mathew Inwood | 467813f | 2011-09-02 15:43:17 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | public String getPreloadEnabled() { |
| 1003 | return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting()); |
| 1004 | } |
| 1005 | |
Victoria Lease | 9649783 | 2012-03-23 14:19:56 -0700 | [diff] [blame] | 1006 | public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) { |
| 1007 | return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only); |
| 1008 | } |
| 1009 | |
| 1010 | public static String getLinkPrefetchAlwaysPreferenceString(Context context) { |
| 1011 | return context.getResources().getString(R.string.pref_link_prefetch_value_always); |
| 1012 | } |
| 1013 | |
| 1014 | private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY = |
| 1015 | "browser_default_link_prefetch_setting"; |
| 1016 | |
| 1017 | public String getDefaultLinkPrefetchSetting() { |
| 1018 | String preload = Settings.Secure.getString(mContext.getContentResolver(), |
| 1019 | DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY); |
| 1020 | if (preload == null) { |
| 1021 | preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value); |
| 1022 | } |
| 1023 | return preload; |
| 1024 | } |
| 1025 | |
| 1026 | public String getLinkPrefetchEnabled() { |
| 1027 | return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting()); |
| 1028 | } |
| 1029 | |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 1030 | // ----------------------------- |
| 1031 | // getter/setters for browser recovery |
| 1032 | // ----------------------------- |
| 1033 | /** |
| 1034 | * The last time browser was started. |
| 1035 | * @return The last browser start time as System.currentTimeMillis. This |
| 1036 | * can be 0 if this is the first time or the last tab was closed. |
| 1037 | */ |
| 1038 | public long getLastRecovered() { |
| 1039 | return mPrefs.getLong(KEY_LAST_RECOVERED, 0); |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * Sets the last browser start time. |
| 1044 | * @param time The last time as System.currentTimeMillis that the browser |
| 1045 | * was started. This should be set to 0 if the last tab is closed. |
| 1046 | */ |
| 1047 | public void setLastRecovered(long time) { |
| 1048 | mPrefs.edit() |
| 1049 | .putLong(KEY_LAST_RECOVERED, time) |
| 1050 | .apply(); |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Used to determine whether or not the previous browser run crashed. Once |
| 1055 | * the previous state has been determined, the value will be set to false |
| 1056 | * until a pause is received. |
| 1057 | * @return true if the last browser run was paused or false if it crashed. |
| 1058 | */ |
| 1059 | public boolean wasLastRunPaused() { |
| 1060 | return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false); |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * Sets whether or not the last run was a pause or crash. |
| 1065 | * @param isPaused Set to true When a pause is received or false after |
| 1066 | * resuming. |
| 1067 | */ |
| 1068 | public void setLastRunPaused(boolean isPaused) { |
| 1069 | mPrefs.edit() |
| 1070 | .putBoolean(KEY_LAST_RUN_PAUSED, isPaused) |
| 1071 | .apply(); |
| 1072 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1073 | } |