blob: 617584b144b29f46072de01d370a678031f0520f [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.
45 */
46 // XXX: These must match LayoutAlgorithm in Settings.h in WebCore.
47 public enum LayoutAlgorithm {
48 NORMAL,
John Reck5a1ef4132011-10-26 10:37:00 -070049 /**
50 * @deprecated This algorithm is now obsolete.
51 */
52 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070053 SINGLE_COLUMN,
54 NARROW_COLUMNS
55 }
56
57 /**
58 * Enum for specifying the text size.
59 * SMALLEST is 50%
60 * SMALLER is 75%
61 * NORMAL is 100%
62 * LARGER is 150%
63 * LARGEST is 200%
John Reckcaeb1202011-06-17 11:50:15 -070064 * @deprecated Use {@link WebSettings#setTextZoom(int)} and {@link WebSettings#getTextZoom()} instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070065 */
66 public enum TextSize {
67 SMALLEST(50),
68 SMALLER(75),
69 NORMAL(100),
70 LARGER(150),
71 LARGEST(200);
72 TextSize(int size) {
73 value = size;
74 }
75 int value;
76 }
Grace Kloba0d8b77c2009-06-25 11:20:51 -070077
78 /**
79 * Enum for specifying the WebView's desired density.
80 * FAR makes 100% looking like in 240dpi
81 * MEDIUM makes 100% looking like in 160dpi
82 * CLOSE makes 100% looking like in 120dpi
Grace Kloba0d8b77c2009-06-25 11:20:51 -070083 */
84 public enum ZoomDensity {
85 FAR(150), // 240dpi
86 MEDIUM(100), // 160dpi
87 CLOSE(75); // 120dpi
88 ZoomDensity(int size) {
89 value = size;
90 }
91 int value;
92 }
93
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070094 /**
95 * Default cache usage pattern Use with {@link #setCacheMode}.
96 */
97 public static final int LOAD_DEFAULT = -1;
98
99 /**
100 * Normal cache usage pattern Use with {@link #setCacheMode}.
101 */
102 public static final int LOAD_NORMAL = 0;
103
104 /**
105 * Use cache if content is there, even if expired (eg, history nav)
106 * If it is not in the cache, load from network.
107 * Use with {@link #setCacheMode}.
108 */
109 public static final int LOAD_CACHE_ELSE_NETWORK = 1;
110
111 /**
112 * Don't use the cache, load from network
113 * Use with {@link #setCacheMode}.
114 */
115 public static final int LOAD_NO_CACHE = 2;
Michael Kolba172e7d2010-06-30 12:35:26 -0700116
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700117 /**
118 * Don't use the network, load from cache only.
119 * Use with {@link #setCacheMode}.
120 */
121 public static final int LOAD_CACHE_ONLY = 3;
122
123 public enum RenderPriority {
124 NORMAL,
125 HIGH,
126 LOW
127 }
128
Patrick Scott300f2e92010-03-22 10:20:45 -0400129 /**
130 * The plugin state effects how plugins are treated on a page. ON means
131 * that any object will be loaded even if a plugin does not exist to handle
132 * the content. ON_DEMAND means that if there is a plugin installed that
133 * can handle the content, a placeholder is shown until the user clicks on
134 * the placeholder. Once clicked, the plugin will be enabled on the page.
135 * OFF means that all plugins will be turned off and any fallback content
136 * will be used.
137 */
138 public enum PluginState {
139 ON,
140 ON_DEMAND,
141 OFF
142 }
143
John Reckf5577402011-04-28 10:27:40 -0700144 // TODO: Keep this up to date
145 private static final String PREVIOUS_VERSION = "3.1";
146
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700147 // WebView associated with this WebSettings.
148 private WebView mWebView;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700149 // BrowserFrame used to access the native frame pointer.
150 private BrowserFrame mBrowserFrame;
151 // Flag to prevent multiple SYNC messages at one time.
152 private boolean mSyncPending = false;
153 // Custom handler that queues messages until the WebCore thread is active.
154 private final EventHandler mEventHandler;
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100155
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700156 // Private settings so we don't have to go into native code to
157 // retrieve the values. After setXXX, postSync() needs to be called.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100158 //
159 // The default values need to match those in WebSettings.cpp
160 // If the defaults change, please also update the JavaDocs so developers
161 // know what they are.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700162 private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800163 private Context mContext;
John Reckff56bcd2011-06-16 17:12:08 -0700164 private int mTextSize = 100;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700165 private String mStandardFontFamily = "sans-serif";
166 private String mFixedFontFamily = "monospace";
167 private String mSansSerifFontFamily = "sans-serif";
168 private String mSerifFontFamily = "serif";
169 private String mCursiveFontFamily = "cursive";
170 private String mFantasyFontFamily = "fantasy";
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900171 private String mDefaultTextEncoding;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800172 private String mUserAgent;
173 private boolean mUseDefaultUserAgent;
174 private String mAcceptLanguage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700175 private int mMinimumFontSize = 8;
176 private int mMinimumLogicalFontSize = 8;
177 private int mDefaultFontSize = 16;
178 private int mDefaultFixedFontSize = 13;
Grace Kloba097b1e772009-11-24 14:23:18 -0800179 private int mPageCacheCapacity = 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700180 private boolean mLoadsImagesAutomatically = true;
181 private boolean mBlockNetworkImage = false;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700182 private boolean mBlockNetworkLoads;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700183 private boolean mJavaScriptEnabled = false;
Derek Sollenberger1d335f32011-07-08 11:28:23 -0400184 private boolean mHardwareAccelSkia = false;
Teng-Hui Zhuda7378e2011-02-16 11:25:03 -0800185 private boolean mShowVisualIndicator = false;
Patrick Scott300f2e92010-03-22 10:20:45 -0400186 private PluginState mPluginState = PluginState.OFF;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700187 private boolean mJavaScriptCanOpenWindowsAutomatically = false;
188 private boolean mUseDoubleTree = false;
189 private boolean mUseWideViewport = false;
190 private boolean mSupportMultipleWindows = false;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800191 private boolean mShrinksStandaloneImagesToFit = false;
Cary Clarkf0785a62010-06-25 11:45:40 -0400192 private long mMaximumDecodedImageSize = 0; // 0 means default
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700193 private boolean mPrivateBrowsingEnabled = false;
Cary Clark6c43d522010-08-31 15:41:54 -0400194 private boolean mSyntheticLinksEnabled = true;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100195 // HTML5 API flags
196 private boolean mAppCacheEnabled = false;
197 private boolean mDatabaseEnabled = false;
198 private boolean mDomStorageEnabled = false;
199 private boolean mWorkersEnabled = false; // only affects V8.
Steve Block09b0ca12009-08-26 18:16:58 +0100200 private boolean mGeolocationEnabled = true;
Elliott Slaughter5dc0c822010-06-22 11:31:54 -0700201 private boolean mXSSAuditorEnabled = false;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100202 // HTML5 configuration parameters
203 private long mAppCacheMaxSize = Long.MAX_VALUE;
Steve Block92f30c32011-12-15 15:16:19 +0000204 private String mAppCachePath = null;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100205 private String mDatabasePath = "";
Ben Murdoch18773af2010-02-25 18:41:56 +0000206 // The WebCore DatabaseTracker only allows the database path to be set
207 // once. Keep track of when the path has been set.
208 private boolean mDatabasePathHasBeenSet = false;
Steve Block9d3273f2009-08-21 13:16:27 +0100209 private String mGeolocationDatabasePath = "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700210 // Don't need to synchronize the get/set methods as they
211 // are basic types, also none of these values are used in
212 // native WebCore code.
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700213 private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700214 private RenderPriority mRenderPriority = RenderPriority.NORMAL;
215 private int mOverrideCacheMode = LOAD_DEFAULT;
Mangesh Ghiwareedb528e2011-10-12 14:25:41 -0700216 private int mDoubleTapZoom = 100;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700217 private boolean mSaveFormData = true;
Ben Murdochf39b2cf2010-09-09 10:26:46 +0100218 private boolean mAutoFillEnabled = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700219 private boolean mSavePassword = true;
220 private boolean mLightTouchEnabled = false;
221 private boolean mNeedInitialFocus = true;
222 private boolean mNavDump = false;
223 private boolean mSupportZoom = true;
The Android Open Source Project10592532009-03-18 17:39:46 -0700224 private boolean mBuiltInZoomControls = false;
Michael Kolb6fe3b422010-08-19 12:41:24 -0700225 private boolean mDisplayZoomControls = true;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800226 private boolean mAllowFileAccess = true;
Patrick Scottd1737ed2011-01-05 11:36:48 -0500227 private boolean mAllowContentAccess = true;
Cary Clarkf8d49642009-09-08 13:23:24 -0400228 private boolean mLoadWithOverviewMode = false;
Grace Klobaf9b731d2010-06-21 19:23:57 -0700229 private boolean mEnableSmoothTransition = false;
John Reck7818aaa2011-04-26 16:57:46 -0700230 private boolean mForceUserScalable = false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700231
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100232 // AutoFill Profile data
233 /**
234 * @hide for now, pending API council approval.
235 */
236 public static class AutoFillProfile {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100237 private int mUniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100238 private String mFullName;
239 private String mEmailAddress;
Ben Murdochcf308722010-10-13 17:38:46 +0100240 private String mCompanyName;
241 private String mAddressLine1;
242 private String mAddressLine2;
243 private String mCity;
244 private String mState;
245 private String mZipCode;
246 private String mCountry;
247 private String mPhoneNumber;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100248
Ben Murdochb1b82a82010-10-20 14:18:25 +0100249 public AutoFillProfile(int uniqueId, String fullName, String email,
Ben Murdochcf308722010-10-13 17:38:46 +0100250 String companyName, String addressLine1, String addressLine2,
251 String city, String state, String zipCode, String country,
252 String phoneNumber) {
Ben Murdochb1b82a82010-10-20 14:18:25 +0100253 mUniqueId = uniqueId;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100254 mFullName = fullName;
255 mEmailAddress = email;
Ben Murdochcf308722010-10-13 17:38:46 +0100256 mCompanyName = companyName;
257 mAddressLine1 = addressLine1;
258 mAddressLine2 = addressLine2;
259 mCity = city;
260 mState = state;
261 mZipCode = zipCode;
262 mCountry = country;
263 mPhoneNumber = phoneNumber;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100264 }
265
Ben Murdochb1b82a82010-10-20 14:18:25 +0100266 public int getUniqueId() { return mUniqueId; }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100267 public String getFullName() { return mFullName; }
268 public String getEmailAddress() { return mEmailAddress; }
Ben Murdochcf308722010-10-13 17:38:46 +0100269 public String getCompanyName() { return mCompanyName; }
270 public String getAddressLine1() { return mAddressLine1; }
271 public String getAddressLine2() { return mAddressLine2; }
272 public String getCity() { return mCity; }
273 public String getState() { return mState; }
274 public String getZipCode() { return mZipCode; }
275 public String getCountry() { return mCountry; }
276 public String getPhoneNumber() { return mPhoneNumber; }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +0100277 }
278
279
280 private AutoFillProfile mAutoFillProfile;
281
Adam Powell637d3372010-08-25 14:37:03 -0700282 private boolean mUseWebViewBackgroundForOverscroll = true;
283
Grace Klobaf8d8b462009-09-20 15:57:49 -0700284 // private WebSettings, not accessible by the host activity
Grace Kloba24a3ff92009-09-22 10:42:22 -0700285 static private int mDoubleTapToastCount = 3;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700286
287 private static final String PREF_FILE = "WebViewSettings";
288 private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";
289
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700290 // Class to handle messages before WebCore is ready.
291 private class EventHandler {
292 // Message id for syncing
293 static final int SYNC = 0;
294 // Message id for setting priority
295 static final int PRIORITY = 1;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700296 // Message id for writing double-tap toast count
297 static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700298 // Actual WebCore thread handler
299 private Handler mHandler;
300
301 private synchronized void createHandler() {
302 // as mRenderPriority can be set before thread is running, sync up
303 setRenderPriority();
304
305 // create a new handler
306 mHandler = new Handler() {
307 @Override
308 public void handleMessage(Message msg) {
309 switch (msg.what) {
310 case SYNC:
311 synchronized (WebSettings.this) {
312 if (mBrowserFrame.mNativeFrame != 0) {
313 nativeSync(mBrowserFrame.mNativeFrame);
314 }
315 mSyncPending = false;
316 }
317 break;
318
319 case PRIORITY: {
320 setRenderPriority();
321 break;
322 }
Grace Klobaf8d8b462009-09-20 15:57:49 -0700323
324 case SET_DOUBLE_TAP_TOAST_COUNT: {
325 SharedPreferences.Editor editor = mContext
326 .getSharedPreferences(PREF_FILE,
327 Context.MODE_PRIVATE).edit();
328 editor.putInt(DOUBLE_TAP_TOAST_COUNT,
329 mDoubleTapToastCount);
330 editor.commit();
331 break;
332 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700333 }
334 }
335 };
336 }
337
338 private void setRenderPriority() {
339 synchronized (WebSettings.this) {
340 if (mRenderPriority == RenderPriority.NORMAL) {
341 android.os.Process.setThreadPriority(
342 android.os.Process.THREAD_PRIORITY_DEFAULT);
343 } else if (mRenderPriority == RenderPriority.HIGH) {
344 android.os.Process.setThreadPriority(
345 android.os.Process.THREAD_PRIORITY_FOREGROUND +
346 android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
347 } else if (mRenderPriority == RenderPriority.LOW) {
348 android.os.Process.setThreadPriority(
349 android.os.Process.THREAD_PRIORITY_BACKGROUND);
350 }
351 }
352 }
353
354 /**
355 * Send a message to the private queue or handler.
356 */
357 private synchronized boolean sendMessage(Message msg) {
358 if (mHandler != null) {
359 mHandler.sendMessage(msg);
360 return true;
361 } else {
362 return false;
363 }
364 }
365 }
366
367 // User agent strings.
John Reck5443ba42011-05-23 16:50:29 -0700368 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
369 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
370 "Chrome/11.0.696.34 Safari/534.24";
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700371 private static final String IPHONE_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700372 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)"
373 + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0"
374 + " Mobile/7A341 Safari/528.16";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800375 private static Locale sLocale;
376 private static Object sLockForLocaleSettings;
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700377
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700378 /**
379 * Package constructor to prevent clients from creating a new settings
380 * instance.
381 */
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700382 WebSettings(Context context, WebView webview) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700383 mEventHandler = new EventHandler();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800384 mContext = context;
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700385 mWebView = webview;
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900386 mDefaultTextEncoding = context.getString(com.android.internal.
387 R.string.default_text_encoding);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800388
389 if (sLockForLocaleSettings == null) {
390 sLockForLocaleSettings = new Object();
391 sLocale = Locale.getDefault();
392 }
393 mAcceptLanguage = getCurrentAcceptLanguage();
394 mUserAgent = getCurrentUserAgent();
395 mUseDefaultUserAgent = true;
396
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700397 mBlockNetworkLoads = mContext.checkPermission(
398 "android.permission.INTERNET", android.os.Process.myPid(),
399 android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700400 }
401
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700402 private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US";
403
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700404 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800405 * Looks at sLocale and returns current AcceptLanguage String.
406 * @return Current AcceptLanguage String.
407 */
408 private String getCurrentAcceptLanguage() {
409 Locale locale;
410 synchronized(sLockForLocaleSettings) {
411 locale = sLocale;
412 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700413 StringBuilder buffer = new StringBuilder();
414 addLocaleToHttpAcceptLanguage(buffer, locale);
415
416 if (!Locale.US.equals(locale)) {
417 if (buffer.length() > 0) {
418 buffer.append(", ");
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800419 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700420 buffer.append(ACCEPT_LANG_FOR_US_LOCALE);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800421 }
422
423 return buffer.toString();
424 }
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700425
426 /**
427 * Convert obsolete language codes, including Hebrew/Indonesian/Yiddish,
428 * to new standard.
429 */
430 private static String convertObsoleteLanguageCodeToNew(String langCode) {
431 if (langCode == null) {
432 return null;
433 }
434 if ("iw".equals(langCode)) {
435 // Hebrew
436 return "he";
437 } else if ("in".equals(langCode)) {
438 // Indonesian
439 return "id";
440 } else if ("ji".equals(langCode)) {
441 // Yiddish
442 return "yi";
443 }
444 return langCode;
445 }
446
447 private static void addLocaleToHttpAcceptLanguage(StringBuilder builder,
448 Locale locale) {
449 String language = convertObsoleteLanguageCodeToNew(locale.getLanguage());
450 if (language != null) {
451 builder.append(language);
452 String country = locale.getCountry();
453 if (country != null) {
454 builder.append("-");
455 builder.append(country);
456 }
457 }
458 }
459
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800460 /**
461 * Looks at sLocale and mContext and returns current UserAgent String.
462 * @return Current UserAgent String.
463 */
464 private synchronized String getCurrentUserAgent() {
465 Locale locale;
466 synchronized(sLockForLocaleSettings) {
467 locale = sLocale;
468 }
469 StringBuffer buffer = new StringBuffer();
470 // Add version
471 final String version = Build.VERSION.RELEASE;
472 if (version.length() > 0) {
John Reckf5577402011-04-28 10:27:40 -0700473 if (Character.isDigit(version.charAt(0))) {
474 // Release is a version, eg "3.1"
475 buffer.append(version);
476 } else {
477 // Release is a codename, eg "Honeycomb"
478 // In this case, use the previous release's version
479 buffer.append(PREVIOUS_VERSION);
480 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800481 } else {
482 // default to "1.0"
483 buffer.append("1.0");
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700484 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800485 buffer.append("; ");
486 final String language = locale.getLanguage();
487 if (language != null) {
Shimeng (Simon) Wang0e4cb9d2010-04-14 18:11:05 -0700488 buffer.append(convertObsoleteLanguageCodeToNew(language));
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800489 final String country = locale.getCountry();
490 if (country != null) {
491 buffer.append("-");
492 buffer.append(country.toLowerCase());
493 }
494 } else {
495 // default to "en"
496 buffer.append("en");
497 }
John Reck36fd7a32011-01-07 18:45:33 -0800498 buffer.append(";");
Grace Klobace761d32009-08-27 15:24:59 -0700499 // add the model for the release build
500 if ("REL".equals(Build.VERSION.CODENAME)) {
501 final String model = Build.MODEL;
502 if (model.length() > 0) {
John Reck36fd7a32011-01-07 18:45:33 -0800503 buffer.append(" ");
Grace Klobace761d32009-08-27 15:24:59 -0700504 buffer.append(model);
505 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 }
507 final String id = Build.ID;
508 if (id.length() > 0) {
509 buffer.append(" Build/");
510 buffer.append(id);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800511 }
Michael Kolb37b64de2010-07-01 12:05:47 -0700512 String mobile = mContext.getResources().getText(
513 com.android.internal.R.string.web_user_agent_target_content).toString();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800514 final String base = mContext.getResources().getText(
515 com.android.internal.R.string.web_user_agent).toString();
Michael Kolba172e7d2010-06-30 12:35:26 -0700516 return String.format(base, buffer, mobile);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800517 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700518
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800519 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700520 * Enables dumping the pages navigation cache to a text file.
Kristian Monsenfc771652011-05-10 16:44:05 +0100521 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700522 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100523 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700524 public void setNavDump(boolean enabled) {
525 mNavDump = enabled;
526 }
527
528 /**
529 * Returns true if dumping the navigation cache is enabled.
Kristian Monsenfc771652011-05-10 16:44:05 +0100530 * @deprecated This method is now obsolete.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700531 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100532 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700533 public boolean getNavDump() {
534 return mNavDump;
535 }
536
537 /**
Grace Kloba178db412010-05-18 22:22:23 -0700538 * If WebView only supports touch, a different navigation model will be
539 * applied. Otherwise, the navigation to support both touch and keyboard
540 * will be used.
541 * @hide
542 public void setSupportTouchOnly(boolean touchOnly) {
543 mSupportTounchOnly = touchOnly;
544 }
545 */
546
547 boolean supportTouchOnly() {
548 // for debug only, use mLightTouchEnabled for mSupportTounchOnly
549 return mLightTouchEnabled;
550 }
551
552 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700553 * Set whether the WebView supports zoom
554 */
555 public void setSupportZoom(boolean support) {
556 mSupportZoom = support;
Grace Kloba3a0def22010-01-23 21:11:54 -0800557 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700558 }
559
560 /**
561 * Returns whether the WebView supports zoom
562 */
563 public boolean supportZoom() {
564 return mSupportZoom;
565 }
566
567 /**
The Android Open Source Project10592532009-03-18 17:39:46 -0700568 * Sets whether the zoom mechanism built into WebView is used.
569 */
570 public void setBuiltInZoomControls(boolean enabled) {
571 mBuiltInZoomControls = enabled;
Grace Kloba3a0def22010-01-23 21:11:54 -0800572 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project10592532009-03-18 17:39:46 -0700573 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700574
The Android Open Source Project10592532009-03-18 17:39:46 -0700575 /**
576 * Returns true if the zoom mechanism built into WebView is being used.
577 */
578 public boolean getBuiltInZoomControls() {
579 return mBuiltInZoomControls;
580 }
Michael Kolba172e7d2010-06-30 12:35:26 -0700581
The Android Open Source Project10592532009-03-18 17:39:46 -0700582 /**
Michael Kolb6fe3b422010-08-19 12:41:24 -0700583 * Sets whether the on screen zoom buttons are used.
584 * A combination of built in zoom controls enabled
585 * and on screen zoom controls disabled allows for pinch to zoom
586 * to work without the on screen controls
Michael Kolb6fe3b422010-08-19 12:41:24 -0700587 */
588 public void setDisplayZoomControls(boolean enabled) {
589 mDisplayZoomControls = enabled;
590 mWebView.updateMultiTouchSupport(mContext);
591 }
592
593 /**
594 * Returns true if the on screen zoom buttons are being used.
Michael Kolb6fe3b422010-08-19 12:41:24 -0700595 */
596 public boolean getDisplayZoomControls() {
597 return mDisplayZoomControls;
598 }
599
600 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800601 * Enable or disable file access within WebView. File access is enabled by
Patrick Scottd1737ed2011-01-05 11:36:48 -0500602 * default. Note that this enables or disables file system access only.
603 * Assets and resources are still accessible using file:///android_asset and
604 * file:///android_res.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800605 */
606 public void setAllowFileAccess(boolean allow) {
607 mAllowFileAccess = allow;
608 }
609
610 /**
611 * Returns true if this WebView supports file access.
612 */
613 public boolean getAllowFileAccess() {
614 return mAllowFileAccess;
615 }
616
617 /**
Patrick Scottd1737ed2011-01-05 11:36:48 -0500618 * Enable or disable content url access within WebView. Content url access
619 * allows WebView to load content from a content provider installed in the
620 * system. The default is enabled.
621 */
622 public void setAllowContentAccess(boolean allow) {
623 mAllowContentAccess = allow;
624 }
625
626 /**
627 * Returns true if this WebView supports content url access.
628 */
629 public boolean getAllowContentAccess() {
630 return mAllowContentAccess;
631 }
632
633 /**
Grace Klobae397a882009-08-06 12:04:14 -0700634 * Set whether the WebView loads a page with overview mode.
Grace Klobae397a882009-08-06 12:04:14 -0700635 */
636 public void setLoadWithOverviewMode(boolean overview) {
637 mLoadWithOverviewMode = overview;
638 }
639
640 /**
641 * Returns true if this WebView loads page with overview mode
Grace Klobae397a882009-08-06 12:04:14 -0700642 */
643 public boolean getLoadWithOverviewMode() {
644 return mLoadWithOverviewMode;
645 }
646
647 /**
Grace Klobaf9b731d2010-06-21 19:23:57 -0700648 * Set whether the WebView will enable smooth transition while panning or
Adam Powelle00e8a782011-09-11 17:48:42 -0700649 * zooming or while the window hosting the WebView does not have focus.
650 * If it is true, WebView will choose a solution to maximize the performance.
651 * e.g. the WebView's content may not be updated during the transition.
652 * If it is false, WebView will keep its fidelity. The default value is false.
Grace Klobaf9b731d2010-06-21 19:23:57 -0700653 */
654 public void setEnableSmoothTransition(boolean enable) {
655 mEnableSmoothTransition = enable;
656 }
657
658 /**
659 * Returns true if the WebView enables smooth transition while panning or
660 * zooming.
661 */
662 public boolean enableSmoothTransition() {
663 return mEnableSmoothTransition;
664 }
665
666 /**
Adam Powell637d3372010-08-25 14:37:03 -0700667 * Set whether the WebView uses its background for over scroll background.
668 * If true, it will use the WebView's background. If false, it will use an
669 * internal pattern. Default is true.
Kristian Monsenfc771652011-05-10 16:44:05 +0100670 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700671 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100672 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700673 public void setUseWebViewBackgroundForOverscrollBackground(boolean view) {
674 mUseWebViewBackgroundForOverscroll = view;
675 }
676
677 /**
678 * Returns true if this WebView uses WebView's background instead of
679 * internal pattern for over scroll background.
Kristian Monsenfc771652011-05-10 16:44:05 +0100680 * @deprecated This method is now obsolete.
Adam Powell637d3372010-08-25 14:37:03 -0700681 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100682 @Deprecated
Adam Powell637d3372010-08-25 14:37:03 -0700683 public boolean getUseWebViewBackgroundForOverscrollBackground() {
684 return mUseWebViewBackgroundForOverscroll;
685 }
686
687 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700688 * Store whether the WebView is saving form data.
689 */
690 public void setSaveFormData(boolean save) {
691 mSaveFormData = save;
692 }
693
694 /**
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500695 * Return whether the WebView is saving form data and displaying prior
696 * entries/autofill++. Always false in private browsing mode.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700697 */
698 public boolean getSaveFormData() {
Leon Scrogginsaa6b9f52011-01-10 11:02:00 -0500699 return mSaveFormData && !mPrivateBrowsingEnabled;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700700 }
701
702 /**
703 * Store whether the WebView is saving password.
704 */
705 public void setSavePassword(boolean save) {
706 mSavePassword = save;
707 }
708
709 /**
710 * Return whether the WebView is saving password.
711 */
712 public boolean getSavePassword() {
713 return mSavePassword;
714 }
715
716 /**
John Reckff56bcd2011-06-16 17:12:08 -0700717 * Set the text zoom of the page in percent. Default is 100.
718 * @param textZoom A percent value for increasing or decreasing the text.
John Reckff56bcd2011-06-16 17:12:08 -0700719 */
720 public synchronized void setTextZoom(int textZoom) {
721 if (mTextSize != textZoom) {
722 if (WebView.mLogEvent) {
723 EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
724 mTextSize, textZoom);
725 }
726 mTextSize = textZoom;
727 postSync();
728 }
729 }
730
731 /**
732 * Get the text zoom of the page in percent.
733 * @return A percent value describing the text zoom.
734 * @see setTextSizeZoom
John Reckff56bcd2011-06-16 17:12:08 -0700735 */
736 public synchronized int getTextZoom() {
737 return mTextSize;
738 }
739
740 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700741 * Set the text size of the page.
742 * @param t A TextSize value for increasing or decreasing the text.
743 * @see WebSettings.TextSize
John Reckcaeb1202011-06-17 11:50:15 -0700744 * @deprecated Use {@link #setTextZoom(int)} instead
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700745 */
746 public synchronized void setTextSize(TextSize t) {
John Reckff56bcd2011-06-16 17:12:08 -0700747 setTextZoom(t.value);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700748 }
749
750 /**
John Reckcaeb1202011-06-17 11:50:15 -0700751 * Get the text size of the page. If the text size was previously specified
752 * in percent using {@link #setTextZoom(int)}, this will return
753 * the closest matching {@link TextSize}.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700754 * @return A TextSize enum value describing the text size.
755 * @see WebSettings.TextSize
John Reckcaeb1202011-06-17 11:50:15 -0700756 * @deprecated Use {@link #getTextZoom()} instead
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700757 */
758 public synchronized TextSize getTextSize() {
John Reckff56bcd2011-06-16 17:12:08 -0700759 TextSize closestSize = null;
760 int smallestDelta = Integer.MAX_VALUE;
761 for (TextSize size : TextSize.values()) {
762 int delta = Math.abs(mTextSize - size.value);
763 if (delta == 0) {
764 return size;
765 }
766 if (delta < smallestDelta) {
767 smallestDelta = delta;
768 closestSize = size;
769 }
770 }
771 return closestSize != null ? closestSize : TextSize.NORMAL;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700772 }
773
774 /**
Mangesh Ghiwareedb528e2011-10-12 14:25:41 -0700775 * Set the double-tap zoom of the page in percent. Default is 100.
776 * @param doubleTapZoom A percent value for increasing or decreasing the double-tap zoom.
777 * @hide
778 */
779 public void setDoubleTapZoom(int doubleTapZoom) {
780 if (mDoubleTapZoom != doubleTapZoom) {
781 mDoubleTapZoom = doubleTapZoom;
Mangesh Ghiwarebb99e282011-10-21 10:53:29 -0700782 mWebView.updateDoubleTapZoom(doubleTapZoom);
Mangesh Ghiwareedb528e2011-10-12 14:25:41 -0700783 }
784 }
785
786 /**
787 * Get the double-tap zoom of the page in percent.
788 * @return A percent value describing the double-tap zoom.
789 * @hide
790 */
791 public int getDoubleTapZoom() {
792 return mDoubleTapZoom;
793 }
794
795 /**
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700796 * Set the default zoom density of the page. This should be called from UI
797 * thread.
798 * @param zoom A ZoomDensity value
799 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700800 */
801 public void setDefaultZoom(ZoomDensity zoom) {
802 if (mDefaultZoom != zoom) {
803 mDefaultZoom = zoom;
Mangesh Ghiwaree832b632011-11-16 11:46:39 -0800804 mWebView.adjustDefaultZoomDensity(zoom.value);
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700805 }
806 }
807
808 /**
809 * Get the default zoom density of the page. This should be called from UI
810 * thread.
811 * @return A ZoomDensity value
812 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700813 */
814 public ZoomDensity getDefaultZoom() {
815 return mDefaultZoom;
816 }
817
818 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700819 * Enables using light touches to make a selection and activate mouseovers.
820 */
821 public void setLightTouchEnabled(boolean enabled) {
822 mLightTouchEnabled = enabled;
823 }
824
825 /**
826 * Returns true if light touches are enabled.
827 */
828 public boolean getLightTouchEnabled() {
829 return mLightTouchEnabled;
830 }
831
832 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100833 * @deprecated This setting controlled a rendering optimization
834 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700835 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100836 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700837 public synchronized void setUseDoubleTree(boolean use) {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100838 return;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700839 }
840
841 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100842 * @deprecated This setting controlled a rendering optimization
843 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700844 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100845 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700846 public synchronized boolean getUseDoubleTree() {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100847 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700848 }
849
850 /**
851 * Tell the WebView about user-agent string.
852 * @param ua 0 if the WebView should use an Android user-agent string,
853 * 1 if the WebView should use a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800854 *
855 * @deprecated Please use setUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700856 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800857 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700858 public synchronized void setUserAgent(int ua) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800859 String uaString = null;
860 if (ua == 1) {
861 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
862 return; // do nothing
863 } else {
864 uaString = DESKTOP_USERAGENT;
865 }
866 } else if (ua == 2) {
867 if (IPHONE_USERAGENT.equals(mUserAgent)) {
868 return; // do nothing
869 } else {
870 uaString = IPHONE_USERAGENT;
871 }
872 } else if (ua != 0) {
873 return; // do nothing
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700874 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800875 setUserAgentString(uaString);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700876 }
877
878 /**
879 * Return user-agent as int
880 * @return int 0 if the WebView is using an Android user-agent string.
881 * 1 if the WebView is using a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800882 * -1 if the WebView is using user defined user-agent string.
883 *
884 * @deprecated Please use getUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700885 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800886 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700887 public synchronized int getUserAgent() {
888 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
889 return 1;
890 } else if (IPHONE_USERAGENT.equals(mUserAgent)) {
891 return 2;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800892 } else if (mUseDefaultUserAgent) {
893 return 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700894 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800895 return -1;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700896 }
897
898 /**
899 * Tell the WebView to use the wide viewport
900 */
901 public synchronized void setUseWideViewPort(boolean use) {
902 if (mUseWideViewport != use) {
903 mUseWideViewport = use;
904 postSync();
905 }
906 }
907
908 /**
909 * @return True if the WebView is using a wide viewport
910 */
911 public synchronized boolean getUseWideViewPort() {
912 return mUseWideViewport;
913 }
914
915 /**
916 * Tell the WebView whether it supports multiple windows. TRUE means
917 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
918 * boolean, Message)} is implemented by the host application.
919 */
920 public synchronized void setSupportMultipleWindows(boolean support) {
921 if (mSupportMultipleWindows != support) {
922 mSupportMultipleWindows = support;
923 postSync();
924 }
925 }
926
927 /**
928 * @return True if the WebView is supporting multiple windows. This means
929 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
930 * boolean, Message)} is implemented by the host application.
931 */
932 public synchronized boolean supportMultipleWindows() {
933 return mSupportMultipleWindows;
934 }
935
936 /**
937 * Set the underlying layout algorithm. This will cause a relayout of the
938 * WebView.
939 * @param l A LayoutAlgorithm enum specifying the algorithm to use.
940 * @see WebSettings.LayoutAlgorithm
941 */
942 public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) {
943 // XXX: This will only be affective if libwebcore was built with
944 // ANDROID_LAYOUT defined.
945 if (mLayoutAlgorithm != l) {
946 mLayoutAlgorithm = l;
947 postSync();
948 }
949 }
950
951 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100952 * Return the current layout algorithm. The default is NARROW_COLUMNS.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700953 * @return LayoutAlgorithm enum value describing the layout algorithm
954 * being used.
955 * @see WebSettings.LayoutAlgorithm
956 */
957 public synchronized LayoutAlgorithm getLayoutAlgorithm() {
958 return mLayoutAlgorithm;
959 }
960
961 /**
962 * Set the standard font family name.
963 * @param font A font family name.
964 */
965 public synchronized void setStandardFontFamily(String font) {
966 if (font != null && !font.equals(mStandardFontFamily)) {
967 mStandardFontFamily = font;
968 postSync();
969 }
970 }
971
972 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100973 * Get the standard font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700974 * @return The standard font family name as a string.
975 */
976 public synchronized String getStandardFontFamily() {
977 return mStandardFontFamily;
978 }
979
980 /**
981 * Set the fixed font family name.
982 * @param font A font family name.
983 */
984 public synchronized void setFixedFontFamily(String font) {
985 if (font != null && !font.equals(mFixedFontFamily)) {
986 mFixedFontFamily = font;
987 postSync();
988 }
989 }
990
991 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100992 * Get the fixed font family name. The default is "monospace".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700993 * @return The fixed font family name as a string.
994 */
995 public synchronized String getFixedFontFamily() {
996 return mFixedFontFamily;
997 }
998
999 /**
1000 * Set the sans-serif font family name.
1001 * @param font A font family name.
1002 */
1003 public synchronized void setSansSerifFontFamily(String font) {
1004 if (font != null && !font.equals(mSansSerifFontFamily)) {
1005 mSansSerifFontFamily = font;
1006 postSync();
1007 }
1008 }
1009
1010 /**
1011 * Get the sans-serif font family name.
1012 * @return The sans-serif font family name as a string.
1013 */
1014 public synchronized String getSansSerifFontFamily() {
1015 return mSansSerifFontFamily;
1016 }
1017
1018 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001019 * Set the serif font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001020 * @param font A font family name.
1021 */
1022 public synchronized void setSerifFontFamily(String font) {
1023 if (font != null && !font.equals(mSerifFontFamily)) {
1024 mSerifFontFamily = font;
1025 postSync();
1026 }
1027 }
1028
1029 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001030 * Get the serif font family name. The default is "serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001031 * @return The serif font family name as a string.
1032 */
1033 public synchronized String getSerifFontFamily() {
1034 return mSerifFontFamily;
1035 }
1036
1037 /**
1038 * Set the cursive font family name.
1039 * @param font A font family name.
1040 */
1041 public synchronized void setCursiveFontFamily(String font) {
1042 if (font != null && !font.equals(mCursiveFontFamily)) {
1043 mCursiveFontFamily = font;
1044 postSync();
1045 }
1046 }
1047
1048 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001049 * Get the cursive font family name. The default is "cursive".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001050 * @return The cursive font family name as a string.
1051 */
1052 public synchronized String getCursiveFontFamily() {
1053 return mCursiveFontFamily;
1054 }
1055
1056 /**
1057 * Set the fantasy font family name.
1058 * @param font A font family name.
1059 */
1060 public synchronized void setFantasyFontFamily(String font) {
1061 if (font != null && !font.equals(mFantasyFontFamily)) {
1062 mFantasyFontFamily = font;
1063 postSync();
1064 }
1065 }
1066
1067 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001068 * Get the fantasy font family name. The default is "fantasy".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001069 * @return The fantasy font family name as a string.
1070 */
1071 public synchronized String getFantasyFontFamily() {
1072 return mFantasyFontFamily;
1073 }
1074
1075 /**
1076 * Set the minimum font size.
1077 * @param size A non-negative integer between 1 and 72.
1078 * Any number outside the specified range will be pinned.
1079 */
1080 public synchronized void setMinimumFontSize(int size) {
1081 size = pin(size);
1082 if (mMinimumFontSize != size) {
1083 mMinimumFontSize = size;
1084 postSync();
1085 }
1086 }
1087
1088 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001089 * Get the minimum font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001090 * @return A non-negative integer between 1 and 72.
1091 */
1092 public synchronized int getMinimumFontSize() {
1093 return mMinimumFontSize;
1094 }
1095
1096 /**
1097 * Set the minimum logical font size.
1098 * @param size A non-negative integer between 1 and 72.
1099 * Any number outside the specified range will be pinned.
1100 */
1101 public synchronized void setMinimumLogicalFontSize(int size) {
1102 size = pin(size);
1103 if (mMinimumLogicalFontSize != size) {
1104 mMinimumLogicalFontSize = size;
1105 postSync();
1106 }
1107 }
1108
1109 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001110 * Get the minimum logical font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001111 * @return A non-negative integer between 1 and 72.
1112 */
1113 public synchronized int getMinimumLogicalFontSize() {
1114 return mMinimumLogicalFontSize;
1115 }
1116
1117 /**
1118 * Set the default font size.
1119 * @param size A non-negative integer between 1 and 72.
1120 * Any number outside the specified range will be pinned.
1121 */
1122 public synchronized void setDefaultFontSize(int size) {
1123 size = pin(size);
1124 if (mDefaultFontSize != size) {
1125 mDefaultFontSize = size;
1126 postSync();
1127 }
1128 }
1129
1130 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001131 * Get the default font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001132 * @return A non-negative integer between 1 and 72.
1133 */
1134 public synchronized int getDefaultFontSize() {
1135 return mDefaultFontSize;
1136 }
1137
1138 /**
1139 * Set the default fixed font size.
1140 * @param size A non-negative integer between 1 and 72.
1141 * Any number outside the specified range will be pinned.
1142 */
1143 public synchronized void setDefaultFixedFontSize(int size) {
1144 size = pin(size);
1145 if (mDefaultFixedFontSize != size) {
1146 mDefaultFixedFontSize = size;
1147 postSync();
1148 }
1149 }
1150
1151 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001152 * Get the default fixed font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001153 * @return A non-negative integer between 1 and 72.
1154 */
1155 public synchronized int getDefaultFixedFontSize() {
1156 return mDefaultFixedFontSize;
1157 }
1158
1159 /**
Grace Kloba097b1e772009-11-24 14:23:18 -08001160 * Set the number of pages cached by the WebKit for the history navigation.
1161 * @param size A non-negative integer between 0 (no cache) and 20 (max).
1162 * @hide
1163 */
1164 public synchronized void setPageCacheCapacity(int size) {
1165 if (size < 0) size = 0;
1166 if (size > 20) size = 20;
1167 if (mPageCacheCapacity != size) {
1168 mPageCacheCapacity = size;
1169 postSync();
1170 }
1171 }
1172
1173 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001174 * Tell the WebView to load image resources automatically.
1175 * @param flag True if the WebView should load images automatically.
1176 */
1177 public synchronized void setLoadsImagesAutomatically(boolean flag) {
1178 if (mLoadsImagesAutomatically != flag) {
1179 mLoadsImagesAutomatically = flag;
1180 postSync();
1181 }
1182 }
1183
1184 /**
1185 * Return true if the WebView will load image resources automatically.
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001186 * The default is true.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001187 * @return True if the WebView loads images automatically.
1188 */
1189 public synchronized boolean getLoadsImagesAutomatically() {
1190 return mLoadsImagesAutomatically;
1191 }
1192
1193 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001194 * Tell the WebView to block network images. This is only checked when
1195 * {@link #getLoadsImagesAutomatically} is true. If you set the value to
1196 * false, images will automatically be loaded. Use this api to reduce
1197 * bandwidth only. Use {@link #setBlockNetworkLoads} if possible.
1198 * @param flag True if the WebView should block network images.
1199 * @see #setBlockNetworkLoads
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001200 */
1201 public synchronized void setBlockNetworkImage(boolean flag) {
1202 if (mBlockNetworkImage != flag) {
1203 mBlockNetworkImage = flag;
1204 postSync();
1205 }
1206 }
1207
1208 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001209 * Return true if the WebView will block network images. The default is
1210 * false.
1211 * @return True if the WebView blocks network images.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001212 */
1213 public synchronized boolean getBlockNetworkImage() {
1214 return mBlockNetworkImage;
1215 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001216
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001217 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001218 * Tell the WebView to block all network load requests. If you set the
1219 * value to false, you must call {@link android.webkit.WebView#reload} to
1220 * fetch remote resources. This flag supercedes the value passed to
1221 * {@link #setBlockNetworkImage}.
1222 * @param flag True if the WebView should block all network loads.
1223 * @see android.webkit.WebView#reload
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001224 */
1225 public synchronized void setBlockNetworkLoads(boolean flag) {
1226 if (mBlockNetworkLoads != flag) {
1227 mBlockNetworkLoads = flag;
1228 verifyNetworkAccess();
Patrick Scott4243a3a2010-10-05 09:30:24 -04001229 postSync();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001230 }
1231 }
1232
1233 /**
Patrick Scottf43113f2010-02-18 09:13:12 -05001234 * Return true if the WebView will block all network loads. The default is
1235 * false.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001236 * @return True if the WebView blocks all network loads.
1237 */
1238 public synchronized boolean getBlockNetworkLoads() {
1239 return mBlockNetworkLoads;
1240 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001241
1242
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001243 private void verifyNetworkAccess() {
1244 if (!mBlockNetworkLoads) {
Michael Kolba172e7d2010-06-30 12:35:26 -07001245 if (mContext.checkPermission("android.permission.INTERNET",
1246 android.os.Process.myPid(), android.os.Process.myUid()) !=
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001247 PackageManager.PERMISSION_GRANTED) {
1248 throw new SecurityException
1249 ("Permission denied - " +
1250 "application missing INTERNET permission");
1251 }
1252 }
1253 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001254
1255 /**
1256 * Tell the WebView to enable javascript execution.
1257 * @param flag True if the WebView should execute javascript.
1258 */
1259 public synchronized void setJavaScriptEnabled(boolean flag) {
1260 if (mJavaScriptEnabled != flag) {
1261 mJavaScriptEnabled = flag;
1262 postSync();
1263 }
1264 }
1265
1266 /**
Derek Sollenberger1d335f32011-07-08 11:28:23 -04001267 * Tell the WebView to use Skia's hardware accelerated rendering path
1268 * @param flag True if the WebView should use Skia's hw-accel path
1269 * @hide
1270 */
1271 public synchronized void setHardwareAccelSkiaEnabled(boolean flag) {
1272 if (mHardwareAccelSkia != flag) {
1273 mHardwareAccelSkia = flag;
1274 postSync();
1275 }
1276 }
1277
1278 /**
1279 * @return True if the WebView is using hardware accelerated skia
1280 * @hide
1281 */
1282 public synchronized boolean getHardwareAccelSkiaEnabled() {
1283 return mHardwareAccelSkia;
1284 }
1285
1286 /**
Teng-Hui Zhuda7378e2011-02-16 11:25:03 -08001287 * Tell the WebView to show the visual indicator
1288 * @param flag True if the WebView should show the visual indicator
1289 * @hide
1290 */
1291 public synchronized void setShowVisualIndicator(boolean flag) {
1292 if (mShowVisualIndicator != flag) {
1293 mShowVisualIndicator = flag;
1294 postSync();
1295 }
1296 }
1297
1298 /**
1299 * @return True if the WebView is showing the visual indicator
1300 * @hide
1301 */
1302 public synchronized boolean getShowVisualIndicator() {
1303 return mShowVisualIndicator;
1304 }
1305
1306 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001307 * Tell the WebView to enable plugins.
1308 * @param flag True if the WebView should load plugins.
Patrick Scott300f2e92010-03-22 10:20:45 -04001309 * @deprecated This method has been deprecated in favor of
1310 * {@link #setPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001311 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001312 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001313 public synchronized void setPluginsEnabled(boolean flag) {
Tero Saarni29086e42011-06-02 21:05:38 +03001314 setPluginState(flag ? PluginState.ON : PluginState.OFF);
Patrick Scott300f2e92010-03-22 10:20:45 -04001315 }
1316
1317 /**
1318 * Tell the WebView to enable, disable, or have plugins on demand. On
1319 * demand mode means that if a plugin exists that can handle the embedded
1320 * content, a placeholder icon will be shown instead of the plugin. When
1321 * the placeholder is clicked, the plugin will be enabled.
1322 * @param state One of the PluginState values.
1323 */
1324 public synchronized void setPluginState(PluginState state) {
1325 if (mPluginState != state) {
1326 mPluginState = state;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001327 postSync();
1328 }
1329 }
1330
1331 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001332 * Set a custom path to plugins used by the WebView. This method is
1333 * obsolete since each plugin is now loaded from its own package.
1334 * @param pluginsPath String path to the directory containing plugins.
1335 * @deprecated This method is no longer used as plugins are loaded from
1336 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001337 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001338 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001339 public synchronized void setPluginsPath(String pluginsPath) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001340 }
1341
1342 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001343 * Set the path to where database storage API databases should be saved.
Ben Murdoch18773af2010-02-25 18:41:56 +00001344 * Nota that the WebCore Database Tracker only allows the path to be set once.
Ben Murdoch7df19852009-04-22 13:07:58 +01001345 * This will update WebCore when the Sync runs in the C++ side.
1346 * @param databasePath String path to the directory where databases should
1347 * be saved. May be the empty string but should never be null.
1348 */
1349 public synchronized void setDatabasePath(String databasePath) {
Ben Murdoch18773af2010-02-25 18:41:56 +00001350 if (databasePath != null && !mDatabasePathHasBeenSet) {
Ben Murdoch7df19852009-04-22 13:07:58 +01001351 mDatabasePath = databasePath;
Ben Murdoch18773af2010-02-25 18:41:56 +00001352 mDatabasePathHasBeenSet = true;
Ben Murdoch7df19852009-04-22 13:07:58 +01001353 postSync();
1354 }
1355 }
1356
1357 /**
Steve Block9d3273f2009-08-21 13:16:27 +01001358 * Set the path where the Geolocation permissions database should be saved.
1359 * This will update WebCore when the Sync runs in the C++ side.
1360 * @param databasePath String path to the directory where the Geolocation
1361 * permissions database should be saved. May be the empty string but
1362 * should never be null.
Steve Block9d3273f2009-08-21 13:16:27 +01001363 */
1364 public synchronized void setGeolocationDatabasePath(String databasePath) {
Grace Kloba8f5e4052009-10-06 12:56:07 -07001365 if (databasePath != null
1366 && !databasePath.equals(mGeolocationDatabasePath)) {
Steve Block9d3273f2009-08-21 13:16:27 +01001367 mGeolocationDatabasePath = databasePath;
1368 postSync();
1369 }
1370 }
1371
1372 /**
Steve Block92f30c32011-12-15 15:16:19 +00001373 * Enable or disable the Application Cache API.
1374 * @param flag Whether to enable the Application Cache API.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001375 */
1376 public synchronized void setAppCacheEnabled(boolean flag) {
1377 if (mAppCacheEnabled != flag) {
1378 mAppCacheEnabled = flag;
1379 postSync();
1380 }
1381 }
1382
1383 /**
Steve Block92f30c32011-12-15 15:16:19 +00001384 * Set the path used by the Application Cache API to store files. This
1385 * setting is applied to all WebViews in the application. In order for the
1386 * Application Cache API to function, this method must be called with a
1387 * path which exists and is writable by the application. This method may
1388 * only be called once: repeated calls are ignored.
1389 * @param path Path to the directory that should be used to store Application
1390 * Cache files.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001391 */
Steve Block92f30c32011-12-15 15:16:19 +00001392 public synchronized void setAppCachePath(String path) {
1393 // We test for a valid path and for repeated setting on the native
1394 // side, but we can avoid syncing in some simple cases.
1395 if (mAppCachePath == null && path != null && !path.isEmpty()) {
1396 mAppCachePath = path;
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001397 postSync();
1398 }
1399 }
1400
1401 /**
Andrei Popescu1c829202009-07-22 16:47:52 +01001402 * Set the maximum size for the Application Caches content.
1403 * @param appCacheMaxSize the maximum size in bytes.
Andrei Popescu1c829202009-07-22 16:47:52 +01001404 */
1405 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) {
1406 if (appCacheMaxSize != mAppCacheMaxSize) {
1407 mAppCacheMaxSize = appCacheMaxSize;
1408 postSync();
1409 }
1410 }
1411
1412 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001413 * Set whether the database storage API is enabled.
1414 * @param flag boolean True if the WebView should use the database storage
1415 * API.
1416 */
1417 public synchronized void setDatabaseEnabled(boolean flag) {
1418 if (mDatabaseEnabled != flag) {
1419 mDatabaseEnabled = flag;
1420 postSync();
1421 }
1422 }
1423
1424 /**
Ben Murdoch274680d2009-05-28 13:44:44 +01001425 * Set whether the DOM storage API is enabled.
1426 * @param flag boolean True if the WebView should use the DOM storage
1427 * API.
Ben Murdoch274680d2009-05-28 13:44:44 +01001428 */
1429 public synchronized void setDomStorageEnabled(boolean flag) {
1430 if (mDomStorageEnabled != flag) {
1431 mDomStorageEnabled = flag;
1432 postSync();
1433 }
1434 }
1435
1436 /**
1437 * Returns true if the DOM Storage API's are enabled.
1438 * @return True if the DOM Storage API's are enabled.
Ben Murdoch274680d2009-05-28 13:44:44 +01001439 */
1440 public synchronized boolean getDomStorageEnabled() {
1441 return mDomStorageEnabled;
1442 }
1443
1444 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001445 * Return the path to where database storage API databases are saved for
1446 * the current WebView.
1447 * @return the String path to the database storage API databases.
1448 */
1449 public synchronized String getDatabasePath() {
1450 return mDatabasePath;
1451 }
1452
1453 /**
1454 * Returns true if database storage API is enabled.
1455 * @return True if the database storage API is enabled.
1456 */
1457 public synchronized boolean getDatabaseEnabled() {
1458 return mDatabaseEnabled;
1459 }
1460
1461 /**
Andrei Popescuc27a9ac2009-08-03 15:59:24 +01001462 * Tell the WebView to enable WebWorkers API.
1463 * @param flag True if the WebView should enable WebWorkers.
1464 * Note that this flag only affects V8. JSC does not have
1465 * an equivalent setting.
Jonathan Dixon4cde13a2011-12-16 18:36:20 +00001466 * @hide
Andrei Popescuc27a9ac2009-08-03 15:59:24 +01001467 */
1468 public synchronized void setWorkersEnabled(boolean flag) {
1469 if (mWorkersEnabled != flag) {
1470 mWorkersEnabled = flag;
1471 postSync();
1472 }
1473 }
1474
1475 /**
Steve Block06cd7512009-08-21 10:26:37 +01001476 * Sets whether Geolocation is enabled.
1477 * @param flag Whether Geolocation should be enabled.
Steve Block06cd7512009-08-21 10:26:37 +01001478 */
1479 public synchronized void setGeolocationEnabled(boolean flag) {
1480 if (mGeolocationEnabled != flag) {
1481 mGeolocationEnabled = flag;
1482 postSync();
1483 }
1484 }
1485
1486 /**
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001487 * Sets whether XSS Auditor is enabled.
1488 * @param flag Whether XSS Auditor should be enabled.
Elliott Slaughterbe1304f2010-06-23 11:29:02 -07001489 * @hide Only used by LayoutTestController.
Elliott Slaughter5dc0c822010-06-22 11:31:54 -07001490 */
1491 public synchronized void setXSSAuditorEnabled(boolean flag) {
1492 if (mXSSAuditorEnabled != flag) {
1493 mXSSAuditorEnabled = flag;
1494 postSync();
1495 }
1496 }
1497
1498 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001499 * Return true if javascript is enabled. <b>Note: The default is false.</b>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001500 * @return True if javascript is enabled.
1501 */
1502 public synchronized boolean getJavaScriptEnabled() {
1503 return mJavaScriptEnabled;
1504 }
1505
1506 /**
1507 * Return true if plugins are enabled.
1508 * @return True if plugins are enabled.
Patrick Scott300f2e92010-03-22 10:20:45 -04001509 * @deprecated This method has been replaced by {@link #getPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001510 */
Michael Kolba172e7d2010-06-30 12:35:26 -07001511 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001512 public synchronized boolean getPluginsEnabled() {
Patrick Scott300f2e92010-03-22 10:20:45 -04001513 return mPluginState == PluginState.ON;
1514 }
1515
1516 /**
1517 * Return the current plugin state.
1518 * @return A value corresponding to the enum PluginState.
1519 */
1520 public synchronized PluginState getPluginState() {
1521 return mPluginState;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001522 }
1523
1524 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001525 * Returns the directory that contains the plugin libraries. This method is
1526 * obsolete since each plugin is now loaded from its own package.
1527 * @return An empty string.
1528 * @deprecated This method is no longer used as plugins are loaded from
1529 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001530 */
Jason Chen9dc2e752010-09-01 19:11:14 -07001531 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001532 public synchronized String getPluginsPath() {
Grace Kloba658ab7d2009-05-14 14:45:26 -07001533 return "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001534 }
1535
1536 /**
1537 * Tell javascript to open windows automatically. This applies to the
1538 * javascript function window.open().
1539 * @param flag True if javascript can open windows automatically.
1540 */
1541 public synchronized void setJavaScriptCanOpenWindowsAutomatically(
1542 boolean flag) {
1543 if (mJavaScriptCanOpenWindowsAutomatically != flag) {
1544 mJavaScriptCanOpenWindowsAutomatically = flag;
1545 postSync();
1546 }
1547 }
1548
1549 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001550 * Return true if javascript can open windows automatically. The default
1551 * is false.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001552 * @return True if javascript can open windows automatically during
1553 * window.open().
1554 */
1555 public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() {
1556 return mJavaScriptCanOpenWindowsAutomatically;
1557 }
1558
1559 /**
1560 * Set the default text encoding name to use when decoding html pages.
1561 * @param encoding The text encoding name.
1562 */
1563 public synchronized void setDefaultTextEncodingName(String encoding) {
1564 if (encoding != null && !encoding.equals(mDefaultTextEncoding)) {
1565 mDefaultTextEncoding = encoding;
1566 postSync();
1567 }
1568 }
1569
1570 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001571 * Get the default text encoding name. The default is "Latin-1".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001572 * @return The default text encoding name as a string.
1573 */
1574 public synchronized String getDefaultTextEncodingName() {
1575 return mDefaultTextEncoding;
1576 }
1577
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001578 /**
1579 * Set the WebView's user-agent string. If the string "ua" is null or empty,
1580 * it will use the system default user-agent string.
1581 */
1582 public synchronized void setUserAgentString(String ua) {
1583 if (ua == null || ua.length() == 0) {
1584 synchronized(sLockForLocaleSettings) {
Michael Kolba172e7d2010-06-30 12:35:26 -07001585 Locale currentLocale = Locale.getDefault();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001586 if (!sLocale.equals(currentLocale)) {
1587 sLocale = currentLocale;
1588 mAcceptLanguage = getCurrentAcceptLanguage();
1589 }
1590 }
1591 ua = getCurrentUserAgent();
1592 mUseDefaultUserAgent = true;
1593 } else {
1594 mUseDefaultUserAgent = false;
1595 }
1596
1597 if (!ua.equals(mUserAgent)) {
1598 mUserAgent = ua;
1599 postSync();
1600 }
1601 }
1602
1603 /**
1604 * Return the WebView's user-agent string.
1605 */
1606 public synchronized String getUserAgentString() {
1607 if (DESKTOP_USERAGENT.equals(mUserAgent) ||
1608 IPHONE_USERAGENT.equals(mUserAgent) ||
1609 !mUseDefaultUserAgent) {
1610 return mUserAgent;
1611 }
1612
1613 boolean doPostSync = false;
1614 synchronized(sLockForLocaleSettings) {
1615 Locale currentLocale = Locale.getDefault();
1616 if (!sLocale.equals(currentLocale)) {
1617 sLocale = currentLocale;
1618 mUserAgent = getCurrentUserAgent();
1619 mAcceptLanguage = getCurrentAcceptLanguage();
1620 doPostSync = true;
1621 }
1622 }
1623 if (doPostSync) {
1624 postSync();
1625 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001626 return mUserAgent;
1627 }
1628
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001629 /* package api to grab the Accept Language string. */
1630 /*package*/ synchronized String getAcceptLanguage() {
1631 synchronized(sLockForLocaleSettings) {
1632 Locale currentLocale = Locale.getDefault();
1633 if (!sLocale.equals(currentLocale)) {
1634 sLocale = currentLocale;
1635 mAcceptLanguage = getCurrentAcceptLanguage();
1636 }
1637 }
1638 return mAcceptLanguage;
1639 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001640
Shimeng (Simon) Wangc55886a2010-10-28 13:46:02 -07001641 /* package */ boolean isNarrowColumnLayout() {
1642 return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS;
1643 }
1644
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001645 /**
1646 * Tell the WebView whether it needs to set a node to have focus when
1647 * {@link WebView#requestFocus(int, android.graphics.Rect)} is called.
Michael Kolba172e7d2010-06-30 12:35:26 -07001648 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001649 * @param flag
1650 */
1651 public void setNeedInitialFocus(boolean flag) {
1652 if (mNeedInitialFocus != flag) {
1653 mNeedInitialFocus = flag;
1654 }
1655 }
1656
1657 /* Package api to get the choice whether it needs to set initial focus. */
1658 /* package */ boolean getNeedInitialFocus() {
1659 return mNeedInitialFocus;
1660 }
1661
1662 /**
1663 * Set the priority of the Render thread. Unlike the other settings, this
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001664 * one only needs to be called once per process. The default is NORMAL.
1665 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001666 * @param priority RenderPriority, can be normal, high or low.
1667 */
1668 public synchronized void setRenderPriority(RenderPriority priority) {
1669 if (mRenderPriority != priority) {
1670 mRenderPriority = priority;
1671 mEventHandler.sendMessage(Message.obtain(null,
1672 EventHandler.PRIORITY));
1673 }
1674 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001675
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001676 /**
1677 * Override the way the cache is used. The way the cache is used is based
1678 * on the navigation option. For a normal page load, the cache is checked
1679 * and content is re-validated as needed. When navigating back, content is
1680 * not revalidated, instead the content is just pulled from the cache.
1681 * This function allows the client to override this behavior.
1682 * @param mode One of the LOAD_ values.
1683 */
1684 public void setCacheMode(int mode) {
1685 if (mode != mOverrideCacheMode) {
1686 mOverrideCacheMode = mode;
Kristian Monsenc40fc872011-01-19 15:44:04 +00001687 postSync();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001688 }
1689 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001690
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001691 /**
1692 * Return the current setting for overriding the cache mode. For a full
1693 * description, see the {@link #setCacheMode(int)} function.
1694 */
1695 public int getCacheMode() {
1696 return mOverrideCacheMode;
1697 }
Michael Kolba172e7d2010-06-30 12:35:26 -07001698
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001699 /**
1700 * If set, webkit alternately shrinks and expands images viewed outside
1701 * of an HTML page to fit the screen. This conflicts with attempts by
1702 * the UI to zoom in and out of an image, so it is set false by default.
1703 * @param shrink Set true to let webkit shrink the standalone image to fit.
1704 * {@hide}
1705 */
1706 public void setShrinksStandaloneImagesToFit(boolean shrink) {
1707 if (mShrinksStandaloneImagesToFit != shrink) {
1708 mShrinksStandaloneImagesToFit = shrink;
1709 postSync();
1710 }
1711 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001712
Cary Clarkf0785a62010-06-25 11:45:40 -04001713 /**
1714 * Specify the maximum decoded image size. The default is
1715 * 2 megs for small memory devices and 8 megs for large memory devices.
1716 * @param size The maximum decoded size, or zero to set to the default.
Jonathan Dixon4cde13a2011-12-16 18:36:20 +00001717 * @hide
Cary Clarkf0785a62010-06-25 11:45:40 -04001718 */
1719 public void setMaximumDecodedImageSize(long size) {
1720 if (mMaximumDecodedImageSize != size) {
1721 mMaximumDecodedImageSize = size;
1722 postSync();
1723 }
1724 }
1725
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001726 /**
Shimeng (Simon) Wang99415602011-05-24 13:40:08 -07001727 * Returns whether to use fixed viewport. Use fixed viewport
1728 * whenever wide viewport is on.
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001729 */
1730 /* package */ boolean getUseFixedViewport() {
Shimeng (Simon) Wang99415602011-05-24 13:40:08 -07001731 return getUseWideViewPort();
Shimeng (Simon) Wangc1cba782010-08-17 10:53:59 -07001732 }
1733
1734 /**
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001735 * Returns whether private browsing is enabled.
1736 */
1737 /* package */ boolean isPrivateBrowsingEnabled() {
1738 return mPrivateBrowsingEnabled;
1739 }
1740
1741 /**
1742 * Sets whether private browsing is enabled.
1743 * @param flag Whether private browsing should be enabled.
1744 */
1745 /* package */ synchronized void setPrivateBrowsingEnabled(boolean flag) {
1746 if (mPrivateBrowsingEnabled != flag) {
1747 mPrivateBrowsingEnabled = flag;
Ben Murdoch4bd87d62011-01-18 14:10:48 +00001748
1749 // AutoFill is dependant on private browsing being enabled so
1750 // reset it to take account of the new value of mPrivateBrowsingEnabled.
1751 setAutoFillEnabled(mAutoFillEnabled);
1752
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001753 postSync();
1754 }
1755 }
1756
John Reck7818aaa2011-04-26 16:57:46 -07001757 /**
1758 * Returns whether the viewport metatag can disable zooming
1759 * @hide
1760 */
1761 public boolean forceUserScalable() {
1762 return mForceUserScalable;
1763 }
1764
1765 /**
1766 * Sets whether viewport metatag can disable zooming.
1767 * @param flag Whether or not to forceably enable user scalable.
1768 * @hide
1769 */
1770 public synchronized void setForceUserScalable(boolean flag) {
1771 mForceUserScalable = flag;
1772 }
1773
Cary Clark6c43d522010-08-31 15:41:54 -04001774 synchronized void setSyntheticLinksEnabled(boolean flag) {
1775 if (mSyntheticLinksEnabled != flag) {
1776 mSyntheticLinksEnabled = flag;
1777 postSync();
1778 }
1779 }
1780
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001781 /**
1782 * @hide
1783 */
1784 public synchronized void setAutoFillEnabled(boolean enabled) {
Ben Murdoch4bd87d62011-01-18 14:10:48 +00001785 // AutoFill is always disabled in private browsing mode.
1786 boolean autoFillEnabled = enabled && !mPrivateBrowsingEnabled;
1787 if (mAutoFillEnabled != autoFillEnabled) {
1788 mAutoFillEnabled = autoFillEnabled;
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001789 postSync();
1790 }
1791 }
1792
1793 /**
1794 * @hide
1795 */
1796 public synchronized boolean getAutoFillEnabled() {
1797 return mAutoFillEnabled;
1798 }
1799
1800 /**
1801 * @hide
1802 */
1803 public synchronized void setAutoFillProfile(AutoFillProfile profile) {
Ben Murdochb1b82a82010-10-20 14:18:25 +01001804 if (mAutoFillProfile != profile) {
1805 mAutoFillProfile = profile;
1806 postSync();
1807 }
Ben Murdoche9e3ccd2010-10-06 14:33:02 +01001808 }
1809
Ben Murdoch57914382010-11-16 11:50:39 +00001810 /**
1811 * @hide
1812 */
1813 public synchronized AutoFillProfile getAutoFillProfile() {
1814 return mAutoFillProfile;
1815 }
1816
Grace Klobaf8d8b462009-09-20 15:57:49 -07001817 int getDoubleTapToastCount() {
1818 return mDoubleTapToastCount;
1819 }
1820
1821 void setDoubleTapToastCount(int count) {
1822 if (mDoubleTapToastCount != count) {
1823 mDoubleTapToastCount = count;
1824 // write the settings in the non-UI thread
1825 mEventHandler.sendMessage(Message.obtain(null,
1826 EventHandler.SET_DOUBLE_TAP_TOAST_COUNT));
1827 }
1828 }
1829
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001830 /**
John Reck637758942011-07-15 11:14:43 -07001831 * @hide
1832 */
1833 public void setProperty(String key, String value) {
Nicolas Roard872cf222011-08-18 11:53:04 -07001834 if (mWebView.nativeSetProperty(key, value)) {
1835 mWebView.contentInvalidateAll();
1836 }
John Reck637758942011-07-15 11:14:43 -07001837 }
1838
1839 /**
1840 * @hide
1841 */
1842 public String getProperty(String key) {
1843 return mWebView.nativeGetProperty(key);
1844 }
1845
1846 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001847 * Transfer messages from the queue to the new WebCoreThread. Called from
1848 * WebCore thread.
1849 */
1850 /*package*/
1851 synchronized void syncSettingsAndCreateHandler(BrowserFrame frame) {
1852 mBrowserFrame = frame;
Derek Sollenberger2e5c1502009-06-03 10:44:42 -04001853 if (DebugFlags.WEB_SETTINGS) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001854 junit.framework.Assert.assertTrue(frame.mNativeFrame != 0);
1855 }
Andrei Popescudee76be2009-09-22 18:28:21 +01001856
Grace Klobaf8d8b462009-09-20 15:57:49 -07001857 SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
1858 Context.MODE_PRIVATE);
Grace Kloba24a3ff92009-09-22 10:42:22 -07001859 if (mDoubleTapToastCount > 0) {
1860 mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
1861 mDoubleTapToastCount);
1862 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001863 nativeSync(frame.mNativeFrame);
1864 mSyncPending = false;
1865 mEventHandler.createHandler();
1866 }
1867
Andrei Popescudee76be2009-09-22 18:28:21 +01001868 /**
1869 * Let the Settings object know that our owner is being destroyed.
1870 */
1871 /*package*/
1872 synchronized void onDestroyed() {
Andrei Popescudee76be2009-09-22 18:28:21 +01001873 }
1874
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001875 private int pin(int size) {
1876 // FIXME: 72 is just an arbitrary max text size value.
1877 if (size < 1) {
1878 return 1;
1879 } else if (size > 72) {
1880 return 72;
1881 }
1882 return size;
1883 }
1884
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001885 /* Post a SYNC message to handle syncing the native settings. */
1886 private synchronized void postSync() {
1887 // Only post if a sync is not pending
1888 if (!mSyncPending) {
1889 mSyncPending = mEventHandler.sendMessage(
1890 Message.obtain(null, EventHandler.SYNC));
1891 }
1892 }
1893
1894 // Synchronize the native and java settings.
1895 private native void nativeSync(int nativeFrame);
1896}