blob: c41bc00045b0ab295efbfc55938f272241cb8790 [file] [log] [blame]
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001/*
Jonathan Dixon3c909522012-02-28 18:45:06 +00002 * Copyright (C) 2012 The Android Open Source Project
Jonathan Dixonded37ed92012-02-13 17:26:46 -08003 *
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;
20import android.content.SharedPreferences;
21import android.content.pm.PackageManager;
22import android.os.Build;
23import android.os.Handler;
24import android.os.Message;
25import android.util.DisplayMetrics;
26import android.util.EventLog;
27
28import java.util.Locale;
29
30/**
Jonathan Dixon3c909522012-02-28 18:45:06 +000031 * WebSettings implementation for the WebViewClassic implementation of WebView.
32 * @hide
Jonathan Dixonded37ed92012-02-13 17:26:46 -080033 */
Jonathan Dixon3c909522012-02-28 18:45:06 +000034public class WebSettingsClassic extends WebSettings {
Jonathan Dixonded37ed92012-02-13 17:26:46 -080035 // TODO: Keep this up to date
36 private static final String PREVIOUS_VERSION = "4.0.3";
37
38 // WebView associated with this WebSettings.
Jonathan Dixon3c909522012-02-28 18:45:06 +000039 private WebViewClassic mWebView;
Jonathan Dixonded37ed92012-02-13 17:26:46 -080040 // BrowserFrame used to access the native frame pointer.
41 private BrowserFrame mBrowserFrame;
42 // Flag to prevent multiple SYNC messages at one time.
43 private boolean mSyncPending = false;
44 // Custom handler that queues messages until the WebCore thread is active.
45 private final EventHandler mEventHandler;
46
47 // Private settings so we don't have to go into native code to
48 // retrieve the values. After setXXX, postSync() needs to be called.
49 //
50 // The default values need to match those in WebSettings.cpp
51 // If the defaults change, please also update the JavaDocs so developers
52 // know what they are.
53 private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
54 private Context mContext;
55 private int mTextSize = 100;
56 private String mStandardFontFamily = "sans-serif";
57 private String mFixedFontFamily = "monospace";
58 private String mSansSerifFontFamily = "sans-serif";
59 private String mSerifFontFamily = "serif";
60 private String mCursiveFontFamily = "cursive";
61 private String mFantasyFontFamily = "fantasy";
62 private String mDefaultTextEncoding;
63 private String mUserAgent;
64 private boolean mUseDefaultUserAgent;
65 private String mAcceptLanguage;
66 private int mMinimumFontSize = 8;
67 private int mMinimumLogicalFontSize = 8;
68 private int mDefaultFontSize = 16;
69 private int mDefaultFixedFontSize = 13;
70 private int mPageCacheCapacity = 0;
71 private boolean mLoadsImagesAutomatically = true;
72 private boolean mBlockNetworkImage = false;
73 private boolean mBlockNetworkLoads;
74 private boolean mJavaScriptEnabled = false;
75 private boolean mHardwareAccelSkia = false;
76 private boolean mShowVisualIndicator = false;
77 private PluginState mPluginState = PluginState.OFF;
78 private boolean mJavaScriptCanOpenWindowsAutomatically = false;
79 private boolean mUseDoubleTree = false;
80 private boolean mUseWideViewport = false;
81 private boolean mSupportMultipleWindows = false;
82 private boolean mShrinksStandaloneImagesToFit = false;
83 private long mMaximumDecodedImageSize = 0; // 0 means default
84 private boolean mPrivateBrowsingEnabled = false;
85 private boolean mSyntheticLinksEnabled = true;
86 // HTML5 API flags
87 private boolean mAppCacheEnabled = false;
88 private boolean mDatabaseEnabled = false;
89 private boolean mDomStorageEnabled = false;
90 private boolean mWorkersEnabled = false; // only affects V8.
91 private boolean mGeolocationEnabled = true;
92 private boolean mXSSAuditorEnabled = false;
93 // HTML5 configuration parameters
94 private long mAppCacheMaxSize = Long.MAX_VALUE;
95 private String mAppCachePath = null;
96 private String mDatabasePath = "";
97 // The WebCore DatabaseTracker only allows the database path to be set
98 // once. Keep track of when the path has been set.
99 private boolean mDatabasePathHasBeenSet = false;
100 private String mGeolocationDatabasePath = "";
101 // Don't need to synchronize the get/set methods as they
102 // are basic types, also none of these values are used in
103 // native WebCore code.
104 private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
105 private RenderPriority mRenderPriority = RenderPriority.NORMAL;
106 private int mOverrideCacheMode = LOAD_DEFAULT;
107 private int mDoubleTapZoom = 100;
108 private boolean mSaveFormData = true;
109 private boolean mAutoFillEnabled = false;
110 private boolean mSavePassword = true;
111 private boolean mLightTouchEnabled = false;
112 private boolean mNeedInitialFocus = true;
113 private boolean mNavDump = false;
114 private boolean mSupportZoom = true;
115 private boolean mBuiltInZoomControls = false;
116 private boolean mDisplayZoomControls = true;
117 private boolean mAllowFileAccess = true;
118 private boolean mAllowContentAccess = true;
119 private boolean mLoadWithOverviewMode = false;
120 private boolean mEnableSmoothTransition = false;
121 private boolean mForceUserScalable = false;
122
123 // AutoFill Profile data
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800124 public static class AutoFillProfile {
125 private int mUniqueId;
126 private String mFullName;
127 private String mEmailAddress;
128 private String mCompanyName;
129 private String mAddressLine1;
130 private String mAddressLine2;
131 private String mCity;
132 private String mState;
133 private String mZipCode;
134 private String mCountry;
135 private String mPhoneNumber;
136
137 public AutoFillProfile(int uniqueId, String fullName, String email,
138 String companyName, String addressLine1, String addressLine2,
139 String city, String state, String zipCode, String country,
140 String phoneNumber) {
141 mUniqueId = uniqueId;
142 mFullName = fullName;
143 mEmailAddress = email;
144 mCompanyName = companyName;
145 mAddressLine1 = addressLine1;
146 mAddressLine2 = addressLine2;
147 mCity = city;
148 mState = state;
149 mZipCode = zipCode;
150 mCountry = country;
151 mPhoneNumber = phoneNumber;
152 }
153
154 public int getUniqueId() { return mUniqueId; }
155 public String getFullName() { return mFullName; }
156 public String getEmailAddress() { return mEmailAddress; }
157 public String getCompanyName() { return mCompanyName; }
158 public String getAddressLine1() { return mAddressLine1; }
159 public String getAddressLine2() { return mAddressLine2; }
160 public String getCity() { return mCity; }
161 public String getState() { return mState; }
162 public String getZipCode() { return mZipCode; }
163 public String getCountry() { return mCountry; }
164 public String getPhoneNumber() { return mPhoneNumber; }
165 }
166
167
168 private AutoFillProfile mAutoFillProfile;
169
170 private boolean mUseWebViewBackgroundForOverscroll = true;
171
172 // private WebSettings, not accessible by the host activity
173 static private int mDoubleTapToastCount = 3;
174
175 private static final String PREF_FILE = "WebViewSettings";
176 private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";
177
178 // Class to handle messages before WebCore is ready.
179 private class EventHandler {
180 // Message id for syncing
181 static final int SYNC = 0;
182 // Message id for setting priority
183 static final int PRIORITY = 1;
184 // Message id for writing double-tap toast count
185 static final int SET_DOUBLE_TAP_TOAST_COUNT = 2;
186 // Actual WebCore thread handler
187 private Handler mHandler;
188
189 private synchronized void createHandler() {
190 // as mRenderPriority can be set before thread is running, sync up
191 setRenderPriority();
192
193 // create a new handler
194 mHandler = new Handler() {
195 @Override
196 public void handleMessage(Message msg) {
197 switch (msg.what) {
198 case SYNC:
Jonathan Dixon3c909522012-02-28 18:45:06 +0000199 synchronized (WebSettingsClassic.this) {
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800200 if (mBrowserFrame.mNativeFrame != 0) {
201 nativeSync(mBrowserFrame.mNativeFrame);
202 }
203 mSyncPending = false;
204 }
205 break;
206
207 case PRIORITY: {
208 setRenderPriority();
209 break;
210 }
211
212 case SET_DOUBLE_TAP_TOAST_COUNT: {
213 SharedPreferences.Editor editor = mContext
214 .getSharedPreferences(PREF_FILE,
215 Context.MODE_PRIVATE).edit();
216 editor.putInt(DOUBLE_TAP_TOAST_COUNT,
217 mDoubleTapToastCount);
218 editor.commit();
219 break;
220 }
221 }
222 }
223 };
224 }
225
226 private void setRenderPriority() {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000227 synchronized (WebSettingsClassic.this) {
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800228 if (mRenderPriority == RenderPriority.NORMAL) {
229 android.os.Process.setThreadPriority(
230 android.os.Process.THREAD_PRIORITY_DEFAULT);
231 } else if (mRenderPriority == RenderPriority.HIGH) {
232 android.os.Process.setThreadPriority(
233 android.os.Process.THREAD_PRIORITY_FOREGROUND +
234 android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
235 } else if (mRenderPriority == RenderPriority.LOW) {
236 android.os.Process.setThreadPriority(
237 android.os.Process.THREAD_PRIORITY_BACKGROUND);
238 }
239 }
240 }
241
242 /**
243 * Send a message to the private queue or handler.
244 */
245 private synchronized boolean sendMessage(Message msg) {
246 if (mHandler != null) {
247 mHandler.sendMessage(msg);
248 return true;
249 } else {
250 return false;
251 }
252 }
253 }
254
255 // User agent strings.
256 private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
257 "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
258 "Chrome/11.0.696.34 Safari/534.24";
259 private static final String IPHONE_USERAGENT =
260 "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)"
261 + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0"
262 + " Mobile/7A341 Safari/528.16";
263 private static Locale sLocale;
264 private static Object sLockForLocaleSettings;
265
266 /**
267 * Package constructor to prevent clients from creating a new settings
268 * instance.
269 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000270 WebSettingsClassic(Context context, WebViewClassic webview) {
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800271 mEventHandler = new EventHandler();
272 mContext = context;
273 mWebView = webview;
274 mDefaultTextEncoding = context.getString(com.android.internal.
275 R.string.default_text_encoding);
276
277 if (sLockForLocaleSettings == null) {
278 sLockForLocaleSettings = new Object();
279 sLocale = Locale.getDefault();
280 }
281 mAcceptLanguage = getCurrentAcceptLanguage();
282 mUserAgent = getCurrentUserAgent();
283 mUseDefaultUserAgent = true;
284
285 mBlockNetworkLoads = mContext.checkPermission(
286 "android.permission.INTERNET", android.os.Process.myPid(),
287 android.os.Process.myUid()) != PackageManager.PERMISSION_GRANTED;
288 }
289
290 private static final String ACCEPT_LANG_FOR_US_LOCALE = "en-US";
291
292 /**
293 * Looks at sLocale and returns current AcceptLanguage String.
294 * @return Current AcceptLanguage String.
295 */
296 private String getCurrentAcceptLanguage() {
297 Locale locale;
298 synchronized(sLockForLocaleSettings) {
299 locale = sLocale;
300 }
301 StringBuilder buffer = new StringBuilder();
302 addLocaleToHttpAcceptLanguage(buffer, locale);
303
304 if (!Locale.US.equals(locale)) {
305 if (buffer.length() > 0) {
306 buffer.append(", ");
307 }
308 buffer.append(ACCEPT_LANG_FOR_US_LOCALE);
309 }
310
311 return buffer.toString();
312 }
313
314 /**
315 * Convert obsolete language codes, including Hebrew/Indonesian/Yiddish,
316 * to new standard.
317 */
318 private static String convertObsoleteLanguageCodeToNew(String langCode) {
319 if (langCode == null) {
320 return null;
321 }
322 if ("iw".equals(langCode)) {
323 // Hebrew
324 return "he";
325 } else if ("in".equals(langCode)) {
326 // Indonesian
327 return "id";
328 } else if ("ji".equals(langCode)) {
329 // Yiddish
330 return "yi";
331 }
332 return langCode;
333 }
334
335 private static void addLocaleToHttpAcceptLanguage(StringBuilder builder,
336 Locale locale) {
337 String language = convertObsoleteLanguageCodeToNew(locale.getLanguage());
338 if (language != null) {
339 builder.append(language);
340 String country = locale.getCountry();
341 if (country != null) {
342 builder.append("-");
343 builder.append(country);
344 }
345 }
346 }
347
348 /**
349 * Looks at sLocale and mContext and returns current UserAgent String.
350 * @return Current UserAgent String.
351 */
352 private synchronized String getCurrentUserAgent() {
353 Locale locale;
354 synchronized(sLockForLocaleSettings) {
355 locale = sLocale;
356 }
357 StringBuffer buffer = new StringBuffer();
358 // Add version
359 final String version = Build.VERSION.RELEASE;
360 if (version.length() > 0) {
361 if (Character.isDigit(version.charAt(0))) {
362 // Release is a version, eg "3.1"
363 buffer.append(version);
364 } else {
365 // Release is a codename, eg "Honeycomb"
366 // In this case, use the previous release's version
367 buffer.append(PREVIOUS_VERSION);
368 }
369 } else {
370 // default to "1.0"
371 buffer.append("1.0");
372 }
373 buffer.append("; ");
374 final String language = locale.getLanguage();
375 if (language != null) {
376 buffer.append(convertObsoleteLanguageCodeToNew(language));
377 final String country = locale.getCountry();
378 if (country != null) {
379 buffer.append("-");
380 buffer.append(country.toLowerCase());
381 }
382 } else {
383 // default to "en"
384 buffer.append("en");
385 }
386 buffer.append(";");
387 // add the model for the release build
388 if ("REL".equals(Build.VERSION.CODENAME)) {
389 final String model = Build.MODEL;
390 if (model.length() > 0) {
391 buffer.append(" ");
392 buffer.append(model);
393 }
394 }
395 final String id = Build.ID;
396 if (id.length() > 0) {
397 buffer.append(" Build/");
398 buffer.append(id);
399 }
400 String mobile = mContext.getResources().getText(
401 com.android.internal.R.string.web_user_agent_target_content).toString();
402 final String base = mContext.getResources().getText(
403 com.android.internal.R.string.web_user_agent).toString();
404 return String.format(base, buffer, mobile);
405 }
406
407 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000408 * @see android.webkit.WebSettings#setNavDump(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800409 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000410 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800411 @Deprecated
412 public void setNavDump(boolean enabled) {
413 mNavDump = enabled;
414 }
415
416 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000417 * @see android.webkit.WebSettings#getNavDump()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800418 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000419 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800420 @Deprecated
421 public boolean getNavDump() {
422 return mNavDump;
423 }
424
425 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000426 * @see android.webkit.WebSettings#setSupportZoom(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800427 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000428 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800429 public void setSupportZoom(boolean support) {
430 mSupportZoom = support;
431 mWebView.updateMultiTouchSupport(mContext);
432 }
433
434 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000435 * @see android.webkit.WebSettings#supportZoom()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800436 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000437 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800438 public boolean supportZoom() {
439 return mSupportZoom;
440 }
441
442 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000443 * @see android.webkit.WebSettings#setBuiltInZoomControls(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800444 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000445 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800446 public void setBuiltInZoomControls(boolean enabled) {
447 mBuiltInZoomControls = enabled;
448 mWebView.updateMultiTouchSupport(mContext);
449 }
450
451 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000452 * @see android.webkit.WebSettings#getBuiltInZoomControls()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800453 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000454 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800455 public boolean getBuiltInZoomControls() {
456 return mBuiltInZoomControls;
457 }
458
459 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000460 * @see android.webkit.WebSettings#setDisplayZoomControls(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800461 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000462 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800463 public void setDisplayZoomControls(boolean enabled) {
464 mDisplayZoomControls = enabled;
465 mWebView.updateMultiTouchSupport(mContext);
466 }
467
468 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000469 * @see android.webkit.WebSettings#getDisplayZoomControls()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800470 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000471 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800472 public boolean getDisplayZoomControls() {
473 return mDisplayZoomControls;
474 }
475
476 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000477 * @see android.webkit.WebSettings#setAllowFileAccess(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800478 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000479 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800480 public void setAllowFileAccess(boolean allow) {
481 mAllowFileAccess = allow;
482 }
483
484 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000485 * @see android.webkit.WebSettings#getAllowFileAccess()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800486 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000487 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800488 public boolean getAllowFileAccess() {
489 return mAllowFileAccess;
490 }
491
492 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000493 * @see android.webkit.WebSettings#setAllowContentAccess(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800494 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000495 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800496 public void setAllowContentAccess(boolean allow) {
497 mAllowContentAccess = allow;
498 }
499
500 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000501 * @see android.webkit.WebSettings#getAllowContentAccess()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800502 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000503 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800504 public boolean getAllowContentAccess() {
505 return mAllowContentAccess;
506 }
507
508 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000509 * @see android.webkit.WebSettings#setLoadWithOverviewMode(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800510 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000511 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800512 public void setLoadWithOverviewMode(boolean overview) {
513 mLoadWithOverviewMode = overview;
514 }
515
516 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000517 * @see android.webkit.WebSettings#getLoadWithOverviewMode()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800518 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000519 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800520 public boolean getLoadWithOverviewMode() {
521 return mLoadWithOverviewMode;
522 }
523
524 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000525 * @see android.webkit.WebSettings#setEnableSmoothTransition(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800526 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000527 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800528 public void setEnableSmoothTransition(boolean enable) {
529 mEnableSmoothTransition = enable;
530 }
531
532 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000533 * @see android.webkit.WebSettings#enableSmoothTransition()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800534 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000535 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800536 public boolean enableSmoothTransition() {
537 return mEnableSmoothTransition;
538 }
539
540 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000541 * @see android.webkit.WebSettings#setUseWebViewBackgroundForOverscrollBackground(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800542 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000543 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800544 @Deprecated
545 public void setUseWebViewBackgroundForOverscrollBackground(boolean view) {
546 mUseWebViewBackgroundForOverscroll = view;
547 }
548
549 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000550 * @see android.webkit.WebSettings#getUseWebViewBackgroundForOverscrollBackground()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800551 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000552 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800553 @Deprecated
554 public boolean getUseWebViewBackgroundForOverscrollBackground() {
555 return mUseWebViewBackgroundForOverscroll;
556 }
557
558 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000559 * @see android.webkit.WebSettings#setSaveFormData(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800560 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000561 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800562 public void setSaveFormData(boolean save) {
563 mSaveFormData = save;
564 }
565
566 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000567 * @see android.webkit.WebSettings#getSaveFormData()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800568 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000569 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800570 public boolean getSaveFormData() {
571 return mSaveFormData && !mPrivateBrowsingEnabled;
572 }
573
574 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000575 * @see android.webkit.WebSettings#setSavePassword(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800576 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000577 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800578 public void setSavePassword(boolean save) {
579 mSavePassword = save;
580 }
581
582 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000583 * @see android.webkit.WebSettings#getSavePassword()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800584 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000585 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800586 public boolean getSavePassword() {
587 return mSavePassword;
588 }
589
590 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000591 * @see android.webkit.WebSettings#setTextZoom(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800592 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000593 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800594 public synchronized void setTextZoom(int textZoom) {
595 if (mTextSize != textZoom) {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000596 if (WebViewClassic.mLogEvent) {
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800597 EventLog.writeEvent(EventLogTags.BROWSER_TEXT_SIZE_CHANGE,
598 mTextSize, textZoom);
599 }
600 mTextSize = textZoom;
601 postSync();
602 }
603 }
604
605 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000606 * @see android.webkit.WebSettings#getTextZoom()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800607 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000608 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800609 public synchronized int getTextZoom() {
610 return mTextSize;
611 }
612
613 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000614 * @see android.webkit.WebSettings#setTextSize(android.webkit.WebSettingsClassic.TextSize)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800615 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000616 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800617 public synchronized void setTextSize(TextSize t) {
618 setTextZoom(t.value);
619 }
620
621 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000622 * @see android.webkit.WebSettings#getTextSize()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800623 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000624 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800625 public synchronized TextSize getTextSize() {
626 TextSize closestSize = null;
627 int smallestDelta = Integer.MAX_VALUE;
628 for (TextSize size : TextSize.values()) {
629 int delta = Math.abs(mTextSize - size.value);
630 if (delta == 0) {
631 return size;
632 }
633 if (delta < smallestDelta) {
634 smallestDelta = delta;
635 closestSize = size;
636 }
637 }
638 return closestSize != null ? closestSize : TextSize.NORMAL;
639 }
640
641 /**
642 * Set the double-tap zoom of the page in percent. Default is 100.
643 * @param doubleTapZoom A percent value for increasing or decreasing the double-tap zoom.
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800644 */
645 public void setDoubleTapZoom(int doubleTapZoom) {
646 if (mDoubleTapZoom != doubleTapZoom) {
647 mDoubleTapZoom = doubleTapZoom;
648 mWebView.updateDoubleTapZoom(doubleTapZoom);
649 }
650 }
651
652 /**
653 * Get the double-tap zoom of the page in percent.
654 * @return A percent value describing the double-tap zoom.
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800655 */
656 public int getDoubleTapZoom() {
657 return mDoubleTapZoom;
658 }
659
660 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000661 * @see android.webkit.WebSettings#setDefaultZoom(android.webkit.WebSettingsClassic.ZoomDensity)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800662 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000663 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800664 public void setDefaultZoom(ZoomDensity zoom) {
665 if (mDefaultZoom != zoom) {
666 mDefaultZoom = zoom;
667 mWebView.adjustDefaultZoomDensity(zoom.value);
668 }
669 }
670
671 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000672 * @see android.webkit.WebSettings#getDefaultZoom()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800673 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000674 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800675 public ZoomDensity getDefaultZoom() {
676 return mDefaultZoom;
677 }
678
679 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000680 * @see android.webkit.WebSettings#setLightTouchEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800681 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000682 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800683 public void setLightTouchEnabled(boolean enabled) {
684 mLightTouchEnabled = enabled;
685 }
686
687 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000688 * @see android.webkit.WebSettings#getLightTouchEnabled()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800689 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000690 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800691 public boolean getLightTouchEnabled() {
692 return mLightTouchEnabled;
693 }
694
695 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000696 * @see android.webkit.WebSettings#setUseDoubleTree(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800697 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000698 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800699 @Deprecated
700 public synchronized void setUseDoubleTree(boolean use) {
701 return;
702 }
703
704 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000705 * @see android.webkit.WebSettings#getUseDoubleTree()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800706 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000707 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800708 @Deprecated
709 public synchronized boolean getUseDoubleTree() {
710 return false;
711 }
712
713 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000714 * @see android.webkit.WebSettings#setUserAgent(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800715 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000716 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800717 @Deprecated
718 public synchronized void setUserAgent(int ua) {
719 String uaString = null;
720 if (ua == 1) {
721 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
722 return; // do nothing
723 } else {
724 uaString = DESKTOP_USERAGENT;
725 }
726 } else if (ua == 2) {
727 if (IPHONE_USERAGENT.equals(mUserAgent)) {
728 return; // do nothing
729 } else {
730 uaString = IPHONE_USERAGENT;
731 }
732 } else if (ua != 0) {
733 return; // do nothing
734 }
735 setUserAgentString(uaString);
736 }
737
738 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000739 * @see android.webkit.WebSettings#getUserAgent()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800740 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000741 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800742 @Deprecated
743 public synchronized int getUserAgent() {
744 if (DESKTOP_USERAGENT.equals(mUserAgent)) {
745 return 1;
746 } else if (IPHONE_USERAGENT.equals(mUserAgent)) {
747 return 2;
748 } else if (mUseDefaultUserAgent) {
749 return 0;
750 }
751 return -1;
752 }
753
754 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000755 * @see android.webkit.WebSettings#setUseWideViewPort(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800756 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000757 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800758 public synchronized void setUseWideViewPort(boolean use) {
759 if (mUseWideViewport != use) {
760 mUseWideViewport = use;
761 postSync();
762 }
763 }
764
765 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000766 * @see android.webkit.WebSettings#getUseWideViewPort()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800767 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000768 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800769 public synchronized boolean getUseWideViewPort() {
770 return mUseWideViewport;
771 }
772
773 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000774 * @see android.webkit.WebSettings#setSupportMultipleWindows(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800775 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000776 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800777 public synchronized void setSupportMultipleWindows(boolean support) {
778 if (mSupportMultipleWindows != support) {
779 mSupportMultipleWindows = support;
780 postSync();
781 }
782 }
783
784 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000785 * @see android.webkit.WebSettings#supportMultipleWindows()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800786 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000787 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800788 public synchronized boolean supportMultipleWindows() {
789 return mSupportMultipleWindows;
790 }
791
792 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000793 * @see android.webkit.WebSettings#setLayoutAlgorithm(android.webkit.WebSettingsClassic.LayoutAlgorithm)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800794 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000795 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800796 public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) {
797 // XXX: This will only be affective if libwebcore was built with
798 // ANDROID_LAYOUT defined.
799 if (mLayoutAlgorithm != l) {
800 mLayoutAlgorithm = l;
801 postSync();
802 }
803 }
804
805 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000806 * @see android.webkit.WebSettings#getLayoutAlgorithm()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800807 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000808 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800809 public synchronized LayoutAlgorithm getLayoutAlgorithm() {
810 return mLayoutAlgorithm;
811 }
812
813 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000814 * @see android.webkit.WebSettings#setStandardFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800815 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000816 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800817 public synchronized void setStandardFontFamily(String font) {
818 if (font != null && !font.equals(mStandardFontFamily)) {
819 mStandardFontFamily = font;
820 postSync();
821 }
822 }
823
824 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000825 * @see android.webkit.WebSettings#getStandardFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800826 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000827 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800828 public synchronized String getStandardFontFamily() {
829 return mStandardFontFamily;
830 }
831
832 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000833 * @see android.webkit.WebSettings#setFixedFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800834 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000835 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800836 public synchronized void setFixedFontFamily(String font) {
837 if (font != null && !font.equals(mFixedFontFamily)) {
838 mFixedFontFamily = font;
839 postSync();
840 }
841 }
842
843 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000844 * @see android.webkit.WebSettings#getFixedFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800845 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000846 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800847 public synchronized String getFixedFontFamily() {
848 return mFixedFontFamily;
849 }
850
851 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000852 * @see android.webkit.WebSettings#setSansSerifFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800853 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000854 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800855 public synchronized void setSansSerifFontFamily(String font) {
856 if (font != null && !font.equals(mSansSerifFontFamily)) {
857 mSansSerifFontFamily = font;
858 postSync();
859 }
860 }
861
862 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000863 * @see android.webkit.WebSettings#getSansSerifFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800864 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000865 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800866 public synchronized String getSansSerifFontFamily() {
867 return mSansSerifFontFamily;
868 }
869
870 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000871 * @see android.webkit.WebSettings#setSerifFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800872 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000873 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800874 public synchronized void setSerifFontFamily(String font) {
875 if (font != null && !font.equals(mSerifFontFamily)) {
876 mSerifFontFamily = font;
877 postSync();
878 }
879 }
880
881 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000882 * @see android.webkit.WebSettings#getSerifFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800883 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000884 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800885 public synchronized String getSerifFontFamily() {
886 return mSerifFontFamily;
887 }
888
889 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000890 * @see android.webkit.WebSettings#setCursiveFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800891 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000892 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800893 public synchronized void setCursiveFontFamily(String font) {
894 if (font != null && !font.equals(mCursiveFontFamily)) {
895 mCursiveFontFamily = font;
896 postSync();
897 }
898 }
899
900 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000901 * @see android.webkit.WebSettings#getCursiveFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800902 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000903 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800904 public synchronized String getCursiveFontFamily() {
905 return mCursiveFontFamily;
906 }
907
908 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000909 * @see android.webkit.WebSettings#setFantasyFontFamily(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800910 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000911 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800912 public synchronized void setFantasyFontFamily(String font) {
913 if (font != null && !font.equals(mFantasyFontFamily)) {
914 mFantasyFontFamily = font;
915 postSync();
916 }
917 }
918
919 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000920 * @see android.webkit.WebSettings#getFantasyFontFamily()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800921 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000922 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800923 public synchronized String getFantasyFontFamily() {
924 return mFantasyFontFamily;
925 }
926
927 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000928 * @see android.webkit.WebSettings#setMinimumFontSize(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800929 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000930 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800931 public synchronized void setMinimumFontSize(int size) {
932 size = pin(size);
933 if (mMinimumFontSize != size) {
934 mMinimumFontSize = size;
935 postSync();
936 }
937 }
938
939 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000940 * @see android.webkit.WebSettings#getMinimumFontSize()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800941 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000942 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800943 public synchronized int getMinimumFontSize() {
944 return mMinimumFontSize;
945 }
946
947 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000948 * @see android.webkit.WebSettings#setMinimumLogicalFontSize(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800949 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000950 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800951 public synchronized void setMinimumLogicalFontSize(int size) {
952 size = pin(size);
953 if (mMinimumLogicalFontSize != size) {
954 mMinimumLogicalFontSize = size;
955 postSync();
956 }
957 }
958
959 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000960 * @see android.webkit.WebSettings#getMinimumLogicalFontSize()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800961 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000962 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800963 public synchronized int getMinimumLogicalFontSize() {
964 return mMinimumLogicalFontSize;
965 }
966
967 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000968 * @see android.webkit.WebSettings#setDefaultFontSize(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800969 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000970 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800971 public synchronized void setDefaultFontSize(int size) {
972 size = pin(size);
973 if (mDefaultFontSize != size) {
974 mDefaultFontSize = size;
975 postSync();
976 }
977 }
978
979 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000980 * @see android.webkit.WebSettings#getDefaultFontSize()
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800981 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000982 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800983 public synchronized int getDefaultFontSize() {
984 return mDefaultFontSize;
985 }
986
987 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +0000988 * @see android.webkit.WebSettings#setDefaultFixedFontSize(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800989 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000990 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -0800991 public synchronized void setDefaultFixedFontSize(int size) {
992 size = pin(size);
993 if (mDefaultFixedFontSize != size) {
994 mDefaultFixedFontSize = size;
995 postSync();
996 }
997 }
998
999 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001000 * @see android.webkit.WebSettings#getDefaultFixedFontSize()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001001 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001002 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001003 public synchronized int getDefaultFixedFontSize() {
1004 return mDefaultFixedFontSize;
1005 }
1006
1007 /**
1008 * Set the number of pages cached by the WebKit for the history navigation.
1009 * @param size A non-negative integer between 0 (no cache) and 20 (max).
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001010 */
1011 public synchronized void setPageCacheCapacity(int size) {
1012 if (size < 0) size = 0;
1013 if (size > 20) size = 20;
1014 if (mPageCacheCapacity != size) {
1015 mPageCacheCapacity = size;
1016 postSync();
1017 }
1018 }
1019
1020 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001021 * @see android.webkit.WebSettings#setLoadsImagesAutomatically(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001022 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001023 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001024 public synchronized void setLoadsImagesAutomatically(boolean flag) {
1025 if (mLoadsImagesAutomatically != flag) {
1026 mLoadsImagesAutomatically = flag;
1027 postSync();
1028 }
1029 }
1030
1031 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001032 * @see android.webkit.WebSettings#getLoadsImagesAutomatically()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001033 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001034 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001035 public synchronized boolean getLoadsImagesAutomatically() {
1036 return mLoadsImagesAutomatically;
1037 }
1038
1039 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001040 * @see android.webkit.WebSettings#setBlockNetworkImage(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001041 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001042 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001043 public synchronized void setBlockNetworkImage(boolean flag) {
1044 if (mBlockNetworkImage != flag) {
1045 mBlockNetworkImage = flag;
1046 postSync();
1047 }
1048 }
1049
1050 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001051 * @see android.webkit.WebSettings#getBlockNetworkImage()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001052 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001053 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001054 public synchronized boolean getBlockNetworkImage() {
1055 return mBlockNetworkImage;
1056 }
1057
1058 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001059 * @see android.webkit.WebSettings#setBlockNetworkLoads(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001060 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001061 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001062 public synchronized void setBlockNetworkLoads(boolean flag) {
1063 if (mBlockNetworkLoads != flag) {
1064 mBlockNetworkLoads = flag;
1065 verifyNetworkAccess();
1066 postSync();
1067 }
1068 }
1069
1070 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001071 * @see android.webkit.WebSettings#getBlockNetworkLoads()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001072 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001073 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001074 public synchronized boolean getBlockNetworkLoads() {
1075 return mBlockNetworkLoads;
1076 }
1077
1078
1079 private void verifyNetworkAccess() {
1080 if (!mBlockNetworkLoads) {
1081 if (mContext.checkPermission("android.permission.INTERNET",
1082 android.os.Process.myPid(), android.os.Process.myUid()) !=
1083 PackageManager.PERMISSION_GRANTED) {
1084 throw new SecurityException
1085 ("Permission denied - " +
1086 "application missing INTERNET permission");
1087 }
1088 }
1089 }
1090
1091 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001092 * @see android.webkit.WebSettings#setJavaScriptEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001093 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001094 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001095 public synchronized void setJavaScriptEnabled(boolean flag) {
1096 if (mJavaScriptEnabled != flag) {
1097 mJavaScriptEnabled = flag;
1098 postSync();
1099 }
1100 }
1101
1102 /**
1103 * Tell the WebView to use Skia's hardware accelerated rendering path
1104 * @param flag True if the WebView should use Skia's hw-accel path
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001105 */
1106 public synchronized void setHardwareAccelSkiaEnabled(boolean flag) {
1107 if (mHardwareAccelSkia != flag) {
1108 mHardwareAccelSkia = flag;
1109 postSync();
1110 }
1111 }
1112
1113 /**
1114 * @return True if the WebView is using hardware accelerated skia
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001115 */
1116 public synchronized boolean getHardwareAccelSkiaEnabled() {
1117 return mHardwareAccelSkia;
1118 }
1119
1120 /**
1121 * Tell the WebView to show the visual indicator
1122 * @param flag True if the WebView should show the visual indicator
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001123 */
1124 public synchronized void setShowVisualIndicator(boolean flag) {
1125 if (mShowVisualIndicator != flag) {
1126 mShowVisualIndicator = flag;
1127 postSync();
1128 }
1129 }
1130
1131 /**
1132 * @return True if the WebView is showing the visual indicator
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001133 */
1134 public synchronized boolean getShowVisualIndicator() {
1135 return mShowVisualIndicator;
1136 }
1137
1138 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001139 * @see android.webkit.WebSettings#setPluginsEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001140 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001141 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001142 @Deprecated
1143 public synchronized void setPluginsEnabled(boolean flag) {
1144 setPluginState(flag ? PluginState.ON : PluginState.OFF);
1145 }
1146
1147 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001148 * @see android.webkit.WebSettings#setPluginState(android.webkit.WebSettingsClassic.PluginState)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001149 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001150 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001151 public synchronized void setPluginState(PluginState state) {
1152 if (mPluginState != state) {
1153 mPluginState = state;
1154 postSync();
1155 }
1156 }
1157
1158 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001159 * @see android.webkit.WebSettings#setPluginsPath(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001160 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001161 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001162 @Deprecated
1163 public synchronized void setPluginsPath(String pluginsPath) {
1164 }
1165
1166 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001167 * @see android.webkit.WebSettings#setDatabasePath(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001168 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001169 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001170 public synchronized void setDatabasePath(String databasePath) {
1171 if (databasePath != null && !mDatabasePathHasBeenSet) {
1172 mDatabasePath = databasePath;
1173 mDatabasePathHasBeenSet = true;
1174 postSync();
1175 }
1176 }
1177
1178 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001179 * @see android.webkit.WebSettings#setGeolocationDatabasePath(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001180 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001181 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001182 public synchronized void setGeolocationDatabasePath(String databasePath) {
1183 if (databasePath != null
1184 && !databasePath.equals(mGeolocationDatabasePath)) {
1185 mGeolocationDatabasePath = databasePath;
1186 postSync();
1187 }
1188 }
1189
1190 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001191 * @see android.webkit.WebSettings#setAppCacheEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001192 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001193 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001194 public synchronized void setAppCacheEnabled(boolean flag) {
1195 if (mAppCacheEnabled != flag) {
1196 mAppCacheEnabled = flag;
1197 postSync();
1198 }
1199 }
1200
1201 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001202 * @see android.webkit.WebSettings#setAppCachePath(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001203 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001204 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001205 public synchronized void setAppCachePath(String path) {
1206 // We test for a valid path and for repeated setting on the native
1207 // side, but we can avoid syncing in some simple cases.
1208 if (mAppCachePath == null && path != null && !path.isEmpty()) {
1209 mAppCachePath = path;
1210 postSync();
1211 }
1212 }
1213
1214 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001215 * @see android.webkit.WebSettings#setAppCacheMaxSize(long)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001216 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001217 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001218 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) {
1219 if (appCacheMaxSize != mAppCacheMaxSize) {
1220 mAppCacheMaxSize = appCacheMaxSize;
1221 postSync();
1222 }
1223 }
1224
1225 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001226 * @see android.webkit.WebSettings#setDatabaseEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001227 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001228 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001229 public synchronized void setDatabaseEnabled(boolean flag) {
1230 if (mDatabaseEnabled != flag) {
1231 mDatabaseEnabled = flag;
1232 postSync();
1233 }
1234 }
1235
1236 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001237 * @see android.webkit.WebSettings#setDomStorageEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001238 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001239 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001240 public synchronized void setDomStorageEnabled(boolean flag) {
1241 if (mDomStorageEnabled != flag) {
1242 mDomStorageEnabled = flag;
1243 postSync();
1244 }
1245 }
1246
1247 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001248 * @see android.webkit.WebSettings#getDomStorageEnabled()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001249 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001250 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001251 public synchronized boolean getDomStorageEnabled() {
1252 return mDomStorageEnabled;
1253 }
1254
1255 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001256 * @see android.webkit.WebSettings#getDatabasePath()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001257 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001258 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001259 public synchronized String getDatabasePath() {
1260 return mDatabasePath;
1261 }
1262
1263 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001264 * @see android.webkit.WebSettings#getDatabaseEnabled()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001265 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001266 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001267 public synchronized boolean getDatabaseEnabled() {
1268 return mDatabaseEnabled;
1269 }
1270
1271 /**
1272 * Tell the WebView to enable WebWorkers API.
1273 * @param flag True if the WebView should enable WebWorkers.
1274 * Note that this flag only affects V8. JSC does not have
1275 * an equivalent setting.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001276 */
1277 public synchronized void setWorkersEnabled(boolean flag) {
1278 if (mWorkersEnabled != flag) {
1279 mWorkersEnabled = flag;
1280 postSync();
1281 }
1282 }
1283
1284 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001285 * @see android.webkit.WebSettings#setGeolocationEnabled(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001286 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001287 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001288 public synchronized void setGeolocationEnabled(boolean flag) {
1289 if (mGeolocationEnabled != flag) {
1290 mGeolocationEnabled = flag;
1291 postSync();
1292 }
1293 }
1294
1295 /**
1296 * Sets whether XSS Auditor is enabled.
Steve Block20a75452012-03-22 12:51:22 +00001297 * Only used by LayoutTestController.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001298 * @param flag Whether XSS Auditor should be enabled.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001299 */
1300 public synchronized void setXSSAuditorEnabled(boolean flag) {
1301 if (mXSSAuditorEnabled != flag) {
1302 mXSSAuditorEnabled = flag;
1303 postSync();
1304 }
1305 }
1306
1307 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001308 * @see android.webkit.WebSettings#getJavaScriptEnabled()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001309 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001310 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001311 public synchronized boolean getJavaScriptEnabled() {
1312 return mJavaScriptEnabled;
1313 }
1314
1315 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001316 * @see android.webkit.WebSettings#getPluginsEnabled()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001317 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001318 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001319 @Deprecated
1320 public synchronized boolean getPluginsEnabled() {
1321 return mPluginState == PluginState.ON;
1322 }
1323
1324 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001325 * @see android.webkit.WebSettings#getPluginState()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001326 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001327 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001328 public synchronized PluginState getPluginState() {
1329 return mPluginState;
1330 }
1331
1332 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001333 * @see android.webkit.WebSettings#getPluginsPath()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001334 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001335 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001336 @Deprecated
1337 public synchronized String getPluginsPath() {
1338 return "";
1339 }
1340
1341 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001342 * @see android.webkit.WebSettings#setJavaScriptCanOpenWindowsAutomatically(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001343 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001344 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001345 public synchronized void setJavaScriptCanOpenWindowsAutomatically(
1346 boolean flag) {
1347 if (mJavaScriptCanOpenWindowsAutomatically != flag) {
1348 mJavaScriptCanOpenWindowsAutomatically = flag;
1349 postSync();
1350 }
1351 }
1352
1353 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001354 * @see android.webkit.WebSettings#getJavaScriptCanOpenWindowsAutomatically()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001355 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001356 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001357 public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() {
1358 return mJavaScriptCanOpenWindowsAutomatically;
1359 }
1360
1361 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001362 * @see android.webkit.WebSettings#setDefaultTextEncodingName(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001363 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001364 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001365 public synchronized void setDefaultTextEncodingName(String encoding) {
1366 if (encoding != null && !encoding.equals(mDefaultTextEncoding)) {
1367 mDefaultTextEncoding = encoding;
1368 postSync();
1369 }
1370 }
1371
1372 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001373 * @see android.webkit.WebSettings#getDefaultTextEncodingName()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001374 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001375 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001376 public synchronized String getDefaultTextEncodingName() {
1377 return mDefaultTextEncoding;
1378 }
1379
1380 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001381 * @see android.webkit.WebSettings#setUserAgentString(java.lang.String)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001382 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001383 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001384 public synchronized void setUserAgentString(String ua) {
1385 if (ua == null || ua.length() == 0) {
1386 synchronized(sLockForLocaleSettings) {
1387 Locale currentLocale = Locale.getDefault();
1388 if (!sLocale.equals(currentLocale)) {
1389 sLocale = currentLocale;
1390 mAcceptLanguage = getCurrentAcceptLanguage();
1391 }
1392 }
1393 ua = getCurrentUserAgent();
1394 mUseDefaultUserAgent = true;
1395 } else {
1396 mUseDefaultUserAgent = false;
1397 }
1398
1399 if (!ua.equals(mUserAgent)) {
1400 mUserAgent = ua;
1401 postSync();
1402 }
1403 }
1404
1405 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001406 * @see android.webkit.WebSettings#getUserAgentString()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001407 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001408 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001409 public synchronized String getUserAgentString() {
1410 if (DESKTOP_USERAGENT.equals(mUserAgent) ||
1411 IPHONE_USERAGENT.equals(mUserAgent) ||
1412 !mUseDefaultUserAgent) {
1413 return mUserAgent;
1414 }
1415
1416 boolean doPostSync = false;
1417 synchronized(sLockForLocaleSettings) {
1418 Locale currentLocale = Locale.getDefault();
1419 if (!sLocale.equals(currentLocale)) {
1420 sLocale = currentLocale;
1421 mUserAgent = getCurrentUserAgent();
1422 mAcceptLanguage = getCurrentAcceptLanguage();
1423 doPostSync = true;
1424 }
1425 }
1426 if (doPostSync) {
1427 postSync();
1428 }
1429 return mUserAgent;
1430 }
1431
1432 /* package api to grab the Accept Language string. */
1433 /*package*/ synchronized String getAcceptLanguage() {
1434 synchronized(sLockForLocaleSettings) {
1435 Locale currentLocale = Locale.getDefault();
1436 if (!sLocale.equals(currentLocale)) {
1437 sLocale = currentLocale;
1438 mAcceptLanguage = getCurrentAcceptLanguage();
1439 }
1440 }
1441 return mAcceptLanguage;
1442 }
1443
1444 /* package */ boolean isNarrowColumnLayout() {
1445 return getLayoutAlgorithm() == LayoutAlgorithm.NARROW_COLUMNS;
1446 }
1447
1448 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001449 * @see android.webkit.WebSettings#setNeedInitialFocus(boolean)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001450 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001451 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001452 public void setNeedInitialFocus(boolean flag) {
1453 if (mNeedInitialFocus != flag) {
1454 mNeedInitialFocus = flag;
1455 }
1456 }
1457
1458 /* Package api to get the choice whether it needs to set initial focus. */
1459 /* package */ boolean getNeedInitialFocus() {
1460 return mNeedInitialFocus;
1461 }
1462
1463 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001464 * @see android.webkit.WebSettings#setRenderPriority(android.webkit.WebSettingsClassic.RenderPriority)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001465 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001466 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001467 public synchronized void setRenderPriority(RenderPriority priority) {
1468 if (mRenderPriority != priority) {
1469 mRenderPriority = priority;
1470 mEventHandler.sendMessage(Message.obtain(null,
1471 EventHandler.PRIORITY));
1472 }
1473 }
1474
1475 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001476 * @see android.webkit.WebSettings#setCacheMode(int)
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001477 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001478 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001479 public void setCacheMode(int mode) {
1480 if (mode != mOverrideCacheMode) {
1481 mOverrideCacheMode = mode;
1482 postSync();
1483 }
1484 }
1485
1486 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001487 * @see android.webkit.WebSettings#getCacheMode()
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001488 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001489 @Override
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001490 public int getCacheMode() {
1491 return mOverrideCacheMode;
1492 }
1493
1494 /**
1495 * If set, webkit alternately shrinks and expands images viewed outside
1496 * of an HTML page to fit the screen. This conflicts with attempts by
1497 * the UI to zoom in and out of an image, so it is set false by default.
1498 * @param shrink Set true to let webkit shrink the standalone image to fit.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001499 */
1500 public void setShrinksStandaloneImagesToFit(boolean shrink) {
1501 if (mShrinksStandaloneImagesToFit != shrink) {
1502 mShrinksStandaloneImagesToFit = shrink;
1503 postSync();
1504 }
1505 }
1506
1507 /**
1508 * Specify the maximum decoded image size. The default is
1509 * 2 megs for small memory devices and 8 megs for large memory devices.
1510 * @param size The maximum decoded size, or zero to set to the default.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001511 */
1512 public void setMaximumDecodedImageSize(long size) {
1513 if (mMaximumDecodedImageSize != size) {
1514 mMaximumDecodedImageSize = size;
1515 postSync();
1516 }
1517 }
1518
1519 /**
1520 * Returns whether to use fixed viewport. Use fixed viewport
1521 * whenever wide viewport is on.
1522 */
1523 /* package */ boolean getUseFixedViewport() {
1524 return getUseWideViewPort();
1525 }
1526
1527 /**
1528 * Returns whether private browsing is enabled.
1529 */
1530 /* package */ boolean isPrivateBrowsingEnabled() {
1531 return mPrivateBrowsingEnabled;
1532 }
1533
1534 /**
1535 * Sets whether private browsing is enabled.
1536 * @param flag Whether private browsing should be enabled.
1537 */
1538 /* package */ synchronized void setPrivateBrowsingEnabled(boolean flag) {
1539 if (mPrivateBrowsingEnabled != flag) {
1540 mPrivateBrowsingEnabled = flag;
1541
1542 // AutoFill is dependant on private browsing being enabled so
1543 // reset it to take account of the new value of mPrivateBrowsingEnabled.
1544 setAutoFillEnabled(mAutoFillEnabled);
1545
1546 postSync();
1547 }
1548 }
1549
1550 /**
1551 * Returns whether the viewport metatag can disable zooming
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001552 */
1553 public boolean forceUserScalable() {
1554 return mForceUserScalable;
1555 }
1556
1557 /**
1558 * Sets whether viewport metatag can disable zooming.
1559 * @param flag Whether or not to forceably enable user scalable.
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001560 */
1561 public synchronized void setForceUserScalable(boolean flag) {
1562 mForceUserScalable = flag;
1563 }
1564
1565 synchronized void setSyntheticLinksEnabled(boolean flag) {
1566 if (mSyntheticLinksEnabled != flag) {
1567 mSyntheticLinksEnabled = flag;
1568 postSync();
1569 }
1570 }
1571
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001572 public synchronized void setAutoFillEnabled(boolean enabled) {
1573 // AutoFill is always disabled in private browsing mode.
1574 boolean autoFillEnabled = enabled && !mPrivateBrowsingEnabled;
1575 if (mAutoFillEnabled != autoFillEnabled) {
1576 mAutoFillEnabled = autoFillEnabled;
1577 postSync();
1578 }
1579 }
1580
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001581 public synchronized boolean getAutoFillEnabled() {
1582 return mAutoFillEnabled;
1583 }
1584
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001585 public synchronized void setAutoFillProfile(AutoFillProfile profile) {
1586 if (mAutoFillProfile != profile) {
1587 mAutoFillProfile = profile;
1588 postSync();
1589 }
1590 }
1591
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001592 public synchronized AutoFillProfile getAutoFillProfile() {
1593 return mAutoFillProfile;
1594 }
1595
1596 int getDoubleTapToastCount() {
1597 return mDoubleTapToastCount;
1598 }
1599
1600 void setDoubleTapToastCount(int count) {
1601 if (mDoubleTapToastCount != count) {
1602 mDoubleTapToastCount = count;
1603 // write the settings in the non-UI thread
1604 mEventHandler.sendMessage(Message.obtain(null,
1605 EventHandler.SET_DOUBLE_TAP_TOAST_COUNT));
1606 }
1607 }
1608
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001609 public void setProperty(String key, String value) {
1610 if (mWebView.nativeSetProperty(key, value)) {
John Reck9a5f5652012-03-20 16:01:26 -07001611 mWebView.invalidate();
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001612 }
1613 }
1614
Jonathan Dixonded37ed92012-02-13 17:26:46 -08001615 public String getProperty(String key) {
1616 return mWebView.nativeGetProperty(key);
1617 }
1618
1619 /**
1620 * Transfer messages from the queue to the new WebCoreThread. Called from
1621 * WebCore thread.
1622 */
1623 /*package*/
1624 synchronized void syncSettingsAndCreateHandler(BrowserFrame frame) {
1625 mBrowserFrame = frame;
1626 if (DebugFlags.WEB_SETTINGS) {
1627 junit.framework.Assert.assertTrue(frame.mNativeFrame != 0);
1628 }
1629
1630 SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE,
1631 Context.MODE_PRIVATE);
1632 if (mDoubleTapToastCount > 0) {
1633 mDoubleTapToastCount = sp.getInt(DOUBLE_TAP_TOAST_COUNT,
1634 mDoubleTapToastCount);
1635 }
1636 nativeSync(frame.mNativeFrame);
1637 mSyncPending = false;
1638 mEventHandler.createHandler();
1639 }
1640
1641 /**
1642 * Let the Settings object know that our owner is being destroyed.
1643 */
1644 /*package*/
1645 synchronized void onDestroyed() {
1646 }
1647
1648 private int pin(int size) {
1649 // FIXME: 72 is just an arbitrary max text size value.
1650 if (size < 1) {
1651 return 1;
1652 } else if (size > 72) {
1653 return 72;
1654 }
1655 return size;
1656 }
1657
1658 /* Post a SYNC message to handle syncing the native settings. */
1659 private synchronized void postSync() {
1660 // Only post if a sync is not pending
1661 if (!mSyncPending) {
1662 mSyncPending = mEventHandler.sendMessage(
1663 Message.obtain(null, EventHandler.SYNC));
1664 }
1665 }
1666
1667 // Synchronize the native and java settings.
1668 private native void nativeSync(int nativeFrame);
1669}