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