blob: 5bc39f1584084bfc45b5b470c226c7f9cf636e2c [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;
Selim Gurunfc3f4ee2013-08-20 07:04:20 -070031import android.os.CancellationSignal;
Steve Block08d584c2011-05-17 19:05:03 +010032import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.Message;
Steve Block08d584c2011-05-17 19:05:03 +010034import android.os.StrictMode;
Selim Guruna5c86c62013-09-06 14:39:05 -070035import android.print.PrintDocumentAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070041import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.view.ViewGroup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070044import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070045import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010046import android.view.accessibility.AccessibilityNodeProvider;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050047import android.view.inputmethod.EditorInfo;
48import android.view.inputmethod.InputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010050
John Reck926cf562012-06-14 10:00:31 -070051import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import java.io.File;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010053import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55/**
Cary Clarkd6982c92009-05-29 11:02:22 -040056 * <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 -080057 * can roll your own web browser or simply display some online content within your Activity.
58 * It uses the WebKit rendering engine to display
59 * web pages and includes methods to navigate forward and backward
60 * through a history, zoom in and out, perform text searches and more.</p>
61 * <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 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700161 * webview.loadUrl("http://developer.android.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100162 * </pre>
163 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700164 * <h3>Zoom</h3>
165 *
166 * <p>To enable the built-in zoom, set
167 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
168 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).</p>
169 * <p>NOTE: Using zoom if either the height or width is set to
170 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} may lead to undefined behavior
171 * and should be avoided.</p>
172 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100173 * <h3>Cookie and window management</h3>
174 *
175 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700176 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100177 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100178 * </p>
179 *
180 * <p>By default, requests by the HTML to open new windows are
181 * ignored. This is true whether they be opened by JavaScript or by
182 * the target attribute on a link. You can customize your
Scott Main8b3cea02010-05-14 14:12:43 -0700183 * {@link WebChromeClient} to provide your own behaviour for opening multiple windows,
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100184 * and render them in whatever manner you want.</p>
185 *
Scott Main8b3cea02010-05-14 14:12:43 -0700186 * <p>The standard behavior for an Activity is to be destroyed and
187 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100188 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700189 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100190 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700191 * re-orient itself as appropriate. Read <a
192 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
193 * more information about how to handle configuration changes during runtime.</p>
194 *
195 *
196 * <h3>Building web pages to support different screen densities</h3>
197 *
198 * <p>The screen density of a device is based on the screen resolution. A screen with low density
199 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700200 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700201 * screen is important because, other things being equal, a UI element (such as a button) whose
202 * height and width are defined in terms of screen pixels will appear larger on the lower density
203 * screen and smaller on the higher density screen.
204 * For simplicity, Android collapses all actual screen densities into three generalized densities:
205 * high, medium, and low.</p>
206 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
207 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
208 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
209 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100210 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
211 * and meta tag features to help you (as a web developer) target screens with different screen
212 * densities.</p>
Scott Main8b3cea02010-05-14 14:12:43 -0700213 * <p>Here's a summary of the features you can use to handle different screen densities:</p>
214 * <ul>
215 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
216 * default scaling factor used for the current device. For example, if the value of {@code
217 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
218 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
219 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
220 * 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 -0800221 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700222 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
223 * densities for which this style sheet is to be used. The corresponding value should be either
224 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
225 * density, or high density screens, respectively. For example:
226 * <pre>
227 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
228 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
229 * which is the high density pixel ratio.</p>
230 * </li>
Martin Kosiba0d147d92013-09-19 19:05:00 -0700231 * </ul>
Scott Main8b3cea02010-05-14 14:12:43 -0700232 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800233 * <h3>HTML5 Video support</h3>
234 *
235 * <p>In order to support inline HTML5 video in your application, you need to have hardware
236 * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support,
237 * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
238 * and {@link WebChromeClient#onHideCustomView()} are required,
239 * {@link WebChromeClient#getVideoLoadingProgressView()} is optional.
240 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 */
Steve Block406aeb22012-04-23 18:17:19 +0100242// Implementation notes.
243// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
244// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
245// Methods are delegated to the provider implementation: all public API methods introduced in this
246// file are fully delegated, whereas public and protected methods from the View base classes are
247// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800248@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400249public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700251 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700253 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700254
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700255 // Throwing an exception for incorrect thread usage if the
256 // build target is JB MR2 or newer. Defaults to false, and is
257 // set in the WebView constructor.
258 private static Boolean sEnforceThreadChecking = false;
259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 /**
261 * Transportation object for returning WebView across thread boundaries.
262 */
263 public class WebViewTransport {
264 private WebView mWebview;
265
266 /**
Steve Block4e584df2012-04-24 23:12:47 +0100267 * Sets the WebView to the transportation object.
268 *
269 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 */
271 public synchronized void setWebView(WebView webview) {
272 mWebview = webview;
273 }
274
275 /**
Steve Block4e584df2012-04-24 23:12:47 +0100276 * Gets the WebView object.
277 *
278 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 */
280 public synchronized WebView getWebView() {
281 return mWebview;
282 }
283 }
284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
Steve Block4e584df2012-04-24 23:12:47 +0100286 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 */
288 public static final String SCHEME_TEL = "tel:";
289 /**
Steve Block4e584df2012-04-24 23:12:47 +0100290 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 */
292 public static final String SCHEME_MAILTO = "mailto:";
293 /**
Steve Block4e584df2012-04-24 23:12:47 +0100294 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 */
296 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 /**
Victoria Leased405a432012-03-22 15:53:48 -0700299 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700300 */
301 public interface FindListener {
302 /**
Steve Block4e584df2012-04-24 23:12:47 +0100303 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700304 *
Steve Block4e584df2012-04-24 23:12:47 +0100305 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700306 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100307 * @param isDoneCounting whether the find operation has actually completed. The listener
308 * may be notified multiple times while the
309 * operation is underway, and the numberOfMatches
310 * value should not be considered final unless
311 * isDoneCounting is true.
Victoria Leased405a432012-03-22 15:53:48 -0700312 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700313 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700314 boolean isDoneCounting);
315 }
316
317 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100319 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100320 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100322 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 public interface PictureListener {
324 /**
Steve Block72498ed2012-07-17 15:57:25 +0100325 * Used to provide notification that the WebView's picture has changed.
326 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100327 *
328 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000329 * @param picture the new picture. Applications targeting
330 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
331 * will always receive a null Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100332 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100334 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 public void onNewPicture(WebView view, Picture picture);
336 }
337
Jonathan Dixon19644b62011-12-21 14:21:36 +0000338 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /**
Steve Block4e584df2012-04-24 23:12:47 +0100340 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
342 public static final int UNKNOWN_TYPE = 0;
343 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100344 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 */
Steve Block1854ddb2011-04-19 12:18:19 +0100346 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 public static final int ANCHOR_TYPE = 1;
348 /**
Steve Block4e584df2012-04-24 23:12:47 +0100349 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 */
351 public static final int PHONE_TYPE = 2;
352 /**
Steve Block4e584df2012-04-24 23:12:47 +0100353 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 */
355 public static final int GEO_TYPE = 3;
356 /**
Steve Block4e584df2012-04-24 23:12:47 +0100357 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 */
359 public static final int EMAIL_TYPE = 4;
360 /**
Steve Block4e584df2012-04-24 23:12:47 +0100361 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 */
363 public static final int IMAGE_TYPE = 5;
364 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100365 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 */
Steve Block1854ddb2011-04-19 12:18:19 +0100367 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 public static final int IMAGE_ANCHOR_TYPE = 6;
369 /**
Steve Block4e584df2012-04-24 23:12:47 +0100370 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 */
372 public static final int SRC_ANCHOR_TYPE = 7;
373 /**
Steve Block4e584df2012-04-24 23:12:47 +0100374 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 */
376 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
377 /**
Steve Block4e584df2012-04-24 23:12:47 +0100378 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 */
380 public static final int EDIT_TEXT_TYPE = 9;
381
382 private int mType;
383 private String mExtra;
384
Jonathan Dixon3c909522012-02-28 18:45:06 +0000385 /**
386 * @hide Only for use by WebViewProvider implementations
387 */
388 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 mType = UNKNOWN_TYPE;
390 }
391
Jonathan Dixon3c909522012-02-28 18:45:06 +0000392 /**
393 * @hide Only for use by WebViewProvider implementations
394 */
395 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 mType = type;
397 }
398
Jonathan Dixon3c909522012-02-28 18:45:06 +0000399 /**
400 * @hide Only for use by WebViewProvider implementations
401 */
402 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 mExtra = extra;
404 }
405
Jonathan Dixone230e542011-12-21 10:57:00 +0000406 /**
Steve Block4e584df2012-04-24 23:12:47 +0100407 * Gets the type of the hit test result. See the XXX_TYPE constants
408 * defined in this class.
409 *
410 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000411 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 public int getType() {
413 return mType;
414 }
415
Jonathan Dixone230e542011-12-21 10:57:00 +0000416 /**
Steve Block4e584df2012-04-24 23:12:47 +0100417 * Gets additional type-dependant information about the result. See
418 * {@link WebView#getHitTestResult()} for details. May either be null
419 * or contain extra information about this result.
420 *
421 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000422 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 public String getExtra() {
424 return mExtra;
425 }
426 }
427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 /**
Steve Block4e584df2012-04-24 23:12:47 +0100429 * Constructs a new WebView with a Context object.
430 *
431 * @param context a Context object used to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 */
433 public WebView(Context context) {
434 this(context, null);
435 }
436
437 /**
Steve Block4e584df2012-04-24 23:12:47 +0100438 * Constructs a new WebView with layout parameters.
439 *
440 * @param context a Context object used to access application assets
441 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 */
443 public WebView(Context context, AttributeSet attrs) {
444 this(context, attrs, com.android.internal.R.attr.webViewStyle);
445 }
446
447 /**
Steve Block4e584df2012-04-24 23:12:47 +0100448 * Constructs a new WebView with layout parameters and a default style.
449 *
450 * @param context a Context object used to access application assets
451 * @param attrs an AttributeSet passed to our parent
452 * @param defStyle the default style resource ID
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 */
454 public WebView(Context context, AttributeSet attrs, int defStyle) {
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700455 this(context, attrs, defStyle, false);
456 }
457
458 /**
Steve Block4e584df2012-04-24 23:12:47 +0100459 * Constructs a new WebView with layout parameters and a default style.
460 *
461 * @param context a Context object used to access application assets
462 * @param attrs an AttributeSet passed to our parent
463 * @param defStyle the default style resource ID
464 * @param privateBrowsing whether this WebView will be initialized in
465 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400466 *
467 * @deprecated Private browsing is no longer supported directly via
468 * WebView and will be removed in a future release. Prefer using
469 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
470 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700471 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400472 @Deprecated
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700473 public WebView(Context context, AttributeSet attrs, int defStyle,
474 boolean privateBrowsing) {
475 this(context, attrs, defStyle, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100476 }
477
478 /**
Steve Block4e584df2012-04-24 23:12:47 +0100479 * Constructs a new WebView with layout parameters, a default style and a set
480 * of custom Javscript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800481 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100482 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100483 *
484 * @param context a Context object used to access application assets
485 * @param attrs an AttributeSet passed to our parent
486 * @param defStyle the default style resource ID
487 * @param javaScriptInterfaces a Map of interface names, as keys, and
488 * object implementing those interfaces, as
489 * values
490 * @param privateBrowsing whether this WebView will be initialized in
491 * private mode
Jonathan Dixon3c909522012-02-28 18:45:06 +0000492 * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100493 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100494 */
Jonathan Dixon3c909522012-02-28 18:45:06 +0000495 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100496 protected WebView(Context context, AttributeSet attrs, int defStyle,
Steve Block81f19ff2010-11-01 13:23:24 +0000497 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 super(context, attrs, defStyle);
Kristian Monsen87af7312011-09-09 02:12:51 +0100499 if (context == null) {
500 throw new IllegalArgumentException("Invalid context argument");
501 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700502 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
503 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000504 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700505 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "WebView<init>");
Kristian Monsen87af7312011-09-09 02:12:51 +0100506
Jonathan Dixon3c909522012-02-28 18:45:06 +0000507 ensureProviderCreated();
508 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100509 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
510 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
512
513 /**
Steve Block4e584df2012-04-24 23:12:47 +0100514 * Specifies whether the horizontal scrollbar has overlay style.
515 *
516 * @param overlay true if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 */
518 public void setHorizontalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100519 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700520 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setHorizontalScrollbarOverlay=" + overlay);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000521 mProvider.setHorizontalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 }
523
524 /**
Steve Block4e584df2012-04-24 23:12:47 +0100525 * Specifies whether the vertical scrollbar has overlay style.
526 *
527 * @param overlay true if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 */
529 public void setVerticalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100530 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700531 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setVerticalScrollbarOverlay=" + overlay);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000532 mProvider.setVerticalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
534
535 /**
Steve Block4e584df2012-04-24 23:12:47 +0100536 * Gets whether horizontal scrollbar has overlay style.
537 *
538 * @return true if horizontal scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 */
540 public boolean overlayHorizontalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100541 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000542 return mProvider.overlayHorizontalScrollbar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544
545 /**
Steve Block4e584df2012-04-24 23:12:47 +0100546 * Gets whether vertical scrollbar has overlay style.
547 *
548 * @return true if vertical scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 */
550 public boolean overlayVerticalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100551 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000552 return mProvider.overlayVerticalScrollbar();
Mike Reede8853fc2009-09-04 14:01:48 -0400553 }
554
Michael Kolbe54f6652011-03-16 09:11:51 -0700555 /**
Steve Block4e584df2012-04-24 23:12:47 +0100556 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700557 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700558 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400559 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400560 */
Michael Kolb73980a92010-08-05 16:32:51 -0700561 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100562 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000563 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565
566 /**
Steve Block4e584df2012-04-24 23:12:47 +0100567 * Gets the SSL certificate for the main top-level page or null if there is
568 * no certificate (the site is not secure).
569 *
570 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 */
572 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100573 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000574 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576
577 /**
578 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400579 *
580 * @deprecated Calling this function has no useful effect, and will be
581 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400583 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100585 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700586 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setCertificate=" + certificate);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000587 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589
590 //-------------------------------------------------------------------------
591 // Methods called by activity
592 //-------------------------------------------------------------------------
593
594 /**
Steve Block32fe4102012-07-17 16:29:11 +0100595 * Sets a username and password pair for the specified host. This data is
596 * used by the Webview to autocomplete username and password fields in web
597 * forms. Note that this is unrelated to the credentials used for HTTP
598 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100599 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000600 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100601 * @param username the username for the given host
602 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100603 * @see WebViewDatabase#clearUsernamePassword
604 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800605 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800607 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100609 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700610 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "savePassword=" + host);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000611 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
613
614 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100615 * Stores HTTP authentication credentials for a given host and realm. This
616 * method is intended to be used with
617 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 *
Steve Block46ce1db2012-07-17 16:43:00 +0100619 * @param host the host to which the credentials apply
620 * @param realm the realm to which the credentials apply
621 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100622 * @param password the password
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800623 * @see #getHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100624 * @see WebViewDatabase#hasHttpAuthUsernamePassword
625 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 */
627 public void setHttpAuthUsernamePassword(String host, String realm,
628 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100629 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700630 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setHttpAuthUsernamePassword=" + host);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000631 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 }
633
634 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100635 * Retrieves HTTP authentication credentials for a given host and realm.
636 * This method is intended to be used with
637 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 *
Steve Block46ce1db2012-07-17 16:43:00 +0100639 * @param host the host to which the credentials apply
640 * @param realm the realm to which the credentials apply
641 * @return the credentials as a String array, if found. The first element
642 * is the username and the second element is the password. Null if
643 * no credentials are found.
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800644 * @see #setHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100645 * @see WebViewDatabase#hasHttpAuthUsernamePassword
646 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 */
648 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100649 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000650 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400651 }
652
653 /**
Steve Block4e584df2012-04-24 23:12:47 +0100654 * Destroys the internal state of this WebView. This method should be called
655 * after this WebView has been removed from the view system. No other
656 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 */
658 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100659 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700660 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "destroy");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000661 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663
664 /**
665 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100666 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100667 *
668 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400669 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100671 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 public static void enablePlatformNotifications() {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000673 getFactory().getStatics().setPlatformNotificationsEnabled(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
675
676 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100677 * Disables platform notifications of data state and proxy changes.
678 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100679 *
680 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400681 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100683 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 public static void disablePlatformNotifications() {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000685 getFactory().getStatics().setPlatformNotificationsEnabled(false);
Feng Qianb3081372009-06-29 15:55:18 -0700686 }
687
688 /**
Steve Block4e584df2012-04-24 23:12:47 +0100689 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000690 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100692 *
693 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 */
695 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100696 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700697 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setNetworkAvailable=" + networkUp);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000698 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 }
700
701 /**
Steve Block4e584df2012-04-24 23:12:47 +0100702 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
704 * method no longer stores the display data for this WebView. The previous
705 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400706 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100707 *
708 * @param outState the Bundle to store this WebView's state
709 * @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 -0800710 * saveState fails, the returned list will be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 */
712 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100713 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700714 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveState");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000715 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 }
717
718 /**
Steve Block4e584df2012-04-24 23:12:47 +0100719 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100721 * @param b a Bundle to store the display data
722 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 * overwritten with this WebView's picture data.
Steve Block4e584df2012-04-24 23:12:47 +0100724 * @return true if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100725 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400726 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100728 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400729 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100730 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700731 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "savePicture=" + dest.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +0000732 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 }
734
735 /**
Steve Block4e584df2012-04-24 23:12:47 +0100736 * Restores the display data that was saved in {@link #savePicture}. Used in
737 * conjunction with {@link #restoreState}. Note that this will not work if
738 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700739 *
Steve Block4e584df2012-04-24 23:12:47 +0100740 * @param b a Bundle containing the saved display data
741 * @param src the file where the picture data was stored
742 * @return true if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100743 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400744 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100746 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100748 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700749 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "restorePicture=" + src.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +0000750 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700751 }
752
753 /**
Steve Block42499062012-07-17 15:34:46 +0100754 * Restores the state of this WebView from the given Bundle. This method is
755 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
756 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100757 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400758 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400760 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100761 *
762 * @param inState the incoming Bundle of state
763 * @return the restored back/forward list or null if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 */
765 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100766 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700767 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "restoreState");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000768 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
770
771 /**
Steve Block4e584df2012-04-24 23:12:47 +0100772 * Loads the given URL with the specified additional HTTP headers.
773 *
774 * @param url the URL of the resource to load
775 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100776 * HTTP request for this URL, specified as a map from name to
777 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100778 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100779 * controlling caching, accept types or the User-Agent, their
Steve Block4e584df2012-04-24 23:12:47 +0100780 * values may be overriden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800781 */
Steve Blockf71dea02011-08-01 12:29:14 +0100782 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100783 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700784 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadUrl(extra headers)=" + url);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000785 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800786 }
787
788 /**
Steve Block4e584df2012-04-24 23:12:47 +0100789 * Loads the given URL.
790 *
791 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 */
793 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100794 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700795 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadUrl=" + url);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000796 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 }
798
799 /**
Steve Block4e584df2012-04-24 23:12:47 +0100800 * Loads the URL with postData using "POST" method into this WebView. If url
801 * is not a network URL, it will be loaded with {link
Grace Kloba57534302009-05-22 18:55:02 -0700802 * {@link #loadUrl(String)} instead.
Cary Clarkd6982c92009-05-29 11:02:22 -0400803 *
Steve Block4e584df2012-04-24 23:12:47 +0100804 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100805 * @param postData the data will be passed to "POST" request, which must be
806 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700807 */
808 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100809 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700810 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "postUrl=" + url);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000811 mProvider.postUrl(url, postData);
Grace Kloba57534302009-05-22 18:55:02 -0700812 }
813
814 /**
Steve Block4e584df2012-04-24 23:12:47 +0100815 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100816 * <p>
817 * Note that JavaScript's same origin policy means that script running in a
818 * page loaded using this method will be unable to access content loaded
819 * using any scheme other than 'data', including 'http(s)'. To avoid this
820 * restriction, use {@link
821 * #loadDataWithBaseURL(String,String,String,String,String)
822 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100823 * <p>
Steve Block27f3e322012-07-23 10:45:59 +0100824 * The encoding parameter specifies whether the data is base64 or URL
825 * encoded. If the data is base64 encoded, the value of the encoding
826 * parameter must be 'base64'. For all other values of the parameter,
827 * including null, it is assumed that the data uses ASCII encoding for
Steve Blockf95d4902011-06-09 11:53:26 +0100828 * octets inside the range of safe URL characters and use the standard %xx
Steve Block27f3e322012-07-23 10:45:59 +0100829 * hex encoding of URLs for octets outside that range. For example, '#',
830 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
Steve Blockb19c7872011-10-10 14:09:44 +0100831 * <p>
832 * The 'data' scheme URL formed by this method uses the default US-ASCII
833 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100834 * 'data' scheme URL which explicitly specifies a charset parameter in the
835 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
836 * Note that the charset obtained from the mediatype portion of a data URL
837 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +0100838 *
839 * @param data a String of data in the given encoding
840 * @param mimeType the MIME type of the data, e.g. 'text/html'
841 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 */
843 public void loadData(String data, String mimeType, String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100844 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700845 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadData");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000846 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 }
848
849 /**
Steve Block4e584df2012-04-24 23:12:47 +0100850 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100851 * the content. The base URL is used both to resolve relative URLs and when
852 * applying JavaScript's same origin policy. The historyUrl is used for the
853 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100855 * Note that content specified in this way can access local device files
856 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
857 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100858 * <p>
859 * If the base URL uses the data scheme, this method is equivalent to
860 * calling {@link #loadData(String,String,String) loadData()} and the
Ben Murdoch597256e2013-07-22 16:52:12 +0100861 * historyUrl is ignored, and the data will be treated as part of a data: URL.
862 * If the base URL uses any other scheme, then the data will be loaded into
863 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
864 * entities in the string will not be decoded.
Steve Block4e584df2012-04-24 23:12:47 +0100865 *
866 * @param baseUrl the URL to use as the page's base URL. If null defaults to
867 * 'about:blank'.
868 * @param data a String of data in the given encoding
869 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
870 * defaults to 'text/html'.
871 * @param encoding the encoding of the data
872 * @param historyUrl the URL to use as the history entry. If null defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000873 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 */
875 public void loadDataWithBaseURL(String baseUrl, String data,
Leon Scroggins1bb1a912010-03-23 15:39:46 -0400876 String mimeType, String encoding, String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100877 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700878 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadDataWithBaseURL=" + baseUrl);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000879 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 }
881
882 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +0100883 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
884 * If non-null, |resultCallback| will be invoked with any result returned from that
885 * execution. This method must be called on the UI thread and the callback will
886 * be made on the UI thread.
887 *
888 * @param script the JavaScript to execute.
889 * @param resultCallback A callback to be invoked when the script execution
890 * completes with the result of the execution (if any).
891 * May be null if no notificaion of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100892 */
893 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) {
894 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700895 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "evaluateJavascript=" + script);
Ben Murdocha5cdd512013-07-17 16:25:07 +0100896 mProvider.evaluateJavaScript(script, resultCallback);
897 }
898
899 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700900 * Saves the current view as a web archive.
901 *
Steve Block4e584df2012-04-24 23:12:47 +0100902 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700903 */
904 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100905 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700906 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveWebArchive=" + filename);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000907 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700908 }
909
910 /**
911 * Saves the current view as a web archive.
912 *
Steve Block4e584df2012-04-24 23:12:47 +0100913 * @param basename the filename where the archive should be placed
914 * @param autoname if false, takes basename to be a file. If true, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700915 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100916 * chosen according to the URL of the current page.
917 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700918 * parameter for onReceiveValue will either be the filename
919 * under which the file was saved, or null if saving the
920 * file failed.
921 */
922 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
Steve Block51b08912011-04-27 15:04:48 +0100923 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700924 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveWebArchive(auto)=" + basename);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000925 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700926 }
927
928 /**
Steve Block4e584df2012-04-24 23:12:47 +0100929 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 */
931 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100932 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700933 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "stopLoading");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000934 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 }
936
937 /**
Steve Block4e584df2012-04-24 23:12:47 +0100938 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 */
940 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100941 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700942 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "reload");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000943 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 }
945
946 /**
Steve Block4e584df2012-04-24 23:12:47 +0100947 * Gets whether this WebView has a back history item.
948 *
949 * @return true iff this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 */
951 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +0100952 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000953 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955
956 /**
Steve Block4e584df2012-04-24 23:12:47 +0100957 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 */
959 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +0100960 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700961 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goBack");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000962 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 }
964
965 /**
Steve Block4e584df2012-04-24 23:12:47 +0100966 * Gets whether this WebView has a forward history item.
967 *
968 * @return true iff this Webview has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 */
970 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +0100971 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000972 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
974
975 /**
Steve Block4e584df2012-04-24 23:12:47 +0100976 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 */
978 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +0100979 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700980 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goForward");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000981 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 }
983
984 /**
Steve Block4e584df2012-04-24 23:12:47 +0100985 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +0100987 *
988 * @param steps the negative or positive number of steps to move the
989 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 */
991 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100992 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000993 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 }
995
996 /**
Steve Block4e584df2012-04-24 23:12:47 +0100997 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 * the current item. Steps is negative if backward and positive
999 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +01001000 *
1001 * @param steps the number of steps to take back or forward in the back
1002 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 */
1004 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001005 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001006 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goBackOrForwad=" + steps);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001007 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001009
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001010 /**
Steve Block4e584df2012-04-24 23:12:47 +01001011 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001012 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -07001013 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +01001014 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001015 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 /**
Steve Block4e584df2012-04-24 23:12:47 +01001019 * Scrolls the contents of this WebView up by half the view size.
1020 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 * @param top true to jump to the top of the page
1022 * @return true if the page was scrolled
1023 */
1024 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +01001025 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001026 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pageUp");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001027 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 /**
Steve Block4e584df2012-04-24 23:12:47 +01001031 * Scrolls the contents of this WebView down by half the page size.
1032 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 * @param bottom true to jump to bottom of page
1034 * @return true if the page was scrolled
1035 */
1036 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001037 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001038 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pageDown");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001039 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 }
1041
1042 /**
Steve Block4e584df2012-04-24 23:12:47 +01001043 * Clears this WebView so that onDraw() will draw nothing but white background,
1044 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001045 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1046 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001048 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001050 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001051 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearView");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001052 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 /**
Steve Block72498ed2012-07-17 15:57:25 +01001056 * Gets a new picture that captures the current contents of this WebView.
1057 * The picture is of the entire document being displayed, and is not
1058 * limited to the area currently displayed by this WebView. Also, the
1059 * picture is a static copy and is unaffected by later changes to the
1060 * content being displayed.
1061 * <p>
1062 * Note that due to internal changes, for API levels between
1063 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1064 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1065 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001066 * <p>
1067 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1068 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
1069 * additional conversion at a cost in memory and performance. Also the
1070 * {@link android.graphics.Picture#createFromStream} and
1071 * {@link android.graphics.Picture#writeToStream} methods are not supported on the
1072 * returned object.
1073 *
1074 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001075 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 *
Steve Block72498ed2012-07-17 15:57:25 +01001077 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001079 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001081 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001082 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "capturePicture");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001083 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 }
1085
Cary Clarkd6982c92009-05-29 11:02:22 -04001086 /**
Selim Guruna5c86c62013-09-06 14:39:05 -07001087 * Creates a PrintDocumentAdapter that provides the content of this Webview for printing.
1088 * Only supported for API levels
Chet Haasee8222dd2013-09-05 07:44:18 -07001089 * {@link android.os.Build.VERSION_CODES#KITKAT} and above.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001090 *
Selim Guruna5c86c62013-09-06 14:39:05 -07001091 * The adapter works by converting the Webview contents to a PDF stream. The Webview cannot
1092 * be drawn during the conversion process - any such draws are undefined. It is recommended
1093 * to use a dedicated off screen Webview for the printing. If necessary, an application may
1094 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1095 * wrapped around the object returned and observing the onStart and onFinish methods. See
1096 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001097 */
Selim Guruna5c86c62013-09-06 14:39:05 -07001098 public PrintDocumentAdapter createPrintDocumentAdapter() {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001099 checkThread();
Selim Guruna5c86c62013-09-06 14:39:05 -07001100 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "createPrintDocumentAdapter");
1101 return mProvider.createPrintDocumentAdapter();
Selim Gurun2167c0b2013-08-05 15:23:09 -07001102 }
1103
1104 /**
Steve Block4e584df2012-04-24 23:12:47 +01001105 * Gets the current scale of this WebView.
1106 *
1107 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001108 *
1109 * @deprecated This method is prone to inaccuracy due to race conditions
1110 * between the web rendering and UI threads; prefer
1111 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001113 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001114 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001116 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001117 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001118 }
1119
1120 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001121 * Sets the initial scale for this WebView. 0 means default.
1122 * The behavior for the default scale depends on the state of
1123 * {@link WebSettings#getUseWideViewPort()} and
1124 * {@link WebSettings#getLoadWithOverviewMode()}.
1125 * If the content fits into the WebView control by width, then
1126 * the zoom is set to 100%. For wide content, the behavor
1127 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
1128 * If its value is true, the content will be zoomed out to be fit
1129 * by width into the WebView control, otherwise not.
1130 *
1131 * If initial scale is greater than 0, WebView starts with this value
1132 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001133 * Please note that unlike the scale properties in the viewport meta tag,
1134 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 *
Steve Block4e584df2012-04-24 23:12:47 +01001136 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 */
1138 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001139 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001140 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setInitialScale=" + scaleInPercent);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001141 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 }
1143
1144 /**
Steve Block4e584df2012-04-24 23:12:47 +01001145 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 * result in the zoom widget appearing on the screen to control the zoom
1147 * level of this WebView.
1148 */
1149 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001150 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001151 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "invokeZoomPicker");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001152 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 }
1154
1155 /**
Steve Block4e584df2012-04-24 23:12:47 +01001156 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1157 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1158 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1159 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1160 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001162 * 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 -08001163 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001164 * 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 -08001165 * a child node. If a phone number is found, the HitTestResult type is set
1166 * to PHONE_TYPE and the phone number is set in the "extra" field of
1167 * HitTestResult. If a map address is found, the HitTestResult type is set
1168 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1169 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1170 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1171 * HitTestResult type is set to UNKNOWN_TYPE.
1172 */
1173 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001174 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001175 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "getHitTestResult");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001176 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001177 }
1178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 /**
Steve Block4e584df2012-04-24 23:12:47 +01001180 * Requests the anchor or image element URL at the last tapped point.
Cary Clark861368a2010-12-15 11:24:37 -05001181 * If hrefMsg is null, this method returns immediately and does not
1182 * dispatch hrefMsg to its target. If the tapped point hits an image,
1183 * an anchor, or an image in an anchor, the message associates
1184 * strings in named keys in its data. The value paired with the key
1185 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001186 *
Steve Block4e584df2012-04-24 23:12:47 +01001187 * @param hrefMsg the message to be dispatched with the result of the
1188 * request. The message data contains three keys. "url"
1189 * returns the anchor's href attribute. "title" returns the
1190 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 */
1192 public void requestFocusNodeHref(Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001193 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001194 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "requestFocusNodeHref");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001195 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 /**
Steve Block4e584df2012-04-24 23:12:47 +01001199 * Requests the URL of the image last touched by the user. msg will be sent
1200 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001201 *
Steve Block4e584df2012-04-24 23:12:47 +01001202 * @param msg the message to be dispatched with the result of the request
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 * as the data member with "url" as key. The result can be null.
1204 */
1205 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001206 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001207 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "requestImageRef");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001208 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001209 }
1210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 /**
Steve Block4e584df2012-04-24 23:12:47 +01001212 * 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 -08001213 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001214 * that URL has begun, the current page may not have changed.
1215 *
1216 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 */
John Reck926cf562012-06-14 10:00:31 -07001218 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001220 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001221 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 /**
Steve Block4e584df2012-04-24 23:12:47 +01001225 * Gets the original URL for the current page. This is not always the same
1226 * as the URL passed to WebViewClient.onPageStarted because although the
1227 * load for that URL has begun, the current page may not have changed.
1228 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001230 *
1231 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 */
John Reck926cf562012-06-14 10:00:31 -07001233 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001235 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001236 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238
1239 /**
Steve Block4e584df2012-04-24 23:12:47 +01001240 * 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 -08001241 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001242 *
1243 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 */
John Reck926cf562012-06-14 10:00:31 -07001245 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001247 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001248 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250
1251 /**
Steve Block4e584df2012-04-24 23:12:47 +01001252 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001254 *
1255 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 */
1257 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001258 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001259 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 }
1261
1262 /**
Steve Block4e584df2012-04-24 23:12:47 +01001263 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001264 * a URL on this site's server pointing to the standard location of a
1265 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001266 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001267 * @hide
1268 */
1269 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001270 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001271 }
1272
1273 /**
Steve Block4e584df2012-04-24 23:12:47 +01001274 * Gets the progress for the current page.
1275 *
1276 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 */
1278 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001279 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001280 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 /**
Steve Block4e584df2012-04-24 23:12:47 +01001284 * Gets the height of the HTML content.
1285 *
1286 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 */
John Reck926cf562012-06-14 10:00:31 -07001288 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001290 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001291 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 }
1293
1294 /**
Steve Block4e584df2012-04-24 23:12:47 +01001295 * Gets the width of the HTML content.
1296 *
1297 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001298 * @hide
1299 */
John Reck926cf562012-06-14 10:00:31 -07001300 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001301 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001302 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001303 }
1304
1305 /**
Steve Block4e584df2012-04-24 23:12:47 +01001306 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1307 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001308 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 */
1310 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001311 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001312 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pauseTimers");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001313 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 }
1315
1316 /**
Steve Block4e584df2012-04-24 23:12:47 +01001317 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001318 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 */
1320 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001321 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001322 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "resumeTimers");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001323 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 }
1325
1326 /**
Steve Block4e584df2012-04-24 23:12:47 +01001327 * Pauses any extra processing associated with this WebView and its
1328 * associated DOM, plugins, JavaScript etc. For example, if this WebView is
1329 * taken offscreen, this could be called to reduce unnecessary CPU or
1330 * network traffic. When this WebView is again "active", call onResume().
Steve Block81f19ff2010-11-01 13:23:24 +00001331 * Note that this differs from pauseTimers(), which affects all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001332 */
1333 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001334 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001335 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "onPause");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001336 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001337 }
1338
1339 /**
Steve Block4e584df2012-04-24 23:12:47 +01001340 * Resumes a WebView after a previous call to onPause().
Mike Reedd205d5b2009-05-27 11:02:29 -04001341 */
1342 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001343 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001344 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "onResume");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001345 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001346 }
1347
1348 /**
Steve Block4e584df2012-04-24 23:12:47 +01001349 * Gets whether this WebView is paused, meaning onPause() was called.
1350 * Calling onResume() sets the paused state back to false.
1351 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001352 * @hide
1353 */
1354 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001355 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001356 }
1357
1358 /**
Steve Block4e584df2012-04-24 23:12:47 +01001359 * Informs this WebView that memory is low so that it can free any available
1360 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001361 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1362 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001363 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001364 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001365 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001366 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001367 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "freeMemory");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001368 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001369 }
1370
1371 /**
Steve Block4e584df2012-04-24 23:12:47 +01001372 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001373 * this will clear the cache for all WebViews used.
1374 *
Steve Block4e584df2012-04-24 23:12:47 +01001375 * @param includeDiskFiles if false, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 */
1377 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001378 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001379 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearCache");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001380 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 }
1382
1383 /**
Steve Block219dfa42012-07-20 10:31:21 +01001384 * Removes the autocomplete popup from the currently focused form field, if
1385 * present. Note this only affects the display of the autocomplete popup,
1386 * it does not remove any saved form data from this WebView's store. To do
1387 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 */
1389 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001390 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001391 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearFormData");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001392 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 }
1394
1395 /**
Steve Block4e584df2012-04-24 23:12:47 +01001396 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 */
1398 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001399 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001400 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearHistory");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001401 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 }
1403
1404 /**
Steve Block4e584df2012-04-24 23:12:47 +01001405 * Clears the SSL preferences table stored in response to proceeding with
1406 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 */
1408 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001409 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001410 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearSslPreferences");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001411 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 }
1413
1414 /**
Steve Block4e584df2012-04-24 23:12:47 +01001415 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 * back/forward list for use in querying each item in the history stack.
1417 * This is a copy of the private WebBackForwardList so it contains only a
1418 * snapshot of the current state. Multiple calls to this method may return
1419 * different objects. The object returned from this method will not be
1420 * updated to reflect any new state.
1421 */
1422 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001423 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001424 return mProvider.copyBackForwardList();
1425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 }
1427
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001428 /**
Steve Block4e584df2012-04-24 23:12:47 +01001429 * Registers the listener to be notified as find-on-page operations
1430 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001431 *
Steve Block4e584df2012-04-24 23:12:47 +01001432 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001433 */
1434 public void setFindListener(FindListener listener) {
1435 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001436 setupFindListenerIfNeeded();
1437 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001438 }
1439
1440 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001441 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001442 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001443 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1444 * has not been called yet, or if {@link #clearMatches} has been called since the
1445 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 *
Steve Block4e584df2012-04-24 23:12:47 +01001447 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001448 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 */
1450 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001451 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001452 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findNext");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001453 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 }
1455
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001456 /**
Steve Block4e584df2012-04-24 23:12:47 +01001457 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001458 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001459 *
Steve Block4e584df2012-04-24 23:12:47 +01001460 * @param find the string to find
1461 * @return the number of occurances of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001462 * @deprecated {@link #findAllAsync} is preferred.
1463 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001465 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001467 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001468 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findAll");
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001469 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001470 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 }
1472
Cary Clark3403eb32010-03-03 10:05:16 -05001473 /**
Steve Block4e584df2012-04-24 23:12:47 +01001474 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001475 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001476 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001477 *
Steve Block4e584df2012-04-24 23:12:47 +01001478 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001479 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001480 */
1481 public void findAllAsync(String find) {
1482 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001483 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findAllAsync");
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001484 mProvider.findAllAsync(find);
1485 }
1486
1487 /**
Steve Block4e584df2012-04-24 23:12:47 +01001488 * Starts an ActionMode for finding text in this WebView. Only works if this
1489 * WebView is attached to the view system.
1490 *
1491 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001492 * Otherwise, the last String searched for in this WebView will
1493 * be used to start.
Steve Block4e584df2012-04-24 23:12:47 +01001494 * @param showIme if true, show the IME, assuming the user will begin typing.
1495 * If false and text is non-null, perform a find all.
1496 * @return true if the find dialog is shown, false otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001497 * @deprecated This method does not work reliably on all Android versions;
1498 * implementing a custom find dialog using WebView.findAllAsync()
1499 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001500 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001501 @Deprecated
Leon Scroggins571354f2011-01-04 10:12:41 -05001502 public boolean showFindDialog(String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001503 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001504 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "showFindDialog");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001505 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001506 }
1507
1508 /**
Steve Block4e584df2012-04-24 23:12:47 +01001509 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 * location. Currently, only addresses in the United States are detected,
1511 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001512 * <ul>
1513 * <li>a house number</li>
1514 * <li>a street name</li>
1515 * <li>a street type (Road, Circle, etc), either spelled out or
1516 * abbreviated</li>
1517 * <li>a city name</li>
1518 * <li>a state or territory, either spelled out or two-letter abbr</li>
1519 * <li>an optional 5 digit or 9 digit zip code</li>
1520 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 * All names must be correctly capitalized, and the zip code, if present,
1522 * must be valid for the state. The street type must be a standard USPS
1523 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001524 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 *
Steve Block4e584df2012-04-24 23:12:47 +01001527 * @param addr the string to search for addresses
1528 * @return the address, or if no address is found, null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 */
1530 public static String findAddress(String addr) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001531 return getFactory().getStatics().findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 }
1533
Victoria Lease0b8413b2012-03-26 13:04:10 -07001534 /**
Steve Block4e584df2012-04-24 23:12:47 +01001535 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001536 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 */
1538 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001539 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001540 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearMatches");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001541 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 }
1543
1544 /**
Steve Block4e584df2012-04-24 23:12:47 +01001545 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 * message object will be dispatched with arg1 being set to 1 if images
1547 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001548 *
1549 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 */
1551 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001552 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001553 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 }
1555
1556 /**
Steve Block4e584df2012-04-24 23:12:47 +01001557 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001558 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001559 *
1560 * @param client an implementation of WebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 */
1562 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001563 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001564 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001565 }
1566
1567 /**
Steve Block4e584df2012-04-24 23:12:47 +01001568 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 * the rendering engine, and should be downloaded instead. This will replace
1570 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001571 *
1572 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 */
1574 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001575 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001576 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 }
1578
1579 /**
Steve Block4e584df2012-04-24 23:12:47 +01001580 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001581 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001583 *
1584 * @param client an implementation of WebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 */
1586 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001587 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001588 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001589 }
1590
1591 /**
Steve Block4e584df2012-04-24 23:12:47 +01001592 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001594 *
1595 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001596 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001598 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001600 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001601 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setPictureListener=" + listener);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001602 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 }
1604
1605 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001606 * Injects the supplied Java object into this WebView. The object is
1607 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001608 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001609 * accessed from JavaScript. For applications targeted to API
1610 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001611 * and above, only public methods that are annotated with
1612 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001613 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001614 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001615 * important security note below for implications.
1616 * <p> Note that injected objects will not
Steve Block3aa800b2012-04-24 13:01:34 +01001617 * appear in JavaScript until the page is next (re)loaded. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001618 * <pre>
1619 * class JsObject {
1620 * {@literal @}JavascriptInterface
1621 * public String toString() { return "injectedObject"; }
1622 * }
1623 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001624 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1625 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001626 * <p>
1627 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001629 * <li> This method can be used to allow JavaScript to control the host
1630 * application. This is a powerful feature, but also presents a security
Selim Gurunb4c02e62012-09-12 13:36:21 -07001631 * risk for applications targeted to API level
Selim Gurune91d5be2012-09-11 16:11:22 -07001632 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because
1633 * JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001634 * injected object's public fields. Use of this method in a WebView
1635 * containing untrusted content could allow an attacker to manipulate the
1636 * host application in unintended ways, executing Java code with the
1637 * permissions of the host application. Use extreme care when using this
1638 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001639 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001640 * thread of this WebView. Care is therefore required to maintain thread
Steve Block4cd73c52011-11-09 13:06:52 +00001641 * safety.</li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001642 * <li> The Java object's fields are not accessible.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001643 * </ul>
1644 *
1645 * @param object the Java object to inject into this WebView's JavaScript
Steve Block4cd73c52011-11-09 13:06:52 +00001646 * context. Null values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001647 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 */
Steve Block4cd73c52011-11-09 13:06:52 +00001649 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001650 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001651 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "addJavascriptInterface=" + name);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001652 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 }
1654
1655 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001656 * Removes a previously injected Java object from this WebView. Note that
1657 * the removal will not be reflected in JavaScript until the page is next
1658 * (re)loaded. See {@link #addJavascriptInterface}.
1659 *
1660 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001661 */
Steve Block3aa800b2012-04-24 13:01:34 +01001662 public void removeJavascriptInterface(String name) {
Steve Block51b08912011-04-27 15:04:48 +01001663 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001664 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "removeJavascriptInterface=" + name);
Steve Block3aa800b2012-04-24 13:01:34 +01001665 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001666 }
1667
1668 /**
Steve Block4e584df2012-04-24 23:12:47 +01001669 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001671 *
1672 * @return a WebSettings object that can be used to control this WebView's
1673 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 */
1675 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001676 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001677 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 }
1679
Jonathan Dixon3c909522012-02-28 18:45:06 +00001680 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07001681 * Enables debugging of web contents (HTML / CSS / JavaScript)
1682 * loaded into any WebViews of this application. This flag can be enabled
1683 * in order to facilitate debugging of web layouts and JavaScript
1684 * code running inside WebViews. Please refer to WebView documentation
1685 * for the debugging guide.
1686 *
1687 * The default is false.
1688 *
1689 * @param enabled whether to enable web contents debugging
1690 */
1691 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07001692 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
1693 }
1694
1695 /**
Steve Block4e584df2012-04-24 23:12:47 +01001696 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001697 *
Steve Block4e584df2012-04-24 23:12:47 +01001698 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001699 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001700 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001701 */
Andrei Popescu385df692009-08-13 11:59:57 +01001702 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08001704 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 }
1706
Jonathan Dixon3c909522012-02-28 18:45:06 +00001707 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001708 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001709 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001710 */
Andrei Popescu385df692009-08-13 11:59:57 +01001711 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01001712 public void refreshPlugins(boolean reloadOpenPages) {
1713 checkThread();
1714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715
Cary Clark966641a2010-03-04 08:41:56 -05001716 /**
Steve Block4e584df2012-04-24 23:12:47 +01001717 * Puts this WebView into text selection mode. Do not rely on this
1718 * functionality; it will be deprecated in the future.
1719 *
Kristian Monsenfc771652011-05-10 16:44:05 +01001720 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001721 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05001722 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001723 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01001725 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07001726 }
1727
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001728 /**
1729 * @deprecated WebView no longer needs to implement
1730 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1731 */
George Mountfab67a12012-01-05 09:58:53 -08001732 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001733 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001734 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04001736
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001737 /**
1738 * @deprecated WebView no longer needs to implement
1739 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1740 */
George Mountfab67a12012-01-05 09:58:53 -08001741 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001742 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001743 @Deprecated
1744 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001745
1746 /**
1747 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08001748 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 */
George Mountfab67a12012-01-05 09:58:53 -08001750 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001751 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 @Deprecated
1753 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1754 }
1755
Kristian Monsen5cc23512012-08-09 15:33:08 -04001756 /**
1757 * @deprecated Only the default case, true, will be supported in a future version.
1758 */
1759 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01001761 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001762 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 }
1764
Derek Sollenberger03e48912010-05-18 17:03:42 -04001765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01001767 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001768 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "flingScroll");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001769 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 }
1771
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001772 /**
Steve Block4e584df2012-04-24 23:12:47 +01001773 * Gets the zoom controls for this WebView, as a separate View. The caller
1774 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001775 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01001776 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
1777 * built-in zoom mechanisms for the WebView, as opposed to these separate
1778 * zoom controls. The built-in mechanisms are preferred and can be enabled
1779 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07001780 *
Steve Block4e584df2012-04-24 23:12:47 +01001781 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01001782 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 */
The Android Open Source Project10592532009-03-18 17:39:46 -07001784 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01001786 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001787 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07001788 }
1789
1790 /**
Steve Block4e584df2012-04-24 23:12:47 +01001791 * Gets whether this WebView can be zoomed in.
1792 *
1793 * @return true if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04001794 *
1795 * @deprecated This method is prone to inaccuracy due to race conditions
1796 * between the web rendering and UI threads; prefer
1797 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001798 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001799 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001800 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001801 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001802 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07001803 }
1804
1805 /**
Steve Block4e584df2012-04-24 23:12:47 +01001806 * Gets whether this WebView can be zoomed out.
1807 *
1808 * @return true if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04001809 *
1810 * @deprecated This method is prone to inaccuracy due to race conditions
1811 * between the web rendering and UI threads; prefer
1812 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001813 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001814 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001815 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001816 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001817 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07001818 }
1819
1820 /**
Steve Block4e584df2012-04-24 23:12:47 +01001821 * Performs zoom in in this WebView.
1822 *
1823 * @return true if zoom in succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 */
1825 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001826 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001827 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 }
1829
1830 /**
Steve Block4e584df2012-04-24 23:12:47 +01001831 * Performs zoom out in this WebView.
1832 *
1833 * @return true if zoom out succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 */
1835 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001836 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001837 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 }
1839
Kristian Monsenfc771652011-05-10 16:44:05 +01001840 /**
1841 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001842 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01001843 */
1844 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01001846 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001848
John Reck926cf562012-06-14 10:00:31 -07001849 /**
John Reckf2361152012-06-14 15:23:22 -07001850 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07001851 * @hide
1852 */
1853 @Override
1854 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
1855 mProvider.dumpViewHierarchyWithProperties(out, level);
1856 }
1857
1858 /**
1859 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
1860 * @hide
1861 */
1862 @Override
1863 public View findHierarchyView(String className, int hashCode) {
1864 return mProvider.findHierarchyView(className, hashCode);
1865 }
1866
Jonathan Dixon3c909522012-02-28 18:45:06 +00001867 //-------------------------------------------------------------------------
1868 // Interface for WebView providers
1869 //-------------------------------------------------------------------------
1870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 /**
Steve Block4e584df2012-04-24 23:12:47 +01001872 * Gets the WebViewProvider. Used by providers to obtain the underlying
1873 * implementation, e.g. when the appliction responds to
1874 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04001875 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00001876 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04001877 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001878 public WebViewProvider getWebViewProvider() {
1879 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04001880 }
1881
1882 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001883 * Callback interface, allows the provider implementation to access non-public methods
1884 * and fields, and make super-class calls in this WebView instance.
1885 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001886 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001887 public class PrivateAccess {
1888 // ---- Access to super-class methods ----
1889 public int super_getScrollBarStyle() {
1890 return WebView.super.getScrollBarStyle();
1891 }
1892
1893 public void super_scrollTo(int scrollX, int scrollY) {
1894 WebView.super.scrollTo(scrollX, scrollY);
1895 }
1896
1897 public void super_computeScroll() {
1898 WebView.super.computeScroll();
1899 }
1900
alanveebebc92012-06-15 18:59:11 -07001901 public boolean super_onHoverEvent(MotionEvent event) {
1902 return WebView.super.onHoverEvent(event);
1903 }
1904
alanv448902d2012-05-16 20:27:47 -07001905 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
1906 return WebView.super.performAccessibilityAction(action, arguments);
1907 }
1908
Jonathan Dixon3c909522012-02-28 18:45:06 +00001909 public boolean super_performLongClick() {
1910 return WebView.super.performLongClick();
1911 }
1912
1913 public boolean super_setFrame(int left, int top, int right, int bottom) {
1914 return WebView.super.setFrame(left, top, right, bottom);
1915 }
1916
1917 public boolean super_dispatchKeyEvent(KeyEvent event) {
1918 return WebView.super.dispatchKeyEvent(event);
1919 }
1920
1921 public boolean super_onGenericMotionEvent(MotionEvent event) {
1922 return WebView.super.onGenericMotionEvent(event);
1923 }
1924
1925 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
1926 return WebView.super.requestFocus(direction, previouslyFocusedRect);
1927 }
1928
1929 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
1930 WebView.super.setLayoutParams(params);
1931 }
1932
1933 // ---- Access to non-public methods ----
1934 public void overScrollBy(int deltaX, int deltaY,
1935 int scrollX, int scrollY,
1936 int scrollRangeX, int scrollRangeY,
1937 int maxOverScrollX, int maxOverScrollY,
1938 boolean isTouchEvent) {
1939 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
1940 maxOverScrollX, maxOverScrollY, isTouchEvent);
1941 }
1942
1943 public void awakenScrollBars(int duration) {
1944 WebView.this.awakenScrollBars(duration);
1945 }
1946
1947 public void awakenScrollBars(int duration, boolean invalidate) {
1948 WebView.this.awakenScrollBars(duration, invalidate);
1949 }
1950
1951 public float getVerticalScrollFactor() {
1952 return WebView.this.getVerticalScrollFactor();
1953 }
1954
1955 public float getHorizontalScrollFactor() {
1956 return WebView.this.getHorizontalScrollFactor();
1957 }
1958
1959 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
1960 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
1961 }
1962
1963 public void onScrollChanged(int l, int t, int oldl, int oldt) {
1964 WebView.this.onScrollChanged(l, t, oldl, oldt);
1965 }
1966
1967 public int getHorizontalScrollbarHeight() {
1968 return WebView.this.getHorizontalScrollbarHeight();
1969 }
1970
Martin Kosiba9a68f822013-08-08 14:02:41 +01001971 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
1972 int l, int t, int r, int b) {
1973 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
1974 }
1975
Jonathan Dixon3c909522012-02-28 18:45:06 +00001976 // ---- Access to (non-public) fields ----
1977 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
1978 public void setScrollXRaw(int scrollX) {
1979 WebView.this.mScrollX = scrollX;
1980 }
1981
1982 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
1983 public void setScrollYRaw(int scrollY) {
1984 WebView.this.mScrollY = scrollY;
1985 }
1986
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001987 }
1988
Jonathan Dixon3c909522012-02-28 18:45:06 +00001989 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001990 // Package-private internal stuff
1991 //-------------------------------------------------------------------------
1992
1993 // Only used by android.webkit.FindActionModeCallback.
1994 void setFindDialogFindListener(FindListener listener) {
1995 checkThread();
1996 setupFindListenerIfNeeded();
1997 mFindListener.mFindDialogFindListener = listener;
1998 }
1999
2000 // Only used by android.webkit.FindActionModeCallback.
2001 void notifyFindDialogDismissed() {
2002 checkThread();
2003 mProvider.notifyFindDialogDismissed();
2004 }
2005
2006 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002007 // Private internal stuff
2008 //-------------------------------------------------------------------------
2009
Jonathan Dixon3c909522012-02-28 18:45:06 +00002010 private WebViewProvider mProvider;
2011
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002012 /**
2013 * In addition to the FindListener that the user may set via the WebView.setFindListener
2014 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
2015 * via this class so that that the two FindListeners can potentially exist at once.
2016 */
2017 private class FindListenerDistributor implements FindListener {
2018 private FindListener mFindDialogFindListener;
2019 private FindListener mUserFindListener;
2020
2021 @Override
2022 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2023 boolean isDoneCounting) {
2024 if (mFindDialogFindListener != null) {
2025 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2026 isDoneCounting);
2027 }
2028
2029 if (mUserFindListener != null) {
2030 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2031 isDoneCounting);
2032 }
2033 }
2034 }
2035 private FindListenerDistributor mFindListener;
2036
2037 private void setupFindListenerIfNeeded() {
2038 if (mFindListener == null) {
2039 mFindListener = new FindListenerDistributor();
2040 mProvider.setFindListener(mFindListener);
2041 }
2042 }
2043
Jonathan Dixon3c909522012-02-28 18:45:06 +00002044 private void ensureProviderCreated() {
2045 checkThread();
2046 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002047 // As this can get called during the base class constructor chain, pass the minimum
2048 // number of dependencies here; the rest are deferred to init().
2049 mProvider = getFactory().createWebView(this, new PrivateAccess());
2050 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002051 }
2052
Jonathan Dixon951fcab2012-08-20 16:37:15 -07002053 private static synchronized WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002054 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002055 }
2056
Jonathan Dixon517771b2013-10-08 13:32:11 -07002057 private final Looper mWebViewThread = Looper.myLooper();
2058
2059 private void checkThread() {
2060 // Ignore mWebViewThread == null because this can be called during in the super class
2061 // constructor, before this class's own constructor has even started.
2062 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002063 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002064 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002065 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002066 "All WebView methods must be called on the same thread. " +
2067 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2068 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002069 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2070 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002071
2072 if (sEnforceThreadChecking) {
2073 throw new RuntimeException(throwable);
2074 }
Steve Block51b08912011-04-27 15:04:48 +01002075 }
2076 }
2077
Jonathan Dixon3c909522012-02-28 18:45:06 +00002078 //-------------------------------------------------------------------------
2079 // Override View methods
2080 //-------------------------------------------------------------------------
2081
2082 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2083 // there's a corresponding override (or better, caller) for each of them in here.
2084
2085 @Override
2086 protected void onAttachedToWindow() {
2087 super.onAttachedToWindow();
2088 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002089 }
2090
Jonathan Dixon3c909522012-02-28 18:45:06 +00002091 @Override
2092 protected void onDetachedFromWindow() {
2093 mProvider.getViewDelegate().onDetachedFromWindow();
2094 super.onDetachedFromWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002095 }
2096
Jonathan Dixon3c909522012-02-28 18:45:06 +00002097 @Override
2098 public void setLayoutParams(ViewGroup.LayoutParams params) {
2099 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002100 }
2101
Jonathan Dixon3c909522012-02-28 18:45:06 +00002102 @Override
2103 public void setOverScrollMode(int mode) {
2104 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002105 // This method may be called in the constructor chain, before the WebView provider is
2106 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002107 ensureProviderCreated();
2108 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002109 }
2110
Jonathan Dixon3c909522012-02-28 18:45:06 +00002111 @Override
2112 public void setScrollBarStyle(int style) {
2113 mProvider.getViewDelegate().setScrollBarStyle(style);
2114 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002115 }
2116
Jonathan Dixon3c909522012-02-28 18:45:06 +00002117 @Override
2118 protected int computeHorizontalScrollRange() {
2119 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002120 }
2121
Jonathan Dixon3c909522012-02-28 18:45:06 +00002122 @Override
2123 protected int computeHorizontalScrollOffset() {
2124 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2125 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002126
Jonathan Dixon3c909522012-02-28 18:45:06 +00002127 @Override
2128 protected int computeVerticalScrollRange() {
2129 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2130 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002131
Jonathan Dixon3c909522012-02-28 18:45:06 +00002132 @Override
2133 protected int computeVerticalScrollOffset() {
2134 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2135 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002136
Jonathan Dixon3c909522012-02-28 18:45:06 +00002137 @Override
2138 protected int computeVerticalScrollExtent() {
2139 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2140 }
2141
2142 @Override
2143 public void computeScroll() {
2144 mProvider.getScrollDelegate().computeScroll();
2145 }
2146
2147 @Override
2148 public boolean onHoverEvent(MotionEvent event) {
2149 return mProvider.getViewDelegate().onHoverEvent(event);
2150 }
2151
2152 @Override
2153 public boolean onTouchEvent(MotionEvent event) {
2154 return mProvider.getViewDelegate().onTouchEvent(event);
2155 }
2156
2157 @Override
2158 public boolean onGenericMotionEvent(MotionEvent event) {
2159 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2160 }
2161
2162 @Override
2163 public boolean onTrackballEvent(MotionEvent event) {
2164 return mProvider.getViewDelegate().onTrackballEvent(event);
2165 }
2166
2167 @Override
2168 public boolean onKeyDown(int keyCode, KeyEvent event) {
2169 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2170 }
2171
2172 @Override
2173 public boolean onKeyUp(int keyCode, KeyEvent event) {
2174 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2175 }
2176
2177 @Override
2178 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2179 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2180 }
2181
2182 /*
2183 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2184 to be delegating them too.
2185
2186 @Override
2187 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2188 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2189 }
2190 @Override
2191 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2192 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2193 }
2194 @Override
2195 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2196 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2197 }
2198 */
2199
Ben Murdoche3f90712013-06-05 14:19:48 +01002200 @Override
2201 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2202 AccessibilityNodeProvider provider =
2203 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2204 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2205 }
2206
Jonathan Dixon3c909522012-02-28 18:45:06 +00002207 @Deprecated
2208 @Override
2209 public boolean shouldDelayChildPressedState() {
2210 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2211 }
2212
2213 @Override
2214 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
2215 super.onInitializeAccessibilityNodeInfo(info);
alanvea077212012-03-30 14:59:42 -07002216 info.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002217 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
2218 }
2219
2220 @Override
2221 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2222 super.onInitializeAccessibilityEvent(event);
alanvea077212012-03-30 14:59:42 -07002223 event.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002224 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
2225 }
2226
alanv448902d2012-05-16 20:27:47 -07002227 @Override
2228 public boolean performAccessibilityAction(int action, Bundle arguments) {
2229 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
2230 }
2231
Jonathan Dixon3c909522012-02-28 18:45:06 +00002232 /** @hide */
2233 @Override
2234 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2235 int l, int t, int r, int b) {
2236 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2237 }
2238
2239 @Override
2240 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2241 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2242 }
2243
2244 @Override
2245 protected void onWindowVisibilityChanged(int visibility) {
2246 super.onWindowVisibilityChanged(visibility);
2247 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2248 }
2249
2250 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002251 protected void onDraw(Canvas canvas) {
2252 mProvider.getViewDelegate().onDraw(canvas);
2253 }
2254
2255 @Override
2256 public boolean performLongClick() {
2257 return mProvider.getViewDelegate().performLongClick();
2258 }
2259
2260 @Override
2261 protected void onConfigurationChanged(Configuration newConfig) {
2262 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2263 }
2264
2265 @Override
2266 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2267 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2268 }
2269
2270 @Override
2271 protected void onVisibilityChanged(View changedView, int visibility) {
2272 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002273 // This method may be called in the constructor chain, before the WebView provider is
2274 // created.
2275 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002276 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2277 }
2278
2279 @Override
2280 public void onWindowFocusChanged(boolean hasWindowFocus) {
2281 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2282 super.onWindowFocusChanged(hasWindowFocus);
2283 }
2284
2285 @Override
2286 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2287 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2288 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2289 }
2290
2291 /** @hide */
2292 @Override
2293 protected boolean setFrame(int left, int top, int right, int bottom) {
2294 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2295 }
2296
2297 @Override
2298 protected void onSizeChanged(int w, int h, int ow, int oh) {
2299 super.onSizeChanged(w, h, ow, oh);
2300 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2301 }
2302
2303 @Override
2304 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2305 super.onScrollChanged(l, t, oldl, oldt);
2306 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2307 }
2308
2309 @Override
2310 public boolean dispatchKeyEvent(KeyEvent event) {
2311 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2312 }
2313
2314 @Override
2315 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2316 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2317 }
2318
Jonathan Dixon3c909522012-02-28 18:45:06 +00002319 @Override
2320 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2321 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2322 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2323 }
2324
2325 @Override
2326 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2327 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2328 }
2329
2330 @Override
2331 public void setBackgroundColor(int color) {
2332 mProvider.getViewDelegate().setBackgroundColor(color);
2333 }
John Recka5408e62012-03-16 14:18:44 -07002334
2335 @Override
2336 public void setLayerType(int layerType, Paint paint) {
2337 super.setLayerType(layerType, paint);
2338 mProvider.getViewDelegate().setLayerType(layerType, paint);
2339 }
Ben Murdoche623e242012-09-07 20:47:07 +01002340
2341 @Override
2342 protected void dispatchDraw(Canvas canvas) {
2343 mProvider.getViewDelegate().preDispatchDraw(canvas);
2344 super.dispatchDraw(canvas);
2345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346}