The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
John Reck | bafe58a | 2011-01-11 10:26:02 -0800 | [diff] [blame] | 19 | import com.android.browser.homepages.HomeProvider; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 20 | import com.android.browser.search.SearchEngine; |
| 21 | import com.android.browser.search.SearchEngines; |
| 22 | |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 24 | import android.content.ContentResolver; |
| 25 | import android.content.Context; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 26 | import android.content.SharedPreferences; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 27 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 28 | import android.os.Build; |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 29 | import android.os.Message; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 30 | import android.preference.PreferenceManager; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 31 | import android.provider.Browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 32 | import android.webkit.CookieManager; |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 33 | import android.webkit.GeolocationPermissions; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 34 | import android.webkit.WebIconDatabase; |
| 35 | import android.webkit.WebSettings; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 36 | import android.webkit.WebSettings.AutoFillProfile; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 37 | import android.webkit.WebSettings.LayoutAlgorithm; |
| 38 | import android.webkit.WebSettings.PluginState; |
| 39 | import android.webkit.WebSettings.TextSize; |
| 40 | import android.webkit.WebSettings.ZoomDensity; |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 41 | import android.webkit.WebStorage; |
John Reck | 812d2d6 | 2011-01-18 14:16:15 -0800 | [diff] [blame] | 42 | import android.webkit.WebView; |
| 43 | import android.webkit.WebViewDatabase; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 44 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 45 | import java.lang.ref.WeakReference; |
| 46 | import java.util.Iterator; |
| 47 | import java.util.LinkedList; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 48 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Class for managing settings |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 51 | */ |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 52 | public class BrowserSettings implements OnSharedPreferenceChangeListener, |
| 53 | PreferenceKeys { |
Andrei Popescu | 0106870 | 2009-08-03 16:03:24 +0100 | [diff] [blame] | 54 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 55 | // TODO: Do something with this UserAgent stuff |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 56 | private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " + |
| 57 | "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " + |
| 58 | "Chrome/11.0.696.34 Safari/534.24"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 59 | |
| 60 | private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 61 | "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " + |
| 62 | "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 63 | |
| 64 | private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 65 | "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " + |
| 66 | "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10"; |
Bart Sears | f6915fb | 2010-07-08 19:58:22 -0700 | [diff] [blame] | 67 | |
| 68 | private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 69 | "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " + |
| 70 | "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 71 | |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 72 | private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " + |
| 73 | "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " + |
| 74 | "(KHTML, like Gecko) Version/4.0 Safari/534.13"; |
| 75 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 76 | private static final String USER_AGENTS[] = { null, |
| 77 | DESKTOP_USERAGENT, |
| 78 | IPHONE_USERAGENT, |
| 79 | IPAD_USERAGENT, |
John Reck | 7fd1e8f | 2011-04-27 18:22:57 -0700 | [diff] [blame] | 80 | FROYO_USERAGENT, |
| 81 | HONEYCOMB_USERAGENT, |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 82 | }; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 83 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 84 | private static BrowserSettings sInstance; |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 85 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 86 | private Context mContext; |
| 87 | private SharedPreferences mPrefs; |
| 88 | private LinkedList<WeakReference<WebSettings>> mManagedSettings; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 89 | private Controller mController; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 90 | private WebStorageSizeManager mWebStorageSizeManager; |
| 91 | private AutofillHandler mAutofillHandler; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 92 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 93 | // Cached settings |
| 94 | private SearchEngine mSearchEngine; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 95 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 96 | public static void initialize(final Context context) { |
| 97 | sInstance = new BrowserSettings(context); |
| 98 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 99 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 100 | public static BrowserSettings getInstance() { |
| 101 | return sInstance; |
| 102 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 103 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 104 | private BrowserSettings(Context context) { |
| 105 | mContext = context; |
| 106 | mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 107 | if (Build.VERSION.CODENAME.equals("REL")) { |
| 108 | // This is a release build, always startup with debug disabled |
| 109 | setDebugEnabled(false); |
| 110 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 111 | mAutofillHandler = new AutofillHandler(mContext); |
| 112 | mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); |
| 113 | mWebStorageSizeManager = new WebStorageSizeManager(mContext, |
| 114 | new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), |
| 115 | new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); |
| 116 | mPrefs.registerOnSharedPreferenceChangeListener(this); |
| 117 | mAutofillHandler.asyncLoadFromDb(); |
| 118 | } |
| 119 | |
| 120 | public void setController(Controller controller) { |
| 121 | mController = controller; |
| 122 | syncSharedSettings(); |
| 123 | |
| 124 | if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { |
| 125 | ((InstantSearchEngine) mSearchEngine).setController(mController); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 129 | public void startManagingSettings(WebSettings settings) { |
| 130 | synchronized (mManagedSettings) { |
| 131 | syncStaticSettings(settings); |
| 132 | syncSetting(settings); |
| 133 | mManagedSettings.add(new WeakReference<WebSettings>(settings)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 138 | * Syncs all the settings that have a Preference UI |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 139 | */ |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 140 | private void syncSetting(WebSettings settings) { |
| 141 | settings.setGeolocationEnabled(enableGeolocation()); |
| 142 | settings.setJavaScriptEnabled(enableJavascript()); |
| 143 | settings.setLightTouchEnabled(enableLightTouch()); |
| 144 | settings.setNavDump(enableNavDump()); |
| 145 | settings.setShowVisualIndicator(enableVisualIndicator()); |
| 146 | settings.setDefaultTextEncodingName(getDefaultTextEncoding()); |
| 147 | settings.setDefaultZoom(getDefaultZoom()); |
| 148 | settings.setMinimumFontSize(getMinimumFontSize()); |
| 149 | settings.setMinimumLogicalFontSize(getMinimumFontSize()); |
John Reck | 92f25f8 | 2011-04-26 16:57:10 -0700 | [diff] [blame] | 150 | settings.setForceUserScalable(forceEnableUserScalable()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 151 | settings.setPluginState(getPluginState()); |
| 152 | settings.setTextSize(getTextSize()); |
| 153 | settings.setUserAgentString(USER_AGENTS[getUserAgent()]); |
| 154 | settings.setAutoFillEnabled(isAutofillEnabled()); |
| 155 | settings.setLayoutAlgorithm(getLayoutAlgorithm()); |
| 156 | settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows()); |
| 157 | settings.setLoadsImagesAutomatically(loadImages()); |
| 158 | settings.setLoadWithOverviewMode(loadPageInOverviewMode()); |
| 159 | settings.setSavePassword(rememberPasswords()); |
| 160 | settings.setSaveFormData(saveFormdata()); |
| 161 | settings.setUseWideViewPort(isWideViewport()); |
| 162 | settings.setAutoFillProfile(getAutoFillProfile()); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 163 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 164 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 165 | /** |
| 166 | * Syncs all the settings that have no UI |
| 167 | * These cannot change, so we only need to set them once per WebSettings |
| 168 | */ |
| 169 | private void syncStaticSettings(WebSettings settings) { |
| 170 | settings.setDefaultFontSize(16); |
| 171 | settings.setDefaultFixedFontSize(13); |
| 172 | settings.setPageCacheCapacity(getPageCacheCapacity()); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 173 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 174 | // WebView inside Browser doesn't want initial focus to be set. |
| 175 | settings.setNeedInitialFocus(false); |
| 176 | // Browser supports multiple windows |
| 177 | settings.setSupportMultipleWindows(true); |
| 178 | // enable smooth transition for better performance during panning or |
| 179 | // zooming |
| 180 | settings.setEnableSmoothTransition(true); |
| 181 | // disable content url access |
| 182 | settings.setAllowContentAccess(false); |
| 183 | |
| 184 | // HTML5 API flags |
| 185 | settings.setAppCacheEnabled(true); |
| 186 | settings.setDatabaseEnabled(true); |
| 187 | settings.setDomStorageEnabled(true); |
| 188 | settings.setWorkersEnabled(true); // This only affects V8. |
| 189 | |
| 190 | // HTML5 configuration parametersettings. |
| 191 | settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize()); |
| 192 | settings.setAppCachePath(getAppCachePath()); |
| 193 | settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); |
| 194 | settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); |
| 195 | } |
| 196 | |
| 197 | private void syncSharedSettings() { |
| 198 | CookieManager.getInstance().setAcceptCookie(acceptCookies()); |
| 199 | if (mController != null) { |
| 200 | mController.setShouldShowErrorConsole(enableJavascriptConsole()); |
Shimeng (Simon) Wang | e83e906 | 2010-03-29 16:13:09 -0700 | [diff] [blame] | 201 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 202 | } |
Ramanan Rajeswaran | dd4f429 | 2009-03-24 20:41:19 -0700 | [diff] [blame] | 203 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 204 | private void syncManagedSettings() { |
| 205 | syncSharedSettings(); |
| 206 | synchronized (mManagedSettings) { |
| 207 | Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator(); |
| 208 | while (iter.hasNext()) { |
| 209 | WeakReference<WebSettings> ref = iter.next(); |
| 210 | WebSettings settings = ref.get(); |
| 211 | if (settings == null) { |
| 212 | iter.remove(); |
| 213 | continue; |
| 214 | } |
| 215 | syncSetting(settings); |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 216 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 219 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 220 | @Override |
| 221 | public void onSharedPreferenceChanged( |
| 222 | SharedPreferences sharedPreferences, String key) { |
| 223 | syncManagedSettings(); |
| 224 | if (PREF_SEARCH_ENGINE.equals(key)) { |
| 225 | updateSearchEngine(false); |
| 226 | } |
| 227 | if (PREF_USE_INSTANT_SEARCH.equals(key)) { |
| 228 | updateSearchEngine(true); |
| 229 | } |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 230 | if (PREF_FULLSCREEN.equals(key)) { |
| 231 | if (mController.getUi() != null) { |
| 232 | mController.getUi().setFullscreen(useFullscreen()); |
| 233 | } |
| 234 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static String getFactoryResetHomeUrl(Context context) { |
| 238 | String url = context.getResources().getString(R.string.homepage_base); |
| 239 | if (url.indexOf("{CID}") != -1) { |
| 240 | url = url.replace("{CID}", |
| 241 | BrowserProvider.getClientId(context.getContentResolver())); |
| 242 | } |
| 243 | return url; |
| 244 | } |
| 245 | |
| 246 | public LayoutAlgorithm getLayoutAlgorithm() { |
| 247 | LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 248 | if (autofitPages()) { |
| 249 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 250 | } |
| 251 | if (isDebugEnabled()) { |
| 252 | if (isSmallScreen()) { |
| 253 | layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN; |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 254 | } else { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 255 | if (isNormalLayout()) { |
| 256 | layoutAlgorithm = LayoutAlgorithm.NORMAL; |
| 257 | } else { |
| 258 | layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 259 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 260 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 261 | } |
| 262 | return layoutAlgorithm; |
| 263 | } |
Ben Murdoch | ef67165 | 2010-11-25 17:17:58 +0000 | [diff] [blame] | 264 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 265 | // TODO: Cache |
| 266 | public int getPageCacheCapacity() { |
| 267 | // the cost of one cached page is ~3M (measured using nytimes.com). For |
| 268 | // low end devices, we only cache one page. For high end devices, we try |
| 269 | // to cache more pages, currently choose 5. |
| 270 | if (ActivityManager.staticGetMemoryClass() > 16) { |
| 271 | return 5; |
| 272 | } else { |
| 273 | return 1; |
Grace Kloba | 9804c43 | 2009-12-02 11:07:40 -0800 | [diff] [blame] | 274 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 275 | } |
| 276 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 277 | public WebStorageSizeManager getWebStorageSizeManager() { |
| 278 | return mWebStorageSizeManager; |
| 279 | } |
| 280 | |
| 281 | // TODO: Cache |
| 282 | private String getAppCachePath() { |
| 283 | return mContext.getDir("appcache", 0).getPath(); |
| 284 | } |
| 285 | |
| 286 | private void updateSearchEngine(boolean force) { |
| 287 | String searchEngineName = getSearchEngineName(); |
| 288 | if (force || mSearchEngine == null || |
| 289 | !mSearchEngine.getName().equals(searchEngineName)) { |
| 290 | if (mSearchEngine != null) { |
| 291 | if (mSearchEngine.supportsVoiceSearch()) { |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 292 | // One or more tabs could have been in voice search mode. |
| 293 | // Clear it, since the new SearchEngine may not support |
| 294 | // it, or may handle it differently. |
| 295 | for (int i = 0; i < mController.getTabControl().getTabCount(); i++) { |
| 296 | mController.getTabControl().getTab(i).revertVoiceSearchMode(); |
| 297 | } |
| 298 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 299 | mSearchEngine.close(); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 300 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 301 | mSearchEngine = SearchEngines.get(mContext, searchEngineName); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 302 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 303 | if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) { |
| 304 | ((InstantSearchEngine) mSearchEngine).setController(mController); |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 309 | public SearchEngine getSearchEngine() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 310 | if (mSearchEngine == null) { |
| 311 | updateSearchEngine(false); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 312 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 313 | return mSearchEngine; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 314 | } |
| 315 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 316 | public boolean isDebugEnabled() { |
| 317 | return mPrefs.getBoolean(PREF_DEBUG_MENU, false); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 318 | } |
| 319 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 320 | public void setDebugEnabled(boolean value) { |
| 321 | mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply(); |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 322 | } |
| 323 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 324 | public void clearCache() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 325 | WebIconDatabase.getInstance().removeAllIcons(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 326 | if (mController != null) { |
| 327 | WebView current = mController.getCurrentWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 328 | if (current != null) { |
| 329 | current.clearCache(true); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 334 | public void clearCookies() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 335 | CookieManager.getInstance().removeAllCookie(); |
| 336 | } |
| 337 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 338 | public void clearHistory() { |
| 339 | ContentResolver resolver = mContext.getContentResolver(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 340 | Browser.clearHistory(resolver); |
| 341 | Browser.clearSearches(resolver); |
| 342 | } |
| 343 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 344 | public void clearFormData() { |
| 345 | WebViewDatabase.getInstance(mContext).clearFormData(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 346 | if (mController!= null) { |
| 347 | WebView currentTopView = mController.getCurrentTopWebView(); |
Henrik Baard | 794dc72 | 2010-02-19 16:28:06 +0100 | [diff] [blame] | 348 | if (currentTopView != null) { |
| 349 | currentTopView.clearFormData(); |
| 350 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 354 | public void clearPasswords() { |
| 355 | WebViewDatabase db = WebViewDatabase.getInstance(mContext); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 356 | db.clearUsernamePassword(); |
| 357 | db.clearHttpAuthUsernamePassword(); |
| 358 | } |
| 359 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 360 | public void clearDatabases() { |
Andrei Popescu | 824faeb | 2009-07-21 18:24:06 +0100 | [diff] [blame] | 361 | WebStorage.getInstance().deleteAllData(); |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 362 | } |
| 363 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 364 | public void clearLocationAccess() { |
Steve Block | f344d03 | 2009-07-30 10:50:45 +0100 | [diff] [blame] | 365 | GeolocationPermissions.getInstance().clearAll(); |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 366 | } |
| 367 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 368 | public void resetDefaultPreferences() { |
| 369 | mPrefs.edit().clear().apply(); |
| 370 | syncManagedSettings(); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 371 | } |
| 372 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 373 | public AutoFillProfile getAutoFillProfile() { |
| 374 | mAutofillHandler.waitForLoad(); |
| 375 | return mAutofillHandler.getAutoFillProfile(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 376 | } |
| 377 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 378 | public void setAutoFillProfile(AutoFillProfile profile, Message msg) { |
| 379 | mAutofillHandler.waitForLoad(); |
| 380 | mAutofillHandler.setAutoFillProfile(profile, msg); |
Shimeng (Simon) Wang | f739271 | 2010-03-10 16:44:31 -0800 | [diff] [blame] | 381 | } |
| 382 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 383 | public void toggleDebugSettings() { |
| 384 | setDebugEnabled(!isDebugEnabled()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 385 | } |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 386 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 387 | // ----------------------------- |
| 388 | // getter/setters for accessibility_preferences.xml |
| 389 | // ----------------------------- |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 390 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 391 | // TODO: Cache |
| 392 | public TextSize getTextSize() { |
| 393 | String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL"); |
| 394 | return TextSize.valueOf(textSize); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 395 | } |
| 396 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 397 | public int getMinimumFontSize() { |
| 398 | return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 399 | } |
| 400 | |
John Reck | 92f25f8 | 2011-04-26 16:57:10 -0700 | [diff] [blame] | 401 | public boolean forceEnableUserScalable() { |
| 402 | return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false); |
| 403 | } |
| 404 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 405 | // ----------------------------- |
| 406 | // getter/setters for advanced_preferences.xml |
| 407 | // ----------------------------- |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 408 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 409 | public String getSearchEngineName() { |
| 410 | return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE); |
Ben Murdoch | 23da30e | 2010-10-26 15:18:44 +0100 | [diff] [blame] | 411 | } |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 412 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 413 | public boolean openInBackground() { |
| 414 | return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 415 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 416 | |
| 417 | public boolean enableJavascript() { |
| 418 | return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true); |
| 419 | } |
| 420 | |
| 421 | // TODO: Cache |
| 422 | public PluginState getPluginState() { |
| 423 | String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON"); |
| 424 | return PluginState.valueOf(state); |
| 425 | } |
| 426 | |
| 427 | // TODO: Cache |
| 428 | public ZoomDensity getDefaultZoom() { |
| 429 | String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM"); |
| 430 | return ZoomDensity.valueOf(zoom); |
| 431 | } |
| 432 | |
| 433 | public boolean loadPageInOverviewMode() { |
| 434 | return mPrefs.getBoolean(PREF_LOAD_PAGE, true); |
| 435 | } |
| 436 | |
| 437 | public boolean autofitPages() { |
| 438 | return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true); |
| 439 | } |
| 440 | |
| 441 | public boolean blockPopupWindows() { |
| 442 | return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true); |
| 443 | } |
| 444 | |
| 445 | public boolean loadImages() { |
| 446 | return mPrefs.getBoolean(PREF_LOAD_IMAGES, true); |
| 447 | } |
| 448 | |
| 449 | public String getDefaultTextEncoding() { |
| 450 | return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null); |
| 451 | } |
| 452 | |
| 453 | // ----------------------------- |
| 454 | // getter/setters for general_preferences.xml |
| 455 | // ----------------------------- |
| 456 | |
| 457 | public String getHomePage() { |
| 458 | if (useMostVisitedHomepage()) { |
| 459 | return HomeProvider.MOST_VISITED; |
| 460 | } |
| 461 | return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext)); |
| 462 | } |
| 463 | |
| 464 | public void setHomePage(String value) { |
| 465 | mPrefs.edit().putString(PREF_HOMEPAGE, value).apply(); |
| 466 | } |
| 467 | |
| 468 | public boolean isAutofillEnabled() { |
| 469 | return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true); |
| 470 | } |
| 471 | |
| 472 | public void setAutofillEnabled(boolean value) { |
| 473 | mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply(); |
| 474 | } |
| 475 | |
| 476 | // ----------------------------- |
| 477 | // getter/setters for debug_preferences.xml |
| 478 | // ----------------------------- |
| 479 | |
| 480 | public boolean isHardwareAccelerated() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 481 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 482 | return true; |
| 483 | } |
| 484 | return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true); |
| 485 | } |
| 486 | |
| 487 | public int getUserAgent() { |
John Reck | f48314f | 2011-04-27 17:52:17 -0700 | [diff] [blame] | 488 | if (!isDebugEnabled()) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0")); |
| 492 | } |
| 493 | |
| 494 | // ----------------------------- |
| 495 | // getter/setters for hidden_debug_preferences.xml |
| 496 | // ----------------------------- |
| 497 | |
| 498 | public boolean enableVisualIndicator() { |
| 499 | if (!isDebugEnabled()) { |
| 500 | return false; |
| 501 | } |
| 502 | return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false); |
| 503 | } |
| 504 | |
| 505 | public boolean enableJavascriptConsole() { |
| 506 | if (!isDebugEnabled()) { |
| 507 | return false; |
| 508 | } |
| 509 | return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true); |
| 510 | } |
| 511 | |
| 512 | public boolean isSmallScreen() { |
| 513 | if (!isDebugEnabled()) { |
| 514 | return false; |
| 515 | } |
| 516 | return mPrefs.getBoolean(PREF_SMALL_SCREEN, false); |
| 517 | } |
| 518 | |
| 519 | public boolean isWideViewport() { |
| 520 | if (!isDebugEnabled()) { |
| 521 | return true; |
| 522 | } |
| 523 | return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true); |
| 524 | } |
| 525 | |
| 526 | public boolean isNormalLayout() { |
| 527 | if (!isDebugEnabled()) { |
| 528 | return false; |
| 529 | } |
| 530 | return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false); |
| 531 | } |
| 532 | |
| 533 | public boolean isTracing() { |
| 534 | if (!isDebugEnabled()) { |
| 535 | return false; |
| 536 | } |
| 537 | return mPrefs.getBoolean(PREF_ENABLE_TRACING, false); |
| 538 | } |
| 539 | |
| 540 | public boolean enableLightTouch() { |
| 541 | if (!isDebugEnabled()) { |
| 542 | return false; |
| 543 | } |
| 544 | return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false); |
| 545 | } |
| 546 | |
| 547 | public boolean enableNavDump() { |
| 548 | if (!isDebugEnabled()) { |
| 549 | return false; |
| 550 | } |
| 551 | return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false); |
| 552 | } |
| 553 | |
| 554 | public String getJsEngineFlags() { |
| 555 | if (!isDebugEnabled()) { |
| 556 | return ""; |
| 557 | } |
| 558 | return mPrefs.getString(PREF_JS_ENGINE_FLAGS, ""); |
| 559 | } |
| 560 | |
| 561 | // ----------------------------- |
| 562 | // getter/setters for lab_preferences.xml |
| 563 | // ----------------------------- |
| 564 | |
| 565 | public boolean useQuickControls() { |
| 566 | return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false); |
| 567 | } |
| 568 | |
| 569 | public boolean useMostVisitedHomepage() { |
| 570 | return mPrefs.getBoolean(PREF_USE_MOST_VISITED_HOMEPAGE, false); |
| 571 | } |
| 572 | |
| 573 | public boolean useInstantSearch() { |
| 574 | return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false); |
| 575 | } |
| 576 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 577 | public boolean useFullscreen() { |
| 578 | return mPrefs.getBoolean(PREF_FULLSCREEN, false); |
| 579 | } |
| 580 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 581 | // ----------------------------- |
| 582 | // getter/setters for privacy_security_preferences.xml |
| 583 | // ----------------------------- |
| 584 | |
| 585 | public boolean showSecurityWarnings() { |
| 586 | return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true); |
| 587 | } |
| 588 | |
| 589 | public boolean acceptCookies() { |
| 590 | return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true); |
| 591 | } |
| 592 | |
| 593 | public boolean saveFormdata() { |
| 594 | return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true); |
| 595 | } |
| 596 | |
| 597 | public boolean enableGeolocation() { |
| 598 | return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true); |
| 599 | } |
| 600 | |
| 601 | public boolean rememberPasswords() { |
| 602 | return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true); |
| 603 | } |
| 604 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 605 | } |