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