blob: 826bcecd51c93a6054587a8ed1b77787a98b56cb [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
Raphael30df2372010-03-06 10:09:54 -080019import android.annotation.Widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
Cary Clarkc5cd5e92010-11-22 15:20:02 -050021import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.graphics.Bitmap;
23import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070024import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.graphics.Picture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.graphics.Rect;
Mike Reede8853fc2009-09-04 14:01:48 -040027import android.graphics.drawable.Drawable;
Adam Powell9d32d242010-03-29 16:02:07 -070028import android.net.http.SslCertificate;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -070029import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Bundle;
Steve Block08d584c2011-05-17 19:05:03 +010031import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Message;
Steve Block08d584c2011-05-17 19:05:03 +010033import android.os.StrictMode;
Selim Gurunda7d6422013-09-06 14:39:05 -070034import android.print.PrintDocumentAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070040import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.view.ViewGroup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070043import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070044import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010045import android.view.accessibility.AccessibilityNodeProvider;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050046import android.view.inputmethod.EditorInfo;
47import android.view.inputmethod.InputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010049
John Reck926cf562012-06-14 10:00:31 -070050import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import java.io.File;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010052import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54/**
Cary Clarkd6982c92009-05-29 11:02:22 -040055 * <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 -080056 * can roll your own web browser or simply display some online content within your Activity.
57 * It uses the WebKit rendering engine to display
58 * web pages and includes methods to navigate forward and backward
59 * through a history, zoom in and out, perform text searches and more.</p>
60 * <p>Note that, in order for your Activity to access the Internet and load web pages
Scott Main8b3cea02010-05-14 14:12:43 -070061 * in a WebView, you must add the {@code INTERNET} permissions to your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 * Android Manifest file:</p>
63 * <pre>&lt;uses-permission android:name="android.permission.INTERNET" /></pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010064 *
Scott Main8b3cea02010-05-14 14:12:43 -070065 * <p>This must be a child of the <a
Ben Dodson4e8620f2010-08-25 10:55:47 -070066 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
Scott Main8b3cea02010-05-14 14:12:43 -070067 * element.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010068 *
Scott Main4c359b72012-07-24 15:51:27 -070069 * <p>For more information, read
70 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p>
Scott Main41ec6532010-08-19 16:57:07 -070071 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010072 * <h3>Basic usage</h3>
73 *
74 * <p>By default, a WebView provides no browser-like widgets, does not
Scott Main8b3cea02010-05-14 14:12:43 -070075 * enable JavaScript and web page errors are ignored. If your goal is only
Mike Hearnadcd2ed2009-01-21 16:44:36 +010076 * to display some HTML as a part of your UI, this is probably fine;
77 * the user won't need to interact with the web page beyond reading
78 * it, and the web page won't need to interact with the user. If you
Scott Main8b3cea02010-05-14 14:12:43 -070079 * actually want a full-blown web browser, then you probably want to
80 * invoke the Browser application with a URL Intent rather than show it
81 * with a WebView. For example:
82 * <pre>
83 * Uri uri = Uri.parse("http://www.example.com");
84 * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
85 * startActivity(intent);
86 * </pre>
87 * <p>See {@link android.content.Intent} for more information.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010088 *
Ben Dodson4e8620f2010-08-25 10:55:47 -070089 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout,
Scott Main8b3cea02010-05-14 14:12:43 -070090 * or set the entire Activity window as a WebView during {@link
91 * android.app.Activity#onCreate(Bundle) onCreate()}:</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010092 * <pre class="prettyprint">
93 * WebView webview = new WebView(this);
94 * setContentView(webview);
Scott Main8b3cea02010-05-14 14:12:43 -070095 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010096 *
Scott Main8b3cea02010-05-14 14:12:43 -070097 * <p>Then load the desired web page:</p>
Scott Maine3b9f8b2010-05-18 08:41:36 -070098 * <pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010099 * // Simplest usage: note that an exception will NOT be thrown
100 * // if there is an error loading this page (see below).
101 * webview.loadUrl("http://slashdot.org/");
102 *
Scott Main8b3cea02010-05-14 14:12:43 -0700103 * // OR, you can also load from an HTML string:
Scott Maine3b9f8b2010-05-18 08:41:36 -0700104 * 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 +0100105 * webview.loadData(summary, "text/html", null);
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100106 * // ... although note that there are restrictions on what this HTML can do.
Scott Main8b3cea02010-05-14 14:12:43 -0700107 * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
108 * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100109 * </pre>
110 *
111 * <p>A WebView has several customization points where you can add your
112 * own behavior. These are:</p>
113 *
114 * <ul>
115 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass.
116 * This class is called when something that might impact a
117 * browser UI happens, for instance, progress updates and
Scott Main8b3cea02010-05-14 14:12:43 -0700118 * JavaScript alerts are sent here (see <a
119 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>).
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100120 * </li>
121 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass.
122 * It will be called when things happen that impact the
123 * rendering of the content, eg, errors or form submissions. You
Scott Main8b3cea02010-05-14 14:12:43 -0700124 * can also intercept URL loading here (via {@link
125 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String)
126 * shouldOverrideUrlLoading()}).</li>
127 * <li>Modifying the {@link android.webkit.WebSettings}, such as
128 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
129 * setJavaScriptEnabled()}. </li>
Steve Block4cd73c52011-11-09 13:06:52 +0000130 * <li>Injecting Java objects into the WebView using the
131 * {@link android.webkit.WebView#addJavascriptInterface} method. This
132 * method allows you to inject Java objects into a page's JavaScript
133 * context, so that they can be accessed by JavaScript in the page.</li>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100134 * </ul>
135 *
136 * <p>Here's a more complicated example, showing error handling,
137 * settings, and progress notification:</p>
138 *
139 * <pre class="prettyprint">
140 * // Let's display the progress in the activity title bar, like the
141 * // browser app does.
142 * getWindow().requestFeature(Window.FEATURE_PROGRESS);
143 *
144 * webview.getSettings().setJavaScriptEnabled(true);
145 *
146 * final Activity activity = this;
147 * webview.setWebChromeClient(new WebChromeClient() {
148 * public void onProgressChanged(WebView view, int progress) {
149 * // Activities and WebViews measure progress with different scales.
150 * // The progress meter will automatically disappear when we reach 100%
151 * activity.setProgress(progress * 1000);
152 * }
153 * });
154 * webview.setWebViewClient(new WebViewClient() {
155 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
156 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
157 * }
158 * });
159 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700160 * webview.loadUrl("http://developer.android.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100161 * </pre>
162 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700163 * <h3>Zoom</h3>
164 *
165 * <p>To enable the built-in zoom, set
166 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
167 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).</p>
168 * <p>NOTE: Using zoom if either the height or width is set to
169 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} may lead to undefined behavior
170 * and should be avoided.</p>
171 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100172 * <h3>Cookie and window management</h3>
173 *
174 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700175 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100176 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100177 * </p>
178 *
179 * <p>By default, requests by the HTML to open new windows are
180 * ignored. This is true whether they be opened by JavaScript or by
181 * the target attribute on a link. You can customize your
Scott Main8b3cea02010-05-14 14:12:43 -0700182 * {@link WebChromeClient} to provide your own behaviour for opening multiple windows,
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100183 * and render them in whatever manner you want.</p>
184 *
Scott Main8b3cea02010-05-14 14:12:43 -0700185 * <p>The standard behavior for an Activity is to be destroyed and
186 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100187 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700188 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100189 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700190 * re-orient itself as appropriate. Read <a
191 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
192 * more information about how to handle configuration changes during runtime.</p>
193 *
194 *
195 * <h3>Building web pages to support different screen densities</h3>
196 *
197 * <p>The screen density of a device is based on the screen resolution. A screen with low density
198 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700199 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700200 * screen is important because, other things being equal, a UI element (such as a button) whose
201 * height and width are defined in terms of screen pixels will appear larger on the lower density
202 * screen and smaller on the higher density screen.
203 * For simplicity, Android collapses all actual screen densities into three generalized densities:
204 * high, medium, and low.</p>
205 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
206 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
207 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
208 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100209 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
210 * and meta tag features to help you (as a web developer) target screens with different screen
211 * densities.</p>
Scott Main8b3cea02010-05-14 14:12:43 -0700212 * <p>Here's a summary of the features you can use to handle different screen densities:</p>
213 * <ul>
214 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
215 * default scaling factor used for the current device. For example, if the value of {@code
216 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
217 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
218 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
219 * 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 -0800220 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700221 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
222 * densities for which this style sheet is to be used. The corresponding value should be either
223 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
224 * density, or high density screens, respectively. For example:
225 * <pre>
226 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
227 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
228 * which is the high density pixel ratio.</p>
229 * </li>
Martin Kosiba0d147d92013-09-19 19:05:00 -0700230 * </ul>
Scott Main8b3cea02010-05-14 14:12:43 -0700231 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800232 * <h3>HTML5 Video support</h3>
233 *
234 * <p>In order to support inline HTML5 video in your application, you need to have hardware
235 * acceleration turned on, and set a {@link android.webkit.WebChromeClient}. For full screen support,
236 * implementations of {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
237 * and {@link WebChromeClient#onHideCustomView()} are required,
238 * {@link WebChromeClient#getVideoLoadingProgressView()} is optional.
239 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 */
Steve Block406aeb22012-04-23 18:17:19 +0100241// Implementation notes.
242// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
243// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
244// Methods are delegated to the provider implementation: all public API methods introduced in this
245// file are fully delegated, whereas public and protected methods from the View base classes are
246// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800247@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400248public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700250 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700252 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700253
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700254 // Throwing an exception for incorrect thread usage if the
255 // build target is JB MR2 or newer. Defaults to false, and is
256 // set in the WebView constructor.
Jonathan Dixon0d6a1452013-08-21 13:09:36 -0700257 private static volatile boolean sEnforceThreadChecking = false;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * Transportation object for returning WebView across thread boundaries.
261 */
262 public class WebViewTransport {
263 private WebView mWebview;
264
265 /**
Steve Block4e584df2012-04-24 23:12:47 +0100266 * Sets the WebView to the transportation object.
267 *
268 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 */
270 public synchronized void setWebView(WebView webview) {
271 mWebview = webview;
272 }
273
274 /**
Steve Block4e584df2012-04-24 23:12:47 +0100275 * Gets the WebView object.
276 *
277 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 */
279 public synchronized WebView getWebView() {
280 return mWebview;
281 }
282 }
283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 /**
Steve Block4e584df2012-04-24 23:12:47 +0100285 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 */
287 public static final String SCHEME_TEL = "tel:";
288 /**
Steve Block4e584df2012-04-24 23:12:47 +0100289 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 */
291 public static final String SCHEME_MAILTO = "mailto:";
292 /**
Steve Block4e584df2012-04-24 23:12:47 +0100293 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 */
295 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 /**
Victoria Leased405a432012-03-22 15:53:48 -0700298 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700299 */
300 public interface FindListener {
301 /**
Steve Block4e584df2012-04-24 23:12:47 +0100302 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700303 *
Steve Block4e584df2012-04-24 23:12:47 +0100304 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700305 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100306 * @param isDoneCounting whether the find operation has actually completed. The listener
307 * may be notified multiple times while the
308 * operation is underway, and the numberOfMatches
309 * value should not be considered final unless
310 * isDoneCounting is true.
Victoria Leased405a432012-03-22 15:53:48 -0700311 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700312 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700313 boolean isDoneCounting);
314 }
315
316 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100318 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100319 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100321 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 public interface PictureListener {
323 /**
Steve Block72498ed2012-07-17 15:57:25 +0100324 * Used to provide notification that the WebView's picture has changed.
325 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100326 *
327 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000328 * @param picture the new picture. Applications targeting
329 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
330 * will always receive a null Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100331 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100333 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 public void onNewPicture(WebView view, Picture picture);
335 }
336
Jonathan Dixon19644b62011-12-21 14:21:36 +0000337 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 /**
Steve Block4e584df2012-04-24 23:12:47 +0100339 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 */
341 public static final int UNKNOWN_TYPE = 0;
342 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100343 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 */
Steve Block1854ddb2011-04-19 12:18:19 +0100345 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 public static final int ANCHOR_TYPE = 1;
347 /**
Steve Block4e584df2012-04-24 23:12:47 +0100348 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 */
350 public static final int PHONE_TYPE = 2;
351 /**
Steve Block4e584df2012-04-24 23:12:47 +0100352 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 */
354 public static final int GEO_TYPE = 3;
355 /**
Steve Block4e584df2012-04-24 23:12:47 +0100356 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 */
358 public static final int EMAIL_TYPE = 4;
359 /**
Steve Block4e584df2012-04-24 23:12:47 +0100360 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 */
362 public static final int IMAGE_TYPE = 5;
363 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100364 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 */
Steve Block1854ddb2011-04-19 12:18:19 +0100366 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 public static final int IMAGE_ANCHOR_TYPE = 6;
368 /**
Steve Block4e584df2012-04-24 23:12:47 +0100369 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 */
371 public static final int SRC_ANCHOR_TYPE = 7;
372 /**
Steve Block4e584df2012-04-24 23:12:47 +0100373 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 */
375 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
376 /**
Steve Block4e584df2012-04-24 23:12:47 +0100377 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 */
379 public static final int EDIT_TEXT_TYPE = 9;
380
381 private int mType;
382 private String mExtra;
383
Jonathan Dixon3c909522012-02-28 18:45:06 +0000384 /**
385 * @hide Only for use by WebViewProvider implementations
386 */
387 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 mType = UNKNOWN_TYPE;
389 }
390
Jonathan Dixon3c909522012-02-28 18:45:06 +0000391 /**
392 * @hide Only for use by WebViewProvider implementations
393 */
394 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 mType = type;
396 }
397
Jonathan Dixon3c909522012-02-28 18:45:06 +0000398 /**
399 * @hide Only for use by WebViewProvider implementations
400 */
401 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 mExtra = extra;
403 }
404
Jonathan Dixone230e542011-12-21 10:57:00 +0000405 /**
Steve Block4e584df2012-04-24 23:12:47 +0100406 * Gets the type of the hit test result. See the XXX_TYPE constants
407 * defined in this class.
408 *
409 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000410 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 public int getType() {
412 return mType;
413 }
414
Jonathan Dixone230e542011-12-21 10:57:00 +0000415 /**
Steve Block4e584df2012-04-24 23:12:47 +0100416 * Gets additional type-dependant information about the result. See
417 * {@link WebView#getHitTestResult()} for details. May either be null
418 * or contain extra information about this result.
419 *
420 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000421 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 public String getExtra() {
423 return mExtra;
424 }
425 }
426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 /**
Steve Block4e584df2012-04-24 23:12:47 +0100428 * Constructs a new WebView with a Context object.
429 *
430 * @param context a Context object used to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 */
432 public WebView(Context context) {
433 this(context, null);
434 }
435
436 /**
Steve Block4e584df2012-04-24 23:12:47 +0100437 * Constructs a new WebView with layout parameters.
438 *
439 * @param context a Context object used to access application assets
440 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 */
442 public WebView(Context context, AttributeSet attrs) {
443 this(context, attrs, com.android.internal.R.attr.webViewStyle);
444 }
445
446 /**
Steve Block4e584df2012-04-24 23:12:47 +0100447 * Constructs a new WebView with layout parameters and a default style.
448 *
449 * @param context a Context object used to access application assets
450 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700451 * @param defStyleAttr an attribute in the current theme that contains a
452 * reference to a style resource that supplies default values for
453 * the view. Can be 0 to not look for defaults.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 */
Alan Viverette617feb92013-09-09 18:09:13 -0700455 public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
456 this(context, attrs, defStyleAttr, 0);
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700457 }
458
459 /**
Steve Block4e584df2012-04-24 23:12:47 +0100460 * Constructs a new WebView with layout parameters and a default style.
461 *
462 * @param context a Context object used to access application assets
463 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700464 * @param defStyleAttr an attribute in the current theme that contains a
465 * reference to a style resource that supplies default values for
466 * the view. Can be 0 to not look for defaults.
467 * @param defStyleRes a resource identifier of a style resource that
468 * supplies default values for the view, used only if
469 * defStyleAttr is 0 or can not be found in the theme. Can be 0
470 * to not look for defaults.
471 */
472 public WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
473 this(context, attrs, defStyleAttr, defStyleRes, null, false);
474 }
475
476 /**
477 * Constructs a new WebView with layout parameters and a default style.
478 *
479 * @param context a Context object used to access application assets
480 * @param attrs an AttributeSet passed to our parent
481 * @param defStyleAttr an attribute in the current theme that contains a
482 * reference to a style resource that supplies default values for
483 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100484 * @param privateBrowsing whether this WebView will be initialized in
485 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400486 *
487 * @deprecated Private browsing is no longer supported directly via
488 * WebView and will be removed in a future release. Prefer using
489 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
490 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700491 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400492 @Deprecated
Alan Viverette617feb92013-09-09 18:09:13 -0700493 public WebView(Context context, AttributeSet attrs, int defStyleAttr,
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700494 boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700495 this(context, attrs, defStyleAttr, 0, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100496 }
497
498 /**
Steve Block4e584df2012-04-24 23:12:47 +0100499 * Constructs a new WebView with layout parameters, a default style and a set
500 * of custom Javscript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800501 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100502 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100503 *
504 * @param context a Context object used to access application assets
505 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700506 * @param defStyleAttr an attribute in the current theme that contains a
507 * reference to a style resource that supplies default values for
508 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100509 * @param javaScriptInterfaces a Map of interface names, as keys, and
510 * object implementing those interfaces, as
511 * values
512 * @param privateBrowsing whether this WebView will be initialized in
513 * private mode
Jonathan Dixon3c909522012-02-28 18:45:06 +0000514 * @hide This is used internally by dumprendertree, as it requires the javaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100515 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100516 */
Alan Viverette617feb92013-09-09 18:09:13 -0700517 protected WebView(Context context, AttributeSet attrs, int defStyleAttr,
Steve Block81f19ff2010-11-01 13:23:24 +0000518 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700519 this(context, attrs, defStyleAttr, 0, javaScriptInterfaces, privateBrowsing);
520 }
521
522 /**
523 * @hide
524 */
525 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
526 protected WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
527 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
528 super(context, attrs, defStyleAttr, defStyleRes);
Kristian Monsen87af7312011-09-09 02:12:51 +0100529 if (context == null) {
530 throw new IllegalArgumentException("Invalid context argument");
531 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700532 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
533 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000534 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700535 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "WebView<init>");
Kristian Monsen87af7312011-09-09 02:12:51 +0100536
Jonathan Dixon3c909522012-02-28 18:45:06 +0000537 ensureProviderCreated();
538 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100539 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
540 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542
543 /**
Steve Block4e584df2012-04-24 23:12:47 +0100544 * Specifies whether the horizontal scrollbar has overlay style.
545 *
546 * @param overlay true if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 */
548 public void setHorizontalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100549 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700550 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setHorizontalScrollbarOverlay=" + overlay);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000551 mProvider.setHorizontalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 }
553
554 /**
Steve Block4e584df2012-04-24 23:12:47 +0100555 * Specifies whether the vertical scrollbar has overlay style.
556 *
557 * @param overlay true if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 */
559 public void setVerticalScrollbarOverlay(boolean overlay) {
Steve Block51b08912011-04-27 15:04:48 +0100560 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700561 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setVerticalScrollbarOverlay=" + overlay);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000562 mProvider.setVerticalScrollbarOverlay(overlay);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
565 /**
Steve Block4e584df2012-04-24 23:12:47 +0100566 * Gets whether horizontal scrollbar has overlay style.
567 *
568 * @return true if horizontal scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 */
570 public boolean overlayHorizontalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100571 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000572 return mProvider.overlayHorizontalScrollbar();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 }
574
575 /**
Steve Block4e584df2012-04-24 23:12:47 +0100576 * Gets whether vertical scrollbar has overlay style.
577 *
578 * @return true if vertical scrollbar has overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 */
580 public boolean overlayVerticalScrollbar() {
Steve Block51b08912011-04-27 15:04:48 +0100581 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000582 return mProvider.overlayVerticalScrollbar();
Mike Reede8853fc2009-09-04 14:01:48 -0400583 }
584
Michael Kolbe54f6652011-03-16 09:11:51 -0700585 /**
Steve Block4e584df2012-04-24 23:12:47 +0100586 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700587 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700588 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400589 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400590 */
Michael Kolb73980a92010-08-05 16:32:51 -0700591 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100592 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000593 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
596 /**
Steve Block4e584df2012-04-24 23:12:47 +0100597 * Gets the SSL certificate for the main top-level page or null if there is
598 * no certificate (the site is not secure).
599 *
600 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 */
602 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100603 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000604 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 }
606
607 /**
608 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400609 *
610 * @deprecated Calling this function has no useful effect, and will be
611 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400613 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100615 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700616 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setCertificate=" + certificate);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000617 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 }
619
620 //-------------------------------------------------------------------------
621 // Methods called by activity
622 //-------------------------------------------------------------------------
623
624 /**
Steve Block32fe4102012-07-17 16:29:11 +0100625 * Sets a username and password pair for the specified host. This data is
626 * used by the Webview to autocomplete username and password fields in web
627 * forms. Note that this is unrelated to the credentials used for HTTP
628 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100629 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000630 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100631 * @param username the username for the given host
632 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100633 * @see WebViewDatabase#clearUsernamePassword
634 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800635 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800637 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100639 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700640 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "savePassword=" + host);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000641 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 }
643
644 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100645 * Stores HTTP authentication credentials for a given host and realm. This
646 * method is intended to be used with
647 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 *
Steve Block46ce1db2012-07-17 16:43:00 +0100649 * @param host the host to which the credentials apply
650 * @param realm the realm to which the credentials apply
651 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100652 * @param password the password
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800653 * @see #getHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100654 * @see WebViewDatabase#hasHttpAuthUsernamePassword
655 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
657 public void setHttpAuthUsernamePassword(String host, String realm,
658 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100659 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700660 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setHttpAuthUsernamePassword=" + host);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000661 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663
664 /**
Steve Block46ce1db2012-07-17 16:43:00 +0100665 * Retrieves HTTP authentication credentials for a given host and realm.
666 * This method is intended to be used with
667 * {@link WebViewClient#onReceivedHttpAuthRequest}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 *
Steve Block46ce1db2012-07-17 16:43:00 +0100669 * @param host the host to which the credentials apply
670 * @param realm the realm to which the credentials apply
671 * @return the credentials as a String array, if found. The first element
672 * is the username and the second element is the password. Null if
673 * no credentials are found.
Jonathan Dixon47aaba32012-11-30 16:32:17 -0800674 * @see #setHttpAuthUsernamePassword
Steve Block46ce1db2012-07-17 16:43:00 +0100675 * @see WebViewDatabase#hasHttpAuthUsernamePassword
676 * @see WebViewDatabase#clearHttpAuthUsernamePassword
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 */
678 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100679 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000680 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400681 }
682
683 /**
Steve Block4e584df2012-04-24 23:12:47 +0100684 * Destroys the internal state of this WebView. This method should be called
685 * after this WebView has been removed from the view system. No other
686 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 */
688 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100689 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700690 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "destroy");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000691 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
694 /**
695 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100696 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100697 *
698 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400699 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100701 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 public static void enablePlatformNotifications() {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000703 getFactory().getStatics().setPlatformNotificationsEnabled(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 }
705
706 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100707 * Disables platform notifications of data state and proxy changes.
708 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100709 *
710 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400711 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100713 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 public static void disablePlatformNotifications() {
Jonathan Dixon3c909522012-02-28 18:45:06 +0000715 getFactory().getStatics().setPlatformNotificationsEnabled(false);
Feng Qianb3081372009-06-29 15:55:18 -0700716 }
717
718 /**
Primiano Tucci24426752013-09-05 12:01:51 +0100719 * Used only by internal tests to free up memory.
720 *
721 * @hide
722 */
723 public static void freeMemoryForTests() {
Primiano Tucci24426752013-09-05 12:01:51 +0100724 getFactory().getStatics().freeMemoryForTests();
725 }
726
727 /**
Steve Block4e584df2012-04-24 23:12:47 +0100728 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000729 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100731 *
732 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 */
734 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100735 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700736 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setNetworkAvailable=" + networkUp);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000737 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 }
739
740 /**
Steve Block4e584df2012-04-24 23:12:47 +0100741 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
743 * method no longer stores the display data for this WebView. The previous
744 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400745 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100746 *
747 * @param outState the Bundle to store this WebView's state
748 * @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 -0800749 * saveState fails, the returned list will be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 */
751 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100752 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700753 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveState");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000754 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756
757 /**
Steve Block4e584df2012-04-24 23:12:47 +0100758 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100760 * @param b a Bundle to store the display data
761 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 * overwritten with this WebView's picture data.
Steve Block4e584df2012-04-24 23:12:47 +0100763 * @return true if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100764 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400765 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100767 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400768 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100769 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700770 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "savePicture=" + dest.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +0000771 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 }
773
774 /**
Steve Block4e584df2012-04-24 23:12:47 +0100775 * Restores the display data that was saved in {@link #savePicture}. Used in
776 * conjunction with {@link #restoreState}. Note that this will not work if
777 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700778 *
Steve Block4e584df2012-04-24 23:12:47 +0100779 * @param b a Bundle containing the saved display data
780 * @param src the file where the picture data was stored
781 * @return true if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100782 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400783 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100785 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100787 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700788 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "restorePicture=" + src.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +0000789 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700790 }
791
792 /**
Steve Block42499062012-07-17 15:34:46 +0100793 * Restores the state of this WebView from the given Bundle. This method is
794 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
795 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100796 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400797 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400799 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100800 *
801 * @param inState the incoming Bundle of state
802 * @return the restored back/forward list or null if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 */
804 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100805 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700806 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "restoreState");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000807 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 }
809
810 /**
Steve Block4e584df2012-04-24 23:12:47 +0100811 * Loads the given URL with the specified additional HTTP headers.
812 *
813 * @param url the URL of the resource to load
814 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100815 * HTTP request for this URL, specified as a map from name to
816 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100817 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100818 * controlling caching, accept types or the User-Agent, their
Steve Block4e584df2012-04-24 23:12:47 +0100819 * values may be overriden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800820 */
Steve Blockf71dea02011-08-01 12:29:14 +0100821 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100822 checkThread();
Selim Gurun90b48b22013-09-20 17:22:35 -0700823 if (DebugFlags.TRACE_API) {
824 StringBuilder headers = new StringBuilder();
825 if (additionalHttpHeaders != null) {
826 for (Map.Entry<String, String> entry : additionalHttpHeaders.entrySet()) {
827 headers.append(entry.getKey() + ":" + entry.getValue() + "\n");
828 }
829 }
830 Log.d(LOGTAG, "loadUrl(extra headers)=" + url + "\n" + headers);
831 }
Jonathan Dixon3c909522012-02-28 18:45:06 +0000832 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800833 }
834
835 /**
Steve Block4e584df2012-04-24 23:12:47 +0100836 * Loads the given URL.
837 *
838 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 */
840 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100841 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700842 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadUrl=" + url);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000843 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
845
846 /**
Steve Block4e584df2012-04-24 23:12:47 +0100847 * Loads the URL with postData using "POST" method into this WebView. If url
Hui Shuc60ad9c2014-02-05 09:30:36 -0800848 * is not a network URL, it will be loaded with {@link #loadUrl(String)}
849 * instead, ignoring the postData param.
Cary Clarkd6982c92009-05-29 11:02:22 -0400850 *
Steve Block4e584df2012-04-24 23:12:47 +0100851 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100852 * @param postData the data will be passed to "POST" request, which must be
853 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700854 */
855 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100856 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700857 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "postUrl=" + url);
Hui Shuc60ad9c2014-02-05 09:30:36 -0800858 if (URLUtil.isNetworkUrl(url)) {
859 mProvider.postUrl(url, postData);
860 } else {
861 mProvider.loadUrl(url);
862 }
Grace Kloba57534302009-05-22 18:55:02 -0700863 }
864
865 /**
Steve Block4e584df2012-04-24 23:12:47 +0100866 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100867 * <p>
868 * Note that JavaScript's same origin policy means that script running in a
869 * page loaded using this method will be unable to access content loaded
870 * using any scheme other than 'data', including 'http(s)'. To avoid this
871 * restriction, use {@link
872 * #loadDataWithBaseURL(String,String,String,String,String)
873 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100874 * <p>
Steve Block27f3e322012-07-23 10:45:59 +0100875 * The encoding parameter specifies whether the data is base64 or URL
876 * encoded. If the data is base64 encoded, the value of the encoding
877 * parameter must be 'base64'. For all other values of the parameter,
878 * including null, it is assumed that the data uses ASCII encoding for
Steve Blockf95d4902011-06-09 11:53:26 +0100879 * octets inside the range of safe URL characters and use the standard %xx
Steve Block27f3e322012-07-23 10:45:59 +0100880 * hex encoding of URLs for octets outside that range. For example, '#',
881 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
Steve Blockb19c7872011-10-10 14:09:44 +0100882 * <p>
883 * The 'data' scheme URL formed by this method uses the default US-ASCII
884 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100885 * 'data' scheme URL which explicitly specifies a charset parameter in the
886 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
887 * Note that the charset obtained from the mediatype portion of a data URL
888 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +0100889 *
890 * @param data a String of data in the given encoding
891 * @param mimeType the MIME type of the data, e.g. 'text/html'
892 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 */
894 public void loadData(String data, String mimeType, String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100895 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700896 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadData");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000897 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 }
899
900 /**
Steve Block4e584df2012-04-24 23:12:47 +0100901 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100902 * the content. The base URL is used both to resolve relative URLs and when
903 * applying JavaScript's same origin policy. The historyUrl is used for the
904 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100906 * Note that content specified in this way can access local device files
907 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
908 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100909 * <p>
910 * If the base URL uses the data scheme, this method is equivalent to
911 * calling {@link #loadData(String,String,String) loadData()} and the
Ben Murdoch597256e2013-07-22 16:52:12 +0100912 * historyUrl is ignored, and the data will be treated as part of a data: URL.
913 * If the base URL uses any other scheme, then the data will be loaded into
914 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
915 * entities in the string will not be decoded.
Steve Block4e584df2012-04-24 23:12:47 +0100916 *
917 * @param baseUrl the URL to use as the page's base URL. If null defaults to
918 * 'about:blank'.
919 * @param data a String of data in the given encoding
920 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
921 * defaults to 'text/html'.
922 * @param encoding the encoding of the data
923 * @param historyUrl the URL to use as the history entry. If null defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000924 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 */
926 public void loadDataWithBaseURL(String baseUrl, String data,
Leon Scroggins1bb1a912010-03-23 15:39:46 -0400927 String mimeType, String encoding, String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100928 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700929 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "loadDataWithBaseURL=" + baseUrl);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000930 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 }
932
933 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +0100934 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
935 * If non-null, |resultCallback| will be invoked with any result returned from that
936 * execution. This method must be called on the UI thread and the callback will
937 * be made on the UI thread.
938 *
939 * @param script the JavaScript to execute.
940 * @param resultCallback A callback to be invoked when the script execution
941 * completes with the result of the execution (if any).
942 * May be null if no notificaion of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100943 */
944 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) {
945 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700946 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "evaluateJavascript=" + script);
Ben Murdocha5cdd512013-07-17 16:25:07 +0100947 mProvider.evaluateJavaScript(script, resultCallback);
948 }
949
950 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700951 * Saves the current view as a web archive.
952 *
Steve Block4e584df2012-04-24 23:12:47 +0100953 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700954 */
955 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100956 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700957 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveWebArchive=" + filename);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000958 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700959 }
960
961 /**
962 * Saves the current view as a web archive.
963 *
Steve Block4e584df2012-04-24 23:12:47 +0100964 * @param basename the filename where the archive should be placed
965 * @param autoname if false, takes basename to be a file. If true, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700966 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100967 * chosen according to the URL of the current page.
968 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700969 * parameter for onReceiveValue will either be the filename
970 * under which the file was saved, or null if saving the
971 * file failed.
972 */
973 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
Steve Block51b08912011-04-27 15:04:48 +0100974 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700975 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "saveWebArchive(auto)=" + basename);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000976 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700977 }
978
979 /**
Steve Block4e584df2012-04-24 23:12:47 +0100980 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 */
982 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100983 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700984 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "stopLoading");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000985 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 }
987
988 /**
Steve Block4e584df2012-04-24 23:12:47 +0100989 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 */
991 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100992 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700993 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "reload");
Jonathan Dixon3c909522012-02-28 18:45:06 +0000994 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 }
996
997 /**
Steve Block4e584df2012-04-24 23:12:47 +0100998 * Gets whether this WebView has a back history item.
999 *
1000 * @return true iff this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 */
1002 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +01001003 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001004 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 }
1006
1007 /**
Steve Block4e584df2012-04-24 23:12:47 +01001008 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 */
1010 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +01001011 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001012 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goBack");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001013 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 }
1015
1016 /**
Steve Block4e584df2012-04-24 23:12:47 +01001017 * Gets whether this WebView has a forward history item.
1018 *
1019 * @return true iff this Webview has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 */
1021 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +01001022 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001023 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 }
1025
1026 /**
Steve Block4e584df2012-04-24 23:12:47 +01001027 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 */
1029 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +01001030 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001031 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goForward");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001032 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 }
1034
1035 /**
Steve Block4e584df2012-04-24 23:12:47 +01001036 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +01001038 *
1039 * @param steps the negative or positive number of steps to move the
1040 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 */
1042 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001043 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001044 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
1046
1047 /**
Steve Block4e584df2012-04-24 23:12:47 +01001048 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 * the current item. Steps is negative if backward and positive
1050 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +01001051 *
1052 * @param steps the number of steps to take back or forward in the back
1053 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 */
1055 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001056 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001057 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "goBackOrForwad=" + steps);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001058 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001060
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001061 /**
Steve Block4e584df2012-04-24 23:12:47 +01001062 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001063 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -07001064 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +01001065 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001066 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 /**
Steve Block4e584df2012-04-24 23:12:47 +01001070 * Scrolls the contents of this WebView up by half the view size.
1071 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 * @param top true to jump to the top of the page
1073 * @return true if the page was scrolled
1074 */
1075 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +01001076 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001077 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pageUp");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001078 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 /**
Steve Block4e584df2012-04-24 23:12:47 +01001082 * Scrolls the contents of this WebView down by half the page size.
1083 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 * @param bottom true to jump to bottom of page
1085 * @return true if the page was scrolled
1086 */
1087 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001088 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001089 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pageDown");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001090 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092
1093 /**
Steve Block4e584df2012-04-24 23:12:47 +01001094 * Clears this WebView so that onDraw() will draw nothing but white background,
1095 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001096 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1097 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001099 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001101 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001102 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearView");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001103 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 /**
Steve Block72498ed2012-07-17 15:57:25 +01001107 * Gets a new picture that captures the current contents of this WebView.
1108 * The picture is of the entire document being displayed, and is not
1109 * limited to the area currently displayed by this WebView. Also, the
1110 * picture is a static copy and is unaffected by later changes to the
1111 * content being displayed.
1112 * <p>
1113 * Note that due to internal changes, for API levels between
1114 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1115 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1116 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001117 * <p>
1118 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1119 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
1120 * additional conversion at a cost in memory and performance. Also the
1121 * {@link android.graphics.Picture#createFromStream} and
1122 * {@link android.graphics.Picture#writeToStream} methods are not supported on the
1123 * returned object.
1124 *
1125 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001126 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 *
Steve Block72498ed2012-07-17 15:57:25 +01001128 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001130 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001132 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001133 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "capturePicture");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001134 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136
Cary Clarkd6982c92009-05-29 11:02:22 -04001137 /**
Selim Gurunda7d6422013-09-06 14:39:05 -07001138 * Creates a PrintDocumentAdapter that provides the content of this Webview for printing.
1139 * Only supported for API levels
Chet Haasee8222dd2013-09-05 07:44:18 -07001140 * {@link android.os.Build.VERSION_CODES#KITKAT} and above.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001141 *
Selim Gurunda7d6422013-09-06 14:39:05 -07001142 * The adapter works by converting the Webview contents to a PDF stream. The Webview cannot
1143 * be drawn during the conversion process - any such draws are undefined. It is recommended
1144 * to use a dedicated off screen Webview for the printing. If necessary, an application may
1145 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1146 * wrapped around the object returned and observing the onStart and onFinish methods. See
1147 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001148 */
Selim Gurunda7d6422013-09-06 14:39:05 -07001149 public PrintDocumentAdapter createPrintDocumentAdapter() {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001150 checkThread();
Selim Gurunda7d6422013-09-06 14:39:05 -07001151 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "createPrintDocumentAdapter");
1152 return mProvider.createPrintDocumentAdapter();
Selim Gurun2167c0b2013-08-05 15:23:09 -07001153 }
1154
1155 /**
Steve Block4e584df2012-04-24 23:12:47 +01001156 * Gets the current scale of this WebView.
1157 *
1158 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001159 *
1160 * @deprecated This method is prone to inaccuracy due to race conditions
1161 * between the web rendering and UI threads; prefer
1162 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001164 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001165 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001167 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001168 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001169 }
1170
1171 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001172 * Sets the initial scale for this WebView. 0 means default.
1173 * The behavior for the default scale depends on the state of
1174 * {@link WebSettings#getUseWideViewPort()} and
1175 * {@link WebSettings#getLoadWithOverviewMode()}.
1176 * If the content fits into the WebView control by width, then
1177 * the zoom is set to 100%. For wide content, the behavor
1178 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
1179 * If its value is true, the content will be zoomed out to be fit
1180 * by width into the WebView control, otherwise not.
1181 *
1182 * If initial scale is greater than 0, WebView starts with this value
1183 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001184 * Please note that unlike the scale properties in the viewport meta tag,
1185 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 *
Steve Block4e584df2012-04-24 23:12:47 +01001187 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 */
1189 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001190 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001191 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setInitialScale=" + scaleInPercent);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001192 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
1194
1195 /**
Steve Block4e584df2012-04-24 23:12:47 +01001196 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 * result in the zoom widget appearing on the screen to control the zoom
1198 * level of this WebView.
1199 */
1200 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001201 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001202 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "invokeZoomPicker");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001203 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 }
1205
1206 /**
Steve Block4e584df2012-04-24 23:12:47 +01001207 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1208 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1209 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1210 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1211 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001213 * 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 -08001214 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001215 * 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 -08001216 * a child node. If a phone number is found, the HitTestResult type is set
1217 * to PHONE_TYPE and the phone number is set in the "extra" field of
1218 * HitTestResult. If a map address is found, the HitTestResult type is set
1219 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1220 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1221 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1222 * HitTestResult type is set to UNKNOWN_TYPE.
1223 */
1224 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001225 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001226 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "getHitTestResult");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001227 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001228 }
1229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 /**
Steve Block4e584df2012-04-24 23:12:47 +01001231 * Requests the anchor or image element URL at the last tapped point.
Cary Clark861368a2010-12-15 11:24:37 -05001232 * If hrefMsg is null, this method returns immediately and does not
1233 * dispatch hrefMsg to its target. If the tapped point hits an image,
1234 * an anchor, or an image in an anchor, the message associates
1235 * strings in named keys in its data. The value paired with the key
1236 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001237 *
Steve Block4e584df2012-04-24 23:12:47 +01001238 * @param hrefMsg the message to be dispatched with the result of the
1239 * request. The message data contains three keys. "url"
1240 * returns the anchor's href attribute. "title" returns the
1241 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 */
1243 public void requestFocusNodeHref(Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001244 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001245 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "requestFocusNodeHref");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001246 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 /**
Steve Block4e584df2012-04-24 23:12:47 +01001250 * Requests the URL of the image last touched by the user. msg will be sent
1251 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001252 *
Steve Block4e584df2012-04-24 23:12:47 +01001253 * @param msg the message to be dispatched with the result of the request
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 * as the data member with "url" as key. The result can be null.
1255 */
1256 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001257 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001258 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "requestImageRef");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001259 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001260 }
1261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 /**
Steve Block4e584df2012-04-24 23:12:47 +01001263 * 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 -08001264 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001265 * that URL has begun, the current page may not have changed.
1266 *
1267 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 */
John Reck926cf562012-06-14 10:00:31 -07001269 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001271 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001272 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 /**
Steve Block4e584df2012-04-24 23:12:47 +01001276 * Gets the original URL for the current page. This is not always the same
1277 * as the URL passed to WebViewClient.onPageStarted because although the
1278 * load for that URL has begun, the current page may not have changed.
1279 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001281 *
1282 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 */
John Reck926cf562012-06-14 10:00:31 -07001284 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001286 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001287 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 }
1289
1290 /**
Steve Block4e584df2012-04-24 23:12:47 +01001291 * 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 -08001292 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001293 *
1294 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295 */
John Reck926cf562012-06-14 10:00:31 -07001296 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001298 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001299 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 }
1301
1302 /**
Steve Block4e584df2012-04-24 23:12:47 +01001303 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001305 *
1306 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 */
1308 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001309 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001310 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 }
1312
1313 /**
Steve Block4e584df2012-04-24 23:12:47 +01001314 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001315 * a URL on this site's server pointing to the standard location of a
1316 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001317 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001318 * @hide
1319 */
1320 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001321 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001322 }
1323
1324 /**
Steve Block4e584df2012-04-24 23:12:47 +01001325 * Gets the progress for the current page.
1326 *
1327 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 */
1329 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001330 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001331 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 /**
Steve Block4e584df2012-04-24 23:12:47 +01001335 * Gets the height of the HTML content.
1336 *
1337 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 */
John Reck926cf562012-06-14 10:00:31 -07001339 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001341 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001342 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 }
1344
1345 /**
Steve Block4e584df2012-04-24 23:12:47 +01001346 * Gets the width of the HTML content.
1347 *
1348 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001349 * @hide
1350 */
John Reck926cf562012-06-14 10:00:31 -07001351 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001352 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001353 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001354 }
1355
1356 /**
Steve Block4e584df2012-04-24 23:12:47 +01001357 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1358 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001359 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 */
1361 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001362 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001363 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "pauseTimers");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001364 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 }
1366
1367 /**
Steve Block4e584df2012-04-24 23:12:47 +01001368 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001369 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 */
1371 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001372 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001373 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "resumeTimers");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001374 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 }
1376
1377 /**
Steve Block4e584df2012-04-24 23:12:47 +01001378 * Pauses any extra processing associated with this WebView and its
1379 * associated DOM, plugins, JavaScript etc. For example, if this WebView is
1380 * taken offscreen, this could be called to reduce unnecessary CPU or
1381 * network traffic. When this WebView is again "active", call onResume().
Steve Block81f19ff2010-11-01 13:23:24 +00001382 * Note that this differs from pauseTimers(), which affects all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001383 */
1384 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001385 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001386 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "onPause");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001387 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001388 }
1389
1390 /**
Steve Block4e584df2012-04-24 23:12:47 +01001391 * Resumes a WebView after a previous call to onPause().
Mike Reedd205d5b2009-05-27 11:02:29 -04001392 */
1393 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001394 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001395 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "onResume");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001396 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001397 }
1398
1399 /**
Steve Block4e584df2012-04-24 23:12:47 +01001400 * Gets whether this WebView is paused, meaning onPause() was called.
1401 * Calling onResume() sets the paused state back to false.
1402 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001403 * @hide
1404 */
1405 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001406 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001407 }
1408
1409 /**
Steve Block4e584df2012-04-24 23:12:47 +01001410 * Informs this WebView that memory is low so that it can free any available
1411 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001412 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1413 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001414 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001415 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001416 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001417 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001418 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "freeMemory");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001419 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001420 }
1421
1422 /**
Steve Block4e584df2012-04-24 23:12:47 +01001423 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001424 * this will clear the cache for all WebViews used.
1425 *
Steve Block4e584df2012-04-24 23:12:47 +01001426 * @param includeDiskFiles if false, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 */
1428 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001429 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001430 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearCache");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001431 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
1433
1434 /**
Steve Block219dfa42012-07-20 10:31:21 +01001435 * Removes the autocomplete popup from the currently focused form field, if
1436 * present. Note this only affects the display of the autocomplete popup,
1437 * it does not remove any saved form data from this WebView's store. To do
1438 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 */
1440 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001441 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001442 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearFormData");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001443 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 }
1445
1446 /**
Steve Block4e584df2012-04-24 23:12:47 +01001447 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 */
1449 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001450 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001451 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearHistory");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001452 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 }
1454
1455 /**
Steve Block4e584df2012-04-24 23:12:47 +01001456 * Clears the SSL preferences table stored in response to proceeding with
1457 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 */
1459 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001460 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001461 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearSslPreferences");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001462 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464
1465 /**
Steve Block4e584df2012-04-24 23:12:47 +01001466 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 * back/forward list for use in querying each item in the history stack.
1468 * This is a copy of the private WebBackForwardList so it contains only a
1469 * snapshot of the current state. Multiple calls to this method may return
1470 * different objects. The object returned from this method will not be
1471 * updated to reflect any new state.
1472 */
1473 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001474 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001475 return mProvider.copyBackForwardList();
1476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 }
1478
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001479 /**
Steve Block4e584df2012-04-24 23:12:47 +01001480 * Registers the listener to be notified as find-on-page operations
1481 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001482 *
Steve Block4e584df2012-04-24 23:12:47 +01001483 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001484 */
1485 public void setFindListener(FindListener listener) {
1486 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001487 setupFindListenerIfNeeded();
1488 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001489 }
1490
1491 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001492 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001493 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001494 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1495 * has not been called yet, or if {@link #clearMatches} has been called since the
1496 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 *
Steve Block4e584df2012-04-24 23:12:47 +01001498 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001499 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 */
1501 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001502 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001503 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findNext");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001504 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 }
1506
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001507 /**
Steve Block4e584df2012-04-24 23:12:47 +01001508 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001509 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001510 *
Steve Block4e584df2012-04-24 23:12:47 +01001511 * @param find the string to find
1512 * @return the number of occurances of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001513 * @deprecated {@link #findAllAsync} is preferred.
1514 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001516 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001518 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001519 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findAll");
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001520 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001521 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 }
1523
Cary Clark3403eb32010-03-03 10:05:16 -05001524 /**
Steve Block4e584df2012-04-24 23:12:47 +01001525 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001526 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001527 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001528 *
Steve Block4e584df2012-04-24 23:12:47 +01001529 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001530 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001531 */
1532 public void findAllAsync(String find) {
1533 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001534 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "findAllAsync");
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001535 mProvider.findAllAsync(find);
1536 }
1537
1538 /**
Steve Block4e584df2012-04-24 23:12:47 +01001539 * Starts an ActionMode for finding text in this WebView. Only works if this
1540 * WebView is attached to the view system.
1541 *
1542 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001543 * Otherwise, the last String searched for in this WebView will
1544 * be used to start.
Steve Block4e584df2012-04-24 23:12:47 +01001545 * @param showIme if true, show the IME, assuming the user will begin typing.
1546 * If false and text is non-null, perform a find all.
1547 * @return true if the find dialog is shown, false otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001548 * @deprecated This method does not work reliably on all Android versions;
1549 * implementing a custom find dialog using WebView.findAllAsync()
1550 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001551 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001552 @Deprecated
Leon Scroggins571354f2011-01-04 10:12:41 -05001553 public boolean showFindDialog(String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001554 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001555 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "showFindDialog");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001556 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001557 }
1558
1559 /**
Steve Block4e584df2012-04-24 23:12:47 +01001560 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 * location. Currently, only addresses in the United States are detected,
1562 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001563 * <ul>
1564 * <li>a house number</li>
1565 * <li>a street name</li>
1566 * <li>a street type (Road, Circle, etc), either spelled out or
1567 * abbreviated</li>
1568 * <li>a city name</li>
1569 * <li>a state or territory, either spelled out or two-letter abbr</li>
1570 * <li>an optional 5 digit or 9 digit zip code</li>
1571 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 * All names must be correctly capitalized, and the zip code, if present,
1573 * must be valid for the state. The street type must be a standard USPS
1574 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001575 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 *
Steve Block4e584df2012-04-24 23:12:47 +01001578 * @param addr the string to search for addresses
1579 * @return the address, or if no address is found, null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 */
1581 public static String findAddress(String addr) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001582 return getFactory().getStatics().findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 }
1584
Victoria Lease0b8413b2012-03-26 13:04:10 -07001585 /**
Steve Block4e584df2012-04-24 23:12:47 +01001586 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001587 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 */
1589 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001590 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001591 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearMatches");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001592 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 }
1594
1595 /**
Steve Block4e584df2012-04-24 23:12:47 +01001596 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 * message object will be dispatched with arg1 being set to 1 if images
1598 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001599 *
1600 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 */
1602 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001603 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001604 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 }
1606
1607 /**
Steve Block4e584df2012-04-24 23:12:47 +01001608 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001610 *
1611 * @param client an implementation of WebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 */
1613 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001614 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001615 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001616 }
1617
1618 /**
Steve Block4e584df2012-04-24 23:12:47 +01001619 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 * the rendering engine, and should be downloaded instead. This will replace
1621 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001622 *
1623 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 */
1625 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001626 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001627 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
1629
1630 /**
Steve Block4e584df2012-04-24 23:12:47 +01001631 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001632 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001634 *
1635 * @param client an implementation of WebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 */
1637 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001638 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001639 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001640 }
1641
1642 /**
Steve Block4e584df2012-04-24 23:12:47 +01001643 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001645 *
1646 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001647 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001649 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001651 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001652 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "setPictureListener=" + listener);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001653 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 }
1655
1656 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001657 * Injects the supplied Java object into this WebView. The object is
1658 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001659 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001660 * accessed from JavaScript. For applications targeted to API
1661 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001662 * and above, only public methods that are annotated with
1663 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001664 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001665 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001666 * important security note below for implications.
1667 * <p> Note that injected objects will not
Steve Block3aa800b2012-04-24 13:01:34 +01001668 * appear in JavaScript until the page is next (re)loaded. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001669 * <pre>
1670 * class JsObject {
1671 * {@literal @}JavascriptInterface
1672 * public String toString() { return "injectedObject"; }
1673 * }
1674 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001675 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1676 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001677 * <p>
1678 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001680 * <li> This method can be used to allow JavaScript to control the host
1681 * application. This is a powerful feature, but also presents a security
Selim Gurunb4c02e62012-09-12 13:36:21 -07001682 * risk for applications targeted to API level
Selim Gurune91d5be2012-09-11 16:11:22 -07001683 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, because
1684 * JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001685 * injected object's public fields. Use of this method in a WebView
1686 * containing untrusted content could allow an attacker to manipulate the
1687 * host application in unintended ways, executing Java code with the
1688 * permissions of the host application. Use extreme care when using this
1689 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001690 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001691 * thread of this WebView. Care is therefore required to maintain thread
Steve Block4cd73c52011-11-09 13:06:52 +00001692 * safety.</li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001693 * <li> The Java object's fields are not accessible.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001694 * </ul>
1695 *
1696 * @param object the Java object to inject into this WebView's JavaScript
Steve Block4cd73c52011-11-09 13:06:52 +00001697 * context. Null values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001698 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 */
Steve Block4cd73c52011-11-09 13:06:52 +00001700 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001701 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001702 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "addJavascriptInterface=" + name);
Jonathan Dixon3c909522012-02-28 18:45:06 +00001703 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 }
1705
1706 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001707 * Removes a previously injected Java object from this WebView. Note that
1708 * the removal will not be reflected in JavaScript until the page is next
1709 * (re)loaded. See {@link #addJavascriptInterface}.
1710 *
1711 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001712 */
Steve Block3aa800b2012-04-24 13:01:34 +01001713 public void removeJavascriptInterface(String name) {
Steve Block51b08912011-04-27 15:04:48 +01001714 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001715 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "removeJavascriptInterface=" + name);
Steve Block3aa800b2012-04-24 13:01:34 +01001716 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001717 }
1718
1719 /**
Steve Block4e584df2012-04-24 23:12:47 +01001720 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001722 *
1723 * @return a WebSettings object that can be used to control this WebView's
1724 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725 */
1726 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001727 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001728 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 }
1730
Jonathan Dixon3c909522012-02-28 18:45:06 +00001731 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07001732 * Enables debugging of web contents (HTML / CSS / JavaScript)
1733 * loaded into any WebViews of this application. This flag can be enabled
1734 * in order to facilitate debugging of web layouts and JavaScript
1735 * code running inside WebViews. Please refer to WebView documentation
1736 * for the debugging guide.
1737 *
1738 * The default is false.
1739 *
1740 * @param enabled whether to enable web contents debugging
1741 */
1742 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07001743 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
1744 }
1745
1746 /**
Steve Block4e584df2012-04-24 23:12:47 +01001747 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001748 *
Steve Block4e584df2012-04-24 23:12:47 +01001749 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001750 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001751 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001752 */
Andrei Popescu385df692009-08-13 11:59:57 +01001753 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08001755 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 }
1757
Jonathan Dixon3c909522012-02-28 18:45:06 +00001758 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001759 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001760 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001761 */
Andrei Popescu385df692009-08-13 11:59:57 +01001762 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01001763 public void refreshPlugins(boolean reloadOpenPages) {
1764 checkThread();
1765 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766
Cary Clark966641a2010-03-04 08:41:56 -05001767 /**
Steve Block4e584df2012-04-24 23:12:47 +01001768 * Puts this WebView into text selection mode. Do not rely on this
1769 * functionality; it will be deprecated in the future.
1770 *
Kristian Monsenfc771652011-05-10 16:44:05 +01001771 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001772 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05001773 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001774 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01001776 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07001777 }
1778
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001779 /**
1780 * @deprecated WebView no longer needs to implement
1781 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1782 */
George Mountfab67a12012-01-05 09:58:53 -08001783 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001784 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001785 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04001787
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001788 /**
1789 * @deprecated WebView no longer needs to implement
1790 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1791 */
George Mountfab67a12012-01-05 09:58:53 -08001792 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001793 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001794 @Deprecated
1795 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796
1797 /**
1798 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08001799 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 */
George Mountfab67a12012-01-05 09:58:53 -08001801 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001802 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 @Deprecated
1804 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1805 }
1806
Kristian Monsen5cc23512012-08-09 15:33:08 -04001807 /**
1808 * @deprecated Only the default case, true, will be supported in a future version.
1809 */
1810 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01001812 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001813 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 }
1815
Derek Sollenberger03e48912010-05-18 17:03:42 -04001816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01001818 checkThread();
Jonathan Dixon69f9f932013-08-28 15:54:29 -07001819 if (DebugFlags.TRACE_API) Log.d(LOGTAG, "flingScroll");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001820 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 }
1822
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001823 /**
Steve Block4e584df2012-04-24 23:12:47 +01001824 * Gets the zoom controls for this WebView, as a separate View. The caller
1825 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001826 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01001827 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
1828 * built-in zoom mechanisms for the WebView, as opposed to these separate
1829 * zoom controls. The built-in mechanisms are preferred and can be enabled
1830 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07001831 *
Steve Block4e584df2012-04-24 23:12:47 +01001832 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01001833 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 */
The Android Open Source Project10592532009-03-18 17:39:46 -07001835 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01001837 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001838 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07001839 }
1840
1841 /**
Steve Block4e584df2012-04-24 23:12:47 +01001842 * Gets whether this WebView can be zoomed in.
1843 *
1844 * @return true if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04001845 *
1846 * @deprecated This method is prone to inaccuracy due to race conditions
1847 * between the web rendering and UI threads; prefer
1848 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001849 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001850 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001851 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001852 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001853 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07001854 }
1855
1856 /**
Steve Block4e584df2012-04-24 23:12:47 +01001857 * Gets whether this WebView can be zoomed out.
1858 *
1859 * @return true if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04001860 *
1861 * @deprecated This method is prone to inaccuracy due to race conditions
1862 * between the web rendering and UI threads; prefer
1863 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07001864 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001865 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07001866 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001867 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001868 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07001869 }
1870
1871 /**
Steve Block4e584df2012-04-24 23:12:47 +01001872 * Performs zoom in in this WebView.
1873 *
1874 * @return true if zoom in succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 */
1876 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01001877 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001878 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 /**
Steve Block4e584df2012-04-24 23:12:47 +01001882 * Performs zoom out in this WebView.
1883 *
1884 * @return true if zoom out succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 */
1886 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01001887 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001888 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 }
1890
Kristian Monsenfc771652011-05-10 16:44:05 +01001891 /**
1892 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001893 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01001894 */
1895 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01001897 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001899
John Reck926cf562012-06-14 10:00:31 -07001900 /**
John Reckf2361152012-06-14 15:23:22 -07001901 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07001902 * @hide
1903 */
1904 @Override
1905 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
1906 mProvider.dumpViewHierarchyWithProperties(out, level);
1907 }
1908
1909 /**
1910 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
1911 * @hide
1912 */
1913 @Override
1914 public View findHierarchyView(String className, int hashCode) {
1915 return mProvider.findHierarchyView(className, hashCode);
1916 }
1917
Jonathan Dixon3c909522012-02-28 18:45:06 +00001918 //-------------------------------------------------------------------------
1919 // Interface for WebView providers
1920 //-------------------------------------------------------------------------
1921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 /**
Steve Block4e584df2012-04-24 23:12:47 +01001923 * Gets the WebViewProvider. Used by providers to obtain the underlying
1924 * implementation, e.g. when the appliction responds to
1925 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04001926 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00001927 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04001928 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001929 public WebViewProvider getWebViewProvider() {
1930 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04001931 }
1932
1933 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001934 * Callback interface, allows the provider implementation to access non-public methods
1935 * and fields, and make super-class calls in this WebView instance.
1936 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08001937 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00001938 public class PrivateAccess {
1939 // ---- Access to super-class methods ----
1940 public int super_getScrollBarStyle() {
1941 return WebView.super.getScrollBarStyle();
1942 }
1943
1944 public void super_scrollTo(int scrollX, int scrollY) {
1945 WebView.super.scrollTo(scrollX, scrollY);
1946 }
1947
1948 public void super_computeScroll() {
1949 WebView.super.computeScroll();
1950 }
1951
alanveebebc92012-06-15 18:59:11 -07001952 public boolean super_onHoverEvent(MotionEvent event) {
1953 return WebView.super.onHoverEvent(event);
1954 }
1955
alanv448902d2012-05-16 20:27:47 -07001956 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
1957 return WebView.super.performAccessibilityAction(action, arguments);
1958 }
1959
Jonathan Dixon3c909522012-02-28 18:45:06 +00001960 public boolean super_performLongClick() {
1961 return WebView.super.performLongClick();
1962 }
1963
1964 public boolean super_setFrame(int left, int top, int right, int bottom) {
1965 return WebView.super.setFrame(left, top, right, bottom);
1966 }
1967
1968 public boolean super_dispatchKeyEvent(KeyEvent event) {
1969 return WebView.super.dispatchKeyEvent(event);
1970 }
1971
1972 public boolean super_onGenericMotionEvent(MotionEvent event) {
1973 return WebView.super.onGenericMotionEvent(event);
1974 }
1975
1976 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
1977 return WebView.super.requestFocus(direction, previouslyFocusedRect);
1978 }
1979
1980 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
1981 WebView.super.setLayoutParams(params);
1982 }
1983
1984 // ---- Access to non-public methods ----
1985 public void overScrollBy(int deltaX, int deltaY,
1986 int scrollX, int scrollY,
1987 int scrollRangeX, int scrollRangeY,
1988 int maxOverScrollX, int maxOverScrollY,
1989 boolean isTouchEvent) {
1990 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
1991 maxOverScrollX, maxOverScrollY, isTouchEvent);
1992 }
1993
1994 public void awakenScrollBars(int duration) {
1995 WebView.this.awakenScrollBars(duration);
1996 }
1997
1998 public void awakenScrollBars(int duration, boolean invalidate) {
1999 WebView.this.awakenScrollBars(duration, invalidate);
2000 }
2001
2002 public float getVerticalScrollFactor() {
2003 return WebView.this.getVerticalScrollFactor();
2004 }
2005
2006 public float getHorizontalScrollFactor() {
2007 return WebView.this.getHorizontalScrollFactor();
2008 }
2009
2010 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
2011 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
2012 }
2013
2014 public void onScrollChanged(int l, int t, int oldl, int oldt) {
2015 WebView.this.onScrollChanged(l, t, oldl, oldt);
2016 }
2017
2018 public int getHorizontalScrollbarHeight() {
2019 return WebView.this.getHorizontalScrollbarHeight();
2020 }
2021
Martin Kosiba9a68f822013-08-08 14:02:41 +01002022 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2023 int l, int t, int r, int b) {
2024 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2025 }
2026
Jonathan Dixon3c909522012-02-28 18:45:06 +00002027 // ---- Access to (non-public) fields ----
2028 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
2029 public void setScrollXRaw(int scrollX) {
2030 WebView.this.mScrollX = scrollX;
2031 }
2032
2033 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
2034 public void setScrollYRaw(int scrollY) {
2035 WebView.this.mScrollY = scrollY;
2036 }
2037
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002038 }
2039
Jonathan Dixon3c909522012-02-28 18:45:06 +00002040 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002041 // Package-private internal stuff
2042 //-------------------------------------------------------------------------
2043
2044 // Only used by android.webkit.FindActionModeCallback.
2045 void setFindDialogFindListener(FindListener listener) {
2046 checkThread();
2047 setupFindListenerIfNeeded();
2048 mFindListener.mFindDialogFindListener = listener;
2049 }
2050
2051 // Only used by android.webkit.FindActionModeCallback.
2052 void notifyFindDialogDismissed() {
2053 checkThread();
2054 mProvider.notifyFindDialogDismissed();
2055 }
2056
2057 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002058 // Private internal stuff
2059 //-------------------------------------------------------------------------
2060
Jonathan Dixon3c909522012-02-28 18:45:06 +00002061 private WebViewProvider mProvider;
2062
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002063 /**
2064 * In addition to the FindListener that the user may set via the WebView.setFindListener
2065 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
2066 * via this class so that that the two FindListeners can potentially exist at once.
2067 */
2068 private class FindListenerDistributor implements FindListener {
2069 private FindListener mFindDialogFindListener;
2070 private FindListener mUserFindListener;
2071
2072 @Override
2073 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2074 boolean isDoneCounting) {
2075 if (mFindDialogFindListener != null) {
2076 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2077 isDoneCounting);
2078 }
2079
2080 if (mUserFindListener != null) {
2081 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2082 isDoneCounting);
2083 }
2084 }
2085 }
2086 private FindListenerDistributor mFindListener;
2087
2088 private void setupFindListenerIfNeeded() {
2089 if (mFindListener == null) {
2090 mFindListener = new FindListenerDistributor();
2091 mProvider.setFindListener(mFindListener);
2092 }
2093 }
2094
Jonathan Dixon3c909522012-02-28 18:45:06 +00002095 private void ensureProviderCreated() {
2096 checkThread();
2097 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002098 // As this can get called during the base class constructor chain, pass the minimum
2099 // number of dependencies here; the rest are deferred to init().
2100 mProvider = getFactory().createWebView(this, new PrivateAccess());
2101 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002102 }
2103
Jonathan Dixon951fcab2012-08-20 16:37:15 -07002104 private static synchronized WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002105 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002106 }
2107
Jonathan Dixon517771b2013-10-08 13:32:11 -07002108 private final Looper mWebViewThread = Looper.myLooper();
2109
2110 private void checkThread() {
2111 // Ignore mWebViewThread == null because this can be called during in the super class
2112 // constructor, before this class's own constructor has even started.
2113 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002114 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002115 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002116 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002117 "All WebView methods must be called on the same thread. " +
2118 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2119 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002120 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2121 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002122
2123 if (sEnforceThreadChecking) {
2124 throw new RuntimeException(throwable);
2125 }
Steve Block51b08912011-04-27 15:04:48 +01002126 }
2127 }
2128
Jonathan Dixon3c909522012-02-28 18:45:06 +00002129 //-------------------------------------------------------------------------
2130 // Override View methods
2131 //-------------------------------------------------------------------------
2132
2133 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2134 // there's a corresponding override (or better, caller) for each of them in here.
2135
2136 @Override
2137 protected void onAttachedToWindow() {
2138 super.onAttachedToWindow();
2139 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002140 }
2141
Jonathan Dixon3c909522012-02-28 18:45:06 +00002142 @Override
2143 protected void onDetachedFromWindow() {
2144 mProvider.getViewDelegate().onDetachedFromWindow();
2145 super.onDetachedFromWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002146 }
2147
Jonathan Dixon3c909522012-02-28 18:45:06 +00002148 @Override
2149 public void setLayoutParams(ViewGroup.LayoutParams params) {
2150 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002151 }
2152
Jonathan Dixon3c909522012-02-28 18:45:06 +00002153 @Override
2154 public void setOverScrollMode(int mode) {
2155 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002156 // This method may be called in the constructor chain, before the WebView provider is
2157 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002158 ensureProviderCreated();
2159 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002160 }
2161
Jonathan Dixon3c909522012-02-28 18:45:06 +00002162 @Override
2163 public void setScrollBarStyle(int style) {
2164 mProvider.getViewDelegate().setScrollBarStyle(style);
2165 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002166 }
2167
Jonathan Dixon3c909522012-02-28 18:45:06 +00002168 @Override
2169 protected int computeHorizontalScrollRange() {
2170 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002171 }
2172
Jonathan Dixon3c909522012-02-28 18:45:06 +00002173 @Override
2174 protected int computeHorizontalScrollOffset() {
2175 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2176 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002177
Jonathan Dixon3c909522012-02-28 18:45:06 +00002178 @Override
2179 protected int computeVerticalScrollRange() {
2180 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2181 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002182
Jonathan Dixon3c909522012-02-28 18:45:06 +00002183 @Override
2184 protected int computeVerticalScrollOffset() {
2185 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2186 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002187
Jonathan Dixon3c909522012-02-28 18:45:06 +00002188 @Override
2189 protected int computeVerticalScrollExtent() {
2190 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2191 }
2192
2193 @Override
2194 public void computeScroll() {
2195 mProvider.getScrollDelegate().computeScroll();
2196 }
2197
2198 @Override
2199 public boolean onHoverEvent(MotionEvent event) {
2200 return mProvider.getViewDelegate().onHoverEvent(event);
2201 }
2202
2203 @Override
2204 public boolean onTouchEvent(MotionEvent event) {
2205 return mProvider.getViewDelegate().onTouchEvent(event);
2206 }
2207
2208 @Override
2209 public boolean onGenericMotionEvent(MotionEvent event) {
2210 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2211 }
2212
2213 @Override
2214 public boolean onTrackballEvent(MotionEvent event) {
2215 return mProvider.getViewDelegate().onTrackballEvent(event);
2216 }
2217
2218 @Override
2219 public boolean onKeyDown(int keyCode, KeyEvent event) {
2220 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2221 }
2222
2223 @Override
2224 public boolean onKeyUp(int keyCode, KeyEvent event) {
2225 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2226 }
2227
2228 @Override
2229 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2230 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2231 }
2232
2233 /*
2234 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2235 to be delegating them too.
2236
2237 @Override
2238 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2239 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2240 }
2241 @Override
2242 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2243 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2244 }
2245 @Override
2246 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2247 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2248 }
2249 */
2250
Ben Murdoche3f90712013-06-05 14:19:48 +01002251 @Override
2252 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2253 AccessibilityNodeProvider provider =
2254 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2255 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2256 }
2257
Jonathan Dixon3c909522012-02-28 18:45:06 +00002258 @Deprecated
2259 @Override
2260 public boolean shouldDelayChildPressedState() {
2261 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2262 }
2263
2264 @Override
2265 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
2266 super.onInitializeAccessibilityNodeInfo(info);
alanvea077212012-03-30 14:59:42 -07002267 info.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002268 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
2269 }
2270
2271 @Override
2272 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2273 super.onInitializeAccessibilityEvent(event);
alanvea077212012-03-30 14:59:42 -07002274 event.setClassName(WebView.class.getName());
Jonathan Dixon3c909522012-02-28 18:45:06 +00002275 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
2276 }
2277
alanv448902d2012-05-16 20:27:47 -07002278 @Override
2279 public boolean performAccessibilityAction(int action, Bundle arguments) {
2280 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
2281 }
2282
Jonathan Dixon3c909522012-02-28 18:45:06 +00002283 /** @hide */
2284 @Override
2285 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2286 int l, int t, int r, int b) {
2287 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2288 }
2289
2290 @Override
2291 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2292 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2293 }
2294
2295 @Override
2296 protected void onWindowVisibilityChanged(int visibility) {
2297 super.onWindowVisibilityChanged(visibility);
2298 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2299 }
2300
2301 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002302 protected void onDraw(Canvas canvas) {
2303 mProvider.getViewDelegate().onDraw(canvas);
2304 }
2305
2306 @Override
2307 public boolean performLongClick() {
2308 return mProvider.getViewDelegate().performLongClick();
2309 }
2310
2311 @Override
2312 protected void onConfigurationChanged(Configuration newConfig) {
2313 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2314 }
2315
2316 @Override
2317 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2318 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2319 }
2320
2321 @Override
2322 protected void onVisibilityChanged(View changedView, int visibility) {
2323 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002324 // This method may be called in the constructor chain, before the WebView provider is
2325 // created.
2326 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002327 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2328 }
2329
2330 @Override
2331 public void onWindowFocusChanged(boolean hasWindowFocus) {
2332 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2333 super.onWindowFocusChanged(hasWindowFocus);
2334 }
2335
2336 @Override
2337 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2338 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2339 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2340 }
2341
2342 /** @hide */
2343 @Override
2344 protected boolean setFrame(int left, int top, int right, int bottom) {
2345 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2346 }
2347
2348 @Override
2349 protected void onSizeChanged(int w, int h, int ow, int oh) {
2350 super.onSizeChanged(w, h, ow, oh);
2351 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2352 }
2353
2354 @Override
2355 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2356 super.onScrollChanged(l, t, oldl, oldt);
2357 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2358 }
2359
2360 @Override
2361 public boolean dispatchKeyEvent(KeyEvent event) {
2362 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2363 }
2364
2365 @Override
2366 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2367 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2368 }
2369
Jonathan Dixon3c909522012-02-28 18:45:06 +00002370 @Override
2371 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2372 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2373 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2374 }
2375
2376 @Override
2377 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2378 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2379 }
2380
2381 @Override
2382 public void setBackgroundColor(int color) {
2383 mProvider.getViewDelegate().setBackgroundColor(color);
2384 }
John Recka5408e62012-03-16 14:18:44 -07002385
2386 @Override
2387 public void setLayerType(int layerType, Paint paint) {
2388 super.setLayerType(layerType, paint);
2389 mProvider.getViewDelegate().setLayerType(layerType, paint);
2390 }
Ben Murdoche623e242012-09-07 20:47:07 +01002391
2392 @Override
2393 protected void dispatchDraw(Canvas canvas) {
2394 mProvider.getViewDelegate().preDispatchDraw(canvas);
2395 super.dispatchDraw(canvas);
2396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397}