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