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