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