• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.webkit;
18 
19 import android.annotation.IntDef;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.content.Context;
24 
25 import java.lang.annotation.ElementType;
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.lang.annotation.Target;
29 
30 /**
31  * Manages settings state for a WebView. When a WebView is first created, it
32  * obtains a set of default settings. These default settings will be returned
33  * from any getter call. A {@code WebSettings} object obtained from
34  * {@link WebView#getSettings()} is tied to the life of the WebView. If a WebView has
35  * been destroyed, any method call on {@code WebSettings} will throw an
36  * {@link IllegalStateException}.
37  */
38 // This is an abstract base class: concrete WebViewProviders must
39 // create a class derived from this, and return an instance of it in the
40 // WebViewProvider.getWebSettingsProvider() method implementation.
41 public abstract class WebSettings {
42     /**
43      * Enum for controlling the layout of html.
44      * <ul>
45      *   <li>{@code NORMAL} means no rendering changes. This is the recommended choice for maximum
46      *       compatibility across different platforms and Android versions.</li>
47      *   <li>{@code SINGLE_COLUMN} moves all content into one column that is the width of the
48      *       view.</li>
49      *   <li>{@code NARROW_COLUMNS} makes all columns no wider than the screen if possible. Only use
50      *       this for API levels prior to {@link android.os.Build.VERSION_CODES#KITKAT}.</li>
51      *   <li>{@code TEXT_AUTOSIZING} boosts font size of paragraphs based on heuristics to make
52      *       the text readable when viewing a wide-viewport layout in the overview mode.
53      *       It is recommended to enable zoom support {@link #setSupportZoom} when
54      *       using this mode. Supported from API level
55      *       {@link android.os.Build.VERSION_CODES#KITKAT}</li>
56      * </ul>
57      */
58     // XXX: These must match LayoutAlgorithm in Settings.h in WebCore.
59     public enum LayoutAlgorithm {
60         NORMAL,
61         /**
62          * @deprecated This algorithm is now obsolete.
63          */
64         @Deprecated
65         SINGLE_COLUMN,
66         /**
67          * @deprecated This algorithm is now obsolete.
68          */
69         @Deprecated
70         NARROW_COLUMNS,
71         TEXT_AUTOSIZING
72     }
73 
74     /**
75      * Enum for specifying the text size.
76      * <ul>
77      *   <li>SMALLEST is 50%</li>
78      *   <li>SMALLER is 75%</li>
79      *   <li>NORMAL is 100%</li>
80      *   <li>LARGER is 150%</li>
81      *   <li>LARGEST is 200%</li>
82      * </ul>
83      *
84      * @deprecated Use {@link WebSettings#setTextZoom(int)} and {@link WebSettings#getTextZoom()} instead.
85      */
86     @Deprecated
87     public enum TextSize {
88         SMALLEST(50),
89         SMALLER(75),
90         NORMAL(100),
91         LARGER(150),
92         LARGEST(200);
TextSize(int size)93         TextSize(int size) {
94             value = size;
95         }
96         @UnsupportedAppUsage
97         int value;
98     }
99 
100     /**
101      * Enum for specifying the WebView's desired density.
102      * <ul>
103      *   <li>{@code FAR} makes 100% looking like in 240dpi</li>
104      *   <li>{@code MEDIUM} makes 100% looking like in 160dpi</li>
105      *   <li>{@code CLOSE} makes 100% looking like in 120dpi</li>
106      * </ul>
107      */
108     public enum ZoomDensity {
109         FAR(150),      // 240dpi
110         MEDIUM(100),    // 160dpi
111         CLOSE(75);     // 120dpi
ZoomDensity(int size)112         ZoomDensity(int size) {
113             value = size;
114         }
115 
116         /**
117          * @hide Only for use by WebViewProvider implementations
118          */
getValue()119         public int getValue() {
120             return value;
121         }
122 
123         int value;
124     }
125 
126     /** @hide */
127     @IntDef(prefix = { "LOAD_" }, value = {
128             LOAD_DEFAULT,
129             LOAD_NORMAL,
130             LOAD_CACHE_ELSE_NETWORK,
131             LOAD_NO_CACHE,
132             LOAD_CACHE_ONLY
133     })
134     @Retention(RetentionPolicy.SOURCE)
135     public @interface CacheMode {}
136 
137     /**
138      * Default cache usage mode. If the navigation type doesn't impose any
139      * specific behavior, use cached resources when they are available
140      * and not expired, otherwise load resources from the network.
141      * Use with {@link #setCacheMode}.
142      */
143     public static final int LOAD_DEFAULT = -1;
144 
145     /**
146      * Normal cache usage mode. Use with {@link #setCacheMode}.
147      *
148      * @deprecated This value is obsolete, as from API level
149      * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and onwards it has the
150      * same effect as {@link #LOAD_DEFAULT}.
151      */
152     @Deprecated
153     public static final int LOAD_NORMAL = 0;
154 
155     /**
156      * Use cached resources when they are available, even if they have expired.
157      * Otherwise load resources from the network.
158      * Use with {@link #setCacheMode}.
159      */
160     public static final int LOAD_CACHE_ELSE_NETWORK = 1;
161 
162     /**
163      * Don't use the cache, load from the network.
164      * Use with {@link #setCacheMode}.
165      */
166     public static final int LOAD_NO_CACHE = 2;
167 
168     /**
169      * Don't use the network, load from the cache.
170      * Use with {@link #setCacheMode}.
171      */
172     public static final int LOAD_CACHE_ONLY = 3;
173 
174     public enum RenderPriority {
175         NORMAL,
176         HIGH,
177         LOW
178     }
179 
180     /**
181      * The plugin state effects how plugins are treated on a page. ON means
182      * that any object will be loaded even if a plugin does not exist to handle
183      * the content. ON_DEMAND means that if there is a plugin installed that
184      * can handle the content, a placeholder is shown until the user clicks on
185      * the placeholder. Once clicked, the plugin will be enabled on the page.
186      * OFF means that all plugins will be turned off and any fallback content
187      * will be used.
188      */
189     public enum PluginState {
190         ON,
191         ON_DEMAND,
192         OFF
193     }
194 
195     /**
196      * In this mode, the WebView will allow a secure origin to load content from any other origin,
197      * even if that origin is insecure. This is the least secure mode of operation for the WebView,
198      * and where possible apps should not set this mode.
199      *
200      * @see #setMixedContentMode
201      */
202     public static final int MIXED_CONTENT_ALWAYS_ALLOW = 0;
203 
204     /**
205      * In this mode, the WebView will not allow a secure origin to load content from an insecure
206      * origin. This is the preferred and most secure mode of operation for the WebView and apps are
207      * strongly advised to use this mode.
208      *
209      * @see #setMixedContentMode
210      */
211     public static final int MIXED_CONTENT_NEVER_ALLOW = 1;
212 
213     /**
214      * In this mode, the WebView will attempt to be compatible with the approach of a modern web
215      * browser with regard to mixed content. Some insecure content may be allowed to be loaded by
216      * a secure origin and other types of content will be blocked. The types of content are allowed
217      * or blocked may change release to release and are not explicitly defined.
218      *
219      * This mode is intended to be used by apps that are not in control of the content that they
220      * render but desire to operate in a reasonably secure environment. For highest security, apps
221      * are recommended to use {@link #MIXED_CONTENT_NEVER_ALLOW}.
222      *
223      * @see #setMixedContentMode
224      */
225     public static final int MIXED_CONTENT_COMPATIBILITY_MODE = 2;
226 
227     /** @hide */
228     @IntDef(prefix = { "FORCE_DARK_" }, value = {
229             FORCE_DARK_OFF,
230             FORCE_DARK_AUTO,
231             FORCE_DARK_ON
232     })
233     @Retention(RetentionPolicy.SOURCE)
234     public @interface ForceDark {}
235 
236     /**
237      * Disable force dark, irrespective of the force dark mode of the WebView parent. In this mode,
238      * WebView content will always be rendered as-is, regardless of whether native views are being
239      * automatically darkened.
240      *
241      * @see #setForceDark
242      */
243     public static final int FORCE_DARK_OFF = 0;
244 
245     /**
246      * Enable force dark dependent on the state of the WebView parent view. If the WebView parent
247      * view is being automatically force darkened
248      * (see: {@link android.view.View#setForceDarkAllowed}), then WebView content will be rendered
249      * so as to emulate a dark theme. WebViews that are not attached to the view hierarchy will not
250      * be inverted.
251      *
252      * @see #setForceDark
253      */
254     public static final int FORCE_DARK_AUTO = 1;
255 
256     /**
257      * Unconditionally enable force dark. In this mode WebView content will always be rendered so
258      * as to emulate a dark theme.
259      *
260      * @see #setForceDark
261      */
262     public static final int FORCE_DARK_ON = 2;
263 
264     /**
265      * Enables dumping the pages navigation cache to a text file. The default
266      * is {@code false}.
267      *
268      * @deprecated This method is now obsolete.
269      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
270      */
271     @SystemApi
272     @Deprecated
setNavDump(boolean enabled)273     public abstract void setNavDump(boolean enabled);
274 
275     /**
276      * Gets whether dumping the navigation cache is enabled.
277      *
278      * @return whether dumping the navigation cache is enabled
279      * @see #setNavDump
280      * @deprecated This method is now obsolete.
281      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
282      */
283     @SystemApi
284     @Deprecated
getNavDump()285     public abstract boolean getNavDump();
286 
287     /**
288      * Sets whether the WebView should support zooming using its on-screen zoom
289      * controls and gestures. The particular zoom mechanisms that should be used
290      * can be set with {@link #setBuiltInZoomControls}. This setting does not
291      * affect zooming performed using the {@link WebView#zoomIn()} and
292      * {@link WebView#zoomOut()} methods. The default is {@code true}.
293      *
294      * @param support whether the WebView should support zoom
295      */
setSupportZoom(boolean support)296     public abstract void setSupportZoom(boolean support);
297 
298     /**
299      * Gets whether the WebView supports zoom.
300      *
301      * @return {@code true} if the WebView supports zoom
302      * @see #setSupportZoom
303      */
supportZoom()304     public abstract boolean supportZoom();
305 
306     /**
307      * Sets whether the WebView requires a user gesture to play media.
308      * The default is {@code true}.
309      *
310      * @param require whether the WebView requires a user gesture to play media
311      */
setMediaPlaybackRequiresUserGesture(boolean require)312     public abstract void setMediaPlaybackRequiresUserGesture(boolean require);
313 
314     /**
315      * Gets whether the WebView requires a user gesture to play media.
316      *
317      * @return {@code true} if the WebView requires a user gesture to play media
318      * @see #setMediaPlaybackRequiresUserGesture
319      */
getMediaPlaybackRequiresUserGesture()320     public abstract boolean getMediaPlaybackRequiresUserGesture();
321 
322     /**
323      * Sets whether the WebView should use its built-in zoom mechanisms. The
324      * built-in zoom mechanisms comprise on-screen zoom controls, which are
325      * displayed over the WebView's content, and the use of a pinch gesture to
326      * control zooming. Whether or not these on-screen controls are displayed
327      * can be set with {@link #setDisplayZoomControls}. The default is {@code false}.
328      * <p>
329      * The built-in mechanisms are the only currently supported zoom
330      * mechanisms, so it is recommended that this setting is always enabled.
331      * However, on-screen zoom controls are deprecated in Android (see
332      * {@link android.widget.ZoomButtonsController}) so it's recommended to
333      * disable {@link #setDisplayZoomControls}.
334      *
335      * @param enabled whether the WebView should use its built-in zoom mechanisms
336      */
337     // This method was intended to select between the built-in zoom mechanisms
338     // and the separate zoom controls. The latter were obtained using
339     // {@link WebView#getZoomControls}, which is now hidden.
setBuiltInZoomControls(boolean enabled)340     public abstract void setBuiltInZoomControls(boolean enabled);
341 
342     /**
343      * Gets whether the zoom mechanisms built into WebView are being used.
344      *
345      * @return {@code true} if the zoom mechanisms built into WebView are being used
346      * @see #setBuiltInZoomControls
347      */
getBuiltInZoomControls()348     public abstract boolean getBuiltInZoomControls();
349 
350     /**
351      * Sets whether the WebView should display on-screen zoom controls when
352      * using the built-in zoom mechanisms. See {@link #setBuiltInZoomControls}.
353      * The default is {@code true}. However, on-screen zoom controls are deprecated
354      * in Android (see {@link android.widget.ZoomButtonsController}) so it's
355      * recommended to set this to {@code false}.
356      *
357      * @param enabled whether the WebView should display on-screen zoom controls
358      */
setDisplayZoomControls(boolean enabled)359     public abstract void setDisplayZoomControls(boolean enabled);
360 
361     /**
362      * Gets whether the WebView displays on-screen zoom controls when using
363      * the built-in zoom mechanisms.
364      *
365      * @return {@code true} if the WebView displays on-screen zoom controls when using
366      *         the built-in zoom mechanisms
367      * @see #setDisplayZoomControls
368      */
getDisplayZoomControls()369     public abstract boolean getDisplayZoomControls();
370 
371     /**
372      * Enables or disables file access within WebView.
373      * Note that this enables or disables file system access only. Assets and resources
374      * are still accessible using file:///android_asset and file:///android_res.
375      * <p class="note">
376      * <b>Note:</b> Apps should not open {@code file://} URLs from any external source in
377      * WebView, don't enable this if your app accepts arbitrary URLs from external sources.
378      * It's recommended to always use
379      * <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader">
380      * androidx.webkit.WebViewAssetLoader</a> to access files including assets and resources over
381      * {@code http(s)://} schemes, instead of {@code file://} URLs. To prevent possible security
382      * issues targeting {@link android.os.Build.VERSION_CODES#Q} and earlier, you should explicitly
383      * set this value to {@code false}.
384      * <p>
385      * The default value is {@code true} for apps targeting
386      * {@link android.os.Build.VERSION_CODES#Q} and below, and {@code false} when targeting
387      * {@link android.os.Build.VERSION_CODES#R} and above.
388      */
setAllowFileAccess(boolean allow)389     public abstract void setAllowFileAccess(boolean allow);
390 
391     /**
392      * Gets whether this WebView supports file access.
393      *
394      * @see #setAllowFileAccess
395      */
getAllowFileAccess()396     public abstract boolean getAllowFileAccess();
397 
398     /**
399      * Enables or disables content URL access within WebView.  Content URL
400      * access allows WebView to load content from a content provider installed
401      * in the system. The default is enabled.
402      */
setAllowContentAccess(boolean allow)403     public abstract void setAllowContentAccess(boolean allow);
404 
405     /**
406      * Gets whether this WebView supports content URL access.
407      *
408      * @see #setAllowContentAccess
409      */
getAllowContentAccess()410     public abstract boolean getAllowContentAccess();
411 
412     /**
413      * Sets whether the WebView loads pages in overview mode, that is,
414      * zooms out the content to fit on screen by width. This setting is
415      * taken into account when the content width is greater than the width
416      * of the WebView control, for example, when {@link #getUseWideViewPort}
417      * is enabled. The default is {@code false}.
418      */
setLoadWithOverviewMode(boolean overview)419     public abstract void setLoadWithOverviewMode(boolean overview);
420 
421     /**
422      * Gets whether this WebView loads pages in overview mode.
423      *
424      * @return whether this WebView loads pages in overview mode
425      * @see #setLoadWithOverviewMode
426      */
getLoadWithOverviewMode()427     public abstract boolean getLoadWithOverviewMode();
428 
429     /**
430      * Sets whether the WebView will enable smooth transition while panning or
431      * zooming or while the window hosting the WebView does not have focus.
432      * If it is {@code true}, WebView will choose a solution to maximize the performance.
433      * e.g. the WebView's content may not be updated during the transition.
434      * If it is false, WebView will keep its fidelity. The default value is {@code false}.
435      *
436      * @deprecated This method is now obsolete, and will become a no-op in future.
437      */
438     @Deprecated
setEnableSmoothTransition(boolean enable)439     public abstract void setEnableSmoothTransition(boolean enable);
440 
441     /**
442      * Gets whether the WebView enables smooth transition while panning or
443      * zooming.
444      *
445      * @see #setEnableSmoothTransition
446      *
447      * @deprecated This method is now obsolete, and will become a no-op in future.
448      */
449     @Deprecated
enableSmoothTransition()450     public abstract  boolean enableSmoothTransition();
451 
452     /**
453      * Sets whether the WebView uses its background for over scroll background.
454      * If {@code true}, it will use the WebView's background. If {@code false}, it will use an
455      * internal pattern. Default is {@code true}.
456      *
457      * @deprecated This method is now obsolete.
458      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
459      */
460     @SystemApi
461     @Deprecated
setUseWebViewBackgroundForOverscrollBackground(boolean view)462     public abstract  void setUseWebViewBackgroundForOverscrollBackground(boolean view);
463 
464     /**
465      * Gets whether this WebView uses WebView's background instead of
466      * internal pattern for over scroll background.
467      *
468      * @see #setUseWebViewBackgroundForOverscrollBackground
469      * @deprecated This method is now obsolete.
470      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
471      */
472     @SystemApi
473     @Deprecated
getUseWebViewBackgroundForOverscrollBackground()474     public abstract  boolean getUseWebViewBackgroundForOverscrollBackground();
475 
476     /**
477      * Sets whether the WebView should save form data. In Android O, the
478      * platform has implemented a fully functional Autofill feature to store
479      * form data. Therefore, the Webview form data save feature is disabled.
480      *
481      * Note that the feature will continue to be supported on older versions of
482      * Android as before.
483      *
484      * @deprecated In Android O and afterwards, this function does not have
485      * any effect, the form data will be saved to platform's autofill service
486      * if applicable.
487      */
488     @Deprecated
setSaveFormData(boolean save)489     public abstract  void setSaveFormData(boolean save);
490 
491     /**
492      * Gets whether the WebView saves form data.
493      *
494      * @return whether the WebView saves form data
495      * @see #setSaveFormData
496      */
497     @Deprecated
getSaveFormData()498     public abstract boolean getSaveFormData();
499 
500     /**
501      * Sets whether the WebView should save passwords. The default is {@code true}.
502      * @deprecated Saving passwords in WebView will not be supported in future versions.
503      */
504     @Deprecated
setSavePassword(boolean save)505     public abstract void setSavePassword(boolean save);
506 
507     /**
508      * Gets whether the WebView saves passwords.
509      *
510      * @return whether the WebView saves passwords
511      * @see #setSavePassword
512      * @deprecated Saving passwords in WebView will not be supported in future versions.
513      */
514     @Deprecated
getSavePassword()515     public abstract boolean getSavePassword();
516 
517     /**
518      * Sets the text zoom of the page in percent. The default is 100.
519      *
520      * @param textZoom the text zoom in percent
521      */
setTextZoom(int textZoom)522     public abstract void setTextZoom(int textZoom);
523 
524     /**
525      * Gets the text zoom of the page in percent.
526      *
527      * @return the text zoom of the page in percent
528      * @see #setTextZoom
529      */
getTextZoom()530     public abstract int getTextZoom();
531 
532     /**
533      * Sets policy for third party cookies.
534      * Developers should access this via {@link CookieManager#setShouldAcceptThirdPartyCookies}.
535      * @hide Internal API.
536      */
537     @SystemApi
setAcceptThirdPartyCookies(boolean accept)538     public abstract void setAcceptThirdPartyCookies(boolean accept);
539 
540     /**
541      * Gets policy for third party cookies.
542      * Developers should access this via {@link CookieManager#getShouldAcceptThirdPartyCookies}.
543      * @hide Internal API
544      */
545     @SystemApi
getAcceptThirdPartyCookies()546     public abstract boolean getAcceptThirdPartyCookies();
547 
548     /**
549      * Sets the text size of the page. The default is {@link TextSize#NORMAL}.
550      *
551      * @param t the text size as a {@link TextSize} value
552      * @deprecated Use {@link #setTextZoom} instead.
553      */
554     @Deprecated
setTextSize(TextSize t)555     public synchronized void setTextSize(TextSize t) {
556         setTextZoom(t.value);
557     }
558 
559     /**
560      * Gets the text size of the page. If the text size was previously specified
561      * in percent using {@link #setTextZoom}, this will return the closest
562      * matching {@link TextSize}.
563      *
564      * @return the text size as a {@link TextSize} value
565      * @see #setTextSize
566      * @deprecated Use {@link #getTextZoom} instead.
567      */
568     @Deprecated
getTextSize()569     public synchronized TextSize getTextSize() {
570         TextSize closestSize = null;
571         int smallestDelta = Integer.MAX_VALUE;
572         int textSize = getTextZoom();
573         for (TextSize size : TextSize.values()) {
574             int delta = Math.abs(textSize - size.value);
575             if (delta == 0) {
576                 return size;
577             }
578             if (delta < smallestDelta) {
579                 smallestDelta = delta;
580                 closestSize = size;
581             }
582         }
583         return closestSize != null ? closestSize : TextSize.NORMAL;
584     }
585 
586     /**
587      * Sets the default zoom density of the page. This must be called from the UI
588      * thread. The default is {@link ZoomDensity#MEDIUM}.
589      *
590      * This setting is not recommended for use in new applications.  If the WebView
591      * is utilized to display mobile-oriented pages, the desired effect can be achieved by
592      * adjusting 'width' and 'initial-scale' attributes of page's 'meta viewport'
593      * tag. For pages lacking the tag, {@link android.webkit.WebView#setInitialScale}
594      * and {@link #setUseWideViewPort} can be used.
595      *
596      * @param zoom the zoom density
597      * @deprecated This method is no longer supported, see the function documentation for
598      *             recommended alternatives.
599      */
600     @Deprecated
setDefaultZoom(ZoomDensity zoom)601     public abstract void setDefaultZoom(ZoomDensity zoom);
602 
603     /**
604      * Gets the default zoom density of the page. This should be called from
605      * the UI thread.
606      *
607      * This setting is not recommended for use in new applications.
608      *
609      * @return the zoom density
610      * @see #setDefaultZoom
611      * @deprecated Will only return the default value.
612      */
613     @Deprecated
getDefaultZoom()614     public abstract ZoomDensity getDefaultZoom();
615 
616     /**
617      * Enables using light touches to make a selection and activate mouseovers.
618      * @deprecated From {@link android.os.Build.VERSION_CODES#JELLY_BEAN} this
619      *             setting is obsolete and has no effect.
620      */
621     @Deprecated
setLightTouchEnabled(boolean enabled)622     public abstract void setLightTouchEnabled(boolean enabled);
623 
624     /**
625      * Gets whether light touches are enabled.
626      * @see #setLightTouchEnabled
627      * @deprecated This setting is obsolete.
628      */
629     @Deprecated
getLightTouchEnabled()630     public abstract boolean getLightTouchEnabled();
631 
632     /**
633      * Controlled a rendering optimization that is no longer present. Setting
634      * it now has no effect.
635      *
636      * @deprecated This setting now has no effect.
637      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
638      */
639     @Deprecated
640     @UnsupportedAppUsage
setUseDoubleTree(boolean use)641     public void setUseDoubleTree(boolean use) {
642         // Specified to do nothing, so no need for derived classes to override.
643     }
644 
645     /**
646      * Controlled a rendering optimization that is no longer present. Setting
647      * it now has no effect.
648      *
649      * @deprecated This setting now has no effect.
650      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
651      */
652     @Deprecated
653     @UnsupportedAppUsage
getUseDoubleTree()654     public boolean getUseDoubleTree() {
655         // Returns false unconditionally, so no need for derived classes to override.
656         return false;
657     }
658 
659     /**
660      * Sets the user-agent string using an integer code.
661      * <ul>
662      *   <li>0 means the WebView should use an Android user-agent string</li>
663      *   <li>1 means the WebView should use a desktop user-agent string</li>
664      * </ul>
665      * Other values are ignored. The default is an Android user-agent string,
666      * i.e. code value 0.
667      *
668      * @param ua the integer code for the user-agent string
669      * @deprecated Please use {@link #setUserAgentString} instead.
670      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
671      */
672     @SystemApi
673     @Deprecated
setUserAgent(int ua)674     public abstract void setUserAgent(int ua);
675 
676     /**
677      * Gets the user-agent as an integer code.
678      * <ul>
679      *   <li>-1 means the WebView is using a custom user-agent string set with
680      *   {@link #setUserAgentString}</li>
681      *   <li>0 means the WebView should use an Android user-agent string</li>
682      *   <li>1 means the WebView should use a desktop user-agent string</li>
683      * </ul>
684      *
685      * @return the integer code for the user-agent string
686      * @see #setUserAgent
687      * @deprecated Please use {@link #getUserAgentString} instead.
688      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
689      */
690     @SystemApi
691     @Deprecated
getUserAgent()692     public abstract int getUserAgent();
693 
694     /**
695      * Sets whether the WebView should enable support for the &quot;viewport&quot;
696      * HTML meta tag or should use a wide viewport.
697      * When the value of the setting is {@code false}, the layout width is always set to the
698      * width of the WebView control in device-independent (CSS) pixels.
699      * When the value is {@code true} and the page contains the viewport meta tag, the value
700      * of the width specified in the tag is used. If the page does not contain the tag or
701      * does not provide a width, then a wide viewport will be used.
702      *
703      * @param use whether to enable support for the viewport meta tag
704      */
setUseWideViewPort(boolean use)705     public abstract void setUseWideViewPort(boolean use);
706 
707     /**
708      * Gets whether the WebView supports the &quot;viewport&quot;
709      * HTML meta tag or will use a wide viewport.
710      *
711      * @return {@code true} if the WebView supports the viewport meta tag
712      * @see #setUseWideViewPort
713      */
getUseWideViewPort()714     public abstract boolean getUseWideViewPort();
715 
716     /**
717      * Sets whether the WebView whether supports multiple windows. If set to
718      * true, {@link WebChromeClient#onCreateWindow} must be implemented by the
719      * host application. The default is {@code false}.
720      *
721      * @param support whether to support multiple windows
722      */
setSupportMultipleWindows(boolean support)723     public abstract void setSupportMultipleWindows(boolean support);
724 
725     /**
726      * Gets whether the WebView supports multiple windows.
727      *
728      * @return {@code true} if the WebView supports multiple windows
729      * @see #setSupportMultipleWindows
730      */
supportMultipleWindows()731     public abstract boolean supportMultipleWindows();
732 
733     /**
734      * Sets the underlying layout algorithm. This will cause a re-layout of the
735      * WebView. The default is {@link LayoutAlgorithm#NARROW_COLUMNS}.
736      *
737      * @param l the layout algorithm to use, as a {@link LayoutAlgorithm} value
738      */
setLayoutAlgorithm(LayoutAlgorithm l)739     public abstract void setLayoutAlgorithm(LayoutAlgorithm l);
740 
741     /**
742      * Gets the current layout algorithm.
743      *
744      * @return the layout algorithm in use, as a {@link LayoutAlgorithm} value
745      * @see #setLayoutAlgorithm
746      */
getLayoutAlgorithm()747     public abstract LayoutAlgorithm getLayoutAlgorithm();
748 
749     /**
750      * Sets the standard font family name. The default is "sans-serif".
751      *
752      * @param font a font family name
753      */
setStandardFontFamily(String font)754     public abstract void setStandardFontFamily(String font);
755 
756     /**
757      * Gets the standard font family name.
758      *
759      * @return the standard font family name as a string
760      * @see #setStandardFontFamily
761      */
getStandardFontFamily()762     public abstract String getStandardFontFamily();
763 
764     /**
765      * Sets the fixed font family name. The default is "monospace".
766      *
767      * @param font a font family name
768      */
setFixedFontFamily(String font)769     public abstract void setFixedFontFamily(String font);
770 
771     /**
772      * Gets the fixed font family name.
773      *
774      * @return the fixed font family name as a string
775      * @see #setFixedFontFamily
776      */
getFixedFontFamily()777     public abstract String getFixedFontFamily();
778 
779     /**
780      * Sets the sans-serif font family name. The default is "sans-serif".
781      *
782      * @param font a font family name
783      */
setSansSerifFontFamily(String font)784     public abstract void setSansSerifFontFamily(String font);
785 
786     /**
787      * Gets the sans-serif font family name.
788      *
789      * @return the sans-serif font family name as a string
790      * @see #setSansSerifFontFamily
791      */
getSansSerifFontFamily()792     public abstract String getSansSerifFontFamily();
793 
794     /**
795      * Sets the serif font family name. The default is "sans-serif".
796      *
797      * @param font a font family name
798      */
setSerifFontFamily(String font)799     public abstract void setSerifFontFamily(String font);
800 
801     /**
802      * Gets the serif font family name. The default is "serif".
803      *
804      * @return the serif font family name as a string
805      * @see #setSerifFontFamily
806      */
getSerifFontFamily()807     public abstract String getSerifFontFamily();
808 
809     /**
810      * Sets the cursive font family name. The default is "cursive".
811      *
812      * @param font a font family name
813      */
setCursiveFontFamily(String font)814     public abstract void setCursiveFontFamily(String font);
815 
816     /**
817      * Gets the cursive font family name.
818      *
819      * @return the cursive font family name as a string
820      * @see #setCursiveFontFamily
821      */
getCursiveFontFamily()822     public abstract String getCursiveFontFamily();
823 
824     /**
825      * Sets the fantasy font family name. The default is "fantasy".
826      *
827      * @param font a font family name
828      */
setFantasyFontFamily(String font)829     public abstract void setFantasyFontFamily(String font);
830 
831     /**
832      * Gets the fantasy font family name.
833      *
834      * @return the fantasy font family name as a string
835      * @see #setFantasyFontFamily
836      */
getFantasyFontFamily()837     public abstract String getFantasyFontFamily();
838 
839     /**
840      * Sets the minimum font size. The default is 8.
841      *
842      * @param size a non-negative integer between 1 and 72. Any number outside
843      *             the specified range will be pinned.
844      */
setMinimumFontSize(int size)845     public abstract void setMinimumFontSize(int size);
846 
847     /**
848      * Gets the minimum font size.
849      *
850      * @return a non-negative integer between 1 and 72
851      * @see #setMinimumFontSize
852      */
getMinimumFontSize()853     public abstract int getMinimumFontSize();
854 
855     /**
856      * Sets the minimum logical font size. The default is 8.
857      *
858      * @param size a non-negative integer between 1 and 72. Any number outside
859      *             the specified range will be pinned.
860      */
setMinimumLogicalFontSize(int size)861     public abstract void setMinimumLogicalFontSize(int size);
862 
863     /**
864      * Gets the minimum logical font size.
865      *
866      * @return a non-negative integer between 1 and 72
867      * @see #setMinimumLogicalFontSize
868      */
getMinimumLogicalFontSize()869     public abstract int getMinimumLogicalFontSize();
870 
871     /**
872      * Sets the default font size. The default is 16.
873      *
874      * @param size a non-negative integer between 1 and 72. Any number outside
875      *             the specified range will be pinned.
876      */
setDefaultFontSize(int size)877     public abstract void setDefaultFontSize(int size);
878 
879     /**
880      * Gets the default font size.
881      *
882      * @return a non-negative integer between 1 and 72
883      * @see #setDefaultFontSize
884      */
getDefaultFontSize()885     public abstract int getDefaultFontSize();
886 
887     /**
888      * Sets the default fixed font size. The default is 16.
889      *
890      * @param size a non-negative integer between 1 and 72. Any number outside
891      *             the specified range will be pinned.
892      */
setDefaultFixedFontSize(int size)893     public abstract void setDefaultFixedFontSize(int size);
894 
895     /**
896      * Gets the default fixed font size.
897      *
898      * @return a non-negative integer between 1 and 72
899      * @see #setDefaultFixedFontSize
900      */
getDefaultFixedFontSize()901     public abstract int getDefaultFixedFontSize();
902 
903     /**
904      * Sets whether the WebView should load image resources. Note that this method
905      * controls loading of all images, including those embedded using the data
906      * URI scheme. Use {@link #setBlockNetworkImage} to control loading only
907      * of images specified using network URI schemes. Note that if the value of this
908      * setting is changed from {@code false} to {@code true}, all images resources referenced
909      * by content currently displayed by the WebView are loaded automatically.
910      * The default is {@code true}.
911      *
912      * @param flag whether the WebView should load image resources
913      */
setLoadsImagesAutomatically(boolean flag)914     public abstract void setLoadsImagesAutomatically(boolean flag);
915 
916     /**
917      * Gets whether the WebView loads image resources. This includes
918      * images embedded using the data URI scheme.
919      *
920      * @return {@code true} if the WebView loads image resources
921      * @see #setLoadsImagesAutomatically
922      */
getLoadsImagesAutomatically()923     public abstract boolean getLoadsImagesAutomatically();
924 
925     /**
926      * Sets whether the WebView should not load image resources from the
927      * network (resources accessed via http and https URI schemes).  Note
928      * that this method has no effect unless
929      * {@link #getLoadsImagesAutomatically} returns {@code true}. Also note that
930      * disabling all network loads using {@link #setBlockNetworkLoads}
931      * will also prevent network images from loading, even if this flag is set
932      * to false. When the value of this setting is changed from {@code true} to {@code false},
933      * network images resources referenced by content currently displayed by
934      * the WebView are fetched automatically. The default is {@code false}.
935      *
936      * @param flag whether the WebView should not load image resources from the
937      *             network
938      * @see #setBlockNetworkLoads
939      */
setBlockNetworkImage(boolean flag)940     public abstract void setBlockNetworkImage(boolean flag);
941 
942     /**
943      * Gets whether the WebView does not load image resources from the network.
944      *
945      * @return {@code true} if the WebView does not load image resources from the network
946      * @see #setBlockNetworkImage
947      */
getBlockNetworkImage()948     public abstract boolean getBlockNetworkImage();
949 
950     /**
951      * Sets whether the WebView should not load resources from the network.
952      * Use {@link #setBlockNetworkImage} to only avoid loading
953      * image resources. Note that if the value of this setting is
954      * changed from {@code true} to {@code false}, network resources referenced by content
955      * currently displayed by the WebView are not fetched until
956      * {@link android.webkit.WebView#reload} is called.
957      * If the application does not have the
958      * {@link android.Manifest.permission#INTERNET} permission, attempts to set
959      * a value of {@code false} will cause a {@link java.lang.SecurityException}
960      * to be thrown. The default value is {@code false} if the application has the
961      * {@link android.Manifest.permission#INTERNET} permission, otherwise it is
962      * {@code true}.
963      *
964      * @param flag {@code true} means block network loads by the WebView
965      * @see android.webkit.WebView#reload
966      */
setBlockNetworkLoads(boolean flag)967     public abstract void setBlockNetworkLoads(boolean flag);
968 
969     /**
970      * Gets whether the WebView does not load any resources from the network.
971      *
972      * @return {@code true} if the WebView does not load any resources from the network
973      * @see #setBlockNetworkLoads
974      */
getBlockNetworkLoads()975     public abstract boolean getBlockNetworkLoads();
976 
977     /**
978      * Tells the WebView to enable JavaScript execution.
979      * <b>The default is {@code false}.</b>
980      *
981      * @param flag {@code true} if the WebView should execute JavaScript
982      */
setJavaScriptEnabled(boolean flag)983     public abstract void setJavaScriptEnabled(boolean flag);
984 
985     /**
986      * Sets whether cross-origin requests in the context of a file scheme URL should be allowed to
987      * access content from <i>any</i> origin. This includes access to content from other file
988      * scheme URLs or web contexts. Note that some access such as image HTML elements doesn't
989      * follow same-origin rules and isn't affected by this setting.
990      * <p>
991      * <b>Don't</b> enable this setting if you open files that may be created or altered by
992      * external sources. Enabling this setting allows malicious scripts loaded in a {@code file://}
993      * context to launch cross-site scripting attacks, either accessing arbitrary local files
994      * including WebView cookies, app private data or even credentials used on arbitrary web sites.
995      * <p class="note">
996      * Loading content via {@code file://} URLs is generally discouraged. See the note in
997      * {@link #setAllowFileAccess}.
998      * <p>
999      * The default value is {@code true} for apps targeting
1000      * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, and {@code false}
1001      * when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and above. To prevent
1002      * possible violation of same domain policy when targeting
1003      * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, you should
1004      * explicitly set this value to {@code false}.
1005      *
1006      * @param flag whether JavaScript running in the context of a file scheme URL should be allowed
1007      *             to access content from any origin
1008      * @deprecated This setting is not secure, please use
1009      *             <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html">
1010      *             androidx.webkit.WebViewAssetLoader</a> to load file content securely.
1011      */
1012     @Deprecated
setAllowUniversalAccessFromFileURLs(boolean flag)1013     public abstract void setAllowUniversalAccessFromFileURLs(boolean flag);
1014 
1015     /**
1016      * Sets whether cross-origin requests in the context of a file scheme URL should be allowed to
1017      * access content from other file scheme URLs. Note that some accesses such as image HTML
1018      * elements don't follow same-origin rules and aren't affected by this setting.
1019      * <p>
1020      * <b>Don't</b> enable this setting if you open files that may be created or altered by
1021      * external sources. Enabling this setting allows malicious scripts loaded in a {@code file://}
1022      * context to access arbitrary local files including WebView cookies and app private data.
1023      * <p class="note">
1024      * Loading content via {@code file://} URLs is generally discouraged. See the note in
1025      * {@link #setAllowFileAccess}.
1026      * <p>
1027      * Note that the value of this setting is ignored if the value of
1028      * {@link #getAllowUniversalAccessFromFileURLs} is {@code true}. The default value is
1029      * {@code true} for apps targeting {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1}
1030      * and below, and {@code false} when targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1031      * and above. To prevent possible violation of same domain policy when targeting
1032      * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, you should
1033      * explicitly set this value to {@code false}.
1034      *
1035      * @param flag whether JavaScript running in the context of a file scheme
1036      *             URL should be allowed to access content from other file
1037      *             scheme URLs
1038      * @deprecated This setting is not secure, please use
1039      *             <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader.html">
1040      *             androidx.webkit.WebViewAssetLoader</a> to load file content securely.
1041      */
1042     @Deprecated
setAllowFileAccessFromFileURLs(boolean flag)1043     public abstract void setAllowFileAccessFromFileURLs(boolean flag);
1044 
1045     /**
1046      * Sets whether the WebView should enable plugins. The default is {@code false}.
1047      *
1048      * @param flag {@code true} if plugins should be enabled
1049      * @deprecated This method has been deprecated in favor of
1050      *             {@link #setPluginState}
1051      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}
1052      */
1053     @SystemApi
1054     @Deprecated
setPluginsEnabled(boolean flag)1055     public abstract void setPluginsEnabled(boolean flag);
1056 
1057     /**
1058      * Tells the WebView to enable, disable, or have plugins on demand. On
1059      * demand mode means that if a plugin exists that can handle the embedded
1060      * content, a placeholder icon will be shown instead of the plugin. When
1061      * the placeholder is clicked, the plugin will be enabled. The default is
1062      * {@link PluginState#OFF}.
1063      *
1064      * @param state a PluginState value
1065      * @deprecated Plugins are not supported in API level
1066      *             {@link android.os.Build.VERSION_CODES#KITKAT} or later;
1067      *             enabling plugins is a no-op.
1068      */
1069     @Deprecated
setPluginState(PluginState state)1070     public abstract void setPluginState(PluginState state);
1071 
1072     /**
1073      * Sets a custom path to plugins used by the WebView. This method is
1074      * obsolete since each plugin is now loaded from its own package.
1075      *
1076      * @param pluginsPath a String path to the directory containing plugins
1077      * @deprecated This method is no longer used as plugins are loaded from
1078      *             their own APK via the system's package manager.
1079      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}
1080      */
1081     @Deprecated
1082     @UnsupportedAppUsage
setPluginsPath(String pluginsPath)1083     public void setPluginsPath(String pluginsPath) {
1084         // Specified to do nothing, so no need for derived classes to override.
1085     }
1086 
1087     /**
1088      * Sets the path to where database storage API databases should be saved.
1089      * In order for the database storage API to function correctly, this method
1090      * must be called with a path to which the application can write. This
1091      * method should only be called once: repeated calls are ignored.
1092      *
1093      * @param databasePath a path to the directory where databases should be
1094      *                     saved.
1095      * @deprecated Database paths are managed by the implementation and calling this method
1096      *             will have no effect.
1097      */
1098     @Deprecated
setDatabasePath(String databasePath)1099     public abstract void setDatabasePath(String databasePath);
1100 
1101     /**
1102      * Sets the path where the Geolocation databases should be saved. In order
1103      * for Geolocation permissions and cached positions to be persisted, this
1104      * method must be called with a path to which the application can write.
1105      *
1106      * @param databasePath a path to the directory where databases should be
1107      *                     saved.
1108      * @deprecated Geolocation database are managed by the implementation and calling this method
1109      *             will have no effect.
1110      */
1111     @Deprecated
setGeolocationDatabasePath(String databasePath)1112     public abstract void setGeolocationDatabasePath(String databasePath);
1113 
1114     /**
1115      * Sets whether the Application Caches API should be enabled. The default
1116      * is {@code false}. Note that in order for the Application Caches API to be
1117      * enabled, a valid database path must also be supplied to
1118      * {@link #setAppCachePath}.
1119      *
1120      * @param flag {@code true} if the WebView should enable Application Caches
1121      * @deprecated The Application Cache API is deprecated and this method will
1122      *             become a no-op on all Android versions once support is
1123      *             removed in Chromium. Consider using Service Workers instead.
1124      *             See https://web.dev/appcache-removal/ for more information.
1125      */
setAppCacheEnabled(boolean flag)1126     public abstract void setAppCacheEnabled(boolean flag);
1127 
1128     /**
1129      * Sets the path to the Application Caches files. In order for the
1130      * Application Caches API to be enabled, this method must be called with a
1131      * path to which the application can write. This method should only be
1132      * called once: repeated calls are ignored.
1133      *
1134      * @param appCachePath a String path to the directory containing
1135      *                     Application Caches files.
1136      * @see #setAppCacheEnabled
1137      * @deprecated The Application Cache API is deprecated and this method will
1138      *             become a no-op on all Android versions once support is
1139      *             removed in Chromium. Consider using Service Workers instead.
1140      *             See https://web.dev/appcache-removal/ for more information.
1141      */
setAppCachePath(String appCachePath)1142     public abstract void setAppCachePath(String appCachePath);
1143 
1144     /**
1145      * Sets the maximum size for the Application Cache content. The passed size
1146      * will be rounded to the nearest value that the database can support, so
1147      * this should be viewed as a guide, not a hard limit. Setting the
1148      * size to a value less than current database size does not cause the
1149      * database to be trimmed. The default size is {@link Long#MAX_VALUE}.
1150      * It is recommended to leave the maximum size set to the default value.
1151      *
1152      * @param appCacheMaxSize the maximum size in bytes
1153      * @deprecated Quota is managed automatically; this method is a no-op.
1154      */
1155     @Deprecated
setAppCacheMaxSize(long appCacheMaxSize)1156     public abstract void setAppCacheMaxSize(long appCacheMaxSize);
1157 
1158     /**
1159      * Sets whether the database storage API is enabled. The default value is
1160      * false. See also {@link #setDatabasePath} for how to correctly set up the
1161      * database storage API.
1162      *
1163      * This setting is global in effect, across all WebView instances in a process.
1164      * Note you should only modify this setting prior to making <b>any</b> WebView
1165      * page load within a given process, as the WebView implementation may ignore
1166      * changes to this setting after that point.
1167      *
1168      * @param flag {@code true} if the WebView should use the database storage API
1169      */
setDatabaseEnabled(boolean flag)1170     public abstract void setDatabaseEnabled(boolean flag);
1171 
1172     /**
1173      * Sets whether the DOM storage API is enabled. The default value is {@code false}.
1174      *
1175      * @param flag {@code true} if the WebView should use the DOM storage API
1176      */
setDomStorageEnabled(boolean flag)1177     public abstract void setDomStorageEnabled(boolean flag);
1178 
1179     /**
1180      * Gets whether the DOM Storage APIs are enabled.
1181      *
1182      * @return {@code true} if the DOM Storage APIs are enabled
1183      * @see #setDomStorageEnabled
1184      */
getDomStorageEnabled()1185     public abstract boolean getDomStorageEnabled();
1186 
1187     /**
1188      * Gets the path to where database storage API databases are saved.
1189      *
1190      * @return the String path to the database storage API databases
1191      * @see #setDatabasePath
1192      * @deprecated Database paths are managed by the implementation this method is obsolete.
1193      */
1194     @Deprecated
getDatabasePath()1195     public abstract String getDatabasePath();
1196 
1197     /**
1198      * Gets whether the database storage API is enabled.
1199      *
1200      * @return {@code true} if the database storage API is enabled
1201      * @see #setDatabaseEnabled
1202      */
getDatabaseEnabled()1203     public abstract boolean getDatabaseEnabled();
1204 
1205     /**
1206      * Sets whether Geolocation is enabled. The default is {@code true}.
1207      * <p>
1208      * Please note that in order for the Geolocation API to be usable
1209      * by a page in the WebView, the following requirements must be met:
1210      * <ul>
1211      *   <li>an application must have permission to access the device location,
1212      *   see {@link android.Manifest.permission#ACCESS_COARSE_LOCATION},
1213      *   {@link android.Manifest.permission#ACCESS_FINE_LOCATION};
1214      *   <li>an application must provide an implementation of the
1215      *   {@link WebChromeClient#onGeolocationPermissionsShowPrompt} callback
1216      *   to receive notifications that a page is requesting access to location
1217      *   via the JavaScript Geolocation API.
1218      * </ul>
1219      * <p>
1220      *
1221      * @param flag whether Geolocation should be enabled
1222      */
setGeolocationEnabled(boolean flag)1223     public abstract void setGeolocationEnabled(boolean flag);
1224 
1225     /**
1226      * Gets whether JavaScript is enabled.
1227      *
1228      * @return {@code true} if JavaScript is enabled
1229      * @see #setJavaScriptEnabled
1230      */
getJavaScriptEnabled()1231     public abstract boolean getJavaScriptEnabled();
1232 
1233     /**
1234      * Gets whether JavaScript running in the context of a file scheme URL can
1235      * access content from any origin. This includes access to content from
1236      * other file scheme URLs.
1237      *
1238      * @return whether JavaScript running in the context of a file scheme URL
1239      *         can access content from any origin
1240      * @see #setAllowUniversalAccessFromFileURLs
1241      */
getAllowUniversalAccessFromFileURLs()1242     public abstract boolean getAllowUniversalAccessFromFileURLs();
1243 
1244     /**
1245      * Gets whether JavaScript running in the context of a file scheme URL can
1246      * access content from other file scheme URLs.
1247      *
1248      * @return whether JavaScript running in the context of a file scheme URL
1249      *         can access content from other file scheme URLs
1250      * @see #setAllowFileAccessFromFileURLs
1251      */
getAllowFileAccessFromFileURLs()1252     public abstract boolean getAllowFileAccessFromFileURLs();
1253 
1254     /**
1255      * Gets whether plugins are enabled.
1256      *
1257      * @return {@code true} if plugins are enabled
1258      * @see #setPluginsEnabled
1259      * @deprecated This method has been replaced by {@link #getPluginState}
1260      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}
1261      */
1262     @SystemApi
1263     @Deprecated
getPluginsEnabled()1264     public abstract boolean getPluginsEnabled();
1265 
1266     /**
1267      * Gets the current state regarding whether plugins are enabled.
1268      *
1269      * @return the plugin state as a {@link PluginState} value
1270      * @see #setPluginState
1271      * @deprecated Plugins are not supported in API level
1272      *             {@link android.os.Build.VERSION_CODES#KITKAT} or later;
1273      *             enabling plugins is a no-op.
1274      */
1275     @Deprecated
getPluginState()1276     public abstract PluginState getPluginState();
1277 
1278     /**
1279      * Gets the directory that contains the plugin libraries. This method is
1280      * obsolete since each plugin is now loaded from its own package.
1281      *
1282      * @return an empty string
1283      * @deprecated This method is no longer used as plugins are loaded from
1284      * their own APK via the system's package manager.
1285      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}
1286      */
1287     @Deprecated
1288     @UnsupportedAppUsage
getPluginsPath()1289     public String getPluginsPath() {
1290         // Unconditionally returns empty string, so no need for derived classes to override.
1291         return "";
1292     }
1293 
1294     /**
1295      * Tells JavaScript to open windows automatically. This applies to the
1296      * JavaScript function {@code window.open()}. The default is {@code false}.
1297      *
1298      * @param flag {@code true} if JavaScript can open windows automatically
1299      */
setJavaScriptCanOpenWindowsAutomatically(boolean flag)1300     public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean flag);
1301 
1302     /**
1303      * Gets whether JavaScript can open windows automatically.
1304      *
1305      * @return {@code true} if JavaScript can open windows automatically during
1306      *         {@code window.open()}
1307      * @see #setJavaScriptCanOpenWindowsAutomatically
1308      */
getJavaScriptCanOpenWindowsAutomatically()1309     public abstract boolean getJavaScriptCanOpenWindowsAutomatically();
1310 
1311     /**
1312      * Sets the default text encoding name to use when decoding html pages.
1313      * The default is "UTF-8".
1314      *
1315      * @param encoding the text encoding name
1316      */
setDefaultTextEncodingName(String encoding)1317     public abstract void setDefaultTextEncodingName(String encoding);
1318 
1319     /**
1320      * Gets the default text encoding name.
1321      *
1322      * @return the default text encoding name as a string
1323      * @see #setDefaultTextEncodingName
1324      */
getDefaultTextEncodingName()1325     public abstract String getDefaultTextEncodingName();
1326 
1327     /**
1328      * Sets the WebView's user-agent string. If the string is {@code null} or empty,
1329      * the system default value will be used.
1330      *
1331      * Note that starting from {@link android.os.Build.VERSION_CODES#KITKAT} Android
1332      * version, changing the user-agent while loading a web page causes WebView
1333      * to initiate loading once again.
1334      *
1335      * @param ua new user-agent string
1336      */
setUserAgentString(@ullable String ua)1337     public abstract void setUserAgentString(@Nullable String ua);
1338 
1339     /**
1340      * Gets the WebView's user-agent string.
1341      *
1342      * @return the WebView's user-agent string
1343      * @see #setUserAgentString
1344      */
getUserAgentString()1345     public abstract String getUserAgentString();
1346 
1347     /**
1348      * Returns the default User-Agent used by a WebView.
1349      * An instance of WebView could use a different User-Agent if a call
1350      * is made to {@link WebSettings#setUserAgentString(String)}.
1351      *
1352      * @param context a Context object used to access application assets
1353      */
getDefaultUserAgent(Context context)1354     public static String getDefaultUserAgent(Context context) {
1355         return WebViewFactory.getProvider().getStatics().getDefaultUserAgent(context);
1356     }
1357 
1358     /**
1359      * Tells the WebView whether it needs to set a node to have focus when
1360      * {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The
1361      * default value is {@code true}.
1362      *
1363      * @param flag whether the WebView needs to set a node
1364      */
setNeedInitialFocus(boolean flag)1365     public abstract void setNeedInitialFocus(boolean flag);
1366 
1367     /**
1368      * Sets the priority of the Render thread. Unlike the other settings, this
1369      * one only needs to be called once per process. The default value is
1370      * {@link RenderPriority#NORMAL}.
1371      *
1372      * @param priority the priority
1373      * @deprecated It is not recommended to adjust thread priorities, and this will
1374      *             not be supported in future versions.
1375      */
1376     @Deprecated
setRenderPriority(RenderPriority priority)1377     public abstract void setRenderPriority(RenderPriority priority);
1378 
1379     /**
1380      * Overrides the way the cache is used. The way the cache is used is based
1381      * on the navigation type. For a normal page load, the cache is checked
1382      * and content is re-validated as needed. When navigating back, content is
1383      * not revalidated, instead the content is just retrieved from the cache.
1384      * This method allows the client to override this behavior by specifying
1385      * one of {@link #LOAD_DEFAULT},
1386      * {@link #LOAD_CACHE_ELSE_NETWORK}, {@link #LOAD_NO_CACHE} or
1387      * {@link #LOAD_CACHE_ONLY}. The default value is {@link #LOAD_DEFAULT}.
1388      *
1389      * @param mode the mode to use
1390      */
setCacheMode(@acheMode int mode)1391     public abstract void setCacheMode(@CacheMode int mode);
1392 
1393     /**
1394      * Gets the current setting for overriding the cache mode.
1395      *
1396      * @return the current setting for overriding the cache mode
1397      * @see #setCacheMode
1398      */
1399     @CacheMode
getCacheMode()1400     public abstract int getCacheMode();
1401 
1402     /**
1403      * Configures the WebView's behavior when a secure origin attempts to load a resource from an
1404      * insecure origin.
1405      *
1406      * By default, apps that target {@link android.os.Build.VERSION_CODES#KITKAT} or below default
1407      * to {@link #MIXED_CONTENT_ALWAYS_ALLOW}. Apps targeting
1408      * {@link android.os.Build.VERSION_CODES#LOLLIPOP} default to {@link #MIXED_CONTENT_NEVER_ALLOW}.
1409      *
1410      * The preferred and most secure mode of operation for the WebView is
1411      * {@link #MIXED_CONTENT_NEVER_ALLOW} and use of {@link #MIXED_CONTENT_ALWAYS_ALLOW} is
1412      * strongly discouraged.
1413      *
1414      * @param mode The mixed content mode to use. One of {@link #MIXED_CONTENT_NEVER_ALLOW},
1415      *     {@link #MIXED_CONTENT_ALWAYS_ALLOW} or {@link #MIXED_CONTENT_COMPATIBILITY_MODE}.
1416      */
setMixedContentMode(int mode)1417     public abstract void setMixedContentMode(int mode);
1418 
1419     /**
1420      * Gets the current behavior of the WebView with regard to loading insecure content from a
1421      * secure origin.
1422      * @return The current setting, one of {@link #MIXED_CONTENT_NEVER_ALLOW},
1423      *     {@link #MIXED_CONTENT_ALWAYS_ALLOW} or {@link #MIXED_CONTENT_COMPATIBILITY_MODE}.
1424      */
getMixedContentMode()1425     public abstract int getMixedContentMode();
1426 
1427     /**
1428      * Sets whether to use a video overlay for embedded encrypted video.
1429      * In API levels prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, encrypted video can
1430      * only be rendered directly on a secure video surface, so it had been a hard problem to play
1431      * encrypted video in HTML.  When this flag is on, WebView can play encrypted video (MSE/EME)
1432      * by using a video overlay (aka hole-punching) for videos embedded using HTML &lt;video&gt;
1433      * tag.<br>
1434      * Caution: This setting is intended for use only in a narrow set of circumstances and apps
1435      * should only enable it if they require playback of encrypted video content. It will impose
1436      * the following limitations on the WebView:
1437      * <ul>
1438      * <li> Only one video overlay can be played at a time.
1439      * <li> Changes made to position or dimensions of a video element may be propagated to the
1440      * corresponding video overlay with a noticeable delay.
1441      * <li> The video overlay is not visible to web APIs and as such may not interact with
1442      * script or styling. For example, CSS styles applied to the &lt;video&gt; tag may be ignored.
1443      * </ul>
1444      * This is not an exhaustive set of constraints and it may vary with new versions of the
1445      * WebView.
1446      * @hide
1447      */
1448     @SystemApi
setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean flag)1449     public abstract void setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean flag);
1450 
1451     /**
1452      * Gets whether a video overlay will be used for embedded encrypted video.
1453      *
1454      * @return {@code true} if WebView uses a video overlay for embedded encrypted video.
1455      * @see #setVideoOverlayForEmbeddedEncryptedVideoEnabled
1456      * @hide
1457      */
1458     @SystemApi
getVideoOverlayForEmbeddedEncryptedVideoEnabled()1459     public abstract boolean getVideoOverlayForEmbeddedEncryptedVideoEnabled();
1460 
1461     /**
1462      * Sets whether this WebView should raster tiles when it is
1463      * offscreen but attached to a window. Turning this on can avoid
1464      * rendering artifacts when animating an offscreen WebView on-screen.
1465      * Offscreen WebViews in this mode use more memory. The default value is
1466      * false.<br>
1467      * Please follow these guidelines to limit memory usage:
1468      * <ul>
1469      * <li> WebView size should be not be larger than the device screen size.
1470      * <li> Limit use of this mode to a small number of WebViews. Use it for
1471      *   visible WebViews and WebViews about to be animated to visible.
1472      * </ul>
1473      */
setOffscreenPreRaster(boolean enabled)1474     public abstract void setOffscreenPreRaster(boolean enabled);
1475 
1476     /**
1477      * Gets whether this WebView should raster tiles when it is
1478      * offscreen but attached to a window.
1479      * @return {@code true} if this WebView will raster tiles when it is
1480      * offscreen but attached to a window.
1481      */
getOffscreenPreRaster()1482     public abstract boolean getOffscreenPreRaster();
1483 
1484 
1485     /**
1486      * Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to
1487      * protect against malware and phishing attacks by verifying the links.
1488      *
1489      * <p>
1490      * Safe Browsing can be disabled for all WebViews using a manifest tag (read <a
1491      * href="{@docRoot}reference/android/webkit/WebView.html">general Safe Browsing info</a>). The
1492      * manifest tag has a lower precedence than this API.
1493      *
1494      * <p>
1495      * Safe Browsing is enabled by default for devices which support it.
1496      *
1497      * @param enabled Whether Safe Browsing is enabled.
1498      */
setSafeBrowsingEnabled(boolean enabled)1499     public abstract void setSafeBrowsingEnabled(boolean enabled);
1500 
1501     /**
1502      * Gets whether Safe Browsing is enabled.
1503      * See {@link #setSafeBrowsingEnabled}.
1504      *
1505      * @return {@code true} if Safe Browsing is enabled and {@code false} otherwise.
1506      */
getSafeBrowsingEnabled()1507     public abstract boolean getSafeBrowsingEnabled();
1508 
1509 
1510     /**
1511      * Set the force dark mode for this WebView.
1512      *
1513      * @param forceDark the force dark mode to set.
1514      * @see #getForceDark
1515      */
setForceDark(@orceDark int forceDark)1516     public void setForceDark(@ForceDark int forceDark) {
1517         // Stub implementation to satisfy Roboelectrc shadows that don't override this yet.
1518     }
1519 
1520     /**
1521      * Get the force dark mode for this WebView.
1522      * The default force dark mode is {@link #FORCE_DARK_AUTO}.
1523      *
1524      * @return the currently set force dark mode.
1525      * @see #setForceDark
1526      */
getForceDark()1527     public @ForceDark int getForceDark() {
1528         // Stub implementation to satisfy Roboelectrc shadows that don't override this yet.
1529         return FORCE_DARK_AUTO;
1530     }
1531 
1532     /**
1533      * @hide
1534      */
1535     @IntDef(flag = true, prefix = { "MENU_ITEM_" }, value = {
1536             MENU_ITEM_NONE,
1537             MENU_ITEM_SHARE,
1538             MENU_ITEM_WEB_SEARCH,
1539             MENU_ITEM_PROCESS_TEXT
1540     })
1541     @Retention(RetentionPolicy.SOURCE)
1542     @Target({ElementType.PARAMETER, ElementType.METHOD})
1543     private @interface MenuItemFlags {}
1544 
1545     /**
1546      * Disables the action mode menu items according to {@code menuItems} flag.
1547      * @param menuItems an integer field flag for the menu items to be disabled.
1548      */
setDisabledActionModeMenuItems(@enuItemFlags int menuItems)1549     public abstract void setDisabledActionModeMenuItems(@MenuItemFlags int menuItems);
1550 
1551     /**
1552      * Gets the action mode menu items that are disabled, expressed in an integer field flag.
1553      * The default value is {@link #MENU_ITEM_NONE}
1554      *
1555      * @return all the disabled menu item flags combined with bitwise OR.
1556      */
getDisabledActionModeMenuItems()1557     public abstract @MenuItemFlags int getDisabledActionModeMenuItems();
1558 
1559     /**
1560      * No menu items should be disabled.
1561      *
1562      * @see #setDisabledActionModeMenuItems
1563      */
1564     public static final int MENU_ITEM_NONE = 0;
1565 
1566     /**
1567      * Disable menu item "Share".
1568      *
1569      * @see #setDisabledActionModeMenuItems
1570      */
1571     public static final int MENU_ITEM_SHARE = 1 << 0;
1572 
1573     /**
1574      * Disable menu item "Web Search".
1575      *
1576      * @see #setDisabledActionModeMenuItems
1577      */
1578     public static final int MENU_ITEM_WEB_SEARCH = 1 << 1;
1579 
1580     /**
1581      * Disable all the action mode menu items for text processing.
1582      * By default WebView searches for activities that are able to handle
1583      * {@link android.content.Intent#ACTION_PROCESS_TEXT} and show them in the
1584      * action mode menu. If this flag is set via {@link
1585      * #setDisabledActionModeMenuItems}, these menu items will be disabled.
1586      *
1587      * @see #setDisabledActionModeMenuItems
1588      */
1589     public static final int MENU_ITEM_PROCESS_TEXT = 1 << 2;
1590 }
1591