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