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