• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.android_webview;
6 
7 import android.content.Context;
8 import android.content.pm.PackageManager;
9 import android.os.Handler;
10 import android.os.Message;
11 import android.os.Process;
12 import android.provider.Settings;
13 import android.util.Log;
14 import android.webkit.WebSettings;
15 import android.webkit.WebSettings.PluginState;
16 
17 import org.chromium.base.CalledByNative;
18 import org.chromium.base.JNINamespace;
19 import org.chromium.base.ThreadUtils;
20 
21 /**
22  * Stores Android WebView specific settings that does not need to be synced to WebKit.
23  * Use {@link org.chromium.content.browser.ContentSettings} for WebKit settings.
24  *
25  * Methods in this class can be called from any thread, including threads created by
26  * the client of WebView.
27  */
28 @JNINamespace("android_webview")
29 public class AwSettings {
30     // This enum corresponds to WebSettings.LayoutAlgorithm. We use our own to be
31     // able to extend it.
32     public enum LayoutAlgorithm {
33         NORMAL,
34         SINGLE_COLUMN,
35         NARROW_COLUMNS,
36         TEXT_AUTOSIZING,
37     }
38 
39     private static final String TAG = "AwSettings";
40 
41     // This class must be created on the UI thread. Afterwards, it can be
42     // used from any thread. Internally, the class uses a message queue
43     // to call native code on the UI thread only.
44 
45     // Values passed in on construction.
46     private final boolean mHasInternetPermission;
47 
48     private ZoomSupportChangeListener mZoomChangeListener;
49     private double mDIPScale = 1.0;
50 
51     // Lock to protect all settings.
52     private final Object mAwSettingsLock = new Object();
53 
54     private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
55     private int mTextSizePercent = 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     // TODO(mnaganov): Should be obtained from Android. Problem: it is hidden.
63     private String mDefaultTextEncoding = "Latin-1";
64     private String mUserAgent;
65     private int mMinimumFontSize = 8;
66     private int mMinimumLogicalFontSize = 8;
67     private int mDefaultFontSize = 16;
68     private int mDefaultFixedFontSize = 13;
69     private boolean mLoadsImagesAutomatically = true;
70     private boolean mImagesEnabled = true;
71     private boolean mJavaScriptEnabled = false;
72     private boolean mAllowUniversalAccessFromFileURLs = false;
73     private boolean mAllowFileAccessFromFileURLs = false;
74     private boolean mJavaScriptCanOpenWindowsAutomatically = false;
75     private boolean mSupportMultipleWindows = false;
76     private PluginState mPluginState = PluginState.OFF;
77     private boolean mAppCacheEnabled = false;
78     private boolean mDomStorageEnabled = false;
79     private boolean mDatabaseEnabled = false;
80     private boolean mUseWideViewport = false;
81     private boolean mLoadWithOverviewMode = false;
82     private boolean mMediaPlaybackRequiresUserGesture = true;
83     private String mDefaultVideoPosterURL;
84     private float mInitialPageScalePercent = 0;
85     private boolean mSpatialNavigationEnabled;  // Default depends on device features.
86     private boolean mEnableSupportedHardwareAcceleratedFeatures = false;
87 
88     private final boolean mSupportLegacyQuirks;
89 
90     private final boolean mPasswordEchoEnabled;
91 
92     // Not accessed by the native side.
93     private boolean mBlockNetworkLoads;  // Default depends on permission of embedding APK.
94     private boolean mAllowContentUrlAccess = true;
95     private boolean mAllowFileUrlAccess = true;
96     private int mCacheMode = WebSettings.LOAD_DEFAULT;
97     private boolean mShouldFocusFirstNode = true;
98     private boolean mGeolocationEnabled = true;
99     private boolean mAutoCompleteEnabled = true;
100     private boolean mSupportZoom = true;
101     private boolean mBuiltInZoomControls = false;
102     private boolean mDisplayZoomControls = true;
103 
104     static class LazyDefaultUserAgent{
105         // Lazy Holder pattern
106         private static final String sInstance = nativeGetDefaultUserAgent();
107     }
108 
109     // Protects access to settings global fields.
110     private static final Object sGlobalContentSettingsLock = new Object();
111     // For compatibility with the legacy WebView, we can only enable AppCache when the path is
112     // provided. However, we don't use the path, so we just check if we have received it from the
113     // client.
114     private static boolean sAppCachePathIsSet = false;
115 
116     // The native side of this object. It's lifetime is bounded by the WebContent it is attached to.
117     private long mNativeAwSettings = 0;
118 
119     // Custom handler that queues messages to call native code on the UI thread.
120     private final EventHandler mEventHandler;
121 
122     private static final int MINIMUM_FONT_SIZE = 1;
123     private static final int MAXIMUM_FONT_SIZE = 72;
124 
125     // Class to handle messages to be processed on the UI thread.
126     private class EventHandler {
127         // Message id for running a Runnable with mAwSettingsLock held.
128         private static final int RUN_RUNNABLE_BLOCKING = 0;
129         // Actual UI thread handler
130         private Handler mHandler;
131         // Synchronization flag.
132         private boolean mSynchronizationPending = false;
133 
EventHandler()134         EventHandler() {
135         }
136 
bindUiThread()137         void bindUiThread() {
138             if (mHandler != null) return;
139             mHandler = new Handler(ThreadUtils.getUiThreadLooper()) {
140                 @Override
141                 public void handleMessage(Message msg) {
142                     switch (msg.what) {
143                         case RUN_RUNNABLE_BLOCKING:
144                             synchronized (mAwSettingsLock) {
145                                 if (mNativeAwSettings != 0) {
146                                     ((Runnable)msg.obj).run();
147                                 }
148                                 mSynchronizationPending = false;
149                                 mAwSettingsLock.notifyAll();
150                             }
151                             break;
152                     }
153                 }
154             };
155         }
156 
runOnUiThreadBlockingAndLocked(Runnable r)157         void runOnUiThreadBlockingAndLocked(Runnable r) {
158             assert Thread.holdsLock(mAwSettingsLock);
159             if (mHandler == null) return;
160             if (ThreadUtils.runningOnUiThread()) {
161                 r.run();
162             } else {
163                 assert !mSynchronizationPending;
164                 mSynchronizationPending = true;
165                 mHandler.sendMessage(Message.obtain(null, RUN_RUNNABLE_BLOCKING, r));
166                 try {
167                     while (mSynchronizationPending) {
168                         mAwSettingsLock.wait();
169                     }
170                 } catch (InterruptedException e) {
171                     Log.e(TAG, "Interrupted waiting a Runnable to complete", e);
172                     mSynchronizationPending = false;
173                 }
174             }
175         }
176 
maybePostOnUiThread(Runnable r)177         void maybePostOnUiThread(Runnable r) {
178             if (mHandler != null) {
179                 mHandler.post(r);
180             }
181         }
182 
updateWebkitPreferencesLocked()183         void updateWebkitPreferencesLocked() {
184             runOnUiThreadBlockingAndLocked(new Runnable() {
185                 @Override
186                 public void run() {
187                     updateWebkitPreferencesOnUiThreadLocked();
188                 }
189             });
190         }
191     }
192 
193     interface ZoomSupportChangeListener {
onGestureZoomSupportChanged( boolean supportsDoubleTapZoom, boolean supportsMultiTouchZoom)194         public void onGestureZoomSupportChanged(
195                 boolean supportsDoubleTapZoom, boolean supportsMultiTouchZoom);
196     }
197 
AwSettings(Context context, boolean isAccessFromFileURLsGrantedByDefault, boolean supportsLegacyQuirks)198     public AwSettings(Context context,
199             boolean isAccessFromFileURLsGrantedByDefault,
200             boolean supportsLegacyQuirks) {
201        boolean hasInternetPermission = context.checkPermission(
202                     android.Manifest.permission.INTERNET,
203                     Process.myPid(),
204                     Process.myUid()) == PackageManager.PERMISSION_GRANTED;
205         synchronized (mAwSettingsLock) {
206             mHasInternetPermission = hasInternetPermission;
207             mBlockNetworkLoads = !hasInternetPermission;
208             mEventHandler = new EventHandler();
209             if (isAccessFromFileURLsGrantedByDefault) {
210                 mAllowUniversalAccessFromFileURLs = true;
211                 mAllowFileAccessFromFileURLs = true;
212             }
213 
214             mUserAgent = LazyDefaultUserAgent.sInstance;
215 
216             // Best-guess a sensible initial value based on the features supported on the device.
217             mSpatialNavigationEnabled = !context.getPackageManager().hasSystemFeature(
218                     PackageManager.FEATURE_TOUCHSCREEN);
219 
220             // Respect the system setting for password echoing.
221             mPasswordEchoEnabled = Settings.System.getInt(context.getContentResolver(),
222                     Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;
223 
224             // By default, scale the text size by the system font scale factor. Embedders
225             // may override this by invoking setTextZoom().
226             mTextSizePercent *= context.getResources().getConfiguration().fontScale;
227 
228             mSupportLegacyQuirks = supportsLegacyQuirks;
229         }
230         // Defer initializing the native side until a native WebContents instance is set.
231     }
232 
233     @CalledByNative
nativeAwSettingsGone(long nativeAwSettings)234     private void nativeAwSettingsGone(long nativeAwSettings) {
235         assert mNativeAwSettings != 0 && mNativeAwSettings == nativeAwSettings;
236         mNativeAwSettings = 0;
237     }
238 
239     @CalledByNative
getDIPScaleLocked()240     private double getDIPScaleLocked() {
241         assert Thread.holdsLock(mAwSettingsLock);
242         return mDIPScale;
243     }
244 
setDIPScale(double dipScale)245     void setDIPScale(double dipScale) {
246         synchronized (mAwSettingsLock) {
247             mDIPScale = dipScale;
248             // TODO(joth): This should also be synced over to native side, but right now
249             // the setDIPScale call is always followed by a setWebContents() which covers this.
250         }
251     }
252 
setZoomListener(ZoomSupportChangeListener zoomChangeListener)253     void setZoomListener(ZoomSupportChangeListener zoomChangeListener) {
254         synchronized (mAwSettingsLock) {
255             mZoomChangeListener = zoomChangeListener;
256         }
257     }
258 
setWebContents(int nativeWebContents)259     void setWebContents(int nativeWebContents) {
260         synchronized (mAwSettingsLock) {
261             if (mNativeAwSettings != 0) {
262                 nativeDestroy(mNativeAwSettings);
263                 assert mNativeAwSettings == 0;  // nativeAwSettingsGone should have been called.
264             }
265             if (nativeWebContents != 0) {
266                 mEventHandler.bindUiThread();
267                 mNativeAwSettings = nativeInit(nativeWebContents);
268                 nativeUpdateEverythingLocked(mNativeAwSettings);
269                 onGestureZoomSupportChanged(
270                         supportsDoubleTapZoomLocked(), supportsMultiTouchZoomLocked());
271             }
272         }
273     }
274 
275     /**
276      * See {@link android.webkit.WebSettings#setBlockNetworkLoads}.
277      */
setBlockNetworkLoads(boolean flag)278     public void setBlockNetworkLoads(boolean flag) {
279         synchronized (mAwSettingsLock) {
280             if (!flag && !mHasInternetPermission) {
281                 throw new SecurityException("Permission denied - " +
282                         "application missing INTERNET permission");
283             }
284             mBlockNetworkLoads = flag;
285         }
286     }
287 
288     /**
289      * See {@link android.webkit.WebSettings#getBlockNetworkLoads}.
290      */
getBlockNetworkLoads()291     public boolean getBlockNetworkLoads() {
292         synchronized (mAwSettingsLock) {
293             return mBlockNetworkLoads;
294         }
295     }
296 
297     /**
298      * See {@link android.webkit.WebSettings#setAllowFileAccess}.
299      */
setAllowFileAccess(boolean allow)300     public void setAllowFileAccess(boolean allow) {
301         synchronized (mAwSettingsLock) {
302             if (mAllowFileUrlAccess != allow) {
303                 mAllowFileUrlAccess = allow;
304             }
305         }
306     }
307 
308     /**
309      * See {@link android.webkit.WebSettings#getAllowFileAccess}.
310      */
getAllowFileAccess()311     public boolean getAllowFileAccess() {
312         synchronized (mAwSettingsLock) {
313             return mAllowFileUrlAccess;
314         }
315     }
316 
317     /**
318      * See {@link android.webkit.WebSettings#setAllowContentAccess}.
319      */
setAllowContentAccess(boolean allow)320     public void setAllowContentAccess(boolean allow) {
321         synchronized (mAwSettingsLock) {
322             if (mAllowContentUrlAccess != allow) {
323                 mAllowContentUrlAccess = allow;
324             }
325         }
326     }
327 
328     /**
329      * See {@link android.webkit.WebSettings#getAllowContentAccess}.
330      */
getAllowContentAccess()331     public boolean getAllowContentAccess() {
332         synchronized (mAwSettingsLock) {
333             return mAllowContentUrlAccess;
334         }
335     }
336 
337     /**
338      * See {@link android.webkit.WebSettings#setCacheMode}.
339      */
setCacheMode(int mode)340     public void setCacheMode(int mode) {
341         synchronized (mAwSettingsLock) {
342             if (mCacheMode != mode) {
343                 mCacheMode = mode;
344             }
345         }
346     }
347 
348     /**
349      * See {@link android.webkit.WebSettings#getCacheMode}.
350      */
getCacheMode()351     public int getCacheMode() {
352         synchronized (mAwSettingsLock) {
353             return mCacheMode;
354         }
355     }
356 
357     /**
358      * See {@link android.webkit.WebSettings#setNeedInitialFocus}.
359      */
setShouldFocusFirstNode(boolean flag)360     public void setShouldFocusFirstNode(boolean flag) {
361         synchronized (mAwSettingsLock) {
362             mShouldFocusFirstNode = flag;
363         }
364     }
365 
366     /**
367      * See {@link android.webkit.WebView#setInitialScale}.
368      */
setInitialPageScale(final float scaleInPercent)369     public void setInitialPageScale(final float scaleInPercent) {
370         synchronized (mAwSettingsLock) {
371             if (mInitialPageScalePercent != scaleInPercent) {
372                 mInitialPageScalePercent = scaleInPercent;
373                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
374                     @Override
375                     public void run() {
376                         nativeUpdateInitialPageScaleLocked(mNativeAwSettings);
377                     }
378                 });
379             }
380         }
381     }
382 
383     @CalledByNative
getInitialPageScalePercentLocked()384     private float getInitialPageScalePercentLocked() {
385         assert Thread.holdsLock(mAwSettingsLock);
386         return mInitialPageScalePercent;
387     }
388 
setSpatialNavigationEnabled(boolean enable)389     void setSpatialNavigationEnabled(boolean enable) {
390         synchronized (mAwSettingsLock) {
391             if (mSpatialNavigationEnabled != enable) {
392                 mSpatialNavigationEnabled = enable;
393                 mEventHandler.updateWebkitPreferencesLocked();
394             }
395         }
396     }
397 
398     @CalledByNative
getSpatialNavigationLocked()399     private boolean getSpatialNavigationLocked() {
400         assert Thread.holdsLock(mAwSettingsLock);
401         return mSpatialNavigationEnabled;
402     }
403 
setEnableSupportedHardwareAcceleratedFeatures(boolean enable)404     void setEnableSupportedHardwareAcceleratedFeatures(boolean enable) {
405         synchronized (mAwSettingsLock) {
406             if (mEnableSupportedHardwareAcceleratedFeatures != enable) {
407                 mEnableSupportedHardwareAcceleratedFeatures = enable;
408                 mEventHandler.updateWebkitPreferencesLocked();
409             }
410         }
411     }
412 
413     @CalledByNative
getEnableSupportedHardwareAcceleratedFeaturesLocked()414     private boolean getEnableSupportedHardwareAcceleratedFeaturesLocked() {
415         return mEnableSupportedHardwareAcceleratedFeatures;
416     }
417 
418     /**
419      * See {@link android.webkit.WebSettings#setNeedInitialFocus}.
420      */
shouldFocusFirstNode()421     public boolean shouldFocusFirstNode() {
422         synchronized (mAwSettingsLock) {
423             return mShouldFocusFirstNode;
424         }
425     }
426 
427     /**
428      * See {@link android.webkit.WebSettings#setGeolocationEnabled}.
429      */
setGeolocationEnabled(boolean flag)430     public void setGeolocationEnabled(boolean flag) {
431         synchronized (mAwSettingsLock) {
432             if (mGeolocationEnabled != flag) {
433                 mGeolocationEnabled = flag;
434             }
435         }
436     }
437 
438     /**
439      * @return Returns if geolocation is currently enabled.
440      */
getGeolocationEnabled()441     boolean getGeolocationEnabled() {
442         synchronized (mAwSettingsLock) {
443             return mGeolocationEnabled;
444         }
445     }
446 
447     /**
448      * See {@link android.webkit.WebSettings#setSaveFormData}.
449      */
setSaveFormData(final boolean enable)450     public void setSaveFormData(final boolean enable) {
451         synchronized (mAwSettingsLock) {
452             if (mAutoCompleteEnabled != enable) {
453                 mAutoCompleteEnabled = enable;
454                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
455                     @Override
456                     public void run() {
457                         nativeUpdateFormDataPreferencesLocked(mNativeAwSettings);
458                     }
459                 });
460             }
461         }
462     }
463 
464     /**
465      * See {@link android.webkit.WebSettings#getSaveFormData}.
466      */
getSaveFormData()467     public boolean getSaveFormData() {
468         synchronized (mAwSettingsLock) {
469             return getSaveFormDataLocked();
470         }
471     }
472 
473     @CalledByNative
getSaveFormDataLocked()474     private boolean getSaveFormDataLocked() {
475         assert Thread.holdsLock(mAwSettingsLock);
476         return mAutoCompleteEnabled;
477     }
478 
479     /**
480      * @returns the default User-Agent used by each ContentViewCore instance, i.e. unless
481      * overridden by {@link #setUserAgentString()}
482      */
getDefaultUserAgent()483     public static String getDefaultUserAgent() {
484         return LazyDefaultUserAgent.sInstance;
485     }
486 
487     /**
488      * See {@link android.webkit.WebSettings#setUserAgentString}.
489      */
setUserAgentString(String ua)490     public void setUserAgentString(String ua) {
491         synchronized (mAwSettingsLock) {
492             final String oldUserAgent = mUserAgent;
493             if (ua == null || ua.length() == 0) {
494                 mUserAgent = LazyDefaultUserAgent.sInstance;
495             } else {
496                 mUserAgent = ua;
497             }
498             if (!oldUserAgent.equals(mUserAgent)) {
499                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
500                     @Override
501                     public void run() {
502                         nativeUpdateUserAgentLocked(mNativeAwSettings);
503                     }
504                 });
505             }
506         }
507     }
508 
509     /**
510      * See {@link android.webkit.WebSettings#getUserAgentString}.
511      */
getUserAgentString()512     public String getUserAgentString() {
513         synchronized (mAwSettingsLock) {
514             return mUserAgent;
515         }
516     }
517 
518     @CalledByNative
getUserAgentLocked()519     private String getUserAgentLocked() {
520         assert Thread.holdsLock(mAwSettingsLock);
521         return mUserAgent;
522     }
523 
524     /**
525      * See {@link android.webkit.WebSettings#setLoadWithOverviewMode}.
526      */
setLoadWithOverviewMode(boolean overview)527     public void setLoadWithOverviewMode(boolean overview) {
528         synchronized (mAwSettingsLock) {
529             if (mLoadWithOverviewMode != overview) {
530                 mLoadWithOverviewMode = overview;
531                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
532                     @Override
533                     public void run() {
534                         updateWebkitPreferencesOnUiThreadLocked();
535                         nativeResetScrollAndScaleState(mNativeAwSettings);
536                     }
537                 });
538             }
539         }
540     }
541 
542     /**
543      * See {@link android.webkit.WebSettings#getLoadWithOverviewMode}.
544      */
getLoadWithOverviewMode()545     public boolean getLoadWithOverviewMode() {
546         synchronized (mAwSettingsLock) {
547             return mLoadWithOverviewMode;
548         }
549     }
550 
551     @CalledByNative
getLoadWithOverviewModeLocked()552     private boolean getLoadWithOverviewModeLocked() {
553         assert Thread.holdsLock(mAwSettingsLock);
554         return mLoadWithOverviewMode;
555     }
556 
557     /**
558      * See {@link android.webkit.WebSettings#setTextZoom}.
559      */
setTextZoom(final int textZoom)560     public void setTextZoom(final int textZoom) {
561         synchronized (mAwSettingsLock) {
562             if (mTextSizePercent != textZoom) {
563                 mTextSizePercent = textZoom;
564                 mEventHandler.updateWebkitPreferencesLocked();
565             }
566         }
567     }
568 
569     /**
570      * See {@link android.webkit.WebSettings#getTextZoom}.
571      */
getTextZoom()572     public int getTextZoom() {
573         synchronized (mAwSettingsLock) {
574             return mTextSizePercent;
575         }
576     }
577 
578     @CalledByNative
getTextSizePercentLocked()579     private int getTextSizePercentLocked() {
580         assert Thread.holdsLock(mAwSettingsLock);
581         return mTextSizePercent;
582     }
583 
584     /**
585      * See {@link android.webkit.WebSettings#setStandardFontFamily}.
586      */
setStandardFontFamily(String font)587     public void setStandardFontFamily(String font) {
588         synchronized (mAwSettingsLock) {
589             if (font != null && !mStandardFontFamily.equals(font)) {
590                 mStandardFontFamily = font;
591                 mEventHandler.updateWebkitPreferencesLocked();
592             }
593         }
594     }
595 
596     /**
597      * See {@link android.webkit.WebSettings#getStandardFontFamily}.
598      */
getStandardFontFamily()599     public String getStandardFontFamily() {
600         synchronized (mAwSettingsLock) {
601             return mStandardFontFamily;
602         }
603     }
604 
605     @CalledByNative
getStandardFontFamilyLocked()606     private String getStandardFontFamilyLocked() {
607         assert Thread.holdsLock(mAwSettingsLock);
608         return mStandardFontFamily;
609     }
610 
611     /**
612      * See {@link android.webkit.WebSettings#setFixedFontFamily}.
613      */
setFixedFontFamily(String font)614     public void setFixedFontFamily(String font) {
615         synchronized (mAwSettingsLock) {
616             if (font != null && !mFixedFontFamily.equals(font)) {
617                 mFixedFontFamily = font;
618                 mEventHandler.updateWebkitPreferencesLocked();
619             }
620         }
621     }
622 
623     /**
624      * See {@link android.webkit.WebSettings#getFixedFontFamily}.
625      */
getFixedFontFamily()626     public String getFixedFontFamily() {
627         synchronized (mAwSettingsLock) {
628             return mFixedFontFamily;
629         }
630     }
631 
632     @CalledByNative
getFixedFontFamilyLocked()633     private String getFixedFontFamilyLocked() {
634         assert Thread.holdsLock(mAwSettingsLock);
635         return mFixedFontFamily;
636     }
637 
638     /**
639      * See {@link android.webkit.WebSettings#setSansSerifFontFamily}.
640      */
setSansSerifFontFamily(String font)641     public void setSansSerifFontFamily(String font) {
642         synchronized (mAwSettingsLock) {
643             if (font != null && !mSansSerifFontFamily.equals(font)) {
644                 mSansSerifFontFamily = font;
645                 mEventHandler.updateWebkitPreferencesLocked();
646             }
647         }
648     }
649 
650     /**
651      * See {@link android.webkit.WebSettings#getSansSerifFontFamily}.
652      */
getSansSerifFontFamily()653     public String getSansSerifFontFamily() {
654         synchronized (mAwSettingsLock) {
655             return mSansSerifFontFamily;
656         }
657     }
658 
659     @CalledByNative
getSansSerifFontFamilyLocked()660     private String getSansSerifFontFamilyLocked() {
661         assert Thread.holdsLock(mAwSettingsLock);
662         return mSansSerifFontFamily;
663     }
664 
665     /**
666      * See {@link android.webkit.WebSettings#setSerifFontFamily}.
667      */
setSerifFontFamily(String font)668     public void setSerifFontFamily(String font) {
669         synchronized (mAwSettingsLock) {
670             if (font != null && !mSerifFontFamily.equals(font)) {
671                 mSerifFontFamily = font;
672                 mEventHandler.updateWebkitPreferencesLocked();
673             }
674         }
675     }
676 
677     /**
678      * See {@link android.webkit.WebSettings#getSerifFontFamily}.
679      */
getSerifFontFamily()680     public String getSerifFontFamily() {
681         synchronized (mAwSettingsLock) {
682             return mSerifFontFamily;
683         }
684     }
685 
686     @CalledByNative
getSerifFontFamilyLocked()687     private String getSerifFontFamilyLocked() {
688         assert Thread.holdsLock(mAwSettingsLock);
689         return mSerifFontFamily;
690     }
691 
692     /**
693      * See {@link android.webkit.WebSettings#setCursiveFontFamily}.
694      */
setCursiveFontFamily(String font)695     public void setCursiveFontFamily(String font) {
696         synchronized (mAwSettingsLock) {
697             if (font != null && !mCursiveFontFamily.equals(font)) {
698                 mCursiveFontFamily = font;
699                 mEventHandler.updateWebkitPreferencesLocked();
700             }
701         }
702     }
703 
704     /**
705      * See {@link android.webkit.WebSettings#getCursiveFontFamily}.
706      */
getCursiveFontFamily()707     public String getCursiveFontFamily() {
708         synchronized (mAwSettingsLock) {
709             return mCursiveFontFamily;
710         }
711     }
712 
713     @CalledByNative
getCursiveFontFamilyLocked()714     private String getCursiveFontFamilyLocked() {
715         assert Thread.holdsLock(mAwSettingsLock);
716         return mCursiveFontFamily;
717     }
718 
719     /**
720      * See {@link android.webkit.WebSettings#setFantasyFontFamily}.
721      */
setFantasyFontFamily(String font)722     public void setFantasyFontFamily(String font) {
723         synchronized (mAwSettingsLock) {
724             if (font != null && !mFantasyFontFamily.equals(font)) {
725                 mFantasyFontFamily = font;
726                 mEventHandler.updateWebkitPreferencesLocked();
727             }
728         }
729     }
730 
731     /**
732      * See {@link android.webkit.WebSettings#getFantasyFontFamily}.
733      */
getFantasyFontFamily()734     public String getFantasyFontFamily() {
735         synchronized (mAwSettingsLock) {
736             return mFantasyFontFamily;
737         }
738     }
739 
740     @CalledByNative
getFantasyFontFamilyLocked()741     private String getFantasyFontFamilyLocked() {
742         assert Thread.holdsLock(mAwSettingsLock);
743         return mFantasyFontFamily;
744     }
745 
746     /**
747      * See {@link android.webkit.WebSettings#setMinimumFontSize}.
748      */
setMinimumFontSize(int size)749     public void setMinimumFontSize(int size) {
750         synchronized (mAwSettingsLock) {
751             size = clipFontSize(size);
752             if (mMinimumFontSize != size) {
753                 mMinimumFontSize = size;
754                 mEventHandler.updateWebkitPreferencesLocked();
755             }
756         }
757     }
758 
759     /**
760      * See {@link android.webkit.WebSettings#getMinimumFontSize}.
761      */
getMinimumFontSize()762     public int getMinimumFontSize() {
763         synchronized (mAwSettingsLock) {
764             return mMinimumFontSize;
765         }
766     }
767 
768     @CalledByNative
getMinimumFontSizeLocked()769     private int getMinimumFontSizeLocked() {
770         assert Thread.holdsLock(mAwSettingsLock);
771         return mMinimumFontSize;
772     }
773 
774     /**
775      * See {@link android.webkit.WebSettings#setMinimumLogicalFontSize}.
776      */
setMinimumLogicalFontSize(int size)777     public void setMinimumLogicalFontSize(int size) {
778         synchronized (mAwSettingsLock) {
779             size = clipFontSize(size);
780             if (mMinimumLogicalFontSize != size) {
781                 mMinimumLogicalFontSize = size;
782                 mEventHandler.updateWebkitPreferencesLocked();
783             }
784         }
785     }
786 
787     /**
788      * See {@link android.webkit.WebSettings#getMinimumLogicalFontSize}.
789      */
getMinimumLogicalFontSize()790     public int getMinimumLogicalFontSize() {
791         synchronized (mAwSettingsLock) {
792             return mMinimumLogicalFontSize;
793         }
794     }
795 
796     @CalledByNative
getMinimumLogicalFontSizeLocked()797     private int getMinimumLogicalFontSizeLocked() {
798         assert Thread.holdsLock(mAwSettingsLock);
799         return mMinimumLogicalFontSize;
800     }
801 
802     /**
803      * See {@link android.webkit.WebSettings#setDefaultFontSize}.
804      */
setDefaultFontSize(int size)805     public void setDefaultFontSize(int size) {
806         synchronized (mAwSettingsLock) {
807             size = clipFontSize(size);
808             if (mDefaultFontSize != size) {
809                 mDefaultFontSize = size;
810                 mEventHandler.updateWebkitPreferencesLocked();
811             }
812         }
813     }
814 
815     /**
816      * See {@link android.webkit.WebSettings#getDefaultFontSize}.
817      */
getDefaultFontSize()818     public int getDefaultFontSize() {
819         synchronized (mAwSettingsLock) {
820             return mDefaultFontSize;
821         }
822     }
823 
824     @CalledByNative
getDefaultFontSizeLocked()825     private int getDefaultFontSizeLocked() {
826         assert Thread.holdsLock(mAwSettingsLock);
827         return mDefaultFontSize;
828     }
829 
830     /**
831      * See {@link android.webkit.WebSettings#setDefaultFixedFontSize}.
832      */
setDefaultFixedFontSize(int size)833     public void setDefaultFixedFontSize(int size) {
834         synchronized (mAwSettingsLock) {
835             size = clipFontSize(size);
836             if (mDefaultFixedFontSize != size) {
837                 mDefaultFixedFontSize = size;
838                 mEventHandler.updateWebkitPreferencesLocked();
839             }
840         }
841     }
842 
843     /**
844      * See {@link android.webkit.WebSettings#getDefaultFixedFontSize}.
845      */
getDefaultFixedFontSize()846     public int getDefaultFixedFontSize() {
847         synchronized (mAwSettingsLock) {
848             return mDefaultFixedFontSize;
849         }
850     }
851 
852     @CalledByNative
getDefaultFixedFontSizeLocked()853     private int getDefaultFixedFontSizeLocked() {
854         assert Thread.holdsLock(mAwSettingsLock);
855         return mDefaultFixedFontSize;
856     }
857 
858     /**
859      * See {@link android.webkit.WebSettings#setJavaScriptEnabled}.
860      */
setJavaScriptEnabled(boolean flag)861     public void setJavaScriptEnabled(boolean flag) {
862         synchronized (mAwSettingsLock) {
863             if (mJavaScriptEnabled != flag) {
864                 mJavaScriptEnabled = flag;
865                 mEventHandler.updateWebkitPreferencesLocked();
866             }
867         }
868     }
869 
870     /**
871      * See {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs}.
872      */
setAllowUniversalAccessFromFileURLs(boolean flag)873     public void setAllowUniversalAccessFromFileURLs(boolean flag) {
874         synchronized (mAwSettingsLock) {
875             if (mAllowUniversalAccessFromFileURLs != flag) {
876                 mAllowUniversalAccessFromFileURLs = flag;
877                 mEventHandler.updateWebkitPreferencesLocked();
878             }
879         }
880     }
881 
882     /**
883      * See {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs}.
884      */
setAllowFileAccessFromFileURLs(boolean flag)885     public void setAllowFileAccessFromFileURLs(boolean flag) {
886         synchronized (mAwSettingsLock) {
887             if (mAllowFileAccessFromFileURLs != flag) {
888                 mAllowFileAccessFromFileURLs = flag;
889                 mEventHandler.updateWebkitPreferencesLocked();
890             }
891         }
892     }
893 
894     /**
895      * See {@link android.webkit.WebSettings#setLoadsImagesAutomatically}.
896      */
setLoadsImagesAutomatically(boolean flag)897     public void setLoadsImagesAutomatically(boolean flag) {
898         synchronized (mAwSettingsLock) {
899             if (mLoadsImagesAutomatically != flag) {
900                 mLoadsImagesAutomatically = flag;
901                 mEventHandler.updateWebkitPreferencesLocked();
902             }
903         }
904     }
905 
906     /**
907      * See {@link android.webkit.WebSettings#getLoadsImagesAutomatically}.
908      */
getLoadsImagesAutomatically()909     public boolean getLoadsImagesAutomatically() {
910         synchronized (mAwSettingsLock) {
911             return mLoadsImagesAutomatically;
912         }
913     }
914 
915     @CalledByNative
getLoadsImagesAutomaticallyLocked()916     private boolean getLoadsImagesAutomaticallyLocked() {
917         assert Thread.holdsLock(mAwSettingsLock);
918         return mLoadsImagesAutomatically;
919     }
920 
921     /**
922      * See {@link android.webkit.WebSettings#setImagesEnabled}.
923      */
setImagesEnabled(boolean flag)924     public void setImagesEnabled(boolean flag) {
925         synchronized (mAwSettingsLock) {
926             if (mImagesEnabled != flag) {
927                 mImagesEnabled = flag;
928                 mEventHandler.updateWebkitPreferencesLocked();
929             }
930         }
931     }
932 
933     /**
934      * See {@link android.webkit.WebSettings#getImagesEnabled}.
935      */
getImagesEnabled()936     public boolean getImagesEnabled() {
937         synchronized (mAwSettingsLock) {
938             return mImagesEnabled;
939         }
940     }
941 
942     @CalledByNative
getImagesEnabledLocked()943     private boolean getImagesEnabledLocked() {
944         assert Thread.holdsLock(mAwSettingsLock);
945         return mImagesEnabled;
946     }
947 
948     /**
949      * See {@link android.webkit.WebSettings#getJavaScriptEnabled}.
950      */
getJavaScriptEnabled()951     public boolean getJavaScriptEnabled() {
952         synchronized (mAwSettingsLock) {
953             return mJavaScriptEnabled;
954         }
955     }
956 
957     @CalledByNative
getJavaScriptEnabledLocked()958     private boolean getJavaScriptEnabledLocked() {
959         assert Thread.holdsLock(mAwSettingsLock);
960         return mJavaScriptEnabled;
961     }
962 
963     /**
964      * See {@link android.webkit.WebSettings#getAllowUniversalAccessFromFileURLs}.
965      */
getAllowUniversalAccessFromFileURLs()966     public boolean getAllowUniversalAccessFromFileURLs() {
967         synchronized (mAwSettingsLock) {
968             return mAllowUniversalAccessFromFileURLs;
969         }
970     }
971 
972     @CalledByNative
getAllowUniversalAccessFromFileURLsLocked()973     private boolean getAllowUniversalAccessFromFileURLsLocked() {
974         assert Thread.holdsLock(mAwSettingsLock);
975         return mAllowUniversalAccessFromFileURLs;
976     }
977 
978     /**
979      * See {@link android.webkit.WebSettings#getAllowFileAccessFromFileURLs}.
980      */
getAllowFileAccessFromFileURLs()981     public boolean getAllowFileAccessFromFileURLs() {
982         synchronized (mAwSettingsLock) {
983             return mAllowFileAccessFromFileURLs;
984         }
985     }
986 
987     @CalledByNative
getAllowFileAccessFromFileURLsLocked()988     private boolean getAllowFileAccessFromFileURLsLocked() {
989         assert Thread.holdsLock(mAwSettingsLock);
990         return mAllowFileAccessFromFileURLs;
991     }
992 
993     /**
994      * See {@link android.webkit.WebSettings#setPluginsEnabled}.
995      */
setPluginsEnabled(boolean flag)996     public void setPluginsEnabled(boolean flag) {
997         setPluginState(flag ? PluginState.ON : PluginState.OFF);
998     }
999 
1000     /**
1001      * See {@link android.webkit.WebSettings#setPluginState}.
1002      */
setPluginState(PluginState state)1003     public void setPluginState(PluginState state) {
1004         synchronized (mAwSettingsLock) {
1005             if (mPluginState != state) {
1006                 mPluginState = state;
1007                 mEventHandler.updateWebkitPreferencesLocked();
1008             }
1009         }
1010     }
1011 
1012     /**
1013      * See {@link android.webkit.WebSettings#getPluginsEnabled}.
1014      */
getPluginsEnabled()1015     public boolean getPluginsEnabled() {
1016         synchronized (mAwSettingsLock) {
1017             return mPluginState == PluginState.ON;
1018         }
1019     }
1020 
1021     /**
1022      * Return true if plugins are disabled.
1023      * @return True if plugins are disabled.
1024      */
1025     @CalledByNative
getPluginsDisabledLocked()1026     private boolean getPluginsDisabledLocked() {
1027         assert Thread.holdsLock(mAwSettingsLock);
1028         return mPluginState == PluginState.OFF;
1029     }
1030 
1031     /**
1032      * See {@link android.webkit.WebSettings#getPluginState}.
1033      */
getPluginState()1034     public PluginState getPluginState() {
1035         synchronized (mAwSettingsLock) {
1036             return mPluginState;
1037         }
1038     }
1039 
1040 
1041     /**
1042      * See {@link android.webkit.WebSettings#setJavaScriptCanOpenWindowsAutomatically}.
1043      */
setJavaScriptCanOpenWindowsAutomatically(boolean flag)1044     public void setJavaScriptCanOpenWindowsAutomatically(boolean flag) {
1045         synchronized (mAwSettingsLock) {
1046             if (mJavaScriptCanOpenWindowsAutomatically != flag) {
1047                 mJavaScriptCanOpenWindowsAutomatically = flag;
1048                 mEventHandler.updateWebkitPreferencesLocked();
1049             }
1050         }
1051     }
1052 
1053     /**
1054      * See {@link android.webkit.WebSettings#getJavaScriptCanOpenWindowsAutomatically}.
1055      */
getJavaScriptCanOpenWindowsAutomatically()1056     public boolean getJavaScriptCanOpenWindowsAutomatically() {
1057         synchronized (mAwSettingsLock) {
1058             return mJavaScriptCanOpenWindowsAutomatically;
1059         }
1060     }
1061 
1062     @CalledByNative
getJavaScriptCanOpenWindowsAutomaticallyLocked()1063     private boolean getJavaScriptCanOpenWindowsAutomaticallyLocked() {
1064         assert Thread.holdsLock(mAwSettingsLock);
1065         return mJavaScriptCanOpenWindowsAutomatically;
1066     }
1067 
1068     /**
1069      * See {@link android.webkit.WebSettings#setLayoutAlgorithm}.
1070      */
setLayoutAlgorithm(LayoutAlgorithm l)1071     public void setLayoutAlgorithm(LayoutAlgorithm l) {
1072         synchronized (mAwSettingsLock) {
1073             if (mLayoutAlgorithm != l) {
1074                 mLayoutAlgorithm = l;
1075                 mEventHandler.updateWebkitPreferencesLocked();
1076             }
1077         }
1078     }
1079 
1080     /**
1081      * See {@link android.webkit.WebSettings#getLayoutAlgorithm}.
1082      */
getLayoutAlgorithm()1083     public LayoutAlgorithm getLayoutAlgorithm() {
1084         synchronized (mAwSettingsLock) {
1085             return mLayoutAlgorithm;
1086         }
1087     }
1088 
1089     /**
1090      * Gets whether Text Auto-sizing layout algorithm is enabled.
1091      *
1092      * @return true if Text Auto-sizing layout algorithm is enabled
1093      */
1094     @CalledByNative
getTextAutosizingEnabledLocked()1095     private boolean getTextAutosizingEnabledLocked() {
1096         assert Thread.holdsLock(mAwSettingsLock);
1097         return mLayoutAlgorithm == LayoutAlgorithm.TEXT_AUTOSIZING;
1098     }
1099 
1100     /**
1101      * See {@link android.webkit.WebSettings#setSupportMultipleWindows}.
1102      */
setSupportMultipleWindows(boolean support)1103     public void setSupportMultipleWindows(boolean support) {
1104         synchronized (mAwSettingsLock) {
1105             if (mSupportMultipleWindows != support) {
1106                 mSupportMultipleWindows = support;
1107                 mEventHandler.updateWebkitPreferencesLocked();
1108             }
1109         }
1110     }
1111 
1112     /**
1113      * See {@link android.webkit.WebSettings#supportMultipleWindows}.
1114      */
supportMultipleWindows()1115     public boolean supportMultipleWindows() {
1116         synchronized (mAwSettingsLock) {
1117             return mSupportMultipleWindows;
1118         }
1119     }
1120 
1121     @CalledByNative
getSupportMultipleWindowsLocked()1122     private boolean getSupportMultipleWindowsLocked() {
1123         assert Thread.holdsLock(mAwSettingsLock);
1124         return mSupportMultipleWindows;
1125     }
1126 
1127     @CalledByNative
getSupportLegacyQuirksLocked()1128     private boolean getSupportLegacyQuirksLocked() {
1129         assert Thread.holdsLock(mAwSettingsLock);
1130         return mSupportLegacyQuirks;
1131     }
1132 
1133     /**
1134      * See {@link android.webkit.WebSettings#setUseWideViewPort}.
1135      */
setUseWideViewPort(boolean use)1136     public void setUseWideViewPort(boolean use) {
1137         synchronized (mAwSettingsLock) {
1138             if (mUseWideViewport != use) {
1139                 mUseWideViewport = use;
1140                 onGestureZoomSupportChanged(
1141                         supportsDoubleTapZoomLocked(), supportsMultiTouchZoomLocked());
1142                 mEventHandler.updateWebkitPreferencesLocked();
1143             }
1144         }
1145     }
1146 
1147     /**
1148      * See {@link android.webkit.WebSettings#getUseWideViewPort}.
1149      */
getUseWideViewPort()1150     public boolean getUseWideViewPort() {
1151         synchronized (mAwSettingsLock) {
1152             return mUseWideViewport;
1153         }
1154     }
1155 
1156     @CalledByNative
getUseWideViewportLocked()1157     private boolean getUseWideViewportLocked() {
1158         assert Thread.holdsLock(mAwSettingsLock);
1159         return mUseWideViewport;
1160     }
1161 
1162     @CalledByNative
getPasswordEchoEnabledLocked()1163     private boolean getPasswordEchoEnabledLocked() {
1164         assert Thread.holdsLock(mAwSettingsLock);
1165         return mPasswordEchoEnabled;
1166     }
1167 
1168     /**
1169      * See {@link android.webkit.WebSettings#setAppCacheEnabled}.
1170      */
setAppCacheEnabled(boolean flag)1171     public void setAppCacheEnabled(boolean flag) {
1172         synchronized (mAwSettingsLock) {
1173             if (mAppCacheEnabled != flag) {
1174                 mAppCacheEnabled = flag;
1175                 mEventHandler.updateWebkitPreferencesLocked();
1176             }
1177         }
1178     }
1179 
1180     /**
1181      * See {@link android.webkit.WebSettings#setAppCachePath}.
1182      */
setAppCachePath(String path)1183     public void setAppCachePath(String path) {
1184         boolean needToSync = false;
1185         synchronized (sGlobalContentSettingsLock) {
1186             // AppCachePath can only be set once.
1187             if (!sAppCachePathIsSet && path != null && !path.isEmpty()) {
1188                 sAppCachePathIsSet = true;
1189                 needToSync = true;
1190             }
1191         }
1192         // The obvious problem here is that other WebViews will not be updated,
1193         // until they execute synchronization from Java to the native side.
1194         // But this is the same behaviour as it was in the legacy WebView.
1195         if (needToSync) {
1196             synchronized (mAwSettingsLock) {
1197                 mEventHandler.updateWebkitPreferencesLocked();
1198             }
1199         }
1200     }
1201 
1202     /**
1203      * Gets whether Application Cache is enabled.
1204      *
1205      * @return true if Application Cache is enabled
1206      */
1207     @CalledByNative
getAppCacheEnabledLocked()1208     private boolean getAppCacheEnabledLocked() {
1209         assert Thread.holdsLock(mAwSettingsLock);
1210         if (!mAppCacheEnabled) {
1211             return false;
1212         }
1213         synchronized (sGlobalContentSettingsLock) {
1214             return sAppCachePathIsSet;
1215         }
1216     }
1217 
1218     /**
1219      * See {@link android.webkit.WebSettings#setDomStorageEnabled}.
1220      */
setDomStorageEnabled(boolean flag)1221     public void setDomStorageEnabled(boolean flag) {
1222         synchronized (mAwSettingsLock) {
1223             if (mDomStorageEnabled != flag) {
1224                 mDomStorageEnabled = flag;
1225                 mEventHandler.updateWebkitPreferencesLocked();
1226             }
1227         }
1228     }
1229 
1230     /**
1231      * See {@link android.webkit.WebSettings#getDomStorageEnabled}.
1232      */
getDomStorageEnabled()1233     public boolean getDomStorageEnabled() {
1234         synchronized (mAwSettingsLock) {
1235             return mDomStorageEnabled;
1236         }
1237     }
1238 
1239     @CalledByNative
getDomStorageEnabledLocked()1240     private boolean getDomStorageEnabledLocked() {
1241         assert Thread.holdsLock(mAwSettingsLock);
1242         return mDomStorageEnabled;
1243     }
1244 
1245     /**
1246      * See {@link android.webkit.WebSettings#setDatabaseEnabled}.
1247      */
setDatabaseEnabled(boolean flag)1248     public void setDatabaseEnabled(boolean flag) {
1249         synchronized (mAwSettingsLock) {
1250             if (mDatabaseEnabled != flag) {
1251                 mDatabaseEnabled = flag;
1252                 mEventHandler.updateWebkitPreferencesLocked();
1253             }
1254         }
1255     }
1256 
1257     /**
1258      * See {@link android.webkit.WebSettings#getDatabaseEnabled}.
1259      */
getDatabaseEnabled()1260     public boolean getDatabaseEnabled() {
1261         synchronized (mAwSettingsLock) {
1262             return mDatabaseEnabled;
1263         }
1264     }
1265 
1266     @CalledByNative
getDatabaseEnabledLocked()1267     private boolean getDatabaseEnabledLocked() {
1268         assert Thread.holdsLock(mAwSettingsLock);
1269         return mDatabaseEnabled;
1270     }
1271 
1272     /**
1273      * See {@link android.webkit.WebSettings#setDefaultTextEncodingName}.
1274      */
setDefaultTextEncodingName(String encoding)1275     public void setDefaultTextEncodingName(String encoding) {
1276         synchronized (mAwSettingsLock) {
1277             if (encoding != null && !mDefaultTextEncoding.equals(encoding)) {
1278                 mDefaultTextEncoding = encoding;
1279                 mEventHandler.updateWebkitPreferencesLocked();
1280             }
1281         }
1282     }
1283 
1284     /**
1285      * See {@link android.webkit.WebSettings#getDefaultTextEncodingName}.
1286      */
getDefaultTextEncodingName()1287     public String getDefaultTextEncodingName() {
1288         synchronized (mAwSettingsLock) {
1289             return mDefaultTextEncoding;
1290         }
1291     }
1292 
1293     @CalledByNative
getDefaultTextEncodingLocked()1294     private String getDefaultTextEncodingLocked() {
1295         assert Thread.holdsLock(mAwSettingsLock);
1296         return mDefaultTextEncoding;
1297     }
1298 
1299     /**
1300      * See {@link android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture}.
1301      */
setMediaPlaybackRequiresUserGesture(boolean require)1302     public void setMediaPlaybackRequiresUserGesture(boolean require) {
1303         synchronized (mAwSettingsLock) {
1304             if (mMediaPlaybackRequiresUserGesture != require) {
1305                 mMediaPlaybackRequiresUserGesture = require;
1306                 mEventHandler.updateWebkitPreferencesLocked();
1307             }
1308         }
1309     }
1310 
1311     /**
1312      * See {@link android.webkit.WebSettings#getMediaPlaybackRequiresUserGesture}.
1313      */
getMediaPlaybackRequiresUserGesture()1314     public boolean getMediaPlaybackRequiresUserGesture() {
1315         synchronized (mAwSettingsLock) {
1316             return mMediaPlaybackRequiresUserGesture;
1317         }
1318     }
1319 
1320     @CalledByNative
getMediaPlaybackRequiresUserGestureLocked()1321     private boolean getMediaPlaybackRequiresUserGestureLocked() {
1322         assert Thread.holdsLock(mAwSettingsLock);
1323         return mMediaPlaybackRequiresUserGesture;
1324     }
1325 
1326     /**
1327      * See {@link android.webkit.WebSettings#setDefaultVideoPosterURL}.
1328      */
setDefaultVideoPosterURL(String url)1329     public void setDefaultVideoPosterURL(String url) {
1330         synchronized (mAwSettingsLock) {
1331             if (mDefaultVideoPosterURL != null && !mDefaultVideoPosterURL.equals(url) ||
1332                     mDefaultVideoPosterURL == null && url != null) {
1333                 mDefaultVideoPosterURL = url;
1334                 mEventHandler.updateWebkitPreferencesLocked();
1335             }
1336         }
1337     }
1338 
1339     /**
1340      * See {@link android.webkit.WebSettings#getDefaultVideoPosterURL}.
1341      */
getDefaultVideoPosterURL()1342     public String getDefaultVideoPosterURL() {
1343         synchronized (mAwSettingsLock) {
1344             return mDefaultVideoPosterURL;
1345         }
1346     }
1347 
1348     @CalledByNative
getDefaultVideoPosterURLLocked()1349     private String getDefaultVideoPosterURLLocked() {
1350         assert Thread.holdsLock(mAwSettingsLock);
1351         return mDefaultVideoPosterURL;
1352     }
1353 
onGestureZoomSupportChanged( final boolean supportsDoubleTapZoom, final boolean supportsMultiTouchZoom)1354     private void onGestureZoomSupportChanged(
1355             final boolean supportsDoubleTapZoom, final boolean supportsMultiTouchZoom) {
1356         // Always post asynchronously here, to avoid doubling back onto the caller.
1357         mEventHandler.maybePostOnUiThread(new Runnable() {
1358             @Override
1359             public void run() {
1360                 synchronized (mAwSettingsLock) {
1361                     if (mZoomChangeListener != null) {
1362                         mZoomChangeListener.onGestureZoomSupportChanged(
1363                                 supportsDoubleTapZoom, supportsMultiTouchZoom);
1364                     }
1365                 }
1366             }
1367         });
1368     }
1369 
1370     /**
1371      * See {@link android.webkit.WebSettings#setSupportZoom}.
1372      */
setSupportZoom(boolean support)1373     public void setSupportZoom(boolean support) {
1374         synchronized (mAwSettingsLock) {
1375             if (mSupportZoom != support) {
1376                 mSupportZoom = support;
1377                 onGestureZoomSupportChanged(
1378                         supportsDoubleTapZoomLocked(), supportsMultiTouchZoomLocked());
1379             }
1380         }
1381     }
1382 
1383     /**
1384      * See {@link android.webkit.WebSettings#supportZoom}.
1385      */
supportZoom()1386     public boolean supportZoom() {
1387         synchronized (mAwSettingsLock) {
1388             return mSupportZoom;
1389         }
1390     }
1391 
1392     /**
1393      * See {@link android.webkit.WebSettings#setBuiltInZoomControls}.
1394      */
setBuiltInZoomControls(boolean enabled)1395     public void setBuiltInZoomControls(boolean enabled) {
1396         synchronized (mAwSettingsLock) {
1397             if (mBuiltInZoomControls != enabled) {
1398                 mBuiltInZoomControls = enabled;
1399                 onGestureZoomSupportChanged(
1400                         supportsDoubleTapZoomLocked(), supportsMultiTouchZoomLocked());
1401             }
1402         }
1403     }
1404 
1405     /**
1406      * See {@link android.webkit.WebSettings#getBuiltInZoomControls}.
1407      */
getBuiltInZoomControls()1408     public boolean getBuiltInZoomControls() {
1409         synchronized (mAwSettingsLock) {
1410             return mBuiltInZoomControls;
1411         }
1412     }
1413 
1414     /**
1415      * See {@link android.webkit.WebSettings#setDisplayZoomControls}.
1416      */
setDisplayZoomControls(boolean enabled)1417     public void setDisplayZoomControls(boolean enabled) {
1418         synchronized (mAwSettingsLock) {
1419             mDisplayZoomControls = enabled;
1420         }
1421     }
1422 
1423     /**
1424      * See {@link android.webkit.WebSettings#getDisplayZoomControls}.
1425      */
getDisplayZoomControls()1426     public boolean getDisplayZoomControls() {
1427         synchronized (mAwSettingsLock) {
1428             return mDisplayZoomControls;
1429         }
1430     }
1431 
1432     @CalledByNative
supportsDoubleTapZoomLocked()1433     private boolean supportsDoubleTapZoomLocked() {
1434         assert Thread.holdsLock(mAwSettingsLock);
1435         return mSupportZoom && mBuiltInZoomControls && mUseWideViewport;
1436     }
1437 
supportsMultiTouchZoomLocked()1438     private boolean supportsMultiTouchZoomLocked() {
1439         assert Thread.holdsLock(mAwSettingsLock);
1440         return mSupportZoom && mBuiltInZoomControls;
1441     }
1442 
supportsMultiTouchZoom()1443     boolean supportsMultiTouchZoom() {
1444         synchronized (mAwSettingsLock) {
1445             return supportsMultiTouchZoomLocked();
1446         }
1447     }
1448 
shouldDisplayZoomControls()1449     boolean shouldDisplayZoomControls() {
1450         synchronized (mAwSettingsLock) {
1451             return supportsMultiTouchZoomLocked() && mDisplayZoomControls;
1452         }
1453     }
1454 
clipFontSize(int size)1455     private int clipFontSize(int size) {
1456         if (size < MINIMUM_FONT_SIZE) {
1457             return MINIMUM_FONT_SIZE;
1458         } else if (size > MAXIMUM_FONT_SIZE) {
1459             return MAXIMUM_FONT_SIZE;
1460         }
1461         return size;
1462     }
1463 
1464     @CalledByNative
updateEverything()1465     private void updateEverything() {
1466         synchronized (mAwSettingsLock) {
1467             nativeUpdateEverythingLocked(mNativeAwSettings);
1468         }
1469     }
1470 
1471     @CalledByNative
populateWebPreferences(long webPrefsPtr)1472     private void populateWebPreferences(long webPrefsPtr) {
1473         synchronized (mAwSettingsLock) {
1474             nativePopulateWebPreferencesLocked(mNativeAwSettings, webPrefsPtr);
1475         }
1476     }
1477 
updateWebkitPreferencesOnUiThreadLocked()1478     private void updateWebkitPreferencesOnUiThreadLocked() {
1479         assert mEventHandler.mHandler != null;
1480         ThreadUtils.assertOnUiThread();
1481         nativeUpdateWebkitPreferencesLocked(mNativeAwSettings);
1482     }
1483 
nativeInit(long webContentsPtr)1484     private native long nativeInit(long webContentsPtr);
1485 
nativeDestroy(long nativeAwSettings)1486     private native void nativeDestroy(long nativeAwSettings);
1487 
nativePopulateWebPreferencesLocked(long nativeAwSettings, long webPrefsPtr)1488     private native void nativePopulateWebPreferencesLocked(long nativeAwSettings, long webPrefsPtr);
1489 
nativeResetScrollAndScaleState(long nativeAwSettings)1490     private native void nativeResetScrollAndScaleState(long nativeAwSettings);
1491 
nativeUpdateEverythingLocked(long nativeAwSettings)1492     private native void nativeUpdateEverythingLocked(long nativeAwSettings);
1493 
nativeUpdateInitialPageScaleLocked(long nativeAwSettings)1494     private native void nativeUpdateInitialPageScaleLocked(long nativeAwSettings);
1495 
nativeUpdateUserAgentLocked(long nativeAwSettings)1496     private native void nativeUpdateUserAgentLocked(long nativeAwSettings);
1497 
nativeUpdateWebkitPreferencesLocked(long nativeAwSettings)1498     private native void nativeUpdateWebkitPreferencesLocked(long nativeAwSettings);
1499 
nativeGetDefaultUserAgent()1500     private static native String nativeGetDefaultUserAgent();
1501 
nativeUpdateFormDataPreferencesLocked(long nativeAwSettings)1502     private native void nativeUpdateFormDataPreferencesLocked(long nativeAwSettings);
1503 }
1504