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