blob: da0c61b2dc5118769c276d8911cb837c8e12da1f [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;
Dan Egnor18e93962010-02-10 19:27:58 -080025import android.util.EventLog;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -080026import java.lang.SecurityException;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070027import java.util.Locale;
28
29/**
30 * Manages settings state for a WebView. When a WebView is first created, it
31 * obtains a set of default settings. These default settings will be returned
32 * from any getter call. A WebSettings object obtained from
33 * WebView.getSettings() is tied to the life of the WebView. If a WebView has
34 * been destroyed, any method call on WebSettings will throw an
35 * IllegalStateException.
36 */
37public class WebSettings {
38 /**
39 * Enum for controlling the layout of html.
40 * NORMAL means no rendering changes.
41 * SINGLE_COLUMN moves all content into one column that is the width of the
42 * view.
43 * NARROW_COLUMNS makes all columns no wider than the screen if possible.
44 */
45 // XXX: These must match LayoutAlgorithm in Settings.h in WebCore.
46 public enum LayoutAlgorithm {
47 NORMAL,
48 SINGLE_COLUMN,
49 NARROW_COLUMNS
50 }
51
52 /**
53 * Enum for specifying the text size.
54 * SMALLEST is 50%
55 * SMALLER is 75%
56 * NORMAL is 100%
57 * LARGER is 150%
58 * LARGEST is 200%
59 */
60 public enum TextSize {
61 SMALLEST(50),
62 SMALLER(75),
63 NORMAL(100),
64 LARGER(150),
65 LARGEST(200);
66 TextSize(int size) {
67 value = size;
68 }
69 int value;
70 }
Grace Kloba0d8b77c2009-06-25 11:20:51 -070071
72 /**
73 * Enum for specifying the WebView's desired density.
74 * FAR makes 100% looking like in 240dpi
75 * MEDIUM makes 100% looking like in 160dpi
76 * CLOSE makes 100% looking like in 120dpi
Grace Kloba0d8b77c2009-06-25 11:20:51 -070077 */
78 public enum ZoomDensity {
79 FAR(150), // 240dpi
80 MEDIUM(100), // 160dpi
81 CLOSE(75); // 120dpi
82 ZoomDensity(int size) {
83 value = size;
84 }
85 int value;
86 }
87
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070088 /**
89 * Default cache usage pattern Use with {@link #setCacheMode}.
90 */
91 public static final int LOAD_DEFAULT = -1;
92
93 /**
94 * Normal cache usage pattern Use with {@link #setCacheMode}.
95 */
96 public static final int LOAD_NORMAL = 0;
97
98 /**
99 * Use cache if content is there, even if expired (eg, history nav)
100 * If it is not in the cache, load from network.
101 * Use with {@link #setCacheMode}.
102 */
103 public static final int LOAD_CACHE_ELSE_NETWORK = 1;
104
105 /**
106 * Don't use the cache, load from network
107 * Use with {@link #setCacheMode}.
108 */
109 public static final int LOAD_NO_CACHE = 2;
110
111 /**
112 * Don't use the network, load from cache only.
113 * Use with {@link #setCacheMode}.
114 */
115 public static final int LOAD_CACHE_ONLY = 3;
116
117 public enum RenderPriority {
118 NORMAL,
119 HIGH,
120 LOW
121 }
122
Patrick Scott300f2e92010-03-22 10:20:45 -0400123 /**
124 * The plugin state effects how plugins are treated on a page. ON means
125 * that any object will be loaded even if a plugin does not exist to handle
126 * the content. ON_DEMAND means that if there is a plugin installed that
127 * can handle the content, a placeholder is shown until the user clicks on
128 * the placeholder. Once clicked, the plugin will be enabled on the page.
129 * OFF means that all plugins will be turned off and any fallback content
130 * will be used.
131 */
132 public enum PluginState {
133 ON,
134 ON_DEMAND,
135 OFF
136 }
137
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700138 // WebView associated with this WebSettings.
139 private WebView mWebView;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700140 // BrowserFrame used to access the native frame pointer.
141 private BrowserFrame mBrowserFrame;
142 // Flag to prevent multiple SYNC messages at one time.
143 private boolean mSyncPending = false;
144 // Custom handler that queues messages until the WebCore thread is active.
145 private final EventHandler mEventHandler;
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100146
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700147 // Private settings so we don't have to go into native code to
148 // retrieve the values. After setXXX, postSync() needs to be called.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100149 //
150 // The default values need to match those in WebSettings.cpp
151 // If the defaults change, please also update the JavaDocs so developers
152 // know what they are.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700153 private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800154 private Context mContext;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700155 private TextSize mTextSize = TextSize.NORMAL;
156 private String mStandardFontFamily = "sans-serif";
157 private String mFixedFontFamily = "monospace";
158 private String mSansSerifFontFamily = "sans-serif";
159 private String mSerifFontFamily = "serif";
160 private String mCursiveFontFamily = "cursive";
161 private String mFantasyFontFamily = "fantasy";
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900162 private String mDefaultTextEncoding;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800163 private String mUserAgent;
164 private boolean mUseDefaultUserAgent;
165 private String mAcceptLanguage;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700166 private int mMinimumFontSize = 8;
167 private int mMinimumLogicalFontSize = 8;
168 private int mDefaultFontSize = 16;
169 private int mDefaultFixedFontSize = 13;
Grace Kloba097b1e772009-11-24 14:23:18 -0800170 private int mPageCacheCapacity = 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700171 private boolean mLoadsImagesAutomatically = true;
172 private boolean mBlockNetworkImage = false;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700173 private boolean mBlockNetworkLoads;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700174 private boolean mJavaScriptEnabled = false;
Patrick Scott300f2e92010-03-22 10:20:45 -0400175 private PluginState mPluginState = PluginState.OFF;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700176 private boolean mJavaScriptCanOpenWindowsAutomatically = false;
177 private boolean mUseDoubleTree = false;
178 private boolean mUseWideViewport = false;
179 private boolean mSupportMultipleWindows = false;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800180 private boolean mShrinksStandaloneImagesToFit = false;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100181 // HTML5 API flags
182 private boolean mAppCacheEnabled = false;
183 private boolean mDatabaseEnabled = false;
184 private boolean mDomStorageEnabled = false;
185 private boolean mWorkersEnabled = false; // only affects V8.
Steve Block09b0ca12009-08-26 18:16:58 +0100186 private boolean mGeolocationEnabled = true;
Andrei Popescuc27a9ac2009-08-03 15:59:24 +0100187 // HTML5 configuration parameters
188 private long mAppCacheMaxSize = Long.MAX_VALUE;
189 private String mAppCachePath = "";
190 private String mDatabasePath = "";
Ben Murdoch18773af2010-02-25 18:41:56 +0000191 // The WebCore DatabaseTracker only allows the database path to be set
192 // once. Keep track of when the path has been set.
193 private boolean mDatabasePathHasBeenSet = false;
Steve Block9d3273f2009-08-21 13:16:27 +0100194 private String mGeolocationDatabasePath = "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700195 // Don't need to synchronize the get/set methods as they
196 // are basic types, also none of these values are used in
197 // native WebCore code.
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700198 private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700199 private RenderPriority mRenderPriority = RenderPriority.NORMAL;
200 private int mOverrideCacheMode = LOAD_DEFAULT;
201 private boolean mSaveFormData = true;
202 private boolean mSavePassword = true;
203 private boolean mLightTouchEnabled = false;
204 private boolean mNeedInitialFocus = true;
205 private boolean mNavDump = false;
206 private boolean mSupportZoom = true;
The Android Open Source Project10592532009-03-18 17:39:46 -0700207 private boolean mBuiltInZoomControls = false;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800208 private boolean mAllowFileAccess = true;
Cary Clarkf8d49642009-09-08 13:23:24 -0400209 private boolean mLoadWithOverviewMode = false;
Adam Powell0a77ce22010-08-25 14:37:03 -0700210 private boolean mUseWebViewBackgroundOverscrollBackground = true;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700211
Grace Klobaf8d8b462009-09-20 15:57:49 -0700212 // private WebSettings, not accessible by the host activity
Grace Kloba24a3ff92009-09-22 10:42:22 -0700213 static private int mDoubleTapToastCount = 3;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700214
215 private static final String PREF_FILE = "WebViewSettings";
216 private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";
217
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700218 // Class to handle messages before WebCore is ready.
219 private class EventHandler {
220 // Message id for syncing
221 static final int SYNC = 0;
222 // Message id for setting priority
223 static final int PRIORITY = 1;
Grace Klobaf8d8b462009-09-20 15:57:49 -0700224 // Message id for writing double-tap toast count
225 static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700226 // Actual WebCore thread handler
227 private Handler mHandler;
228
229 private synchronized void createHandler() {
230 // as mRenderPriority can be set before thread is running, sync up
231 setRenderPriority();
232
233 // create a new handler
234 mHandler = new Handler() {
235 @Override
236 public void handleMessage(Message msg) {
237 switch (msg.what) {
238 case SYNC:
239 synchronized (WebSettings.this) {
240 if (mBrowserFrame.mNativeFrame != 0) {
241 nativeSync(mBrowserFrame.mNativeFrame);
242 }
243 mSyncPending = false;
244 }
245 break;
246
247 case PRIORITY: {
248 setRenderPriority();
249 break;
250 }
Grace Klobaf8d8b462009-09-20 15:57:49 -0700251
252 case SET_DOUBLE_TAP_TOAST_COUNT: {
253 SharedPreferences.Editor editor = mContext
254 .getSharedPreferences(PREF_FILE,
255 Context.MODE_PRIVATE).edit();
256 editor.putInt(DOUBLE_TAP_TOAST_COUNT,
257 mDoubleTapToastCount);
258 editor.commit();
259 break;
260 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700261 }
262 }
263 };
264 }
265
266 private void setRenderPriority() {
267 synchronized (WebSettings.this) {
268 if (mRenderPriority == RenderPriority.NORMAL) {
269 android.os.Process.setThreadPriority(
270 android.os.Process.THREAD_PRIORITY_DEFAULT);
271 } else if (mRenderPriority == RenderPriority.HIGH) {
272 android.os.Process.setThreadPriority(
273 android.os.Process.THREAD_PRIORITY_FOREGROUND +
274 android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
275 } else if (mRenderPriority == RenderPriority.LOW) {
276 android.os.Process.setThreadPriority(
277 android.os.Process.THREAD_PRIORITY_BACKGROUND);
278 }
279 }
280 }
281
282 /**
283 * Send a message to the private queue or handler.
284 */
285 private synchronized boolean sendMessage(Message msg) {
286 if (mHandler != null) {
287 mHandler.sendMessage(msg);
288 return true;
289 } else {
290 return false;
291 }
292 }
293 }
294
295 // User agent strings.
296 private static final String DESKTOP_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700297 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us)"
298 + " AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0"
299 + " Safari/530.17";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800300 private static final String IPHONE_USERAGENT =
Grace Klobab4f33442009-06-25 23:38:40 -0700301 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)"
302 + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0"
303 + " Mobile/7A341 Safari/528.16";
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800304 private static Locale sLocale;
305 private static Object sLockForLocaleSettings;
306
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700307 /**
308 * Package constructor to prevent clients from creating a new settings
309 * instance.
310 */
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700311 WebSettings(Context context, WebView webview) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700312 mEventHandler = new EventHandler();
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800313 mContext = context;
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700314 mWebView = webview;
Daisuke Miyakawac27d9b52009-05-25 16:57:15 +0900315 mDefaultTextEncoding = context.getString(com.android.internal.
316 R.string.default_text_encoding);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800317
318 if (sLockForLocaleSettings == null) {
319 sLockForLocaleSettings = new Object();
320 sLocale = Locale.getDefault();
321 }
322 mAcceptLanguage = getCurrentAcceptLanguage();
323 mUserAgent = getCurrentUserAgent();
324 mUseDefaultUserAgent = true;
325
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700326 mBlockNetworkLoads = mContext.checkPermission(
327 "android.permission.INTERNET", android.os.Process.myPid(),
328 android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700329 }
330
331 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800332 * Looks at sLocale and returns current AcceptLanguage String.
333 * @return Current AcceptLanguage String.
334 */
335 private String getCurrentAcceptLanguage() {
336 Locale locale;
337 synchronized(sLockForLocaleSettings) {
338 locale = sLocale;
339 }
340 StringBuffer buffer = new StringBuffer();
341 final String language = locale.getLanguage();
342 if (language != null) {
343 buffer.append(language);
344 final String country = locale.getCountry();
345 if (country != null) {
346 buffer.append("-");
347 buffer.append(country);
348 }
349 }
350 if (!locale.equals(Locale.US)) {
351 buffer.append(", ");
352 java.util.Locale us = Locale.US;
353 if (us.getLanguage() != null) {
354 buffer.append(us.getLanguage());
355 final String country = us.getCountry();
356 if (country != null) {
357 buffer.append("-");
358 buffer.append(country);
359 }
360 }
361 }
362
363 return buffer.toString();
364 }
365
366 /**
367 * Looks at sLocale and mContext and returns current UserAgent String.
368 * @return Current UserAgent String.
369 */
370 private synchronized String getCurrentUserAgent() {
371 Locale locale;
372 synchronized(sLockForLocaleSettings) {
373 locale = sLocale;
374 }
375 StringBuffer buffer = new StringBuffer();
376 // Add version
377 final String version = Build.VERSION.RELEASE;
378 if (version.length() > 0) {
379 buffer.append(version);
380 } else {
381 // default to "1.0"
382 buffer.append("1.0");
383 }
384 buffer.append("; ");
385 final String language = locale.getLanguage();
386 if (language != null) {
387 buffer.append(language.toLowerCase());
388 final String country = locale.getCountry();
389 if (country != null) {
390 buffer.append("-");
391 buffer.append(country.toLowerCase());
392 }
393 } else {
394 // default to "en"
395 buffer.append("en");
396 }
Grace Klobace761d32009-08-27 15:24:59 -0700397 // add the model for the release build
398 if ("REL".equals(Build.VERSION.CODENAME)) {
399 final String model = Build.MODEL;
400 if (model.length() > 0) {
401 buffer.append("; ");
402 buffer.append(model);
403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 }
405 final String id = Build.ID;
406 if (id.length() > 0) {
407 buffer.append(" Build/");
408 buffer.append(id);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800409 }
410 final String base = mContext.getResources().getText(
411 com.android.internal.R.string.web_user_agent).toString();
412 return String.format(base, buffer);
413 }
414
415 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700416 * Enables dumping the pages navigation cache to a text file.
417 */
418 public void setNavDump(boolean enabled) {
419 mNavDump = enabled;
420 }
421
422 /**
423 * Returns true if dumping the navigation cache is enabled.
424 */
425 public boolean getNavDump() {
426 return mNavDump;
427 }
428
429 /**
430 * Set whether the WebView supports zoom
431 */
432 public void setSupportZoom(boolean support) {
433 mSupportZoom = support;
Grace Kloba3a0def22010-01-23 21:11:54 -0800434 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700435 }
436
437 /**
438 * Returns whether the WebView supports zoom
439 */
440 public boolean supportZoom() {
441 return mSupportZoom;
442 }
443
444 /**
The Android Open Source Project10592532009-03-18 17:39:46 -0700445 * Sets whether the zoom mechanism built into WebView is used.
446 */
447 public void setBuiltInZoomControls(boolean enabled) {
448 mBuiltInZoomControls = enabled;
Grace Kloba3a0def22010-01-23 21:11:54 -0800449 mWebView.updateMultiTouchSupport(mContext);
The Android Open Source Project10592532009-03-18 17:39:46 -0700450 }
451
452 /**
453 * Returns true if the zoom mechanism built into WebView is being used.
454 */
455 public boolean getBuiltInZoomControls() {
456 return mBuiltInZoomControls;
457 }
458
459 /**
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800460 * Enable or disable file access within WebView. File access is enabled by
461 * default.
462 */
463 public void setAllowFileAccess(boolean allow) {
464 mAllowFileAccess = allow;
465 }
466
467 /**
468 * Returns true if this WebView supports file access.
469 */
470 public boolean getAllowFileAccess() {
471 return mAllowFileAccess;
472 }
473
474 /**
Grace Klobae397a882009-08-06 12:04:14 -0700475 * Set whether the WebView loads a page with overview mode.
Grace Klobae397a882009-08-06 12:04:14 -0700476 */
477 public void setLoadWithOverviewMode(boolean overview) {
478 mLoadWithOverviewMode = overview;
479 }
480
481 /**
482 * Returns true if this WebView loads page with overview mode
Grace Klobae397a882009-08-06 12:04:14 -0700483 */
484 public boolean getLoadWithOverviewMode() {
485 return mLoadWithOverviewMode;
486 }
487
488 /**
Adam Powell0a77ce22010-08-25 14:37:03 -0700489 * Set whether the WebView uses its background for over scroll background.
490 * If true, it will use the WebView's background. If false, it will use an
491 * internal pattern. Default is true.
492 */
493 public void setUseWebViewBackgroundForOverscrollBackground(boolean view) {
494 mUseWebViewBackgroundOverscrollBackground = view;
495 }
496
497 /**
498 * Returns true if this WebView uses WebView's background instead of
499 * internal pattern for over scroll background.
500 */
501 public boolean getUseWebViewBackgroundForOverscrollBackground() {
502 return mUseWebViewBackgroundOverscrollBackground;
503 }
504
505 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700506 * Store whether the WebView is saving form data.
507 */
508 public void setSaveFormData(boolean save) {
509 mSaveFormData = save;
510 }
511
512 /**
513 * Return whether the WebView is saving form data.
514 */
515 public boolean getSaveFormData() {
516 return mSaveFormData;
517 }
518
519 /**
520 * Store whether the WebView is saving password.
521 */
522 public void setSavePassword(boolean save) {
523 mSavePassword = save;
524 }
525
526 /**
527 * Return whether the WebView is saving password.
528 */
529 public boolean getSavePassword() {
530 return mSavePassword;
531 }
532
533 /**
534 * Set the text size of the page.
535 * @param t A TextSize value for increasing or decreasing the text.
536 * @see WebSettings.TextSize
537 */
538 public synchronized void setTextSize(TextSize t) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 if (WebView.mLogEvent && mTextSize != t ) {
Dan Egnor18e93962010-02-10 19:27:58 -0800540 EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
541 mTextSize.value, t.value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700543 mTextSize = t;
544 postSync();
545 }
546
547 /**
548 * Get the text size of the page.
549 * @return A TextSize enum value describing the text size.
550 * @see WebSettings.TextSize
551 */
552 public synchronized TextSize getTextSize() {
553 return mTextSize;
554 }
555
556 /**
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700557 * Set the default zoom density of the page. This should be called from UI
558 * thread.
559 * @param zoom A ZoomDensity value
560 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700561 */
562 public void setDefaultZoom(ZoomDensity zoom) {
563 if (mDefaultZoom != zoom) {
564 mDefaultZoom = zoom;
565 mWebView.updateDefaultZoomDensity(zoom.value);
566 }
567 }
568
569 /**
570 * Get the default zoom density of the page. This should be called from UI
571 * thread.
572 * @return A ZoomDensity value
573 * @see WebSettings.ZoomDensity
Grace Kloba0d8b77c2009-06-25 11:20:51 -0700574 */
575 public ZoomDensity getDefaultZoom() {
576 return mDefaultZoom;
577 }
578
579 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700580 * Enables using light touches to make a selection and activate mouseovers.
581 */
582 public void setLightTouchEnabled(boolean enabled) {
583 mLightTouchEnabled = enabled;
584 }
585
586 /**
587 * Returns true if light touches are enabled.
588 */
589 public boolean getLightTouchEnabled() {
590 return mLightTouchEnabled;
591 }
592
593 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100594 * @deprecated This setting controlled a rendering optimization
595 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700596 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100597 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700598 public synchronized void setUseDoubleTree(boolean use) {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100599 return;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700600 }
601
602 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100603 * @deprecated This setting controlled a rendering optimization
604 * that is no longer present. Setting it now has no effect.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700605 */
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100606 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700607 public synchronized boolean getUseDoubleTree() {
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100608 return false;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700609 }
610
611 /**
612 * Tell the WebView about user-agent string.
613 * @param ua 0 if the WebView should use an Android user-agent string,
614 * 1 if the WebView should use a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800615 *
616 * @deprecated Please use setUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700617 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800618 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700619 public synchronized void setUserAgent(int ua) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800620 String uaString = null;
621 if (ua == 1) {
622 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
623 return; // do nothing
624 } else {
625 uaString = DESKTOP_USERAGENT;
626 }
627 } else if (ua == 2) {
628 if (IPHONE_USERAGENT.equals(mUserAgent)) {
629 return; // do nothing
630 } else {
631 uaString = IPHONE_USERAGENT;
632 }
633 } else if (ua != 0) {
634 return; // do nothing
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700635 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800636 setUserAgentString(uaString);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700637 }
638
639 /**
640 * Return user-agent as int
641 * @return int 0 if the WebView is using an Android user-agent string.
642 * 1 if the WebView is using a desktop user-agent string.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800643 * -1 if the WebView is using user defined user-agent string.
644 *
645 * @deprecated Please use getUserAgentString instead.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700646 */
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800647 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700648 public synchronized int getUserAgent() {
649 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
650 return 1;
651 } else if (IPHONE_USERAGENT.equals(mUserAgent)) {
652 return 2;
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800653 } else if (mUseDefaultUserAgent) {
654 return 0;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700655 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800656 return -1;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700657 }
658
659 /**
660 * Tell the WebView to use the wide viewport
661 */
662 public synchronized void setUseWideViewPort(boolean use) {
663 if (mUseWideViewport != use) {
664 mUseWideViewport = use;
665 postSync();
666 }
667 }
668
669 /**
670 * @return True if the WebView is using a wide viewport
671 */
672 public synchronized boolean getUseWideViewPort() {
673 return mUseWideViewport;
674 }
675
676 /**
677 * Tell the WebView whether it supports multiple windows. TRUE means
678 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
679 * boolean, Message)} is implemented by the host application.
680 */
681 public synchronized void setSupportMultipleWindows(boolean support) {
682 if (mSupportMultipleWindows != support) {
683 mSupportMultipleWindows = support;
684 postSync();
685 }
686 }
687
688 /**
689 * @return True if the WebView is supporting multiple windows. This means
690 * that {@link WebChromeClient#onCreateWindow(WebView, boolean,
691 * boolean, Message)} is implemented by the host application.
692 */
693 public synchronized boolean supportMultipleWindows() {
694 return mSupportMultipleWindows;
695 }
696
697 /**
698 * Set the underlying layout algorithm. This will cause a relayout of the
699 * WebView.
700 * @param l A LayoutAlgorithm enum specifying the algorithm to use.
701 * @see WebSettings.LayoutAlgorithm
702 */
703 public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) {
704 // XXX: This will only be affective if libwebcore was built with
705 // ANDROID_LAYOUT defined.
706 if (mLayoutAlgorithm != l) {
707 mLayoutAlgorithm = l;
708 postSync();
709 }
710 }
711
712 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100713 * Return the current layout algorithm. The default is NARROW_COLUMNS.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700714 * @return LayoutAlgorithm enum value describing the layout algorithm
715 * being used.
716 * @see WebSettings.LayoutAlgorithm
717 */
718 public synchronized LayoutAlgorithm getLayoutAlgorithm() {
719 return mLayoutAlgorithm;
720 }
721
722 /**
723 * Set the standard font family name.
724 * @param font A font family name.
725 */
726 public synchronized void setStandardFontFamily(String font) {
727 if (font != null && !font.equals(mStandardFontFamily)) {
728 mStandardFontFamily = font;
729 postSync();
730 }
731 }
732
733 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100734 * Get the standard font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700735 * @return The standard font family name as a string.
736 */
737 public synchronized String getStandardFontFamily() {
738 return mStandardFontFamily;
739 }
740
741 /**
742 * Set the fixed font family name.
743 * @param font A font family name.
744 */
745 public synchronized void setFixedFontFamily(String font) {
746 if (font != null && !font.equals(mFixedFontFamily)) {
747 mFixedFontFamily = font;
748 postSync();
749 }
750 }
751
752 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100753 * Get the fixed font family name. The default is "monospace".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700754 * @return The fixed font family name as a string.
755 */
756 public synchronized String getFixedFontFamily() {
757 return mFixedFontFamily;
758 }
759
760 /**
761 * Set the sans-serif font family name.
762 * @param font A font family name.
763 */
764 public synchronized void setSansSerifFontFamily(String font) {
765 if (font != null && !font.equals(mSansSerifFontFamily)) {
766 mSansSerifFontFamily = font;
767 postSync();
768 }
769 }
770
771 /**
772 * Get the sans-serif font family name.
773 * @return The sans-serif font family name as a string.
774 */
775 public synchronized String getSansSerifFontFamily() {
776 return mSansSerifFontFamily;
777 }
778
779 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100780 * Set the serif font family name. The default is "sans-serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700781 * @param font A font family name.
782 */
783 public synchronized void setSerifFontFamily(String font) {
784 if (font != null && !font.equals(mSerifFontFamily)) {
785 mSerifFontFamily = font;
786 postSync();
787 }
788 }
789
790 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100791 * Get the serif font family name. The default is "serif".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700792 * @return The serif font family name as a string.
793 */
794 public synchronized String getSerifFontFamily() {
795 return mSerifFontFamily;
796 }
797
798 /**
799 * Set the cursive font family name.
800 * @param font A font family name.
801 */
802 public synchronized void setCursiveFontFamily(String font) {
803 if (font != null && !font.equals(mCursiveFontFamily)) {
804 mCursiveFontFamily = font;
805 postSync();
806 }
807 }
808
809 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100810 * Get the cursive font family name. The default is "cursive".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700811 * @return The cursive font family name as a string.
812 */
813 public synchronized String getCursiveFontFamily() {
814 return mCursiveFontFamily;
815 }
816
817 /**
818 * Set the fantasy font family name.
819 * @param font A font family name.
820 */
821 public synchronized void setFantasyFontFamily(String font) {
822 if (font != null && !font.equals(mFantasyFontFamily)) {
823 mFantasyFontFamily = font;
824 postSync();
825 }
826 }
827
828 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100829 * Get the fantasy font family name. The default is "fantasy".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700830 * @return The fantasy font family name as a string.
831 */
832 public synchronized String getFantasyFontFamily() {
833 return mFantasyFontFamily;
834 }
835
836 /**
837 * Set the minimum font size.
838 * @param size A non-negative integer between 1 and 72.
839 * Any number outside the specified range will be pinned.
840 */
841 public synchronized void setMinimumFontSize(int size) {
842 size = pin(size);
843 if (mMinimumFontSize != size) {
844 mMinimumFontSize = size;
845 postSync();
846 }
847 }
848
849 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100850 * Get the minimum font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700851 * @return A non-negative integer between 1 and 72.
852 */
853 public synchronized int getMinimumFontSize() {
854 return mMinimumFontSize;
855 }
856
857 /**
858 * Set the minimum logical font size.
859 * @param size A non-negative integer between 1 and 72.
860 * Any number outside the specified range will be pinned.
861 */
862 public synchronized void setMinimumLogicalFontSize(int size) {
863 size = pin(size);
864 if (mMinimumLogicalFontSize != size) {
865 mMinimumLogicalFontSize = size;
866 postSync();
867 }
868 }
869
870 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100871 * Get the minimum logical font size. The default is 8.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700872 * @return A non-negative integer between 1 and 72.
873 */
874 public synchronized int getMinimumLogicalFontSize() {
875 return mMinimumLogicalFontSize;
876 }
877
878 /**
879 * Set the default font size.
880 * @param size A non-negative integer between 1 and 72.
881 * Any number outside the specified range will be pinned.
882 */
883 public synchronized void setDefaultFontSize(int size) {
884 size = pin(size);
885 if (mDefaultFontSize != size) {
886 mDefaultFontSize = size;
887 postSync();
888 }
889 }
890
891 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100892 * Get the default font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700893 * @return A non-negative integer between 1 and 72.
894 */
895 public synchronized int getDefaultFontSize() {
896 return mDefaultFontSize;
897 }
898
899 /**
900 * Set the default fixed font size.
901 * @param size A non-negative integer between 1 and 72.
902 * Any number outside the specified range will be pinned.
903 */
904 public synchronized void setDefaultFixedFontSize(int size) {
905 size = pin(size);
906 if (mDefaultFixedFontSize != size) {
907 mDefaultFixedFontSize = size;
908 postSync();
909 }
910 }
911
912 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100913 * Get the default fixed font size. The default is 16.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700914 * @return A non-negative integer between 1 and 72.
915 */
916 public synchronized int getDefaultFixedFontSize() {
917 return mDefaultFixedFontSize;
918 }
919
920 /**
Grace Kloba097b1e772009-11-24 14:23:18 -0800921 * Set the number of pages cached by the WebKit for the history navigation.
922 * @param size A non-negative integer between 0 (no cache) and 20 (max).
923 * @hide
924 */
925 public synchronized void setPageCacheCapacity(int size) {
926 if (size < 0) size = 0;
927 if (size > 20) size = 20;
928 if (mPageCacheCapacity != size) {
929 mPageCacheCapacity = size;
930 postSync();
931 }
932 }
933
934 /**
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700935 * Tell the WebView to load image resources automatically.
936 * @param flag True if the WebView should load images automatically.
937 */
938 public synchronized void setLoadsImagesAutomatically(boolean flag) {
939 if (mLoadsImagesAutomatically != flag) {
940 mLoadsImagesAutomatically = flag;
941 postSync();
942 }
943 }
944
945 /**
946 * Return true if the WebView will load image resources automatically.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100947 * The default is true.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700948 * @return True if the WebView loads images automatically.
949 */
950 public synchronized boolean getLoadsImagesAutomatically() {
951 return mLoadsImagesAutomatically;
952 }
953
954 /**
Patrick Scottf43113f2010-02-18 09:13:12 -0500955 * Tell the WebView to block network images. This is only checked when
956 * {@link #getLoadsImagesAutomatically} is true. If you set the value to
957 * false, images will automatically be loaded. Use this api to reduce
958 * bandwidth only. Use {@link #setBlockNetworkLoads} if possible.
959 * @param flag True if the WebView should block network images.
960 * @see #setBlockNetworkLoads
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700961 */
962 public synchronized void setBlockNetworkImage(boolean flag) {
963 if (mBlockNetworkImage != flag) {
964 mBlockNetworkImage = flag;
965 postSync();
966 }
967 }
968
969 /**
Patrick Scottf43113f2010-02-18 09:13:12 -0500970 * Return true if the WebView will block network images. The default is
971 * false.
972 * @return True if the WebView blocks network images.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700973 */
974 public synchronized boolean getBlockNetworkImage() {
975 return mBlockNetworkImage;
976 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100977
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800978 /**
Patrick Scottf43113f2010-02-18 09:13:12 -0500979 * Tell the WebView to block all network load requests. If you set the
980 * value to false, you must call {@link android.webkit.WebView#reload} to
981 * fetch remote resources. This flag supercedes the value passed to
982 * {@link #setBlockNetworkImage}.
983 * @param flag True if the WebView should block all network loads.
984 * @see android.webkit.WebView#reload
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800985 */
986 public synchronized void setBlockNetworkLoads(boolean flag) {
987 if (mBlockNetworkLoads != flag) {
988 mBlockNetworkLoads = flag;
989 verifyNetworkAccess();
990 }
991 }
992
993 /**
Patrick Scottf43113f2010-02-18 09:13:12 -0500994 * Return true if the WebView will block all network loads. The default is
995 * false.
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800996 * @return True if the WebView blocks all network loads.
997 */
998 public synchronized boolean getBlockNetworkLoads() {
999 return mBlockNetworkLoads;
1000 }
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001001
1002
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001003 private void verifyNetworkAccess() {
1004 if (!mBlockNetworkLoads) {
1005 if (mContext.checkPermission("android.permission.INTERNET",
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001006 android.os.Process.myPid(), android.os.Process.myUid()) !=
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001007 PackageManager.PERMISSION_GRANTED) {
1008 throw new SecurityException
1009 ("Permission denied - " +
1010 "application missing INTERNET permission");
1011 }
1012 }
1013 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001014
1015 /**
1016 * Tell the WebView to enable javascript execution.
1017 * @param flag True if the WebView should execute javascript.
1018 */
1019 public synchronized void setJavaScriptEnabled(boolean flag) {
1020 if (mJavaScriptEnabled != flag) {
1021 mJavaScriptEnabled = flag;
1022 postSync();
1023 }
1024 }
1025
1026 /**
1027 * Tell the WebView to enable plugins.
1028 * @param flag True if the WebView should load plugins.
Patrick Scott300f2e92010-03-22 10:20:45 -04001029 * @deprecated This method has been deprecated in favor of
1030 * {@link #setPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001031 */
1032 public synchronized void setPluginsEnabled(boolean flag) {
Patrick Scott300f2e92010-03-22 10:20:45 -04001033 setPluginState(PluginState.ON);
1034 }
1035
1036 /**
1037 * Tell the WebView to enable, disable, or have plugins on demand. On
1038 * demand mode means that if a plugin exists that can handle the embedded
1039 * content, a placeholder icon will be shown instead of the plugin. When
1040 * the placeholder is clicked, the plugin will be enabled.
1041 * @param state One of the PluginState values.
1042 */
1043 public synchronized void setPluginState(PluginState state) {
1044 if (mPluginState != state) {
1045 mPluginState = state;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001046 postSync();
1047 }
1048 }
1049
1050 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001051 * Set a custom path to plugins used by the WebView. This method is
1052 * obsolete since each plugin is now loaded from its own package.
1053 * @param pluginsPath String path to the directory containing plugins.
1054 * @deprecated This method is no longer used as plugins are loaded from
1055 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001056 */
Jason Chenb766ab82010-09-01 19:02:26 -07001057 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001058 public synchronized void setPluginsPath(String pluginsPath) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001059 }
1060
1061 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001062 * Set the path to where database storage API databases should be saved.
Ben Murdoch18773af2010-02-25 18:41:56 +00001063 * Nota that the WebCore Database Tracker only allows the path to be set once.
Ben Murdoch7df19852009-04-22 13:07:58 +01001064 * This will update WebCore when the Sync runs in the C++ side.
1065 * @param databasePath String path to the directory where databases should
1066 * be saved. May be the empty string but should never be null.
1067 */
1068 public synchronized void setDatabasePath(String databasePath) {
Ben Murdoch18773af2010-02-25 18:41:56 +00001069 if (databasePath != null && !mDatabasePathHasBeenSet) {
Ben Murdoch7df19852009-04-22 13:07:58 +01001070 mDatabasePath = databasePath;
Ben Murdoch18773af2010-02-25 18:41:56 +00001071 mDatabasePathHasBeenSet = true;
Ben Murdoch7df19852009-04-22 13:07:58 +01001072 postSync();
1073 }
1074 }
1075
1076 /**
Steve Block9d3273f2009-08-21 13:16:27 +01001077 * Set the path where the Geolocation permissions database should be saved.
1078 * This will update WebCore when the Sync runs in the C++ side.
1079 * @param databasePath String path to the directory where the Geolocation
1080 * permissions database should be saved. May be the empty string but
1081 * should never be null.
Steve Block9d3273f2009-08-21 13:16:27 +01001082 */
1083 public synchronized void setGeolocationDatabasePath(String databasePath) {
Grace Kloba8f5e4052009-10-06 12:56:07 -07001084 if (databasePath != null
1085 && !databasePath.equals(mGeolocationDatabasePath)) {
Steve Block9d3273f2009-08-21 13:16:27 +01001086 mGeolocationDatabasePath = databasePath;
1087 postSync();
1088 }
1089 }
1090
1091 /**
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001092 * Tell the WebView to enable Application Caches API.
1093 * @param flag True if the WebView should enable Application Caches.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001094 */
1095 public synchronized void setAppCacheEnabled(boolean flag) {
1096 if (mAppCacheEnabled != flag) {
1097 mAppCacheEnabled = flag;
1098 postSync();
1099 }
1100 }
1101
1102 /**
1103 * Set a custom path to the Application Caches files. The client
1104 * must ensure it exists before this call.
1105 * @param appCachePath String path to the directory containing Application
1106 * Caches files. The appCache path can be the empty string but should not
1107 * be null. Passing null for this parameter will result in a no-op.
Andrei Popescu60a9a7d2009-04-17 10:43:42 +01001108 */
1109 public synchronized void setAppCachePath(String appCachePath) {
1110 if (appCachePath != null && !appCachePath.equals(mAppCachePath)) {
1111 mAppCachePath = appCachePath;
1112 postSync();
1113 }
1114 }
1115
1116 /**
Andrei Popescu1c829202009-07-22 16:47:52 +01001117 * Set the maximum size for the Application Caches content.
1118 * @param appCacheMaxSize the maximum size in bytes.
Andrei Popescu1c829202009-07-22 16:47:52 +01001119 */
1120 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) {
1121 if (appCacheMaxSize != mAppCacheMaxSize) {
1122 mAppCacheMaxSize = appCacheMaxSize;
1123 postSync();
1124 }
1125 }
1126
1127 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001128 * Set whether the database storage API is enabled.
1129 * @param flag boolean True if the WebView should use the database storage
1130 * API.
1131 */
1132 public synchronized void setDatabaseEnabled(boolean flag) {
1133 if (mDatabaseEnabled != flag) {
1134 mDatabaseEnabled = flag;
1135 postSync();
1136 }
1137 }
1138
1139 /**
Ben Murdoch274680d2009-05-28 13:44:44 +01001140 * Set whether the DOM storage API is enabled.
1141 * @param flag boolean True if the WebView should use the DOM storage
1142 * API.
Ben Murdoch274680d2009-05-28 13:44:44 +01001143 */
1144 public synchronized void setDomStorageEnabled(boolean flag) {
1145 if (mDomStorageEnabled != flag) {
1146 mDomStorageEnabled = flag;
1147 postSync();
1148 }
1149 }
1150
1151 /**
1152 * Returns true if the DOM Storage API's are enabled.
1153 * @return True if the DOM Storage API's are enabled.
Ben Murdoch274680d2009-05-28 13:44:44 +01001154 */
1155 public synchronized boolean getDomStorageEnabled() {
1156 return mDomStorageEnabled;
1157 }
1158
1159 /**
Ben Murdoch7df19852009-04-22 13:07:58 +01001160 * Return the path to where database storage API databases are saved for
1161 * the current WebView.
1162 * @return the String path to the database storage API databases.
1163 */
1164 public synchronized String getDatabasePath() {
1165 return mDatabasePath;
1166 }
1167
1168 /**
1169 * Returns true if database storage API is enabled.
1170 * @return True if the database storage API is enabled.
1171 */
1172 public synchronized boolean getDatabaseEnabled() {
1173 return mDatabaseEnabled;
1174 }
1175
1176 /**
Andrei Popescuc27a9ac2009-08-03 15:59:24 +01001177 * Tell the WebView to enable WebWorkers API.
1178 * @param flag True if the WebView should enable WebWorkers.
1179 * Note that this flag only affects V8. JSC does not have
1180 * an equivalent setting.
1181 * @hide pending api council approval
1182 */
1183 public synchronized void setWorkersEnabled(boolean flag) {
1184 if (mWorkersEnabled != flag) {
1185 mWorkersEnabled = flag;
1186 postSync();
1187 }
1188 }
1189
1190 /**
Steve Block06cd7512009-08-21 10:26:37 +01001191 * Sets whether Geolocation is enabled.
1192 * @param flag Whether Geolocation should be enabled.
Steve Block06cd7512009-08-21 10:26:37 +01001193 */
1194 public synchronized void setGeolocationEnabled(boolean flag) {
1195 if (mGeolocationEnabled != flag) {
1196 mGeolocationEnabled = flag;
1197 postSync();
1198 }
1199 }
1200
1201 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001202 * Return true if javascript is enabled. <b>Note: The default is false.</b>
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001203 * @return True if javascript is enabled.
1204 */
1205 public synchronized boolean getJavaScriptEnabled() {
1206 return mJavaScriptEnabled;
1207 }
1208
1209 /**
1210 * Return true if plugins are enabled.
1211 * @return True if plugins are enabled.
Patrick Scott300f2e92010-03-22 10:20:45 -04001212 * @deprecated This method has been replaced by {@link #getPluginState}
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001213 */
1214 public synchronized boolean getPluginsEnabled() {
Patrick Scott300f2e92010-03-22 10:20:45 -04001215 return mPluginState == PluginState.ON;
1216 }
1217
1218 /**
1219 * Return the current plugin state.
1220 * @return A value corresponding to the enum PluginState.
1221 */
1222 public synchronized PluginState getPluginState() {
1223 return mPluginState;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001224 }
1225
1226 /**
Derek Sollenbergerfdbdeb32010-08-12 11:20:13 -04001227 * Returns the directory that contains the plugin libraries. This method is
1228 * obsolete since each plugin is now loaded from its own package.
1229 * @return An empty string.
1230 * @deprecated This method is no longer used as plugins are loaded from
1231 * their own APK via the system's package manager.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001232 */
Jason Chenb766ab82010-09-01 19:02:26 -07001233 @Deprecated
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001234 public synchronized String getPluginsPath() {
Grace Kloba658ab7d2009-05-14 14:45:26 -07001235 return "";
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001236 }
1237
1238 /**
1239 * Tell javascript to open windows automatically. This applies to the
1240 * javascript function window.open().
1241 * @param flag True if javascript can open windows automatically.
1242 */
1243 public synchronized void setJavaScriptCanOpenWindowsAutomatically(
1244 boolean flag) {
1245 if (mJavaScriptCanOpenWindowsAutomatically != flag) {
1246 mJavaScriptCanOpenWindowsAutomatically = flag;
1247 postSync();
1248 }
1249 }
1250
1251 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001252 * Return true if javascript can open windows automatically. The default
1253 * is false.
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001254 * @return True if javascript can open windows automatically during
1255 * window.open().
1256 */
1257 public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() {
1258 return mJavaScriptCanOpenWindowsAutomatically;
1259 }
1260
1261 /**
1262 * Set the default text encoding name to use when decoding html pages.
1263 * @param encoding The text encoding name.
1264 */
1265 public synchronized void setDefaultTextEncodingName(String encoding) {
1266 if (encoding != null && !encoding.equals(mDefaultTextEncoding)) {
1267 mDefaultTextEncoding = encoding;
1268 postSync();
1269 }
1270 }
1271
1272 /**
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001273 * Get the default text encoding name. The default is "Latin-1".
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001274 * @return The default text encoding name as a string.
1275 */
1276 public synchronized String getDefaultTextEncodingName() {
1277 return mDefaultTextEncoding;
1278 }
1279
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001280 /**
1281 * Set the WebView's user-agent string. If the string "ua" is null or empty,
1282 * it will use the system default user-agent string.
1283 */
1284 public synchronized void setUserAgentString(String ua) {
1285 if (ua == null || ua.length() == 0) {
1286 synchronized(sLockForLocaleSettings) {
1287 Locale currentLocale = Locale.getDefault();
1288 if (!sLocale.equals(currentLocale)) {
1289 sLocale = currentLocale;
1290 mAcceptLanguage = getCurrentAcceptLanguage();
1291 }
1292 }
1293 ua = getCurrentUserAgent();
1294 mUseDefaultUserAgent = true;
1295 } else {
1296 mUseDefaultUserAgent = false;
1297 }
1298
1299 if (!ua.equals(mUserAgent)) {
1300 mUserAgent = ua;
1301 postSync();
1302 }
1303 }
1304
1305 /**
1306 * Return the WebView's user-agent string.
1307 */
1308 public synchronized String getUserAgentString() {
1309 if (DESKTOP_USERAGENT.equals(mUserAgent) ||
1310 IPHONE_USERAGENT.equals(mUserAgent) ||
1311 !mUseDefaultUserAgent) {
1312 return mUserAgent;
1313 }
1314
1315 boolean doPostSync = false;
1316 synchronized(sLockForLocaleSettings) {
1317 Locale currentLocale = Locale.getDefault();
1318 if (!sLocale.equals(currentLocale)) {
1319 sLocale = currentLocale;
1320 mUserAgent = getCurrentUserAgent();
1321 mAcceptLanguage = getCurrentAcceptLanguage();
1322 doPostSync = true;
1323 }
1324 }
1325 if (doPostSync) {
1326 postSync();
1327 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001328 return mUserAgent;
1329 }
1330
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001331 /* package api to grab the Accept Language string. */
1332 /*package*/ synchronized String getAcceptLanguage() {
1333 synchronized(sLockForLocaleSettings) {
1334 Locale currentLocale = Locale.getDefault();
1335 if (!sLocale.equals(currentLocale)) {
1336 sLocale = currentLocale;
1337 mAcceptLanguage = getCurrentAcceptLanguage();
1338 }
1339 }
1340 return mAcceptLanguage;
1341 }
1342
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001343 /**
1344 * Tell the WebView whether it needs to set a node to have focus when
1345 * {@link WebView#requestFocus(int, android.graphics.Rect)} is called.
1346 *
1347 * @param flag
1348 */
1349 public void setNeedInitialFocus(boolean flag) {
1350 if (mNeedInitialFocus != flag) {
1351 mNeedInitialFocus = flag;
1352 }
1353 }
1354
1355 /* Package api to get the choice whether it needs to set initial focus. */
1356 /* package */ boolean getNeedInitialFocus() {
1357 return mNeedInitialFocus;
1358 }
1359
1360 /**
1361 * Set the priority of the Render thread. Unlike the other settings, this
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001362 * one only needs to be called once per process. The default is NORMAL.
1363 *
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001364 * @param priority RenderPriority, can be normal, high or low.
1365 */
1366 public synchronized void setRenderPriority(RenderPriority priority) {
1367 if (mRenderPriority != priority) {
1368 mRenderPriority = priority;
1369 mEventHandler.sendMessage(Message.obtain(null,
1370 EventHandler.PRIORITY));
1371 }
1372 }
1373
1374 /**
1375 * Override the way the cache is used. The way the cache is used is based
1376 * on the navigation option. For a normal page load, the cache is checked
1377 * and content is re-validated as needed. When navigating back, content is
1378 * not revalidated, instead the content is just pulled from the cache.
1379 * This function allows the client to override this behavior.
1380 * @param mode One of the LOAD_ values.
1381 */
1382 public void setCacheMode(int mode) {
1383 if (mode != mOverrideCacheMode) {
1384 mOverrideCacheMode = mode;
1385 }
1386 }
1387
1388 /**
1389 * Return the current setting for overriding the cache mode. For a full
1390 * description, see the {@link #setCacheMode(int)} function.
1391 */
1392 public int getCacheMode() {
1393 return mOverrideCacheMode;
1394 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001395
1396 /**
1397 * If set, webkit alternately shrinks and expands images viewed outside
1398 * of an HTML page to fit the screen. This conflicts with attempts by
1399 * the UI to zoom in and out of an image, so it is set false by default.
1400 * @param shrink Set true to let webkit shrink the standalone image to fit.
1401 * {@hide}
1402 */
1403 public void setShrinksStandaloneImagesToFit(boolean shrink) {
1404 if (mShrinksStandaloneImagesToFit != shrink) {
1405 mShrinksStandaloneImagesToFit = shrink;
1406 postSync();
1407 }
1408 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001409
Grace Klobaf8d8b462009-09-20 15:57:49 -07001410 int getDoubleTapToastCount() {
1411 return mDoubleTapToastCount;
1412 }
1413
1414 void setDoubleTapToastCount(int count) {
1415 if (mDoubleTapToastCount != count) {
1416 mDoubleTapToastCount = count;
1417 // write the settings in the non-UI thread
1418 mEventHandler.sendMessage(Message.obtain(null,
1419 EventHandler.SET_DOUBLE_TAP_TOAST_COUNT));
1420 }
1421 }
1422
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001423 /**
1424 * Transfer messages from the queue to the new WebCoreThread. Called from
1425 * WebCore thread.
1426 */
1427 /*package*/
1428 synchronized void syncSettingsAndCreateHandler(BrowserFrame frame) {
1429 mBrowserFrame = frame;
Derek Sollenberger2e5c1502009-06-03 10:44:42 -04001430 if (DebugFlags.WEB_SETTINGS) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001431 junit.framework.Assert.assertTrue(frame.mNativeFrame != 0);
1432 }
Andrei Popescudee76be2009-09-22 18:28:21 +01001433
Grace Klobaf8d8b462009-09-20 15:57:49 -07001434 SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
1435 Context.MODE_PRIVATE);
Grace Kloba24a3ff92009-09-22 10:42:22 -07001436 if (mDoubleTapToastCount > 0) {
1437 mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
1438 mDoubleTapToastCount);
1439 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001440 nativeSync(frame.mNativeFrame);
1441 mSyncPending = false;
1442 mEventHandler.createHandler();
1443 }
1444
Andrei Popescudee76be2009-09-22 18:28:21 +01001445 /**
1446 * Let the Settings object know that our owner is being destroyed.
1447 */
1448 /*package*/
1449 synchronized void onDestroyed() {
Andrei Popescudee76be2009-09-22 18:28:21 +01001450 }
1451
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001452 private int pin(int size) {
1453 // FIXME: 72 is just an arbitrary max text size value.
1454 if (size < 1) {
1455 return 1;
1456 } else if (size > 72) {
1457 return 72;
1458 }
1459 return size;
1460 }
1461
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001462 /* Post a SYNC message to handle syncing the native settings. */
1463 private synchronized void postSync() {
1464 // Only post if a sync is not pending
1465 if (!mSyncPending) {
1466 mSyncPending = mEventHandler.sendMessage(
1467 Message.obtain(null, EventHandler.SYNC));
1468 }
1469 }
1470
1471 // Synchronize the native and java settings.
1472 private native void nativeSync(int nativeFrame);
1473}