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