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