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