The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 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 android.webkit; |
| 18 | |
| 19 | import android.content.Context; |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 20 | import android.content.SharedPreferences; |
Andrei Popescu | 972acd0 | 2009-07-10 16:58:13 +0100 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | import android.os.Build; |
| 23 | import android.os.Handler; |
| 24 | import android.os.Message; |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 25 | import android.util.DisplayMetrics; |
Dan Egnor | 18e9396 | 2010-02-10 19:27:58 -0800 | [diff] [blame] | 26 | import android.util.EventLog; |
Michael Kolb | 37b64de | 2010-07-01 12:05:47 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | import java.util.Locale; |
| 29 | |
| 30 | /** |
| 31 | * Manages settings state for a WebView. When a WebView is first created, it |
| 32 | * obtains a set of default settings. These default settings will be returned |
| 33 | * from any getter call. A WebSettings object obtained from |
| 34 | * WebView.getSettings() is tied to the life of the WebView. If a WebView has |
| 35 | * been destroyed, any method call on WebSettings will throw an |
| 36 | * IllegalStateException. |
| 37 | */ |
| 38 | public class WebSettings { |
| 39 | /** |
| 40 | * Enum for controlling the layout of html. |
| 41 | * NORMAL means no rendering changes. |
| 42 | * SINGLE_COLUMN moves all content into one column that is the width of the |
| 43 | * view. |
| 44 | * NARROW_COLUMNS makes all columns no wider than the screen if possible. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 45 | * @deprecated This enum is now obsolete. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 46 | */ |
| 47 | // XXX: These must match LayoutAlgorithm in Settings.h in WebCore. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 48 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | public enum LayoutAlgorithm { |
| 50 | NORMAL, |
| 51 | SINGLE_COLUMN, |
| 52 | NARROW_COLUMNS |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Enum for specifying the text size. |
| 57 | * SMALLEST is 50% |
| 58 | * SMALLER is 75% |
| 59 | * NORMAL is 100% |
| 60 | * LARGER is 150% |
| 61 | * LARGEST is 200% |
| 62 | */ |
| 63 | public enum TextSize { |
| 64 | SMALLEST(50), |
| 65 | SMALLER(75), |
| 66 | NORMAL(100), |
| 67 | LARGER(150), |
| 68 | LARGEST(200); |
| 69 | TextSize(int size) { |
| 70 | value = size; |
| 71 | } |
| 72 | int value; |
| 73 | } |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Enum for specifying the WebView's desired density. |
| 77 | * FAR makes 100% looking like in 240dpi |
| 78 | * MEDIUM makes 100% looking like in 160dpi |
| 79 | * CLOSE makes 100% looking like in 120dpi |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 80 | */ |
| 81 | public enum ZoomDensity { |
| 82 | FAR(150), // 240dpi |
| 83 | MEDIUM(100), // 160dpi |
| 84 | CLOSE(75); // 120dpi |
| 85 | ZoomDensity(int size) { |
| 86 | value = size; |
| 87 | } |
| 88 | int value; |
| 89 | } |
| 90 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Default cache usage pattern Use with {@link #setCacheMode}. |
| 93 | */ |
| 94 | public static final int LOAD_DEFAULT = -1; |
| 95 | |
| 96 | /** |
| 97 | * Normal cache usage pattern Use with {@link #setCacheMode}. |
| 98 | */ |
| 99 | public static final int LOAD_NORMAL = 0; |
| 100 | |
| 101 | /** |
| 102 | * Use cache if content is there, even if expired (eg, history nav) |
| 103 | * If it is not in the cache, load from network. |
| 104 | * Use with {@link #setCacheMode}. |
| 105 | */ |
| 106 | public static final int LOAD_CACHE_ELSE_NETWORK = 1; |
| 107 | |
| 108 | /** |
| 109 | * Don't use the cache, load from network |
| 110 | * Use with {@link #setCacheMode}. |
| 111 | */ |
| 112 | public static final int LOAD_NO_CACHE = 2; |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 113 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | /** |
| 115 | * Don't use the network, load from cache only. |
| 116 | * Use with {@link #setCacheMode}. |
| 117 | */ |
| 118 | public static final int LOAD_CACHE_ONLY = 3; |
| 119 | |
| 120 | public enum RenderPriority { |
| 121 | NORMAL, |
| 122 | HIGH, |
| 123 | LOW |
| 124 | } |
| 125 | |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 126 | /** |
| 127 | * The plugin state effects how plugins are treated on a page. ON means |
| 128 | * that any object will be loaded even if a plugin does not exist to handle |
| 129 | * the content. ON_DEMAND means that if there is a plugin installed that |
| 130 | * can handle the content, a placeholder is shown until the user clicks on |
| 131 | * the placeholder. Once clicked, the plugin will be enabled on the page. |
| 132 | * OFF means that all plugins will be turned off and any fallback content |
| 133 | * will be used. |
| 134 | */ |
| 135 | public enum PluginState { |
| 136 | ON, |
| 137 | ON_DEMAND, |
| 138 | OFF |
| 139 | } |
| 140 | |
John Reck | f557740 | 2011-04-28 10:27:40 -0700 | [diff] [blame] | 141 | // TODO: Keep this up to date |
| 142 | private static final String PREVIOUS_VERSION = "3.1"; |
| 143 | |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 144 | // WebView associated with this WebSettings. |
| 145 | private WebView mWebView; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | // BrowserFrame used to access the native frame pointer. |
| 147 | private BrowserFrame mBrowserFrame; |
| 148 | // Flag to prevent multiple SYNC messages at one time. |
| 149 | private boolean mSyncPending = false; |
| 150 | // Custom handler that queues messages until the WebCore thread is active. |
| 151 | private final EventHandler mEventHandler; |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 152 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 153 | // Private settings so we don't have to go into native code to |
| 154 | // retrieve the values. After setXXX, postSync() needs to be called. |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 155 | // |
| 156 | // The default values need to match those in WebSettings.cpp |
| 157 | // If the defaults change, please also update the JavaDocs so developers |
| 158 | // know what they are. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 159 | private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 160 | private Context mContext; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 161 | private TextSize mTextSize = TextSize.NORMAL; |
| 162 | private String mStandardFontFamily = "sans-serif"; |
| 163 | private String mFixedFontFamily = "monospace"; |
| 164 | private String mSansSerifFontFamily = "sans-serif"; |
| 165 | private String mSerifFontFamily = "serif"; |
| 166 | private String mCursiveFontFamily = "cursive"; |
| 167 | private String mFantasyFontFamily = "fantasy"; |
Daisuke Miyakawa | c27d9b5 | 2009-05-25 16:57:15 +0900 | [diff] [blame] | 168 | private String mDefaultTextEncoding; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 169 | private String mUserAgent; |
| 170 | private boolean mUseDefaultUserAgent; |
| 171 | private String mAcceptLanguage; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 | private int mMinimumFontSize = 8; |
| 173 | private int mMinimumLogicalFontSize = 8; |
| 174 | private int mDefaultFontSize = 16; |
| 175 | private int mDefaultFixedFontSize = 13; |
Grace Kloba | 097b1e77 | 2009-11-24 14:23:18 -0800 | [diff] [blame] | 176 | private int mPageCacheCapacity = 0; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 177 | private boolean mLoadsImagesAutomatically = true; |
| 178 | private boolean mBlockNetworkImage = false; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 179 | private boolean mBlockNetworkLoads; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 180 | private boolean mJavaScriptEnabled = false; |
Teng-Hui Zhu | da7378e | 2011-02-16 11:25:03 -0800 | [diff] [blame] | 181 | private boolean mShowVisualIndicator = false; |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 182 | private PluginState mPluginState = PluginState.OFF; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 183 | private boolean mJavaScriptCanOpenWindowsAutomatically = false; |
| 184 | private boolean mUseDoubleTree = false; |
| 185 | private boolean mUseWideViewport = false; |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 186 | private boolean mUseFixedViewport = false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 | private boolean mSupportMultipleWindows = false; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 188 | private boolean mShrinksStandaloneImagesToFit = false; |
Cary Clark | f0785a6 | 2010-06-25 11:45:40 -0400 | [diff] [blame] | 189 | private long mMaximumDecodedImageSize = 0; // 0 means default |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 190 | private boolean mPrivateBrowsingEnabled = false; |
Cary Clark | 6c43d52 | 2010-08-31 15:41:54 -0400 | [diff] [blame] | 191 | private boolean mSyntheticLinksEnabled = true; |
Andrei Popescu | c27a9ac | 2009-08-03 15:59:24 +0100 | [diff] [blame] | 192 | // HTML5 API flags |
| 193 | private boolean mAppCacheEnabled = false; |
| 194 | private boolean mDatabaseEnabled = false; |
| 195 | private boolean mDomStorageEnabled = false; |
| 196 | private boolean mWorkersEnabled = false; // only affects V8. |
Steve Block | 09b0ca1 | 2009-08-26 18:16:58 +0100 | [diff] [blame] | 197 | private boolean mGeolocationEnabled = true; |
Elliott Slaughter | 5dc0c82 | 2010-06-22 11:31:54 -0700 | [diff] [blame] | 198 | private boolean mXSSAuditorEnabled = false; |
Andrei Popescu | c27a9ac | 2009-08-03 15:59:24 +0100 | [diff] [blame] | 199 | // HTML5 configuration parameters |
| 200 | private long mAppCacheMaxSize = Long.MAX_VALUE; |
| 201 | private String mAppCachePath = ""; |
| 202 | private String mDatabasePath = ""; |
Ben Murdoch | 18773af | 2010-02-25 18:41:56 +0000 | [diff] [blame] | 203 | // The WebCore DatabaseTracker only allows the database path to be set |
| 204 | // once. Keep track of when the path has been set. |
| 205 | private boolean mDatabasePathHasBeenSet = false; |
Steve Block | 9d3273f | 2009-08-21 13:16:27 +0100 | [diff] [blame] | 206 | private String mGeolocationDatabasePath = ""; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 207 | // Don't need to synchronize the get/set methods as they |
| 208 | // are basic types, also none of these values are used in |
| 209 | // native WebCore code. |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 210 | private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | private RenderPriority mRenderPriority = RenderPriority.NORMAL; |
| 212 | private int mOverrideCacheMode = LOAD_DEFAULT; |
| 213 | private boolean mSaveFormData = true; |
Ben Murdoch | f39b2cf | 2010-09-09 10:26:46 +0100 | [diff] [blame] | 214 | private boolean mAutoFillEnabled = false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 215 | private boolean mSavePassword = true; |
| 216 | private boolean mLightTouchEnabled = false; |
| 217 | private boolean mNeedInitialFocus = true; |
| 218 | private boolean mNavDump = false; |
| 219 | private boolean mSupportZoom = true; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 220 | private boolean mBuiltInZoomControls = false; |
Michael Kolb | 6fe3b42 | 2010-08-19 12:41:24 -0700 | [diff] [blame] | 221 | private boolean mDisplayZoomControls = true; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 222 | private boolean mAllowFileAccess = true; |
Patrick Scott | d1737ed | 2011-01-05 11:36:48 -0500 | [diff] [blame] | 223 | private boolean mAllowContentAccess = true; |
Cary Clark | f8d4964 | 2009-09-08 13:23:24 -0400 | [diff] [blame] | 224 | private boolean mLoadWithOverviewMode = false; |
Grace Kloba | f9b731d | 2010-06-21 19:23:57 -0700 | [diff] [blame] | 225 | private boolean mEnableSmoothTransition = false; |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 226 | private boolean mForceUserScalable = false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 227 | |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 228 | // AutoFill Profile data |
| 229 | /** |
| 230 | * @hide for now, pending API council approval. |
| 231 | */ |
| 232 | public static class AutoFillProfile { |
Ben Murdoch | b1b82a8 | 2010-10-20 14:18:25 +0100 | [diff] [blame] | 233 | private int mUniqueId; |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 234 | private String mFullName; |
| 235 | private String mEmailAddress; |
Ben Murdoch | cf30872 | 2010-10-13 17:38:46 +0100 | [diff] [blame] | 236 | private String mCompanyName; |
| 237 | private String mAddressLine1; |
| 238 | private String mAddressLine2; |
| 239 | private String mCity; |
| 240 | private String mState; |
| 241 | private String mZipCode; |
| 242 | private String mCountry; |
| 243 | private String mPhoneNumber; |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 244 | |
Ben Murdoch | b1b82a8 | 2010-10-20 14:18:25 +0100 | [diff] [blame] | 245 | public AutoFillProfile(int uniqueId, String fullName, String email, |
Ben Murdoch | cf30872 | 2010-10-13 17:38:46 +0100 | [diff] [blame] | 246 | String companyName, String addressLine1, String addressLine2, |
| 247 | String city, String state, String zipCode, String country, |
| 248 | String phoneNumber) { |
Ben Murdoch | b1b82a8 | 2010-10-20 14:18:25 +0100 | [diff] [blame] | 249 | mUniqueId = uniqueId; |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 250 | mFullName = fullName; |
| 251 | mEmailAddress = email; |
Ben Murdoch | cf30872 | 2010-10-13 17:38:46 +0100 | [diff] [blame] | 252 | mCompanyName = companyName; |
| 253 | mAddressLine1 = addressLine1; |
| 254 | mAddressLine2 = addressLine2; |
| 255 | mCity = city; |
| 256 | mState = state; |
| 257 | mZipCode = zipCode; |
| 258 | mCountry = country; |
| 259 | mPhoneNumber = phoneNumber; |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Ben Murdoch | b1b82a8 | 2010-10-20 14:18:25 +0100 | [diff] [blame] | 262 | public int getUniqueId() { return mUniqueId; } |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 263 | public String getFullName() { return mFullName; } |
| 264 | public String getEmailAddress() { return mEmailAddress; } |
Ben Murdoch | cf30872 | 2010-10-13 17:38:46 +0100 | [diff] [blame] | 265 | public String getCompanyName() { return mCompanyName; } |
| 266 | public String getAddressLine1() { return mAddressLine1; } |
| 267 | public String getAddressLine2() { return mAddressLine2; } |
| 268 | public String getCity() { return mCity; } |
| 269 | public String getState() { return mState; } |
| 270 | public String getZipCode() { return mZipCode; } |
| 271 | public String getCountry() { return mCountry; } |
| 272 | public String getPhoneNumber() { return mPhoneNumber; } |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
| 276 | private AutoFillProfile mAutoFillProfile; |
| 277 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 278 | private boolean mUseWebViewBackgroundForOverscroll = true; |
| 279 | |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 280 | // private WebSettings, not accessible by the host activity |
Grace Kloba | 24a3ff9 | 2009-09-22 10:42:22 -0700 | [diff] [blame] | 281 | static private int mDoubleTapToastCount = 3; |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 282 | |
| 283 | private static final String PREF_FILE = "WebViewSettings"; |
| 284 | private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count"; |
| 285 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 286 | // Class to handle messages before WebCore is ready. |
| 287 | private class EventHandler { |
| 288 | // Message id for syncing |
| 289 | static final int SYNC = 0; |
| 290 | // Message id for setting priority |
| 291 | static final int PRIORITY = 1; |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 292 | // Message id for writing double-tap toast count |
| 293 | static final int SET_DOUBLE_TAP_TOAST_COUNT = 2; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 294 | // Actual WebCore thread handler |
| 295 | private Handler mHandler; |
| 296 | |
| 297 | private synchronized void createHandler() { |
| 298 | // as mRenderPriority can be set before thread is running, sync up |
| 299 | setRenderPriority(); |
| 300 | |
| 301 | // create a new handler |
| 302 | mHandler = new Handler() { |
| 303 | @Override |
| 304 | public void handleMessage(Message msg) { |
| 305 | switch (msg.what) { |
| 306 | case SYNC: |
| 307 | synchronized (WebSettings.this) { |
| 308 | if (mBrowserFrame.mNativeFrame != 0) { |
| 309 | nativeSync(mBrowserFrame.mNativeFrame); |
| 310 | } |
| 311 | mSyncPending = false; |
| 312 | } |
| 313 | break; |
| 314 | |
| 315 | case PRIORITY: { |
| 316 | setRenderPriority(); |
| 317 | break; |
| 318 | } |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 319 | |
| 320 | case SET_DOUBLE_TAP_TOAST_COUNT: { |
| 321 | SharedPreferences.Editor editor = mContext |
| 322 | .getSharedPreferences(PREF_FILE, |
| 323 | Context.MODE_PRIVATE).edit(); |
| 324 | editor.putInt(DOUBLE_TAP_TOAST_COUNT, |
| 325 | mDoubleTapToastCount); |
| 326 | editor.commit(); |
| 327 | break; |
| 328 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | }; |
| 332 | } |
| 333 | |
| 334 | private void setRenderPriority() { |
| 335 | synchronized (WebSettings.this) { |
| 336 | if (mRenderPriority == RenderPriority.NORMAL) { |
| 337 | android.os.Process.setThreadPriority( |
| 338 | android.os.Process.THREAD_PRIORITY_DEFAULT); |
| 339 | } else if (mRenderPriority == RenderPriority.HIGH) { |
| 340 | android.os.Process.setThreadPriority( |
| 341 | android.os.Process.THREAD_PRIORITY_FOREGROUND + |
| 342 | android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE); |
| 343 | } else if (mRenderPriority == RenderPriority.LOW) { |
| 344 | android.os.Process.setThreadPriority( |
| 345 | android.os.Process.THREAD_PRIORITY_BACKGROUND); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Send a message to the private queue or handler. |
| 352 | */ |
| 353 | private synchronized boolean sendMessage(Message msg) { |
| 354 | if (mHandler != null) { |
| 355 | mHandler.sendMessage(msg); |
| 356 | return true; |
| 357 | } else { |
| 358 | return false; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // User agent strings. |
| 364 | private static final String DESKTOP_USERAGENT = |
Grace Kloba | b4f3344 | 2009-06-25 23:38:40 -0700 | [diff] [blame] | 365 | "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us)" |
| 366 | + " AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0" |
| 367 | + " Safari/530.17"; |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 368 | private static final String IPHONE_USERAGENT = |
Grace Kloba | b4f3344 | 2009-06-25 23:38:40 -0700 | [diff] [blame] | 369 | "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)" |
| 370 | + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0" |
| 371 | + " Mobile/7A341 Safari/528.16"; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 372 | private static Locale sLocale; |
| 373 | private static Object sLockForLocaleSettings; |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 375 | /** |
| 376 | * Package constructor to prevent clients from creating a new settings |
| 377 | * instance. |
| 378 | */ |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 379 | WebSettings(Context context, WebView webview) { |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 380 | mEventHandler = new EventHandler(); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 381 | mContext = context; |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 382 | mWebView = webview; |
Daisuke Miyakawa | c27d9b5 | 2009-05-25 16:57:15 +0900 | [diff] [blame] | 383 | mDefaultTextEncoding = context.getString(com.android.internal. |
| 384 | R.string.default_text_encoding); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 385 | |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 386 | // Detect tablet device for fixed viewport mode. |
| 387 | final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
Shimeng (Simon) Wang | 14bcc0e | 2010-09-17 10:12:05 -0700 | [diff] [blame] | 388 | final int landscapeWidth = Math.max(metrics.widthPixels, metrics.heightPixels); |
Shimeng (Simon) Wang | a2ded6c | 2010-09-17 12:59:01 -0700 | [diff] [blame] | 389 | final int minTabletWidth = context.getResources().getDimensionPixelSize( |
| 390 | com.android.internal.R.dimen.min_xlarge_screen_width); |
| 391 | mUseFixedViewport = (metrics.density == 1.0f && landscapeWidth >= minTabletWidth); |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 392 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 393 | if (sLockForLocaleSettings == null) { |
| 394 | sLockForLocaleSettings = new Object(); |
| 395 | sLocale = Locale.getDefault(); |
| 396 | } |
| 397 | mAcceptLanguage = getCurrentAcceptLanguage(); |
| 398 | mUserAgent = getCurrentUserAgent(); |
| 399 | mUseDefaultUserAgent = true; |
| 400 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 401 | mBlockNetworkLoads = mContext.checkPermission( |
| 402 | "android.permission.INTERNET", android.os.Process.myPid(), |
| 403 | android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 406 | private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US"; |
| 407 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | /** |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 409 | * Looks at sLocale and returns current AcceptLanguage String. |
| 410 | * @return Current AcceptLanguage String. |
| 411 | */ |
| 412 | private String getCurrentAcceptLanguage() { |
| 413 | Locale locale; |
| 414 | synchronized(sLockForLocaleSettings) { |
| 415 | locale = sLocale; |
| 416 | } |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 417 | StringBuilder buffer = new StringBuilder(); |
| 418 | addLocaleToHttpAcceptLanguage(buffer, locale); |
| 419 | |
| 420 | if (!Locale.US.equals(locale)) { |
| 421 | if (buffer.length() > 0) { |
| 422 | buffer.append(", "); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 423 | } |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 424 | buffer.append(ACCEPT_LANG_FOR_US_LOCALE); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | return buffer.toString(); |
| 428 | } |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 429 | |
| 430 | /** |
| 431 | * Convert obsolete language codes, including Hebrew/Indonesian/Yiddish, |
| 432 | * to new standard. |
| 433 | */ |
| 434 | private static String convertObsoleteLanguageCodeToNew(String langCode) { |
| 435 | if (langCode == null) { |
| 436 | return null; |
| 437 | } |
| 438 | if ("iw".equals(langCode)) { |
| 439 | // Hebrew |
| 440 | return "he"; |
| 441 | } else if ("in".equals(langCode)) { |
| 442 | // Indonesian |
| 443 | return "id"; |
| 444 | } else if ("ji".equals(langCode)) { |
| 445 | // Yiddish |
| 446 | return "yi"; |
| 447 | } |
| 448 | return langCode; |
| 449 | } |
| 450 | |
| 451 | private static void addLocaleToHttpAcceptLanguage(StringBuilder builder, |
| 452 | Locale locale) { |
| 453 | String language = convertObsoleteLanguageCodeToNew(locale.getLanguage()); |
| 454 | if (language != null) { |
| 455 | builder.append(language); |
| 456 | String country = locale.getCountry(); |
| 457 | if (country != null) { |
| 458 | builder.append("-"); |
| 459 | builder.append(country); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Looks at sLocale and mContext and returns current UserAgent String. |
| 466 | * @return Current UserAgent String. |
| 467 | */ |
| 468 | private synchronized String getCurrentUserAgent() { |
| 469 | Locale locale; |
| 470 | synchronized(sLockForLocaleSettings) { |
| 471 | locale = sLocale; |
| 472 | } |
| 473 | StringBuffer buffer = new StringBuffer(); |
| 474 | // Add version |
| 475 | final String version = Build.VERSION.RELEASE; |
| 476 | if (version.length() > 0) { |
John Reck | f557740 | 2011-04-28 10:27:40 -0700 | [diff] [blame] | 477 | if (Character.isDigit(version.charAt(0))) { |
| 478 | // Release is a version, eg "3.1" |
| 479 | buffer.append(version); |
| 480 | } else { |
| 481 | // Release is a codename, eg "Honeycomb" |
| 482 | // In this case, use the previous release's version |
| 483 | buffer.append(PREVIOUS_VERSION); |
| 484 | } |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 485 | } else { |
| 486 | // default to "1.0" |
| 487 | buffer.append("1.0"); |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 488 | } |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 489 | buffer.append("; "); |
| 490 | final String language = locale.getLanguage(); |
| 491 | if (language != null) { |
Shimeng (Simon) Wang | 0e4cb9d | 2010-04-14 18:11:05 -0700 | [diff] [blame] | 492 | buffer.append(convertObsoleteLanguageCodeToNew(language)); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 493 | final String country = locale.getCountry(); |
| 494 | if (country != null) { |
| 495 | buffer.append("-"); |
| 496 | buffer.append(country.toLowerCase()); |
| 497 | } |
| 498 | } else { |
| 499 | // default to "en" |
| 500 | buffer.append("en"); |
| 501 | } |
John Reck | 36fd7a3 | 2011-01-07 18:45:33 -0800 | [diff] [blame] | 502 | buffer.append(";"); |
Grace Kloba | ce761d3 | 2009-08-27 15:24:59 -0700 | [diff] [blame] | 503 | // add the model for the release build |
| 504 | if ("REL".equals(Build.VERSION.CODENAME)) { |
| 505 | final String model = Build.MODEL; |
| 506 | if (model.length() > 0) { |
John Reck | 36fd7a3 | 2011-01-07 18:45:33 -0800 | [diff] [blame] | 507 | buffer.append(" "); |
Grace Kloba | ce761d3 | 2009-08-27 15:24:59 -0700 | [diff] [blame] | 508 | buffer.append(model); |
| 509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
| 511 | final String id = Build.ID; |
| 512 | if (id.length() > 0) { |
| 513 | buffer.append(" Build/"); |
| 514 | buffer.append(id); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 515 | } |
Michael Kolb | 37b64de | 2010-07-01 12:05:47 -0700 | [diff] [blame] | 516 | String mobile = mContext.getResources().getText( |
| 517 | com.android.internal.R.string.web_user_agent_target_content).toString(); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 518 | final String base = mContext.getResources().getText( |
| 519 | com.android.internal.R.string.web_user_agent).toString(); |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 520 | return String.format(base, buffer, mobile); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 521 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 522 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 523 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 524 | * Enables dumping the pages navigation cache to a text file. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 525 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 526 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 527 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 528 | public void setNavDump(boolean enabled) { |
| 529 | mNavDump = enabled; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * Returns true if dumping the navigation cache is enabled. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 534 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 535 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 536 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 537 | public boolean getNavDump() { |
| 538 | return mNavDump; |
| 539 | } |
| 540 | |
| 541 | /** |
Grace Kloba | 178db41 | 2010-05-18 22:22:23 -0700 | [diff] [blame] | 542 | * If WebView only supports touch, a different navigation model will be |
| 543 | * applied. Otherwise, the navigation to support both touch and keyboard |
| 544 | * will be used. |
| 545 | * @hide |
| 546 | public void setSupportTouchOnly(boolean touchOnly) { |
| 547 | mSupportTounchOnly = touchOnly; |
| 548 | } |
| 549 | */ |
| 550 | |
| 551 | boolean supportTouchOnly() { |
| 552 | // for debug only, use mLightTouchEnabled for mSupportTounchOnly |
| 553 | return mLightTouchEnabled; |
| 554 | } |
| 555 | |
| 556 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 557 | * Set whether the WebView supports zoom |
| 558 | */ |
| 559 | public void setSupportZoom(boolean support) { |
| 560 | mSupportZoom = support; |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 561 | mWebView.updateMultiTouchSupport(mContext); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Returns whether the WebView supports zoom |
| 566 | */ |
| 567 | public boolean supportZoom() { |
| 568 | return mSupportZoom; |
| 569 | } |
| 570 | |
| 571 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 572 | * Sets whether the zoom mechanism built into WebView is used. |
| 573 | */ |
| 574 | public void setBuiltInZoomControls(boolean enabled) { |
| 575 | mBuiltInZoomControls = enabled; |
Grace Kloba | 3a0def2 | 2010-01-23 21:11:54 -0800 | [diff] [blame] | 576 | mWebView.updateMultiTouchSupport(mContext); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 577 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 578 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 579 | /** |
| 580 | * Returns true if the zoom mechanism built into WebView is being used. |
| 581 | */ |
| 582 | public boolean getBuiltInZoomControls() { |
| 583 | return mBuiltInZoomControls; |
| 584 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 585 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 586 | /** |
Michael Kolb | 6fe3b42 | 2010-08-19 12:41:24 -0700 | [diff] [blame] | 587 | * Sets whether the on screen zoom buttons are used. |
| 588 | * A combination of built in zoom controls enabled |
| 589 | * and on screen zoom controls disabled allows for pinch to zoom |
| 590 | * to work without the on screen controls |
Michael Kolb | 6fe3b42 | 2010-08-19 12:41:24 -0700 | [diff] [blame] | 591 | */ |
| 592 | public void setDisplayZoomControls(boolean enabled) { |
| 593 | mDisplayZoomControls = enabled; |
| 594 | mWebView.updateMultiTouchSupport(mContext); |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * Returns true if the on screen zoom buttons are being used. |
Michael Kolb | 6fe3b42 | 2010-08-19 12:41:24 -0700 | [diff] [blame] | 599 | */ |
| 600 | public boolean getDisplayZoomControls() { |
| 601 | return mDisplayZoomControls; |
| 602 | } |
| 603 | |
| 604 | /** |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 605 | * Enable or disable file access within WebView. File access is enabled by |
Patrick Scott | d1737ed | 2011-01-05 11:36:48 -0500 | [diff] [blame] | 606 | * default. Note that this enables or disables file system access only. |
| 607 | * Assets and resources are still accessible using file:///android_asset and |
| 608 | * file:///android_res. |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 609 | */ |
| 610 | public void setAllowFileAccess(boolean allow) { |
| 611 | mAllowFileAccess = allow; |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Returns true if this WebView supports file access. |
| 616 | */ |
| 617 | public boolean getAllowFileAccess() { |
| 618 | return mAllowFileAccess; |
| 619 | } |
| 620 | |
| 621 | /** |
Patrick Scott | d1737ed | 2011-01-05 11:36:48 -0500 | [diff] [blame] | 622 | * Enable or disable content url access within WebView. Content url access |
| 623 | * allows WebView to load content from a content provider installed in the |
| 624 | * system. The default is enabled. |
| 625 | */ |
| 626 | public void setAllowContentAccess(boolean allow) { |
| 627 | mAllowContentAccess = allow; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Returns true if this WebView supports content url access. |
| 632 | */ |
| 633 | public boolean getAllowContentAccess() { |
| 634 | return mAllowContentAccess; |
| 635 | } |
| 636 | |
| 637 | /** |
Grace Kloba | e397a88 | 2009-08-06 12:04:14 -0700 | [diff] [blame] | 638 | * Set whether the WebView loads a page with overview mode. |
Grace Kloba | e397a88 | 2009-08-06 12:04:14 -0700 | [diff] [blame] | 639 | */ |
| 640 | public void setLoadWithOverviewMode(boolean overview) { |
| 641 | mLoadWithOverviewMode = overview; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Returns true if this WebView loads page with overview mode |
Grace Kloba | e397a88 | 2009-08-06 12:04:14 -0700 | [diff] [blame] | 646 | */ |
| 647 | public boolean getLoadWithOverviewMode() { |
| 648 | return mLoadWithOverviewMode; |
| 649 | } |
| 650 | |
| 651 | /** |
Grace Kloba | f9b731d | 2010-06-21 19:23:57 -0700 | [diff] [blame] | 652 | * Set whether the WebView will enable smooth transition while panning or |
| 653 | * zooming. If it is true, WebView will choose a solution to maximize the |
| 654 | * performance. e.g. the WebView's content may not be updated during the |
| 655 | * transition. If it is false, WebView will keep its fidelity. The default |
| 656 | * value is false. |
| 657 | */ |
| 658 | public void setEnableSmoothTransition(boolean enable) { |
| 659 | mEnableSmoothTransition = enable; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Returns true if the WebView enables smooth transition while panning or |
| 664 | * zooming. |
| 665 | */ |
| 666 | public boolean enableSmoothTransition() { |
| 667 | return mEnableSmoothTransition; |
| 668 | } |
| 669 | |
| 670 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 671 | * Set whether the WebView uses its background for over scroll background. |
| 672 | * If true, it will use the WebView's background. If false, it will use an |
| 673 | * internal pattern. Default is true. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 674 | * @deprecated This method is now obsolete. |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 675 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 676 | @Deprecated |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 677 | public void setUseWebViewBackgroundForOverscrollBackground(boolean view) { |
| 678 | mUseWebViewBackgroundForOverscroll = view; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Returns true if this WebView uses WebView's background instead of |
| 683 | * internal pattern for over scroll background. |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 684 | * @deprecated This method is now obsolete. |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 685 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 686 | @Deprecated |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 687 | public boolean getUseWebViewBackgroundForOverscrollBackground() { |
| 688 | return mUseWebViewBackgroundForOverscroll; |
| 689 | } |
| 690 | |
| 691 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 692 | * Store whether the WebView is saving form data. |
| 693 | */ |
| 694 | public void setSaveFormData(boolean save) { |
| 695 | mSaveFormData = save; |
| 696 | } |
| 697 | |
| 698 | /** |
Leon Scroggins | aa6b9f5 | 2011-01-10 11:02:00 -0500 | [diff] [blame] | 699 | * Return whether the WebView is saving form data and displaying prior |
| 700 | * entries/autofill++. Always false in private browsing mode. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 701 | */ |
| 702 | public boolean getSaveFormData() { |
Leon Scroggins | aa6b9f5 | 2011-01-10 11:02:00 -0500 | [diff] [blame] | 703 | return mSaveFormData && !mPrivateBrowsingEnabled; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Store whether the WebView is saving password. |
| 708 | */ |
| 709 | public void setSavePassword(boolean save) { |
| 710 | mSavePassword = save; |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Return whether the WebView is saving password. |
| 715 | */ |
| 716 | public boolean getSavePassword() { |
| 717 | return mSavePassword; |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Set the text size of the page. |
| 722 | * @param t A TextSize value for increasing or decreasing the text. |
| 723 | * @see WebSettings.TextSize |
| 724 | */ |
| 725 | public synchronized void setTextSize(TextSize t) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | if (WebView.mLogEvent && mTextSize != t ) { |
Dan Egnor | 18e9396 | 2010-02-10 19:27:58 -0800 | [diff] [blame] | 727 | EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE, |
| 728 | mTextSize.value, t.value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 730 | mTextSize = t; |
| 731 | postSync(); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * Get the text size of the page. |
| 736 | * @return A TextSize enum value describing the text size. |
| 737 | * @see WebSettings.TextSize |
| 738 | */ |
| 739 | public synchronized TextSize getTextSize() { |
| 740 | return mTextSize; |
| 741 | } |
| 742 | |
| 743 | /** |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 744 | * Set the default zoom density of the page. This should be called from UI |
| 745 | * thread. |
| 746 | * @param zoom A ZoomDensity value |
| 747 | * @see WebSettings.ZoomDensity |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 748 | */ |
| 749 | public void setDefaultZoom(ZoomDensity zoom) { |
| 750 | if (mDefaultZoom != zoom) { |
| 751 | mDefaultZoom = zoom; |
| 752 | mWebView.updateDefaultZoomDensity(zoom.value); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Get the default zoom density of the page. This should be called from UI |
| 758 | * thread. |
| 759 | * @return A ZoomDensity value |
| 760 | * @see WebSettings.ZoomDensity |
Grace Kloba | 0d8b77c | 2009-06-25 11:20:51 -0700 | [diff] [blame] | 761 | */ |
| 762 | public ZoomDensity getDefaultZoom() { |
| 763 | return mDefaultZoom; |
| 764 | } |
| 765 | |
| 766 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 767 | * Enables using light touches to make a selection and activate mouseovers. |
| 768 | */ |
| 769 | public void setLightTouchEnabled(boolean enabled) { |
| 770 | mLightTouchEnabled = enabled; |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * Returns true if light touches are enabled. |
| 775 | */ |
| 776 | public boolean getLightTouchEnabled() { |
| 777 | return mLightTouchEnabled; |
| 778 | } |
| 779 | |
| 780 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 781 | * @deprecated This setting controlled a rendering optimization |
| 782 | * that is no longer present. Setting it now has no effect. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 783 | */ |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 784 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 785 | public synchronized void setUseDoubleTree(boolean use) { |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 786 | return; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 790 | * @deprecated This setting controlled a rendering optimization |
| 791 | * that is no longer present. Setting it now has no effect. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 792 | */ |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 793 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 794 | public synchronized boolean getUseDoubleTree() { |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 795 | return false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Tell the WebView about user-agent string. |
| 800 | * @param ua 0 if the WebView should use an Android user-agent string, |
| 801 | * 1 if the WebView should use a desktop user-agent string. |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 802 | * |
| 803 | * @deprecated Please use setUserAgentString instead. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 804 | */ |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 805 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 806 | public synchronized void setUserAgent(int ua) { |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 807 | String uaString = null; |
| 808 | if (ua == 1) { |
| 809 | if (DESKTOP_USERAGENT.equals(mUserAgent)) { |
| 810 | return; // do nothing |
| 811 | } else { |
| 812 | uaString = DESKTOP_USERAGENT; |
| 813 | } |
| 814 | } else if (ua == 2) { |
| 815 | if (IPHONE_USERAGENT.equals(mUserAgent)) { |
| 816 | return; // do nothing |
| 817 | } else { |
| 818 | uaString = IPHONE_USERAGENT; |
| 819 | } |
| 820 | } else if (ua != 0) { |
| 821 | return; // do nothing |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 822 | } |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 823 | setUserAgentString(uaString); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Return user-agent as int |
| 828 | * @return int 0 if the WebView is using an Android user-agent string. |
| 829 | * 1 if the WebView is using a desktop user-agent string. |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 830 | * -1 if the WebView is using user defined user-agent string. |
| 831 | * |
| 832 | * @deprecated Please use getUserAgentString instead. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 833 | */ |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 834 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 835 | public synchronized int getUserAgent() { |
| 836 | if (DESKTOP_USERAGENT.equals(mUserAgent)) { |
| 837 | return 1; |
| 838 | } else if (IPHONE_USERAGENT.equals(mUserAgent)) { |
| 839 | return 2; |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 840 | } else if (mUseDefaultUserAgent) { |
| 841 | return 0; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 842 | } |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 843 | return -1; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /** |
| 847 | * Tell the WebView to use the wide viewport |
| 848 | */ |
| 849 | public synchronized void setUseWideViewPort(boolean use) { |
| 850 | if (mUseWideViewport != use) { |
| 851 | mUseWideViewport = use; |
| 852 | postSync(); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * @return True if the WebView is using a wide viewport |
| 858 | */ |
| 859 | public synchronized boolean getUseWideViewPort() { |
| 860 | return mUseWideViewport; |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Tell the WebView whether it supports multiple windows. TRUE means |
| 865 | * that {@link WebChromeClient#onCreateWindow(WebView, boolean, |
| 866 | * boolean, Message)} is implemented by the host application. |
| 867 | */ |
| 868 | public synchronized void setSupportMultipleWindows(boolean support) { |
| 869 | if (mSupportMultipleWindows != support) { |
| 870 | mSupportMultipleWindows = support; |
| 871 | postSync(); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * @return True if the WebView is supporting multiple windows. This means |
| 877 | * that {@link WebChromeClient#onCreateWindow(WebView, boolean, |
| 878 | * boolean, Message)} is implemented by the host application. |
| 879 | */ |
| 880 | public synchronized boolean supportMultipleWindows() { |
| 881 | return mSupportMultipleWindows; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Set the underlying layout algorithm. This will cause a relayout of the |
| 886 | * WebView. |
| 887 | * @param l A LayoutAlgorithm enum specifying the algorithm to use. |
| 888 | * @see WebSettings.LayoutAlgorithm |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 889 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 891 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 892 | public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) { |
| 893 | // XXX: This will only be affective if libwebcore was built with |
| 894 | // ANDROID_LAYOUT defined. |
| 895 | if (mLayoutAlgorithm != l) { |
| 896 | mLayoutAlgorithm = l; |
| 897 | postSync(); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 902 | * Return the current layout algorithm. The default is NARROW_COLUMNS. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 903 | * @return LayoutAlgorithm enum value describing the layout algorithm |
| 904 | * being used. |
| 905 | * @see WebSettings.LayoutAlgorithm |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 906 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 907 | */ |
Kristian Monsen | fc77165 | 2011-05-10 16:44:05 +0100 | [diff] [blame] | 908 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 909 | public synchronized LayoutAlgorithm getLayoutAlgorithm() { |
| 910 | return mLayoutAlgorithm; |
| 911 | } |
| 912 | |
| 913 | /** |
| 914 | * Set the standard font family name. |
| 915 | * @param font A font family name. |
| 916 | */ |
| 917 | public synchronized void setStandardFontFamily(String font) { |
| 918 | if (font != null && !font.equals(mStandardFontFamily)) { |
| 919 | mStandardFontFamily = font; |
| 920 | postSync(); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 925 | * Get the standard font family name. The default is "sans-serif". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 926 | * @return The standard font family name as a string. |
| 927 | */ |
| 928 | public synchronized String getStandardFontFamily() { |
| 929 | return mStandardFontFamily; |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Set the fixed font family name. |
| 934 | * @param font A font family name. |
| 935 | */ |
| 936 | public synchronized void setFixedFontFamily(String font) { |
| 937 | if (font != null && !font.equals(mFixedFontFamily)) { |
| 938 | mFixedFontFamily = font; |
| 939 | postSync(); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 944 | * Get the fixed font family name. The default is "monospace". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 945 | * @return The fixed font family name as a string. |
| 946 | */ |
| 947 | public synchronized String getFixedFontFamily() { |
| 948 | return mFixedFontFamily; |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * Set the sans-serif font family name. |
| 953 | * @param font A font family name. |
| 954 | */ |
| 955 | public synchronized void setSansSerifFontFamily(String font) { |
| 956 | if (font != null && !font.equals(mSansSerifFontFamily)) { |
| 957 | mSansSerifFontFamily = font; |
| 958 | postSync(); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Get the sans-serif font family name. |
| 964 | * @return The sans-serif font family name as a string. |
| 965 | */ |
| 966 | public synchronized String getSansSerifFontFamily() { |
| 967 | return mSansSerifFontFamily; |
| 968 | } |
| 969 | |
| 970 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 971 | * Set the serif font family name. The default is "sans-serif". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 972 | * @param font A font family name. |
| 973 | */ |
| 974 | public synchronized void setSerifFontFamily(String font) { |
| 975 | if (font != null && !font.equals(mSerifFontFamily)) { |
| 976 | mSerifFontFamily = font; |
| 977 | postSync(); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 982 | * Get the serif font family name. The default is "serif". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 983 | * @return The serif font family name as a string. |
| 984 | */ |
| 985 | public synchronized String getSerifFontFamily() { |
| 986 | return mSerifFontFamily; |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Set the cursive font family name. |
| 991 | * @param font A font family name. |
| 992 | */ |
| 993 | public synchronized void setCursiveFontFamily(String font) { |
| 994 | if (font != null && !font.equals(mCursiveFontFamily)) { |
| 995 | mCursiveFontFamily = font; |
| 996 | postSync(); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1001 | * Get the cursive font family name. The default is "cursive". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1002 | * @return The cursive font family name as a string. |
| 1003 | */ |
| 1004 | public synchronized String getCursiveFontFamily() { |
| 1005 | return mCursiveFontFamily; |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * Set the fantasy font family name. |
| 1010 | * @param font A font family name. |
| 1011 | */ |
| 1012 | public synchronized void setFantasyFontFamily(String font) { |
| 1013 | if (font != null && !font.equals(mFantasyFontFamily)) { |
| 1014 | mFantasyFontFamily = font; |
| 1015 | postSync(); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1020 | * Get the fantasy font family name. The default is "fantasy". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1021 | * @return The fantasy font family name as a string. |
| 1022 | */ |
| 1023 | public synchronized String getFantasyFontFamily() { |
| 1024 | return mFantasyFontFamily; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * Set the minimum font size. |
| 1029 | * @param size A non-negative integer between 1 and 72. |
| 1030 | * Any number outside the specified range will be pinned. |
| 1031 | */ |
| 1032 | public synchronized void setMinimumFontSize(int size) { |
| 1033 | size = pin(size); |
| 1034 | if (mMinimumFontSize != size) { |
| 1035 | mMinimumFontSize = size; |
| 1036 | postSync(); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1041 | * Get the minimum font size. The default is 8. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1042 | * @return A non-negative integer between 1 and 72. |
| 1043 | */ |
| 1044 | public synchronized int getMinimumFontSize() { |
| 1045 | return mMinimumFontSize; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Set the minimum logical font size. |
| 1050 | * @param size A non-negative integer between 1 and 72. |
| 1051 | * Any number outside the specified range will be pinned. |
| 1052 | */ |
| 1053 | public synchronized void setMinimumLogicalFontSize(int size) { |
| 1054 | size = pin(size); |
| 1055 | if (mMinimumLogicalFontSize != size) { |
| 1056 | mMinimumLogicalFontSize = size; |
| 1057 | postSync(); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1062 | * Get the minimum logical font size. The default is 8. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1063 | * @return A non-negative integer between 1 and 72. |
| 1064 | */ |
| 1065 | public synchronized int getMinimumLogicalFontSize() { |
| 1066 | return mMinimumLogicalFontSize; |
| 1067 | } |
| 1068 | |
| 1069 | /** |
| 1070 | * Set the default font size. |
| 1071 | * @param size A non-negative integer between 1 and 72. |
| 1072 | * Any number outside the specified range will be pinned. |
| 1073 | */ |
| 1074 | public synchronized void setDefaultFontSize(int size) { |
| 1075 | size = pin(size); |
| 1076 | if (mDefaultFontSize != size) { |
| 1077 | mDefaultFontSize = size; |
| 1078 | postSync(); |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1083 | * Get the default font size. The default is 16. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1084 | * @return A non-negative integer between 1 and 72. |
| 1085 | */ |
| 1086 | public synchronized int getDefaultFontSize() { |
| 1087 | return mDefaultFontSize; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Set the default fixed font size. |
| 1092 | * @param size A non-negative integer between 1 and 72. |
| 1093 | * Any number outside the specified range will be pinned. |
| 1094 | */ |
| 1095 | public synchronized void setDefaultFixedFontSize(int size) { |
| 1096 | size = pin(size); |
| 1097 | if (mDefaultFixedFontSize != size) { |
| 1098 | mDefaultFixedFontSize = size; |
| 1099 | postSync(); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1104 | * Get the default fixed font size. The default is 16. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1105 | * @return A non-negative integer between 1 and 72. |
| 1106 | */ |
| 1107 | public synchronized int getDefaultFixedFontSize() { |
| 1108 | return mDefaultFixedFontSize; |
| 1109 | } |
| 1110 | |
| 1111 | /** |
Grace Kloba | 097b1e77 | 2009-11-24 14:23:18 -0800 | [diff] [blame] | 1112 | * Set the number of pages cached by the WebKit for the history navigation. |
| 1113 | * @param size A non-negative integer between 0 (no cache) and 20 (max). |
| 1114 | * @hide |
| 1115 | */ |
| 1116 | public synchronized void setPageCacheCapacity(int size) { |
| 1117 | if (size < 0) size = 0; |
| 1118 | if (size > 20) size = 20; |
| 1119 | if (mPageCacheCapacity != size) { |
| 1120 | mPageCacheCapacity = size; |
| 1121 | postSync(); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1126 | * Tell the WebView to load image resources automatically. |
| 1127 | * @param flag True if the WebView should load images automatically. |
| 1128 | */ |
| 1129 | public synchronized void setLoadsImagesAutomatically(boolean flag) { |
| 1130 | if (mLoadsImagesAutomatically != flag) { |
| 1131 | mLoadsImagesAutomatically = flag; |
| 1132 | postSync(); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Return true if the WebView will load image resources automatically. |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1138 | * The default is true. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1139 | * @return True if the WebView loads images automatically. |
| 1140 | */ |
| 1141 | public synchronized boolean getLoadsImagesAutomatically() { |
| 1142 | return mLoadsImagesAutomatically; |
| 1143 | } |
| 1144 | |
| 1145 | /** |
Patrick Scott | f43113f | 2010-02-18 09:13:12 -0500 | [diff] [blame] | 1146 | * Tell the WebView to block network images. This is only checked when |
| 1147 | * {@link #getLoadsImagesAutomatically} is true. If you set the value to |
| 1148 | * false, images will automatically be loaded. Use this api to reduce |
| 1149 | * bandwidth only. Use {@link #setBlockNetworkLoads} if possible. |
| 1150 | * @param flag True if the WebView should block network images. |
| 1151 | * @see #setBlockNetworkLoads |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1152 | */ |
| 1153 | public synchronized void setBlockNetworkImage(boolean flag) { |
| 1154 | if (mBlockNetworkImage != flag) { |
| 1155 | mBlockNetworkImage = flag; |
| 1156 | postSync(); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | /** |
Patrick Scott | f43113f | 2010-02-18 09:13:12 -0500 | [diff] [blame] | 1161 | * Return true if the WebView will block network images. The default is |
| 1162 | * false. |
| 1163 | * @return True if the WebView blocks network images. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1164 | */ |
| 1165 | public synchronized boolean getBlockNetworkImage() { |
| 1166 | return mBlockNetworkImage; |
| 1167 | } |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1168 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1169 | /** |
Patrick Scott | f43113f | 2010-02-18 09:13:12 -0500 | [diff] [blame] | 1170 | * Tell the WebView to block all network load requests. If you set the |
| 1171 | * value to false, you must call {@link android.webkit.WebView#reload} to |
| 1172 | * fetch remote resources. This flag supercedes the value passed to |
| 1173 | * {@link #setBlockNetworkImage}. |
| 1174 | * @param flag True if the WebView should block all network loads. |
| 1175 | * @see android.webkit.WebView#reload |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1176 | */ |
| 1177 | public synchronized void setBlockNetworkLoads(boolean flag) { |
| 1178 | if (mBlockNetworkLoads != flag) { |
| 1179 | mBlockNetworkLoads = flag; |
| 1180 | verifyNetworkAccess(); |
Patrick Scott | 4243a3a | 2010-10-05 09:30:24 -0400 | [diff] [blame] | 1181 | postSync(); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | /** |
Patrick Scott | f43113f | 2010-02-18 09:13:12 -0500 | [diff] [blame] | 1186 | * Return true if the WebView will block all network loads. The default is |
| 1187 | * false. |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1188 | * @return True if the WebView blocks all network loads. |
| 1189 | */ |
| 1190 | public synchronized boolean getBlockNetworkLoads() { |
| 1191 | return mBlockNetworkLoads; |
| 1192 | } |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1193 | |
| 1194 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1195 | private void verifyNetworkAccess() { |
| 1196 | if (!mBlockNetworkLoads) { |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1197 | if (mContext.checkPermission("android.permission.INTERNET", |
| 1198 | android.os.Process.myPid(), android.os.Process.myUid()) != |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1199 | PackageManager.PERMISSION_GRANTED) { |
| 1200 | throw new SecurityException |
| 1201 | ("Permission denied - " + |
| 1202 | "application missing INTERNET permission"); |
| 1203 | } |
| 1204 | } |
| 1205 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1206 | |
| 1207 | /** |
| 1208 | * Tell the WebView to enable javascript execution. |
| 1209 | * @param flag True if the WebView should execute javascript. |
| 1210 | */ |
| 1211 | public synchronized void setJavaScriptEnabled(boolean flag) { |
| 1212 | if (mJavaScriptEnabled != flag) { |
| 1213 | mJavaScriptEnabled = flag; |
| 1214 | postSync(); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /** |
Teng-Hui Zhu | da7378e | 2011-02-16 11:25:03 -0800 | [diff] [blame] | 1219 | * Tell the WebView to show the visual indicator |
| 1220 | * @param flag True if the WebView should show the visual indicator |
| 1221 | * @hide |
| 1222 | */ |
| 1223 | public synchronized void setShowVisualIndicator(boolean flag) { |
| 1224 | if (mShowVisualIndicator != flag) { |
| 1225 | mShowVisualIndicator = flag; |
| 1226 | postSync(); |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * @return True if the WebView is showing the visual indicator |
| 1232 | * @hide |
| 1233 | */ |
| 1234 | public synchronized boolean getShowVisualIndicator() { |
| 1235 | return mShowVisualIndicator; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1239 | * Tell the WebView to enable plugins. |
| 1240 | * @param flag True if the WebView should load plugins. |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 1241 | * @deprecated This method has been deprecated in favor of |
| 1242 | * {@link #setPluginState} |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1243 | */ |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1244 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1245 | public synchronized void setPluginsEnabled(boolean flag) { |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 1246 | setPluginState(PluginState.ON); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * Tell the WebView to enable, disable, or have plugins on demand. On |
| 1251 | * demand mode means that if a plugin exists that can handle the embedded |
| 1252 | * content, a placeholder icon will be shown instead of the plugin. When |
| 1253 | * the placeholder is clicked, the plugin will be enabled. |
| 1254 | * @param state One of the PluginState values. |
| 1255 | */ |
| 1256 | public synchronized void setPluginState(PluginState state) { |
| 1257 | if (mPluginState != state) { |
| 1258 | mPluginState = state; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1259 | postSync(); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Derek Sollenberger | fdbdeb3 | 2010-08-12 11:20:13 -0400 | [diff] [blame] | 1264 | * Set a custom path to plugins used by the WebView. This method is |
| 1265 | * obsolete since each plugin is now loaded from its own package. |
| 1266 | * @param pluginsPath String path to the directory containing plugins. |
| 1267 | * @deprecated This method is no longer used as plugins are loaded from |
| 1268 | * their own APK via the system's package manager. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1269 | */ |
Jason Chen | 9dc2e75 | 2010-09-01 19:11:14 -0700 | [diff] [blame] | 1270 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1271 | public synchronized void setPluginsPath(String pluginsPath) { |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /** |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1275 | * Set the path to where database storage API databases should be saved. |
Ben Murdoch | 18773af | 2010-02-25 18:41:56 +0000 | [diff] [blame] | 1276 | * Nota that the WebCore Database Tracker only allows the path to be set once. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1277 | * This will update WebCore when the Sync runs in the C++ side. |
| 1278 | * @param databasePath String path to the directory where databases should |
| 1279 | * be saved. May be the empty string but should never be null. |
| 1280 | */ |
| 1281 | public synchronized void setDatabasePath(String databasePath) { |
Ben Murdoch | 18773af | 2010-02-25 18:41:56 +0000 | [diff] [blame] | 1282 | if (databasePath != null && !mDatabasePathHasBeenSet) { |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1283 | mDatabasePath = databasePath; |
Ben Murdoch | 18773af | 2010-02-25 18:41:56 +0000 | [diff] [blame] | 1284 | mDatabasePathHasBeenSet = true; |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1285 | postSync(); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | /** |
Steve Block | 9d3273f | 2009-08-21 13:16:27 +0100 | [diff] [blame] | 1290 | * Set the path where the Geolocation permissions database should be saved. |
| 1291 | * This will update WebCore when the Sync runs in the C++ side. |
| 1292 | * @param databasePath String path to the directory where the Geolocation |
| 1293 | * permissions database should be saved. May be the empty string but |
| 1294 | * should never be null. |
Steve Block | 9d3273f | 2009-08-21 13:16:27 +0100 | [diff] [blame] | 1295 | */ |
| 1296 | public synchronized void setGeolocationDatabasePath(String databasePath) { |
Grace Kloba | 8f5e405 | 2009-10-06 12:56:07 -0700 | [diff] [blame] | 1297 | if (databasePath != null |
| 1298 | && !databasePath.equals(mGeolocationDatabasePath)) { |
Steve Block | 9d3273f | 2009-08-21 13:16:27 +0100 | [diff] [blame] | 1299 | mGeolocationDatabasePath = databasePath; |
| 1300 | postSync(); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /** |
Andrei Popescu | 60a9a7d | 2009-04-17 10:43:42 +0100 | [diff] [blame] | 1305 | * Tell the WebView to enable Application Caches API. |
| 1306 | * @param flag True if the WebView should enable Application Caches. |
Andrei Popescu | 60a9a7d | 2009-04-17 10:43:42 +0100 | [diff] [blame] | 1307 | */ |
| 1308 | public synchronized void setAppCacheEnabled(boolean flag) { |
| 1309 | if (mAppCacheEnabled != flag) { |
| 1310 | mAppCacheEnabled = flag; |
| 1311 | postSync(); |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * Set a custom path to the Application Caches files. The client |
| 1317 | * must ensure it exists before this call. |
| 1318 | * @param appCachePath String path to the directory containing Application |
| 1319 | * Caches files. The appCache path can be the empty string but should not |
| 1320 | * be null. Passing null for this parameter will result in a no-op. |
Andrei Popescu | 60a9a7d | 2009-04-17 10:43:42 +0100 | [diff] [blame] | 1321 | */ |
| 1322 | public synchronized void setAppCachePath(String appCachePath) { |
| 1323 | if (appCachePath != null && !appCachePath.equals(mAppCachePath)) { |
| 1324 | mAppCachePath = appCachePath; |
| 1325 | postSync(); |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | /** |
Andrei Popescu | 1c82920 | 2009-07-22 16:47:52 +0100 | [diff] [blame] | 1330 | * Set the maximum size for the Application Caches content. |
| 1331 | * @param appCacheMaxSize the maximum size in bytes. |
Andrei Popescu | 1c82920 | 2009-07-22 16:47:52 +0100 | [diff] [blame] | 1332 | */ |
| 1333 | public synchronized void setAppCacheMaxSize(long appCacheMaxSize) { |
| 1334 | if (appCacheMaxSize != mAppCacheMaxSize) { |
| 1335 | mAppCacheMaxSize = appCacheMaxSize; |
| 1336 | postSync(); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1341 | * Set whether the database storage API is enabled. |
| 1342 | * @param flag boolean True if the WebView should use the database storage |
| 1343 | * API. |
| 1344 | */ |
| 1345 | public synchronized void setDatabaseEnabled(boolean flag) { |
| 1346 | if (mDatabaseEnabled != flag) { |
| 1347 | mDatabaseEnabled = flag; |
| 1348 | postSync(); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /** |
Ben Murdoch | 274680d | 2009-05-28 13:44:44 +0100 | [diff] [blame] | 1353 | * Set whether the DOM storage API is enabled. |
| 1354 | * @param flag boolean True if the WebView should use the DOM storage |
| 1355 | * API. |
Ben Murdoch | 274680d | 2009-05-28 13:44:44 +0100 | [diff] [blame] | 1356 | */ |
| 1357 | public synchronized void setDomStorageEnabled(boolean flag) { |
| 1358 | if (mDomStorageEnabled != flag) { |
| 1359 | mDomStorageEnabled = flag; |
| 1360 | postSync(); |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * Returns true if the DOM Storage API's are enabled. |
| 1366 | * @return True if the DOM Storage API's are enabled. |
Ben Murdoch | 274680d | 2009-05-28 13:44:44 +0100 | [diff] [blame] | 1367 | */ |
| 1368 | public synchronized boolean getDomStorageEnabled() { |
| 1369 | return mDomStorageEnabled; |
| 1370 | } |
| 1371 | |
| 1372 | /** |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 1373 | * Return the path to where database storage API databases are saved for |
| 1374 | * the current WebView. |
| 1375 | * @return the String path to the database storage API databases. |
| 1376 | */ |
| 1377 | public synchronized String getDatabasePath() { |
| 1378 | return mDatabasePath; |
| 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * Returns true if database storage API is enabled. |
| 1383 | * @return True if the database storage API is enabled. |
| 1384 | */ |
| 1385 | public synchronized boolean getDatabaseEnabled() { |
| 1386 | return mDatabaseEnabled; |
| 1387 | } |
| 1388 | |
| 1389 | /** |
Andrei Popescu | c27a9ac | 2009-08-03 15:59:24 +0100 | [diff] [blame] | 1390 | * Tell the WebView to enable WebWorkers API. |
| 1391 | * @param flag True if the WebView should enable WebWorkers. |
| 1392 | * Note that this flag only affects V8. JSC does not have |
| 1393 | * an equivalent setting. |
| 1394 | * @hide pending api council approval |
| 1395 | */ |
| 1396 | public synchronized void setWorkersEnabled(boolean flag) { |
| 1397 | if (mWorkersEnabled != flag) { |
| 1398 | mWorkersEnabled = flag; |
| 1399 | postSync(); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Steve Block | 06cd751 | 2009-08-21 10:26:37 +0100 | [diff] [blame] | 1404 | * Sets whether Geolocation is enabled. |
| 1405 | * @param flag Whether Geolocation should be enabled. |
Steve Block | 06cd751 | 2009-08-21 10:26:37 +0100 | [diff] [blame] | 1406 | */ |
| 1407 | public synchronized void setGeolocationEnabled(boolean flag) { |
| 1408 | if (mGeolocationEnabled != flag) { |
| 1409 | mGeolocationEnabled = flag; |
| 1410 | postSync(); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | /** |
Elliott Slaughter | 5dc0c82 | 2010-06-22 11:31:54 -0700 | [diff] [blame] | 1415 | * Sets whether XSS Auditor is enabled. |
| 1416 | * @param flag Whether XSS Auditor should be enabled. |
Elliott Slaughter | be1304f | 2010-06-23 11:29:02 -0700 | [diff] [blame] | 1417 | * @hide Only used by LayoutTestController. |
Elliott Slaughter | 5dc0c82 | 2010-06-22 11:31:54 -0700 | [diff] [blame] | 1418 | */ |
| 1419 | public synchronized void setXSSAuditorEnabled(boolean flag) { |
| 1420 | if (mXSSAuditorEnabled != flag) { |
| 1421 | mXSSAuditorEnabled = flag; |
| 1422 | postSync(); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1427 | * Return true if javascript is enabled. <b>Note: The default is false.</b> |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1428 | * @return True if javascript is enabled. |
| 1429 | */ |
| 1430 | public synchronized boolean getJavaScriptEnabled() { |
| 1431 | return mJavaScriptEnabled; |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * Return true if plugins are enabled. |
| 1436 | * @return True if plugins are enabled. |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 1437 | * @deprecated This method has been replaced by {@link #getPluginState} |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1438 | */ |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1439 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1440 | public synchronized boolean getPluginsEnabled() { |
Patrick Scott | 300f2e9 | 2010-03-22 10:20:45 -0400 | [diff] [blame] | 1441 | return mPluginState == PluginState.ON; |
| 1442 | } |
| 1443 | |
| 1444 | /** |
| 1445 | * Return the current plugin state. |
| 1446 | * @return A value corresponding to the enum PluginState. |
| 1447 | */ |
| 1448 | public synchronized PluginState getPluginState() { |
| 1449 | return mPluginState; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
Derek Sollenberger | fdbdeb3 | 2010-08-12 11:20:13 -0400 | [diff] [blame] | 1453 | * Returns the directory that contains the plugin libraries. This method is |
| 1454 | * obsolete since each plugin is now loaded from its own package. |
| 1455 | * @return An empty string. |
| 1456 | * @deprecated This method is no longer used as plugins are loaded from |
| 1457 | * their own APK via the system's package manager. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1458 | */ |
Jason Chen | 9dc2e75 | 2010-09-01 19:11:14 -0700 | [diff] [blame] | 1459 | @Deprecated |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1460 | public synchronized String getPluginsPath() { |
Grace Kloba | 658ab7d | 2009-05-14 14:45:26 -0700 | [diff] [blame] | 1461 | return ""; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * Tell javascript to open windows automatically. This applies to the |
| 1466 | * javascript function window.open(). |
| 1467 | * @param flag True if javascript can open windows automatically. |
| 1468 | */ |
| 1469 | public synchronized void setJavaScriptCanOpenWindowsAutomatically( |
| 1470 | boolean flag) { |
| 1471 | if (mJavaScriptCanOpenWindowsAutomatically != flag) { |
| 1472 | mJavaScriptCanOpenWindowsAutomatically = flag; |
| 1473 | postSync(); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1478 | * Return true if javascript can open windows automatically. The default |
| 1479 | * is false. |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1480 | * @return True if javascript can open windows automatically during |
| 1481 | * window.open(). |
| 1482 | */ |
| 1483 | public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() { |
| 1484 | return mJavaScriptCanOpenWindowsAutomatically; |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * Set the default text encoding name to use when decoding html pages. |
| 1489 | * @param encoding The text encoding name. |
| 1490 | */ |
| 1491 | public synchronized void setDefaultTextEncodingName(String encoding) { |
| 1492 | if (encoding != null && !encoding.equals(mDefaultTextEncoding)) { |
| 1493 | mDefaultTextEncoding = encoding; |
| 1494 | postSync(); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | /** |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1499 | * Get the default text encoding name. The default is "Latin-1". |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1500 | * @return The default text encoding name as a string. |
| 1501 | */ |
| 1502 | public synchronized String getDefaultTextEncodingName() { |
| 1503 | return mDefaultTextEncoding; |
| 1504 | } |
| 1505 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1506 | /** |
| 1507 | * Set the WebView's user-agent string. If the string "ua" is null or empty, |
| 1508 | * it will use the system default user-agent string. |
| 1509 | */ |
| 1510 | public synchronized void setUserAgentString(String ua) { |
| 1511 | if (ua == null || ua.length() == 0) { |
| 1512 | synchronized(sLockForLocaleSettings) { |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1513 | Locale currentLocale = Locale.getDefault(); |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1514 | if (!sLocale.equals(currentLocale)) { |
| 1515 | sLocale = currentLocale; |
| 1516 | mAcceptLanguage = getCurrentAcceptLanguage(); |
| 1517 | } |
| 1518 | } |
| 1519 | ua = getCurrentUserAgent(); |
| 1520 | mUseDefaultUserAgent = true; |
| 1521 | } else { |
| 1522 | mUseDefaultUserAgent = false; |
| 1523 | } |
| 1524 | |
| 1525 | if (!ua.equals(mUserAgent)) { |
| 1526 | mUserAgent = ua; |
| 1527 | postSync(); |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Return the WebView's user-agent string. |
| 1533 | */ |
| 1534 | public synchronized String getUserAgentString() { |
| 1535 | if (DESKTOP_USERAGENT.equals(mUserAgent) || |
| 1536 | IPHONE_USERAGENT.equals(mUserAgent) || |
| 1537 | !mUseDefaultUserAgent) { |
| 1538 | return mUserAgent; |
| 1539 | } |
| 1540 | |
| 1541 | boolean doPostSync = false; |
| 1542 | synchronized(sLockForLocaleSettings) { |
| 1543 | Locale currentLocale = Locale.getDefault(); |
| 1544 | if (!sLocale.equals(currentLocale)) { |
| 1545 | sLocale = currentLocale; |
| 1546 | mUserAgent = getCurrentUserAgent(); |
| 1547 | mAcceptLanguage = getCurrentAcceptLanguage(); |
| 1548 | doPostSync = true; |
| 1549 | } |
| 1550 | } |
| 1551 | if (doPostSync) { |
| 1552 | postSync(); |
| 1553 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1554 | return mUserAgent; |
| 1555 | } |
| 1556 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1557 | /* package api to grab the Accept Language string. */ |
| 1558 | /*package*/ synchronized String getAcceptLanguage() { |
| 1559 | synchronized(sLockForLocaleSettings) { |
| 1560 | Locale currentLocale = Locale.getDefault(); |
| 1561 | if (!sLocale.equals(currentLocale)) { |
| 1562 | sLocale = currentLocale; |
| 1563 | mAcceptLanguage = getCurrentAcceptLanguage(); |
| 1564 | } |
| 1565 | } |
| 1566 | return mAcceptLanguage; |
| 1567 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1568 | |
Shimeng (Simon) Wang | c55886a | 2010-10-28 13:46:02 -0700 | [diff] [blame] | 1569 | /* package */ boolean isNarrowColumnLayout() { |
| 1570 | return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS; |
| 1571 | } |
| 1572 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1573 | /** |
| 1574 | * Tell the WebView whether it needs to set a node to have focus when |
| 1575 | * {@link WebView#requestFocus(int, android.graphics.Rect)} is called. |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1576 | * |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1577 | * @param flag |
| 1578 | */ |
| 1579 | public void setNeedInitialFocus(boolean flag) { |
| 1580 | if (mNeedInitialFocus != flag) { |
| 1581 | mNeedInitialFocus = flag; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | /* Package api to get the choice whether it needs to set initial focus. */ |
| 1586 | /* package */ boolean getNeedInitialFocus() { |
| 1587 | return mNeedInitialFocus; |
| 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * Set the priority of the Render thread. Unlike the other settings, this |
Mike Hearn | adcd2ed | 2009-01-21 16:44:36 +0100 | [diff] [blame] | 1592 | * one only needs to be called once per process. The default is NORMAL. |
| 1593 | * |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1594 | * @param priority RenderPriority, can be normal, high or low. |
| 1595 | */ |
| 1596 | public synchronized void setRenderPriority(RenderPriority priority) { |
| 1597 | if (mRenderPriority != priority) { |
| 1598 | mRenderPriority = priority; |
| 1599 | mEventHandler.sendMessage(Message.obtain(null, |
| 1600 | EventHandler.PRIORITY)); |
| 1601 | } |
| 1602 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1603 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1604 | /** |
| 1605 | * Override the way the cache is used. The way the cache is used is based |
| 1606 | * on the navigation option. For a normal page load, the cache is checked |
| 1607 | * and content is re-validated as needed. When navigating back, content is |
| 1608 | * not revalidated, instead the content is just pulled from the cache. |
| 1609 | * This function allows the client to override this behavior. |
| 1610 | * @param mode One of the LOAD_ values. |
| 1611 | */ |
| 1612 | public void setCacheMode(int mode) { |
| 1613 | if (mode != mOverrideCacheMode) { |
| 1614 | mOverrideCacheMode = mode; |
Kristian Monsen | c40fc87 | 2011-01-19 15:44:04 +0000 | [diff] [blame] | 1615 | postSync(); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1616 | } |
| 1617 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1618 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1619 | /** |
| 1620 | * Return the current setting for overriding the cache mode. For a full |
| 1621 | * description, see the {@link #setCacheMode(int)} function. |
| 1622 | */ |
| 1623 | public int getCacheMode() { |
| 1624 | return mOverrideCacheMode; |
| 1625 | } |
Michael Kolb | a172e7d | 2010-06-30 12:35:26 -0700 | [diff] [blame] | 1626 | |
The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1627 | /** |
| 1628 | * If set, webkit alternately shrinks and expands images viewed outside |
| 1629 | * of an HTML page to fit the screen. This conflicts with attempts by |
| 1630 | * the UI to zoom in and out of an image, so it is set false by default. |
| 1631 | * @param shrink Set true to let webkit shrink the standalone image to fit. |
| 1632 | * {@hide} |
| 1633 | */ |
| 1634 | public void setShrinksStandaloneImagesToFit(boolean shrink) { |
| 1635 | if (mShrinksStandaloneImagesToFit != shrink) { |
| 1636 | mShrinksStandaloneImagesToFit = shrink; |
| 1637 | postSync(); |
| 1638 | } |
| 1639 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1640 | |
Cary Clark | f0785a6 | 2010-06-25 11:45:40 -0400 | [diff] [blame] | 1641 | /** |
| 1642 | * Specify the maximum decoded image size. The default is |
| 1643 | * 2 megs for small memory devices and 8 megs for large memory devices. |
| 1644 | * @param size The maximum decoded size, or zero to set to the default. |
| 1645 | * @hide pending api council approval |
| 1646 | */ |
| 1647 | public void setMaximumDecodedImageSize(long size) { |
| 1648 | if (mMaximumDecodedImageSize != size) { |
| 1649 | mMaximumDecodedImageSize = size; |
| 1650 | postSync(); |
| 1651 | } |
| 1652 | } |
| 1653 | |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 1654 | /** |
Shimeng (Simon) Wang | 2c782e3 | 2011-01-04 13:32:06 -0800 | [diff] [blame] | 1655 | * Returns whether to use fixed viewport. Fixed viewport should operate only |
| 1656 | * when wide viewport is on. |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 1657 | */ |
| 1658 | /* package */ boolean getUseFixedViewport() { |
Shimeng (Simon) Wang | 2c782e3 | 2011-01-04 13:32:06 -0800 | [diff] [blame] | 1659 | return getUseWideViewPort() && mUseFixedViewport; |
Shimeng (Simon) Wang | c1cba78 | 2010-08-17 10:53:59 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /** |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 1663 | * Returns whether private browsing is enabled. |
| 1664 | */ |
| 1665 | /* package */ boolean isPrivateBrowsingEnabled() { |
| 1666 | return mPrivateBrowsingEnabled; |
| 1667 | } |
| 1668 | |
| 1669 | /** |
| 1670 | * Sets whether private browsing is enabled. |
| 1671 | * @param flag Whether private browsing should be enabled. |
| 1672 | */ |
| 1673 | /* package */ synchronized void setPrivateBrowsingEnabled(boolean flag) { |
| 1674 | if (mPrivateBrowsingEnabled != flag) { |
| 1675 | mPrivateBrowsingEnabled = flag; |
Ben Murdoch | 4bd87d6 | 2011-01-18 14:10:48 +0000 | [diff] [blame] | 1676 | |
| 1677 | // AutoFill is dependant on private browsing being enabled so |
| 1678 | // reset it to take account of the new value of mPrivateBrowsingEnabled. |
| 1679 | setAutoFillEnabled(mAutoFillEnabled); |
| 1680 | |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 1681 | postSync(); |
| 1682 | } |
| 1683 | } |
| 1684 | |
John Reck | 7818aaa | 2011-04-26 16:57:46 -0700 | [diff] [blame] | 1685 | /** |
| 1686 | * Returns whether the viewport metatag can disable zooming |
| 1687 | * @hide |
| 1688 | */ |
| 1689 | public boolean forceUserScalable() { |
| 1690 | return mForceUserScalable; |
| 1691 | } |
| 1692 | |
| 1693 | /** |
| 1694 | * Sets whether viewport metatag can disable zooming. |
| 1695 | * @param flag Whether or not to forceably enable user scalable. |
| 1696 | * @hide |
| 1697 | */ |
| 1698 | public synchronized void setForceUserScalable(boolean flag) { |
| 1699 | mForceUserScalable = flag; |
| 1700 | } |
| 1701 | |
Cary Clark | 6c43d52 | 2010-08-31 15:41:54 -0400 | [diff] [blame] | 1702 | synchronized void setSyntheticLinksEnabled(boolean flag) { |
| 1703 | if (mSyntheticLinksEnabled != flag) { |
| 1704 | mSyntheticLinksEnabled = flag; |
| 1705 | postSync(); |
| 1706 | } |
| 1707 | } |
| 1708 | |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 1709 | /** |
| 1710 | * @hide |
| 1711 | */ |
| 1712 | public synchronized void setAutoFillEnabled(boolean enabled) { |
Ben Murdoch | 4bd87d6 | 2011-01-18 14:10:48 +0000 | [diff] [blame] | 1713 | // AutoFill is always disabled in private browsing mode. |
| 1714 | boolean autoFillEnabled = enabled && !mPrivateBrowsingEnabled; |
| 1715 | if (mAutoFillEnabled != autoFillEnabled) { |
| 1716 | mAutoFillEnabled = autoFillEnabled; |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 1717 | postSync(); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * @hide |
| 1723 | */ |
| 1724 | public synchronized boolean getAutoFillEnabled() { |
| 1725 | return mAutoFillEnabled; |
| 1726 | } |
| 1727 | |
| 1728 | /** |
| 1729 | * @hide |
| 1730 | */ |
| 1731 | public synchronized void setAutoFillProfile(AutoFillProfile profile) { |
Ben Murdoch | b1b82a8 | 2010-10-20 14:18:25 +0100 | [diff] [blame] | 1732 | if (mAutoFillProfile != profile) { |
| 1733 | mAutoFillProfile = profile; |
| 1734 | postSync(); |
| 1735 | } |
Ben Murdoch | e9e3ccd | 2010-10-06 14:33:02 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
Ben Murdoch | 5791438 | 2010-11-16 11:50:39 +0000 | [diff] [blame] | 1738 | /** |
| 1739 | * @hide |
| 1740 | */ |
| 1741 | public synchronized AutoFillProfile getAutoFillProfile() { |
| 1742 | return mAutoFillProfile; |
| 1743 | } |
| 1744 | |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 1745 | int getDoubleTapToastCount() { |
| 1746 | return mDoubleTapToastCount; |
| 1747 | } |
| 1748 | |
| 1749 | void setDoubleTapToastCount(int count) { |
| 1750 | if (mDoubleTapToastCount != count) { |
| 1751 | mDoubleTapToastCount = count; |
| 1752 | // write the settings in the non-UI thread |
| 1753 | mEventHandler.sendMessage(Message.obtain(null, |
| 1754 | EventHandler.SET_DOUBLE_TAP_TOAST_COUNT)); |
| 1755 | } |
| 1756 | } |
| 1757 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1758 | /** |
| 1759 | * Transfer messages from the queue to the new WebCoreThread. Called from |
| 1760 | * WebCore thread. |
| 1761 | */ |
| 1762 | /*package*/ |
| 1763 | synchronized void syncSettingsAndCreateHandler(BrowserFrame frame) { |
| 1764 | mBrowserFrame = frame; |
Derek Sollenberger | 2e5c150 | 2009-06-03 10:44:42 -0400 | [diff] [blame] | 1765 | if (DebugFlags.WEB_SETTINGS) { |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1766 | junit.framework.Assert.assertTrue(frame.mNativeFrame != 0); |
| 1767 | } |
Andrei Popescu | dee76be | 2009-09-22 18:28:21 +0100 | [diff] [blame] | 1768 | |
Grace Kloba | f8d8b46 | 2009-09-20 15:57:49 -0700 | [diff] [blame] | 1769 | SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE, |
| 1770 | Context.MODE_PRIVATE); |
Grace Kloba | 24a3ff9 | 2009-09-22 10:42:22 -0700 | [diff] [blame] | 1771 | if (mDoubleTapToastCount > 0) { |
| 1772 | mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT, |
| 1773 | mDoubleTapToastCount); |
| 1774 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1775 | nativeSync(frame.mNativeFrame); |
| 1776 | mSyncPending = false; |
| 1777 | mEventHandler.createHandler(); |
| 1778 | } |
| 1779 | |
Andrei Popescu | dee76be | 2009-09-22 18:28:21 +0100 | [diff] [blame] | 1780 | /** |
| 1781 | * Let the Settings object know that our owner is being destroyed. |
| 1782 | */ |
| 1783 | /*package*/ |
| 1784 | synchronized void onDestroyed() { |
Andrei Popescu | dee76be | 2009-09-22 18:28:21 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1787 | private int pin(int size) { |
| 1788 | // FIXME: 72 is just an arbitrary max text size value. |
| 1789 | if (size < 1) { |
| 1790 | return 1; |
| 1791 | } else if (size > 72) { |
| 1792 | return 72; |
| 1793 | } |
| 1794 | return size; |
| 1795 | } |
| 1796 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1797 | /* Post a SYNC message to handle syncing the native settings. */ |
| 1798 | private synchronized void postSync() { |
| 1799 | // Only post if a sync is not pending |
| 1800 | if (!mSyncPending) { |
| 1801 | mSyncPending = mEventHandler.sendMessage( |
| 1802 | Message.obtain(null, EventHandler.SYNC)); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | // Synchronize the native and java settings. |
| 1807 | private native void nativeSync(int nativeFrame); |
| 1808 | } |