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