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