blob: 8ffbda2a128042a92dcbcf44d80038af567b2775 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
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
17package android.webkit;
18
19import android.content.Context;
Grace Klobaf8d8b462009-09-20 15:57:49 -070020import android.content.SharedPreferences;
Andrei Popescu972acd02009-07-10 16:58:13 +010021import android.content.pm.PackageManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070022import android.os.Build;
23import android.os.Handler;
24import android.os.Message;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -070025import android.util.DisplayMetrics;
Dan Egnor18e93962010-02-10 19:27:58 -080026import android.util.EventLog;
Michael Kolb37b64de2010-07-01 12:05:47 -070027
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070028import java.util.Locale;
29
30/**
31 * Manages settings state for a WebView. When a WebView is first created, it
32 * obtains a set of default settings. These default settings will be returned
33 * from any getter call. A WebSettings object obtained from
34 * WebView.getSettings() is tied to the life of the WebView. If a WebView has
35 * been destroyed, any method call on WebSettings will throw an
36 * IllegalStateException.
37 */
38public class WebSettings {
39 /**
40 * Enum for controlling the layout of html.
41 * NORMAL means no rendering changes.
42 * SINGLE_COLUMN moves all content into one column that is the width of the
43 * view.
44 * NARROW_COLUMNS makes all columns no wider than the screen if possible.
Kristian Monsenfc771652011-05-10 16:44:05 +010045 * @deprecated This enum is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070046 */
47 // XXX: These must match LayoutAlgorithm in Settings.h in WebCore.
Kristian Monsenfc771652011-05-10 16:44:05 +010048 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070049 public enum LayoutAlgorithm {
50 NORMAL,
51 SINGLE_COLUMN,
52 NARROW_COLUMNS
53 }
54
55 /**
56 * Enum for specifying the text size.
57 * SMALLEST is 50%
58 * SMALLER is 75%
59 * NORMAL is 100%
60 * LARGER is 150%
61 * LARGEST is 200%
62 */
63 public enum TextSize {
64 SMALLEST(50),
65 SMALLER(75),
66 NORMAL(100),
67 LARGER(150),
68 LARGEST(200);
69 TextSize(int size) {
70 value = size;
71 }
72 int value;
73 }
Grace Kloba0d8b77c2009-06-25 11:20:51 -070074
75 /**
76 * Enum for specifying the WebView's desired density.
77 * FAR makes 100% looking like in 240dpi
78 * MEDIUM makes 100% looking like in 160dpi
79 * CLOSE makes 100% looking like in 120dpi
Grace Kloba0d8b77c2009-06-25 11:20:51 -070080 */
81 public enum ZoomDensity {
82 FAR(150), // 240dpi
83 MEDIUM(100), // 160dpi
84 CLOSE(75); // 120dpi
85 ZoomDensity(int size) {
86 value = size;
87 }
88 int value;
89 }
90
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070091 /**
92 * Default cache usage pattern Use with {@link #setCacheMode}.
93 */
94 public static final int LOAD_DEFAULT = -1;
95
96 /**
97 * Normal cache usage pattern Use with {@link #setCacheMode}.
98 */
99 public static final int LOAD_NORMAL = 0;
100
101 /**
102 * Use cache if content is there, even if expired (eg, history nav)
103 * If it is not in the cache, load from network.
104 * Use with {@link #setCacheMode}.
105 */
106 public static final int LOAD_CACHE_ELSE_NETWORK = 1;
107
108 /**
109 * Don't use the cache, load from network
110 * Use with {@link #setCacheMode}.
111 */
112 public static final int LOAD_NO_CACHE = 2;
Michael Kolba172e7d2010-06-30 12:35:26 -0700113
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700114 /**
115 * Don't use the network, load from cache only.
116 * Use with {@link #setCacheMode}.
117 */
118 public static final int LOAD_CACHE_ONLY = 3;
119
120 public enum RenderPriority {
121 NORMAL,
122 HIGH,
123 LOW
124 }
125
Patrick Scott300f2e92010-03-22 10:20:45 -0400126 /**
127 * The plugin state effects how plugins are treated on a page. ON means
128 * that any object will be loaded even if a plugin does not exist to handle
129 * the content. ON_DEMAND means that if there is a plugin installed that
130 * can handle the content, a placeholder is shown until the user clicks on
131 * the placeholder. Once clicked, the plugin will be enabled on the page.
132 * OFF means that all plugins will be turned off and any fallback content
133 * will be used.
134 */
135 public enum PluginState {
136 ON,
137 ON_DEMAND,
138 OFF
139 }
140
John Reckf5577402011-04-28 10:27:40 -0700141 // TODO: Keep this up to date
142 private static final String PREVIOUS_VERSION = "3.1";
143
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700144 // WebView associated with this WebSettings.
145 private WebView mWebView;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700146 // BrowserFrame used to access the native frame pointer.
147 private BrowserFrame mBrowserFrame;
148 // Flag to prevent multiple SYNC messages at one time.
149 private boolean mSyncPending = false;
150 // Custom handler that queues messages until the WebCore thread is active.
151 private final EventHandler mEventHandler;
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100152
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700153 // Private settings so we don't have to go into native code to
154 // retrieve the values. After setXXX, postSync() needs to be called.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100155 //
156 // The default values need to match those in WebSettings.cpp
157 // If the defaults change, please also update the JavaDocs so developers
158 // know what they are.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700159 private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800160 private Context mContext;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700161 private TextSize mTextSize = TextSize.NORMAL;
162 private String mStandardFontFamily = "sans-serif";
163 private String mFixedFontFamily = "monospace";
164 private String mSansSerifFontFamily = "sans-serif";
165 private String mSerifFontFamily = "serif";
166 private String mCursiveFontFamily = "cursive";
167 private String mFantasyFontFamily = "fantasy";
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900168 private String mDefaultTextEncoding;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800169 private String mUserAgent;
170 private boolean mUseDefaultUserAgent;
171 private String mAcceptLanguage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700172 private int mMinimumFontSize = 8;
173 private int mMinimumLogicalFontSize = 8;
174 private int mDefaultFontSize = 16;
175 private int mDefaultFixedFontSize = 13;
Grace Kloba097b1e772009-11-24 14:23:18 -0800176 private int mPageCacheCapacity = 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700177 private boolean mLoadsImagesAutomatically = true;
178 private boolean mBlockNetworkImage = false;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700179 private boolean mBlockNetworkLoads;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700180 private boolean mJavaScriptEnabled = false;
Teng-Hui Zhuda7378e2011-02-16 11:25:03 -0800181 private boolean mShowVisualIndicator = false;
Patrick Scott300f2e92010-03-22 10:20:45 -0400182 private PluginState mPluginState = PluginState.OFF;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700183 private boolean mJavaScriptCanOpenWindowsAutomatically = false;
184 private boolean mUseDoubleTree = false;
185 private boolean mUseWideViewport = false;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -0700186 private boolean mUseFixedViewport = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700187 private boolean mSupportMultipleWindows = false;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800188 private boolean mShrinksStandaloneImagesToFit = false;
Cary Clarkf0785a62010-06-25 11:45:40 -0400189 private long mMaximumDecodedImageSize = 0; // 0 means default
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700190 private boolean mPrivateBrowsingEnabled = false;
Cary Clark6c43d522010-08-31 15:41:54 -0400191 private boolean mSyntheticLinksEnabled = true;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100192 // HTML5 API flags
193 private boolean mAppCacheEnabled = false;
194 private boolean mDatabaseEnabled = false;
195 private boolean mDomStorageEnabled = false;
196 private boolean mWorkersEnabled = false; // only affects V8.
Steve Block09b0ca12009-08-26 18:16:58 +0100197 private boolean mGeolocationEnabled = true;
Elliott Slaughter5dc0c822010-06-22 11:31:54 -0700198 private boolean mXSSAuditorEnabled = false;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100199 // HTML5 configuration parameters
200 private long mAppCacheMaxSize = Long.MAX_VALUE;
201 private String mAppCachePath = "";
202 private String mDatabasePath = "";
Ben Murdoch18773af2010-02-25 18:41:56 +0000203 // The WebCore DatabaseTracker only allows the database path to be set
204 // once. Keep track of when the path has been set.
205 private boolean mDatabasePathHasBeenSet = false;
Steve Block9d3273f2009-08-21 13:16:27 +0100206 private String mGeolocationDatabasePath = "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700207 // Don't need to synchronize the get/set methods as they
208 // are basic types, also none of these values are used in
209 // native WebCore code.
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700210 private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700211 private RenderPriority mRenderPriority = RenderPriority.NORMAL;
212 private int mOverrideCacheMode = LOAD_DEFAULT;
213 private boolean mSaveFormData = true;
Ben Murdochf39b2cf2010-09-09 10:26:46 +0100214 private boolean mAutoFillEnabled = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700215 private boolean mSavePassword = true;
216 private boolean mLightTouchEnabled = false;
217 private boolean mNeedInitialFocus = true;
218 private boolean mNavDump = false;
219 private boolean mSupportZoom = true;
The Android Open Source Project10592532009-03-18 17:39:46 -0700220 private boolean mBuiltInZoomControls = false;
Michael Kolb6fe3b422010-08-19 12:41:24 -0700221 private boolean mDisplayZoomControls = true;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800222 private boolean mAllowFileAccess = true;
Patrick Scottd1737ed2011-01-05 11:36:48 -0500223 private boolean mAllowContentAccess = true;
Cary Clarkf8d49642009-09-08 13:23:24 -0400224 private boolean mLoadWithOverviewMode = false;
Grace Klobaf9b731d2010-06-21 19:23:57 -0700225 private boolean mEnableSmoothTransition = false;
John Reck7818aaa2011-04-26 16:57:46 -0700226 private boolean mForceUserScalable = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700227
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100228 // AutoFill Profile data
229 /**
230 * @hide for now, pending API council approval.
231 */
232 public static class AutoFillProfile {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100233 private int mUniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100234 private String mFullName;
235 private String mEmailAddress;
Ben Murdochcf308722010-10-13 17:38:46 +0100236 private String mCompanyName;
237 private String mAddressLine1;
238 private String mAddressLine2;
239 private String mCity;
240 private String mState;
241 private String mZipCode;
242 private String mCountry;
243 private String mPhoneNumber;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100244
Ben Murdochb1b82a82010-10-20 14:18:25 +0100245 public AutoFillProfile(int uniqueId, String fullName, String email,
Ben Murdochcf308722010-10-13 17:38:46 +0100246 String companyName, String addressLine1, String addressLine2,
247 String city, String state, String zipCode, String country,
248 String phoneNumber) {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100249 mUniqueId = uniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100250 mFullName = fullName;
251 mEmailAddress = email;
Ben Murdochcf308722010-10-13 17:38:46 +0100252 mCompanyName = companyName;
253 mAddressLine1 = addressLine1;
254 mAddressLine2 = addressLine2;
255 mCity = city;
256 mState = state;
257 mZipCode = zipCode;
258 mCountry = country;
259 mPhoneNumber = phoneNumber;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100260 }
261
Ben Murdochb1b82a82010-10-20 14:18:25 +0100262 public int getUniqueId() { return mUniqueId; }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100263 public String getFullName() { return mFullName; }
264 public String getEmailAddress() { return mEmailAddress; }
Ben Murdochcf308722010-10-13 17:38:46 +0100265 public String getCompanyName() { return mCompanyName; }
266 public String getAddressLine1() { return mAddressLine1; }
267 public String getAddressLine2() { return mAddressLine2; }
268 public String getCity() { return mCity; }
269 public String getState() { return mState; }
270 public String getZipCode() { return mZipCode; }
271 public String getCountry() { return mCountry; }
272 public String getPhoneNumber() { return mPhoneNumber; }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100273 }
274
275
276 private AutoFillProfile mAutoFillProfile;
277
Adam Powell637d3372010-08-25 14:37:03 -0700278 private boolean mUseWebViewBackgroundForOverscroll = true;
279
Grace Klobaf8d8b462009-09-20 15:57:49 -0700280 // private WebSettings, not accessible by the host activity
Grace Kloba24a3ff92009-09-22 10:42:22 -0700281 static private int mDoubleTapToastCount = 3;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700282
283 private static final String PREF_FILE = "WebViewSettings";
284 private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";
285
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700286 // Class to handle messages before WebCore is ready.
287 private class EventHandler {
288 // Message id for syncing
289 static final int SYNC = 0;
290 // Message id for setting priority
291 static final int PRIORITY = 1;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700292 // Message id for writing double-tap toast count
293 static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700294 // Actual WebCore thread handler
295 private Handler mHandler;
296
297 private synchronized void createHandler() {
298 // as mRenderPriority can be set before thread is running, sync up
299 setRenderPriority();
300
301 // create a new handler
302 mHandler = new Handler() {
303 @Override
304 public void handleMessage(Message msg) {
305 switch (msg.what) {
306 case SYNC:
307 synchronized (WebSettings.this) {
308 if (mBrowserFrame.mNativeFrame != 0) {
309 nativeSync(mBrowserFrame.mNativeFrame);
310 }
311 mSyncPending = false;
312 }
313 break;
314
315 case PRIORITY: {
316 setRenderPriority();
317 break;
318 }
Grace Klobaf8d8b462009-09-20 15:57:49 -0700319
320 case SET_DOUBLE_TAP_TOAST_COUNT: {
321 SharedPreferences.Editor editor = mContext
322 .getSharedPreferences(PREF_FILE,
323 Context.MODE_PRIVATE).edit();
324 editor.putInt(DOUBLE_TAP_TOAST_COUNT,
325 mDoubleTapToastCount);
326 editor.commit();
327 break;
328 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700329 }
330 }
331 };
332 }
333
334 private void setRenderPriority() {
335 synchronized (WebSettings.this) {
336 if (mRenderPriority == RenderPriority.NORMAL) {
337 android.os.Process.setThreadPriority(
338 android.os.Process.THREAD_PRIORITY_DEFAULT);
339 } else if (mRenderPriority == RenderPriority.HIGH) {
340 android.os.Process.setThreadPriority(
341 android.os.Process.THREAD_PRIORITY_FOREGROUND +
342 android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
343 } else if (mRenderPriority == RenderPriority.LOW) {
344 android.os.Process.setThreadPriority(
345 android.os.Process.THREAD_PRIORITY_BACKGROUND);
346 }
347 }
348 }
349
350 /**
351 * Send a message to the private queue or handler.
352 */
353 private synchronized boolean sendMessage(Message msg) {
354 if (mHandler != null) {
355 mHandler.sendMessage(msg);
356 return true;
357 } else {
358 return false;
359 }
360 }
361 }
362
363 // User agent strings.
364 private static final String DESKTOP_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700365 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us)"
366 + " AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0"
367 + " Safari/530.17";
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700368 private static final String IPHONE_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700369 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)"
370 + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0"
371 + " Mobile/7A341 Safari/528.16";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800372 private static Locale sLocale;
373 private static Object sLockForLocaleSettings;
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700374
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700375 /**
376 * Package constructor to prevent clients from creating a new settings
377 * instance.
378 */
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700379 WebSettings(Context context, WebView webview) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700380 mEventHandler = new EventHandler();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800381 mContext = context;
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700382 mWebView = webview;
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900383 mDefaultTextEncoding = context.getString(com.android.internal.
384 R.string.default_text_encoding);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800385
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -0700386 // Detect tablet device for fixed viewport mode.
387 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Shimeng (Simon) Wang14bcc0e2010-09-17 10:12:05 -0700388 final int landscapeWidth = Math.max(metrics.widthPixels, metrics.heightPixels);
Shimeng (Simon) Wanga2ded6c2010-09-17 12:59:01 -0700389 final int minTabletWidth = context.getResources().getDimensionPixelSize(
390 com.android.internal.R.dimen.min_xlarge_screen_width);
391 mUseFixedViewport = (metrics.density == 1.0f && landscapeWidth >= minTabletWidth);
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -0700392
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800393 if (sLockForLocaleSettings == null) {
394 sLockForLocaleSettings = new Object();
395 sLocale = Locale.getDefault();
396 }
397 mAcceptLanguage = getCurrentAcceptLanguage();
398 mUserAgent = getCurrentUserAgent();
399 mUseDefaultUserAgent = true;
400
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700401 mBlockNetworkLoads = mContext.checkPermission(
402 "android.permission.INTERNET", android.os.Process.myPid(),
403 android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700404 }
405
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700406 private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US";
407
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700408 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800409 * Looks at sLocale and returns current AcceptLanguage String.
410 * @return Current AcceptLanguage String.
411 */
412 private String getCurrentAcceptLanguage() {
413 Locale locale;
414 synchronized(sLockForLocaleSettings) {
415 locale = sLocale;
416 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700417 StringBuilder buffer = new StringBuilder();
418 addLocaleToHttpAcceptLanguage(buffer, locale);
419
420 if (!Locale.US.equals(locale)) {
421 if (buffer.length() > 0) {
422 buffer.append(", ");
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800423 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700424 buffer.append(ACCEPT_LANG_FOR_US_LOCALE);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800425 }
426
427 return buffer.toString();
428 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700429
430 /**
431 * Convert obsolete language codes, including Hebrew/Indonesian/Yiddish,
432 * to new standard.
433 */
434 private static String convertObsoleteLanguageCodeToNew(String langCode) {
435 if (langCode == null) {
436 return null;
437 }
438 if ("iw".equals(langCode)) {
439 // Hebrew
440 return "he";
441 } else if ("in".equals(langCode)) {
442 // Indonesian
443 return "id";
444 } else if ("ji".equals(langCode)) {
445 // Yiddish
446 return "yi";
447 }
448 return langCode;
449 }
450
451 private static void addLocaleToHttpAcceptLanguage(StringBuilder builder,
452 Locale locale) {
453 String language = convertObsoleteLanguageCodeToNew(locale.getLanguage());
454 if (language != null) {
455 builder.append(language);
456 String country = locale.getCountry();
457 if (country != null) {
458 builder.append("-");
459 builder.append(country);
460 }
461 }
462 }
463
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800464 /**
465 * Looks at sLocale and mContext and returns current UserAgent String.
466 * @return Current UserAgent String.
467 */
468 private synchronized String getCurrentUserAgent() {
469 Locale locale;
470 synchronized(sLockForLocaleSettings) {
471 locale = sLocale;
472 }
473 StringBuffer buffer = new StringBuffer();
474 // Add version
475 final String version = Build.VERSION.RELEASE;
476 if (version.length() > 0) {
John Reckf5577402011-04-28 10:27:40 -0700477 if (Character.isDigit(version.charAt(0))) {
478 // Release is a version, eg "3.1"
479 buffer.append(version);
480 } else {
481 // Release is a codename, eg "Honeycomb"
482 // In this case, use the previous release's version
483 buffer.append(PREVIOUS_VERSION);
484 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800485 } else {
486 // default to "1.0"
487 buffer.append("1.0");
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700488 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800489 buffer.append("; ");
490 final String language = locale.getLanguage();
491 if (language != null) {
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700492 buffer.append(convertObsoleteLanguageCodeToNew(language));
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800493 final String country = locale.getCountry();
494 if (country != null) {
495 buffer.append("-");
496 buffer.append(country.toLowerCase());
497 }
498 } else {
499 // default to "en"
500 buffer.append("en");
501 }
John Reck36fd7a32011-01-07 18:45:33 -0800502 buffer.append(";");
Grace Klobace761d32009-08-27 15:24:59 -0700503 // add the model for the release build
504 if ("REL".equals(Build.VERSION.CODENAME)) {
505 final String model = Build.MODEL;
506 if (model.length() > 0) {
John Reck36fd7a32011-01-07 18:45:33 -0800507 buffer.append(" ");
Grace Klobace761d32009-08-27 15:24:59 -0700508 buffer.append(model);
509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511 final String id = Build.ID;
512 if (id.length() > 0) {
513 buffer.append(" Build/");
514 buffer.append(id);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800515 }
Michael Kolb37b64de2010-07-01 12:05:47 -0700516 String mobile = mContext.getResources().getText(
517 com.android.internal.R.string.web_user_agent_target_content).toString();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800518 final String base = mContext.getResources().getText(
519 com.android.internal.R.string.web_user_agent).toString();
Michael Kolba172e7d2010-06-30 12:35:26 -0700520 return String.format(base, buffer, mobile);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800521 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700522
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800523 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700524 * Enables dumping the pages navigation cache to a text file.
Kristian Monsenfc771652011-05-10 16:44:05 +0100525 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700526 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100527 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700528 public void setNavDump(boolean enabled) {
529 mNavDump = enabled;
530 }
531
532 /**
533 * Returns true if dumping the navigation cache is enabled.
Kristian Monsenfc771652011-05-10 16:44:05 +0100534 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700535 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100536 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700537 public boolean getNavDump() {
538 return mNavDump;
539 }
540
541 /**
Grace Kloba178db412010-05-18 22:22:23 -0700542 * If WebView only supports touch, a different navigation model will be
543 * applied. Otherwise, the navigation to support both touch and keyboard
544 * will be used.
545 * @hide
546 public void setSupportTouchOnly(boolean touchOnly) {
547 mSupportTounchOnly = touchOnly;
548 }
549 */
550
551 boolean supportTouchOnly() {
552 // for debug only, use mLightTouchEnabled for mSupportTounchOnly
553 return mLightTouchEnabled;
554 }
555
556 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700557 * Set whether the WebView supports zoom
558 */
559 public void setSupportZoom(boolean support) {
560 mSupportZoom = support;
Grace Kloba3a0def22010-01-23 21:11:54 -0800561 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700562 }
563
564 /**
565 * Returns whether the WebView supports zoom
566 */
567 public boolean supportZoom() {
568 return mSupportZoom;
569 }
570
571 /**
The Android Open Source Project10592532009-03-18 17:39:46 -0700572 * Sets whether the zoom mechanism built into WebView is used.
573 */
574 public void setBuiltInZoomControls(boolean enabled) {
575 mBuiltInZoomControls = enabled;
Grace Kloba3a0def22010-01-23 21:11:54 -0800576 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project10592532009-03-18 17:39:46 -0700577 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700578
The Android Open Source Project10592532009-03-18 17:39:46 -0700579 /**
580 * Returns true if the zoom mechanism built into WebView is being used.
581 */
582 public boolean getBuiltInZoomControls() {
583 return mBuiltInZoomControls;
584 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700585
The Android Open Source Project10592532009-03-18 17:39:46 -0700586 /**
Michael Kolb6fe3b422010-08-19 12:41:24 -0700587 * Sets whether the on screen zoom buttons are used.
588 * A combination of built in zoom controls enabled
589 * and on screen zoom controls disabled allows for pinch to zoom
590 * to work without the on screen controls
Michael Kolb6fe3b422010-08-19 12:41:24 -0700591 */
592 public void setDisplayZoomControls(boolean enabled) {
593 mDisplayZoomControls = enabled;
594 mWebView.updateMultiTouchSupport(mContext);
595 }
596
597 /**
598 * Returns true if the on screen zoom buttons are being used.
Michael Kolb6fe3b422010-08-19 12:41:24 -0700599 */
600 public boolean getDisplayZoomControls() {
601 return mDisplayZoomControls;
602 }
603
604 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800605 * Enable or disable file access within WebView. File access is enabled by
Patrick Scottd1737ed2011-01-05 11:36:48 -0500606 * default. Note that this enables or disables file system access only.
607 * Assets and resources are still accessible using file:///android_asset and
608 * file:///android_res.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800609 */
610 public void setAllowFileAccess(boolean allow) {
611 mAllowFileAccess = allow;
612 }
613
614 /**
615 * Returns true if this WebView supports file access.
616 */
617 public boolean getAllowFileAccess() {
618 return mAllowFileAccess;
619 }
620
621 /**
Patrick Scottd1737ed2011-01-05 11:36:48 -0500622 * Enable or disable content url access within WebView. Content url access
623 * allows WebView to load content from a content provider installed in the
624 * system. The default is enabled.
625 */
626 public void setAllowContentAccess(boolean allow) {
627 mAllowContentAccess = allow;
628 }
629
630 /**
631 * Returns true if this WebView supports content url access.
632 */
633 public boolean getAllowContentAccess() {
634 return mAllowContentAccess;
635 }
636
637 /**
Grace Klobae397a882009-08-06 12:04:14 -0700638 * Set whether the WebView loads a page with overview mode.
Grace Klobae397a882009-08-06 12:04:14 -0700639 */
640 public void setLoadWithOverviewMode(boolean overview) {
641 mLoadWithOverviewMode = overview;
642 }
643
644 /**
645 * Returns true if this WebView loads page with overview mode
Grace Klobae397a882009-08-06 12:04:14 -0700646 */
647 public boolean getLoadWithOverviewMode() {
648 return mLoadWithOverviewMode;
649 }
650
651 /**
Grace Klobaf9b731d2010-06-21 19:23:57 -0700652 * Set whether the WebView will enable smooth transition while panning or
653 * zooming. If it is true, WebView will choose a solution to maximize the
654 * performance. e.g. the WebView's content may not be updated during the
655 * transition. If it is false, WebView will keep its fidelity. The default
656 * value is false.
657 */
658 public void setEnableSmoothTransition(boolean enable) {
659 mEnableSmoothTransition = enable;
660 }
661
662 /**
663 * Returns true if the WebView enables smooth transition while panning or
664 * zooming.
665 */
666 public boolean enableSmoothTransition() {
667 return mEnableSmoothTransition;
668 }
669
670 /**
Adam Powell637d3372010-08-25 14:37:03 -0700671 * Set whether the WebView uses its background for over scroll background.
672 * If true, it will use the WebView's background. If false, it will use an
673 * internal pattern. Default is true.
Kristian Monsenfc771652011-05-10 16:44:05 +0100674 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700675 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100676 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700677 public void setUseWebViewBackgroundForOverscrollBackground(boolean view) {
678 mUseWebViewBackgroundForOverscroll = view;
679 }
680
681 /**
682 * Returns true if this WebView uses WebView's background instead of
683 * internal pattern for over scroll background.
Kristian Monsenfc771652011-05-10 16:44:05 +0100684 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700685 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100686 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700687 public boolean getUseWebViewBackgroundForOverscrollBackground() {
688 return mUseWebViewBackgroundForOverscroll;
689 }
690
691 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700692 * Store whether the WebView is saving form data.
693 */
694 public void setSaveFormData(boolean save) {
695 mSaveFormData = save;
696 }
697
698 /**
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500699 * Return whether the WebView is saving form data and displaying prior
700 * entries/autofill++. Always false in private browsing mode.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700701 */
702 public boolean getSaveFormData() {
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500703 return mSaveFormData && !mPrivateBrowsingEnabled;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700704 }
705
706 /**
707 * Store whether the WebView is saving password.
708 */
709 public void setSavePassword(boolean save) {
710 mSavePassword = save;
711 }
712
713 /**
714 * Return whether the WebView is saving password.
715 */
716 public boolean getSavePassword() {
717 return mSavePassword;
718 }
719
720 /**
721 * Set the text size of the page.
722 * @param t A TextSize value for increasing or decreasing the text.
723 * @see WebSettings.TextSize
724 */
725 public synchronized void setTextSize(TextSize t) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 if (WebView.mLogEvent && mTextSize != t ) {
Dan Egnor18e93962010-02-10 19:27:58 -0800727 EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
728 mTextSize.value, t.value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700730 mTextSize = t;
731 postSync();
732 }
733
734 /**
735 * Get the text size of the page.
736 * @return A TextSize enum value describing the text size.
737 * @see WebSettings.TextSize
738 */
739 public synchronized TextSize getTextSize() {
740 return mTextSize;
741 }
742
743 /**
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700744 * Set the default zoom density of the page. This should be called from UI
745 * thread.
746 * @param zoom A ZoomDensity value
747 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700748 */
749 public void setDefaultZoom(ZoomDensity zoom) {
750 if (mDefaultZoom != zoom) {
751 mDefaultZoom = zoom;
752 mWebView.updateDefaultZoomDensity(zoom.value);
753 }
754 }
755
756 /**
757 * Get the default zoom density of the page. This should be called from UI
758 * thread.
759 * @return A ZoomDensity value
760 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700761 */
762 public ZoomDensity getDefaultZoom() {
763 return mDefaultZoom;
764 }
765
766 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700767 * Enables using light touches to make a selection and activate mouseovers.
768 */
769 public void setLightTouchEnabled(boolean enabled) {
770 mLightTouchEnabled = enabled;
771 }
772
773 /**
774 * Returns true if light touches are enabled.
775 */
776 public boolean getLightTouchEnabled() {
777 return mLightTouchEnabled;
778 }
779
780 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100781 * @deprecated This setting controlled a rendering optimization
782 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700783 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100784 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700785 public synchronized void setUseDoubleTree(boolean use) {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100786 return;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700787 }
788
789 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100790 * @deprecated This setting controlled a rendering optimization
791 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700792 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100793 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700794 public synchronized boolean getUseDoubleTree() {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100795 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700796 }
797
798 /**
799 * Tell the WebView about user-agent string.
800 * @param ua 0 if the WebView should use an Android user-agent string,
801 * 1 if the WebView should use a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800802 *
803 * @deprecated Please use setUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700804 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800805 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700806 public synchronized void setUserAgent(int ua) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800807 String uaString = null;
808 if (ua == 1) {
809 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
810 return; // do nothing
811 } else {
812 uaString = DESKTOP_USERAGENT;
813 }
814 } else if (ua == 2) {
815 if (IPHONE_USERAGENT.equals(mUserAgent)) {
816 return; // do nothing
817 } else {
818 uaString = IPHONE_USERAGENT;
819 }
820 } else if (ua != 0) {
821 return; // do nothing
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700822 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800823 setUserAgentString(uaString);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700824 }
825
826 /**
827 * Return user-agent as int
828 * @return int 0 if the WebView is using an Android user-agent string.
829 * 1 if the WebView is using a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800830 * -1 if the WebView is using user defined user-agent string.
831 *
832 * @deprecated Please use getUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700833 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800834 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700835 public synchronized int getUserAgent() {
836 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
837 return 1;
838 } else if (IPHONE_USERAGENT.equals(mUserAgent)) {
839 return 2;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800840 } else if (mUseDefaultUserAgent) {
841 return 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700842 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800843 return -1;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700844 }
845
846 /**
847 * Tell the WebView to use the wide viewport
848 */
849 public synchronized void setUseWideViewPort(boolean use) {
850 if (mUseWideViewport != use) {
851 mUseWideViewport = use;
852 postSync();
853 }
854 }
855
856 /**
857 * @return True if the WebView is using a wide viewport
858 */
859 public synchronized boolean getUseWideViewPort() {
860 return mUseWideViewport;
861 }
862
863 /**
864 * Tell the WebView whether it supports multiple windows. TRUE means
865 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
866 * boolean, Message)} is implemented by the host application.
867 */
868 public synchronized void setSupportMultipleWindows(boolean support) {
869 if (mSupportMultipleWindows != support) {
870 mSupportMultipleWindows = support;
871 postSync();
872 }
873 }
874
875 /**
876 * @return True if the WebView is supporting multiple windows. This means
877 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
878 * boolean, Message)} is implemented by the host application.
879 */
880 public synchronized boolean supportMultipleWindows() {
881 return mSupportMultipleWindows;
882 }
883
884 /**
885 * Set the underlying layout algorithm. This will cause a relayout of the
886 * WebView.
887 * @param l A LayoutAlgorithm enum specifying the algorithm to use.
888 * @see WebSettings.LayoutAlgorithm
Kristian Monsenfc771652011-05-10 16:44:05 +0100889 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700890 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100891 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700892 public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) {
893 // XXX: This will only be affective if libwebcore was built with
894 // ANDROID_LAYOUT defined.
895 if (mLayoutAlgorithm != l) {
896 mLayoutAlgorithm = l;
897 postSync();
898 }
899 }
900
901 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100902 * Return the current layout algorithm. The default is NARROW_COLUMNS.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700903 * @return LayoutAlgorithm enum value describing the layout algorithm
904 * being used.
905 * @see WebSettings.LayoutAlgorithm
Kristian Monsenfc771652011-05-10 16:44:05 +0100906 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700907 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100908 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700909 public synchronized LayoutAlgorithm getLayoutAlgorithm() {
910 return mLayoutAlgorithm;
911 }
912
913 /**
914 * Set the standard font family name.
915 * @param font A font family name.
916 */
917 public synchronized void setStandardFontFamily(String font) {
918 if (font != null && !font.equals(mStandardFontFamily)) {
919 mStandardFontFamily = font;
920 postSync();
921 }
922 }
923
924 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100925 * Get the standard font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700926 * @return The standard font family name as a string.
927 */
928 public synchronized String getStandardFontFamily() {
929 return mStandardFontFamily;
930 }
931
932 /**
933 * Set the fixed font family name.
934 * @param font A font family name.
935 */
936 public synchronized void setFixedFontFamily(String font) {
937 if (font != null && !font.equals(mFixedFontFamily)) {
938 mFixedFontFamily = font;
939 postSync();
940 }
941 }
942
943 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100944 * Get the fixed font family name. The default is "monospace".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700945 * @return The fixed font family name as a string.
946 */
947 public synchronized String getFixedFontFamily() {
948 return mFixedFontFamily;
949 }
950
951 /**
952 * Set the sans-serif font family name.
953 * @param font A font family name.
954 */
955 public synchronized void setSansSerifFontFamily(String font) {
956 if (font != null && !font.equals(mSansSerifFontFamily)) {
957 mSansSerifFontFamily = font;
958 postSync();
959 }
960 }
961
962 /**
963 * Get the sans-serif font family name.
964 * @return The sans-serif font family name as a string.
965 */
966 public synchronized String getSansSerifFontFamily() {
967 return mSansSerifFontFamily;
968 }
969
970 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100971 * Set the serif font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700972 * @param font A font family name.
973 */
974 public synchronized void setSerifFontFamily(String font) {
975 if (font != null && !font.equals(mSerifFontFamily)) {
976 mSerifFontFamily = font;
977 postSync();
978 }
979 }
980
981 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100982 * Get the serif font family name. The default is "serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700983 * @return The serif font family name as a string.
984 */
985 public synchronized String getSerifFontFamily() {
986 return mSerifFontFamily;
987 }
988
989 /**
990 * Set the cursive font family name.
991 * @param font A font family name.
992 */
993 public synchronized void setCursiveFontFamily(String font) {
994 if (font != null && !font.equals(mCursiveFontFamily)) {
995 mCursiveFontFamily = font;
996 postSync();
997 }
998 }
999
1000 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001001 * Get the cursive font family name. The default is "cursive".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001002 * @return The cursive font family name as a string.
1003 */
1004 public synchronized String getCursiveFontFamily() {
1005 return mCursiveFontFamily;
1006 }
1007
1008 /**
1009 * Set the fantasy font family name.
1010 * @param font A font family name.
1011 */
1012 public synchronized void setFantasyFontFamily(String font) {
1013 if (font != null && !font.equals(mFantasyFontFamily)) {
1014 mFantasyFontFamily = font;
1015 postSync();
1016 }
1017 }
1018
1019 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001020 * Get the fantasy font family name. The default is "fantasy".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001021 * @return The fantasy font family name as a string.
1022 */
1023 public synchronized String getFantasyFontFamily() {
1024 return mFantasyFontFamily;
1025 }
1026
1027 /**
1028 * Set the minimum font size.
1029 * @param size A non-negative integer between 1 and 72.
1030 * Any number outside the specified range will be pinned.
1031 */
1032 public synchronized void setMinimumFontSize(int size) {
1033 size = pin(size);
1034 if (mMinimumFontSize != size) {
1035 mMinimumFontSize = size;
1036 postSync();
1037 }
1038 }
1039
1040 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001041 * Get the minimum font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001042 * @return A non-negative integer between 1 and 72.
1043 */
1044 public synchronized int getMinimumFontSize() {
1045 return mMinimumFontSize;
1046 }
1047
1048 /**
1049 * Set the minimum logical font size.
1050 * @param size A non-negative integer between 1 and 72.
1051 * Any number outside the specified range will be pinned.
1052 */
1053 public synchronized void setMinimumLogicalFontSize(int size) {
1054 size = pin(size);
1055 if (mMinimumLogicalFontSize != size) {
1056 mMinimumLogicalFontSize = size;
1057 postSync();
1058 }
1059 }
1060
1061 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001062 * Get the minimum logical font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001063 * @return A non-negative integer between 1 and 72.
1064 */
1065 public synchronized int getMinimumLogicalFontSize() {
1066 return mMinimumLogicalFontSize;
1067 }
1068
1069 /**
1070 * Set the default font size.
1071 * @param size A non-negative integer between 1 and 72.
1072 * Any number outside the specified range will be pinned.
1073 */
1074 public synchronized void setDefaultFontSize(int size) {
1075 size = pin(size);
1076 if (mDefaultFontSize != size) {
1077 mDefaultFontSize = size;
1078 postSync();
1079 }
1080 }
1081
1082 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001083 * Get the default font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001084 * @return A non-negative integer between 1 and 72.
1085 */
1086 public synchronized int getDefaultFontSize() {
1087 return mDefaultFontSize;
1088 }
1089
1090 /**
1091 * Set the default fixed font size.
1092 * @param size A non-negative integer between 1 and 72.
1093 * Any number outside the specified range will be pinned.
1094 */
1095 public synchronized void setDefaultFixedFontSize(int size) {
1096 size = pin(size);
1097 if (mDefaultFixedFontSize != size) {
1098 mDefaultFixedFontSize = size;
1099 postSync();
1100 }
1101 }
1102
1103 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001104 * Get the default fixed font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001105 * @return A non-negative integer between 1 and 72.
1106 */
1107 public synchronized int getDefaultFixedFontSize() {
1108 return mDefaultFixedFontSize;
1109 }
1110
1111 /**
Grace Kloba097b1e772009-11-24 14:23:18 -08001112 * Set the number of pages cached by the WebKit for the history navigation.
1113 * @param size A non-negative integer between 0 (no cache) and 20 (max).
1114 * @hide
1115 */
1116 public synchronized void setPageCacheCapacity(int size) {
1117 if (size < 0) size = 0;
1118 if (size > 20) size = 20;
1119 if (mPageCacheCapacity != size) {
1120 mPageCacheCapacity = size;
1121 postSync();
1122 }
1123 }
1124
1125 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001126 * Tell the WebView to load image resources automatically.
1127 * @param flag True if the WebView should load images automatically.
1128 */
1129 public synchronized void setLoadsImagesAutomatically(boolean flag) {
1130 if (mLoadsImagesAutomatically != flag) {
1131 mLoadsImagesAutomatically = flag;
1132 postSync();
1133 }
1134 }
1135
1136 /**
1137 * Return true if the WebView will load image resources automatically.
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001138 * The default is true.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001139 * @return True if the WebView loads images automatically.
1140 */
1141 public synchronized boolean getLoadsImagesAutomatically() {
1142 return mLoadsImagesAutomatically;
1143 }
1144
1145 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001146 * Tell the WebView to block network images. This is only checked when
1147 * {@link #getLoadsImagesAutomatically} is true. If you set the value to
1148 * false, images will automatically be loaded. Use this api to reduce
1149 * bandwidth only. Use {@link #setBlockNetworkLoads} if possible.
1150 * @param flag True if the WebView should block network images.
1151 * @see #setBlockNetworkLoads
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001152 */
1153 public synchronized void setBlockNetworkImage(boolean flag) {
1154 if (mBlockNetworkImage != flag) {
1155 mBlockNetworkImage = flag;
1156 postSync();
1157 }
1158 }
1159
1160 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001161 * Return true if the WebView will block network images. The default is
1162 * false.
1163 * @return True if the WebView blocks network images.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001164 */
1165 public synchronized boolean getBlockNetworkImage() {
1166 return mBlockNetworkImage;
1167 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001168
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001169 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001170 * Tell the WebView to block all network load requests. If you set the
1171 * value to false, you must call {@link android.webkit.WebView#reload} to
1172 * fetch remote resources. This flag supercedes the value passed to
1173 * {@link #setBlockNetworkImage}.
1174 * @param flag True if the WebView should block all network loads.
1175 * @see android.webkit.WebView#reload
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001176 */
1177 public synchronized void setBlockNetworkLoads(boolean flag) {
1178 if (mBlockNetworkLoads != flag) {
1179 mBlockNetworkLoads = flag;
1180 verifyNetworkAccess();
Patrick Scott4243a3a2010-10-05 09:30:24 -04001181 postSync();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001182 }
1183 }
1184
1185 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001186 * Return true if the WebView will block all network loads. The default is
1187 * false.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001188 * @return True if the WebView blocks all network loads.
1189 */
1190 public synchronized boolean getBlockNetworkLoads() {
1191 return mBlockNetworkLoads;
1192 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001193
1194
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001195 private void verifyNetworkAccess() {
1196 if (!mBlockNetworkLoads) {
Michael Kolba172e7d2010-06-30 12:35:26 -07001197 if (mContext.checkPermission("android.permission.INTERNET",
1198 android.os.Process.myPid(), android.os.Process.myUid()) !=
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001199 PackageManager.PERMISSION_GRANTED) {
1200 throw new SecurityException
1201 ("Permission denied - " +
1202 "application missing INTERNET permission");
1203 }
1204 }
1205 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001206
1207 /**
1208 * Tell the WebView to enable javascript execution.
1209 * @param flag True if the WebView should execute javascript.
1210 */
1211 public synchronized void setJavaScriptEnabled(boolean flag) {
1212 if (mJavaScriptEnabled != flag) {
1213 mJavaScriptEnabled = flag;
1214 postSync();
1215 }
1216 }
1217
1218 /**
Teng-Hui Zhuda7378e2011-02-16 11:25:03 -08001219 * Tell the WebView to show the visual indicator
1220 * @param flag True if the WebView should show the visual indicator
1221 * @hide
1222 */
1223 public synchronized void setShowVisualIndicator(boolean flag) {
1224 if (mShowVisualIndicator != flag) {
1225 mShowVisualIndicator = flag;
1226 postSync();
1227 }
1228 }
1229
1230 /**
1231 * @return True if the WebView is showing the visual indicator
1232 * @hide
1233 */
1234 public synchronized boolean getShowVisualIndicator() {
1235 return mShowVisualIndicator;
1236 }
1237
1238 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001239 * Tell the WebView to enable plugins.
1240 * @param flag True if the WebView should load plugins.
Patrick Scott300f2e92010-03-22 10:20:45 -04001241 * @deprecated This method has been deprecated in favor of
1242 * {@link #setPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001243 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001244 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001245 public synchronized void setPluginsEnabled(boolean flag) {
Patrick Scott300f2e92010-03-22 10:20:45 -04001246 setPluginState(PluginState.ON);
1247 }
1248
1249 /**
1250 * Tell the WebView to enable, disable, or have plugins on demand. On
1251 * demand mode means that if a plugin exists that can handle the embedded
1252 * content, a placeholder icon will be shown instead of the plugin. When
1253 * the placeholder is clicked, the plugin will be enabled.
1254 * @param state One of the PluginState values.
1255 */
1256 public synchronized void setPluginState(PluginState state) {
1257 if (mPluginState != state) {
1258 mPluginState = state;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001259 postSync();
1260 }
1261 }
1262
1263 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001264 * Set a custom path to plugins used by the WebView. This method is
1265 * obsolete since each plugin is now loaded from its own package.
1266 * @param pluginsPath String path to the directory containing plugins.
1267 * @deprecated This method is no longer used as plugins are loaded from
1268 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001269 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001270 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001271 public synchronized void setPluginsPath(String pluginsPath) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001272 }
1273
1274 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001275 * Set the path to where database storage API databases should be saved.
Ben Murdoch18773af2010-02-25 18:41:56 +00001276 * Nota that the WebCore Database Tracker only allows the path to be set once.
Ben Murdoch7df19852009-04-22 13:07:58 +01001277 * This will update WebCore when the Sync runs in the C++ side.
1278 * @param databasePath String path to the directory where databases should
1279 * be saved. May be the empty string but should never be null.
1280 */
1281 public synchronized void setDatabasePath(String databasePath) {
Ben Murdoch18773af2010-02-25 18:41:56 +00001282 if (databasePath != null && !mDatabasePathHasBeenSet) {
Ben Murdoch7df19852009-04-22 13:07:58 +01001283 mDatabasePath = databasePath;
Ben Murdoch18773af2010-02-25 18:41:56 +00001284 mDatabasePathHasBeenSet = true;
Ben Murdoch7df19852009-04-22 13:07:58 +01001285 postSync();
1286 }
1287 }
1288
1289 /**
Steve Block9d3273f2009-08-21 13:16:27 +01001290 * Set the path where the Geolocation permissions database should be saved.
1291 * This will update WebCore when the Sync runs in the C++ side.
1292 * @param databasePath String path to the directory where the Geolocation
1293 * permissions database should be saved. May be the empty string but
1294 * should never be null.
Steve Block9d3273f2009-08-21 13:16:27 +01001295 */
1296 public synchronized void setGeolocationDatabasePath(String databasePath) {
Grace Kloba8f5e4052009-10-06 12:56:07 -07001297 if (databasePath != null
1298 && !databasePath.equals(mGeolocationDatabasePath)) {
Steve Block9d3273f2009-08-21 13:16:27 +01001299 mGeolocationDatabasePath = databasePath;
1300 postSync();
1301 }
1302 }
1303
1304 /**
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001305 * Tell the WebView to enable Application Caches API.
1306 * @param flag True if the WebView should enable Application Caches.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001307 */
1308 public synchronized void setAppCacheEnabled(boolean flag) {
1309 if (mAppCacheEnabled != flag) {
1310 mAppCacheEnabled = flag;
1311 postSync();
1312 }
1313 }
1314
1315 /**
1316 * Set a custom path to the Application Caches files. The client
1317 * must ensure it exists before this call.
1318 * @param appCachePath String path to the directory containing Application
1319 * Caches files. The appCache path can be the empty string but should not
1320 * be null. Passing null for this parameter will result in a no-op.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001321 */
1322 public synchronized void setAppCachePath(String appCachePath) {
1323 if (appCachePath != null && !appCachePath.equals(mAppCachePath)) {
1324 mAppCachePath = appCachePath;
1325 postSync();
1326 }
1327 }
1328
1329 /**
Andrei Popescu1c829202009-07-22 16:47:52 +01001330 * Set the maximum size for the Application Caches content.
1331 * @param appCacheMaxSize the maximum size in bytes.
Andrei Popescu1c829202009-07-22 16:47:52 +01001332 */
1333 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) {
1334 if (appCacheMaxSize != mAppCacheMaxSize) {
1335 mAppCacheMaxSize = appCacheMaxSize;
1336 postSync();
1337 }
1338 }
1339
1340 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001341 * Set whether the database storage API is enabled.
1342 * @param flag boolean True if the WebView should use the database storage
1343 * API.
1344 */
1345 public synchronized void setDatabaseEnabled(boolean flag) {
1346 if (mDatabaseEnabled != flag) {
1347 mDatabaseEnabled = flag;
1348 postSync();
1349 }
1350 }
1351
1352 /**
Ben Murdoch274680d2009-05-28 13:44:44 +01001353 * Set whether the DOM storage API is enabled.
1354 * @param flag boolean True if the WebView should use the DOM storage
1355 * API.
Ben Murdoch274680d2009-05-28 13:44:44 +01001356 */
1357 public synchronized void setDomStorageEnabled(boolean flag) {
1358 if (mDomStorageEnabled != flag) {
1359 mDomStorageEnabled = flag;
1360 postSync();
1361 }
1362 }
1363
1364 /**
1365 * Returns true if the DOM Storage API's are enabled.
1366 * @return True if the DOM Storage API's are enabled.
Ben Murdoch274680d2009-05-28 13:44:44 +01001367 */
1368 public synchronized boolean getDomStorageEnabled() {
1369 return mDomStorageEnabled;
1370 }
1371
1372 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001373 * Return the path to where database storage API databases are saved for
1374 * the current WebView.
1375 * @return the String path to the database storage API databases.
1376 */
1377 public synchronized String getDatabasePath() {
1378 return mDatabasePath;
1379 }
1380
1381 /**
1382 * Returns true if database storage API is enabled.
1383 * @return True if the database storage API is enabled.
1384 */
1385 public synchronized boolean getDatabaseEnabled() {
1386 return mDatabaseEnabled;
1387 }
1388
1389 /**
Andrei Popescuc27a9ac2009-08-03 15:59:24 +01001390 * Tell the WebView to enable WebWorkers API.
1391 * @param flag True if the WebView should enable WebWorkers.
1392 * Note that this flag only affects V8. JSC does not have
1393 * an equivalent setting.
1394 * @hide pending api council approval
1395 */
1396 public synchronized void setWorkersEnabled(boolean flag) {
1397 if (mWorkersEnabled != flag) {
1398 mWorkersEnabled = flag;
1399 postSync();
1400 }
1401 }
1402
1403 /**
Steve Block06cd7512009-08-21 10:26:37 +01001404 * Sets whether Geolocation is enabled.
1405 * @param flag Whether Geolocation should be enabled.
Steve Block06cd7512009-08-21 10:26:37 +01001406 */
1407 public synchronized void setGeolocationEnabled(boolean flag) {
1408 if (mGeolocationEnabled != flag) {
1409 mGeolocationEnabled = flag;
1410 postSync();
1411 }
1412 }
1413
1414 /**
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001415 * Sets whether XSS Auditor is enabled.
1416 * @param flag Whether XSS Auditor should be enabled.
Elliott Slaughterbe1304f2010-06-23 11:29:02 -07001417 * @hide Only used by LayoutTestController.
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001418 */
1419 public synchronized void setXSSAuditorEnabled(boolean flag) {
1420 if (mXSSAuditorEnabled != flag) {
1421 mXSSAuditorEnabled = flag;
1422 postSync();
1423 }
1424 }
1425
1426 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001427 * Return true if javascript is enabled. <b>Note: The default is false.</b>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001428 * @return True if javascript is enabled.
1429 */
1430 public synchronized boolean getJavaScriptEnabled() {
1431 return mJavaScriptEnabled;
1432 }
1433
1434 /**
1435 * Return true if plugins are enabled.
1436 * @return True if plugins are enabled.
Patrick Scott300f2e92010-03-22 10:20:45 -04001437 * @deprecated This method has been replaced by {@link #getPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001438 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001439 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001440 public synchronized boolean getPluginsEnabled() {
Patrick Scott300f2e92010-03-22 10:20:45 -04001441 return mPluginState == PluginState.ON;
1442 }
1443
1444 /**
1445 * Return the current plugin state.
1446 * @return A value corresponding to the enum PluginState.
1447 */
1448 public synchronized PluginState getPluginState() {
1449 return mPluginState;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001450 }
1451
1452 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001453 * Returns the directory that contains the plugin libraries. This method is
1454 * obsolete since each plugin is now loaded from its own package.
1455 * @return An empty string.
1456 * @deprecated This method is no longer used as plugins are loaded from
1457 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001458 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001459 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001460 public synchronized String getPluginsPath() {
Grace Kloba658ab7d2009-05-14 14:45:26 -07001461 return "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001462 }
1463
1464 /**
1465 * Tell javascript to open windows automatically. This applies to the
1466 * javascript function window.open().
1467 * @param flag True if javascript can open windows automatically.
1468 */
1469 public synchronized void setJavaScriptCanOpenWindowsAutomatically(
1470 boolean flag) {
1471 if (mJavaScriptCanOpenWindowsAutomatically != flag) {
1472 mJavaScriptCanOpenWindowsAutomatically = flag;
1473 postSync();
1474 }
1475 }
1476
1477 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001478 * Return true if javascript can open windows automatically. The default
1479 * is false.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001480 * @return True if javascript can open windows automatically during
1481 * window.open().
1482 */
1483 public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() {
1484 return mJavaScriptCanOpenWindowsAutomatically;
1485 }
1486
1487 /**
1488 * Set the default text encoding name to use when decoding html pages.
1489 * @param encoding The text encoding name.
1490 */
1491 public synchronized void setDefaultTextEncodingName(String encoding) {
1492 if (encoding != null && !encoding.equals(mDefaultTextEncoding)) {
1493 mDefaultTextEncoding = encoding;
1494 postSync();
1495 }
1496 }
1497
1498 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001499 * Get the default text encoding name. The default is "Latin-1".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001500 * @return The default text encoding name as a string.
1501 */
1502 public synchronized String getDefaultTextEncodingName() {
1503 return mDefaultTextEncoding;
1504 }
1505
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001506 /**
1507 * Set the WebView's user-agent string. If the string "ua" is null or empty,
1508 * it will use the system default user-agent string.
1509 */
1510 public synchronized void setUserAgentString(String ua) {
1511 if (ua == null || ua.length() == 0) {
1512 synchronized(sLockForLocaleSettings) {
Michael Kolba172e7d2010-06-30 12:35:26 -07001513 Locale currentLocale = Locale.getDefault();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001514 if (!sLocale.equals(currentLocale)) {
1515 sLocale = currentLocale;
1516 mAcceptLanguage = getCurrentAcceptLanguage();
1517 }
1518 }
1519 ua = getCurrentUserAgent();
1520 mUseDefaultUserAgent = true;
1521 } else {
1522 mUseDefaultUserAgent = false;
1523 }
1524
1525 if (!ua.equals(mUserAgent)) {
1526 mUserAgent = ua;
1527 postSync();
1528 }
1529 }
1530
1531 /**
1532 * Return the WebView's user-agent string.
1533 */
1534 public synchronized String getUserAgentString() {
1535 if (DESKTOP_USERAGENT.equals(mUserAgent) ||
1536 IPHONE_USERAGENT.equals(mUserAgent) ||
1537 !mUseDefaultUserAgent) {
1538 return mUserAgent;
1539 }
1540
1541 boolean doPostSync = false;
1542 synchronized(sLockForLocaleSettings) {
1543 Locale currentLocale = Locale.getDefault();
1544 if (!sLocale.equals(currentLocale)) {
1545 sLocale = currentLocale;
1546 mUserAgent = getCurrentUserAgent();
1547 mAcceptLanguage = getCurrentAcceptLanguage();
1548 doPostSync = true;
1549 }
1550 }
1551 if (doPostSync) {
1552 postSync();
1553 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001554 return mUserAgent;
1555 }
1556
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001557 /* package api to grab the Accept Language string. */
1558 /*package*/ synchronized String getAcceptLanguage() {
1559 synchronized(sLockForLocaleSettings) {
1560 Locale currentLocale = Locale.getDefault();
1561 if (!sLocale.equals(currentLocale)) {
1562 sLocale = currentLocale;
1563 mAcceptLanguage = getCurrentAcceptLanguage();
1564 }
1565 }
1566 return mAcceptLanguage;
1567 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001568
Shimeng (Simon) Wangc55886a2010-10-28 13:46:02 -07001569 /* package */ boolean isNarrowColumnLayout() {
1570 return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS;
1571 }
1572
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001573 /**
1574 * Tell the WebView whether it needs to set a node to have focus when
1575 * {@link WebView#requestFocus(int, android.graphics.Rect)} is called.
Michael Kolba172e7d2010-06-30 12:35:26 -07001576 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001577 * @param flag
1578 */
1579 public void setNeedInitialFocus(boolean flag) {
1580 if (mNeedInitialFocus != flag) {
1581 mNeedInitialFocus = flag;
1582 }
1583 }
1584
1585 /* Package api to get the choice whether it needs to set initial focus. */
1586 /* package */ boolean getNeedInitialFocus() {
1587 return mNeedInitialFocus;
1588 }
1589
1590 /**
1591 * Set the priority of the Render thread. Unlike the other settings, this
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001592 * one only needs to be called once per process. The default is NORMAL.
1593 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001594 * @param priority RenderPriority, can be normal, high or low.
1595 */
1596 public synchronized void setRenderPriority(RenderPriority priority) {
1597 if (mRenderPriority != priority) {
1598 mRenderPriority = priority;
1599 mEventHandler.sendMessage(Message.obtain(null,
1600 EventHandler.PRIORITY));
1601 }
1602 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001603
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001604 /**
1605 * Override the way the cache is used. The way the cache is used is based
1606 * on the navigation option. For a normal page load, the cache is checked
1607 * and content is re-validated as needed. When navigating back, content is
1608 * not revalidated, instead the content is just pulled from the cache.
1609 * This function allows the client to override this behavior.
1610 * @param mode One of the LOAD_ values.
1611 */
1612 public void setCacheMode(int mode) {
1613 if (mode != mOverrideCacheMode) {
1614 mOverrideCacheMode = mode;
Kristian Monsenc40fc872011-01-19 15:44:04 +00001615 postSync();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001616 }
1617 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001618
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001619 /**
1620 * Return the current setting for overriding the cache mode. For a full
1621 * description, see the {@link #setCacheMode(int)} function.
1622 */
1623 public int getCacheMode() {
1624 return mOverrideCacheMode;
1625 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001626
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001627 /**
1628 * If set, webkit alternately shrinks and expands images viewed outside
1629 * of an HTML page to fit the screen. This conflicts with attempts by
1630 * the UI to zoom in and out of an image, so it is set false by default.
1631 * @param shrink Set true to let webkit shrink the standalone image to fit.
1632 * {@hide}
1633 */
1634 public void setShrinksStandaloneImagesToFit(boolean shrink) {
1635 if (mShrinksStandaloneImagesToFit != shrink) {
1636 mShrinksStandaloneImagesToFit = shrink;
1637 postSync();
1638 }
1639 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001640
Cary Clarkf0785a62010-06-25 11:45:40 -04001641 /**
1642 * Specify the maximum decoded image size. The default is
1643 * 2 megs for small memory devices and 8 megs for large memory devices.
1644 * @param size The maximum decoded size, or zero to set to the default.
1645 * @hide pending api council approval
1646 */
1647 public void setMaximumDecodedImageSize(long size) {
1648 if (mMaximumDecodedImageSize != size) {
1649 mMaximumDecodedImageSize = size;
1650 postSync();
1651 }
1652 }
1653
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001654 /**
Shimeng (Simon) Wang2c782e32011-01-04 13:32:06 -08001655 * Returns whether to use fixed viewport. Fixed viewport should operate only
1656 * when wide viewport is on.
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001657 */
1658 /* package */ boolean getUseFixedViewport() {
Shimeng (Simon) Wang2c782e32011-01-04 13:32:06 -08001659 return getUseWideViewPort() && mUseFixedViewport;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001660 }
1661
1662 /**
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001663 * Returns whether private browsing is enabled.
1664 */
1665 /* package */ boolean isPrivateBrowsingEnabled() {
1666 return mPrivateBrowsingEnabled;
1667 }
1668
1669 /**
1670 * Sets whether private browsing is enabled.
1671 * @param flag Whether private browsing should be enabled.
1672 */
1673 /* package */ synchronized void setPrivateBrowsingEnabled(boolean flag) {
1674 if (mPrivateBrowsingEnabled != flag) {
1675 mPrivateBrowsingEnabled = flag;
Ben Murdoch4bd87d62011-01-18 14:10:48 +00001676
1677 // AutoFill is dependant on private browsing being enabled so
1678 // reset it to take account of the new value of mPrivateBrowsingEnabled.
1679 setAutoFillEnabled(mAutoFillEnabled);
1680
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001681 postSync();
1682 }
1683 }
1684
John Reck7818aaa2011-04-26 16:57:46 -07001685 /**
1686 * Returns whether the viewport metatag can disable zooming
1687 * @hide
1688 */
1689 public boolean forceUserScalable() {
1690 return mForceUserScalable;
1691 }
1692
1693 /**
1694 * Sets whether viewport metatag can disable zooming.
1695 * @param flag Whether or not to forceably enable user scalable.
1696 * @hide
1697 */
1698 public synchronized void setForceUserScalable(boolean flag) {
1699 mForceUserScalable = flag;
1700 }
1701
Cary Clark6c43d522010-08-31 15:41:54 -04001702 synchronized void setSyntheticLinksEnabled(boolean flag) {
1703 if (mSyntheticLinksEnabled != flag) {
1704 mSyntheticLinksEnabled = flag;
1705 postSync();
1706 }
1707 }
1708
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001709 /**
1710 * @hide
1711 */
1712 public synchronized void setAutoFillEnabled(boolean enabled) {
Ben Murdoch4bd87d62011-01-18 14:10:48 +00001713 // AutoFill is always disabled in private browsing mode.
1714 boolean autoFillEnabled = enabled && !mPrivateBrowsingEnabled;
1715 if (mAutoFillEnabled != autoFillEnabled) {
1716 mAutoFillEnabled = autoFillEnabled;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001717 postSync();
1718 }
1719 }
1720
1721 /**
1722 * @hide
1723 */
1724 public synchronized boolean getAutoFillEnabled() {
1725 return mAutoFillEnabled;
1726 }
1727
1728 /**
1729 * @hide
1730 */
1731 public synchronized void setAutoFillProfile(AutoFillProfile profile) {
Ben Murdochb1b82a82010-10-20 14:18:25 +01001732 if (mAutoFillProfile != profile) {
1733 mAutoFillProfile = profile;
1734 postSync();
1735 }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001736 }
1737
Ben Murdoch57914382010-11-16 11:50:39 +00001738 /**
1739 * @hide
1740 */
1741 public synchronized AutoFillProfile getAutoFillProfile() {
1742 return mAutoFillProfile;
1743 }
1744
Grace Klobaf8d8b462009-09-20 15:57:49 -07001745 int getDoubleTapToastCount() {
1746 return mDoubleTapToastCount;
1747 }
1748
1749 void setDoubleTapToastCount(int count) {
1750 if (mDoubleTapToastCount != count) {
1751 mDoubleTapToastCount = count;
1752 // write the settings in the non-UI thread
1753 mEventHandler.sendMessage(Message.obtain(null,
1754 EventHandler.SET_DOUBLE_TAP_TOAST_COUNT));
1755 }
1756 }
1757
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001758 /**
1759 * Transfer messages from the queue to the new WebCoreThread. Called from
1760 * WebCore thread.
1761 */
1762 /*package*/
1763 synchronized void syncSettingsAndCreateHandler(BrowserFrame frame) {
1764 mBrowserFrame = frame;
Derek Sollenberger2e5c1502009-06-03 10:44:42 -04001765 if (DebugFlags.WEB_SETTINGS) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001766 junit.framework.Assert.assertTrue(frame.mNativeFrame != 0);
1767 }
Andrei Popescudee76be2009-09-22 18:28:21 +01001768
Grace Klobaf8d8b462009-09-20 15:57:49 -07001769 SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
1770 Context.MODE_PRIVATE);
Grace Kloba24a3ff92009-09-22 10:42:22 -07001771 if (mDoubleTapToastCount > 0) {
1772 mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
1773 mDoubleTapToastCount);
1774 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001775 nativeSync(frame.mNativeFrame);
1776 mSyncPending = false;
1777 mEventHandler.createHandler();
1778 }
1779
Andrei Popescudee76be2009-09-22 18:28:21 +01001780 /**
1781 * Let the Settings object know that our owner is being destroyed.
1782 */
1783 /*package*/
1784 synchronized void onDestroyed() {
Andrei Popescudee76be2009-09-22 18:28:21 +01001785 }
1786
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001787 private int pin(int size) {
1788 // FIXME: 72 is just an arbitrary max text size value.
1789 if (size < 1) {
1790 return 1;
1791 } else if (size > 72) {
1792 return 72;
1793 }
1794 return size;
1795 }
1796
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001797 /* Post a SYNC message to handle syncing the native settings. */
1798 private synchronized void postSync() {
1799 // Only post if a sync is not pending
1800 if (!mSyncPending) {
1801 mSyncPending = mEventHandler.sendMessage(
1802 Message.obtain(null, EventHandler.SYNC));
1803 }
1804 }
1805
1806 // Synchronize the native and java settings.
1807 private native void nativeSync(int nativeFrame);
1808}