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