WebView.java revision 030d8b0d1b6b0879d0ab4e9a218a784f4c110f75
1/* 2 * Copyright (C) 2006 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.annotation.Widget; 20import android.content.Context; 21import android.content.res.Configuration; 22import android.graphics.Bitmap; 23import android.graphics.Canvas; 24import android.graphics.Paint; 25import android.graphics.Picture; 26import android.graphics.Rect; 27import android.graphics.drawable.Drawable; 28import android.net.http.SslCertificate; 29import android.os.Build; 30import android.os.Bundle; 31import android.os.CancellationSignal; 32import android.os.Looper; 33import android.os.Message; 34import android.os.ParcelFileDescriptor; 35import android.os.StrictMode; 36import android.print.PrintAttributes; 37import android.util.AttributeSet; 38import android.util.Log; 39import android.view.KeyEvent; 40import android.view.MotionEvent; 41import android.view.View; 42import android.view.ViewDebug; 43import android.view.ViewGroup; 44import android.view.ViewTreeObserver; 45import android.view.accessibility.AccessibilityEvent; 46import android.view.accessibility.AccessibilityNodeInfo; 47import android.view.accessibility.AccessibilityNodeProvider; 48import android.view.inputmethod.EditorInfo; 49import android.view.inputmethod.InputConnection; 50import android.widget.AbsoluteLayout; 51 52import java.io.BufferedWriter; 53import java.io.File; 54import java.util.Map; 55 56/** 57 * <p>A View that displays web pages. This class is the basis upon which you 58 * can roll your own web browser or simply display some online content within your Activity. 59 * It uses the WebKit rendering engine to display 60 * web pages and includes methods to navigate forward and backward 61 * through a history, zoom in and out, perform text searches and more.</p> 62 * <p>To enable the built-in zoom, set 63 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)} 64 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}). 65 * <p>Note that, in order for your Activity to access the Internet and load web pages 66 * in a WebView, you must add the {@code INTERNET} permissions to your 67 * Android Manifest file:</p> 68 * <pre><uses-permission android:name="android.permission.INTERNET" /></pre> 69 * 70 * <p>This must be a child of the <a 71 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a> 72 * element.</p> 73 * 74 * <p>For more information, read 75 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p> 76 * 77 * <h3>Basic usage</h3> 78 * 79 * <p>By default, a WebView provides no browser-like widgets, does not 80 * enable JavaScript and web page errors are ignored. If your goal is only 81 * to display some HTML as a part of your UI, this is probably fine; 82 * the user won't need to interact with the web page beyond reading 83 * it, and the web page won't need to interact with the user. If you 84 * actually want a full-blown web browser, then you probably want to 85 * invoke the Browser application with a URL Intent rather than show it 86 * with a WebView. For example: 87 * <pre> 88 * Uri uri = Uri.parse("http://www.example.com"); 89 * Intent intent = new Intent(Intent.ACTION_VIEW, uri); 90 * startActivity(intent); 91 * </pre> 92 * <p>See {@link android.content.Intent} for more information.</p> 93 * 94 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout, 95 * or set the entire Activity window as a WebView during {@link 96 * android.app.Activity#onCreate(Bundle) onCreate()}:</p> 97 * <pre class="prettyprint"> 98 * WebView webview = new WebView(this); 99 * setContentView(webview); 100 * </pre> 101 * 102 * <p>Then load the desired web page:</p> 103 * <pre> 104 * // Simplest usage: note that an exception will NOT be thrown 105 * // if there is an error loading this page (see below). 106 * webview.loadUrl("http://slashdot.org/"); 107 * 108 * // OR, you can also load from an HTML string: 109 * String summary = "<html><body>You scored <b>192</b> points.</body></html>"; 110 * webview.loadData(summary, "text/html", null); 111 * // ... although note that there are restrictions on what this HTML can do. 112 * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link 113 * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info. 114 * </pre> 115 * 116 * <p>A WebView has several customization points where you can add your 117 * own behavior. These are:</p> 118 * 119 * <ul> 120 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass. 121 * This class is called when something that might impact a 122 * browser UI happens, for instance, progress updates and 123 * JavaScript alerts are sent here (see <a 124 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>). 125 * </li> 126 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass. 127 * It will be called when things happen that impact the 128 * rendering of the content, eg, errors or form submissions. You 129 * can also intercept URL loading here (via {@link 130 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String) 131 * shouldOverrideUrlLoading()}).</li> 132 * <li>Modifying the {@link android.webkit.WebSettings}, such as 133 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean) 134 * setJavaScriptEnabled()}. </li> 135 * <li>Injecting Java objects into the WebView using the 136 * {@link android.webkit.WebView#addJavascriptInterface} method. This 137 * method allows you to inject Java objects into a page's JavaScript 138 * context, so that they can be accessed by JavaScript in the page.</li> 139 * </ul> 140 * 141 * <p>Here's a more complicated example, showing error handling, 142 * settings, and progress notification:</p> 143 * 144 * <pre class="prettyprint"> 145 * // Let's display the progress in the activity title bar, like the 146 * // browser app does. 147 * getWindow().requestFeature(Window.FEATURE_PROGRESS); 148 * 149 * webview.getSettings().setJavaScriptEnabled(true); 150 * 151 * final Activity activity = this; 152 * webview.setWebChromeClient(new WebChromeClient() { 153 * public void onProgressChanged(WebView view, int progress) { 154 * // Activities and WebViews measure progress with different scales. 155 * // The progress meter will automatically disappear when we reach 100% 156 * activity.setProgress(progress * 1000); 157 * } 158 * }); 159 * webview.setWebViewClient(new WebViewClient() { 160 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 161 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); 162 * } 163 * }); 164 * 165 * webview.loadUrl("http://slashdot.org/"); 166 * </pre> 167 * 168 * <h3>Cookie and window management</h3> 169 * 170 * <p>For obvious security reasons, your application has its own 171 * cache, cookie store etc.—it does not share the Browser 172 * application's data. 173 * </p> 174 * 175 * <p>By default, requests by the HTML to open new windows are 176 * ignored. This is true whether they be opened by JavaScript or by 177 * the target attribute on a link. You can customize your 178 * {@link WebChromeClient} to provide your own behaviour for opening multiple windows, 179 * and render them in whatever manner you want.</p> 180 * 181 * <p>The standard behavior for an Activity is to be destroyed and 182 * recreated when the device orientation or any other configuration changes. This will cause 183 * the WebView to reload the current page. If you don't want that, you 184 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden} 185 * changes, and then just leave the WebView alone. It'll automatically 186 * re-orient itself as appropriate. Read <a 187 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for 188 * more information about how to handle configuration changes during runtime.</p> 189 * 190 * 191 * <h3>Building web pages to support different screen densities</h3> 192 * 193 * <p>The screen density of a device is based on the screen resolution. A screen with low density 194 * has fewer available pixels per inch, where a screen with high density 195 * has more — sometimes significantly more — pixels per inch. The density of a 196 * screen is important because, other things being equal, a UI element (such as a button) whose 197 * height and width are defined in terms of screen pixels will appear larger on the lower density 198 * screen and smaller on the higher density screen. 199 * For simplicity, Android collapses all actual screen densities into three generalized densities: 200 * high, medium, and low.</p> 201 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default 202 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen 203 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels 204 * are bigger). 205 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS, 206 * and meta tag features to help you (as a web developer) target screens with different screen 207 * densities.</p> 208 * <p>Here's a summary of the features you can use to handle different screen densities:</p> 209 * <ul> 210 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the 211 * default scaling factor used for the current device. For example, if the value of {@code 212 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device 213 * and default scaling is not applied to the web page; if the value is "1.5", then the device is 214 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the 215 * value is "0.75", then the device is considered a low density device (ldpi) and the content is 216 * scaled 0.75x.</li> 217 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen 218 * densities for which this style sheet is to be used. The corresponding value should be either 219 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium 220 * density, or high density screens, respectively. For example: 221 * <pre> 222 * <link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /></pre> 223 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5, 224 * which is the high density pixel ratio.</p> 225 * </li> 226 * 227 * <h3>HTML5 Video support</h3> 228 * 229 * <p>In order to support inline HTML5 video in your application, you need to have hardware 230 * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support, 231 * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)} 232 * and {@link WebChromeClient#onHideCustomView()} are required, 233 * {@link WebChromeClient#getVideoLoadingProgressView()} is optional. 234 * </p> 235 */ 236// Implementation notes. 237// The WebView is a thin API class that delegates its public API to a backend WebViewProvider 238// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons. 239// Methods are delegated to the provider implementation: all public API methods introduced in this 240// file are fully delegated, whereas public and protected methods from the View base classes are 241// only delegated where a specific need exists for them to do so. 242@Widget 243public class WebView extends AbsoluteLayout 244 implements ViewTreeObserver.OnGlobalFocusChangeListener, 245 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler { 246 247 private static final String LOGTAG = "webview_proxy"; 248 249 // Throwing an exception for incorrect thread usage if the 250 // build target is JB MR2 or newer. Defaults to false, and is 251 // set in the WebView constructor. 252 private static Boolean sEnforceThreadChecking = false; 253 254 /** 255 * Transportation object for returning WebView across thread boundaries. 256 */ 257 public class WebViewTransport { 258 private WebView mWebview; 259 260 /** 261 * Sets the WebView to the transportation object. 262 * 263 * @param webview the WebView to transport 264 */ 265 public synchronized void setWebView(WebView webview) { 266 mWebview = webview; 267 } 268 269 /** 270 * Gets the WebView object. 271 * 272 * @return the transported WebView object 273 */ 274 public synchronized WebView getWebView() { 275 return mWebview; 276 } 277 } 278 279 /** 280 * URI scheme for telephone number. 281 */ 282 public static final String SCHEME_TEL = "tel:"; 283 /** 284 * URI scheme for email address. 285 */ 286 public static final String SCHEME_MAILTO = "mailto:"; 287 /** 288 * URI scheme for map address. 289 */ 290 public static final String SCHEME_GEO = "geo:0,0?q="; 291 292 /** 293 * Interface to listen for find results. 294 */ 295 public interface FindListener { 296 /** 297 * Notifies the listener about progress made by a find operation. 298 * 299 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match 300 * @param numberOfMatches how many matches have been found 301 * @param isDoneCounting whether the find operation has actually completed. The listener 302 * may be notified multiple times while the 303 * operation is underway, and the numberOfMatches 304 * value should not be considered final unless 305 * isDoneCounting is true. 306 */ 307 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, 308 boolean isDoneCounting); 309 } 310 311 /** 312 * Interface to listen for new pictures as they change. 313 * 314 * @deprecated This interface is now obsolete. 315 */ 316 @Deprecated 317 public interface PictureListener { 318 /** 319 * Used to provide notification that the WebView's picture has changed. 320 * See {@link WebView#capturePicture} for details of the picture. 321 * 322 * @param view the WebView that owns the picture 323 * @param picture the new picture. Applications targeting 324 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above 325 * will always receive a null Picture. 326 * @deprecated Deprecated due to internal changes. 327 */ 328 @Deprecated 329 public void onNewPicture(WebView view, Picture picture); 330 } 331 332 public static class HitTestResult { 333 /** 334 * Default HitTestResult, where the target is unknown. 335 */ 336 public static final int UNKNOWN_TYPE = 0; 337 /** 338 * @deprecated This type is no longer used. 339 */ 340 @Deprecated 341 public static final int ANCHOR_TYPE = 1; 342 /** 343 * HitTestResult for hitting a phone number. 344 */ 345 public static final int PHONE_TYPE = 2; 346 /** 347 * HitTestResult for hitting a map address. 348 */ 349 public static final int GEO_TYPE = 3; 350 /** 351 * HitTestResult for hitting an email address. 352 */ 353 public static final int EMAIL_TYPE = 4; 354 /** 355 * HitTestResult for hitting an HTML::img tag. 356 */ 357 public static final int IMAGE_TYPE = 5; 358 /** 359 * @deprecated This type is no longer used. 360 */ 361 @Deprecated 362 public static final int IMAGE_ANCHOR_TYPE = 6; 363 /** 364 * HitTestResult for hitting a HTML::a tag with src=http. 365 */ 366 public static final int SRC_ANCHOR_TYPE = 7; 367 /** 368 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img. 369 */ 370 public static final int SRC_IMAGE_ANCHOR_TYPE = 8; 371 /** 372 * HitTestResult for hitting an edit text area. 373 */ 374 public static final int EDIT_TEXT_TYPE = 9; 375 376 private int mType; 377 private String mExtra; 378 379 /** 380 * @hide Only for use by WebViewProvider implementations 381 */ 382 public HitTestResult() { 383 mType = UNKNOWN_TYPE; 384 } 385 386 /** 387 * @hide Only for use by WebViewProvider implementations 388 */ 389 public void setType(int type) { 390 mType = type; 391 } 392 393 /** 394 * @hide Only for use by WebViewProvider implementations 395 */ 396 public void setExtra(String extra) { 397 mExtra = extra; 398 } 399 400 /** 401 * Gets the type of the hit test result. See the XXX_TYPE constants 402 * defined in this class. 403 * 404 * @return the type of the hit test result 405 */ 406 public int getType() { 407 return mType; 408 } 409 410 /** 411 * Gets additional type-dependant information about the result. See 412 * {@link WebView#getHitTestResult()} for details. May either be null 413 * or contain extra information about this result. 414 * 415 * @return additional type-dependant information about the result 416 */ 417 public String getExtra() { 418 return mExtra; 419 } 420 } 421 422 /** 423 * Constructs a new WebView with a Context object. 424 * 425 * @param context a Context object used to access application assets 426 */ 427 public WebView(Context context) { 428 this(context, null); 429 } 430 431 /** 432 * Constructs a new WebView with layout parameters. 433 * 434 * @param context a Context object used to access application assets 435 * @param attrs an AttributeSet passed to our parent 436 */ 437 public WebView(Context context, AttributeSet attrs) { 438 this(context, attrs, com.android.internal.R.attr.webViewStyle); 439 } 440 441 /** 442 * Constructs a new WebView with layout parameters and a default style. 443 * 444 * @param context a Context object used to access application assets 445 * @param attrs an AttributeSet passed to our parent 446 * @param defStyle the default style resource ID 447 */ 448 public WebView(Context context, AttributeSet attrs, int defStyle) { 449 this(context, attrs, defStyle, false); 450 } 451 452 /** 453 * Constructs a new WebView with layout parameters and a default style. 454 * 455 * @param context a Context object used to access application assets 456 * @param attrs an AttributeSet passed to our parent 457 * @param defStyle the default style resource ID 458 * @param privateBrowsing whether this WebView will be initialized in 459 * private mode 460 * 461 * @deprecated Private browsing is no longer supported directly via 462 * WebView and will be removed in a future release. Prefer using 463 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager} 464 * and {@link WebStorage} for fine-grained control of privacy data. 465 */ 466 @Deprecated 467 public WebView(Context context, AttributeSet attrs, int defStyle, 468 boolean privateBrowsing) { 469 this(context, attrs, defStyle, null, privateBrowsing); 470 } 471 472 /** 473 * Constructs a new WebView with layout parameters, a default style and a set 474 * of custom Javscript interfaces to be added to this WebView at initialization 475 * time. This guarantees that these interfaces will be available when the JS 476 * context is initialized. 477 * 478 * @param context a Context object used to access application assets 479 * @param attrs an AttributeSet passed to our parent 480 * @param defStyle the default style resource ID 481 * @param javaScriptInterfaces a Map of interface names, as keys, and 482 * object implementing those interfaces, as 483 * values 484 * @param privateBrowsing whether this WebView will be initialized in 485 * private mode 486 * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to 487 * be added synchronously, before a subsequent loadUrl call takes effect. 488 */ 489 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor. 490 protected WebView(Context context, AttributeSet attrs, int defStyle, 491 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) { 492 super(context, attrs, defStyle); 493 if (context == null) { 494 throw new IllegalArgumentException("Invalid context argument"); 495 } 496 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >= 497 Build.VERSION_CODES.JELLY_BEAN_MR2; 498 checkThread(); 499 500 ensureProviderCreated(); 501 mProvider.init(javaScriptInterfaces, privateBrowsing); 502 } 503 504 /** 505 * Specifies whether the horizontal scrollbar has overlay style. 506 * 507 * @param overlay true if horizontal scrollbar should have overlay style 508 */ 509 public void setHorizontalScrollbarOverlay(boolean overlay) { 510 checkThread(); 511 mProvider.setHorizontalScrollbarOverlay(overlay); 512 } 513 514 /** 515 * Specifies whether the vertical scrollbar has overlay style. 516 * 517 * @param overlay true if vertical scrollbar should have overlay style 518 */ 519 public void setVerticalScrollbarOverlay(boolean overlay) { 520 checkThread(); 521 mProvider.setVerticalScrollbarOverlay(overlay); 522 } 523 524 /** 525 * Gets whether horizontal scrollbar has overlay style. 526 * 527 * @return true if horizontal scrollbar has overlay style 528 */ 529 public boolean overlayHorizontalScrollbar() { 530 checkThread(); 531 return mProvider.overlayHorizontalScrollbar(); 532 } 533 534 /** 535 * Gets whether vertical scrollbar has overlay style. 536 * 537 * @return true if vertical scrollbar has overlay style 538 */ 539 public boolean overlayVerticalScrollbar() { 540 checkThread(); 541 return mProvider.overlayVerticalScrollbar(); 542 } 543 544 /** 545 * Gets the visible height (in pixels) of the embedded title bar (if any). 546 * 547 * @deprecated This method is now obsolete. 548 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 549 */ 550 public int getVisibleTitleHeight() { 551 checkThread(); 552 return mProvider.getVisibleTitleHeight(); 553 } 554 555 /** 556 * Gets the SSL certificate for the main top-level page or null if there is 557 * no certificate (the site is not secure). 558 * 559 * @return the SSL certificate for the main top-level page 560 */ 561 public SslCertificate getCertificate() { 562 checkThread(); 563 return mProvider.getCertificate(); 564 } 565 566 /** 567 * Sets the SSL certificate for the main top-level page. 568 * 569 * @deprecated Calling this function has no useful effect, and will be 570 * ignored in future releases. 571 */ 572 @Deprecated 573 public void setCertificate(SslCertificate certificate) { 574 checkThread(); 575 mProvider.setCertificate(certificate); 576 } 577 578 //------------------------------------------------------------------------- 579 // Methods called by activity 580 //------------------------------------------------------------------------- 581 582 /** 583 * Sets a username and password pair for the specified host. This data is 584 * used by the Webview to autocomplete username and password fields in web 585 * forms. Note that this is unrelated to the credentials used for HTTP 586 * authentication. 587 * 588 * @param host the host that required the credentials 589 * @param username the username for the given host 590 * @param password the password for the given host 591 * @see WebViewDatabase#clearUsernamePassword 592 * @see WebViewDatabase#hasUsernamePassword 593 * @deprecated Saving passwords in WebView will not be supported in future versions. 594 */ 595 @Deprecated 596 public void savePassword(String host, String username, String password) { 597 checkThread(); 598 mProvider.savePassword(host, username, password); 599 } 600 601 /** 602 * Stores HTTP authentication credentials for a given host and realm. This 603 * method is intended to be used with 604 * {@link WebViewClient#onReceivedHttpAuthRequest}. 605 * 606 * @param host the host to which the credentials apply 607 * @param realm the realm to which the credentials apply 608 * @param username the username 609 * @param password the password 610 * @see #getHttpAuthUsernamePassword 611 * @see WebViewDatabase#hasHttpAuthUsernamePassword 612 * @see WebViewDatabase#clearHttpAuthUsernamePassword 613 */ 614 public void setHttpAuthUsernamePassword(String host, String realm, 615 String username, String password) { 616 checkThread(); 617 mProvider.setHttpAuthUsernamePassword(host, realm, username, password); 618 } 619 620 /** 621 * Retrieves HTTP authentication credentials for a given host and realm. 622 * This method is intended to be used with 623 * {@link WebViewClient#onReceivedHttpAuthRequest}. 624 * 625 * @param host the host to which the credentials apply 626 * @param realm the realm to which the credentials apply 627 * @return the credentials as a String array, if found. The first element 628 * is the username and the second element is the password. Null if 629 * no credentials are found. 630 * @see #setHttpAuthUsernamePassword 631 * @see WebViewDatabase#hasHttpAuthUsernamePassword 632 * @see WebViewDatabase#clearHttpAuthUsernamePassword 633 */ 634 public String[] getHttpAuthUsernamePassword(String host, String realm) { 635 checkThread(); 636 return mProvider.getHttpAuthUsernamePassword(host, realm); 637 } 638 639 /** 640 * Destroys the internal state of this WebView. This method should be called 641 * after this WebView has been removed from the view system. No other 642 * methods may be called on this WebView after destroy. 643 */ 644 public void destroy() { 645 checkThread(); 646 mProvider.destroy(); 647 } 648 649 /** 650 * Enables platform notifications of data state and proxy changes. 651 * Notifications are enabled by default. 652 * 653 * @deprecated This method is now obsolete. 654 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 655 */ 656 @Deprecated 657 public static void enablePlatformNotifications() { 658 checkThread(); 659 getFactory().getStatics().setPlatformNotificationsEnabled(true); 660 } 661 662 /** 663 * Disables platform notifications of data state and proxy changes. 664 * Notifications are enabled by default. 665 * 666 * @deprecated This method is now obsolete. 667 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 668 */ 669 @Deprecated 670 public static void disablePlatformNotifications() { 671 checkThread(); 672 getFactory().getStatics().setPlatformNotificationsEnabled(false); 673 } 674 675 /** 676 * Informs WebView of the network state. This is used to set 677 * the JavaScript property window.navigator.isOnline and 678 * generates the online/offline event as specified in HTML5, sec. 5.7.7 679 * 680 * @param networkUp a boolean indicating if network is available 681 */ 682 public void setNetworkAvailable(boolean networkUp) { 683 checkThread(); 684 mProvider.setNetworkAvailable(networkUp); 685 } 686 687 /** 688 * Saves the state of this WebView used in 689 * {@link android.app.Activity#onSaveInstanceState}. Please note that this 690 * method no longer stores the display data for this WebView. The previous 691 * behavior could potentially leak files if {@link #restoreState} was never 692 * called. 693 * 694 * @param outState the Bundle to store this WebView's state 695 * @return the same copy of the back/forward list used to save the state. If 696 * saveState fails, the returned list will be null. 697 */ 698 public WebBackForwardList saveState(Bundle outState) { 699 checkThread(); 700 return mProvider.saveState(outState); 701 } 702 703 /** 704 * Saves the current display data to the Bundle given. Used in conjunction 705 * with {@link #saveState}. 706 * @param b a Bundle to store the display data 707 * @param dest the file to store the serialized picture data. Will be 708 * overwritten with this WebView's picture data. 709 * @return true if the picture was successfully saved 710 * @deprecated This method is now obsolete. 711 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 712 */ 713 @Deprecated 714 public boolean savePicture(Bundle b, final File dest) { 715 checkThread(); 716 return mProvider.savePicture(b, dest); 717 } 718 719 /** 720 * Restores the display data that was saved in {@link #savePicture}. Used in 721 * conjunction with {@link #restoreState}. Note that this will not work if 722 * this WebView is hardware accelerated. 723 * 724 * @param b a Bundle containing the saved display data 725 * @param src the file where the picture data was stored 726 * @return true if the picture was successfully restored 727 * @deprecated This method is now obsolete. 728 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 729 */ 730 @Deprecated 731 public boolean restorePicture(Bundle b, File src) { 732 checkThread(); 733 return mProvider.restorePicture(b, src); 734 } 735 736 /** 737 * Restores the state of this WebView from the given Bundle. This method is 738 * intended for use in {@link android.app.Activity#onRestoreInstanceState} 739 * and should be called to restore the state of this WebView. If 740 * it is called after this WebView has had a chance to build state (load 741 * pages, create a back/forward list, etc.) there may be undesirable 742 * side-effects. Please note that this method no longer restores the 743 * display data for this WebView. 744 * 745 * @param inState the incoming Bundle of state 746 * @return the restored back/forward list or null if restoreState failed 747 */ 748 public WebBackForwardList restoreState(Bundle inState) { 749 checkThread(); 750 return mProvider.restoreState(inState); 751 } 752 753 /** 754 * Loads the given URL with the specified additional HTTP headers. 755 * 756 * @param url the URL of the resource to load 757 * @param additionalHttpHeaders the additional headers to be used in the 758 * HTTP request for this URL, specified as a map from name to 759 * value. Note that if this map contains any of the headers 760 * that are set by default by this WebView, such as those 761 * controlling caching, accept types or the User-Agent, their 762 * values may be overriden by this WebView's defaults. 763 */ 764 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) { 765 checkThread(); 766 mProvider.loadUrl(url, additionalHttpHeaders); 767 } 768 769 /** 770 * Loads the given URL. 771 * 772 * @param url the URL of the resource to load 773 */ 774 public void loadUrl(String url) { 775 checkThread(); 776 mProvider.loadUrl(url); 777 } 778 779 /** 780 * Loads the URL with postData using "POST" method into this WebView. If url 781 * is not a network URL, it will be loaded with {link 782 * {@link #loadUrl(String)} instead. 783 * 784 * @param url the URL of the resource to load 785 * @param postData the data will be passed to "POST" request, which must be 786 * be "application/x-www-form-urlencoded" encoded. 787 */ 788 public void postUrl(String url, byte[] postData) { 789 checkThread(); 790 mProvider.postUrl(url, postData); 791 } 792 793 /** 794 * Loads the given data into this WebView using a 'data' scheme URL. 795 * <p> 796 * Note that JavaScript's same origin policy means that script running in a 797 * page loaded using this method will be unable to access content loaded 798 * using any scheme other than 'data', including 'http(s)'. To avoid this 799 * restriction, use {@link 800 * #loadDataWithBaseURL(String,String,String,String,String) 801 * loadDataWithBaseURL()} with an appropriate base URL. 802 * <p> 803 * The encoding parameter specifies whether the data is base64 or URL 804 * encoded. If the data is base64 encoded, the value of the encoding 805 * parameter must be 'base64'. For all other values of the parameter, 806 * including null, it is assumed that the data uses ASCII encoding for 807 * octets inside the range of safe URL characters and use the standard %xx 808 * hex encoding of URLs for octets outside that range. For example, '#', 809 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively. 810 * <p> 811 * The 'data' scheme URL formed by this method uses the default US-ASCII 812 * charset. If you need need to set a different charset, you should form a 813 * 'data' scheme URL which explicitly specifies a charset parameter in the 814 * mediatype portion of the URL and call {@link #loadUrl(String)} instead. 815 * Note that the charset obtained from the mediatype portion of a data URL 816 * always overrides that specified in the HTML or XML document itself. 817 * 818 * @param data a String of data in the given encoding 819 * @param mimeType the MIME type of the data, e.g. 'text/html' 820 * @param encoding the encoding of the data 821 */ 822 public void loadData(String data, String mimeType, String encoding) { 823 checkThread(); 824 mProvider.loadData(data, mimeType, encoding); 825 } 826 827 /** 828 * Loads the given data into this WebView, using baseUrl as the base URL for 829 * the content. The base URL is used both to resolve relative URLs and when 830 * applying JavaScript's same origin policy. The historyUrl is used for the 831 * history entry. 832 * <p> 833 * Note that content specified in this way can access local device files 834 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 835 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'. 836 * <p> 837 * If the base URL uses the data scheme, this method is equivalent to 838 * calling {@link #loadData(String,String,String) loadData()} and the 839 * historyUrl is ignored, and the data will be treated as part of a data: URL. 840 * If the base URL uses any other scheme, then the data will be loaded into 841 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded 842 * entities in the string will not be decoded. 843 * 844 * @param baseUrl the URL to use as the page's base URL. If null defaults to 845 * 'about:blank'. 846 * @param data a String of data in the given encoding 847 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null, 848 * defaults to 'text/html'. 849 * @param encoding the encoding of the data 850 * @param historyUrl the URL to use as the history entry. If null defaults 851 * to 'about:blank'. If non-null, this must be a valid URL. 852 */ 853 public void loadDataWithBaseURL(String baseUrl, String data, 854 String mimeType, String encoding, String historyUrl) { 855 checkThread(); 856 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); 857 } 858 859 /** 860 * Asynchronously evaluates JavaScript in the context of the currently displayed page. 861 * If non-null, |resultCallback| will be invoked with any result returned from that 862 * execution. This method must be called on the UI thread and the callback will 863 * be made on the UI thread. 864 * 865 * @param script the JavaScript to execute. 866 * @param resultCallback A callback to be invoked when the script execution 867 * completes with the result of the execution (if any). 868 * May be null if no notificaion of the result is required. 869 */ 870 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) { 871 checkThread(); 872 mProvider.evaluateJavaScript(script, resultCallback); 873 } 874 875 /** 876 * Saves the current view as a web archive. 877 * 878 * @param filename the filename where the archive should be placed 879 */ 880 public void saveWebArchive(String filename) { 881 checkThread(); 882 mProvider.saveWebArchive(filename); 883 } 884 885 /** 886 * Saves the current view as a web archive. 887 * 888 * @param basename the filename where the archive should be placed 889 * @param autoname if false, takes basename to be a file. If true, basename 890 * is assumed to be a directory in which a filename will be 891 * chosen according to the URL of the current page. 892 * @param callback called after the web archive has been saved. The 893 * parameter for onReceiveValue will either be the filename 894 * under which the file was saved, or null if saving the 895 * file failed. 896 */ 897 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) { 898 checkThread(); 899 mProvider.saveWebArchive(basename, autoname, callback); 900 } 901 902 /** 903 * Stops the current load. 904 */ 905 public void stopLoading() { 906 checkThread(); 907 mProvider.stopLoading(); 908 } 909 910 /** 911 * Reloads the current URL. 912 */ 913 public void reload() { 914 checkThread(); 915 mProvider.reload(); 916 } 917 918 /** 919 * Gets whether this WebView has a back history item. 920 * 921 * @return true iff this WebView has a back history item 922 */ 923 public boolean canGoBack() { 924 checkThread(); 925 return mProvider.canGoBack(); 926 } 927 928 /** 929 * Goes back in the history of this WebView. 930 */ 931 public void goBack() { 932 checkThread(); 933 mProvider.goBack(); 934 } 935 936 /** 937 * Gets whether this WebView has a forward history item. 938 * 939 * @return true iff this Webview has a forward history item 940 */ 941 public boolean canGoForward() { 942 checkThread(); 943 return mProvider.canGoForward(); 944 } 945 946 /** 947 * Goes forward in the history of this WebView. 948 */ 949 public void goForward() { 950 checkThread(); 951 mProvider.goForward(); 952 } 953 954 /** 955 * Gets whether the page can go back or forward the given 956 * number of steps. 957 * 958 * @param steps the negative or positive number of steps to move the 959 * history 960 */ 961 public boolean canGoBackOrForward(int steps) { 962 checkThread(); 963 return mProvider.canGoBackOrForward(steps); 964 } 965 966 /** 967 * Goes to the history item that is the number of steps away from 968 * the current item. Steps is negative if backward and positive 969 * if forward. 970 * 971 * @param steps the number of steps to take back or forward in the back 972 * forward list 973 */ 974 public void goBackOrForward(int steps) { 975 checkThread(); 976 mProvider.goBackOrForward(steps); 977 } 978 979 /** 980 * Gets whether private browsing is enabled in this WebView. 981 */ 982 public boolean isPrivateBrowsingEnabled() { 983 checkThread(); 984 return mProvider.isPrivateBrowsingEnabled(); 985 } 986 987 /** 988 * Scrolls the contents of this WebView up by half the view size. 989 * 990 * @param top true to jump to the top of the page 991 * @return true if the page was scrolled 992 */ 993 public boolean pageUp(boolean top) { 994 checkThread(); 995 return mProvider.pageUp(top); 996 } 997 998 /** 999 * Scrolls the contents of this WebView down by half the page size. 1000 * 1001 * @param bottom true to jump to bottom of page 1002 * @return true if the page was scrolled 1003 */ 1004 public boolean pageDown(boolean bottom) { 1005 checkThread(); 1006 return mProvider.pageDown(bottom); 1007 } 1008 1009 /** 1010 * Clears this WebView so that onDraw() will draw nothing but white background, 1011 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY. 1012 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state 1013 * and release page resources (including any running JavaScript). 1014 */ 1015 @Deprecated 1016 public void clearView() { 1017 checkThread(); 1018 mProvider.clearView(); 1019 } 1020 1021 /** 1022 * Gets a new picture that captures the current contents of this WebView. 1023 * The picture is of the entire document being displayed, and is not 1024 * limited to the area currently displayed by this WebView. Also, the 1025 * picture is a static copy and is unaffected by later changes to the 1026 * content being displayed. 1027 * <p> 1028 * Note that due to internal changes, for API levels between 1029 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and 1030 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the 1031 * picture does not include fixed position elements or scrollable divs. 1032 * 1033 * @return a picture that captures the current contents of this WebView 1034 */ 1035 public Picture capturePicture() { 1036 checkThread(); 1037 return mProvider.capturePicture(); 1038 } 1039 1040 /** 1041 * Exports the contents of this Webview as PDF. Only supported for API levels 1042 * {@link android.os.Build.VERSION_CODES#KEY_LIME_PIE} and above. 1043 * 1044 * TODO(sgurun) the parameter list is stale. Fix it before unhiding. 1045 * 1046 * @param fd The FileDescriptor to export the PDF contents to. Cannot be null. 1047 * @param width The page width. Should be larger than 0. 1048 * @param height The page height. Should be larger than 0. 1049 * @param resultCallback A callback to be invoked when the PDF content is exported. 1050 * A true indicates success, and a false failure. Cannot be null. 1051 * @param cancellationSignal Signal for cancelling the PDF conversion request. Must not 1052 * be null. 1053 * 1054 * The PDF conversion is done asynchronously and the PDF output is written to the provided 1055 * file descriptor. The caller should not close the file descriptor until the resultCallback 1056 * is called, indicating PDF conversion is complete. Webview will never close the file 1057 * descriptor. 1058 * Limitations: Webview cannot be drawn during the PDF export so the application is 1059 * recommended to take it offscreen, or putting in a layer with an overlaid progress 1060 * UI / spinner. 1061 * 1062 * If the caller cancels the task using the cancellationSignal, the cancellation will be 1063 * acked using the resultCallback signal. 1064 * 1065 * Throws an exception if an IO error occurs accessing the file descriptor. 1066 * 1067 * TODO(sgurun) margins, explain the units, make it public. 1068 * @hide 1069 */ 1070 public void exportToPdf(ParcelFileDescriptor fd, PrintAttributes attributes, 1071 ValueCallback<Boolean> resultCallback, CancellationSignal cancellationSignal) 1072 throws java.io.IOException { 1073 checkThread(); 1074 mProvider.exportToPdf(fd, attributes, resultCallback, cancellationSignal); 1075 } 1076 1077 /** 1078 * Gets the current scale of this WebView. 1079 * 1080 * @return the current scale 1081 * 1082 * @deprecated This method is prone to inaccuracy due to race conditions 1083 * between the web rendering and UI threads; prefer 1084 * {@link WebViewClient#onScaleChanged}. 1085 */ 1086 @Deprecated 1087 @ViewDebug.ExportedProperty(category = "webview") 1088 public float getScale() { 1089 checkThread(); 1090 return mProvider.getScale(); 1091 } 1092 1093 /** 1094 * Sets the initial scale for this WebView. 0 means default. If 1095 * {@link WebSettings#getUseWideViewPort()} is true, it zooms out all the 1096 * way. Otherwise it starts with 100%. If initial scale is greater than 0, 1097 * WebView starts with this value as initial scale. 1098 * Please note that unlike the scale properties in the viewport meta tag, 1099 * this method doesn't take the screen density into account. 1100 * 1101 * @param scaleInPercent the initial scale in percent 1102 */ 1103 public void setInitialScale(int scaleInPercent) { 1104 checkThread(); 1105 mProvider.setInitialScale(scaleInPercent); 1106 } 1107 1108 /** 1109 * Invokes the graphical zoom picker widget for this WebView. This will 1110 * result in the zoom widget appearing on the screen to control the zoom 1111 * level of this WebView. 1112 */ 1113 public void invokeZoomPicker() { 1114 checkThread(); 1115 mProvider.invokeZoomPicker(); 1116 } 1117 1118 /** 1119 * Gets a HitTestResult based on the current cursor node. If a HTML::a 1120 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult 1121 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field. 1122 * If the anchor does not have a URL or if it is a JavaScript URL, the type 1123 * will be UNKNOWN_TYPE and the URL has to be retrieved through 1124 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is 1125 * found, the HitTestResult type is set to IMAGE_TYPE and the URL is set in 1126 * the "extra" field. A type of 1127 * SRC_IMAGE_ANCHOR_TYPE indicates an anchor with a URL that has an image as 1128 * a child node. If a phone number is found, the HitTestResult type is set 1129 * to PHONE_TYPE and the phone number is set in the "extra" field of 1130 * HitTestResult. If a map address is found, the HitTestResult type is set 1131 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult. 1132 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE 1133 * and the email is set in the "extra" field of HitTestResult. Otherwise, 1134 * HitTestResult type is set to UNKNOWN_TYPE. 1135 */ 1136 public HitTestResult getHitTestResult() { 1137 checkThread(); 1138 return mProvider.getHitTestResult(); 1139 } 1140 1141 /** 1142 * Requests the anchor or image element URL at the last tapped point. 1143 * If hrefMsg is null, this method returns immediately and does not 1144 * dispatch hrefMsg to its target. If the tapped point hits an image, 1145 * an anchor, or an image in an anchor, the message associates 1146 * strings in named keys in its data. The value paired with the key 1147 * may be an empty string. 1148 * 1149 * @param hrefMsg the message to be dispatched with the result of the 1150 * request. The message data contains three keys. "url" 1151 * returns the anchor's href attribute. "title" returns the 1152 * anchor's text. "src" returns the image's src attribute. 1153 */ 1154 public void requestFocusNodeHref(Message hrefMsg) { 1155 checkThread(); 1156 mProvider.requestFocusNodeHref(hrefMsg); 1157 } 1158 1159 /** 1160 * Requests the URL of the image last touched by the user. msg will be sent 1161 * to its target with a String representing the URL as its object. 1162 * 1163 * @param msg the message to be dispatched with the result of the request 1164 * as the data member with "url" as key. The result can be null. 1165 */ 1166 public void requestImageRef(Message msg) { 1167 checkThread(); 1168 mProvider.requestImageRef(msg); 1169 } 1170 1171 /** 1172 * Gets the URL for the current page. This is not always the same as the URL 1173 * passed to WebViewClient.onPageStarted because although the load for 1174 * that URL has begun, the current page may not have changed. 1175 * 1176 * @return the URL for the current page 1177 */ 1178 @ViewDebug.ExportedProperty(category = "webview") 1179 public String getUrl() { 1180 checkThread(); 1181 return mProvider.getUrl(); 1182 } 1183 1184 /** 1185 * Gets the original URL for the current page. This is not always the same 1186 * as the URL passed to WebViewClient.onPageStarted because although the 1187 * load for that URL has begun, the current page may not have changed. 1188 * Also, there may have been redirects resulting in a different URL to that 1189 * originally requested. 1190 * 1191 * @return the URL that was originally requested for the current page 1192 */ 1193 @ViewDebug.ExportedProperty(category = "webview") 1194 public String getOriginalUrl() { 1195 checkThread(); 1196 return mProvider.getOriginalUrl(); 1197 } 1198 1199 /** 1200 * Gets the title for the current page. This is the title of the current page 1201 * until WebViewClient.onReceivedTitle is called. 1202 * 1203 * @return the title for the current page 1204 */ 1205 @ViewDebug.ExportedProperty(category = "webview") 1206 public String getTitle() { 1207 checkThread(); 1208 return mProvider.getTitle(); 1209 } 1210 1211 /** 1212 * Gets the favicon for the current page. This is the favicon of the current 1213 * page until WebViewClient.onReceivedIcon is called. 1214 * 1215 * @return the favicon for the current page 1216 */ 1217 public Bitmap getFavicon() { 1218 checkThread(); 1219 return mProvider.getFavicon(); 1220 } 1221 1222 /** 1223 * Gets the touch icon URL for the apple-touch-icon <link> element, or 1224 * a URL on this site's server pointing to the standard location of a 1225 * touch icon. 1226 * 1227 * @hide 1228 */ 1229 public String getTouchIconUrl() { 1230 return mProvider.getTouchIconUrl(); 1231 } 1232 1233 /** 1234 * Gets the progress for the current page. 1235 * 1236 * @return the progress for the current page between 0 and 100 1237 */ 1238 public int getProgress() { 1239 checkThread(); 1240 return mProvider.getProgress(); 1241 } 1242 1243 /** 1244 * Gets the height of the HTML content. 1245 * 1246 * @return the height of the HTML content 1247 */ 1248 @ViewDebug.ExportedProperty(category = "webview") 1249 public int getContentHeight() { 1250 checkThread(); 1251 return mProvider.getContentHeight(); 1252 } 1253 1254 /** 1255 * Gets the width of the HTML content. 1256 * 1257 * @return the width of the HTML content 1258 * @hide 1259 */ 1260 @ViewDebug.ExportedProperty(category = "webview") 1261 public int getContentWidth() { 1262 return mProvider.getContentWidth(); 1263 } 1264 1265 /** 1266 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This 1267 * is a global requests, not restricted to just this WebView. This can be 1268 * useful if the application has been paused. 1269 */ 1270 public void pauseTimers() { 1271 checkThread(); 1272 mProvider.pauseTimers(); 1273 } 1274 1275 /** 1276 * Resumes all layout, parsing, and JavaScript timers for all WebViews. 1277 * This will resume dispatching all timers. 1278 */ 1279 public void resumeTimers() { 1280 checkThread(); 1281 mProvider.resumeTimers(); 1282 } 1283 1284 /** 1285 * Pauses any extra processing associated with this WebView and its 1286 * associated DOM, plugins, JavaScript etc. For example, if this WebView is 1287 * taken offscreen, this could be called to reduce unnecessary CPU or 1288 * network traffic. When this WebView is again "active", call onResume(). 1289 * Note that this differs from pauseTimers(), which affects all WebViews. 1290 */ 1291 public void onPause() { 1292 checkThread(); 1293 mProvider.onPause(); 1294 } 1295 1296 /** 1297 * Resumes a WebView after a previous call to onPause(). 1298 */ 1299 public void onResume() { 1300 checkThread(); 1301 mProvider.onResume(); 1302 } 1303 1304 /** 1305 * Gets whether this WebView is paused, meaning onPause() was called. 1306 * Calling onResume() sets the paused state back to false. 1307 * 1308 * @hide 1309 */ 1310 public boolean isPaused() { 1311 return mProvider.isPaused(); 1312 } 1313 1314 /** 1315 * Informs this WebView that memory is low so that it can free any available 1316 * memory. 1317 */ 1318 public void freeMemory() { 1319 checkThread(); 1320 mProvider.freeMemory(); 1321 } 1322 1323 /** 1324 * Clears the resource cache. Note that the cache is per-application, so 1325 * this will clear the cache for all WebViews used. 1326 * 1327 * @param includeDiskFiles if false, only the RAM cache is cleared 1328 */ 1329 public void clearCache(boolean includeDiskFiles) { 1330 checkThread(); 1331 mProvider.clearCache(includeDiskFiles); 1332 } 1333 1334 /** 1335 * Removes the autocomplete popup from the currently focused form field, if 1336 * present. Note this only affects the display of the autocomplete popup, 1337 * it does not remove any saved form data from this WebView's store. To do 1338 * that, use {@link WebViewDatabase#clearFormData}. 1339 */ 1340 public void clearFormData() { 1341 checkThread(); 1342 mProvider.clearFormData(); 1343 } 1344 1345 /** 1346 * Tells this WebView to clear its internal back/forward list. 1347 */ 1348 public void clearHistory() { 1349 checkThread(); 1350 mProvider.clearHistory(); 1351 } 1352 1353 /** 1354 * Clears the SSL preferences table stored in response to proceeding with 1355 * SSL certificate errors. 1356 */ 1357 public void clearSslPreferences() { 1358 checkThread(); 1359 mProvider.clearSslPreferences(); 1360 } 1361 1362 /** 1363 * Gets the WebBackForwardList for this WebView. This contains the 1364 * back/forward list for use in querying each item in the history stack. 1365 * This is a copy of the private WebBackForwardList so it contains only a 1366 * snapshot of the current state. Multiple calls to this method may return 1367 * different objects. The object returned from this method will not be 1368 * updated to reflect any new state. 1369 */ 1370 public WebBackForwardList copyBackForwardList() { 1371 checkThread(); 1372 return mProvider.copyBackForwardList(); 1373 1374 } 1375 1376 /** 1377 * Registers the listener to be notified as find-on-page operations 1378 * progress. This will replace the current listener. 1379 * 1380 * @param listener an implementation of {@link FindListener} 1381 */ 1382 public void setFindListener(FindListener listener) { 1383 checkThread(); 1384 setupFindListenerIfNeeded(); 1385 mFindListener.mUserFindListener = listener; 1386 } 1387 1388 /** 1389 * Highlights and scrolls to the next match found by 1390 * {@link #findAllAsync}, wrapping around page boundaries as necessary. 1391 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)} 1392 * has not been called yet, or if {@link #clearMatches} has been called since the 1393 * last find operation, this function does nothing. 1394 * 1395 * @param forward the direction to search 1396 * @see #setFindListener 1397 */ 1398 public void findNext(boolean forward) { 1399 checkThread(); 1400 mProvider.findNext(forward); 1401 } 1402 1403 /** 1404 * Finds all instances of find on the page and highlights them. 1405 * Notifies any registered {@link FindListener}. 1406 * 1407 * @param find the string to find 1408 * @return the number of occurances of the String "find" that were found 1409 * @deprecated {@link #findAllAsync} is preferred. 1410 * @see #setFindListener 1411 */ 1412 @Deprecated 1413 public int findAll(String find) { 1414 checkThread(); 1415 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync"); 1416 return mProvider.findAll(find); 1417 } 1418 1419 /** 1420 * Finds all instances of find on the page and highlights them, 1421 * asynchronously. Notifies any registered {@link FindListener}. 1422 * Successive calls to this will cancel any pending searches. 1423 * 1424 * @param find the string to find. 1425 * @see #setFindListener 1426 */ 1427 public void findAllAsync(String find) { 1428 checkThread(); 1429 mProvider.findAllAsync(find); 1430 } 1431 1432 /** 1433 * Starts an ActionMode for finding text in this WebView. Only works if this 1434 * WebView is attached to the view system. 1435 * 1436 * @param text if non-null, will be the initial text to search for. 1437 * Otherwise, the last String searched for in this WebView will 1438 * be used to start. 1439 * @param showIme if true, show the IME, assuming the user will begin typing. 1440 * If false and text is non-null, perform a find all. 1441 * @return true if the find dialog is shown, false otherwise 1442 * @deprecated This method does not work reliably on all Android versions; 1443 * implementing a custom find dialog using WebView.findAllAsync() 1444 * provides a more robust solution. 1445 */ 1446 @Deprecated 1447 public boolean showFindDialog(String text, boolean showIme) { 1448 checkThread(); 1449 return mProvider.showFindDialog(text, showIme); 1450 } 1451 1452 /** 1453 * Gets the first substring consisting of the address of a physical 1454 * location. Currently, only addresses in the United States are detected, 1455 * and consist of: 1456 * <ul> 1457 * <li>a house number</li> 1458 * <li>a street name</li> 1459 * <li>a street type (Road, Circle, etc), either spelled out or 1460 * abbreviated</li> 1461 * <li>a city name</li> 1462 * <li>a state or territory, either spelled out or two-letter abbr</li> 1463 * <li>an optional 5 digit or 9 digit zip code</li> 1464 * </ul> 1465 * All names must be correctly capitalized, and the zip code, if present, 1466 * must be valid for the state. The street type must be a standard USPS 1467 * spelling or abbreviation. The state or territory must also be spelled 1468 * or abbreviated using USPS standards. The house number may not exceed 1469 * five digits. 1470 * 1471 * @param addr the string to search for addresses 1472 * @return the address, or if no address is found, null 1473 */ 1474 public static String findAddress(String addr) { 1475 return getFactory().getStatics().findAddress(addr); 1476 } 1477 1478 /** 1479 * Clears the highlighting surrounding text matches created by 1480 * {@link #findAllAsync}. 1481 */ 1482 public void clearMatches() { 1483 checkThread(); 1484 mProvider.clearMatches(); 1485 } 1486 1487 /** 1488 * Queries the document to see if it contains any image references. The 1489 * message object will be dispatched with arg1 being set to 1 if images 1490 * were found and 0 if the document does not reference any images. 1491 * 1492 * @param response the message that will be dispatched with the result 1493 */ 1494 public void documentHasImages(Message response) { 1495 checkThread(); 1496 mProvider.documentHasImages(response); 1497 } 1498 1499 /** 1500 * Sets the WebViewClient that will receive various notifications and 1501 * requests. This will replace the current handler. 1502 * 1503 * @param client an implementation of WebViewClient 1504 */ 1505 public void setWebViewClient(WebViewClient client) { 1506 checkThread(); 1507 mProvider.setWebViewClient(client); 1508 } 1509 1510 /** 1511 * Registers the interface to be used when content can not be handled by 1512 * the rendering engine, and should be downloaded instead. This will replace 1513 * the current handler. 1514 * 1515 * @param listener an implementation of DownloadListener 1516 */ 1517 public void setDownloadListener(DownloadListener listener) { 1518 checkThread(); 1519 mProvider.setDownloadListener(listener); 1520 } 1521 1522 /** 1523 * Sets the chrome handler. This is an implementation of WebChromeClient for 1524 * use in handling JavaScript dialogs, favicons, titles, and the progress. 1525 * This will replace the current handler. 1526 * 1527 * @param client an implementation of WebChromeClient 1528 */ 1529 public void setWebChromeClient(WebChromeClient client) { 1530 checkThread(); 1531 mProvider.setWebChromeClient(client); 1532 } 1533 1534 /** 1535 * Sets the Picture listener. This is an interface used to receive 1536 * notifications of a new Picture. 1537 * 1538 * @param listener an implementation of WebView.PictureListener 1539 * @deprecated This method is now obsolete. 1540 */ 1541 @Deprecated 1542 public void setPictureListener(PictureListener listener) { 1543 checkThread(); 1544 mProvider.setPictureListener(listener); 1545 } 1546 1547 /** 1548 * Injects the supplied Java object into this WebView. The object is 1549 * injected into the JavaScript context of the main frame, using the 1550 * supplied name. This allows the Java object's methods to be 1551 * accessed from JavaScript. For applications targeted to API 1552 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 1553 * and above, only public methods that are annotated with 1554 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript. 1555 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, 1556 * all public methods (including the inherited ones) can be accessed, see the 1557 * important security note below for implications. 1558 * <p> Note that injected objects will not 1559 * appear in JavaScript until the page is next (re)loaded. For example: 1560 * <pre> 1561 * class JsObject { 1562 * {@literal @}JavascriptInterface 1563 * public String toString() { return "injectedObject"; } 1564 * } 1565 * webView.addJavascriptInterface(new JsObject(), "injectedObject"); 1566 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null); 1567 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre> 1568 * <p> 1569 * <strong>IMPORTANT:</strong> 1570 * <ul> 1571 * <li> This method can be used to allow JavaScript to control the host 1572 * application. This is a powerful feature, but also presents a security 1573 * risk for applications targeted to API level 1574 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because 1575 * JavaScript could use reflection to access an 1576 * injected object's public fields. Use of this method in a WebView 1577 * containing untrusted content could allow an attacker to manipulate the 1578 * host application in unintended ways, executing Java code with the 1579 * permissions of the host application. Use extreme care when using this 1580 * method in a WebView which could contain untrusted content.</li> 1581 * <li> JavaScript interacts with Java object on a private, background 1582 * thread of this WebView. Care is therefore required to maintain thread 1583 * safety.</li> 1584 * <li> The Java object's fields are not accessible.</li> 1585 * </ul> 1586 * 1587 * @param object the Java object to inject into this WebView's JavaScript 1588 * context. Null values are ignored. 1589 * @param name the name used to expose the object in JavaScript 1590 */ 1591 public void addJavascriptInterface(Object object, String name) { 1592 checkThread(); 1593 mProvider.addJavascriptInterface(object, name); 1594 } 1595 1596 /** 1597 * Removes a previously injected Java object from this WebView. Note that 1598 * the removal will not be reflected in JavaScript until the page is next 1599 * (re)loaded. See {@link #addJavascriptInterface}. 1600 * 1601 * @param name the name used to expose the object in JavaScript 1602 */ 1603 public void removeJavascriptInterface(String name) { 1604 checkThread(); 1605 mProvider.removeJavascriptInterface(name); 1606 } 1607 1608 /** 1609 * Gets the WebSettings object used to control the settings for this 1610 * WebView. 1611 * 1612 * @return a WebSettings object that can be used to control this WebView's 1613 * settings 1614 */ 1615 public WebSettings getSettings() { 1616 checkThread(); 1617 return mProvider.getSettings(); 1618 } 1619 1620 /** 1621 * Gets the list of currently loaded plugins. 1622 * 1623 * @return the list of currently loaded plugins 1624 * @deprecated This was used for Gears, which has been deprecated. 1625 * @hide 1626 */ 1627 @Deprecated 1628 public static synchronized PluginList getPluginList() { 1629 checkThread(); 1630 return new PluginList(); 1631 } 1632 1633 /** 1634 * @deprecated This was used for Gears, which has been deprecated. 1635 * @hide 1636 */ 1637 @Deprecated 1638 public void refreshPlugins(boolean reloadOpenPages) { 1639 checkThread(); 1640 } 1641 1642 /** 1643 * Puts this WebView into text selection mode. Do not rely on this 1644 * functionality; it will be deprecated in the future. 1645 * 1646 * @deprecated This method is now obsolete. 1647 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 1648 */ 1649 @Deprecated 1650 public void emulateShiftHeld() { 1651 checkThread(); 1652 } 1653 1654 /** 1655 * @deprecated WebView no longer needs to implement 1656 * ViewGroup.OnHierarchyChangeListener. This method does nothing now. 1657 */ 1658 @Override 1659 // Cannot add @hide as this can always be accessed via the interface. 1660 @Deprecated 1661 public void onChildViewAdded(View parent, View child) {} 1662 1663 /** 1664 * @deprecated WebView no longer needs to implement 1665 * ViewGroup.OnHierarchyChangeListener. This method does nothing now. 1666 */ 1667 @Override 1668 // Cannot add @hide as this can always be accessed via the interface. 1669 @Deprecated 1670 public void onChildViewRemoved(View p, View child) {} 1671 1672 /** 1673 * @deprecated WebView should not have implemented 1674 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now. 1675 */ 1676 @Override 1677 // Cannot add @hide as this can always be accessed via the interface. 1678 @Deprecated 1679 public void onGlobalFocusChanged(View oldFocus, View newFocus) { 1680 } 1681 1682 /** 1683 * @deprecated Only the default case, true, will be supported in a future version. 1684 */ 1685 @Deprecated 1686 public void setMapTrackballToArrowKeys(boolean setMap) { 1687 checkThread(); 1688 mProvider.setMapTrackballToArrowKeys(setMap); 1689 } 1690 1691 1692 public void flingScroll(int vx, int vy) { 1693 checkThread(); 1694 mProvider.flingScroll(vx, vy); 1695 } 1696 1697 /** 1698 * Gets the zoom controls for this WebView, as a separate View. The caller 1699 * is responsible for inserting this View into the layout hierarchy. 1700 * <p/> 1701 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced 1702 * built-in zoom mechanisms for the WebView, as opposed to these separate 1703 * zoom controls. The built-in mechanisms are preferred and can be enabled 1704 * using {@link WebSettings#setBuiltInZoomControls}. 1705 * 1706 * @deprecated the built-in zoom mechanisms are preferred 1707 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} 1708 */ 1709 @Deprecated 1710 public View getZoomControls() { 1711 checkThread(); 1712 return mProvider.getZoomControls(); 1713 } 1714 1715 /** 1716 * Gets whether this WebView can be zoomed in. 1717 * 1718 * @return true if this WebView can be zoomed in 1719 * 1720 * @deprecated This method is prone to inaccuracy due to race conditions 1721 * between the web rendering and UI threads; prefer 1722 * {@link WebViewClient#onScaleChanged}. 1723 */ 1724 @Deprecated 1725 public boolean canZoomIn() { 1726 checkThread(); 1727 return mProvider.canZoomIn(); 1728 } 1729 1730 /** 1731 * Gets whether this WebView can be zoomed out. 1732 * 1733 * @return true if this WebView can be zoomed out 1734 * 1735 * @deprecated This method is prone to inaccuracy due to race conditions 1736 * between the web rendering and UI threads; prefer 1737 * {@link WebViewClient#onScaleChanged}. 1738 */ 1739 @Deprecated 1740 public boolean canZoomOut() { 1741 checkThread(); 1742 return mProvider.canZoomOut(); 1743 } 1744 1745 /** 1746 * Performs zoom in in this WebView. 1747 * 1748 * @return true if zoom in succeeds, false if no zoom changes 1749 */ 1750 public boolean zoomIn() { 1751 checkThread(); 1752 return mProvider.zoomIn(); 1753 } 1754 1755 /** 1756 * Performs zoom out in this WebView. 1757 * 1758 * @return true if zoom out succeeds, false if no zoom changes 1759 */ 1760 public boolean zoomOut() { 1761 checkThread(); 1762 return mProvider.zoomOut(); 1763 } 1764 1765 /** 1766 * @deprecated This method is now obsolete. 1767 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} 1768 */ 1769 @Deprecated 1770 public void debugDump() { 1771 checkThread(); 1772 } 1773 1774 /** 1775 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)} 1776 * @hide 1777 */ 1778 @Override 1779 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) { 1780 mProvider.dumpViewHierarchyWithProperties(out, level); 1781 } 1782 1783 /** 1784 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)} 1785 * @hide 1786 */ 1787 @Override 1788 public View findHierarchyView(String className, int hashCode) { 1789 return mProvider.findHierarchyView(className, hashCode); 1790 } 1791 1792 //------------------------------------------------------------------------- 1793 // Interface for WebView providers 1794 //------------------------------------------------------------------------- 1795 1796 /** 1797 * Gets the WebViewProvider. Used by providers to obtain the underlying 1798 * implementation, e.g. when the appliction responds to 1799 * WebViewClient.onCreateWindow() request. 1800 * 1801 * @hide WebViewProvider is not public API. 1802 */ 1803 public WebViewProvider getWebViewProvider() { 1804 return mProvider; 1805 } 1806 1807 /** 1808 * Callback interface, allows the provider implementation to access non-public methods 1809 * and fields, and make super-class calls in this WebView instance. 1810 * @hide Only for use by WebViewProvider implementations 1811 */ 1812 public class PrivateAccess { 1813 // ---- Access to super-class methods ---- 1814 public int super_getScrollBarStyle() { 1815 return WebView.super.getScrollBarStyle(); 1816 } 1817 1818 public void super_scrollTo(int scrollX, int scrollY) { 1819 WebView.super.scrollTo(scrollX, scrollY); 1820 } 1821 1822 public void super_computeScroll() { 1823 WebView.super.computeScroll(); 1824 } 1825 1826 public boolean super_onHoverEvent(MotionEvent event) { 1827 return WebView.super.onHoverEvent(event); 1828 } 1829 1830 public boolean super_performAccessibilityAction(int action, Bundle arguments) { 1831 return WebView.super.performAccessibilityAction(action, arguments); 1832 } 1833 1834 public boolean super_performLongClick() { 1835 return WebView.super.performLongClick(); 1836 } 1837 1838 public boolean super_setFrame(int left, int top, int right, int bottom) { 1839 return WebView.super.setFrame(left, top, right, bottom); 1840 } 1841 1842 public boolean super_dispatchKeyEvent(KeyEvent event) { 1843 return WebView.super.dispatchKeyEvent(event); 1844 } 1845 1846 public boolean super_onGenericMotionEvent(MotionEvent event) { 1847 return WebView.super.onGenericMotionEvent(event); 1848 } 1849 1850 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) { 1851 return WebView.super.requestFocus(direction, previouslyFocusedRect); 1852 } 1853 1854 public void super_setLayoutParams(ViewGroup.LayoutParams params) { 1855 WebView.super.setLayoutParams(params); 1856 } 1857 1858 // ---- Access to non-public methods ---- 1859 public void overScrollBy(int deltaX, int deltaY, 1860 int scrollX, int scrollY, 1861 int scrollRangeX, int scrollRangeY, 1862 int maxOverScrollX, int maxOverScrollY, 1863 boolean isTouchEvent) { 1864 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, 1865 maxOverScrollX, maxOverScrollY, isTouchEvent); 1866 } 1867 1868 public void awakenScrollBars(int duration) { 1869 WebView.this.awakenScrollBars(duration); 1870 } 1871 1872 public void awakenScrollBars(int duration, boolean invalidate) { 1873 WebView.this.awakenScrollBars(duration, invalidate); 1874 } 1875 1876 public float getVerticalScrollFactor() { 1877 return WebView.this.getVerticalScrollFactor(); 1878 } 1879 1880 public float getHorizontalScrollFactor() { 1881 return WebView.this.getHorizontalScrollFactor(); 1882 } 1883 1884 public void setMeasuredDimension(int measuredWidth, int measuredHeight) { 1885 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight); 1886 } 1887 1888 public void onScrollChanged(int l, int t, int oldl, int oldt) { 1889 WebView.this.onScrollChanged(l, t, oldl, oldt); 1890 } 1891 1892 public int getHorizontalScrollbarHeight() { 1893 return WebView.this.getHorizontalScrollbarHeight(); 1894 } 1895 1896 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, 1897 int l, int t, int r, int b) { 1898 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b); 1899 } 1900 1901 // ---- Access to (non-public) fields ---- 1902 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */ 1903 public void setScrollXRaw(int scrollX) { 1904 WebView.this.mScrollX = scrollX; 1905 } 1906 1907 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */ 1908 public void setScrollYRaw(int scrollY) { 1909 WebView.this.mScrollY = scrollY; 1910 } 1911 1912 } 1913 1914 //------------------------------------------------------------------------- 1915 // Package-private internal stuff 1916 //------------------------------------------------------------------------- 1917 1918 // Only used by android.webkit.FindActionModeCallback. 1919 void setFindDialogFindListener(FindListener listener) { 1920 checkThread(); 1921 setupFindListenerIfNeeded(); 1922 mFindListener.mFindDialogFindListener = listener; 1923 } 1924 1925 // Only used by android.webkit.FindActionModeCallback. 1926 void notifyFindDialogDismissed() { 1927 checkThread(); 1928 mProvider.notifyFindDialogDismissed(); 1929 } 1930 1931 //------------------------------------------------------------------------- 1932 // Private internal stuff 1933 //------------------------------------------------------------------------- 1934 1935 private WebViewProvider mProvider; 1936 1937 /** 1938 * In addition to the FindListener that the user may set via the WebView.setFindListener 1939 * API, FindActionModeCallback will register it's own FindListener. We keep them separate 1940 * via this class so that that the two FindListeners can potentially exist at once. 1941 */ 1942 private class FindListenerDistributor implements FindListener { 1943 private FindListener mFindDialogFindListener; 1944 private FindListener mUserFindListener; 1945 1946 @Override 1947 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, 1948 boolean isDoneCounting) { 1949 if (mFindDialogFindListener != null) { 1950 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, 1951 isDoneCounting); 1952 } 1953 1954 if (mUserFindListener != null) { 1955 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, 1956 isDoneCounting); 1957 } 1958 } 1959 } 1960 private FindListenerDistributor mFindListener; 1961 1962 private void setupFindListenerIfNeeded() { 1963 if (mFindListener == null) { 1964 mFindListener = new FindListenerDistributor(); 1965 mProvider.setFindListener(mFindListener); 1966 } 1967 } 1968 1969 private void ensureProviderCreated() { 1970 checkThread(); 1971 if (mProvider == null) { 1972 // As this can get called during the base class constructor chain, pass the minimum 1973 // number of dependencies here; the rest are deferred to init(). 1974 mProvider = getFactory().createWebView(this, new PrivateAccess()); 1975 } 1976 } 1977 1978 private static synchronized WebViewFactoryProvider getFactory() { 1979 return WebViewFactory.getProvider(); 1980 } 1981 1982 private static void checkThread() { 1983 if (Looper.myLooper() != Looper.getMainLooper()) { 1984 Throwable throwable = new Throwable( 1985 "Warning: A WebView method was called on thread '" + 1986 Thread.currentThread().getName() + "'. " + 1987 "All WebView methods must be called on the UI thread. " + 1988 "Future versions of WebView may not support use on other threads."); 1989 Log.w(LOGTAG, Log.getStackTraceString(throwable)); 1990 StrictMode.onWebViewMethodCalledOnWrongThread(throwable); 1991 1992 if (sEnforceThreadChecking) { 1993 throw new RuntimeException(throwable); 1994 } 1995 } 1996 } 1997 1998 //------------------------------------------------------------------------- 1999 // Override View methods 2000 //------------------------------------------------------------------------- 2001 2002 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures 2003 // there's a corresponding override (or better, caller) for each of them in here. 2004 2005 @Override 2006 protected void onAttachedToWindow() { 2007 super.onAttachedToWindow(); 2008 mProvider.getViewDelegate().onAttachedToWindow(); 2009 } 2010 2011 @Override 2012 protected void onDetachedFromWindow() { 2013 mProvider.getViewDelegate().onDetachedFromWindow(); 2014 super.onDetachedFromWindow(); 2015 } 2016 2017 @Override 2018 public void setLayoutParams(ViewGroup.LayoutParams params) { 2019 mProvider.getViewDelegate().setLayoutParams(params); 2020 } 2021 2022 @Override 2023 public void setOverScrollMode(int mode) { 2024 super.setOverScrollMode(mode); 2025 // This method may be called in the constructor chain, before the WebView provider is 2026 // created. 2027 ensureProviderCreated(); 2028 mProvider.getViewDelegate().setOverScrollMode(mode); 2029 } 2030 2031 @Override 2032 public void setScrollBarStyle(int style) { 2033 mProvider.getViewDelegate().setScrollBarStyle(style); 2034 super.setScrollBarStyle(style); 2035 } 2036 2037 @Override 2038 protected int computeHorizontalScrollRange() { 2039 return mProvider.getScrollDelegate().computeHorizontalScrollRange(); 2040 } 2041 2042 @Override 2043 protected int computeHorizontalScrollOffset() { 2044 return mProvider.getScrollDelegate().computeHorizontalScrollOffset(); 2045 } 2046 2047 @Override 2048 protected int computeVerticalScrollRange() { 2049 return mProvider.getScrollDelegate().computeVerticalScrollRange(); 2050 } 2051 2052 @Override 2053 protected int computeVerticalScrollOffset() { 2054 return mProvider.getScrollDelegate().computeVerticalScrollOffset(); 2055 } 2056 2057 @Override 2058 protected int computeVerticalScrollExtent() { 2059 return mProvider.getScrollDelegate().computeVerticalScrollExtent(); 2060 } 2061 2062 @Override 2063 public void computeScroll() { 2064 mProvider.getScrollDelegate().computeScroll(); 2065 } 2066 2067 @Override 2068 public boolean onHoverEvent(MotionEvent event) { 2069 return mProvider.getViewDelegate().onHoverEvent(event); 2070 } 2071 2072 @Override 2073 public boolean onTouchEvent(MotionEvent event) { 2074 return mProvider.getViewDelegate().onTouchEvent(event); 2075 } 2076 2077 @Override 2078 public boolean onGenericMotionEvent(MotionEvent event) { 2079 return mProvider.getViewDelegate().onGenericMotionEvent(event); 2080 } 2081 2082 @Override 2083 public boolean onTrackballEvent(MotionEvent event) { 2084 return mProvider.getViewDelegate().onTrackballEvent(event); 2085 } 2086 2087 @Override 2088 public boolean onKeyDown(int keyCode, KeyEvent event) { 2089 return mProvider.getViewDelegate().onKeyDown(keyCode, event); 2090 } 2091 2092 @Override 2093 public boolean onKeyUp(int keyCode, KeyEvent event) { 2094 return mProvider.getViewDelegate().onKeyUp(keyCode, event); 2095 } 2096 2097 @Override 2098 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { 2099 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event); 2100 } 2101 2102 /* 2103 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not 2104 to be delegating them too. 2105 2106 @Override 2107 public boolean onKeyPreIme(int keyCode, KeyEvent event) { 2108 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event); 2109 } 2110 @Override 2111 public boolean onKeyLongPress(int keyCode, KeyEvent event) { 2112 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event); 2113 } 2114 @Override 2115 public boolean onKeyShortcut(int keyCode, KeyEvent event) { 2116 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event); 2117 } 2118 */ 2119 2120 @Override 2121 public AccessibilityNodeProvider getAccessibilityNodeProvider() { 2122 AccessibilityNodeProvider provider = 2123 mProvider.getViewDelegate().getAccessibilityNodeProvider(); 2124 return provider == null ? super.getAccessibilityNodeProvider() : provider; 2125 } 2126 2127 @Deprecated 2128 @Override 2129 public boolean shouldDelayChildPressedState() { 2130 return mProvider.getViewDelegate().shouldDelayChildPressedState(); 2131 } 2132 2133 @Override 2134 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { 2135 super.onInitializeAccessibilityNodeInfo(info); 2136 info.setClassName(WebView.class.getName()); 2137 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info); 2138 } 2139 2140 @Override 2141 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 2142 super.onInitializeAccessibilityEvent(event); 2143 event.setClassName(WebView.class.getName()); 2144 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event); 2145 } 2146 2147 @Override 2148 public boolean performAccessibilityAction(int action, Bundle arguments) { 2149 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments); 2150 } 2151 2152 /** @hide */ 2153 @Override 2154 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, 2155 int l, int t, int r, int b) { 2156 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b); 2157 } 2158 2159 @Override 2160 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { 2161 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY); 2162 } 2163 2164 @Override 2165 protected void onWindowVisibilityChanged(int visibility) { 2166 super.onWindowVisibilityChanged(visibility); 2167 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility); 2168 } 2169 2170 @Override 2171 protected void onDraw(Canvas canvas) { 2172 mProvider.getViewDelegate().onDraw(canvas); 2173 } 2174 2175 @Override 2176 public boolean performLongClick() { 2177 return mProvider.getViewDelegate().performLongClick(); 2178 } 2179 2180 @Override 2181 protected void onConfigurationChanged(Configuration newConfig) { 2182 mProvider.getViewDelegate().onConfigurationChanged(newConfig); 2183 } 2184 2185 @Override 2186 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { 2187 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs); 2188 } 2189 2190 @Override 2191 protected void onVisibilityChanged(View changedView, int visibility) { 2192 super.onVisibilityChanged(changedView, visibility); 2193 // This method may be called in the constructor chain, before the WebView provider is 2194 // created. 2195 ensureProviderCreated(); 2196 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility); 2197 } 2198 2199 @Override 2200 public void onWindowFocusChanged(boolean hasWindowFocus) { 2201 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus); 2202 super.onWindowFocusChanged(hasWindowFocus); 2203 } 2204 2205 @Override 2206 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 2207 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect); 2208 super.onFocusChanged(focused, direction, previouslyFocusedRect); 2209 } 2210 2211 /** @hide */ 2212 @Override 2213 protected boolean setFrame(int left, int top, int right, int bottom) { 2214 return mProvider.getViewDelegate().setFrame(left, top, right, bottom); 2215 } 2216 2217 @Override 2218 protected void onSizeChanged(int w, int h, int ow, int oh) { 2219 super.onSizeChanged(w, h, ow, oh); 2220 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh); 2221 } 2222 2223 @Override 2224 protected void onScrollChanged(int l, int t, int oldl, int oldt) { 2225 super.onScrollChanged(l, t, oldl, oldt); 2226 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt); 2227 } 2228 2229 @Override 2230 public boolean dispatchKeyEvent(KeyEvent event) { 2231 return mProvider.getViewDelegate().dispatchKeyEvent(event); 2232 } 2233 2234 @Override 2235 public boolean requestFocus(int direction, Rect previouslyFocusedRect) { 2236 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect); 2237 } 2238 2239 @Override 2240 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 2241 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 2242 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec); 2243 } 2244 2245 @Override 2246 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { 2247 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate); 2248 } 2249 2250 @Override 2251 public void setBackgroundColor(int color) { 2252 mProvider.getViewDelegate().setBackgroundColor(color); 2253 } 2254 2255 @Override 2256 public void setLayerType(int layerType, Paint paint) { 2257 super.setLayerType(layerType, paint); 2258 mProvider.getViewDelegate().setLayerType(layerType, paint); 2259 } 2260 2261 @Override 2262 protected void dispatchDraw(Canvas canvas) { 2263 mProvider.getViewDelegate().preDispatchDraw(canvas); 2264 super.dispatchDraw(canvas); 2265 } 2266} 2267