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