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