• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.webkit;
18 
19 import android.annotation.Widget;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.graphics.Bitmap;
23 import android.graphics.Canvas;
24 import android.graphics.Paint;
25 import android.graphics.Picture;
26 import android.graphics.Rect;
27 import android.graphics.drawable.Drawable;
28 import android.net.http.SslCertificate;
29 import android.os.Bundle;
30 import android.os.Looper;
31 import android.os.Message;
32 import android.os.StrictMode;
33 import android.util.AttributeSet;
34 import android.util.Log;
35 import android.view.KeyEvent;
36 import android.view.MotionEvent;
37 import android.view.View;
38 import android.view.ViewDebug;
39 import android.view.ViewGroup;
40 import android.view.ViewTreeObserver;
41 import android.view.accessibility.AccessibilityEvent;
42 import android.view.accessibility.AccessibilityNodeInfo;
43 import android.view.inputmethod.EditorInfo;
44 import android.view.inputmethod.InputConnection;
45 import android.widget.AbsoluteLayout;
46 
47 import java.io.BufferedWriter;
48 import java.io.File;
49 import 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>&lt;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 = "&lt;html>&lt;body>You scored &lt;b>192&lt;/b> points.&lt;/body>&lt;/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.&mdash;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 &mdash; sometimes significantly more &mdash; 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  * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</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>&lt;meta name="viewport" content="target-densitydpi=device-dpi" /&gt;</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
262 public 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          */
setWebView(WebView webview)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          */
getWebView()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          */
onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting)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
onNewPicture(WebView view, Picture picture)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          */
HitTestResult()394         public HitTestResult() {
395             mType = UNKNOWN_TYPE;
396         }
397 
398         /**
399          * @hide Only for use by WebViewProvider implementations
400          */
setType(int type)401         public void setType(int type) {
402             mType = type;
403         }
404 
405         /**
406          * @hide Only for use by WebViewProvider implementations
407          */
setExtra(String extra)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          */
getType()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          */
getExtra()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      */
WebView(Context context)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      */
WebView(Context context, AttributeSet attrs)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      */
WebView(Context context, AttributeSet attrs, int defStyle)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
WebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing)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.
WebView(Context context, AttributeSet attrs, int defStyle, Map<String, Object> javaScriptInterfaces, boolean privateBrowsing)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      */
setHorizontalScrollbarOverlay(boolean overlay)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      */
setVerticalScrollbarOverlay(boolean overlay)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      */
overlayHorizontalScrollbar()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      */
overlayVerticalScrollbar()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      */
getVisibleTitleHeight()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      */
getCertificate()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
setCertificate(SslCertificate certificate)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      */
savePassword(String host, String username, String password)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      */
setHttpAuthUsernamePassword(String host, String realm, String username, String password)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      */
getHttpAuthUsernamePassword(String host, String realm)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      */
destroy()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
enablePlatformNotifications()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
disablePlatformNotifications()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      */
setNetworkAvailable(boolean networkUp)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      */
saveState(Bundle outState)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
savePicture(Bundle b, final File dest)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
restorePicture(Bundle b, File src)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      */
restoreState(Bundle inState)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      */
loadUrl(String url, Map<String, String> additionalHttpHeaders)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      */
loadUrl(String url)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      */
postUrl(String url, byte[] postData)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      */
loadData(String data, String mimeType, String encoding)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      */
loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)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      */
saveWebArchive(String filename)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      */
saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback)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      */
stopLoading()893     public void stopLoading() {
894         checkThread();
895         mProvider.stopLoading();
896     }
897 
898     /**
899      * Reloads the current URL.
900      */
reload()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      */
canGoBack()911     public boolean canGoBack() {
912         checkThread();
913         return mProvider.canGoBack();
914     }
915 
916     /**
917      * Goes back in the history of this WebView.
918      */
goBack()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      */
canGoForward()929     public boolean canGoForward() {
930         checkThread();
931         return mProvider.canGoForward();
932     }
933 
934     /**
935      * Goes forward in the history of this WebView.
936      */
goForward()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      */
canGoBackOrForward(int steps)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      */
goBackOrForward(int steps)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      */
isPrivateBrowsingEnabled()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      */
pageUp(boolean top)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      */
pageDown(boolean bottom)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      */
clearView()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      */
capturePicture()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")
getScale()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      */
setInitialScale(int scaleInPercent)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      */
invokeZoomPicker()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      */
getHitTestResult()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      */
requestFocusNodeHref(Message hrefMsg)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      */
requestImageRef(Message msg)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")
getUrl()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")
getOriginalUrl()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")
getTitle()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      */
getFavicon()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      */
getTouchIconUrl()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      */
getProgress()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")
getContentHeight()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")
getContentWidth()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      */
pauseTimers()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      */
resumeTimers()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      */
onPause()1239     public void onPause() {
1240         checkThread();
1241         mProvider.onPause();
1242     }
1243 
1244     /**
1245      * Resumes a WebView after a previous call to onPause().
1246      */
onResume()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      */
isPaused()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      */
freeMemory()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      */
clearCache(boolean includeDiskFiles)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      */
clearFormData()1288     public void clearFormData() {
1289         checkThread();
1290         mProvider.clearFormData();
1291     }
1292 
1293     /**
1294      * Tells this WebView to clear its internal back/forward list.
1295      */
clearHistory()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      */
clearSslPreferences()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      */
copyBackForwardList()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      */
setFindListener(FindListener listener)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      */
findNext(boolean forward)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
findAll(String find)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      */
findAllAsync(String find)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      */
showFindDialog(String text, boolean showIme)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      */
findAddress(String addr)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      */
clearMatches()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      */
documentHasImages(Message response)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      */
setWebViewClient(WebViewClient client)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      */
setDownloadListener(DownloadListener listener)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      */
setWebChromeClient(WebChromeClient client)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      */
1484     @Deprecated
setPictureListener(PictureListener listener)1485     public void setPictureListener(PictureListener listener) {
1486         checkThread();
1487         mProvider.setPictureListener(listener);
1488     }
1489 
1490     /**
1491      * Injects the supplied Java object into this WebView. The object is
1492      * injected into the JavaScript context of the main frame, using the
1493      * supplied name. This allows the Java object's methods to be
1494      * accessed from JavaScript. For applications targeted to API
1495      * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1496      * and above, only public methods that are annotated with
1497      * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
1498      * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
1499      * all public methods (including the inherited ones) can be accessed, see the
1500      * important security note below for implications.
1501      * <p> Note that injected objects will not
1502      * appear in JavaScript until the page is next (re)loaded. For example:
1503      * <pre>
1504      * class JsObject {
1505      *    {@literal @}JavascriptInterface
1506      *    public String toString() { return "injectedObject"; }
1507      * }
1508      * webView.addJavascriptInterface(new JsObject(), "injectedObject");
1509      * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1510      * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
1511      * <p>
1512      * <strong>IMPORTANT:</strong>
1513      * <ul>
1514      * <li> This method can be used to allow JavaScript to control the host
1515      * application. This is a powerful feature, but also presents a security
1516      * risk for applications targeted to API level
1517      * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because
1518      * JavaScript could use reflection to access an
1519      * injected object's public fields. Use of this method in a WebView
1520      * containing untrusted content could allow an attacker to manipulate the
1521      * host application in unintended ways, executing Java code with the
1522      * permissions of the host application. Use extreme care when using this
1523      * method in a WebView which could contain untrusted content.</li>
1524      * <li> JavaScript interacts with Java object on a private, background
1525      * thread of this WebView. Care is therefore required to maintain thread
1526      * safety.</li>
1527      * <li> The Java object's fields are not accessible.</li>
1528      * </ul>
1529      *
1530      * @param object the Java object to inject into this WebView's JavaScript
1531      *               context. Null values are ignored.
1532      * @param name the name used to expose the object in JavaScript
1533      */
addJavascriptInterface(Object object, String name)1534     public void addJavascriptInterface(Object object, String name) {
1535         checkThread();
1536         mProvider.addJavascriptInterface(object, name);
1537     }
1538 
1539     /**
1540      * Removes a previously injected Java object from this WebView. Note that
1541      * the removal will not be reflected in JavaScript until the page is next
1542      * (re)loaded. See {@link #addJavascriptInterface}.
1543      *
1544      * @param name the name used to expose the object in JavaScript
1545      */
removeJavascriptInterface(String name)1546     public void removeJavascriptInterface(String name) {
1547         checkThread();
1548         mProvider.removeJavascriptInterface(name);
1549     }
1550 
1551     /**
1552      * Gets the WebSettings object used to control the settings for this
1553      * WebView.
1554      *
1555      * @return a WebSettings object that can be used to control this WebView's
1556      *         settings
1557      */
getSettings()1558     public WebSettings getSettings() {
1559         checkThread();
1560         return mProvider.getSettings();
1561     }
1562 
1563     /**
1564      * Gets the list of currently loaded plugins.
1565      *
1566      * @return the list of currently loaded plugins
1567      * @deprecated This was used for Gears, which has been deprecated.
1568      * @hide
1569      */
1570     @Deprecated
getPluginList()1571     public static synchronized PluginList getPluginList() {
1572         checkThread();
1573         return new PluginList();
1574     }
1575 
1576     /**
1577      * @deprecated This was used for Gears, which has been deprecated.
1578      * @hide
1579      */
1580     @Deprecated
refreshPlugins(boolean reloadOpenPages)1581     public void refreshPlugins(boolean reloadOpenPages) {
1582         checkThread();
1583     }
1584 
1585     /**
1586      * Puts this WebView into text selection mode. Do not rely on this
1587      * functionality; it will be deprecated in the future.
1588      *
1589      * @deprecated This method is now obsolete.
1590      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1591      */
1592     @Deprecated
emulateShiftHeld()1593     public void emulateShiftHeld() {
1594         checkThread();
1595     }
1596 
1597     /**
1598      * @deprecated WebView no longer needs to implement
1599      * ViewGroup.OnHierarchyChangeListener.  This method does nothing now.
1600      */
1601     @Override
1602     // Cannot add @hide as this can always be accessed via the interface.
1603     @Deprecated
onChildViewAdded(View parent, View child)1604     public void onChildViewAdded(View parent, View child) {}
1605 
1606     /**
1607      * @deprecated WebView no longer needs to implement
1608      * ViewGroup.OnHierarchyChangeListener.  This method does nothing now.
1609      */
1610     @Override
1611     // Cannot add @hide as this can always be accessed via the interface.
1612     @Deprecated
onChildViewRemoved(View p, View child)1613     public void onChildViewRemoved(View p, View child) {}
1614 
1615     /**
1616      * @deprecated WebView should not have implemented
1617      * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
1618      */
1619     @Override
1620     // Cannot add @hide as this can always be accessed via the interface.
1621     @Deprecated
onGlobalFocusChanged(View oldFocus, View newFocus)1622     public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1623     }
1624 
1625     /**
1626      * @deprecated Only the default case, true, will be supported in a future version.
1627      */
1628     @Deprecated
setMapTrackballToArrowKeys(boolean setMap)1629     public void setMapTrackballToArrowKeys(boolean setMap) {
1630         checkThread();
1631         mProvider.setMapTrackballToArrowKeys(setMap);
1632     }
1633 
1634 
flingScroll(int vx, int vy)1635     public void flingScroll(int vx, int vy) {
1636         checkThread();
1637         mProvider.flingScroll(vx, vy);
1638     }
1639 
1640     /**
1641      * Gets the zoom controls for this WebView, as a separate View. The caller
1642      * is responsible for inserting this View into the layout hierarchy.
1643      * <p/>
1644      * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
1645      * built-in zoom mechanisms for the WebView, as opposed to these separate
1646      * zoom controls. The built-in mechanisms are preferred and can be enabled
1647      * using {@link WebSettings#setBuiltInZoomControls}.
1648      *
1649      * @deprecated the built-in zoom mechanisms are preferred
1650      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1651      */
1652     @Deprecated
getZoomControls()1653     public View getZoomControls() {
1654         checkThread();
1655         return mProvider.getZoomControls();
1656     }
1657 
1658     /**
1659      * Gets whether this WebView can be zoomed in.
1660      *
1661      * @return true if this WebView can be zoomed in
1662      *
1663      * @deprecated This method is prone to inaccuracy due to race conditions
1664      * between the web rendering and UI threads; prefer
1665      * {@link WebViewClient#onScaleChanged}.
1666      */
1667     @Deprecated
canZoomIn()1668     public boolean canZoomIn() {
1669         checkThread();
1670         return mProvider.canZoomIn();
1671     }
1672 
1673     /**
1674      * Gets whether this WebView can be zoomed out.
1675      *
1676      * @return true if this WebView can be zoomed out
1677      *
1678      * @deprecated This method is prone to inaccuracy due to race conditions
1679      * between the web rendering and UI threads; prefer
1680      * {@link WebViewClient#onScaleChanged}.
1681      */
1682     @Deprecated
canZoomOut()1683     public boolean canZoomOut() {
1684         checkThread();
1685         return mProvider.canZoomOut();
1686     }
1687 
1688     /**
1689      * Performs zoom in in this WebView.
1690      *
1691      * @return true if zoom in succeeds, false if no zoom changes
1692      */
zoomIn()1693     public boolean zoomIn() {
1694         checkThread();
1695         return mProvider.zoomIn();
1696     }
1697 
1698     /**
1699      * Performs zoom out in this WebView.
1700      *
1701      * @return true if zoom out succeeds, false if no zoom changes
1702      */
zoomOut()1703     public boolean zoomOut() {
1704         checkThread();
1705         return mProvider.zoomOut();
1706     }
1707 
1708     /**
1709      * @deprecated This method is now obsolete.
1710      * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1711      */
1712     @Deprecated
debugDump()1713     public void debugDump() {
1714         checkThread();
1715     }
1716 
1717     /**
1718      * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
1719      * @hide
1720      */
1721     @Override
dumpViewHierarchyWithProperties(BufferedWriter out, int level)1722     public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
1723         mProvider.dumpViewHierarchyWithProperties(out, level);
1724     }
1725 
1726     /**
1727      * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
1728      * @hide
1729      */
1730     @Override
findHierarchyView(String className, int hashCode)1731     public View findHierarchyView(String className, int hashCode) {
1732         return mProvider.findHierarchyView(className, hashCode);
1733     }
1734 
1735     //-------------------------------------------------------------------------
1736     // Interface for WebView providers
1737     //-------------------------------------------------------------------------
1738 
1739     /**
1740      * Gets the WebViewProvider. Used by providers to obtain the underlying
1741      * implementation, e.g. when the appliction responds to
1742      * WebViewClient.onCreateWindow() request.
1743      *
1744      * @hide WebViewProvider is not public API.
1745      */
getWebViewProvider()1746     public WebViewProvider getWebViewProvider() {
1747         return mProvider;
1748     }
1749 
1750     /**
1751      * Callback interface, allows the provider implementation to access non-public methods
1752      * and fields, and make super-class calls in this WebView instance.
1753      * @hide Only for use by WebViewProvider implementations
1754      */
1755     public class PrivateAccess {
1756         // ---- Access to super-class methods ----
super_getScrollBarStyle()1757         public int super_getScrollBarStyle() {
1758             return WebView.super.getScrollBarStyle();
1759         }
1760 
super_scrollTo(int scrollX, int scrollY)1761         public void super_scrollTo(int scrollX, int scrollY) {
1762             WebView.super.scrollTo(scrollX, scrollY);
1763         }
1764 
super_computeScroll()1765         public void super_computeScroll() {
1766             WebView.super.computeScroll();
1767         }
1768 
super_onHoverEvent(MotionEvent event)1769         public boolean super_onHoverEvent(MotionEvent event) {
1770             return WebView.super.onHoverEvent(event);
1771         }
1772 
super_performAccessibilityAction(int action, Bundle arguments)1773         public boolean super_performAccessibilityAction(int action, Bundle arguments) {
1774             return WebView.super.performAccessibilityAction(action, arguments);
1775         }
1776 
super_performLongClick()1777         public boolean super_performLongClick() {
1778             return WebView.super.performLongClick();
1779         }
1780 
super_setFrame(int left, int top, int right, int bottom)1781         public boolean super_setFrame(int left, int top, int right, int bottom) {
1782             return WebView.super.setFrame(left, top, right, bottom);
1783         }
1784 
super_dispatchKeyEvent(KeyEvent event)1785         public boolean super_dispatchKeyEvent(KeyEvent event) {
1786             return WebView.super.dispatchKeyEvent(event);
1787         }
1788 
super_onGenericMotionEvent(MotionEvent event)1789         public boolean super_onGenericMotionEvent(MotionEvent event) {
1790             return WebView.super.onGenericMotionEvent(event);
1791         }
1792 
super_requestFocus(int direction, Rect previouslyFocusedRect)1793         public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
1794             return WebView.super.requestFocus(direction, previouslyFocusedRect);
1795         }
1796 
super_setLayoutParams(ViewGroup.LayoutParams params)1797         public void super_setLayoutParams(ViewGroup.LayoutParams params) {
1798             WebView.super.setLayoutParams(params);
1799         }
1800 
1801         // ---- Access to non-public methods ----
overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)1802         public void overScrollBy(int deltaX, int deltaY,
1803                 int scrollX, int scrollY,
1804                 int scrollRangeX, int scrollRangeY,
1805                 int maxOverScrollX, int maxOverScrollY,
1806                 boolean isTouchEvent) {
1807             WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
1808                     maxOverScrollX, maxOverScrollY, isTouchEvent);
1809         }
1810 
awakenScrollBars(int duration)1811         public void awakenScrollBars(int duration) {
1812             WebView.this.awakenScrollBars(duration);
1813         }
1814 
awakenScrollBars(int duration, boolean invalidate)1815         public void awakenScrollBars(int duration, boolean invalidate) {
1816             WebView.this.awakenScrollBars(duration, invalidate);
1817         }
1818 
getVerticalScrollFactor()1819         public float getVerticalScrollFactor() {
1820             return WebView.this.getVerticalScrollFactor();
1821         }
1822 
getHorizontalScrollFactor()1823         public float getHorizontalScrollFactor() {
1824             return WebView.this.getHorizontalScrollFactor();
1825         }
1826 
setMeasuredDimension(int measuredWidth, int measuredHeight)1827         public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
1828             WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
1829         }
1830 
onScrollChanged(int l, int t, int oldl, int oldt)1831         public void onScrollChanged(int l, int t, int oldl, int oldt) {
1832             WebView.this.onScrollChanged(l, t, oldl, oldt);
1833         }
1834 
getHorizontalScrollbarHeight()1835         public int getHorizontalScrollbarHeight() {
1836             return WebView.this.getHorizontalScrollbarHeight();
1837         }
1838 
1839         // ---- Access to (non-public) fields ----
1840         /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
setScrollXRaw(int scrollX)1841         public void setScrollXRaw(int scrollX) {
1842             WebView.this.mScrollX = scrollX;
1843         }
1844 
1845         /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
setScrollYRaw(int scrollY)1846         public void setScrollYRaw(int scrollY) {
1847             WebView.this.mScrollY = scrollY;
1848         }
1849 
1850     }
1851 
1852     //-------------------------------------------------------------------------
1853     // Private internal stuff
1854     //-------------------------------------------------------------------------
1855 
1856     private WebViewProvider mProvider;
1857 
ensureProviderCreated()1858     private void ensureProviderCreated() {
1859         checkThread();
1860         if (mProvider == null) {
1861             // As this can get called during the base class constructor chain, pass the minimum
1862             // number of dependencies here; the rest are deferred to init().
1863             mProvider = getFactory().createWebView(this, new PrivateAccess());
1864         }
1865     }
1866 
getFactory()1867     private static synchronized WebViewFactoryProvider getFactory() {
1868         // For now the main purpose of this function (and the factory abstration) is to keep
1869         // us honest and minimize usage of WebViewClassic internals when binding the proxy.
1870         checkThread();
1871         return WebViewFactory.getProvider();
1872     }
1873 
checkThread()1874     private static void checkThread() {
1875         if (Looper.myLooper() != Looper.getMainLooper()) {
1876             Throwable throwable = new Throwable(
1877                     "Warning: A WebView method was called on thread '" +
1878                     Thread.currentThread().getName() + "'. " +
1879                     "All WebView methods must be called on the UI thread. " +
1880                     "Future versions of WebView may not support use on other threads.");
1881             Log.w(LOGTAG, Log.getStackTraceString(throwable));
1882             StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
1883         }
1884     }
1885 
1886     //-------------------------------------------------------------------------
1887     // Override View methods
1888     //-------------------------------------------------------------------------
1889 
1890     // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
1891     // there's a corresponding override (or better, caller) for each of them in here.
1892 
1893     @Override
onAttachedToWindow()1894     protected void onAttachedToWindow() {
1895         super.onAttachedToWindow();
1896         mProvider.getViewDelegate().onAttachedToWindow();
1897     }
1898 
1899     @Override
onDetachedFromWindow()1900     protected void onDetachedFromWindow() {
1901         mProvider.getViewDelegate().onDetachedFromWindow();
1902         super.onDetachedFromWindow();
1903     }
1904 
1905     @Override
setLayoutParams(ViewGroup.LayoutParams params)1906     public void setLayoutParams(ViewGroup.LayoutParams params) {
1907         mProvider.getViewDelegate().setLayoutParams(params);
1908     }
1909 
1910     @Override
setOverScrollMode(int mode)1911     public void setOverScrollMode(int mode) {
1912         super.setOverScrollMode(mode);
1913         // This method may called in the constructor chain, before the WebView provider is
1914         // created. (Fortunately, this is the only method we override that can get called by
1915         // any of the base class constructors).
1916         ensureProviderCreated();
1917         mProvider.getViewDelegate().setOverScrollMode(mode);
1918     }
1919 
1920     @Override
setScrollBarStyle(int style)1921     public void setScrollBarStyle(int style) {
1922         mProvider.getViewDelegate().setScrollBarStyle(style);
1923         super.setScrollBarStyle(style);
1924     }
1925 
1926     @Override
computeHorizontalScrollRange()1927     protected int computeHorizontalScrollRange() {
1928         return mProvider.getScrollDelegate().computeHorizontalScrollRange();
1929     }
1930 
1931     @Override
computeHorizontalScrollOffset()1932     protected int computeHorizontalScrollOffset() {
1933         return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
1934     }
1935 
1936     @Override
computeVerticalScrollRange()1937     protected int computeVerticalScrollRange() {
1938         return mProvider.getScrollDelegate().computeVerticalScrollRange();
1939     }
1940 
1941     @Override
computeVerticalScrollOffset()1942     protected int computeVerticalScrollOffset() {
1943         return mProvider.getScrollDelegate().computeVerticalScrollOffset();
1944     }
1945 
1946     @Override
computeVerticalScrollExtent()1947     protected int computeVerticalScrollExtent() {
1948         return mProvider.getScrollDelegate().computeVerticalScrollExtent();
1949     }
1950 
1951     @Override
computeScroll()1952     public void computeScroll() {
1953         mProvider.getScrollDelegate().computeScroll();
1954     }
1955 
1956     @Override
onHoverEvent(MotionEvent event)1957     public boolean onHoverEvent(MotionEvent event) {
1958         return mProvider.getViewDelegate().onHoverEvent(event);
1959     }
1960 
1961     @Override
onTouchEvent(MotionEvent event)1962     public boolean onTouchEvent(MotionEvent event) {
1963         return mProvider.getViewDelegate().onTouchEvent(event);
1964     }
1965 
1966     @Override
onGenericMotionEvent(MotionEvent event)1967     public boolean onGenericMotionEvent(MotionEvent event) {
1968         return mProvider.getViewDelegate().onGenericMotionEvent(event);
1969     }
1970 
1971     @Override
onTrackballEvent(MotionEvent event)1972     public boolean onTrackballEvent(MotionEvent event) {
1973         return mProvider.getViewDelegate().onTrackballEvent(event);
1974     }
1975 
1976     @Override
onKeyDown(int keyCode, KeyEvent event)1977     public boolean onKeyDown(int keyCode, KeyEvent event) {
1978         return mProvider.getViewDelegate().onKeyDown(keyCode, event);
1979     }
1980 
1981     @Override
onKeyUp(int keyCode, KeyEvent event)1982     public boolean onKeyUp(int keyCode, KeyEvent event) {
1983         return mProvider.getViewDelegate().onKeyUp(keyCode, event);
1984     }
1985 
1986     @Override
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)1987     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
1988         return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
1989     }
1990 
1991     /*
1992     TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
1993     to be delegating them too.
1994 
1995     @Override
1996     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
1997         return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
1998     }
1999     @Override
2000     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2001         return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2002     }
2003     @Override
2004     public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2005         return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2006     }
2007     */
2008 
2009     @Deprecated
2010     @Override
shouldDelayChildPressedState()2011     public boolean shouldDelayChildPressedState() {
2012         return mProvider.getViewDelegate().shouldDelayChildPressedState();
2013     }
2014 
2015     @Override
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)2016     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
2017         super.onInitializeAccessibilityNodeInfo(info);
2018         info.setClassName(WebView.class.getName());
2019         mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
2020     }
2021 
2022     @Override
onInitializeAccessibilityEvent(AccessibilityEvent event)2023     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2024         super.onInitializeAccessibilityEvent(event);
2025         event.setClassName(WebView.class.getName());
2026         mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
2027     }
2028 
2029     @Override
performAccessibilityAction(int action, Bundle arguments)2030     public boolean performAccessibilityAction(int action, Bundle arguments) {
2031         return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
2032     }
2033 
2034     /** @hide */
2035     @Override
onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t, int r, int b)2036     protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2037             int l, int t, int r, int b) {
2038         mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2039     }
2040 
2041     @Override
onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY)2042     protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2043         mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2044     }
2045 
2046     @Override
onWindowVisibilityChanged(int visibility)2047     protected void onWindowVisibilityChanged(int visibility) {
2048         super.onWindowVisibilityChanged(visibility);
2049         mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2050     }
2051 
2052     @Override
onDraw(Canvas canvas)2053     protected void onDraw(Canvas canvas) {
2054         mProvider.getViewDelegate().onDraw(canvas);
2055     }
2056 
2057     @Override
performLongClick()2058     public boolean performLongClick() {
2059         return mProvider.getViewDelegate().performLongClick();
2060     }
2061 
2062     @Override
onConfigurationChanged(Configuration newConfig)2063     protected void onConfigurationChanged(Configuration newConfig) {
2064         mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2065     }
2066 
2067     @Override
onCreateInputConnection(EditorInfo outAttrs)2068     public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2069         return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2070     }
2071 
2072     @Override
onVisibilityChanged(View changedView, int visibility)2073     protected void onVisibilityChanged(View changedView, int visibility) {
2074         super.onVisibilityChanged(changedView, visibility);
2075         mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2076     }
2077 
2078     @Override
onWindowFocusChanged(boolean hasWindowFocus)2079     public void onWindowFocusChanged(boolean hasWindowFocus) {
2080         mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2081         super.onWindowFocusChanged(hasWindowFocus);
2082     }
2083 
2084     @Override
onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)2085     protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2086         mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2087         super.onFocusChanged(focused, direction, previouslyFocusedRect);
2088     }
2089 
2090     /** @hide */
2091     @Override
setFrame(int left, int top, int right, int bottom)2092     protected boolean setFrame(int left, int top, int right, int bottom) {
2093         return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2094     }
2095 
2096     @Override
onSizeChanged(int w, int h, int ow, int oh)2097     protected void onSizeChanged(int w, int h, int ow, int oh) {
2098         super.onSizeChanged(w, h, ow, oh);
2099         mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2100     }
2101 
2102     @Override
onScrollChanged(int l, int t, int oldl, int oldt)2103     protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2104         super.onScrollChanged(l, t, oldl, oldt);
2105         mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2106     }
2107 
2108     @Override
dispatchKeyEvent(KeyEvent event)2109     public boolean dispatchKeyEvent(KeyEvent event) {
2110         return mProvider.getViewDelegate().dispatchKeyEvent(event);
2111     }
2112 
2113     @Override
requestFocus(int direction, Rect previouslyFocusedRect)2114     public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2115         return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2116     }
2117 
2118     @Deprecated
2119     @Override
onMeasure(int widthMeasureSpec, int heightMeasureSpec)2120     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2121         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2122         mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2123     }
2124 
2125     @Override
requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)2126     public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2127         return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2128     }
2129 
2130     @Override
setBackgroundColor(int color)2131     public void setBackgroundColor(int color) {
2132         mProvider.getViewDelegate().setBackgroundColor(color);
2133     }
2134 
2135     @Override
setLayerType(int layerType, Paint paint)2136     public void setLayerType(int layerType, Paint paint) {
2137         super.setLayerType(layerType, paint);
2138         mProvider.getViewDelegate().setLayerType(layerType, paint);
2139     }
2140 }
2141