blob: 2b507fd5392ab89b8eac86f3773add32a0c0bc6c [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;
Shimeng (Simon) Wanga2ded6c2010-09-17 12:59:01 -070022import android.content.res.Resources;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070023import android.os.Build;
24import android.os.Handler;
25import android.os.Message;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -070026import android.util.DisplayMetrics;
Dan Egnor18e93962010-02-10 19:27:58 -080027import android.util.EventLog;
Michael Kolb37b64de2010-07-01 12:05:47 -070028
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070029import 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 */
39public 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 Monsen9f5f7af2011-02-24 11:14:11 +000046 * @deprecated This enum is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070047 */
48 // XXX: These must match LayoutAlgorithm in Settings.h in WebCore.
Kristian Monsen9f5f7af2011-02-24 11:14:11 +000049 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070050 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 Kloba0d8b77c2009-06-25 11:20:51 -070075
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 Kloba0d8b77c2009-06-25 11:20:51 -070081 */
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 Project54b6cfa2008-10-21 07:00:00 -070092 /**
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 Kolba172e7d2010-06-30 12:35:26 -0700114
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700115 /**
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 Scott300f2e92010-03-22 10:20:45 -0400127 /**
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 Kloba0d8b77c2009-06-25 11:20:51 -0700142 // WebView associated with this WebSettings.
143 private WebView mWebView;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700144 // 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 Hearnadcd2ed2009-01-21 16:44:36 +0100150
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700151 // 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 Hearnadcd2ed2009-01-21 16:44:36 +0100153 //
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 Project54b6cfa2008-10-21 07:00:00 -0700157 private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800158 private Context mContext;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700159 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 Miyakawac27d9b52009-05-25 16:57:15 +0900166 private String mDefaultTextEncoding;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800167 private String mUserAgent;
168 private boolean mUseDefaultUserAgent;
169 private String mAcceptLanguage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700170 private int mMinimumFontSize = 8;
171 private int mMinimumLogicalFontSize = 8;
172 private int mDefaultFontSize = 16;
173 private int mDefaultFixedFontSize = 13;
Grace Kloba097b1e772009-11-24 14:23:18 -0800174 private int mPageCacheCapacity = 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700175 private boolean mLoadsImagesAutomatically = true;
176 private boolean mBlockNetworkImage = false;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700177 private boolean mBlockNetworkLoads;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700178 private boolean mJavaScriptEnabled = false;
Teng-Hui Zhuda7378e2011-02-16 11:25:03 -0800179 private boolean mShowVisualIndicator = false;
Patrick Scott300f2e92010-03-22 10:20:45 -0400180 private PluginState mPluginState = PluginState.OFF;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700181 private boolean mJavaScriptCanOpenWindowsAutomatically = false;
182 private boolean mUseDoubleTree = false;
183 private boolean mUseWideViewport = false;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -0700184 private boolean mUseFixedViewport = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700185 private boolean mSupportMultipleWindows = false;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800186 private boolean mShrinksStandaloneImagesToFit = false;
Cary Clarkf0785a62010-06-25 11:45:40 -0400187 private long mMaximumDecodedImageSize = 0; // 0 means default
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700188 private boolean mPrivateBrowsingEnabled = false;
Cary Clark6c43d522010-08-31 15:41:54 -0400189 private boolean mSyntheticLinksEnabled = true;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100190 // 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 Block09b0ca12009-08-26 18:16:58 +0100195 private boolean mGeolocationEnabled = true;
Elliott Slaughter5dc0c822010-06-22 11:31:54 -0700196 private boolean mXSSAuditorEnabled = false;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100197 // HTML5 configuration parameters
198 private long mAppCacheMaxSize = Long.MAX_VALUE;
199 private String mAppCachePath = "";
200 private String mDatabasePath = "";
Ben Murdoch18773af2010-02-25 18:41:56 +0000201 // 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 Block9d3273f2009-08-21 13:16:27 +0100204 private String mGeolocationDatabasePath = "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700205 // 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 Kloba0d8b77c2009-06-25 11:20:51 -0700208 private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700209 private RenderPriority mRenderPriority = RenderPriority.NORMAL;
210 private int mOverrideCacheMode = LOAD_DEFAULT;
211 private boolean mSaveFormData = true;
Ben Murdochf39b2cf2010-09-09 10:26:46 +0100212 private boolean mAutoFillEnabled = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700213 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 Project10592532009-03-18 17:39:46 -0700218 private boolean mBuiltInZoomControls = false;
Michael Kolb6fe3b422010-08-19 12:41:24 -0700219 private boolean mDisplayZoomControls = true;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800220 private boolean mAllowFileAccess = true;
Patrick Scottd1737ed2011-01-05 11:36:48 -0500221 private boolean mAllowContentAccess = true;
Cary Clarkf8d49642009-09-08 13:23:24 -0400222 private boolean mLoadWithOverviewMode = false;
Grace Klobaf9b731d2010-06-21 19:23:57 -0700223 private boolean mEnableSmoothTransition = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700224
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100225 // AutoFill Profile data
226 /**
227 * @hide for now, pending API council approval.
228 */
229 public static class AutoFillProfile {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100230 private int mUniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100231 private String mFullName;
232 private String mEmailAddress;
Ben Murdochcf308722010-10-13 17:38:46 +0100233 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 Murdoche9e3ccd2010-10-06 14:33:02 +0100241
Ben Murdochb1b82a82010-10-20 14:18:25 +0100242 public AutoFillProfile(int uniqueId, String fullName, String email,
Ben Murdochcf308722010-10-13 17:38:46 +0100243 String companyName, String addressLine1, String addressLine2,
244 String city, String state, String zipCode, String country,
245 String phoneNumber) {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100246 mUniqueId = uniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100247 mFullName = fullName;
248 mEmailAddress = email;
Ben Murdochcf308722010-10-13 17:38:46 +0100249 mCompanyName = companyName;
250 mAddressLine1 = addressLine1;
251 mAddressLine2 = addressLine2;
252 mCity = city;
253 mState = state;
254 mZipCode = zipCode;
255 mCountry = country;
256 mPhoneNumber = phoneNumber;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100257 }
258
Ben Murdochb1b82a82010-10-20 14:18:25 +0100259 public int getUniqueId() { return mUniqueId; }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100260 public String getFullName() { return mFullName; }
261 public String getEmailAddress() { return mEmailAddress; }
Ben Murdochcf308722010-10-13 17:38:46 +0100262 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 Murdoche9e3ccd2010-10-06 14:33:02 +0100270 }
271
272
273 private AutoFillProfile mAutoFillProfile;
274
Adam Powell637d3372010-08-25 14:37:03 -0700275 private boolean mUseWebViewBackgroundForOverscroll = true;
276
Grace Klobaf8d8b462009-09-20 15:57:49 -0700277 // private WebSettings, not accessible by the host activity
Grace Kloba24a3ff92009-09-22 10:42:22 -0700278 static private int mDoubleTapToastCount = 3;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700279
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 Project54b6cfa2008-10-21 07:00:00 -0700283 // 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 Klobaf8d8b462009-09-20 15:57:49 -0700289 // Message id for writing double-tap toast count
290 static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700291 // 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 Klobaf8d8b462009-09-20 15:57:49 -0700316
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 Project54b6cfa2008-10-21 07:00:00 -0700326 }
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 Klobab4f33442009-06-25 23:38:40 -0700362 "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) Wang0e4cb9d2010-04-14 18:11:05 -0700365 private static final String IPHONE_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700366 "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 Projectf013e1a2008-12-17 18:05:43 -0800369 private static Locale sLocale;
370 private static Object sLockForLocaleSettings;
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700371
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700372 /**
373 * Package constructor to prevent clients from creating a new settings
374 * instance.
375 */
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700376 WebSettings(Context context, WebView webview) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700377 mEventHandler = new EventHandler();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800378 mContext = context;
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700379 mWebView = webview;
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900380 mDefaultTextEncoding = context.getString(com.android.internal.
381 R.string.default_text_encoding);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800382
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -0700383 // Detect tablet device for fixed viewport mode.
384 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Shimeng (Simon) Wang14bcc0e2010-09-17 10:12:05 -0700385 final int landscapeWidth = Math.max(metrics.widthPixels, metrics.heightPixels);
Shimeng (Simon) Wanga2ded6c2010-09-17 12:59:01 -0700386 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) Wangc1cba782010-08-17 10:53:59 -0700389
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800390 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 Projectc39a6e02009-03-11 12:11:56 -0700398 mBlockNetworkLoads = mContext.checkPermission(
399 "android.permission.INTERNET", android.os.Process.myPid(),
400 android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700401 }
402
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700403 private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US";
404
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700405 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800406 * 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) Wang0e4cb9d2010-04-14 18:11:05 -0700414 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 Projectf013e1a2008-12-17 18:05:43 -0800420 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700421 buffer.append(ACCEPT_LANG_FOR_US_LOCALE);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800422 }
423
424 return buffer.toString();
425 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700426
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 Projectf013e1a2008-12-17 18:05:43 -0800461 /**
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) Wang0e4cb9d2010-04-14 18:11:05 -0700478 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800479 buffer.append("; ");
480 final String language = locale.getLanguage();
481 if (language != null) {
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700482 buffer.append(convertObsoleteLanguageCodeToNew(language));
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800483 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 Reck36fd7a32011-01-07 18:45:33 -0800492 buffer.append(";");
Grace Klobace761d32009-08-27 15:24:59 -0700493 // 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 Reck36fd7a32011-01-07 18:45:33 -0800497 buffer.append(" ");
Grace Klobace761d32009-08-27 15:24:59 -0700498 buffer.append(model);
499 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
501 final String id = Build.ID;
502 if (id.length() > 0) {
503 buffer.append(" Build/");
504 buffer.append(id);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800505 }
Michael Kolb37b64de2010-07-01 12:05:47 -0700506 String mobile = mContext.getResources().getText(
507 com.android.internal.R.string.web_user_agent_target_content).toString();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800508 final String base = mContext.getResources().getText(
509 com.android.internal.R.string.web_user_agent).toString();
Michael Kolba172e7d2010-06-30 12:35:26 -0700510 return String.format(base, buffer, mobile);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800511 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700512
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800513 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700514 * Enables dumping the pages navigation cache to a text file.
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000515 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700516 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000517 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700518 public void setNavDump(boolean enabled) {
519 mNavDump = enabled;
520 }
521
522 /**
523 * Returns true if dumping the navigation cache is enabled.
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000524 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700525 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000526 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700527 public boolean getNavDump() {
528 return mNavDump;
529 }
530
531 /**
Grace Kloba178db412010-05-18 22:22:23 -0700532 * 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 Project54b6cfa2008-10-21 07:00:00 -0700547 * Set whether the WebView supports zoom
548 */
549 public void setSupportZoom(boolean support) {
550 mSupportZoom = support;
Grace Kloba3a0def22010-01-23 21:11:54 -0800551 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700552 }
553
554 /**
555 * Returns whether the WebView supports zoom
556 */
557 public boolean supportZoom() {
558 return mSupportZoom;
559 }
560
561 /**
The Android Open Source Project10592532009-03-18 17:39:46 -0700562 * Sets whether the zoom mechanism built into WebView is used.
563 */
564 public void setBuiltInZoomControls(boolean enabled) {
565 mBuiltInZoomControls = enabled;
Grace Kloba3a0def22010-01-23 21:11:54 -0800566 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project10592532009-03-18 17:39:46 -0700567 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700568
The Android Open Source Project10592532009-03-18 17:39:46 -0700569 /**
570 * Returns true if the zoom mechanism built into WebView is being used.
571 */
572 public boolean getBuiltInZoomControls() {
573 return mBuiltInZoomControls;
574 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700575
The Android Open Source Project10592532009-03-18 17:39:46 -0700576 /**
Michael Kolb6fe3b422010-08-19 12:41:24 -0700577 * 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 Kolb6fe3b422010-08-19 12:41:24 -0700581 */
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 Kolb6fe3b422010-08-19 12:41:24 -0700589 */
590 public boolean getDisplayZoomControls() {
591 return mDisplayZoomControls;
592 }
593
594 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800595 * Enable or disable file access within WebView. File access is enabled by
Patrick Scottd1737ed2011-01-05 11:36:48 -0500596 * 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 Projectf013e1a2008-12-17 18:05:43 -0800599 */
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 Scottd1737ed2011-01-05 11:36:48 -0500612 * 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 Klobae397a882009-08-06 12:04:14 -0700628 * Set whether the WebView loads a page with overview mode.
Grace Klobae397a882009-08-06 12:04:14 -0700629 */
630 public void setLoadWithOverviewMode(boolean overview) {
631 mLoadWithOverviewMode = overview;
632 }
633
634 /**
635 * Returns true if this WebView loads page with overview mode
Grace Klobae397a882009-08-06 12:04:14 -0700636 */
637 public boolean getLoadWithOverviewMode() {
638 return mLoadWithOverviewMode;
639 }
640
641 /**
Grace Klobaf9b731d2010-06-21 19:23:57 -0700642 * 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 Powell637d3372010-08-25 14:37:03 -0700661 * 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 Monsen9f5f7af2011-02-24 11:14:11 +0000664 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700665 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000666 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700667 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 Monsen9f5f7af2011-02-24 11:14:11 +0000674 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700675 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000676 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700677 public boolean getUseWebViewBackgroundForOverscrollBackground() {
678 return mUseWebViewBackgroundForOverscroll;
679 }
680
681 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700682 * Store whether the WebView is saving form data.
683 */
684 public void setSaveFormData(boolean save) {
685 mSaveFormData = save;
686 }
687
688 /**
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500689 * Return whether the WebView is saving form data and displaying prior
690 * entries/autofill++. Always false in private browsing mode.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700691 */
692 public boolean getSaveFormData() {
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500693 return mSaveFormData && !mPrivateBrowsingEnabled;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700694 }
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 Project9066cfe2009-03-03 19:31:44 -0800716 if (WebView.mLogEvent && mTextSize != t ) {
Dan Egnor18e93962010-02-10 19:27:58 -0800717 EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
718 mTextSize.value, t.value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700720 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 Kloba0d8b77c2009-06-25 11:20:51 -0700734 * 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 Kloba0d8b77c2009-06-25 11:20:51 -0700738 */
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 Kloba0d8b77c2009-06-25 11:20:51 -0700751 */
752 public ZoomDensity getDefaultZoom() {
753 return mDefaultZoom;
754 }
755
756 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700757 * 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 Hearnadcd2ed2009-01-21 16:44:36 +0100771 * @deprecated This setting controlled a rendering optimization
772 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700773 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100774 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700775 public synchronized void setUseDoubleTree(boolean use) {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100776 return;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700777 }
778
779 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100780 * @deprecated This setting controlled a rendering optimization
781 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700782 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100783 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700784 public synchronized boolean getUseDoubleTree() {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100785 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700786 }
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 Projectf013e1a2008-12-17 18:05:43 -0800792 *
793 * @deprecated Please use setUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700794 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800795 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700796 public synchronized void setUserAgent(int ua) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800797 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 Project54b6cfa2008-10-21 07:00:00 -0700812 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800813 setUserAgentString(uaString);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700814 }
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 Projectf013e1a2008-12-17 18:05:43 -0800820 * -1 if the WebView is using user defined user-agent string.
821 *
822 * @deprecated Please use getUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700823 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800824 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700825 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 Projectf013e1a2008-12-17 18:05:43 -0800830 } else if (mUseDefaultUserAgent) {
831 return 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700832 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800833 return -1;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700834 }
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 Monsen9f5f7af2011-02-24 11:14:11 +0000879 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700880 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000881 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700882 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 Hearnadcd2ed2009-01-21 16:44:36 +0100892 * Return the current layout algorithm. The default is NARROW_COLUMNS.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700893 * @return LayoutAlgorithm enum value describing the layout algorithm
894 * being used.
895 * @see WebSettings.LayoutAlgorithm
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000896 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700897 */
Kristian Monsen9f5f7af2011-02-24 11:14:11 +0000898 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700899 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 Hearnadcd2ed2009-01-21 16:44:36 +0100915 * Get the standard font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700916 * @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 Hearnadcd2ed2009-01-21 16:44:36 +0100934 * Get the fixed font family name. The default is "monospace".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700935 * @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 Hearnadcd2ed2009-01-21 16:44:36 +0100961 * Set the serif font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700962 * @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 Hearnadcd2ed2009-01-21 16:44:36 +0100972 * Get the serif font family name. The default is "serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700973 * @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 Hearnadcd2ed2009-01-21 16:44:36 +0100991 * Get the cursive font family name. The default is "cursive".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700992 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001010 * Get the fantasy font family name. The default is "fantasy".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001011 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001031 * Get the minimum font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001032 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001052 * Get the minimum logical font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001053 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001073 * Get the default font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001074 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001094 * Get the default fixed font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001095 * @return A non-negative integer between 1 and 72.
1096 */
1097 public synchronized int getDefaultFixedFontSize() {
1098 return mDefaultFixedFontSize;
1099 }
1100
1101 /**
Grace Kloba097b1e772009-11-24 14:23:18 -08001102 * 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 Project54b6cfa2008-10-21 07:00:00 -07001116 * 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 Hearnadcd2ed2009-01-21 16:44:36 +01001128 * The default is true.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001129 * @return True if the WebView loads images automatically.
1130 */
1131 public synchronized boolean getLoadsImagesAutomatically() {
1132 return mLoadsImagesAutomatically;
1133 }
1134
1135 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001136 * 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 Project54b6cfa2008-10-21 07:00:00 -07001142 */
1143 public synchronized void setBlockNetworkImage(boolean flag) {
1144 if (mBlockNetworkImage != flag) {
1145 mBlockNetworkImage = flag;
1146 postSync();
1147 }
1148 }
1149
1150 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001151 * 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 Project54b6cfa2008-10-21 07:00:00 -07001154 */
1155 public synchronized boolean getBlockNetworkImage() {
1156 return mBlockNetworkImage;
1157 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001158
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001159 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001160 * 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 Projectf013e1a2008-12-17 18:05:43 -08001166 */
1167 public synchronized void setBlockNetworkLoads(boolean flag) {
1168 if (mBlockNetworkLoads != flag) {
1169 mBlockNetworkLoads = flag;
1170 verifyNetworkAccess();
Patrick Scott4243a3a2010-10-05 09:30:24 -04001171 postSync();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001172 }
1173 }
1174
1175 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001176 * Return true if the WebView will block all network loads. The default is
1177 * false.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001178 * @return True if the WebView blocks all network loads.
1179 */
1180 public synchronized boolean getBlockNetworkLoads() {
1181 return mBlockNetworkLoads;
1182 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001183
1184
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001185 private void verifyNetworkAccess() {
1186 if (!mBlockNetworkLoads) {
Michael Kolba172e7d2010-06-30 12:35:26 -07001187 if (mContext.checkPermission("android.permission.INTERNET",
1188 android.os.Process.myPid(), android.os.Process.myUid()) !=
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001189 PackageManager.PERMISSION_GRANTED) {
1190 throw new SecurityException
1191 ("Permission denied - " +
1192 "application missing INTERNET permission");
1193 }
1194 }
1195 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001196
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 Zhuda7378e2011-02-16 11:25:03 -08001209 * 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 Project54b6cfa2008-10-21 07:00:00 -07001229 * Tell the WebView to enable plugins.
1230 * @param flag True if the WebView should load plugins.
Patrick Scott300f2e92010-03-22 10:20:45 -04001231 * @deprecated This method has been deprecated in favor of
1232 * {@link #setPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001233 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001234 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001235 public synchronized void setPluginsEnabled(boolean flag) {
Patrick Scott300f2e92010-03-22 10:20:45 -04001236 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 Project54b6cfa2008-10-21 07:00:00 -07001249 postSync();
1250 }
1251 }
1252
1253 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001254 * 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 Project54b6cfa2008-10-21 07:00:00 -07001259 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001260 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001261 public synchronized void setPluginsPath(String pluginsPath) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001262 }
1263
1264 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001265 * Set the path to where database storage API databases should be saved.
Ben Murdoch18773af2010-02-25 18:41:56 +00001266 * Nota that the WebCore Database Tracker only allows the path to be set once.
Ben Murdoch7df19852009-04-22 13:07:58 +01001267 * 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 Murdoch18773af2010-02-25 18:41:56 +00001272 if (databasePath != null && !mDatabasePathHasBeenSet) {
Ben Murdoch7df19852009-04-22 13:07:58 +01001273 mDatabasePath = databasePath;
Ben Murdoch18773af2010-02-25 18:41:56 +00001274 mDatabasePathHasBeenSet = true;
Ben Murdoch7df19852009-04-22 13:07:58 +01001275 postSync();
1276 }
1277 }
1278
1279 /**
Steve Block9d3273f2009-08-21 13:16:27 +01001280 * 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 Block9d3273f2009-08-21 13:16:27 +01001285 */
1286 public synchronized void setGeolocationDatabasePath(String databasePath) {
Grace Kloba8f5e4052009-10-06 12:56:07 -07001287 if (databasePath != null
1288 && !databasePath.equals(mGeolocationDatabasePath)) {
Steve Block9d3273f2009-08-21 13:16:27 +01001289 mGeolocationDatabasePath = databasePath;
1290 postSync();
1291 }
1292 }
1293
1294 /**
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001295 * Tell the WebView to enable Application Caches API.
1296 * @param flag True if the WebView should enable Application Caches.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001297 */
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 Popescu60a9a7d2009-04-17 10:43:42 +01001311 */
1312 public synchronized void setAppCachePath(String appCachePath) {
1313 if (appCachePath != null && !appCachePath.equals(mAppCachePath)) {
1314 mAppCachePath = appCachePath;
1315 postSync();
1316 }
1317 }
1318
1319 /**
Andrei Popescu1c829202009-07-22 16:47:52 +01001320 * Set the maximum size for the Application Caches content.
1321 * @param appCacheMaxSize the maximum size in bytes.
Andrei Popescu1c829202009-07-22 16:47:52 +01001322 */
1323 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) {
1324 if (appCacheMaxSize != mAppCacheMaxSize) {
1325 mAppCacheMaxSize = appCacheMaxSize;
1326 postSync();
1327 }
1328 }
1329
1330 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001331 * 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 Murdoch274680d2009-05-28 13:44:44 +01001343 * Set whether the DOM storage API is enabled.
1344 * @param flag boolean True if the WebView should use the DOM storage
1345 * API.
Ben Murdoch274680d2009-05-28 13:44:44 +01001346 */
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 Murdoch274680d2009-05-28 13:44:44 +01001357 */
1358 public synchronized boolean getDomStorageEnabled() {
1359 return mDomStorageEnabled;
1360 }
1361
1362 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001363 * 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 Popescuc27a9ac2009-08-03 15:59:24 +01001380 * 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 Block06cd7512009-08-21 10:26:37 +01001394 * Sets whether Geolocation is enabled.
1395 * @param flag Whether Geolocation should be enabled.
Steve Block06cd7512009-08-21 10:26:37 +01001396 */
1397 public synchronized void setGeolocationEnabled(boolean flag) {
1398 if (mGeolocationEnabled != flag) {
1399 mGeolocationEnabled = flag;
1400 postSync();
1401 }
1402 }
1403
1404 /**
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001405 * Sets whether XSS Auditor is enabled.
1406 * @param flag Whether XSS Auditor should be enabled.
Elliott Slaughterbe1304f2010-06-23 11:29:02 -07001407 * @hide Only used by LayoutTestController.
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001408 */
1409 public synchronized void setXSSAuditorEnabled(boolean flag) {
1410 if (mXSSAuditorEnabled != flag) {
1411 mXSSAuditorEnabled = flag;
1412 postSync();
1413 }
1414 }
1415
1416 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001417 * Return true if javascript is enabled. <b>Note: The default is false.</b>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001418 * @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 Scott300f2e92010-03-22 10:20:45 -04001427 * @deprecated This method has been replaced by {@link #getPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001428 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001429 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001430 public synchronized boolean getPluginsEnabled() {
Patrick Scott300f2e92010-03-22 10:20:45 -04001431 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 Project54b6cfa2008-10-21 07:00:00 -07001440 }
1441
1442 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001443 * 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 Project54b6cfa2008-10-21 07:00:00 -07001448 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001449 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001450 public synchronized String getPluginsPath() {
Grace Kloba658ab7d2009-05-14 14:45:26 -07001451 return "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001452 }
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 Hearnadcd2ed2009-01-21 16:44:36 +01001468 * Return true if javascript can open windows automatically. The default
1469 * is false.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001470 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001489 * Get the default text encoding name. The default is "Latin-1".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001490 * @return The default text encoding name as a string.
1491 */
1492 public synchronized String getDefaultTextEncodingName() {
1493 return mDefaultTextEncoding;
1494 }
1495
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001496 /**
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 Kolba172e7d2010-06-30 12:35:26 -07001503 Locale currentLocale = Locale.getDefault();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001504 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 Project54b6cfa2008-10-21 07:00:00 -07001544 return mUserAgent;
1545 }
1546
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001547 /* 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 Kolba172e7d2010-06-30 12:35:26 -07001558
Shimeng (Simon) Wangc55886a2010-10-28 13:46:02 -07001559 /* package */ boolean isNarrowColumnLayout() {
1560 return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS;
1561 }
1562
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001563 /**
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 Kolba172e7d2010-06-30 12:35:26 -07001566 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001567 * @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 Hearnadcd2ed2009-01-21 16:44:36 +01001582 * one only needs to be called once per process. The default is NORMAL.
1583 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001584 * @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 Kolba172e7d2010-06-30 12:35:26 -07001593
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001594 /**
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 Monsenc40fc872011-01-19 15:44:04 +00001605 postSync();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001606 }
1607 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001608
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001609 /**
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 Kolba172e7d2010-06-30 12:35:26 -07001616
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001617 /**
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 Project54b6cfa2008-10-21 07:00:00 -07001630
Cary Clarkf0785a62010-06-25 11:45:40 -04001631 /**
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 Slaughterf21d2e32010-07-14 18:08:54 -07001644 /**
Shimeng (Simon) Wang2c782e32011-01-04 13:32:06 -08001645 * Returns whether to use fixed viewport. Fixed viewport should operate only
1646 * when wide viewport is on.
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001647 */
1648 /* package */ boolean getUseFixedViewport() {
Shimeng (Simon) Wang2c782e32011-01-04 13:32:06 -08001649 return getUseWideViewPort() && mUseFixedViewport;
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001650 }
1651
1652 /**
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001653 * 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 Murdoch4bd87d62011-01-18 14:10:48 +00001666
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 Slaughterf21d2e32010-07-14 18:08:54 -07001671 postSync();
1672 }
1673 }
1674
Cary Clark6c43d522010-08-31 15:41:54 -04001675 synchronized void setSyntheticLinksEnabled(boolean flag) {
1676 if (mSyntheticLinksEnabled != flag) {
1677 mSyntheticLinksEnabled = flag;
1678 postSync();
1679 }
1680 }
1681
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001682 /**
1683 * @hide
1684 */
1685 public synchronized void setAutoFillEnabled(boolean enabled) {
Ben Murdoch4bd87d62011-01-18 14:10:48 +00001686 // AutoFill is always disabled in private browsing mode.
1687 boolean autoFillEnabled = enabled && !mPrivateBrowsingEnabled;
1688 if (mAutoFillEnabled != autoFillEnabled) {
1689 mAutoFillEnabled = autoFillEnabled;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001690 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 Murdochb1b82a82010-10-20 14:18:25 +01001705 if (mAutoFillProfile != profile) {
1706 mAutoFillProfile = profile;
1707 postSync();
1708 }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001709 }
1710
Ben Murdoch57914382010-11-16 11:50:39 +00001711 /**
1712 * @hide
1713 */
1714 public synchronized AutoFillProfile getAutoFillProfile() {
1715 return mAutoFillProfile;
1716 }
1717
Grace Klobaf8d8b462009-09-20 15:57:49 -07001718 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 Project54b6cfa2008-10-21 07:00:00 -07001731 /**
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 Sollenberger2e5c1502009-06-03 10:44:42 -04001738 if (DebugFlags.WEB_SETTINGS) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001739 junit.framework.Assert.assertTrue(frame.mNativeFrame != 0);
1740 }
Andrei Popescudee76be2009-09-22 18:28:21 +01001741
Grace Klobaf8d8b462009-09-20 15:57:49 -07001742 SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
1743 Context.MODE_PRIVATE);
Grace Kloba24a3ff92009-09-22 10:42:22 -07001744 if (mDoubleTapToastCount > 0) {
1745 mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
1746 mDoubleTapToastCount);
1747 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001748 nativeSync(frame.mNativeFrame);
1749 mSyncPending = false;
1750 mEventHandler.createHandler();
1751 }
1752
Andrei Popescudee76be2009-09-22 18:28:21 +01001753 /**
1754 * Let the Settings object know that our owner is being destroyed.
1755 */
1756 /*package*/
1757 synchronized void onDestroyed() {
Andrei Popescudee76be2009-09-22 18:28:21 +01001758 }
1759
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001760 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 Project54b6cfa2008-10-21 07:00:00 -07001770 /* 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}