Debian Codegraph @

core/java/android/webkit/WebSettings.java

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