blob: 7146d0de85a70f0c958695445e57f12711372a34 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Raphael30df2372010-03-06 10:09:54 -080019import android.annotation.Widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
Cary Clarkc5cd5e92010-11-22 15:20:02 -050021import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.graphics.Bitmap;
23import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070024import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.graphics.Picture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.graphics.Rect;
Mike Reede8853fc2009-09-04 14:01:48 -040027import android.graphics.drawable.Drawable;
Adam Powell9d32d242010-03-29 16:02:07 -070028import android.net.http.SslCertificate;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -070029import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Bundle;
Steve Block08d584c2011-05-17 19:05:03 +010031import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Message;
Steve Block08d584c2011-05-17 19:05:03 +010033import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070039import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.view.ViewGroup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070042import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070043import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010044import android.view.accessibility.AccessibilityNodeProvider;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050045import android.view.inputmethod.EditorInfo;
46import android.view.inputmethod.InputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010048
John Reck926cf562012-06-14 10:00:31 -070049import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import java.io.File;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010051import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53/**
Cary Clarkd6982c92009-05-29 11:02:22 -040054 * <p>A View that displays web pages. This class is the basis upon which you
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 * can roll your own web browser or simply display some online content within your Activity.
56 * It uses the WebKit rendering engine to display
57 * web pages and includes methods to navigate forward and backward
58 * through a history, zoom in and out, perform text searches and more.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -070059 * <p>To enable the built-in zoom, set
60 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
Steve Blockb838aef2012-04-23 18:22:15 +010061 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 * <p>Note that, in order for your Activity to access the Internet and load web pages
Scott Main8b3cea02010-05-14 14:12:43 -070063 * in a WebView, you must add the {@code INTERNET} permissions to your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 * Android Manifest file:</p>
65 * <pre>&lt;uses-permission android:name="android.permission.INTERNET" /></pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010066 *
Scott Main8b3cea02010-05-14 14:12:43 -070067 * <p>This must be a child of the <a
Ben Dodson4e8620f2010-08-25 10:55:47 -070068 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
Scott Main8b3cea02010-05-14 14:12:43 -070069 * element.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010070 *
Scott Main4c359b72012-07-24 15:51:27 -070071 * <p>For more information, read
72 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p>
Scott Main41ec6532010-08-19 16:57:07 -070073 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010074 * <h3>Basic usage</h3>
75 *
76 * <p>By default, a WebView provides no browser-like widgets, does not
Scott Main8b3cea02010-05-14 14:12:43 -070077 * enable JavaScript and web page errors are ignored. If your goal is only
Mike Hearnadcd2ed2009-01-21 16:44:36 +010078 * to display some HTML as a part of your UI, this is probably fine;
79 * the user won't need to interact with the web page beyond reading
80 * it, and the web page won't need to interact with the user. If you
Scott Main8b3cea02010-05-14 14:12:43 -070081 * actually want a full-blown web browser, then you probably want to
82 * invoke the Browser application with a URL Intent rather than show it
83 * with a WebView. For example:
84 * <pre>
85 * Uri uri = Uri.parse("http://www.example.com");
86 * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
87 * startActivity(intent);
88 * </pre>
89 * <p>See {@link android.content.Intent} for more information.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010090 *
Ben Dodson4e8620f2010-08-25 10:55:47 -070091 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout,
Scott Main8b3cea02010-05-14 14:12:43 -070092 * or set the entire Activity window as a WebView during {@link
93 * android.app.Activity#onCreate(Bundle) onCreate()}:</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010094 * <pre class="prettyprint">
95 * WebView webview = new WebView(this);
96 * setContentView(webview);
Scott Main8b3cea02010-05-14 14:12:43 -070097 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010098 *
Scott Main8b3cea02010-05-14 14:12:43 -070099 * <p>Then load the desired web page:</p>
Scott Maine3b9f8b2010-05-18 08:41:36 -0700100 * <pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100101 * // Simplest usage: note that an exception will NOT be thrown
102 * // if there is an error loading this page (see below).
103 * webview.loadUrl("http://slashdot.org/");
104 *
Scott Main8b3cea02010-05-14 14:12:43 -0700105 * // OR, you can also load from an HTML string:
Scott Maine3b9f8b2010-05-18 08:41:36 -0700106 * String summary = "&lt;html>&lt;body>You scored &lt;b>192&lt;/b> points.&lt;/body>&lt;/html>";
Steve Blockf95d4902011-06-09 11:53:26 +0100107 * webview.loadData(summary, "text/html", null);
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100108 * // ... although note that there are restrictions on what this HTML can do.
Scott Main8b3cea02010-05-14 14:12:43 -0700109 * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
110 * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100111 * </pre>
112 *
113 * <p>A WebView has several customization points where you can add your
114 * own behavior. These are:</p>
115 *
116 * <ul>
117 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass.
118 * This class is called when something that might impact a
119 * browser UI happens, for instance, progress updates and
Scott Main8b3cea02010-05-14 14:12:43 -0700120 * JavaScript alerts are sent here (see <a
121 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>).
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100122 * </li>
123 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass.
124 * It will be called when things happen that impact the
125 * rendering of the content, eg, errors or form submissions. You
Scott Main8b3cea02010-05-14 14:12:43 -0700126 * can also intercept URL loading here (via {@link
127 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String)
128 * shouldOverrideUrlLoading()}).</li>
129 * <li>Modifying the {@link android.webkit.WebSettings}, such as
130 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
131 * setJavaScriptEnabled()}. </li>
Steve Block4cd73c52011-11-09 13:06:52 +0000132 * <li>Injecting Java objects into the WebView using the
133 * {@link android.webkit.WebView#addJavascriptInterface} method. This
134 * method allows you to inject Java objects into a page's JavaScript
135 * context, so that they can be accessed by JavaScript in the page.</li>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100136 * </ul>
137 *
138 * <p>Here's a more complicated example, showing error handling,
139 * settings, and progress notification:</p>
140 *
141 * <pre class="prettyprint">
142 * // Let's display the progress in the activity title bar, like the
143 * // browser app does.
144 * getWindow().requestFeature(Window.FEATURE_PROGRESS);
145 *
146 * webview.getSettings().setJavaScriptEnabled(true);
147 *
148 * final Activity activity = this;
149 * webview.setWebChromeClient(new WebChromeClient() {
150 * public void onProgressChanged(WebView view, int progress) {
151 * // Activities and WebViews measure progress with different scales.
152 * // The progress meter will automatically disappear when we reach 100%
153 * activity.setProgress(progress * 1000);
154 * }
155 * });
156 * webview.setWebViewClient(new WebViewClient() {
157 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
158 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
159 * }
160 * });
161 *
162 * webview.loadUrl("http://slashdot.org/");
163 * </pre>
164 *
165 * <h3>Cookie and window management</h3>
166 *
167 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700168 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100169 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100170 * </p>
171 *
172 * <p>By default, requests by the HTML to open new windows are
173 * ignored. This is true whether they be opened by JavaScript or by
174 * the target attribute on a link. You can customize your
Scott Main8b3cea02010-05-14 14:12:43 -0700175 * {@link WebChromeClient} to provide your own behaviour for opening multiple windows,
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100176 * and render them in whatever manner you want.</p>
177 *
Scott Main8b3cea02010-05-14 14:12:43 -0700178 * <p>The standard behavior for an Activity is to be destroyed and
179 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100180 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700181 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100182 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700183 * re-orient itself as appropriate. Read <a
184 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
185 * more information about how to handle configuration changes during runtime.</p>
186 *
187 *
188 * <h3>Building web pages to support different screen densities</h3>
189 *
190 * <p>The screen density of a device is based on the screen resolution. A screen with low density
191 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700192 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700193 * screen is important because, other things being equal, a UI element (such as a button) whose
194 * height and width are defined in terms of screen pixels will appear larger on the lower density
195 * screen and smaller on the higher density screen.
196 * For simplicity, Android collapses all actual screen densities into three generalized densities:
197 * high, medium, and low.</p>
198 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
199 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
200 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
201 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100202 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
203 * and meta tag features to help you (as a web developer) target screens with different screen
204 * densities.</p>
Scott Main8b3cea02010-05-14 14:12:43 -0700205 * <p>Here's a summary of the features you can use to handle different screen densities:</p>
206 * <ul>
207 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
208 * default scaling factor used for the current device. For example, if the value of {@code
209 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
210 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
211 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
212 * value is "0.75", then the device is considered a low density device (ldpi) and the content is
Jonathan Dixon89f48e92013-02-27 16:42:48 -0800213 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700214 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
215 * densities for which this style sheet is to be used. The corresponding value should be either
216 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
217 * density, or high density screens, respectively. For example:
218 * <pre>
219 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
220 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
221 * which is the high density pixel ratio.</p>
222 * </li>
Scott Main8b3cea02010-05-14 14:12:43 -0700223 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800224 * <h3>HTML5 Video support</h3>
225 *
226 * <p>In order to support inline HTML5 video in your application, you need to have hardware
227 * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support,
228 * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
229 * and {@link WebChromeClient#onHideCustomView()} are required,
230 * {@link WebChromeClient#getVideoLoadingProgressView()} is optional.
231 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 */
Steve Block406aeb22012-04-23 18:17:19 +0100233// Implementation notes.
234// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
235// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
236// Methods are delegated to the provider implementation: all public API methods introduced in this
237// file are fully delegated, whereas public and protected methods from the View base classes are
238// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800239@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400240public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700242 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243
Jonathan Dixon3c909522012-02-28 18:45:06 +0000244 private static final String LOGTAG = "webview_proxy";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700245
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700246 // Throwing an exception for incorrect thread usage if the
247 // build target is JB MR2 or newer. Defaults to false, and is
248 // set in the WebView constructor.
249 private static Boolean sEnforceThreadChecking = false;
250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 /**
252 * Transportation object for returning WebView across thread boundaries.
253 */
254 public class WebViewTransport {
255 private WebView mWebview;
256
257 /**
Steve Block4e584df2012-04-24 23:12:47 +0100258 * Sets the WebView to the transportation object.
259 *
260 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 */
262 public synchronized void setWebView(WebView webview) {
263 mWebview = webview;
264 }
265
266 /**
Steve Block4e584df2012-04-24 23:12:47 +0100267 * Gets the WebView object.
268 *
269 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 */
271 public synchronized WebView getWebView() {
272 return mWebview;
273 }
274 }
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 /**
Steve Block4e584df2012-04-24 23:12:47 +0100277 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 */
279 public static final String SCHEME_TEL = "tel:";
280 /**
Steve Block4e584df2012-04-24 23:12:47 +0100281 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 */
283 public static final String SCHEME_MAILTO = "mailto:";
284 /**
Steve Block4e584df2012-04-24 23:12:47 +0100285 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 */
287 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 /**
Victoria Leased405a432012-03-22 15:53:48 -0700290 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700291 */
292 public interface FindListener {
293 /**
Steve Block4e584df2012-04-24 23:12:47 +0100294 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700295 *
Steve Block4e584df2012-04-24 23:12:47 +0100296 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700297 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100298 * @param isDoneCounting whether the find operation has actually completed. The listener
299 * may be notified multiple times while the
300 * operation is underway, and the numberOfMatches
301 * value should not be considered final unless
302 * isDoneCounting is true.
Victoria Leased405a432012-03-22 15:53:48 -0700303 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700304 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700305 boolean isDoneCounting);
306 }
307
308 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100310 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100311 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100313 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 public interface PictureListener {
315 /**
Steve Block72498ed2012-07-17 15:57:25 +0100316 * Used to provide notification that the WebView's picture has changed.
317 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100318 *
319 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000320 * @param picture the new picture. Applications targeting
321 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
322 * will always receive a null Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100323 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100325 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 public void onNewPicture(WebView view, Picture picture);
327 }
328
Jonathan Dixon19644b62011-12-21 14:21:36 +0000329 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 /**
Steve Block4e584df2012-04-24 23:12:47 +0100331 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 */
333 public static final int UNKNOWN_TYPE = 0;
334 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100335 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 */
Steve Block1854ddb2011-04-19 12:18:19 +0100337 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 public static final int ANCHOR_TYPE = 1;
339 /**
Steve Block4e584df2012-04-24 23:12:47 +0100340 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
342 public static final int PHONE_TYPE = 2;
343 /**
Steve Block4e584df2012-04-24 23:12:47 +0100344 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 */
346 public static final int GEO_TYPE = 3;
347 /**
Steve Block4e584df2012-04-24 23:12:47 +0100348 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 */
350 public static final int EMAIL_TYPE = 4;
351 /**
Steve Block4e584df2012-04-24 23:12:47 +0100352 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 */
354 public static final int IMAGE_TYPE = 5;
355 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100356 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 */
Steve Block1854ddb2011-04-19 12:18:19 +0100358 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 public static final int IMAGE_ANCHOR_TYPE = 6;
360 /**
Steve Block4e584df2012-04-24 23:12:47 +0100361 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 */
363 public static final int SRC_ANCHOR_TYPE = 7;
364 /**
Steve Block4e584df2012-04-24 23:12:47 +0100365 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 */
367 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
368 /**
Steve Block4e584df2012-04-24 23:12:47 +0100369 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 */
371 public static final int EDIT_TEXT_TYPE = 9;
372
373 private int mType;
374 private String mExtra;
375
Jonathan Dixon3c909522012-02-28 18:45:06 +0000376 /**
377 * @hide Only for use by WebViewProvider implementations
378 */
379 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 mType = UNKNOWN_TYPE;
381 }
382
Jonathan Dixon3c909522012-02-28 18:45:06 +0000383 /**
384 * @hide Only for use by WebViewProvider implementations
385 */
386 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 mType = type;
388 }
389
Jonathan Dixon3c909522012-02-28 18:45:06 +0000390 /**
391 * @hide Only for use by WebViewProvider implementations
392 */
393 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 mExtra = extra;
395 }
396
Jonathan Dixone230e542011-12-21 10:57:00 +0000397 /**
Steve Block4e584df2012-04-24 23:12:47 +0100398 * Gets the type of the hit test result. See the XXX_TYPE constants
399 * defined in this class.
400 *
401 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000402 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 public int getType() {
404 return mType;
405 }
406
Jonathan Dixone230e542011-12-21 10:57:00 +0000407 /**
Steve Block4e584df2012-04-24 23:12:47 +0100408 * Gets additional type-dependant information about the result. See
409 * {@link WebView#getHitTestResult()} for details. May either be null
410 * or contain extra information about this result.
411 *
412 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000413 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 public String getExtra() {
415 return mExtra;
416 }
417 }
418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 /**
Steve Block4e584df2012-04-24 23:12:47 +0100420 * Constructs a new WebView with a Context object.
421 *
422 * @param context a Context object used to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 */
424 public WebView(Context context) {
425 this(context, null);
426 }
427
428 /**
Steve Block4e584df2012-04-24 23:12:47 +0100429 * Constructs a new WebView with layout parameters.
430 *
431 * @param context a Context object used to access application assets
432 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 */
434 public WebView(Context context, AttributeSet attrs) {
435 this(context, attrs, com.android.internal.R.attr.webViewStyle);
436 }
437
438 /**
Steve Block4e584df2012-04-24 23:12:47 +0100439 * Constructs a new WebView with layout parameters and a default style.
440 *
441 * @param context a Context object used to access application assets
442 * @param attrs an AttributeSet passed to our parent
443 * @param defStyle the default style resource ID
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 */
445 public WebView(Context context, AttributeSet attrs, int defStyle) {
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700446 this(context, attrs, defStyle, false);
447 }
448
449 /**
Steve Block4e584df2012-04-24 23:12:47 +0100450 * Constructs a new WebView with layout parameters and a default style.
451 *
452 * @param context a Context object used to access application assets
453 * @param attrs an AttributeSet passed to our parent
454 * @param defStyle the default style resource ID
455 * @param privateBrowsing whether this WebView will be initialized in
456 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400457 *
458 * @deprecated Private browsing is no longer supported directly via
459 * WebView and will be removed in a future release. Prefer using
460 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
461 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700462 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400463 @Deprecated
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700464 public WebView(Context context, AttributeSet attrs, int defStyle,
465 boolean privateBrowsing) {
466 this(context, attrs, defStyle, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100467 }
468
469 /**
Steve Block4e584df2012-04-24 23:12:47 +0100470 * Constructs a new WebView with layout parameters, a default style and a set
471 * of custom Javscript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800472 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100473 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100474 *
475 * @param context a Context object used to access application assets
476 * @param attrs an AttributeSet passed to our parent
477 * @param defStyle the default style resource ID
478 * @param javaScriptInterfaces a Map of interface names, as keys, and
479 * object implementing those interfaces, as
480 * values
481 * @param privateBrowsing whether this WebView will be initialized in
482 * private mode
Jonathan Dixon3c909522012-02-28 18:45:06 +0000483 * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100484 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100485 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000486 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100487 protected WebView(Context context, AttributeSet attrs, int defStyle,
Steve Block81f19ff2010-11-01 13:23:24 +0000488 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 super(context, attrs, defStyle);
Kristian Monsen87af7312011-09-09 02:12:51 +0100490 if (context == null) {
491 throw new IllegalArgumentException("Invalid context argument");
492 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700493 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
494 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000495 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100496
Jonathan Dixon3c909522012-02-28 18:45:06 +0000497 ensureProviderCreated();
498 mProvider.init(javaScriptInterfaces, privateBrowsing);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 }
500
501 /**
Steve Block4e584df2012-04-24 23:12:47 +0100502 * Specifies whether the horizontal scrollbar has overlay style.
503 *
504 * @param overlay true if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 */
506 public void setHorizontalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100507 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000508 mProvider.setHorizontalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
510
511 /**
Steve Block4e584df2012-04-24 23:12:47 +0100512 * Specifies whether the vertical scrollbar has overlay style.
513 *
514 * @param overlay true if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 */
516 public void setVerticalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100517 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000518 mProvider.setVerticalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 }
520
521 /**
Steve Block4e584df2012-04-24 23:12:47 +0100522 * Gets whether horizontal scrollbar has overlay style.
523 *
524 * @return true if horizontal scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 */
526 public boolean overlayHorizontalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100527 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000528 return mProvider.overlayHorizontalScrollbar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 }
530
531 /**
Steve Block4e584df2012-04-24 23:12:47 +0100532 * Gets whether vertical scrollbar has overlay style.
533 *
534 * @return true if vertical scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 */
536 public boolean overlayVerticalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100537 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000538 return mProvider.overlayVerticalScrollbar();
Mike Reede8853fc2009-09-04 14:01:48 -0400539 }
540
Michael Kolbe54f6652011-03-16 09:11:51 -0700541 /**
Steve Block4e584df2012-04-24 23:12:47 +0100542 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700543 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700544 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400545 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400546 */
Michael Kolb73980a92010-08-05 16:32:51 -0700547 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100548 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000549 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 }
551
552 /**
Steve Block4e584df2012-04-24 23:12:47 +0100553 * Gets the SSL certificate for the main top-level page or null if there is
554 * no certificate (the site is not secure).
555 *
556 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 */
558 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100559 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000560 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562
563 /**
564 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400565 *
566 * @deprecated Calling this function has no useful effect, and will be
567 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400569 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100571 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000572 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 }
574
575 //-------------------------------------------------------------------------
576 // Methods called by activity
577 //-------------------------------------------------------------------------
578
579 /**
Steve Block32fe4102012-07-17 16:29:11 +0100580 * Sets a username and password pair for the specified host. This data is
581 * used by the Webview to autocomplete username and password fields in web
582 * forms. Note that this is unrelated to the credentials used for HTTP
583 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100584 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000585 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100586 * @param username the username for the given host
587 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100588 * @see WebViewDatabase#clearUsernamePassword
589 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800590 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800592 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100594 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000595 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 }
597
598 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100599 * Stores HTTP authentication credentials for a given host and realm. This
600 * method is intended to be used with
601 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 *
Steve Block46ce1db2012-07-17 16:43:00 +0100603 * @param host the host to which the credentials apply
604 * @param realm the realm to which the credentials apply
605 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100606 * @param password the password
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800607 * @see #getHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100608 * @see WebViewDatabase#hasHttpAuthUsernamePassword
609 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 */
611 public void setHttpAuthUsernamePassword(String host, String realm,
612 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100613 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000614 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
616
617 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100618 * Retrieves HTTP authentication credentials for a given host and realm.
619 * This method is intended to be used with
620 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 *
Steve Block46ce1db2012-07-17 16:43:00 +0100622 * @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.
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800627 * @see #setHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100628 * @see WebViewDatabase#hasHttpAuthUsernamePassword
629 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 */
631 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100632 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000633 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400634 }
635
636 /**
Steve Block4e584df2012-04-24 23:12:47 +0100637 * 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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 */
641 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100642 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000643 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 }
645
646 /**
647 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100648 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100649 *
650 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400651 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100653 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 public static void enablePlatformNotifications() {
Steve Block51b08912011-04-27 15:04:48 +0100655 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000656 getFactory().getStatics().setPlatformNotificationsEnabled(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 }
658
659 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100660 * Disables platform notifications of data state and proxy changes.
661 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100662 *
663 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400664 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100666 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 public static void disablePlatformNotifications() {
Steve Block51b08912011-04-27 15:04:48 +0100668 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000669 getFactory().getStatics().setPlatformNotificationsEnabled(false);
Feng Qianb3081372009-06-29 15:55:18 -0700670 }
671
672 /**
Steve Block4e584df2012-04-24 23:12:47 +0100673 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000674 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100676 *
677 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 */
679 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100680 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000681 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683
684 /**
Steve Block4e584df2012-04-24 23:12:47 +0100685 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
687 * method no longer stores the display data for this WebView. The previous
688 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400689 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100690 *
691 * @param outState the Bundle to store this WebView's state
692 * @return the same copy of the back/forward list used to save the state. If
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 * saveState fails, the returned list will be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 */
695 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100696 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000697 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 }
699
700 /**
Steve Block4e584df2012-04-24 23:12:47 +0100701 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100703 * @param b a Bundle to store the display data
704 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 * overwritten with this WebView's picture data.
Steve Block4e584df2012-04-24 23:12:47 +0100706 * @return true if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100707 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400708 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100710 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400711 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100712 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000713 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 }
715
716 /**
Steve Block4e584df2012-04-24 23:12:47 +0100717 * 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.
John Reck2df8f422011-09-22 19:50:41 -0700720 *
Steve Block4e584df2012-04-24 23:12:47 +0100721 * @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
Kristian Monsenfc771652011-05-10 16:44:05 +0100724 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400725 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100727 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100729 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000730 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700731 }
732
733 /**
Steve Block42499062012-07-17 15:34:46 +0100734 * Restores the state of this WebView from the given Bundle. This method is
735 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
736 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100737 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400738 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400740 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100741 *
742 * @param inState the incoming Bundle of state
743 * @return the restored back/forward list or null if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 */
745 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100746 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000747 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 }
749
750 /**
Steve Block4e584df2012-04-24 23:12:47 +0100751 * Loads the given URL with the specified additional HTTP headers.
752 *
753 * @param url the URL of the resource to load
754 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100755 * HTTP request for this URL, specified as a map from name to
756 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100757 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100758 * controlling caching, accept types or the User-Agent, their
Steve Block4e584df2012-04-24 23:12:47 +0100759 * values may be overriden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800760 */
Steve Blockf71dea02011-08-01 12:29:14 +0100761 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100762 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000763 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800764 }
765
766 /**
Steve Block4e584df2012-04-24 23:12:47 +0100767 * Loads the given URL.
768 *
769 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 */
771 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100772 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000773 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775
776 /**
Steve Block4e584df2012-04-24 23:12:47 +0100777 * Loads the URL with postData using "POST" method into this WebView. If url
778 * is not a network URL, it will be loaded with {link
Grace Kloba57534302009-05-22 18:55:02 -0700779 * {@link #loadUrl(String)} instead.
Cary Clarkd6982c92009-05-29 11:02:22 -0400780 *
Steve Block4e584df2012-04-24 23:12:47 +0100781 * @param url the URL of the resource to load
782 * @param postData the data will be passed to "POST" request
Grace Kloba57534302009-05-22 18:55:02 -0700783 */
784 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100785 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000786 mProvider.postUrl(url, postData);
Grace Kloba57534302009-05-22 18:55:02 -0700787 }
788
789 /**
Steve Block4e584df2012-04-24 23:12:47 +0100790 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100791 * <p>
792 * Note that JavaScript's same origin policy means that script running in a
793 * page loaded using this method will be unable to access content loaded
794 * using any scheme other than 'data', including 'http(s)'. To avoid this
795 * restriction, use {@link
796 * #loadDataWithBaseURL(String,String,String,String,String)
797 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100798 * <p>
Steve Block27f3e322012-07-23 10:45:59 +0100799 * The encoding parameter specifies whether the data is base64 or URL
800 * encoded. If the data is base64 encoded, the value of the encoding
801 * parameter must be 'base64'. For all other values of the parameter,
802 * including null, it is assumed that the data uses ASCII encoding for
Steve Blockf95d4902011-06-09 11:53:26 +0100803 * octets inside the range of safe URL characters and use the standard %xx
Steve Block27f3e322012-07-23 10:45:59 +0100804 * hex encoding of URLs for octets outside that range. For example, '#',
805 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
Steve Blockb19c7872011-10-10 14:09:44 +0100806 * <p>
807 * The 'data' scheme URL formed by this method uses the default US-ASCII
808 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100809 * 'data' scheme URL which explicitly specifies a charset parameter in the
810 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
811 * Note that the charset obtained from the mediatype portion of a data URL
812 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +0100813 *
814 * @param data a String of data in the given encoding
815 * @param mimeType the MIME type of the data, e.g. 'text/html'
816 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 */
818 public void loadData(String data, String mimeType, String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100819 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000820 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 }
822
823 /**
Steve Block4e584df2012-04-24 23:12:47 +0100824 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100825 * the content. The base URL is used both to resolve relative URLs and when
826 * applying JavaScript's same origin policy. The historyUrl is used for the
827 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100829 * Note that content specified in this way can access local device files
830 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
831 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100832 * <p>
833 * If the base URL uses the data scheme, this method is equivalent to
834 * calling {@link #loadData(String,String,String) loadData()} and the
835 * historyUrl is ignored.
Steve Block4e584df2012-04-24 23:12:47 +0100836 *
837 * @param baseUrl the URL to use as the page's base URL. If null defaults to
838 * 'about:blank'.
839 * @param data a String of data in the given encoding
840 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
841 * defaults to 'text/html'.
842 * @param encoding the encoding of the data
843 * @param historyUrl the URL to use as the history entry. If null defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000844 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 */
846 public void loadDataWithBaseURL(String baseUrl, String data,
Leon Scroggins1bb1a912010-03-23 15:39:46 -0400847 String mimeType, String encoding, String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100848 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000849 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 }
851
852 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +0100853 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
854 * If non-null, |resultCallback| will be invoked with any result returned from that
855 * execution. This method must be called on the UI thread and the callback will
856 * be made on the UI thread.
857 *
858 * @param script the JavaScript to execute.
859 * @param resultCallback A callback to be invoked when the script execution
860 * completes with the result of the execution (if any).
861 * May be null if no notificaion of the result is required.
862 * @hide pending API council approval and CTS test coverage.
863 */
864 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) {
865 checkThread();
866 mProvider.evaluateJavaScript(script, resultCallback);
867 }
868
869 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700870 * Saves the current view as a web archive.
871 *
Steve Block4e584df2012-04-24 23:12:47 +0100872 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700873 */
874 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100875 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000876 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700877 }
878
879 /**
880 * Saves the current view as a web archive.
881 *
Steve Block4e584df2012-04-24 23:12:47 +0100882 * @param basename the filename where the archive should be placed
883 * @param autoname if false, takes basename to be a file. If true, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700884 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100885 * chosen according to the URL of the current page.
886 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700887 * parameter for onReceiveValue will either be the filename
888 * under which the file was saved, or null if saving the
889 * file failed.
890 */
891 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
Steve Block51b08912011-04-27 15:04:48 +0100892 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000893 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700894 }
895
896 /**
Steve Block4e584df2012-04-24 23:12:47 +0100897 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 */
899 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100900 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000901 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 }
903
904 /**
Steve Block4e584df2012-04-24 23:12:47 +0100905 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 */
907 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100908 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000909 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 }
911
912 /**
Steve Block4e584df2012-04-24 23:12:47 +0100913 * Gets whether this WebView has a back history item.
914 *
915 * @return true iff this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 */
917 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +0100918 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000919 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 }
921
922 /**
Steve Block4e584df2012-04-24 23:12:47 +0100923 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 */
925 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +0100926 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000927 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
929
930 /**
Steve Block4e584df2012-04-24 23:12:47 +0100931 * Gets whether this WebView has a forward history item.
932 *
933 * @return true iff this Webview has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 */
935 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +0100936 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000937 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939
940 /**
Steve Block4e584df2012-04-24 23:12:47 +0100941 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 */
943 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +0100944 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000945 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 }
947
948 /**
Steve Block4e584df2012-04-24 23:12:47 +0100949 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +0100951 *
952 * @param steps the negative or positive number of steps to move the
953 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 */
955 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100956 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000957 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
959
960 /**
Steve Block4e584df2012-04-24 23:12:47 +0100961 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 * the current item. Steps is negative if backward and positive
963 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +0100964 *
965 * @param steps the number of steps to take back or forward in the back
966 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 */
968 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100969 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000970 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400972
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700973 /**
Steve Block4e584df2012-04-24 23:12:47 +0100974 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700975 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -0700976 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +0100977 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000978 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 /**
Steve Block4e584df2012-04-24 23:12:47 +0100982 * Scrolls the contents of this WebView up by half the view size.
983 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 * @param top true to jump to the top of the page
985 * @return true if the page was scrolled
986 */
987 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +0100988 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000989 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 /**
Steve Block4e584df2012-04-24 23:12:47 +0100993 * Scrolls the contents of this WebView down by half the page size.
994 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 * @param bottom true to jump to bottom of page
996 * @return true if the page was scrolled
997 */
998 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +0100999 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001000 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 }
1002
1003 /**
Steve Block4e584df2012-04-24 23:12:47 +01001004 * Clears this WebView so that onDraw() will draw nothing but white background,
1005 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001006 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1007 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001009 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001011 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001012 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 /**
Steve Block72498ed2012-07-17 15:57:25 +01001016 * Gets a new picture that captures the current contents of this WebView.
1017 * The picture is of the entire document being displayed, and is not
1018 * limited to the area currently displayed by this WebView. Also, the
1019 * picture is a static copy and is unaffected by later changes to the
1020 * content being displayed.
1021 * <p>
1022 * Note that due to internal changes, for API levels between
1023 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1024 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1025 * picture does not include fixed position elements or scrollable divs.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 *
Steve Block72498ed2012-07-17 15:57:25 +01001027 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 */
1029 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001030 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001031 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 }
1033
Cary Clarkd6982c92009-05-29 11:02:22 -04001034 /**
Steve Block4e584df2012-04-24 23:12:47 +01001035 * Gets the current scale of this WebView.
1036 *
1037 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001038 *
1039 * @deprecated This method is prone to inaccuracy due to race conditions
1040 * between the web rendering and UI threads; prefer
1041 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001043 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001044 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001046 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001047 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001048 }
1049
1050 /**
Steve Block4e584df2012-04-24 23:12:47 +01001051 * Sets the initial scale for this WebView. 0 means default. If
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 * {@link WebSettings#getUseWideViewPort()} is true, it zooms out all the
1053 * way. Otherwise it starts with 100%. If initial scale is greater than 0,
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001054 * WebView starts with this value as initial scale.
1055 * Please note that unlike the scale properties in the viewport meta tag,
1056 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 *
Steve Block4e584df2012-04-24 23:12:47 +01001058 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 */
1060 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001061 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001062 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064
1065 /**
Steve Block4e584df2012-04-24 23:12:47 +01001066 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 * result in the zoom widget appearing on the screen to control the zoom
1068 * level of this WebView.
1069 */
1070 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001071 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001072 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
1074
1075 /**
Steve Block4e584df2012-04-24 23:12:47 +01001076 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1077 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1078 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1079 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1080 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001082 * found, the HitTestResult type is set to IMAGE_TYPE and the URL is set in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001084 * SRC_IMAGE_ANCHOR_TYPE indicates an anchor with a URL that has an image as
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 * a child node. If a phone number is found, the HitTestResult type is set
1086 * to PHONE_TYPE and the phone number is set in the "extra" field of
1087 * HitTestResult. If a map address is found, the HitTestResult type is set
1088 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1089 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1090 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1091 * HitTestResult type is set to UNKNOWN_TYPE.
1092 */
1093 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001094 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001095 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001096 }
1097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 /**
Steve Block4e584df2012-04-24 23:12:47 +01001099 * Requests the anchor or image element URL at the last tapped point.
Cary Clark861368a2010-12-15 11:24:37 -05001100 * If hrefMsg is null, this method returns immediately and does not
1101 * dispatch hrefMsg to its target. If the tapped point hits an image,
1102 * an anchor, or an image in an anchor, the message associates
1103 * strings in named keys in its data. The value paired with the key
1104 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001105 *
Steve Block4e584df2012-04-24 23:12:47 +01001106 * @param hrefMsg the message to be dispatched with the result of the
1107 * request. The message data contains three keys. "url"
1108 * returns the anchor's href attribute. "title" returns the
1109 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 */
1111 public void requestFocusNodeHref(Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001112 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001113 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 /**
Steve Block4e584df2012-04-24 23:12:47 +01001117 * Requests the URL of the image last touched by the user. msg will be sent
1118 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001119 *
Steve Block4e584df2012-04-24 23:12:47 +01001120 * @param msg the message to be dispatched with the result of the request
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 * as the data member with "url" as key. The result can be null.
1122 */
1123 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001124 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001125 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001126 }
1127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 /**
Steve Block4e584df2012-04-24 23:12:47 +01001129 * Gets the URL for the current page. This is not always the same as the URL
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001131 * that URL has begun, the current page may not have changed.
1132 *
1133 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 */
John Reck926cf562012-06-14 10:00:31 -07001135 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001137 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001138 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 /**
Steve Block4e584df2012-04-24 23:12:47 +01001142 * Gets the original URL for the current page. This is not always the same
1143 * as the URL passed to WebViewClient.onPageStarted because although the
1144 * load for that URL has begun, the current page may not have changed.
1145 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001147 *
1148 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 */
John Reck926cf562012-06-14 10:00:31 -07001150 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001152 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001153 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
1155
1156 /**
Steve Block4e584df2012-04-24 23:12:47 +01001157 * Gets the title for the current page. This is the title of the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001159 *
1160 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 */
John Reck926cf562012-06-14 10:00:31 -07001162 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001164 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001165 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
1167
1168 /**
Steve Block4e584df2012-04-24 23:12:47 +01001169 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001171 *
1172 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 */
1174 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001175 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001176 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 }
1178
1179 /**
Steve Block4e584df2012-04-24 23:12:47 +01001180 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001181 * a URL on this site's server pointing to the standard location of a
1182 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001183 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001184 * @hide
1185 */
1186 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001187 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001188 }
1189
1190 /**
Steve Block4e584df2012-04-24 23:12:47 +01001191 * Gets the progress for the current page.
1192 *
1193 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 */
1195 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001196 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001197 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 /**
Steve Block4e584df2012-04-24 23:12:47 +01001201 * Gets the height of the HTML content.
1202 *
1203 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 */
John Reck926cf562012-06-14 10:00:31 -07001205 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001207 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001208 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 }
1210
1211 /**
Steve Block4e584df2012-04-24 23:12:47 +01001212 * Gets the width of the HTML content.
1213 *
1214 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001215 * @hide
1216 */
John Reck926cf562012-06-14 10:00:31 -07001217 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001218 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001219 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001220 }
1221
1222 /**
Steve Block4e584df2012-04-24 23:12:47 +01001223 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1224 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001225 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 */
1227 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001228 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001229 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 }
1231
1232 /**
Steve Block4e584df2012-04-24 23:12:47 +01001233 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001234 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 */
1236 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001237 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001238 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 }
1240
1241 /**
Steve Block4e584df2012-04-24 23:12:47 +01001242 * Pauses any extra processing associated with this WebView and its
1243 * associated DOM, plugins, JavaScript etc. For example, if this WebView is
1244 * taken offscreen, this could be called to reduce unnecessary CPU or
1245 * network traffic. When this WebView is again "active", call onResume().
Steve Block81f19ff2010-11-01 13:23:24 +00001246 * Note that this differs from pauseTimers(), which affects all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001247 */
1248 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001249 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001250 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001251 }
1252
1253 /**
Steve Block4e584df2012-04-24 23:12:47 +01001254 * Resumes a WebView after a previous call to onPause().
Mike Reedd205d5b2009-05-27 11:02:29 -04001255 */
1256 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001257 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001258 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001259 }
1260
1261 /**
Steve Block4e584df2012-04-24 23:12:47 +01001262 * Gets whether this WebView is paused, meaning onPause() was called.
1263 * Calling onResume() sets the paused state back to false.
1264 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001265 * @hide
1266 */
1267 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001268 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001269 }
1270
1271 /**
Steve Block4e584df2012-04-24 23:12:47 +01001272 * Informs this WebView that memory is low so that it can free any available
1273 * memory.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001274 */
1275 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001276 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001277 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001278 }
1279
1280 /**
Steve Block4e584df2012-04-24 23:12:47 +01001281 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001282 * this will clear the cache for all WebViews used.
1283 *
Steve Block4e584df2012-04-24 23:12:47 +01001284 * @param includeDiskFiles if false, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 */
1286 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001287 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001288 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 }
1290
1291 /**
Steve Block219dfa42012-07-20 10:31:21 +01001292 * Removes the autocomplete popup from the currently focused form field, if
1293 * present. Note this only affects the display of the autocomplete popup,
1294 * it does not remove any saved form data from this WebView's store. To do
1295 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 */
1297 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001298 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001299 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 }
1301
1302 /**
Steve Block4e584df2012-04-24 23:12:47 +01001303 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 */
1305 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001306 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001307 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 }
1309
1310 /**
Steve Block4e584df2012-04-24 23:12:47 +01001311 * Clears the SSL preferences table stored in response to proceeding with
1312 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 */
1314 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001315 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001316 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 }
1318
1319 /**
Steve Block4e584df2012-04-24 23:12:47 +01001320 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 * back/forward list for use in querying each item in the history stack.
1322 * This is a copy of the private WebBackForwardList so it contains only a
1323 * snapshot of the current state. Multiple calls to this method may return
1324 * different objects. The object returned from this method will not be
1325 * updated to reflect any new state.
1326 */
1327 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001328 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001329 return mProvider.copyBackForwardList();
1330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 }
1332
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001333 /**
Steve Block4e584df2012-04-24 23:12:47 +01001334 * Registers the listener to be notified as find-on-page operations
1335 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001336 *
Steve Block4e584df2012-04-24 23:12:47 +01001337 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001338 */
1339 public void setFindListener(FindListener listener) {
1340 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001341 setupFindListenerIfNeeded();
1342 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001343 }
1344
1345 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001346 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001347 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001348 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1349 * has not been called yet, or if {@link #clearMatches} has been called since the
1350 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 *
Steve Block4e584df2012-04-24 23:12:47 +01001352 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001353 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 */
1355 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001356 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001357 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 }
1359
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001360 /**
Steve Block4e584df2012-04-24 23:12:47 +01001361 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001362 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001363 *
Steve Block4e584df2012-04-24 23:12:47 +01001364 * @param find the string to find
1365 * @return the number of occurances of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001366 * @deprecated {@link #findAllAsync} is preferred.
1367 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001369 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001371 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001372 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001373 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 }
1375
Cary Clark3403eb32010-03-03 10:05:16 -05001376 /**
Steve Block4e584df2012-04-24 23:12:47 +01001377 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001378 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001379 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001380 *
Steve Block4e584df2012-04-24 23:12:47 +01001381 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001382 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001383 */
1384 public void findAllAsync(String find) {
1385 checkThread();
1386 mProvider.findAllAsync(find);
1387 }
1388
1389 /**
Steve Block4e584df2012-04-24 23:12:47 +01001390 * Starts an ActionMode for finding text in this WebView. Only works if this
1391 * WebView is attached to the view system.
1392 *
1393 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001394 * Otherwise, the last String searched for in this WebView will
1395 * be used to start.
Steve Block4e584df2012-04-24 23:12:47 +01001396 * @param showIme if true, show the IME, assuming the user will begin typing.
1397 * If false and text is non-null, perform a find all.
1398 * @return true if the find dialog is shown, false otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001399 * @deprecated This method does not work reliably on all Android versions;
1400 * implementing a custom find dialog using WebView.findAllAsync()
1401 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001402 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001403 @Deprecated
Leon Scroggins571354f2011-01-04 10:12:41 -05001404 public boolean showFindDialog(String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001405 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001406 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001407 }
1408
1409 /**
Steve Block4e584df2012-04-24 23:12:47 +01001410 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 * location. Currently, only addresses in the United States are detected,
1412 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001413 * <ul>
1414 * <li>a house number</li>
1415 * <li>a street name</li>
1416 * <li>a street type (Road, Circle, etc), either spelled out or
1417 * abbreviated</li>
1418 * <li>a city name</li>
1419 * <li>a state or territory, either spelled out or two-letter abbr</li>
1420 * <li>an optional 5 digit or 9 digit zip code</li>
1421 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 * All names must be correctly capitalized, and the zip code, if present,
1423 * must be valid for the state. The street type must be a standard USPS
1424 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001425 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 *
Steve Block4e584df2012-04-24 23:12:47 +01001428 * @param addr the string to search for addresses
1429 * @return the address, or if no address is found, null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 */
1431 public static String findAddress(String addr) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001432 return getFactory().getStatics().findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 }
1434
Victoria Lease0b8413b2012-03-26 13:04:10 -07001435 /**
Steve Block4e584df2012-04-24 23:12:47 +01001436 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001437 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 */
1439 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001440 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001441 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 }
1443
1444 /**
Steve Block4e584df2012-04-24 23:12:47 +01001445 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 * message object will be dispatched with arg1 being set to 1 if images
1447 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001448 *
1449 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 */
1451 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001452 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001453 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 }
1455
1456 /**
Steve Block4e584df2012-04-24 23:12:47 +01001457 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001459 *
1460 * @param client an implementation of WebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 */
1462 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001463 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001464 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001465 }
1466
1467 /**
Steve Block4e584df2012-04-24 23:12:47 +01001468 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 * the rendering engine, and should be downloaded instead. This will replace
1470 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001471 *
1472 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 */
1474 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001475 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001476 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 }
1478
1479 /**
Steve Block4e584df2012-04-24 23:12:47 +01001480 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001481 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001483 *
1484 * @param client an implementation of WebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 */
1486 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001487 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001488 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001489 }
1490
1491 /**
Steve Block4e584df2012-04-24 23:12:47 +01001492 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001494 *
1495 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001496 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001498 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001500 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001501 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
1503
1504 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001505 * Injects the supplied Java object into this WebView. The object is
1506 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001507 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001508 * accessed from JavaScript. For applications targeted to API
1509 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001510 * and above, only public methods that are annotated with
1511 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001512 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001513 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001514 * important security note below for implications.
1515 * <p> Note that injected objects will not
Steve Block3aa800b2012-04-24 13:01:34 +01001516 * appear in JavaScript until the page is next (re)loaded. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001517 * <pre>
1518 * class JsObject {
1519 * {@literal @}JavascriptInterface
1520 * public String toString() { return "injectedObject"; }
1521 * }
1522 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001523 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1524 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001525 * <p>
1526 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001528 * <li> This method can be used to allow JavaScript to control the host
1529 * application. This is a powerful feature, but also presents a security
Selim Gurunb4c02e62012-09-12 13:36:21 -07001530 * risk for applications targeted to API level
Selim Gurune91d5be2012-09-11 16:11:22 -07001531 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because
1532 * JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001533 * injected object's public fields. Use of this method in a WebView
1534 * containing untrusted content could allow an attacker to manipulate the
1535 * host application in unintended ways, executing Java code with the
1536 * permissions of the host application. Use extreme care when using this
1537 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001538 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001539 * thread of this WebView. Care is therefore required to maintain thread
Steve Block4cd73c52011-11-09 13:06:52 +00001540 * safety.</li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001541 * <li> The Java object's fields are not accessible.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001542 * </ul>
1543 *
1544 * @param object the Java object to inject into this WebView's JavaScript
Steve Block4cd73c52011-11-09 13:06:52 +00001545 * context. Null values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001546 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 */
Steve Block4cd73c52011-11-09 13:06:52 +00001548 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001549 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001550 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 }
1552
1553 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001554 * Removes a previously injected Java object from this WebView. Note that
1555 * the removal will not be reflected in JavaScript until the page is next
1556 * (re)loaded. See {@link #addJavascriptInterface}.
1557 *
1558 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001559 */
Steve Block3aa800b2012-04-24 13:01:34 +01001560 public void removeJavascriptInterface(String name) {
Steve Block51b08912011-04-27 15:04:48 +01001561 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01001562 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001563 }
1564
1565 /**
Steve Block4e584df2012-04-24 23:12:47 +01001566 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001568 *
1569 * @return a WebSettings object that can be used to control this WebView's
1570 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 */
1572 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001573 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001574 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 }
1576
Jonathan Dixon3c909522012-02-28 18:45:06 +00001577 /**
Steve Block4e584df2012-04-24 23:12:47 +01001578 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001579 *
Steve Block4e584df2012-04-24 23:12:47 +01001580 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001581 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001582 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001583 */
Andrei Popescu385df692009-08-13 11:59:57 +01001584 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 public static synchronized PluginList getPluginList() {
Steve Block51b08912011-04-27 15:04:48 +01001586 checkThread();
Grace Klobabb245ea2009-11-10 13:13:24 -08001587 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 }
1589
Jonathan Dixon3c909522012-02-28 18:45:06 +00001590 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001591 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001592 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001593 */
Andrei Popescu385df692009-08-13 11:59:57 +01001594 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01001595 public void refreshPlugins(boolean reloadOpenPages) {
1596 checkThread();
1597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598
Cary Clark966641a2010-03-04 08:41:56 -05001599 /**
Steve Block4e584df2012-04-24 23:12:47 +01001600 * Puts this WebView into text selection mode. Do not rely on this
1601 * functionality; it will be deprecated in the future.
1602 *
Kristian Monsenfc771652011-05-10 16:44:05 +01001603 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001604 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05001605 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001606 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01001608 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07001609 }
1610
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001611 /**
1612 * @deprecated WebView no longer needs to implement
1613 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1614 */
George Mountfab67a12012-01-05 09:58:53 -08001615 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001616 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001617 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04001619
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001620 /**
1621 * @deprecated WebView no longer needs to implement
1622 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1623 */
George Mountfab67a12012-01-05 09:58:53 -08001624 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001625 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001626 @Deprecated
1627 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628
1629 /**
1630 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08001631 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 */
George Mountfab67a12012-01-05 09:58:53 -08001633 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001634 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 @Deprecated
1636 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1637 }
1638
Kristian Monsen5cc23512012-08-09 15:33:08 -04001639 /**
1640 * @deprecated Only the default case, true, will be supported in a future version.
1641 */
1642 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01001644 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001645 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 }
1647
Derek Sollenberger03e48912010-05-18 17:03:42 -04001648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01001650 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001651 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 }
1653
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001654 /**
Steve Block4e584df2012-04-24 23:12:47 +01001655 * Gets the zoom controls for this WebView, as a separate View. The caller
1656 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001657 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01001658 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
1659 * built-in zoom mechanisms for the WebView, as opposed to these separate
1660 * zoom controls. The built-in mechanisms are preferred and can be enabled
1661 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07001662 *
Steve Block4e584df2012-04-24 23:12:47 +01001663 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01001664 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 */
The Android Open Source Project10592532009-03-18 17:39:46 -07001666 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01001668 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001669 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07001670 }
1671
1672 /**
Steve Block4e584df2012-04-24 23:12:47 +01001673 * Gets whether this WebView can be zoomed in.
1674 *
1675 * @return true if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04001676 *
1677 * @deprecated This method is prone to inaccuracy due to race conditions
1678 * between the web rendering and UI threads; prefer
1679 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001680 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001681 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001682 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001683 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001684 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07001685 }
1686
1687 /**
Steve Block4e584df2012-04-24 23:12:47 +01001688 * Gets whether this WebView can be zoomed out.
1689 *
1690 * @return true if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04001691 *
1692 * @deprecated This method is prone to inaccuracy due to race conditions
1693 * between the web rendering and UI threads; prefer
1694 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001695 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001696 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001697 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001698 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001699 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07001700 }
1701
1702 /**
Steve Block4e584df2012-04-24 23:12:47 +01001703 * Performs zoom in in this WebView.
1704 *
1705 * @return true if zoom in succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 */
1707 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001708 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001709 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 }
1711
1712 /**
Steve Block4e584df2012-04-24 23:12:47 +01001713 * Performs zoom out in this WebView.
1714 *
1715 * @return true if zoom out succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 */
1717 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001718 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001719 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 }
1721
Kristian Monsenfc771652011-05-10 16:44:05 +01001722 /**
1723 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001724 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01001725 */
1726 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01001728 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001730
John Reck926cf562012-06-14 10:00:31 -07001731 /**
John Reckf2361152012-06-14 15:23:22 -07001732 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07001733 * @hide
1734 */
1735 @Override
1736 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
1737 mProvider.dumpViewHierarchyWithProperties(out, level);
1738 }
1739
1740 /**
1741 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
1742 * @hide
1743 */
1744 @Override
1745 public View findHierarchyView(String className, int hashCode) {
1746 return mProvider.findHierarchyView(className, hashCode);
1747 }
1748
Jonathan Dixon3c909522012-02-28 18:45:06 +00001749 //-------------------------------------------------------------------------
1750 // Interface for WebView providers
1751 //-------------------------------------------------------------------------
1752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 /**
Steve Block4e584df2012-04-24 23:12:47 +01001754 * Gets the WebViewProvider. Used by providers to obtain the underlying
1755 * implementation, e.g. when the appliction responds to
1756 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04001757 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00001758 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04001759 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001760 public WebViewProvider getWebViewProvider() {
1761 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04001762 }
1763
1764 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001765 * Callback interface, allows the provider implementation to access non-public methods
1766 * and fields, and make super-class calls in this WebView instance.
1767 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001768 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001769 public class PrivateAccess {
1770 // ---- Access to super-class methods ----
1771 public int super_getScrollBarStyle() {
1772 return WebView.super.getScrollBarStyle();
1773 }
1774
1775 public void super_scrollTo(int scrollX, int scrollY) {
1776 WebView.super.scrollTo(scrollX, scrollY);
1777 }
1778
1779 public void super_computeScroll() {
1780 WebView.super.computeScroll();
1781 }
1782
alanveebebc92012-06-15 18:59:11 -07001783 public boolean super_onHoverEvent(MotionEvent event) {
1784 return WebView.super.onHoverEvent(event);
1785 }
1786
alanv448902d2012-05-16 20:27:47 -07001787 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
1788 return WebView.super.performAccessibilityAction(action, arguments);
1789 }
1790
Jonathan Dixon3c909522012-02-28 18:45:06 +00001791 public boolean super_performLongClick() {
1792 return WebView.super.performLongClick();
1793 }
1794
1795 public boolean super_setFrame(int left, int top, int right, int bottom) {
1796 return WebView.super.setFrame(left, top, right, bottom);
1797 }
1798
1799 public boolean super_dispatchKeyEvent(KeyEvent event) {
1800 return WebView.super.dispatchKeyEvent(event);
1801 }
1802
1803 public boolean super_onGenericMotionEvent(MotionEvent event) {
1804 return WebView.super.onGenericMotionEvent(event);
1805 }
1806
1807 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
1808 return WebView.super.requestFocus(direction, previouslyFocusedRect);
1809 }
1810
1811 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
1812 WebView.super.setLayoutParams(params);
1813 }
1814
1815 // ---- Access to non-public methods ----
1816 public void overScrollBy(int deltaX, int deltaY,
1817 int scrollX, int scrollY,
1818 int scrollRangeX, int scrollRangeY,
1819 int maxOverScrollX, int maxOverScrollY,
1820 boolean isTouchEvent) {
1821 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
1822 maxOverScrollX, maxOverScrollY, isTouchEvent);
1823 }
1824
1825 public void awakenScrollBars(int duration) {
1826 WebView.this.awakenScrollBars(duration);
1827 }
1828
1829 public void awakenScrollBars(int duration, boolean invalidate) {
1830 WebView.this.awakenScrollBars(duration, invalidate);
1831 }
1832
1833 public float getVerticalScrollFactor() {
1834 return WebView.this.getVerticalScrollFactor();
1835 }
1836
1837 public float getHorizontalScrollFactor() {
1838 return WebView.this.getHorizontalScrollFactor();
1839 }
1840
1841 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
1842 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
1843 }
1844
1845 public void onScrollChanged(int l, int t, int oldl, int oldt) {
1846 WebView.this.onScrollChanged(l, t, oldl, oldt);
1847 }
1848
1849 public int getHorizontalScrollbarHeight() {
1850 return WebView.this.getHorizontalScrollbarHeight();
1851 }
1852
1853 // ---- Access to (non-public) fields ----
1854 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
1855 public void setScrollXRaw(int scrollX) {
1856 WebView.this.mScrollX = scrollX;
1857 }
1858
1859 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
1860 public void setScrollYRaw(int scrollY) {
1861 WebView.this.mScrollY = scrollY;
1862 }
1863
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001864 }
1865
Jonathan Dixon3c909522012-02-28 18:45:06 +00001866 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001867 // Package-private internal stuff
1868 //-------------------------------------------------------------------------
1869
1870 // Only used by android.webkit.FindActionModeCallback.
1871 void setFindDialogFindListener(FindListener listener) {
1872 checkThread();
1873 setupFindListenerIfNeeded();
1874 mFindListener.mFindDialogFindListener = listener;
1875 }
1876
1877 // Only used by android.webkit.FindActionModeCallback.
1878 void notifyFindDialogDismissed() {
1879 checkThread();
1880 mProvider.notifyFindDialogDismissed();
1881 }
1882
1883 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00001884 // Private internal stuff
1885 //-------------------------------------------------------------------------
1886
Jonathan Dixon3c909522012-02-28 18:45:06 +00001887 private WebViewProvider mProvider;
1888
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001889 /**
1890 * In addition to the FindListener that the user may set via the WebView.setFindListener
1891 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
1892 * via this class so that that the two FindListeners can potentially exist at once.
1893 */
1894 private class FindListenerDistributor implements FindListener {
1895 private FindListener mFindDialogFindListener;
1896 private FindListener mUserFindListener;
1897
1898 @Override
1899 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
1900 boolean isDoneCounting) {
1901 if (mFindDialogFindListener != null) {
1902 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
1903 isDoneCounting);
1904 }
1905
1906 if (mUserFindListener != null) {
1907 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
1908 isDoneCounting);
1909 }
1910 }
1911 }
1912 private FindListenerDistributor mFindListener;
1913
1914 private void setupFindListenerIfNeeded() {
1915 if (mFindListener == null) {
1916 mFindListener = new FindListenerDistributor();
1917 mProvider.setFindListener(mFindListener);
1918 }
1919 }
1920
Jonathan Dixon3c909522012-02-28 18:45:06 +00001921 private void ensureProviderCreated() {
1922 checkThread();
1923 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001924 // As this can get called during the base class constructor chain, pass the minimum
1925 // number of dependencies here; the rest are deferred to init().
1926 mProvider = getFactory().createWebView(this, new PrivateAccess());
1927 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00001928 }
1929
Jonathan Dixon951fcab2012-08-20 16:37:15 -07001930 private static synchronized WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01001931 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00001932 }
1933
Steve Block51b08912011-04-27 15:04:48 +01001934 private static void checkThread() {
Steve Block08d584c2011-05-17 19:05:03 +01001935 if (Looper.myLooper() != Looper.getMainLooper()) {
Steve Block7a01d942011-09-26 12:30:31 +01001936 Throwable throwable = new Throwable(
1937 "Warning: A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01001938 Thread.currentThread().getName() + "'. " +
1939 "All WebView methods must be called on the UI thread. " +
1940 "Future versions of WebView may not support use on other threads.");
Steve Block7a01d942011-09-26 12:30:31 +01001941 Log.w(LOGTAG, Log.getStackTraceString(throwable));
1942 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07001943
1944 if (sEnforceThreadChecking) {
1945 throw new RuntimeException(throwable);
1946 }
Steve Block51b08912011-04-27 15:04:48 +01001947 }
1948 }
1949
Jonathan Dixon3c909522012-02-28 18:45:06 +00001950 //-------------------------------------------------------------------------
1951 // Override View methods
1952 //-------------------------------------------------------------------------
1953
1954 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
1955 // there's a corresponding override (or better, caller) for each of them in here.
1956
1957 @Override
1958 protected void onAttachedToWindow() {
1959 super.onAttachedToWindow();
1960 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07001961 }
1962
Jonathan Dixon3c909522012-02-28 18:45:06 +00001963 @Override
1964 protected void onDetachedFromWindow() {
1965 mProvider.getViewDelegate().onDetachedFromWindow();
1966 super.onDetachedFromWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07001967 }
1968
Jonathan Dixon3c909522012-02-28 18:45:06 +00001969 @Override
1970 public void setLayoutParams(ViewGroup.LayoutParams params) {
1971 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07001972 }
1973
Jonathan Dixon3c909522012-02-28 18:45:06 +00001974 @Override
1975 public void setOverScrollMode(int mode) {
1976 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00001977 // This method may be called in the constructor chain, before the WebView provider is
1978 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001979 ensureProviderCreated();
1980 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07001981 }
1982
Jonathan Dixon3c909522012-02-28 18:45:06 +00001983 @Override
1984 public void setScrollBarStyle(int style) {
1985 mProvider.getViewDelegate().setScrollBarStyle(style);
1986 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08001987 }
1988
Jonathan Dixon3c909522012-02-28 18:45:06 +00001989 @Override
1990 protected int computeHorizontalScrollRange() {
1991 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08001992 }
1993
Jonathan Dixon3c909522012-02-28 18:45:06 +00001994 @Override
1995 protected int computeHorizontalScrollOffset() {
1996 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
1997 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07001998
Jonathan Dixon3c909522012-02-28 18:45:06 +00001999 @Override
2000 protected int computeVerticalScrollRange() {
2001 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2002 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002003
Jonathan Dixon3c909522012-02-28 18:45:06 +00002004 @Override
2005 protected int computeVerticalScrollOffset() {
2006 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2007 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002008
Jonathan Dixon3c909522012-02-28 18:45:06 +00002009 @Override
2010 protected int computeVerticalScrollExtent() {
2011 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2012 }
2013
2014 @Override
2015 public void computeScroll() {
2016 mProvider.getScrollDelegate().computeScroll();
2017 }
2018
2019 @Override
2020 public boolean onHoverEvent(MotionEvent event) {
2021 return mProvider.getViewDelegate().onHoverEvent(event);
2022 }
2023
2024 @Override
2025 public boolean onTouchEvent(MotionEvent event) {
2026 return mProvider.getViewDelegate().onTouchEvent(event);
2027 }
2028
2029 @Override
2030 public boolean onGenericMotionEvent(MotionEvent event) {
2031 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2032 }
2033
2034 @Override
2035 public boolean onTrackballEvent(MotionEvent event) {
2036 return mProvider.getViewDelegate().onTrackballEvent(event);
2037 }
2038
2039 @Override
2040 public boolean onKeyDown(int keyCode, KeyEvent event) {
2041 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2042 }
2043
2044 @Override
2045 public boolean onKeyUp(int keyCode, KeyEvent event) {
2046 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2047 }
2048
2049 @Override
2050 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2051 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2052 }
2053
2054 /*
2055 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2056 to be delegating them too.
2057
2058 @Override
2059 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2060 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2061 }
2062 @Override
2063 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2064 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2065 }
2066 @Override
2067 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2068 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2069 }
2070 */
2071
Ben Murdoche3f90712013-06-05 14:19:48 +01002072 @Override
2073 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2074 AccessibilityNodeProvider provider =
2075 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2076 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2077 }
2078
Jonathan Dixon3c909522012-02-28 18:45:06 +00002079 @Deprecated
2080 @Override
2081 public boolean shouldDelayChildPressedState() {
2082 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2083 }
2084
2085 @Override
2086 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
2087 super.onInitializeAccessibilityNodeInfo(info);
alanvea077212012-03-30 14:59:42 -07002088 info.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002089 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
2090 }
2091
2092 @Override
2093 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2094 super.onInitializeAccessibilityEvent(event);
alanvea077212012-03-30 14:59:42 -07002095 event.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002096 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
2097 }
2098
alanv448902d2012-05-16 20:27:47 -07002099 @Override
2100 public boolean performAccessibilityAction(int action, Bundle arguments) {
2101 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
2102 }
2103
Jonathan Dixon3c909522012-02-28 18:45:06 +00002104 /** @hide */
2105 @Override
2106 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2107 int l, int t, int r, int b) {
2108 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2109 }
2110
2111 @Override
2112 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2113 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2114 }
2115
2116 @Override
2117 protected void onWindowVisibilityChanged(int visibility) {
2118 super.onWindowVisibilityChanged(visibility);
2119 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2120 }
2121
2122 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002123 protected void onDraw(Canvas canvas) {
2124 mProvider.getViewDelegate().onDraw(canvas);
2125 }
2126
2127 @Override
2128 public boolean performLongClick() {
2129 return mProvider.getViewDelegate().performLongClick();
2130 }
2131
2132 @Override
2133 protected void onConfigurationChanged(Configuration newConfig) {
2134 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2135 }
2136
2137 @Override
2138 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2139 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2140 }
2141
2142 @Override
2143 protected void onVisibilityChanged(View changedView, int visibility) {
2144 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002145 // This method may be called in the constructor chain, before the WebView provider is
2146 // created.
2147 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002148 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2149 }
2150
2151 @Override
2152 public void onWindowFocusChanged(boolean hasWindowFocus) {
2153 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2154 super.onWindowFocusChanged(hasWindowFocus);
2155 }
2156
2157 @Override
2158 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2159 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2160 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2161 }
2162
2163 /** @hide */
2164 @Override
2165 protected boolean setFrame(int left, int top, int right, int bottom) {
2166 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2167 }
2168
2169 @Override
2170 protected void onSizeChanged(int w, int h, int ow, int oh) {
2171 super.onSizeChanged(w, h, ow, oh);
2172 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2173 }
2174
2175 @Override
2176 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2177 super.onScrollChanged(l, t, oldl, oldt);
2178 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2179 }
2180
2181 @Override
2182 public boolean dispatchKeyEvent(KeyEvent event) {
2183 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2184 }
2185
2186 @Override
2187 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2188 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2189 }
2190
2191 @Deprecated
2192 @Override
2193 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2194 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2195 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2196 }
2197
2198 @Override
2199 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2200 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2201 }
2202
2203 @Override
2204 public void setBackgroundColor(int color) {
2205 mProvider.getViewDelegate().setBackgroundColor(color);
2206 }
John Recka5408e62012-03-16 14:18:44 -07002207
2208 @Override
2209 public void setLayerType(int layerType, Paint paint) {
2210 super.setLayerType(layerType, paint);
2211 mProvider.getViewDelegate().setLayerType(layerType, paint);
2212 }
Ben Murdoche623e242012-09-07 20:47:07 +01002213
2214 @Override
2215 protected void dispatchDraw(Canvas canvas) {
2216 mProvider.getViewDelegate().preDispatchDraw(canvas);
2217 super.dispatchDraw(canvas);
2218 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219}