blob: 49987428ceef29c1903260a783ed2bde30732214 [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;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050044import android.view.inputmethod.EditorInfo;
45import android.view.inputmethod.InputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010047
John Reck926cf562012-06-14 10:00:31 -070048import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import java.io.File;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010050import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52/**
Cary Clarkd6982c92009-05-29 11:02:22 -040053 * <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 -080054 * can roll your own web browser or simply display some online content within your Activity.
55 * It uses the WebKit rendering engine to display
56 * web pages and includes methods to navigate forward and backward
57 * through a history, zoom in and out, perform text searches and more.</p>
The Android Open Source Project10592532009-03-18 17:39:46 -070058 * <p>To enable the built-in zoom, set
59 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
Steve Blockb838aef2012-04-23 18:22:15 +010060 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 * <p>Note that, in order for your Activity to access the Internet and load web pages
Scott Main8b3cea02010-05-14 14:12:43 -070062 * in a WebView, you must add the {@code INTERNET} permissions to your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 * Android Manifest file:</p>
64 * <pre>&lt;uses-permission android:name="android.permission.INTERNET" /></pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010065 *
Scott Main8b3cea02010-05-14 14:12:43 -070066 * <p>This must be a child of the <a
Ben Dodson4e8620f2010-08-25 10:55:47 -070067 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
Scott Main8b3cea02010-05-14 14:12:43 -070068 * element.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010069 *
Scott Main4c359b72012-07-24 15:51:27 -070070 * <p>For more information, read
71 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p>
Scott Main41ec6532010-08-19 16:57:07 -070072 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010073 * <h3>Basic usage</h3>
74 *
75 * <p>By default, a WebView provides no browser-like widgets, does not
Scott Main8b3cea02010-05-14 14:12:43 -070076 * enable JavaScript and web page errors are ignored. If your goal is only
Mike Hearnadcd2ed2009-01-21 16:44:36 +010077 * to display some HTML as a part of your UI, this is probably fine;
78 * the user won't need to interact with the web page beyond reading
79 * it, and the web page won't need to interact with the user. If you
Scott Main8b3cea02010-05-14 14:12:43 -070080 * actually want a full-blown web browser, then you probably want to
81 * invoke the Browser application with a URL Intent rather than show it
82 * with a WebView. For example:
83 * <pre>
84 * Uri uri = Uri.parse("http://www.example.com");
85 * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
86 * startActivity(intent);
87 * </pre>
88 * <p>See {@link android.content.Intent} for more information.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010089 *
Ben Dodson4e8620f2010-08-25 10:55:47 -070090 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout,
Scott Main8b3cea02010-05-14 14:12:43 -070091 * or set the entire Activity window as a WebView during {@link
92 * android.app.Activity#onCreate(Bundle) onCreate()}:</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010093 * <pre class="prettyprint">
94 * WebView webview = new WebView(this);
95 * setContentView(webview);
Scott Main8b3cea02010-05-14 14:12:43 -070096 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010097 *
Scott Main8b3cea02010-05-14 14:12:43 -070098 * <p>Then load the desired web page:</p>
Scott Maine3b9f8b2010-05-18 08:41:36 -070099 * <pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100100 * // Simplest usage: note that an exception will NOT be thrown
101 * // if there is an error loading this page (see below).
102 * webview.loadUrl("http://slashdot.org/");
103 *
Scott Main8b3cea02010-05-14 14:12:43 -0700104 * // OR, you can also load from an HTML string:
Scott Maine3b9f8b2010-05-18 08:41:36 -0700105 * 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 +0100106 * webview.loadData(summary, "text/html", null);
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100107 * // ... although note that there are restrictions on what this HTML can do.
Scott Main8b3cea02010-05-14 14:12:43 -0700108 * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
109 * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100110 * </pre>
111 *
112 * <p>A WebView has several customization points where you can add your
113 * own behavior. These are:</p>
114 *
115 * <ul>
116 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass.
117 * This class is called when something that might impact a
118 * browser UI happens, for instance, progress updates and
Scott Main8b3cea02010-05-14 14:12:43 -0700119 * JavaScript alerts are sent here (see <a
120 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>).
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100121 * </li>
122 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass.
123 * It will be called when things happen that impact the
124 * rendering of the content, eg, errors or form submissions. You
Scott Main8b3cea02010-05-14 14:12:43 -0700125 * can also intercept URL loading here (via {@link
126 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String)
127 * shouldOverrideUrlLoading()}).</li>
128 * <li>Modifying the {@link android.webkit.WebSettings}, such as
129 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
130 * setJavaScriptEnabled()}. </li>
Steve Block4cd73c52011-11-09 13:06:52 +0000131 * <li>Injecting Java objects into the WebView using the
132 * {@link android.webkit.WebView#addJavascriptInterface} method. This
133 * method allows you to inject Java objects into a page's JavaScript
134 * context, so that they can be accessed by JavaScript in the page.</li>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100135 * </ul>
136 *
137 * <p>Here's a more complicated example, showing error handling,
138 * settings, and progress notification:</p>
139 *
140 * <pre class="prettyprint">
141 * // Let's display the progress in the activity title bar, like the
142 * // browser app does.
143 * getWindow().requestFeature(Window.FEATURE_PROGRESS);
144 *
145 * webview.getSettings().setJavaScriptEnabled(true);
146 *
147 * final Activity activity = this;
148 * webview.setWebChromeClient(new WebChromeClient() {
149 * public void onProgressChanged(WebView view, int progress) {
150 * // Activities and WebViews measure progress with different scales.
151 * // The progress meter will automatically disappear when we reach 100%
152 * activity.setProgress(progress * 1000);
153 * }
154 * });
155 * webview.setWebViewClient(new WebViewClient() {
156 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
157 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
158 * }
159 * });
160 *
161 * webview.loadUrl("http://slashdot.org/");
162 * </pre>
163 *
164 * <h3>Cookie and window management</h3>
165 *
166 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700167 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100168 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100169 * </p>
170 *
171 * <p>By default, requests by the HTML to open new windows are
172 * ignored. This is true whether they be opened by JavaScript or by
173 * the target attribute on a link. You can customize your
Scott Main8b3cea02010-05-14 14:12:43 -0700174 * {@link WebChromeClient} to provide your own behaviour for opening multiple windows,
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100175 * and render them in whatever manner you want.</p>
176 *
Scott Main8b3cea02010-05-14 14:12:43 -0700177 * <p>The standard behavior for an Activity is to be destroyed and
178 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100179 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700180 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100181 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700182 * re-orient itself as appropriate. Read <a
183 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
184 * more information about how to handle configuration changes during runtime.</p>
185 *
186 *
187 * <h3>Building web pages to support different screen densities</h3>
188 *
189 * <p>The screen density of a device is based on the screen resolution. A screen with low density
190 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700191 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700192 * screen is important because, other things being equal, a UI element (such as a button) whose
193 * height and width are defined in terms of screen pixels will appear larger on the lower density
194 * screen and smaller on the higher density screen.
195 * For simplicity, Android collapses all actual screen densities into three generalized densities:
196 * high, medium, and low.</p>
197 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
198 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
199 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
200 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100201 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
202 * and meta tag features to help you (as a web developer) target screens with different screen
203 * densities.</p>
Scott Main8b3cea02010-05-14 14:12:43 -0700204 * <p>Here's a summary of the features you can use to handle different screen densities:</p>
205 * <ul>
206 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
207 * default scaling factor used for the current device. For example, if the value of {@code
208 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
209 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
210 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
211 * 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 -0800212 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700213 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
214 * densities for which this style sheet is to be used. The corresponding value should be either
215 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
216 * density, or high density screens, respectively. For example:
217 * <pre>
218 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
219 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
220 * which is the high density pixel ratio.</p>
221 * </li>
Scott Main8b3cea02010-05-14 14:12:43 -0700222 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800223 * <h3>HTML5 Video support</h3>
224 *
225 * <p>In order to support inline HTML5 video in your application, you need to have hardware
226 * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support,
227 * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
228 * and {@link WebChromeClient#onHideCustomView()} are required,
229 * {@link WebChromeClient#getVideoLoadingProgressView()} is optional.
230 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
Steve Block406aeb22012-04-23 18:17:19 +0100232// Implementation notes.
233// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
234// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
235// Methods are delegated to the provider implementation: all public API methods introduced in this
236// file are fully delegated, whereas public and protected methods from the View base classes are
237// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800238@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400239public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700241 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242
Jonathan Dixon3c909522012-02-28 18:45:06 +0000243 private static final String LOGTAG = "webview_proxy";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700244
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700245 // Throwing an exception for incorrect thread usage if the
246 // build target is JB MR2 or newer. Defaults to false, and is
247 // set in the WebView constructor.
248 private static Boolean sEnforceThreadChecking = false;
249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 /**
251 * Transportation object for returning WebView across thread boundaries.
252 */
253 public class WebViewTransport {
254 private WebView mWebview;
255
256 /**
Steve Block4e584df2012-04-24 23:12:47 +0100257 * Sets the WebView to the transportation object.
258 *
259 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 */
261 public synchronized void setWebView(WebView webview) {
262 mWebview = webview;
263 }
264
265 /**
Steve Block4e584df2012-04-24 23:12:47 +0100266 * Gets the WebView object.
267 *
268 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 */
270 public synchronized WebView getWebView() {
271 return mWebview;
272 }
273 }
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 /**
Steve Block4e584df2012-04-24 23:12:47 +0100276 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 */
278 public static final String SCHEME_TEL = "tel:";
279 /**
Steve Block4e584df2012-04-24 23:12:47 +0100280 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 */
282 public static final String SCHEME_MAILTO = "mailto:";
283 /**
Steve Block4e584df2012-04-24 23:12:47 +0100284 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 */
286 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 /**
Victoria Leased405a432012-03-22 15:53:48 -0700289 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700290 */
291 public interface FindListener {
292 /**
Steve Block4e584df2012-04-24 23:12:47 +0100293 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700294 *
Steve Block4e584df2012-04-24 23:12:47 +0100295 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700296 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100297 * @param isDoneCounting whether the find operation has actually completed. The listener
298 * may be notified multiple times while the
299 * operation is underway, and the numberOfMatches
300 * value should not be considered final unless
301 * isDoneCounting is true.
Victoria Leased405a432012-03-22 15:53:48 -0700302 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700303 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700304 boolean isDoneCounting);
305 }
306
307 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100309 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100310 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100312 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 public interface PictureListener {
314 /**
Steve Block72498ed2012-07-17 15:57:25 +0100315 * Used to provide notification that the WebView's picture has changed.
316 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100317 *
318 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000319 * @param picture the new picture. Applications targeting
320 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
321 * will always receive a null Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100322 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100324 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 public void onNewPicture(WebView view, Picture picture);
326 }
327
Jonathan Dixon19644b62011-12-21 14:21:36 +0000328 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 /**
Steve Block4e584df2012-04-24 23:12:47 +0100330 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 */
332 public static final int UNKNOWN_TYPE = 0;
333 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100334 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 */
Steve Block1854ddb2011-04-19 12:18:19 +0100336 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 public static final int ANCHOR_TYPE = 1;
338 /**
Steve Block4e584df2012-04-24 23:12:47 +0100339 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 */
341 public static final int PHONE_TYPE = 2;
342 /**
Steve Block4e584df2012-04-24 23:12:47 +0100343 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 */
345 public static final int GEO_TYPE = 3;
346 /**
Steve Block4e584df2012-04-24 23:12:47 +0100347 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 */
349 public static final int EMAIL_TYPE = 4;
350 /**
Steve Block4e584df2012-04-24 23:12:47 +0100351 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 */
353 public static final int IMAGE_TYPE = 5;
354 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100355 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 */
Steve Block1854ddb2011-04-19 12:18:19 +0100357 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 public static final int IMAGE_ANCHOR_TYPE = 6;
359 /**
Steve Block4e584df2012-04-24 23:12:47 +0100360 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 */
362 public static final int SRC_ANCHOR_TYPE = 7;
363 /**
Steve Block4e584df2012-04-24 23:12:47 +0100364 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 */
366 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
367 /**
Steve Block4e584df2012-04-24 23:12:47 +0100368 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 */
370 public static final int EDIT_TEXT_TYPE = 9;
371
372 private int mType;
373 private String mExtra;
374
Jonathan Dixon3c909522012-02-28 18:45:06 +0000375 /**
376 * @hide Only for use by WebViewProvider implementations
377 */
378 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 mType = UNKNOWN_TYPE;
380 }
381
Jonathan Dixon3c909522012-02-28 18:45:06 +0000382 /**
383 * @hide Only for use by WebViewProvider implementations
384 */
385 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 mType = type;
387 }
388
Jonathan Dixon3c909522012-02-28 18:45:06 +0000389 /**
390 * @hide Only for use by WebViewProvider implementations
391 */
392 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 mExtra = extra;
394 }
395
Jonathan Dixone230e542011-12-21 10:57:00 +0000396 /**
Steve Block4e584df2012-04-24 23:12:47 +0100397 * Gets the type of the hit test result. See the XXX_TYPE constants
398 * defined in this class.
399 *
400 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000401 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 public int getType() {
403 return mType;
404 }
405
Jonathan Dixone230e542011-12-21 10:57:00 +0000406 /**
Steve Block4e584df2012-04-24 23:12:47 +0100407 * Gets additional type-dependant information about the result. See
408 * {@link WebView#getHitTestResult()} for details. May either be null
409 * or contain extra information about this result.
410 *
411 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000412 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 public String getExtra() {
414 return mExtra;
415 }
416 }
417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 /**
Steve Block4e584df2012-04-24 23:12:47 +0100419 * Constructs a new WebView with a Context object.
420 *
421 * @param context a Context object used to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 */
423 public WebView(Context context) {
424 this(context, null);
425 }
426
427 /**
Steve Block4e584df2012-04-24 23:12:47 +0100428 * Constructs a new WebView with layout parameters.
429 *
430 * @param context a Context object used to access application assets
431 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 */
433 public WebView(Context context, AttributeSet attrs) {
434 this(context, attrs, com.android.internal.R.attr.webViewStyle);
435 }
436
437 /**
Steve Block4e584df2012-04-24 23:12:47 +0100438 * Constructs a new WebView with layout parameters and a default style.
439 *
440 * @param context a Context object used to access application assets
441 * @param attrs an AttributeSet passed to our parent
442 * @param defStyle the default style resource ID
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 */
444 public WebView(Context context, AttributeSet attrs, int defStyle) {
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700445 this(context, attrs, defStyle, false);
446 }
447
448 /**
Steve Block4e584df2012-04-24 23:12:47 +0100449 * Constructs a new WebView with layout parameters and a default style.
450 *
451 * @param context a Context object used to access application assets
452 * @param attrs an AttributeSet passed to our parent
453 * @param defStyle the default style resource ID
454 * @param privateBrowsing whether this WebView will be initialized in
455 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400456 *
457 * @deprecated Private browsing is no longer supported directly via
458 * WebView and will be removed in a future release. Prefer using
459 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
460 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700461 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400462 @Deprecated
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700463 public WebView(Context context, AttributeSet attrs, int defStyle,
464 boolean privateBrowsing) {
465 this(context, attrs, defStyle, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100466 }
467
468 /**
Steve Block4e584df2012-04-24 23:12:47 +0100469 * Constructs a new WebView with layout parameters, a default style and a set
470 * of custom Javscript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800471 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100472 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100473 *
474 * @param context a Context object used to access application assets
475 * @param attrs an AttributeSet passed to our parent
476 * @param defStyle the default style resource ID
477 * @param javaScriptInterfaces a Map of interface names, as keys, and
478 * object implementing those interfaces, as
479 * values
480 * @param privateBrowsing whether this WebView will be initialized in
481 * private mode
Jonathan Dixon3c909522012-02-28 18:45:06 +0000482 * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100483 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100484 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000485 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100486 protected WebView(Context context, AttributeSet attrs, int defStyle,
Steve Block81f19ff2010-11-01 13:23:24 +0000487 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 super(context, attrs, defStyle);
Kristian Monsen87af7312011-09-09 02:12:51 +0100489 if (context == null) {
490 throw new IllegalArgumentException("Invalid context argument");
491 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700492 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
493 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000494 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100495
Jonathan Dixon3c909522012-02-28 18:45:06 +0000496 ensureProviderCreated();
497 mProvider.init(javaScriptInterfaces, privateBrowsing);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499
500 /**
Steve Block4e584df2012-04-24 23:12:47 +0100501 * Specifies whether the horizontal scrollbar has overlay style.
502 *
503 * @param overlay true if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 */
505 public void setHorizontalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100506 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000507 mProvider.setHorizontalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
509
510 /**
Steve Block4e584df2012-04-24 23:12:47 +0100511 * Specifies whether the vertical scrollbar has overlay style.
512 *
513 * @param overlay true if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 */
515 public void setVerticalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100516 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000517 mProvider.setVerticalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
519
520 /**
Steve Block4e584df2012-04-24 23:12:47 +0100521 * Gets whether horizontal scrollbar has overlay style.
522 *
523 * @return true if horizontal scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 */
525 public boolean overlayHorizontalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100526 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000527 return mProvider.overlayHorizontalScrollbar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 }
529
530 /**
Steve Block4e584df2012-04-24 23:12:47 +0100531 * Gets whether vertical scrollbar has overlay style.
532 *
533 * @return true if vertical scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 */
535 public boolean overlayVerticalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100536 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000537 return mProvider.overlayVerticalScrollbar();
Mike Reede8853fc2009-09-04 14:01:48 -0400538 }
539
Michael Kolbe54f6652011-03-16 09:11:51 -0700540 /**
Steve Block4e584df2012-04-24 23:12:47 +0100541 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700542 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700543 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400544 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400545 */
Michael Kolb73980a92010-08-05 16:32:51 -0700546 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100547 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000548 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550
551 /**
Steve Block4e584df2012-04-24 23:12:47 +0100552 * Gets the SSL certificate for the main top-level page or null if there is
553 * no certificate (the site is not secure).
554 *
555 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 */
557 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100558 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000559 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
561
562 /**
563 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400564 *
565 * @deprecated Calling this function has no useful effect, and will be
566 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400568 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100570 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000571 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573
574 //-------------------------------------------------------------------------
575 // Methods called by activity
576 //-------------------------------------------------------------------------
577
578 /**
Steve Block32fe4102012-07-17 16:29:11 +0100579 * Sets a username and password pair for the specified host. This data is
580 * used by the Webview to autocomplete username and password fields in web
581 * forms. Note that this is unrelated to the credentials used for HTTP
582 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100583 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000584 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100585 * @param username the username for the given host
586 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100587 * @see WebViewDatabase#clearUsernamePassword
588 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800589 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800591 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100593 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000594 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 }
596
597 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100598 * Stores HTTP authentication credentials for a given host and realm. This
599 * method is intended to be used with
600 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 *
Steve Block46ce1db2012-07-17 16:43:00 +0100602 * @param host the host to which the credentials apply
603 * @param realm the realm to which the credentials apply
604 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100605 * @param password the password
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800606 * @see #getHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100607 * @see WebViewDatabase#hasHttpAuthUsernamePassword
608 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 */
610 public void setHttpAuthUsernamePassword(String host, String realm,
611 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100612 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000613 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615
616 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100617 * Retrieves HTTP authentication credentials for a given host and realm.
618 * This method is intended to be used with
619 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 *
Steve Block46ce1db2012-07-17 16:43:00 +0100621 * @param host the host to which the credentials apply
622 * @param realm the realm to which the credentials apply
623 * @return the credentials as a String array, if found. The first element
624 * is the username and the second element is the password. Null if
625 * no credentials are found.
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800626 * @see #setHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100627 * @see WebViewDatabase#hasHttpAuthUsernamePassword
628 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 */
630 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100631 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000632 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400633 }
634
635 /**
Steve Block4e584df2012-04-24 23:12:47 +0100636 * Destroys the internal state of this WebView. This method should be called
637 * after this WebView has been removed from the view system. No other
638 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 */
640 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100641 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000642 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
644
645 /**
646 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100647 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100648 *
649 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400650 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100652 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 public static void enablePlatformNotifications() {
Steve Block51b08912011-04-27 15:04:48 +0100654 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000655 getFactory().getStatics().setPlatformNotificationsEnabled(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 }
657
658 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100659 * Disables platform notifications of data state and proxy changes.
660 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100661 *
662 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400663 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100665 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 public static void disablePlatformNotifications() {
Steve Block51b08912011-04-27 15:04:48 +0100667 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000668 getFactory().getStatics().setPlatformNotificationsEnabled(false);
Feng Qianb3081372009-06-29 15:55:18 -0700669 }
670
671 /**
Steve Block4e584df2012-04-24 23:12:47 +0100672 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000673 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100675 *
676 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 */
678 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100679 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000680 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 }
682
683 /**
Steve Block4e584df2012-04-24 23:12:47 +0100684 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
686 * method no longer stores the display data for this WebView. The previous
687 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400688 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100689 *
690 * @param outState the Bundle to store this WebView's state
691 * @return the same copy of the back/forward list used to save the state. If
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 * saveState fails, the returned list will be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 */
694 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100695 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000696 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 }
698
699 /**
Steve Block4e584df2012-04-24 23:12:47 +0100700 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100702 * @param b a Bundle to store the display data
703 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 * overwritten with this WebView's picture data.
Steve Block4e584df2012-04-24 23:12:47 +0100705 * @return true if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100706 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400707 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100709 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400710 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100711 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000712 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 }
714
715 /**
Steve Block4e584df2012-04-24 23:12:47 +0100716 * Restores the display data that was saved in {@link #savePicture}. Used in
717 * conjunction with {@link #restoreState}. Note that this will not work if
718 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700719 *
Steve Block4e584df2012-04-24 23:12:47 +0100720 * @param b a Bundle containing the saved display data
721 * @param src the file where the picture data was stored
722 * @return true if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100723 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400724 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100726 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100728 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000729 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700730 }
731
732 /**
Steve Block42499062012-07-17 15:34:46 +0100733 * Restores the state of this WebView from the given Bundle. This method is
734 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
735 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100736 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400737 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400739 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100740 *
741 * @param inState the incoming Bundle of state
742 * @return the restored back/forward list or null if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 */
744 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100745 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000746 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 }
748
749 /**
Steve Block4e584df2012-04-24 23:12:47 +0100750 * Loads the given URL with the specified additional HTTP headers.
751 *
752 * @param url the URL of the resource to load
753 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100754 * HTTP request for this URL, specified as a map from name to
755 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100756 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100757 * controlling caching, accept types or the User-Agent, their
Steve Block4e584df2012-04-24 23:12:47 +0100758 * values may be overriden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800759 */
Steve Blockf71dea02011-08-01 12:29:14 +0100760 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100761 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000762 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800763 }
764
765 /**
Steve Block4e584df2012-04-24 23:12:47 +0100766 * Loads the given URL.
767 *
768 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 */
770 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100771 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000772 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
774
775 /**
Steve Block4e584df2012-04-24 23:12:47 +0100776 * Loads the URL with postData using "POST" method into this WebView. If url
777 * is not a network URL, it will be loaded with {link
Grace Kloba57534302009-05-22 18:55:02 -0700778 * {@link #loadUrl(String)} instead.
Cary Clarkd6982c92009-05-29 11:02:22 -0400779 *
Steve Block4e584df2012-04-24 23:12:47 +0100780 * @param url the URL of the resource to load
781 * @param postData the data will be passed to "POST" request
Grace Kloba57534302009-05-22 18:55:02 -0700782 */
783 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100784 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000785 mProvider.postUrl(url, postData);
Grace Kloba57534302009-05-22 18:55:02 -0700786 }
787
788 /**
Steve Block4e584df2012-04-24 23:12:47 +0100789 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100790 * <p>
791 * Note that JavaScript's same origin policy means that script running in a
792 * page loaded using this method will be unable to access content loaded
793 * using any scheme other than 'data', including 'http(s)'. To avoid this
794 * restriction, use {@link
795 * #loadDataWithBaseURL(String,String,String,String,String)
796 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100797 * <p>
Steve Block27f3e322012-07-23 10:45:59 +0100798 * The encoding parameter specifies whether the data is base64 or URL
799 * encoded. If the data is base64 encoded, the value of the encoding
800 * parameter must be 'base64'. For all other values of the parameter,
801 * including null, it is assumed that the data uses ASCII encoding for
Steve Blockf95d4902011-06-09 11:53:26 +0100802 * octets inside the range of safe URL characters and use the standard %xx
Steve Block27f3e322012-07-23 10:45:59 +0100803 * hex encoding of URLs for octets outside that range. For example, '#',
804 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
Steve Blockb19c7872011-10-10 14:09:44 +0100805 * <p>
806 * The 'data' scheme URL formed by this method uses the default US-ASCII
807 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100808 * 'data' scheme URL which explicitly specifies a charset parameter in the
809 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
810 * Note that the charset obtained from the mediatype portion of a data URL
811 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +0100812 *
813 * @param data a String of data in the given encoding
814 * @param mimeType the MIME type of the data, e.g. 'text/html'
815 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 */
817 public void loadData(String data, String mimeType, String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100818 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000819 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 }
821
822 /**
Steve Block4e584df2012-04-24 23:12:47 +0100823 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100824 * the content. The base URL is used both to resolve relative URLs and when
825 * applying JavaScript's same origin policy. The historyUrl is used for the
826 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100828 * Note that content specified in this way can access local device files
829 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
830 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100831 * <p>
832 * If the base URL uses the data scheme, this method is equivalent to
833 * calling {@link #loadData(String,String,String) loadData()} and the
834 * historyUrl is ignored.
Steve Block4e584df2012-04-24 23:12:47 +0100835 *
836 * @param baseUrl the URL to use as the page's base URL. If null defaults to
837 * 'about:blank'.
838 * @param data a String of data in the given encoding
839 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
840 * defaults to 'text/html'.
841 * @param encoding the encoding of the data
842 * @param historyUrl the URL to use as the history entry. If null defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000843 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 */
845 public void loadDataWithBaseURL(String baseUrl, String data,
Leon Scroggins1bb1a912010-03-23 15:39:46 -0400846 String mimeType, String encoding, String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100847 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000848 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
850
851 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700852 * Saves the current view as a web archive.
853 *
Steve Block4e584df2012-04-24 23:12:47 +0100854 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700855 */
856 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100857 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000858 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700859 }
860
861 /**
862 * Saves the current view as a web archive.
863 *
Steve Block4e584df2012-04-24 23:12:47 +0100864 * @param basename the filename where the archive should be placed
865 * @param autoname if false, takes basename to be a file. If true, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700866 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100867 * chosen according to the URL of the current page.
868 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700869 * parameter for onReceiveValue will either be the filename
870 * under which the file was saved, or null if saving the
871 * file failed.
872 */
873 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
Steve Block51b08912011-04-27 15:04:48 +0100874 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000875 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700876 }
877
878 /**
Steve Block4e584df2012-04-24 23:12:47 +0100879 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 */
881 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100882 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000883 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
885
886 /**
Steve Block4e584df2012-04-24 23:12:47 +0100887 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 */
889 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100890 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000891 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 }
893
894 /**
Steve Block4e584df2012-04-24 23:12:47 +0100895 * Gets whether this WebView has a back history item.
896 *
897 * @return true iff this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 */
899 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +0100900 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000901 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 }
903
904 /**
Steve Block4e584df2012-04-24 23:12:47 +0100905 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 */
907 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +0100908 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000909 mProvider.goBack();
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 forward history item.
914 *
915 * @return true iff this Webview has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 */
917 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +0100918 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000919 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 }
921
922 /**
Steve Block4e584df2012-04-24 23:12:47 +0100923 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 */
925 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +0100926 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000927 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 }
929
930 /**
Steve Block4e584df2012-04-24 23:12:47 +0100931 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +0100933 *
934 * @param steps the negative or positive number of steps to move the
935 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 */
937 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100938 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000939 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941
942 /**
Steve Block4e584df2012-04-24 23:12:47 +0100943 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 * the current item. Steps is negative if backward and positive
945 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +0100946 *
947 * @param steps the number of steps to take back or forward in the back
948 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 */
950 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100951 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000952 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400954
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700955 /**
Steve Block4e584df2012-04-24 23:12:47 +0100956 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700957 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -0700958 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +0100959 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000960 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 /**
Steve Block4e584df2012-04-24 23:12:47 +0100964 * Scrolls the contents of this WebView up by half the view size.
965 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 * @param top true to jump to the top of the page
967 * @return true if the page was scrolled
968 */
969 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +0100970 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000971 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 /**
Steve Block4e584df2012-04-24 23:12:47 +0100975 * Scrolls the contents of this WebView down by half the page size.
976 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 * @param bottom true to jump to bottom of page
978 * @return true if the page was scrolled
979 */
980 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +0100981 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000982 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984
985 /**
Steve Block4e584df2012-04-24 23:12:47 +0100986 * Clears this WebView so that onDraw() will draw nothing but white background,
987 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800988 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
989 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800991 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +0100993 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000994 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 /**
Steve Block72498ed2012-07-17 15:57:25 +0100998 * Gets a new picture that captures the current contents of this WebView.
999 * The picture is of the entire document being displayed, and is not
1000 * limited to the area currently displayed by this WebView. Also, the
1001 * picture is a static copy and is unaffected by later changes to the
1002 * content being displayed.
1003 * <p>
1004 * Note that due to internal changes, for API levels between
1005 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1006 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1007 * picture does not include fixed position elements or scrollable divs.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 *
Steve Block72498ed2012-07-17 15:57:25 +01001009 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 */
1011 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001012 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001013 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 }
1015
Cary Clarkd6982c92009-05-29 11:02:22 -04001016 /**
Steve Block4e584df2012-04-24 23:12:47 +01001017 * Gets the current scale of this WebView.
1018 *
1019 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001020 *
1021 * @deprecated This method is prone to inaccuracy due to race conditions
1022 * between the web rendering and UI threads; prefer
1023 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001025 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001026 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001028 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001029 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001030 }
1031
1032 /**
Steve Block4e584df2012-04-24 23:12:47 +01001033 * Sets the initial scale for this WebView. 0 means default. If
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 * {@link WebSettings#getUseWideViewPort()} is true, it zooms out all the
1035 * way. Otherwise it starts with 100%. If initial scale is greater than 0,
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001036 * WebView starts with this value as initial scale.
1037 * Please note that unlike the scale properties in the viewport meta tag,
1038 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 *
Steve Block4e584df2012-04-24 23:12:47 +01001040 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 */
1042 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001043 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001044 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
1046
1047 /**
Steve Block4e584df2012-04-24 23:12:47 +01001048 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 * result in the zoom widget appearing on the screen to control the zoom
1050 * level of this WebView.
1051 */
1052 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001053 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001054 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
1056
1057 /**
Steve Block4e584df2012-04-24 23:12:47 +01001058 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1059 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1060 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1061 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1062 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001064 * 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 -08001065 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001066 * 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 -08001067 * a child node. If a phone number is found, the HitTestResult type is set
1068 * to PHONE_TYPE and the phone number is set in the "extra" field of
1069 * HitTestResult. If a map address is found, the HitTestResult type is set
1070 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1071 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1072 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1073 * HitTestResult type is set to UNKNOWN_TYPE.
1074 */
1075 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001076 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001077 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001078 }
1079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 /**
Steve Block4e584df2012-04-24 23:12:47 +01001081 * Requests the anchor or image element URL at the last tapped point.
Cary Clark861368a2010-12-15 11:24:37 -05001082 * If hrefMsg is null, this method returns immediately and does not
1083 * dispatch hrefMsg to its target. If the tapped point hits an image,
1084 * an anchor, or an image in an anchor, the message associates
1085 * strings in named keys in its data. The value paired with the key
1086 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001087 *
Steve Block4e584df2012-04-24 23:12:47 +01001088 * @param hrefMsg the message to be dispatched with the result of the
1089 * request. The message data contains three keys. "url"
1090 * returns the anchor's href attribute. "title" returns the
1091 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 */
1093 public void requestFocusNodeHref(Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001094 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001095 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 /**
Steve Block4e584df2012-04-24 23:12:47 +01001099 * Requests the URL of the image last touched by the user. msg will be sent
1100 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001101 *
Steve Block4e584df2012-04-24 23:12:47 +01001102 * @param msg the message to be dispatched with the result of the request
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 * as the data member with "url" as key. The result can be null.
1104 */
1105 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001106 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001107 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001108 }
1109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 /**
Steve Block4e584df2012-04-24 23:12:47 +01001111 * 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 -08001112 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001113 * that URL has begun, the current page may not have changed.
1114 *
1115 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 */
John Reck926cf562012-06-14 10:00:31 -07001117 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001119 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001120 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 /**
Steve Block4e584df2012-04-24 23:12:47 +01001124 * Gets the original URL for the current page. This is not always the same
1125 * as the URL passed to WebViewClient.onPageStarted because although the
1126 * load for that URL has begun, the current page may not have changed.
1127 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001129 *
1130 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 */
John Reck926cf562012-06-14 10:00:31 -07001132 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001134 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001135 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
1137
1138 /**
Steve Block4e584df2012-04-24 23:12:47 +01001139 * 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 -08001140 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001141 *
1142 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 */
John Reck926cf562012-06-14 10:00:31 -07001144 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001146 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001147 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
1149
1150 /**
Steve Block4e584df2012-04-24 23:12:47 +01001151 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001153 *
1154 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 */
1156 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001157 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001158 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
1160
1161 /**
Steve Block4e584df2012-04-24 23:12:47 +01001162 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001163 * a URL on this site's server pointing to the standard location of a
1164 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001165 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001166 * @hide
1167 */
1168 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001169 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001170 }
1171
1172 /**
Steve Block4e584df2012-04-24 23:12:47 +01001173 * Gets the progress for the current page.
1174 *
1175 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 */
1177 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001178 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001179 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 /**
Steve Block4e584df2012-04-24 23:12:47 +01001183 * Gets the height of the HTML content.
1184 *
1185 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 */
John Reck926cf562012-06-14 10:00:31 -07001187 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001189 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001190 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
1192
1193 /**
Steve Block4e584df2012-04-24 23:12:47 +01001194 * Gets the width of the HTML content.
1195 *
1196 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001197 * @hide
1198 */
John Reck926cf562012-06-14 10:00:31 -07001199 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001200 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001201 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001202 }
1203
1204 /**
Steve Block4e584df2012-04-24 23:12:47 +01001205 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1206 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001207 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 */
1209 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001210 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001211 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 }
1213
1214 /**
Steve Block4e584df2012-04-24 23:12:47 +01001215 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001216 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 */
1218 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001219 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001220 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 }
1222
1223 /**
Steve Block4e584df2012-04-24 23:12:47 +01001224 * Pauses any extra processing associated with this WebView and its
1225 * associated DOM, plugins, JavaScript etc. For example, if this WebView is
1226 * taken offscreen, this could be called to reduce unnecessary CPU or
1227 * network traffic. When this WebView is again "active", call onResume().
Steve Block81f19ff2010-11-01 13:23:24 +00001228 * Note that this differs from pauseTimers(), which affects all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001229 */
1230 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001231 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001232 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001233 }
1234
1235 /**
Steve Block4e584df2012-04-24 23:12:47 +01001236 * Resumes a WebView after a previous call to onPause().
Mike Reedd205d5b2009-05-27 11:02:29 -04001237 */
1238 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001239 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001240 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001241 }
1242
1243 /**
Steve Block4e584df2012-04-24 23:12:47 +01001244 * Gets whether this WebView is paused, meaning onPause() was called.
1245 * Calling onResume() sets the paused state back to false.
1246 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001247 * @hide
1248 */
1249 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001250 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001251 }
1252
1253 /**
Steve Block4e584df2012-04-24 23:12:47 +01001254 * Informs this WebView that memory is low so that it can free any available
1255 * memory.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001256 */
1257 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001258 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001259 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001260 }
1261
1262 /**
Steve Block4e584df2012-04-24 23:12:47 +01001263 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001264 * this will clear the cache for all WebViews used.
1265 *
Steve Block4e584df2012-04-24 23:12:47 +01001266 * @param includeDiskFiles if false, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 */
1268 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001269 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001270 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 }
1272
1273 /**
Steve Block219dfa42012-07-20 10:31:21 +01001274 * Removes the autocomplete popup from the currently focused form field, if
1275 * present. Note this only affects the display of the autocomplete popup,
1276 * it does not remove any saved form data from this WebView's store. To do
1277 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 */
1279 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001280 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001281 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 }
1283
1284 /**
Steve Block4e584df2012-04-24 23:12:47 +01001285 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 */
1287 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001288 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001289 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 }
1291
1292 /**
Steve Block4e584df2012-04-24 23:12:47 +01001293 * Clears the SSL preferences table stored in response to proceeding with
1294 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 */
1296 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001297 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001298 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 }
1300
1301 /**
Steve Block4e584df2012-04-24 23:12:47 +01001302 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 * back/forward list for use in querying each item in the history stack.
1304 * This is a copy of the private WebBackForwardList so it contains only a
1305 * snapshot of the current state. Multiple calls to this method may return
1306 * different objects. The object returned from this method will not be
1307 * updated to reflect any new state.
1308 */
1309 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001310 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001311 return mProvider.copyBackForwardList();
1312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 }
1314
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001315 /**
Steve Block4e584df2012-04-24 23:12:47 +01001316 * Registers the listener to be notified as find-on-page operations
1317 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001318 *
Steve Block4e584df2012-04-24 23:12:47 +01001319 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001320 */
1321 public void setFindListener(FindListener listener) {
1322 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001323 setupFindListenerIfNeeded();
1324 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001325 }
1326
1327 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001328 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001329 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001330 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1331 * has not been called yet, or if {@link #clearMatches} has been called since the
1332 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 *
Steve Block4e584df2012-04-24 23:12:47 +01001334 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001335 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 */
1337 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001338 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001339 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 }
1341
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001342 /**
Steve Block4e584df2012-04-24 23:12:47 +01001343 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001344 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001345 *
Steve Block4e584df2012-04-24 23:12:47 +01001346 * @param find the string to find
1347 * @return the number of occurances of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001348 * @deprecated {@link #findAllAsync} is preferred.
1349 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001351 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001353 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001354 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001355 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 }
1357
Cary Clark3403eb32010-03-03 10:05:16 -05001358 /**
Steve Block4e584df2012-04-24 23:12:47 +01001359 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001360 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001361 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001362 *
Steve Block4e584df2012-04-24 23:12:47 +01001363 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001364 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001365 */
1366 public void findAllAsync(String find) {
1367 checkThread();
1368 mProvider.findAllAsync(find);
1369 }
1370
1371 /**
Steve Block4e584df2012-04-24 23:12:47 +01001372 * Starts an ActionMode for finding text in this WebView. Only works if this
1373 * WebView is attached to the view system.
1374 *
1375 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001376 * Otherwise, the last String searched for in this WebView will
1377 * be used to start.
Steve Block4e584df2012-04-24 23:12:47 +01001378 * @param showIme if true, show the IME, assuming the user will begin typing.
1379 * If false and text is non-null, perform a find all.
1380 * @return true if the find dialog is shown, false otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001381 * @deprecated This method does not work reliably on all Android versions;
1382 * implementing a custom find dialog using WebView.findAllAsync()
1383 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001384 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001385 @Deprecated
Leon Scroggins571354f2011-01-04 10:12:41 -05001386 public boolean showFindDialog(String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001387 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001388 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001389 }
1390
1391 /**
Steve Block4e584df2012-04-24 23:12:47 +01001392 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 * location. Currently, only addresses in the United States are detected,
1394 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001395 * <ul>
1396 * <li>a house number</li>
1397 * <li>a street name</li>
1398 * <li>a street type (Road, Circle, etc), either spelled out or
1399 * abbreviated</li>
1400 * <li>a city name</li>
1401 * <li>a state or territory, either spelled out or two-letter abbr</li>
1402 * <li>an optional 5 digit or 9 digit zip code</li>
1403 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 * All names must be correctly capitalized, and the zip code, if present,
1405 * must be valid for the state. The street type must be a standard USPS
1406 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001407 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 *
Steve Block4e584df2012-04-24 23:12:47 +01001410 * @param addr the string to search for addresses
1411 * @return the address, or if no address is found, null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 */
1413 public static String findAddress(String addr) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001414 return getFactory().getStatics().findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 }
1416
Victoria Lease0b8413b2012-03-26 13:04:10 -07001417 /**
Steve Block4e584df2012-04-24 23:12:47 +01001418 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001419 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 */
1421 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001422 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001423 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 }
1425
1426 /**
Steve Block4e584df2012-04-24 23:12:47 +01001427 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 * message object will be dispatched with arg1 being set to 1 if images
1429 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001430 *
1431 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 */
1433 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001434 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001435 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 }
1437
1438 /**
Steve Block4e584df2012-04-24 23:12:47 +01001439 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001441 *
1442 * @param client an implementation of WebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 */
1444 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001445 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001446 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001447 }
1448
1449 /**
Steve Block4e584df2012-04-24 23:12:47 +01001450 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 * the rendering engine, and should be downloaded instead. This will replace
1452 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001453 *
1454 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 */
1456 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001457 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001458 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 }
1460
1461 /**
Steve Block4e584df2012-04-24 23:12:47 +01001462 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001463 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001465 *
1466 * @param client an implementation of WebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 */
1468 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001469 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001470 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001471 }
1472
1473 /**
Steve Block4e584df2012-04-24 23:12:47 +01001474 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001476 *
1477 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001478 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001480 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001482 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001483 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 }
1485
1486 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001487 * Injects the supplied Java object into this WebView. The object is
1488 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001489 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001490 * accessed from JavaScript. For applications targeted to API
1491 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001492 * and above, only public methods that are annotated with
1493 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001494 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001495 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001496 * important security note below for implications.
1497 * <p> Note that injected objects will not
Steve Block3aa800b2012-04-24 13:01:34 +01001498 * appear in JavaScript until the page is next (re)loaded. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001499 * <pre>
1500 * class JsObject {
1501 * {@literal @}JavascriptInterface
1502 * public String toString() { return "injectedObject"; }
1503 * }
1504 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001505 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1506 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001507 * <p>
1508 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001510 * <li> This method can be used to allow JavaScript to control the host
1511 * application. This is a powerful feature, but also presents a security
Selim Gurunb4c02e62012-09-12 13:36:21 -07001512 * risk for applications targeted to API level
Selim Gurune91d5be2012-09-11 16:11:22 -07001513 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because
1514 * JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001515 * injected object's public fields. Use of this method in a WebView
1516 * containing untrusted content could allow an attacker to manipulate the
1517 * host application in unintended ways, executing Java code with the
1518 * permissions of the host application. Use extreme care when using this
1519 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001520 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001521 * thread of this WebView. Care is therefore required to maintain thread
Steve Block4cd73c52011-11-09 13:06:52 +00001522 * safety.</li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001523 * <li> The Java object's fields are not accessible.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001524 * </ul>
1525 *
1526 * @param object the Java object to inject into this WebView's JavaScript
Steve Block4cd73c52011-11-09 13:06:52 +00001527 * context. Null values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001528 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 */
Steve Block4cd73c52011-11-09 13:06:52 +00001530 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001531 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001532 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 }
1534
1535 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001536 * Removes a previously injected Java object from this WebView. Note that
1537 * the removal will not be reflected in JavaScript until the page is next
1538 * (re)loaded. See {@link #addJavascriptInterface}.
1539 *
1540 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001541 */
Steve Block3aa800b2012-04-24 13:01:34 +01001542 public void removeJavascriptInterface(String name) {
Steve Block51b08912011-04-27 15:04:48 +01001543 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01001544 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001545 }
1546
1547 /**
Steve Block4e584df2012-04-24 23:12:47 +01001548 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001550 *
1551 * @return a WebSettings object that can be used to control this WebView's
1552 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 */
1554 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001555 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001556 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 }
1558
Jonathan Dixon3c909522012-02-28 18:45:06 +00001559 /**
Steve Block4e584df2012-04-24 23:12:47 +01001560 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001561 *
Steve Block4e584df2012-04-24 23:12:47 +01001562 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001563 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001564 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001565 */
Andrei Popescu385df692009-08-13 11:59:57 +01001566 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 public static synchronized PluginList getPluginList() {
Steve Block51b08912011-04-27 15:04:48 +01001568 checkThread();
Grace Klobabb245ea2009-11-10 13:13:24 -08001569 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 }
1571
Jonathan Dixon3c909522012-02-28 18:45:06 +00001572 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001573 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001574 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001575 */
Andrei Popescu385df692009-08-13 11:59:57 +01001576 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01001577 public void refreshPlugins(boolean reloadOpenPages) {
1578 checkThread();
1579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580
Cary Clark966641a2010-03-04 08:41:56 -05001581 /**
Steve Block4e584df2012-04-24 23:12:47 +01001582 * Puts this WebView into text selection mode. Do not rely on this
1583 * functionality; it will be deprecated in the future.
1584 *
Kristian Monsenfc771652011-05-10 16:44:05 +01001585 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001586 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05001587 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001588 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01001590 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07001591 }
1592
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001593 /**
1594 * @deprecated WebView no longer needs to implement
1595 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1596 */
George Mountfab67a12012-01-05 09:58:53 -08001597 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001598 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001599 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04001601
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001602 /**
1603 * @deprecated WebView no longer needs to implement
1604 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1605 */
George Mountfab67a12012-01-05 09:58:53 -08001606 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001607 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001608 @Deprecated
1609 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610
1611 /**
1612 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08001613 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 */
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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 @Deprecated
1618 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1619 }
1620
Kristian Monsen5cc23512012-08-09 15:33:08 -04001621 /**
1622 * @deprecated Only the default case, true, will be supported in a future version.
1623 */
1624 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01001626 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001627 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
1629
Derek Sollenberger03e48912010-05-18 17:03:42 -04001630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01001632 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001633 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 }
1635
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001636 /**
Steve Block4e584df2012-04-24 23:12:47 +01001637 * Gets the zoom controls for this WebView, as a separate View. The caller
1638 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001639 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01001640 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
1641 * built-in zoom mechanisms for the WebView, as opposed to these separate
1642 * zoom controls. The built-in mechanisms are preferred and can be enabled
1643 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07001644 *
Steve Block4e584df2012-04-24 23:12:47 +01001645 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01001646 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 */
The Android Open Source Project10592532009-03-18 17:39:46 -07001648 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01001650 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001651 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07001652 }
1653
1654 /**
Steve Block4e584df2012-04-24 23:12:47 +01001655 * Gets whether this WebView can be zoomed in.
1656 *
1657 * @return true if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04001658 *
1659 * @deprecated This method is prone to inaccuracy due to race conditions
1660 * between the web rendering and UI threads; prefer
1661 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001662 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001663 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001664 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001665 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001666 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07001667 }
1668
1669 /**
Steve Block4e584df2012-04-24 23:12:47 +01001670 * Gets whether this WebView can be zoomed out.
1671 *
1672 * @return true if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04001673 *
1674 * @deprecated This method is prone to inaccuracy due to race conditions
1675 * between the web rendering and UI threads; prefer
1676 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001677 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001678 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001679 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001680 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001681 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07001682 }
1683
1684 /**
Steve Block4e584df2012-04-24 23:12:47 +01001685 * Performs zoom in in this WebView.
1686 *
1687 * @return true if zoom in succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 */
1689 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001690 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001691 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 }
1693
1694 /**
Steve Block4e584df2012-04-24 23:12:47 +01001695 * Performs zoom out in this WebView.
1696 *
1697 * @return true if zoom out succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 */
1699 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001700 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001701 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 }
1703
Kristian Monsenfc771652011-05-10 16:44:05 +01001704 /**
1705 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001706 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01001707 */
1708 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01001710 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001712
John Reck926cf562012-06-14 10:00:31 -07001713 /**
John Reckf2361152012-06-14 15:23:22 -07001714 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07001715 * @hide
1716 */
1717 @Override
1718 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
1719 mProvider.dumpViewHierarchyWithProperties(out, level);
1720 }
1721
1722 /**
1723 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
1724 * @hide
1725 */
1726 @Override
1727 public View findHierarchyView(String className, int hashCode) {
1728 return mProvider.findHierarchyView(className, hashCode);
1729 }
1730
Jonathan Dixon3c909522012-02-28 18:45:06 +00001731 //-------------------------------------------------------------------------
1732 // Interface for WebView providers
1733 //-------------------------------------------------------------------------
1734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 /**
Steve Block4e584df2012-04-24 23:12:47 +01001736 * Gets the WebViewProvider. Used by providers to obtain the underlying
1737 * implementation, e.g. when the appliction responds to
1738 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04001739 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00001740 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04001741 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001742 public WebViewProvider getWebViewProvider() {
1743 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04001744 }
1745
1746 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001747 * Callback interface, allows the provider implementation to access non-public methods
1748 * and fields, and make super-class calls in this WebView instance.
1749 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001750 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001751 public class PrivateAccess {
1752 // ---- Access to super-class methods ----
1753 public int super_getScrollBarStyle() {
1754 return WebView.super.getScrollBarStyle();
1755 }
1756
1757 public void super_scrollTo(int scrollX, int scrollY) {
1758 WebView.super.scrollTo(scrollX, scrollY);
1759 }
1760
1761 public void super_computeScroll() {
1762 WebView.super.computeScroll();
1763 }
1764
alanveebebc92012-06-15 18:59:11 -07001765 public boolean super_onHoverEvent(MotionEvent event) {
1766 return WebView.super.onHoverEvent(event);
1767 }
1768
alanv448902d2012-05-16 20:27:47 -07001769 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
1770 return WebView.super.performAccessibilityAction(action, arguments);
1771 }
1772
Jonathan Dixon3c909522012-02-28 18:45:06 +00001773 public boolean super_performLongClick() {
1774 return WebView.super.performLongClick();
1775 }
1776
1777 public boolean super_setFrame(int left, int top, int right, int bottom) {
1778 return WebView.super.setFrame(left, top, right, bottom);
1779 }
1780
1781 public boolean super_dispatchKeyEvent(KeyEvent event) {
1782 return WebView.super.dispatchKeyEvent(event);
1783 }
1784
1785 public boolean super_onGenericMotionEvent(MotionEvent event) {
1786 return WebView.super.onGenericMotionEvent(event);
1787 }
1788
1789 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
1790 return WebView.super.requestFocus(direction, previouslyFocusedRect);
1791 }
1792
1793 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
1794 WebView.super.setLayoutParams(params);
1795 }
1796
1797 // ---- Access to non-public methods ----
1798 public void overScrollBy(int deltaX, int deltaY,
1799 int scrollX, int scrollY,
1800 int scrollRangeX, int scrollRangeY,
1801 int maxOverScrollX, int maxOverScrollY,
1802 boolean isTouchEvent) {
1803 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
1804 maxOverScrollX, maxOverScrollY, isTouchEvent);
1805 }
1806
1807 public void awakenScrollBars(int duration) {
1808 WebView.this.awakenScrollBars(duration);
1809 }
1810
1811 public void awakenScrollBars(int duration, boolean invalidate) {
1812 WebView.this.awakenScrollBars(duration, invalidate);
1813 }
1814
1815 public float getVerticalScrollFactor() {
1816 return WebView.this.getVerticalScrollFactor();
1817 }
1818
1819 public float getHorizontalScrollFactor() {
1820 return WebView.this.getHorizontalScrollFactor();
1821 }
1822
1823 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
1824 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
1825 }
1826
1827 public void onScrollChanged(int l, int t, int oldl, int oldt) {
1828 WebView.this.onScrollChanged(l, t, oldl, oldt);
1829 }
1830
1831 public int getHorizontalScrollbarHeight() {
1832 return WebView.this.getHorizontalScrollbarHeight();
1833 }
1834
1835 // ---- Access to (non-public) fields ----
1836 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
1837 public void setScrollXRaw(int scrollX) {
1838 WebView.this.mScrollX = scrollX;
1839 }
1840
1841 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
1842 public void setScrollYRaw(int scrollY) {
1843 WebView.this.mScrollY = scrollY;
1844 }
1845
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001846 }
1847
Jonathan Dixon3c909522012-02-28 18:45:06 +00001848 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001849 // Package-private internal stuff
1850 //-------------------------------------------------------------------------
1851
1852 // Only used by android.webkit.FindActionModeCallback.
1853 void setFindDialogFindListener(FindListener listener) {
1854 checkThread();
1855 setupFindListenerIfNeeded();
1856 mFindListener.mFindDialogFindListener = listener;
1857 }
1858
1859 // Only used by android.webkit.FindActionModeCallback.
1860 void notifyFindDialogDismissed() {
1861 checkThread();
1862 mProvider.notifyFindDialogDismissed();
1863 }
1864
1865 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00001866 // Private internal stuff
1867 //-------------------------------------------------------------------------
1868
Jonathan Dixon3c909522012-02-28 18:45:06 +00001869 private WebViewProvider mProvider;
1870
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001871 /**
1872 * In addition to the FindListener that the user may set via the WebView.setFindListener
1873 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
1874 * via this class so that that the two FindListeners can potentially exist at once.
1875 */
1876 private class FindListenerDistributor implements FindListener {
1877 private FindListener mFindDialogFindListener;
1878 private FindListener mUserFindListener;
1879
1880 @Override
1881 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
1882 boolean isDoneCounting) {
1883 if (mFindDialogFindListener != null) {
1884 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
1885 isDoneCounting);
1886 }
1887
1888 if (mUserFindListener != null) {
1889 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
1890 isDoneCounting);
1891 }
1892 }
1893 }
1894 private FindListenerDistributor mFindListener;
1895
1896 private void setupFindListenerIfNeeded() {
1897 if (mFindListener == null) {
1898 mFindListener = new FindListenerDistributor();
1899 mProvider.setFindListener(mFindListener);
1900 }
1901 }
1902
Jonathan Dixon3c909522012-02-28 18:45:06 +00001903 private void ensureProviderCreated() {
1904 checkThread();
1905 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001906 // As this can get called during the base class constructor chain, pass the minimum
1907 // number of dependencies here; the rest are deferred to init().
1908 mProvider = getFactory().createWebView(this, new PrivateAccess());
1909 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00001910 }
1911
Jonathan Dixon951fcab2012-08-20 16:37:15 -07001912 private static synchronized WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01001913 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00001914 }
1915
Steve Block51b08912011-04-27 15:04:48 +01001916 private static void checkThread() {
Steve Block08d584c2011-05-17 19:05:03 +01001917 if (Looper.myLooper() != Looper.getMainLooper()) {
Steve Block7a01d942011-09-26 12:30:31 +01001918 Throwable throwable = new Throwable(
1919 "Warning: A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01001920 Thread.currentThread().getName() + "'. " +
1921 "All WebView methods must be called on the UI thread. " +
1922 "Future versions of WebView may not support use on other threads.");
Steve Block7a01d942011-09-26 12:30:31 +01001923 Log.w(LOGTAG, Log.getStackTraceString(throwable));
1924 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07001925
1926 if (sEnforceThreadChecking) {
1927 throw new RuntimeException(throwable);
1928 }
Steve Block51b08912011-04-27 15:04:48 +01001929 }
1930 }
1931
Jonathan Dixon3c909522012-02-28 18:45:06 +00001932 //-------------------------------------------------------------------------
1933 // Override View methods
1934 //-------------------------------------------------------------------------
1935
1936 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
1937 // there's a corresponding override (or better, caller) for each of them in here.
1938
1939 @Override
1940 protected void onAttachedToWindow() {
1941 super.onAttachedToWindow();
1942 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07001943 }
1944
Jonathan Dixon3c909522012-02-28 18:45:06 +00001945 @Override
1946 protected void onDetachedFromWindow() {
1947 mProvider.getViewDelegate().onDetachedFromWindow();
1948 super.onDetachedFromWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07001949 }
1950
Jonathan Dixon3c909522012-02-28 18:45:06 +00001951 @Override
1952 public void setLayoutParams(ViewGroup.LayoutParams params) {
1953 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07001954 }
1955
Jonathan Dixon3c909522012-02-28 18:45:06 +00001956 @Override
1957 public void setOverScrollMode(int mode) {
1958 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00001959 // This method may be called in the constructor chain, before the WebView provider is
1960 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001961 ensureProviderCreated();
1962 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07001963 }
1964
Jonathan Dixon3c909522012-02-28 18:45:06 +00001965 @Override
1966 public void setScrollBarStyle(int style) {
1967 mProvider.getViewDelegate().setScrollBarStyle(style);
1968 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08001969 }
1970
Jonathan Dixon3c909522012-02-28 18:45:06 +00001971 @Override
1972 protected int computeHorizontalScrollRange() {
1973 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08001974 }
1975
Jonathan Dixon3c909522012-02-28 18:45:06 +00001976 @Override
1977 protected int computeHorizontalScrollOffset() {
1978 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
1979 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07001980
Jonathan Dixon3c909522012-02-28 18:45:06 +00001981 @Override
1982 protected int computeVerticalScrollRange() {
1983 return mProvider.getScrollDelegate().computeVerticalScrollRange();
1984 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04001985
Jonathan Dixon3c909522012-02-28 18:45:06 +00001986 @Override
1987 protected int computeVerticalScrollOffset() {
1988 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
1989 }
Ben Murdochfa148f62011-02-01 20:51:27 +00001990
Jonathan Dixon3c909522012-02-28 18:45:06 +00001991 @Override
1992 protected int computeVerticalScrollExtent() {
1993 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
1994 }
1995
1996 @Override
1997 public void computeScroll() {
1998 mProvider.getScrollDelegate().computeScroll();
1999 }
2000
2001 @Override
2002 public boolean onHoverEvent(MotionEvent event) {
2003 return mProvider.getViewDelegate().onHoverEvent(event);
2004 }
2005
2006 @Override
2007 public boolean onTouchEvent(MotionEvent event) {
2008 return mProvider.getViewDelegate().onTouchEvent(event);
2009 }
2010
2011 @Override
2012 public boolean onGenericMotionEvent(MotionEvent event) {
2013 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2014 }
2015
2016 @Override
2017 public boolean onTrackballEvent(MotionEvent event) {
2018 return mProvider.getViewDelegate().onTrackballEvent(event);
2019 }
2020
2021 @Override
2022 public boolean onKeyDown(int keyCode, KeyEvent event) {
2023 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2024 }
2025
2026 @Override
2027 public boolean onKeyUp(int keyCode, KeyEvent event) {
2028 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2029 }
2030
2031 @Override
2032 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2033 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2034 }
2035
2036 /*
2037 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2038 to be delegating them too.
2039
2040 @Override
2041 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2042 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2043 }
2044 @Override
2045 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2046 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2047 }
2048 @Override
2049 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2050 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2051 }
2052 */
2053
2054 @Deprecated
2055 @Override
2056 public boolean shouldDelayChildPressedState() {
2057 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2058 }
2059
2060 @Override
2061 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
2062 super.onInitializeAccessibilityNodeInfo(info);
alanvea077212012-03-30 14:59:42 -07002063 info.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002064 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
2065 }
2066
2067 @Override
2068 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2069 super.onInitializeAccessibilityEvent(event);
alanvea077212012-03-30 14:59:42 -07002070 event.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002071 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
2072 }
2073
alanv448902d2012-05-16 20:27:47 -07002074 @Override
2075 public boolean performAccessibilityAction(int action, Bundle arguments) {
2076 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
2077 }
2078
Jonathan Dixon3c909522012-02-28 18:45:06 +00002079 /** @hide */
2080 @Override
2081 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2082 int l, int t, int r, int b) {
2083 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2084 }
2085
2086 @Override
2087 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2088 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2089 }
2090
2091 @Override
2092 protected void onWindowVisibilityChanged(int visibility) {
2093 super.onWindowVisibilityChanged(visibility);
2094 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2095 }
2096
2097 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002098 protected void onDraw(Canvas canvas) {
2099 mProvider.getViewDelegate().onDraw(canvas);
2100 }
2101
2102 @Override
2103 public boolean performLongClick() {
2104 return mProvider.getViewDelegate().performLongClick();
2105 }
2106
2107 @Override
2108 protected void onConfigurationChanged(Configuration newConfig) {
2109 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2110 }
2111
2112 @Override
2113 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2114 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2115 }
2116
2117 @Override
2118 protected void onVisibilityChanged(View changedView, int visibility) {
2119 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002120 // This method may be called in the constructor chain, before the WebView provider is
2121 // created.
2122 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002123 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2124 }
2125
2126 @Override
2127 public void onWindowFocusChanged(boolean hasWindowFocus) {
2128 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2129 super.onWindowFocusChanged(hasWindowFocus);
2130 }
2131
2132 @Override
2133 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2134 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2135 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2136 }
2137
2138 /** @hide */
2139 @Override
2140 protected boolean setFrame(int left, int top, int right, int bottom) {
2141 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2142 }
2143
2144 @Override
2145 protected void onSizeChanged(int w, int h, int ow, int oh) {
2146 super.onSizeChanged(w, h, ow, oh);
2147 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2148 }
2149
2150 @Override
2151 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2152 super.onScrollChanged(l, t, oldl, oldt);
2153 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2154 }
2155
2156 @Override
2157 public boolean dispatchKeyEvent(KeyEvent event) {
2158 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2159 }
2160
2161 @Override
2162 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2163 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2164 }
2165
2166 @Deprecated
2167 @Override
2168 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2169 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2170 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2171 }
2172
2173 @Override
2174 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2175 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2176 }
2177
2178 @Override
2179 public void setBackgroundColor(int color) {
2180 mProvider.getViewDelegate().setBackgroundColor(color);
2181 }
John Recka5408e62012-03-16 14:18:44 -07002182
2183 @Override
2184 public void setLayerType(int layerType, Paint paint) {
2185 super.setLayerType(layerType, paint);
2186 mProvider.getViewDelegate().setLayerType(layerType, paint);
2187 }
Ben Murdoche623e242012-09-07 20:47:07 +01002188
2189 @Override
2190 protected void dispatchDraw(Canvas canvas) {
2191 mProvider.getViewDelegate().preDispatchDraw(canvas);
2192 super.dispatchDraw(canvas);
2193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194}