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.content.Context; 20 21 /** 22 * Manages settings state for a WebView. When a WebView is first created, it 23 * obtains a set of default settings. These default settings will be returned 24 * from any getter call. A WebSettings object obtained from 25 * WebView.getSettings() is tied to the life of the WebView. If a WebView has 26 * been destroyed, any method call on WebSettings will throw an 27 * IllegalStateException. 28 */ 29 // This is an abstract base class: concrete WebViewProviders must 30 // create a class derived from this, and return an instance of it in the 31 // WebViewProvider.getWebSettingsProvider() method implementation. 32 public abstract class WebSettings { 33 /** 34 * Enum for controlling the layout of html. 35 * <ul> 36 * <li>NORMAL means no rendering changes.</li> 37 * <li>SINGLE_COLUMN moves all content into one column that is the width of the 38 * view.</li> 39 * <li>NARROW_COLUMNS makes all columns no wider than the screen if possible.</li> 40 * <li>TEXT_AUTOSIZING boosts font size of paragraphs based on heuristics to make 41 * the text readable when viewing a wide-viewport layout in the overview mode. 42 * It is recommended to enable zoom support {@link #setSupportZoom} when 43 * using this mode.</li> 44 * </ul> 45 */ 46 // XXX: These must match LayoutAlgorithm in Settings.h in WebCore. 47 public enum LayoutAlgorithm { 48 NORMAL, 49 /** 50 * @deprecated This algorithm is now obsolete. 51 */ 52 @Deprecated 53 SINGLE_COLUMN, 54 NARROW_COLUMNS, 55 /** 56 * @hide 57 */ 58 TEXT_AUTOSIZING 59 } 60 61 /** 62 * Enum for specifying the text size. 63 * <ul> 64 * <li>SMALLEST is 50%</li> 65 * <li>SMALLER is 75%</li> 66 * <li>NORMAL is 100%</li> 67 * <li>LARGER is 150%</li> 68 * <li>LARGEST is 200%</li> 69 * </ul> 70 * 71 * @deprecated Use {@link WebSettings#setTextZoom(int)} and {@link WebSettings#getTextZoom()} instead. 72 */ 73 public enum TextSize { 74 SMALLEST(50), 75 SMALLER(75), 76 NORMAL(100), 77 LARGER(150), 78 LARGEST(200); TextSize(int size)79 TextSize(int size) { 80 value = size; 81 } 82 int value; 83 } 84 85 /** 86 * Enum for specifying the WebView's desired density. 87 * <ul> 88 * <li>FAR makes 100% looking like in 240dpi</li> 89 * <li>MEDIUM makes 100% looking like in 160dpi</li> 90 * <li>CLOSE makes 100% looking like in 120dpi</li> 91 * </ul> 92 */ 93 public enum ZoomDensity { 94 FAR(150), // 240dpi 95 MEDIUM(100), // 160dpi 96 CLOSE(75); // 120dpi ZoomDensity(int size)97 ZoomDensity(int size) { 98 value = size; 99 } 100 101 /** 102 * @hide Only for use by WebViewProvider implementations 103 */ getValue()104 public int getValue() { 105 return value; 106 } 107 108 int value; 109 } 110 111 /** 112 * Default cache usage mode. If the navigation type doesn't impose any 113 * specific behavior, use cached resources when they are available 114 * and not expired, otherwise load resources from the network. 115 * Use with {@link #setCacheMode}. 116 */ 117 public static final int LOAD_DEFAULT = -1; 118 119 /** 120 * Normal cache usage mode. Use with {@link #setCacheMode}. 121 * 122 * @deprecated This value is obsolete, as from API level 123 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and onwards it has the 124 * same effect as {@link #LOAD_DEFAULT}. 125 */ 126 @Deprecated 127 public static final int LOAD_NORMAL = 0; 128 129 /** 130 * Use cached resources when they are available, even if they have expired. 131 * Otherwise load resources from the network. 132 * Use with {@link #setCacheMode}. 133 */ 134 public static final int LOAD_CACHE_ELSE_NETWORK = 1; 135 136 /** 137 * Don't use the cache, load from the network. 138 * Use with {@link #setCacheMode}. 139 */ 140 public static final int LOAD_NO_CACHE = 2; 141 142 /** 143 * Don't use the network, load from the cache. 144 * Use with {@link #setCacheMode}. 145 */ 146 public static final int LOAD_CACHE_ONLY = 3; 147 148 public enum RenderPriority { 149 NORMAL, 150 HIGH, 151 LOW 152 } 153 154 /** 155 * The plugin state effects how plugins are treated on a page. ON means 156 * that any object will be loaded even if a plugin does not exist to handle 157 * the content. ON_DEMAND means that if there is a plugin installed that 158 * can handle the content, a placeholder is shown until the user clicks on 159 * the placeholder. Once clicked, the plugin will be enabled on the page. 160 * OFF means that all plugins will be turned off and any fallback content 161 * will be used. 162 */ 163 public enum PluginState { 164 ON, 165 ON_DEMAND, 166 OFF 167 } 168 169 /** 170 * Hidden constructor to prevent clients from creating a new settings 171 * instance or deriving the class. 172 * 173 * @hide 174 */ WebSettings()175 protected WebSettings() { 176 } 177 178 /** 179 * Enables dumping the pages navigation cache to a text file. The default 180 * is false. 181 * 182 * @deprecated This method is now obsolete. 183 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 184 */ 185 @Deprecated setNavDump(boolean enabled)186 public void setNavDump(boolean enabled) { 187 throw new MustOverrideException(); 188 } 189 190 /** 191 * Gets whether dumping the navigation cache is enabled. 192 * 193 * @return whether dumping the navigation cache is enabled 194 * @see #setNavDump 195 * @deprecated This method is now obsolete. 196 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 197 */ 198 @Deprecated getNavDump()199 public boolean getNavDump() { 200 throw new MustOverrideException(); 201 } 202 203 /** 204 * Sets whether the WebView should support zooming using its on-screen zoom 205 * controls and gestures. The particular zoom mechanisms that should be used 206 * can be set with {@link #setBuiltInZoomControls}. This setting does not 207 * affect zooming performed using the {@link WebView#zoomIn()} and 208 * {@link WebView#zoomOut()} methods. The default is true. 209 * 210 * @param support whether the WebView should support zoom 211 */ setSupportZoom(boolean support)212 public void setSupportZoom(boolean support) { 213 throw new MustOverrideException(); 214 } 215 216 /** 217 * Gets whether the WebView supports zoom. 218 * 219 * @return true if the WebView supports zoom 220 * @see #setSupportZoom 221 */ supportZoom()222 public boolean supportZoom() { 223 throw new MustOverrideException(); 224 } 225 226 /** 227 * Sets whether the WebView requires a user gesture to play media. 228 * The default is true. 229 * 230 * @param require whether the WebView requires a user gesture to play media 231 */ setMediaPlaybackRequiresUserGesture(boolean require)232 public void setMediaPlaybackRequiresUserGesture(boolean require) { 233 throw new MustOverrideException(); 234 } 235 236 /** 237 * Gets whether the WebView requires a user gesture to play media. 238 * 239 * @return true if the WebView requires a user gesture to play media 240 * @see #setMediaPlaybackRequiresUserGesture 241 */ getMediaPlaybackRequiresUserGesture()242 public boolean getMediaPlaybackRequiresUserGesture() { 243 throw new MustOverrideException(); 244 } 245 246 /** 247 * Sets whether the WebView should use its built-in zoom mechanisms. The 248 * built-in zoom mechanisms comprise on-screen zoom controls, which are 249 * displayed over the WebView's content, and the use of a pinch gesture to 250 * control zooming. Whether or not these on-screen controls are displayed 251 * can be set with {@link #setDisplayZoomControls}. The default is false. 252 * <p> 253 * The built-in mechanisms are the only currently supported zoom 254 * mechanisms, so it is recommended that this setting is always enabled. 255 * 256 * @param enabled whether the WebView should use its built-in zoom mechanisms 257 */ 258 // This method was intended to select between the built-in zoom mechanisms 259 // and the separate zoom controls. The latter were obtained using 260 // {@link WebView#getZoomControls}, which is now hidden. setBuiltInZoomControls(boolean enabled)261 public void setBuiltInZoomControls(boolean enabled) { 262 throw new MustOverrideException(); 263 } 264 265 /** 266 * Gets whether the zoom mechanisms built into WebView are being used. 267 * 268 * @return true if the zoom mechanisms built into WebView are being used 269 * @see #setBuiltInZoomControls 270 */ getBuiltInZoomControls()271 public boolean getBuiltInZoomControls() { 272 throw new MustOverrideException(); 273 } 274 275 /** 276 * Sets whether the WebView should display on-screen zoom controls when 277 * using the built-in zoom mechanisms. See {@link #setBuiltInZoomControls}. 278 * The default is true. 279 * 280 * @param enabled whether the WebView should display on-screen zoom controls 281 */ setDisplayZoomControls(boolean enabled)282 public void setDisplayZoomControls(boolean enabled) { 283 throw new MustOverrideException(); 284 } 285 286 /** 287 * Gets whether the WebView displays on-screen zoom controls when using 288 * the built-in zoom mechanisms. 289 * 290 * @return true if the WebView displays on-screen zoom controls when using 291 * the built-in zoom mechanisms 292 * @see #setDisplayZoomControls 293 */ getDisplayZoomControls()294 public boolean getDisplayZoomControls() { 295 throw new MustOverrideException(); 296 } 297 298 /** 299 * Enables or disables file access within WebView. File access is enabled by 300 * default. Note that this enables or disables file system access only. 301 * Assets and resources are still accessible using file:///android_asset and 302 * file:///android_res. 303 */ setAllowFileAccess(boolean allow)304 public void setAllowFileAccess(boolean allow) { 305 throw new MustOverrideException(); 306 } 307 308 /** 309 * Gets whether this WebView supports file access. 310 * 311 * @see #setAllowFileAccess 312 */ getAllowFileAccess()313 public boolean getAllowFileAccess() { 314 throw new MustOverrideException(); 315 } 316 317 /** 318 * Enables or disables content URL access within WebView. Content URL 319 * access allows WebView to load content from a content provider installed 320 * in the system. The default is enabled. 321 */ setAllowContentAccess(boolean allow)322 public void setAllowContentAccess(boolean allow) { 323 throw new MustOverrideException(); 324 } 325 326 /** 327 * Gets whether this WebView supports content URL access. 328 * 329 * @see #setAllowContentAccess 330 */ getAllowContentAccess()331 public boolean getAllowContentAccess() { 332 throw new MustOverrideException(); 333 } 334 335 /** 336 * Sets whether the WebView loads pages in overview mode. The default is 337 * false. 338 */ setLoadWithOverviewMode(boolean overview)339 public void setLoadWithOverviewMode(boolean overview) { 340 throw new MustOverrideException(); 341 } 342 343 /** 344 * Gets whether this WebView loads pages in overview mode. 345 * 346 * @return whether this WebView loads pages in overview mode 347 * @see #setLoadWithOverviewMode 348 */ getLoadWithOverviewMode()349 public boolean getLoadWithOverviewMode() { 350 throw new MustOverrideException(); 351 } 352 353 /** 354 * Sets whether the WebView will enable smooth transition while panning or 355 * zooming or while the window hosting the WebView does not have focus. 356 * If it is true, WebView will choose a solution to maximize the performance. 357 * e.g. the WebView's content may not be updated during the transition. 358 * If it is false, WebView will keep its fidelity. The default value is false. 359 * 360 * @deprecated This method is now obsolete, and will become a no-op in future. 361 */ 362 @Deprecated setEnableSmoothTransition(boolean enable)363 public void setEnableSmoothTransition(boolean enable) { 364 throw new MustOverrideException(); 365 } 366 367 /** 368 * Gets whether the WebView enables smooth transition while panning or 369 * zooming. 370 * 371 * @see #setEnableSmoothTransition 372 * 373 * @deprecated This method is now obsolete, and will become a no-op in future. 374 */ 375 @Deprecated enableSmoothTransition()376 public boolean enableSmoothTransition() { 377 throw new MustOverrideException(); 378 } 379 380 /** 381 * Sets whether the WebView uses its background for over scroll background. 382 * If true, it will use the WebView's background. If false, it will use an 383 * internal pattern. Default is true. 384 * 385 * @deprecated This method is now obsolete. 386 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 387 */ 388 @Deprecated setUseWebViewBackgroundForOverscrollBackground(boolean view)389 public void setUseWebViewBackgroundForOverscrollBackground(boolean view) { 390 throw new MustOverrideException(); 391 } 392 393 /** 394 * Gets whether this WebView uses WebView's background instead of 395 * internal pattern for over scroll background. 396 * 397 * @see #setUseWebViewBackgroundForOverscrollBackground 398 * @deprecated This method is now obsolete. 399 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 400 */ 401 @Deprecated getUseWebViewBackgroundForOverscrollBackground()402 public boolean getUseWebViewBackgroundForOverscrollBackground() { 403 throw new MustOverrideException(); 404 } 405 406 /** 407 * Sets whether the WebView should save form data. The default is true. 408 */ setSaveFormData(boolean save)409 public void setSaveFormData(boolean save) { 410 throw new MustOverrideException(); 411 } 412 413 /** 414 * Gets whether the WebView saves form data. 415 * 416 * @return whether the WebView saves form data 417 * @see #setSaveFormData 418 */ getSaveFormData()419 public boolean getSaveFormData() { 420 throw new MustOverrideException(); 421 } 422 423 /** 424 * Sets whether the WebView should save passwords. The default is true. 425 * @deprecated Saving passwords in WebView will not be supported in future versions. 426 */ 427 @Deprecated setSavePassword(boolean save)428 public void setSavePassword(boolean save) { 429 throw new MustOverrideException(); 430 } 431 432 /** 433 * Gets whether the WebView saves passwords. 434 * 435 * @return whether the WebView saves passwords 436 * @see #setSavePassword 437 * @deprecated Saving passwords in WebView will not be supported in future versions. 438 */ 439 @Deprecated getSavePassword()440 public boolean getSavePassword() { 441 throw new MustOverrideException(); 442 } 443 444 /** 445 * Sets the text zoom of the page in percent. The default is 100. 446 * 447 * @param textZoom the text zoom in percent 448 */ setTextZoom(int textZoom)449 public synchronized void setTextZoom(int textZoom) { 450 throw new MustOverrideException(); 451 } 452 453 /** 454 * Gets the text zoom of the page in percent. 455 * 456 * @return the text zoom of the page in percent 457 * @see #setTextZoom 458 */ getTextZoom()459 public synchronized int getTextZoom() { 460 throw new MustOverrideException(); 461 } 462 463 /** 464 * Sets the text size of the page. The default is {@link TextSize#NORMAL}. 465 * 466 * @param t the text size as a {@link TextSize} value 467 * @deprecated Use {@link #setTextZoom} instead. 468 */ setTextSize(TextSize t)469 public synchronized void setTextSize(TextSize t) { 470 setTextZoom(t.value); 471 } 472 473 /** 474 * Gets the text size of the page. If the text size was previously specified 475 * in percent using {@link #setTextZoom}, this will return the closest 476 * matching {@link TextSize}. 477 * 478 * @return the text size as a {@link TextSize} value 479 * @see #setTextSize 480 * @deprecated Use {@link #getTextZoom} instead. 481 */ getTextSize()482 public synchronized TextSize getTextSize() { 483 TextSize closestSize = null; 484 int smallestDelta = Integer.MAX_VALUE; 485 int textSize = getTextZoom(); 486 for (TextSize size : TextSize.values()) { 487 int delta = Math.abs(textSize - size.value); 488 if (delta == 0) { 489 return size; 490 } 491 if (delta < smallestDelta) { 492 smallestDelta = delta; 493 closestSize = size; 494 } 495 } 496 return closestSize != null ? closestSize : TextSize.NORMAL; 497 } 498 499 /** 500 * Sets the default zoom density of the page. This must be called from the UI 501 * thread. The default is {@link ZoomDensity#MEDIUM}. 502 * 503 * @param zoom the zoom density 504 */ setDefaultZoom(ZoomDensity zoom)505 public void setDefaultZoom(ZoomDensity zoom) { 506 throw new MustOverrideException(); 507 } 508 509 /** 510 * Gets the default zoom density of the page. This should be called from 511 * the UI thread. 512 * 513 * @return the zoom density 514 * @see #setDefaultZoom 515 */ getDefaultZoom()516 public ZoomDensity getDefaultZoom() { 517 throw new MustOverrideException(); 518 } 519 520 /** 521 * Enables using light touches to make a selection and activate mouseovers. 522 * @deprecated From {@link android.os.Build.VERSION_CODES#JELLY_BEAN} this 523 * setting is obsolete and has no effect. 524 */ 525 @Deprecated setLightTouchEnabled(boolean enabled)526 public void setLightTouchEnabled(boolean enabled) { 527 throw new MustOverrideException(); 528 } 529 530 /** 531 * Gets whether light touches are enabled. 532 * @see #setLightTouchEnabled 533 * @deprecated This setting is obsolete. 534 */ 535 @Deprecated getLightTouchEnabled()536 public boolean getLightTouchEnabled() { 537 throw new MustOverrideException(); 538 } 539 540 /** 541 * Controlled a rendering optimization that is no longer present. Setting 542 * it now has no effect. 543 * 544 * @deprecated This setting now has no effect. 545 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 546 */ 547 @Deprecated setUseDoubleTree(boolean use)548 public synchronized void setUseDoubleTree(boolean use) { 549 // Specified to do nothing, so no need for derived classes to override. 550 } 551 552 /** 553 * Controlled a rendering optimization that is no longer present. Setting 554 * it now has no effect. 555 * 556 * @deprecated This setting now has no effect. 557 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 558 */ 559 @Deprecated getUseDoubleTree()560 public synchronized boolean getUseDoubleTree() { 561 // Returns false unconditionally, so no need for derived classes to override. 562 return false; 563 } 564 565 /** 566 * Sets the user-agent string using an integer code. 567 * <ul> 568 * <li>0 means the WebView should use an Android user-agent string</li> 569 * <li>1 means the WebView should use a desktop user-agent string</li> 570 * </ul> 571 * Other values are ignored. The default is an Android user-agent string, 572 * i.e. code value 0. 573 * 574 * @param ua the integer code for the user-agent string 575 * @deprecated Please use {@link #setUserAgentString} instead. 576 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 577 */ 578 @Deprecated setUserAgent(int ua)579 public synchronized void setUserAgent(int ua) { 580 throw new MustOverrideException(); 581 } 582 583 /** 584 * Gets the user-agent as an integer code. 585 * <ul> 586 * <li>-1 means the WebView is using a custom user-agent string set with 587 * {@link #setUserAgentString}</li> 588 * <li>0 means the WebView should use an Android user-agent string</li> 589 * <li>1 means the WebView should use a desktop user-agent string</li> 590 * </ul> 591 * 592 * @return the integer code for the user-agent string 593 * @see #setUserAgent 594 * @deprecated Please use {@link #getUserAgentString} instead. 595 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 596 */ 597 @Deprecated getUserAgent()598 public synchronized int getUserAgent() { 599 throw new MustOverrideException(); 600 } 601 602 /** 603 * Sets whether the WebView should enable support for the "viewport" 604 * HTML meta tag or should use a wide viewport. 605 * When the value of the setting is false, the layout width is always set to the 606 * width of the WebView control in device-independent (CSS) pixels. 607 * When the value is true and the page contains the viewport meta tag, the value 608 * of the width specified in the tag is used. If the page does not contain the tag or 609 * does not provide a width, then a wide viewport will be used. 610 * 611 * @param use whether to enable support for the viewport meta tag 612 */ setUseWideViewPort(boolean use)613 public synchronized void setUseWideViewPort(boolean use) { 614 throw new MustOverrideException(); 615 } 616 617 /** 618 * Gets whether the WebView supports the "viewport" 619 * HTML meta tag or will use a wide viewport. 620 * 621 * @return true if the WebView supports the viewport meta tag 622 * @see #setUseWideViewPort 623 */ getUseWideViewPort()624 public synchronized boolean getUseWideViewPort() { 625 throw new MustOverrideException(); 626 } 627 628 /** 629 * Sets whether the WebView whether supports multiple windows. If set to 630 * true, {@link WebChromeClient#onCreateWindow} must be implemented by the 631 * host application. The default is false. 632 * 633 * @param support whether to suport multiple windows 634 */ setSupportMultipleWindows(boolean support)635 public synchronized void setSupportMultipleWindows(boolean support) { 636 throw new MustOverrideException(); 637 } 638 639 /** 640 * Gets whether the WebView supports multiple windows. 641 * 642 * @return true if the WebView supports multiple windows 643 * @see #setSupportMultipleWindows 644 */ supportMultipleWindows()645 public synchronized boolean supportMultipleWindows() { 646 throw new MustOverrideException(); 647 } 648 649 /** 650 * Sets the underlying layout algorithm. This will cause a relayout of the 651 * WebView. The default is {@link LayoutAlgorithm#NARROW_COLUMNS}. 652 * 653 * @param l the layout algorithm to use, as a {@link LayoutAlgorithm} value 654 */ setLayoutAlgorithm(LayoutAlgorithm l)655 public synchronized void setLayoutAlgorithm(LayoutAlgorithm l) { 656 throw new MustOverrideException(); 657 } 658 659 /** 660 * Gets the current layout algorithm. 661 * 662 * @return the layout algorithm in use, as a {@link LayoutAlgorithm} value 663 * @see #setLayoutAlgorithm 664 */ getLayoutAlgorithm()665 public synchronized LayoutAlgorithm getLayoutAlgorithm() { 666 throw new MustOverrideException(); 667 } 668 669 /** 670 * Sets the standard font family name. The default is "sans-serif". 671 * 672 * @param font a font family name 673 */ setStandardFontFamily(String font)674 public synchronized void setStandardFontFamily(String font) { 675 throw new MustOverrideException(); 676 } 677 678 /** 679 * Gets the standard font family name. 680 * 681 * @return the standard font family name as a string 682 * @see #setStandardFontFamily 683 */ getStandardFontFamily()684 public synchronized String getStandardFontFamily() { 685 throw new MustOverrideException(); 686 } 687 688 /** 689 * Sets the fixed font family name. The default is "monospace". 690 * 691 * @param font a font family name 692 */ setFixedFontFamily(String font)693 public synchronized void setFixedFontFamily(String font) { 694 throw new MustOverrideException(); 695 } 696 697 /** 698 * Gets the fixed font family name. 699 * 700 * @return the fixed font family name as a string 701 * @see #setFixedFontFamily 702 */ getFixedFontFamily()703 public synchronized String getFixedFontFamily() { 704 throw new MustOverrideException(); 705 } 706 707 /** 708 * Sets the sans-serif font family name. The default is "sans-serif". 709 * 710 * @param font a font family name 711 */ setSansSerifFontFamily(String font)712 public synchronized void setSansSerifFontFamily(String font) { 713 throw new MustOverrideException(); 714 } 715 716 /** 717 * Gets the sans-serif font family name. 718 * 719 * @return the sans-serif font family name as a string 720 * @see #setSansSerifFontFamily 721 */ getSansSerifFontFamily()722 public synchronized String getSansSerifFontFamily() { 723 throw new MustOverrideException(); 724 } 725 726 /** 727 * Sets the serif font family name. The default is "sans-serif". 728 * 729 * @param font a font family name 730 */ setSerifFontFamily(String font)731 public synchronized void setSerifFontFamily(String font) { 732 throw new MustOverrideException(); 733 } 734 735 /** 736 * Gets the serif font family name. The default is "serif". 737 * 738 * @return the serif font family name as a string 739 * @see #setSerifFontFamily 740 */ getSerifFontFamily()741 public synchronized String getSerifFontFamily() { 742 throw new MustOverrideException(); 743 } 744 745 /** 746 * Sets the cursive font family name. The default is "cursive". 747 * 748 * @param font a font family name 749 */ setCursiveFontFamily(String font)750 public synchronized void setCursiveFontFamily(String font) { 751 throw new MustOverrideException(); 752 } 753 754 /** 755 * Gets the cursive font family name. 756 * 757 * @return the cursive font family name as a string 758 * @see #setCursiveFontFamily 759 */ getCursiveFontFamily()760 public synchronized String getCursiveFontFamily() { 761 throw new MustOverrideException(); 762 } 763 764 /** 765 * Sets the fantasy font family name. The default is "fantasy". 766 * 767 * @param font a font family name 768 */ setFantasyFontFamily(String font)769 public synchronized void setFantasyFontFamily(String font) { 770 throw new MustOverrideException(); 771 } 772 773 /** 774 * Gets the fantasy font family name. 775 * 776 * @return the fantasy font family name as a string 777 * @see #setFantasyFontFamily 778 */ getFantasyFontFamily()779 public synchronized String getFantasyFontFamily() { 780 throw new MustOverrideException(); 781 } 782 783 /** 784 * Sets the minimum font size. The default is 8. 785 * 786 * @param size a non-negative integer between 1 and 72. Any number outside 787 * the specified range will be pinned. 788 */ setMinimumFontSize(int size)789 public synchronized void setMinimumFontSize(int size) { 790 throw new MustOverrideException(); 791 } 792 793 /** 794 * Gets the minimum font size. 795 * 796 * @return a non-negative integer between 1 and 72 797 * @see #setMinimumFontSize 798 */ getMinimumFontSize()799 public synchronized int getMinimumFontSize() { 800 throw new MustOverrideException(); 801 } 802 803 /** 804 * Sets the minimum logical font size. The default is 8. 805 * 806 * @param size a non-negative integer between 1 and 72. Any number outside 807 * the specified range will be pinned. 808 */ setMinimumLogicalFontSize(int size)809 public synchronized void setMinimumLogicalFontSize(int size) { 810 throw new MustOverrideException(); 811 } 812 813 /** 814 * Gets the minimum logical font size. 815 * 816 * @return a non-negative integer between 1 and 72 817 * @see #setMinimumLogicalFontSize 818 */ getMinimumLogicalFontSize()819 public synchronized int getMinimumLogicalFontSize() { 820 throw new MustOverrideException(); 821 } 822 823 /** 824 * Sets the default font size. The default is 16. 825 * 826 * @param size a non-negative integer between 1 and 72. Any number outside 827 * the specified range will be pinned. 828 */ setDefaultFontSize(int size)829 public synchronized void setDefaultFontSize(int size) { 830 throw new MustOverrideException(); 831 } 832 833 /** 834 * Gets the default font size. 835 * 836 * @return a non-negative integer between 1 and 72 837 * @see #setDefaultFontSize 838 */ getDefaultFontSize()839 public synchronized int getDefaultFontSize() { 840 throw new MustOverrideException(); 841 } 842 843 /** 844 * Sets the default fixed font size. The default is 16. 845 * 846 * @param size a non-negative integer between 1 and 72. Any number outside 847 * the specified range will be pinned. 848 */ setDefaultFixedFontSize(int size)849 public synchronized void setDefaultFixedFontSize(int size) { 850 throw new MustOverrideException(); 851 } 852 853 /** 854 * Gets the default fixed font size. 855 * 856 * @return a non-negative integer between 1 and 72 857 * @see #setDefaultFixedFontSize 858 */ getDefaultFixedFontSize()859 public synchronized int getDefaultFixedFontSize() { 860 throw new MustOverrideException(); 861 } 862 863 /** 864 * Sets whether the WebView should load image resources. Note that this method 865 * controls loading of all images, including those embedded using the data 866 * URI scheme. Use {@link #setBlockNetworkImage} to control loading only 867 * of images specified using network URI schemes. Note that if the value of this 868 * setting is changed from false to true, all images resources referenced 869 * by content currently displayed by the WebView are loaded automatically. 870 * The default is true. 871 * 872 * @param flag whether the WebView should load image resources 873 */ setLoadsImagesAutomatically(boolean flag)874 public synchronized void setLoadsImagesAutomatically(boolean flag) { 875 throw new MustOverrideException(); 876 } 877 878 /** 879 * Gets whether the WebView loads image resources. This includes 880 * images embedded using the data URI scheme. 881 * 882 * @return true if the WebView loads image resources 883 * @see #setLoadsImagesAutomatically 884 */ getLoadsImagesAutomatically()885 public synchronized boolean getLoadsImagesAutomatically() { 886 throw new MustOverrideException(); 887 } 888 889 /** 890 * Sets whether the WebView should not load image resources from the 891 * network (resources accessed via http and https URI schemes). Note 892 * that this method has no effect unless 893 * {@link #getLoadsImagesAutomatically} returns true. Also note that 894 * disabling all network loads using {@link #setBlockNetworkLoads} 895 * will also prevent network images from loading, even if this flag is set 896 * to false. When the value of this setting is changed from true to false, 897 * network images resources referenced by content currently displayed by 898 * the WebView are fetched automatically. The default is false. 899 * 900 * @param flag whether the WebView should not load image resources from the 901 * network 902 * @see #setBlockNetworkLoads 903 */ setBlockNetworkImage(boolean flag)904 public synchronized void setBlockNetworkImage(boolean flag) { 905 throw new MustOverrideException(); 906 } 907 908 /** 909 * Gets whether the WebView does not load image resources from the network. 910 * 911 * @return true if the WebView does not load image resources from the network 912 * @see #setBlockNetworkImage 913 */ getBlockNetworkImage()914 public synchronized boolean getBlockNetworkImage() { 915 throw new MustOverrideException(); 916 } 917 918 /** 919 * Sets whether the WebView should not load resources from the network. 920 * Use {@link #setBlockNetworkImage} to only avoid loading 921 * image resources. Note that if the value of this setting is 922 * changed from true to false, network resources referenced by content 923 * currently displayed by the WebView are not fetched until 924 * {@link android.webkit.WebView#reload} is called. 925 * If the application does not have the 926 * {@link android.Manifest.permission#INTERNET} permission, attempts to set 927 * a value of false will cause a {@link java.lang.SecurityException} 928 * to be thrown. The default value is false if the application has the 929 * {@link android.Manifest.permission#INTERNET} permission, otherwise it is 930 * true. 931 * 932 * @param flag whether the WebView should not load any resources from the 933 * network 934 * @see android.webkit.WebView#reload 935 */ setBlockNetworkLoads(boolean flag)936 public synchronized void setBlockNetworkLoads(boolean flag) { 937 throw new MustOverrideException(); 938 } 939 940 /** 941 * Gets whether the WebView does not load any resources from the network. 942 * 943 * @return true if the WebView does not load any resources from the network 944 * @see #setBlockNetworkLoads 945 */ getBlockNetworkLoads()946 public synchronized boolean getBlockNetworkLoads() { 947 throw new MustOverrideException(); 948 } 949 950 /** 951 * Tells the WebView to enable JavaScript execution. 952 * <b>The default is false.</b> 953 * 954 * @param flag true if the WebView should execute JavaScript 955 */ setJavaScriptEnabled(boolean flag)956 public synchronized void setJavaScriptEnabled(boolean flag) { 957 throw new MustOverrideException(); 958 } 959 960 /** 961 * Sets whether JavaScript running in the context of a file scheme URL 962 * should be allowed to access content from any origin. This includes 963 * access to content from other file scheme URLs. See 964 * {@link #setAllowFileAccessFromFileURLs}. To enable the most restrictive, 965 * and therefore secure policy, this setting should be disabled. 966 * Note that this setting affects only JavaScript access to file scheme 967 * resources. Other access to such resources, for example, from image HTML 968 * elements, is unaffected. 969 * <p> 970 * The default value is true for API level 971 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, 972 * and false for API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} 973 * and above. 974 * 975 * @param flag whether JavaScript running in the context of a file scheme 976 * URL should be allowed to access content from any origin 977 */ setAllowUniversalAccessFromFileURLs(boolean flag)978 public abstract void setAllowUniversalAccessFromFileURLs(boolean flag); 979 980 /** 981 * Sets whether JavaScript running in the context of a file scheme URL 982 * should be allowed to access content from other file scheme URLs. To 983 * enable the most restrictive, and therefore secure policy, this setting 984 * should be disabled. Note that the value of this setting is ignored if 985 * the value of {@link #getAllowUniversalAccessFromFileURLs} is true. 986 * Note too, that this setting affects only JavaScript access to file scheme 987 * resources. Other access to such resources, for example, from image HTML 988 * elements, is unaffected. 989 * <p> 990 * The default value is true for API level 991 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, 992 * and false for API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} 993 * and above. 994 * 995 * @param flag whether JavaScript running in the context of a file scheme 996 * URL should be allowed to access content from other file 997 * scheme URLs 998 */ setAllowFileAccessFromFileURLs(boolean flag)999 public abstract void setAllowFileAccessFromFileURLs(boolean flag); 1000 1001 /** 1002 * Sets whether the WebView should enable plugins. The default is false. 1003 * 1004 * @param flag true if plugins should be enabled 1005 * @deprecated This method has been deprecated in favor of 1006 * {@link #setPluginState} 1007 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} 1008 */ 1009 @Deprecated setPluginsEnabled(boolean flag)1010 public synchronized void setPluginsEnabled(boolean flag) { 1011 throw new MustOverrideException(); 1012 } 1013 1014 /** 1015 * Tells the WebView to enable, disable, or have plugins on demand. On 1016 * demand mode means that if a plugin exists that can handle the embedded 1017 * content, a placeholder icon will be shown instead of the plugin. When 1018 * the placeholder is clicked, the plugin will be enabled. The default is 1019 * {@link PluginState#OFF}. 1020 * 1021 * @param state a PluginState value 1022 * @deprecated Plugins will not be supported in future, and should not be used. 1023 */ 1024 @Deprecated setPluginState(PluginState state)1025 public synchronized void setPluginState(PluginState state) { 1026 throw new MustOverrideException(); 1027 } 1028 1029 /** 1030 * Sets a custom path to plugins used by the WebView. This method is 1031 * obsolete since each plugin is now loaded from its own package. 1032 * 1033 * @param pluginsPath a String path to the directory containing plugins 1034 * @deprecated This method is no longer used as plugins are loaded from 1035 * their own APK via the system's package manager. 1036 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} 1037 */ 1038 @Deprecated setPluginsPath(String pluginsPath)1039 public synchronized void setPluginsPath(String pluginsPath) { 1040 // Specified to do nothing, so no need for derived classes to override. 1041 } 1042 1043 /** 1044 * Sets the path to where database storage API databases should be saved. 1045 * In order for the database storage API to function correctly, this method 1046 * must be called with a path to which the application can write. This 1047 * method should only be called once: repeated calls are ignored. 1048 * 1049 * @param databasePath a path to the directory where databases should be 1050 * saved. 1051 */ 1052 // This will update WebCore when the Sync runs in the C++ side. 1053 // Note that the WebCore Database Tracker only allows the path to be set 1054 // once. setDatabasePath(String databasePath)1055 public synchronized void setDatabasePath(String databasePath) { 1056 throw new MustOverrideException(); 1057 } 1058 1059 /** 1060 * Sets the path where the Geolocation databases should be saved. In order 1061 * for Geolocation permissions and cached positions to be persisted, this 1062 * method must be called with a path to which the application can write. 1063 * 1064 * @param databasePath a path to the directory where databases should be 1065 * saved. 1066 */ 1067 // This will update WebCore when the Sync runs in the C++ side. setGeolocationDatabasePath(String databasePath)1068 public synchronized void setGeolocationDatabasePath(String databasePath) { 1069 throw new MustOverrideException(); 1070 } 1071 1072 /** 1073 * Sets whether the Application Caches API should be enabled. The default 1074 * is false. Note that in order for the Application Caches API to be 1075 * enabled, a valid database path must also be supplied to 1076 * {@link #setAppCachePath}. 1077 * 1078 * @param flag true if the WebView should enable Application Caches 1079 */ setAppCacheEnabled(boolean flag)1080 public synchronized void setAppCacheEnabled(boolean flag) { 1081 throw new MustOverrideException(); 1082 } 1083 1084 /** 1085 * Sets the path to the Application Caches files. In order for the 1086 * Application Caches API to be enabled, this method must be called with a 1087 * path to which the application can write. This method should only be 1088 * called once: repeated calls are ignored. 1089 * 1090 * @param appCachePath a String path to the directory containing 1091 * Application Caches files. 1092 * @see #setAppCacheEnabled 1093 */ setAppCachePath(String appCachePath)1094 public synchronized void setAppCachePath(String appCachePath) { 1095 throw new MustOverrideException(); 1096 } 1097 1098 /** 1099 * Sets the maximum size for the Application Cache content. The passed size 1100 * will be rounded to the nearest value that the database can support, so 1101 * this should be viewed as a guide, not a hard limit. Setting the 1102 * size to a value less than current database size does not cause the 1103 * database to be trimmed. The default size is {@link Long#MAX_VALUE}. 1104 * It is recommended to leave the maximum size set to the default value. 1105 * 1106 * @param appCacheMaxSize the maximum size in bytes 1107 * @deprecated In future quota will be managed automatically. 1108 */ 1109 @Deprecated setAppCacheMaxSize(long appCacheMaxSize)1110 public synchronized void setAppCacheMaxSize(long appCacheMaxSize) { 1111 throw new MustOverrideException(); 1112 } 1113 1114 /** 1115 * Sets whether the database storage API is enabled. The default value is 1116 * false. See also {@link #setDatabasePath} for how to correctly set up the 1117 * database storage API. 1118 * 1119 * This setting is global in effect, across all WebView instances in a process. 1120 * Note you should only modify this setting prior to making <b>any</b> WebView 1121 * page load within a given process, as the WebView implementation may ignore 1122 * changes to this setting after that point. 1123 * 1124 * @param flag true if the WebView should use the database storage API 1125 */ setDatabaseEnabled(boolean flag)1126 public synchronized void setDatabaseEnabled(boolean flag) { 1127 throw new MustOverrideException(); 1128 } 1129 1130 /** 1131 * Sets whether the DOM storage API is enabled. The default value is false. 1132 * 1133 * @param flag true if the WebView should use the DOM storage API 1134 */ setDomStorageEnabled(boolean flag)1135 public synchronized void setDomStorageEnabled(boolean flag) { 1136 throw new MustOverrideException(); 1137 } 1138 1139 /** 1140 * Gets whether the DOM Storage APIs are enabled. 1141 * 1142 * @return true if the DOM Storage APIs are enabled 1143 * @see #setDomStorageEnabled 1144 */ getDomStorageEnabled()1145 public synchronized boolean getDomStorageEnabled() { 1146 throw new MustOverrideException(); 1147 } 1148 /** 1149 * Gets the path to where database storage API databases are saved. 1150 * 1151 * @return the String path to the database storage API databases 1152 * @see #setDatabasePath 1153 */ getDatabasePath()1154 public synchronized String getDatabasePath() { 1155 throw new MustOverrideException(); 1156 } 1157 1158 /** 1159 * Gets whether the database storage API is enabled. 1160 * 1161 * @return true if the database storage API is enabled 1162 * @see #setDatabaseEnabled 1163 */ getDatabaseEnabled()1164 public synchronized boolean getDatabaseEnabled() { 1165 throw new MustOverrideException(); 1166 } 1167 1168 /** 1169 * Sets whether Geolocation is enabled. The default is true. 1170 * <p> 1171 * Please note that in order for the Geolocation API to be usable 1172 * by a page in the WebView, the following requirements must be met: 1173 * <ul> 1174 * <li>an application must have permission to access the device location, 1175 * see {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}, 1176 * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}; 1177 * <li>an application must provide an implementation of the 1178 * {@link WebChromeClient#onGeolocationPermissionsShowPrompt} callback 1179 * to receive notifications that a page is requesting access to location 1180 * via the JavaScript Geolocation API. 1181 * </ul> 1182 * <p> 1183 * As an option, it is possible to store previous locations and web origin 1184 * permissions in a database. See {@link #setGeolocationDatabasePath}. 1185 * 1186 * @param flag whether Geolocation should be enabled 1187 */ setGeolocationEnabled(boolean flag)1188 public synchronized void setGeolocationEnabled(boolean flag) { 1189 throw new MustOverrideException(); 1190 } 1191 1192 /** 1193 * Gets whether JavaScript is enabled. 1194 * 1195 * @return true if JavaScript is enabled 1196 * @see #setJavaScriptEnabled 1197 */ getJavaScriptEnabled()1198 public synchronized boolean getJavaScriptEnabled() { 1199 throw new MustOverrideException(); 1200 } 1201 1202 /** 1203 * Gets whether JavaScript running in the context of a file scheme URL can 1204 * access content from any origin. This includes access to content from 1205 * other file scheme URLs. 1206 * 1207 * @return whether JavaScript running in the context of a file scheme URL 1208 * can access content from any origin 1209 * @see #setAllowUniversalAccessFromFileURLs 1210 */ getAllowUniversalAccessFromFileURLs()1211 public abstract boolean getAllowUniversalAccessFromFileURLs(); 1212 1213 /** 1214 * Gets whether JavaScript running in the context of a file scheme URL can 1215 * access content from other file scheme URLs. 1216 * 1217 * @return whether JavaScript running in the context of a file scheme URL 1218 * can access content from other file scheme URLs 1219 * @see #setAllowFileAccessFromFileURLs 1220 */ getAllowFileAccessFromFileURLs()1221 public abstract boolean getAllowFileAccessFromFileURLs(); 1222 1223 /** 1224 * Gets whether plugins are enabled. 1225 * 1226 * @return true if plugins are enabled 1227 * @see #setPluginsEnabled 1228 * @deprecated This method has been replaced by {@link #getPluginState} 1229 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} 1230 */ 1231 @Deprecated getPluginsEnabled()1232 public synchronized boolean getPluginsEnabled() { 1233 throw new MustOverrideException(); 1234 } 1235 1236 /** 1237 * Gets the current state regarding whether plugins are enabled. 1238 * 1239 * @return the plugin state as a {@link PluginState} value 1240 * @see #setPluginState 1241 * @deprecated Plugins will not be supported in future, and should not be used. 1242 */ 1243 @Deprecated getPluginState()1244 public synchronized PluginState getPluginState() { 1245 throw new MustOverrideException(); 1246 } 1247 1248 /** 1249 * Gets the directory that contains the plugin libraries. This method is 1250 * obsolete since each plugin is now loaded from its own package. 1251 * 1252 * @return an empty string 1253 * @deprecated This method is no longer used as plugins are loaded from 1254 * their own APK via the system's package manager. 1255 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} 1256 */ 1257 @Deprecated getPluginsPath()1258 public synchronized String getPluginsPath() { 1259 // Unconditionally returns empty string, so no need for derived classes to override. 1260 return ""; 1261 } 1262 1263 /** 1264 * Tells JavaScript to open windows automatically. This applies to the 1265 * JavaScript function window.open(). The default is false. 1266 * 1267 * @param flag true if JavaScript can open windows automatically 1268 */ setJavaScriptCanOpenWindowsAutomatically(boolean flag)1269 public synchronized void setJavaScriptCanOpenWindowsAutomatically(boolean flag) { 1270 throw new MustOverrideException(); 1271 } 1272 1273 /** 1274 * Gets whether JavaScript can open windows automatically. 1275 * 1276 * @return true if JavaScript can open windows automatically during 1277 * window.open() 1278 * @see #setJavaScriptCanOpenWindowsAutomatically 1279 */ getJavaScriptCanOpenWindowsAutomatically()1280 public synchronized boolean getJavaScriptCanOpenWindowsAutomatically() { 1281 throw new MustOverrideException(); 1282 } 1283 /** 1284 * Sets the default text encoding name to use when decoding html pages. 1285 * The default is "Latin-1". 1286 * 1287 * @param encoding the text encoding name 1288 */ setDefaultTextEncodingName(String encoding)1289 public synchronized void setDefaultTextEncodingName(String encoding) { 1290 throw new MustOverrideException(); 1291 } 1292 1293 /** 1294 * Gets the default text encoding name. 1295 * 1296 * @return the default text encoding name as a string 1297 * @see #setDefaultTextEncodingName 1298 */ getDefaultTextEncodingName()1299 public synchronized String getDefaultTextEncodingName() { 1300 throw new MustOverrideException(); 1301 } 1302 1303 /** 1304 * Sets the WebView's user-agent string. If the string is null or empty, 1305 * the system default value will be used. 1306 */ setUserAgentString(String ua)1307 public synchronized void setUserAgentString(String ua) { 1308 throw new MustOverrideException(); 1309 } 1310 1311 /** 1312 * Gets the WebView's user-agent string. 1313 * 1314 * @return the WebView's user-agent string 1315 * @see #setUserAgentString 1316 */ getUserAgentString()1317 public synchronized String getUserAgentString() { 1318 throw new MustOverrideException(); 1319 } 1320 1321 /** 1322 * Returns the default User-Agent used by a WebView. 1323 * An instance of WebView could use a different User-Agent if a call 1324 * is made to {@link WebSettings#setUserAgentString(String)}. 1325 * 1326 * @param context a Context object used to access application assets 1327 */ getDefaultUserAgent(Context context)1328 public static String getDefaultUserAgent(Context context) { 1329 return WebViewFactory.getProvider().getStatics().getDefaultUserAgent(context); 1330 } 1331 1332 /** 1333 * Tells the WebView whether it needs to set a node to have focus when 1334 * {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The 1335 * default value is true. 1336 * 1337 * @param flag whether the WebView needs to set a node 1338 */ setNeedInitialFocus(boolean flag)1339 public void setNeedInitialFocus(boolean flag) { 1340 throw new MustOverrideException(); 1341 } 1342 1343 /** 1344 * Sets the priority of the Render thread. Unlike the other settings, this 1345 * one only needs to be called once per process. The default value is 1346 * {@link RenderPriority#NORMAL}. 1347 * 1348 * @param priority the priority 1349 * @deprecated It is not recommended to adjust thread priorities, and this will 1350 * not be supported in future versions. 1351 */ 1352 @Deprecated setRenderPriority(RenderPriority priority)1353 public synchronized void setRenderPriority(RenderPriority priority) { 1354 throw new MustOverrideException(); 1355 } 1356 1357 /** 1358 * Overrides the way the cache is used. The way the cache is used is based 1359 * on the navigation type. For a normal page load, the cache is checked 1360 * and content is re-validated as needed. When navigating back, content is 1361 * not revalidated, instead the content is just retrieved from the cache. 1362 * This method allows the client to override this behavior by specifying 1363 * one of {@link #LOAD_DEFAULT}, 1364 * {@link #LOAD_CACHE_ELSE_NETWORK}, {@link #LOAD_NO_CACHE} or 1365 * {@link #LOAD_CACHE_ONLY}. The default value is {@link #LOAD_DEFAULT}. 1366 * 1367 * @param mode the mode to use 1368 */ setCacheMode(int mode)1369 public void setCacheMode(int mode) { 1370 throw new MustOverrideException(); 1371 } 1372 1373 /** 1374 * Gets the current setting for overriding the cache mode. 1375 * 1376 * @return the current setting for overriding the cache mode 1377 * @see #setCacheMode 1378 */ getCacheMode()1379 public int getCacheMode() { 1380 throw new MustOverrideException(); 1381 } 1382 } 1383