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