blob: 333c44c5910d76f87ba6f6337bde2c4e329804cb [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
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000019import android.annotation.IntDef;
Siva Velusamy94a6d152015-05-05 15:07:00 -070020import android.annotation.NonNull;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070021import android.annotation.Nullable;
Ignacio Solla451e3382014-11-10 10:35:54 +000022import android.annotation.SystemApi;
Raphael30df2372010-03-06 10:09:54 -080023import android.annotation.Widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.Context;
Hui Shuf119c522015-10-08 10:07:13 -070025import android.content.Intent;
Gustav Senntonbf683e02016-09-15 14:42:50 +010026import android.content.pm.PackageInfo;
Cary Clarkc5cd5e92010-11-22 15:20:02 -050027import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.graphics.Bitmap;
29import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070030import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.graphics.Picture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.graphics.Rect;
Mike Reede8853fc2009-09-04 14:01:48 -040033import android.graphics.drawable.Drawable;
Selim Gurun4c8093a2015-03-10 17:40:06 -070034import android.net.Uri;
Nate Fischer0e72c182017-05-30 11:25:17 -070035import android.net.http.SslCertificate;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -070036import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.Bundle;
Selim Gurune319dad2016-03-17 01:40:40 +000038import android.os.Handler;
Steve Block08d584c2011-05-17 19:05:03 +010039import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.os.Message;
Gustav Senntonbf683e02016-09-15 14:42:50 +010041import android.os.RemoteException;
Nate Fischer0e72c182017-05-30 11:25:17 -070042import android.os.StrictMode;
Selim Gurunda7d6422013-09-06 14:39:05 -070043import android.print.PrintDocumentAdapter;
Selim Gurun87a03512014-05-02 14:52:49 -070044import android.security.KeyChain;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.util.Log;
Tao Baia5717332017-03-30 14:58:53 -070047import android.util.SparseArray;
Hui Shuecdce962016-02-04 15:00:19 -080048import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070052import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070054import android.view.ViewHierarchyEncoder;
Nate Fischer0e72c182017-05-30 11:25:17 -070055import android.view.ViewStructure;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070057import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070058import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010059import android.view.accessibility.AccessibilityNodeProvider;
Tao Baia5717332017-03-30 14:58:53 -070060import android.view.autofill.AutofillValue;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050061import android.view.inputmethod.EditorInfo;
62import android.view.inputmethod.InputConnection;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070063import android.view.textclassifier.TextClassifier;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010065
John Reck926cf562012-06-14 10:00:31 -070066import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.File;
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000068import java.lang.annotation.Retention;
69import java.lang.annotation.RetentionPolicy;
Nate Fischer520a8ba2017-07-12 17:37:07 -070070import java.util.List;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010071import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
73/**
Cary Clarkd6982c92009-05-29 11:02:22 -040074 * <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 -080075 * can roll your own web browser or simply display some online content within your Activity.
76 * It uses the WebKit rendering engine to display
77 * web pages and includes methods to navigate forward and backward
78 * through a history, zoom in and out, perform text searches and more.</p>
79 * <p>Note that, in order for your Activity to access the Internet and load web pages
Scott Main8b3cea02010-05-14 14:12:43 -070080 * in a WebView, you must add the {@code INTERNET} permissions to your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 * Android Manifest file:</p>
82 * <pre>&lt;uses-permission android:name="android.permission.INTERNET" /></pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010083 *
Scott Main8b3cea02010-05-14 14:12:43 -070084 * <p>This must be a child of the <a
Ben Dodson4e8620f2010-08-25 10:55:47 -070085 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
Scott Main8b3cea02010-05-14 14:12:43 -070086 * element.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010087 *
Scott Main4c359b72012-07-24 15:51:27 -070088 * <p>For more information, read
89 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.</p>
Scott Main41ec6532010-08-19 16:57:07 -070090 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010091 * <h3>Basic usage</h3>
92 *
93 * <p>By default, a WebView provides no browser-like widgets, does not
Scott Main8b3cea02010-05-14 14:12:43 -070094 * enable JavaScript and web page errors are ignored. If your goal is only
Mike Hearnadcd2ed2009-01-21 16:44:36 +010095 * to display some HTML as a part of your UI, this is probably fine;
96 * the user won't need to interact with the web page beyond reading
97 * it, and the web page won't need to interact with the user. If you
Scott Main8b3cea02010-05-14 14:12:43 -070098 * actually want a full-blown web browser, then you probably want to
99 * invoke the Browser application with a URL Intent rather than show it
100 * with a WebView. For example:
101 * <pre>
Andrew Solovay51142572017-05-05 16:55:43 -0700102 * Uri uri = Uri.parse("https://www.example.com");
Scott Main8b3cea02010-05-14 14:12:43 -0700103 * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
104 * startActivity(intent);
105 * </pre>
106 * <p>See {@link android.content.Intent} for more information.</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100107 *
Neil Fuller71fbb812015-11-30 09:51:33 +0000108 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout,
Scott Main8b3cea02010-05-14 14:12:43 -0700109 * or set the entire Activity window as a WebView during {@link
110 * android.app.Activity#onCreate(Bundle) onCreate()}:</p>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100111 * <pre class="prettyprint">
112 * WebView webview = new WebView(this);
113 * setContentView(webview);
Scott Main8b3cea02010-05-14 14:12:43 -0700114 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100115 *
Scott Main8b3cea02010-05-14 14:12:43 -0700116 * <p>Then load the desired web page:</p>
Scott Maine3b9f8b2010-05-18 08:41:36 -0700117 * <pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100118 * // Simplest usage: note that an exception will NOT be thrown
119 * // if there is an error loading this page (see below).
Andrew Solovay51142572017-05-05 16:55:43 -0700120 * webview.loadUrl("https://example.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100121 *
Scott Main8b3cea02010-05-14 14:12:43 -0700122 * // OR, you can also load from an HTML string:
Scott Maine3b9f8b2010-05-18 08:41:36 -0700123 * 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 +0100124 * webview.loadData(summary, "text/html", null);
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100125 * // ... although note that there are restrictions on what this HTML can do.
Scott Main8b3cea02010-05-14 14:12:43 -0700126 * // See the JavaDocs for {@link #loadData(String,String,String) loadData()} and {@link
127 * #loadDataWithBaseURL(String,String,String,String,String) loadDataWithBaseURL()} for more info.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100128 * </pre>
129 *
130 * <p>A WebView has several customization points where you can add your
131 * own behavior. These are:</p>
132 *
133 * <ul>
134 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass.
135 * This class is called when something that might impact a
136 * browser UI happens, for instance, progress updates and
Scott Main8b3cea02010-05-14 14:12:43 -0700137 * JavaScript alerts are sent here (see <a
138 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>).
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100139 * </li>
140 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass.
141 * It will be called when things happen that impact the
142 * rendering of the content, eg, errors or form submissions. You
Scott Main8b3cea02010-05-14 14:12:43 -0700143 * can also intercept URL loading here (via {@link
144 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String)
145 * shouldOverrideUrlLoading()}).</li>
146 * <li>Modifying the {@link android.webkit.WebSettings}, such as
147 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
148 * setJavaScriptEnabled()}. </li>
Steve Block4cd73c52011-11-09 13:06:52 +0000149 * <li>Injecting Java objects into the WebView using the
150 * {@link android.webkit.WebView#addJavascriptInterface} method. This
151 * method allows you to inject Java objects into a page's JavaScript
152 * context, so that they can be accessed by JavaScript in the page.</li>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100153 * </ul>
154 *
155 * <p>Here's a more complicated example, showing error handling,
156 * settings, and progress notification:</p>
157 *
158 * <pre class="prettyprint">
159 * // Let's display the progress in the activity title bar, like the
160 * // browser app does.
161 * getWindow().requestFeature(Window.FEATURE_PROGRESS);
162 *
163 * webview.getSettings().setJavaScriptEnabled(true);
164 *
165 * final Activity activity = this;
166 * webview.setWebChromeClient(new WebChromeClient() {
167 * public void onProgressChanged(WebView view, int progress) {
168 * // Activities and WebViews measure progress with different scales.
169 * // The progress meter will automatically disappear when we reach 100%
170 * activity.setProgress(progress * 1000);
171 * }
172 * });
173 * webview.setWebViewClient(new WebViewClient() {
174 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
175 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
176 * }
177 * });
178 *
Andrew Solovay51142572017-05-05 16:55:43 -0700179 * webview.loadUrl("https://developer.android.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100180 * </pre>
181 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700182 * <h3>Zoom</h3>
183 *
184 * <p>To enable the built-in zoom, set
185 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
186 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).</p>
187 * <p>NOTE: Using zoom if either the height or width is set to
188 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} may lead to undefined behavior
189 * and should be avoided.</p>
190 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100191 * <h3>Cookie and window management</h3>
192 *
193 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700194 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100195 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100196 * </p>
197 *
198 * <p>By default, requests by the HTML to open new windows are
199 * ignored. This is true whether they be opened by JavaScript or by
200 * the target attribute on a link. You can customize your
Nate Fischerffb81c42016-09-26 12:35:47 -0700201 * {@link WebChromeClient} to provide your own behavior for opening multiple windows,
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100202 * and render them in whatever manner you want.</p>
203 *
Scott Main8b3cea02010-05-14 14:12:43 -0700204 * <p>The standard behavior for an Activity is to be destroyed and
205 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100206 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700207 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100208 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700209 * re-orient itself as appropriate. Read <a
210 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
211 * more information about how to handle configuration changes during runtime.</p>
212 *
213 *
214 * <h3>Building web pages to support different screen densities</h3>
215 *
216 * <p>The screen density of a device is based on the screen resolution. A screen with low density
217 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700218 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700219 * screen is important because, other things being equal, a UI element (such as a button) whose
220 * height and width are defined in terms of screen pixels will appear larger on the lower density
221 * screen and smaller on the higher density screen.
222 * For simplicity, Android collapses all actual screen densities into three generalized densities:
223 * high, medium, and low.</p>
224 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
225 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
226 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
227 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100228 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
229 * and meta tag features to help you (as a web developer) target screens with different screen
230 * densities.</p>
Scott Main8b3cea02010-05-14 14:12:43 -0700231 * <p>Here's a summary of the features you can use to handle different screen densities:</p>
232 * <ul>
233 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
234 * default scaling factor used for the current device. For example, if the value of {@code
235 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
236 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
237 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
238 * 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 -0800239 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700240 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
241 * densities for which this style sheet is to be used. The corresponding value should be either
242 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
243 * density, or high density screens, respectively. For example:
244 * <pre>
245 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
246 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
247 * which is the high density pixel ratio.</p>
248 * </li>
Martin Kosiba0d147d92013-09-19 19:05:00 -0700249 * </ul>
Scott Main8b3cea02010-05-14 14:12:43 -0700250 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800251 * <h3>HTML5 Video support</h3>
252 *
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000253 * <p>In order to support inline HTML5 video in your application you need to have hardware
254 * acceleration turned on.
255 * </p>
256 *
257 * <h3>Full screen support</h3>
258 *
259 * <p>In order to support full screen &mdash; for video or other HTML content &mdash; you need to set a
260 * {@link android.webkit.WebChromeClient} and implement both
261 * {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
262 * and {@link WebChromeClient#onHideCustomView()}. If the implementation of either of these two methods is
263 * missing then the web contents will not be allowed to enter full screen. Optionally you can implement
264 * {@link WebChromeClient#getVideoLoadingProgressView()} to customize the View displayed whilst a video
265 * is loading.
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800266 * </p>
Marcin Kosiba84644f12014-09-08 18:37:36 +0100267 *
Tim Volodineb0e97982016-04-27 14:14:09 +0100268 * <h3>HTML5 Geolocation API support</h3>
269 *
270 * <p>For applications targeting Android N and later releases
271 * (API level > {@link android.os.Build.VERSION_CODES#M}) the geolocation api is only supported on
272 * secure origins such as https. For such applications requests to geolocation api on non-secure
273 * origins are automatically denied without invoking the corresponding
274 * {@link WebChromeClient#onGeolocationPermissionsShowPrompt(String, GeolocationPermissions.Callback)}
275 * method.
276 * </p>
277 *
Marcin Kosiba84644f12014-09-08 18:37:36 +0100278 * <h3>Layout size</h3>
279 * <p>
280 * It is recommended to set the WebView layout height to a fixed value or to
281 * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT} instead of using
282 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}.
283 * When using {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
284 * for the height none of the WebView's parents should use a
285 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} layout height since that could result in
286 * incorrect sizing of the views.
287 * </p>
288 *
289 * <p>Setting the WebView's height to {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}
290 * enables the following behaviors:
291 * <ul>
292 * <li>The HTML body layout height is set to a fixed value. This means that elements with a height
293 * relative to the HTML body may not be sized correctly. </li>
Nate Fischerffb81c42016-09-26 12:35:47 -0700294 * <li>For applications targeting {@link android.os.Build.VERSION_CODES#KITKAT} and earlier SDKs the
Marcin Kosiba84644f12014-09-08 18:37:36 +0100295 * HTML viewport meta tag will be ignored in order to preserve backwards compatibility. </li>
296 * </ul>
297 * </p>
298 *
299 * <p>
300 * Using a layout width of {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} is not
301 * supported. If such a width is used the WebView will attempt to use the width of the parent
302 * instead.
303 * </p>
304 *
Paul Millera4692182016-01-07 11:32:15 -0800305 * <h3>Metrics</h3>
306 *
307 * <p>
308 * WebView may upload anonymous diagnostic data to Google when the user has consented. This data
309 * helps Google improve WebView. Data is collected on a per-app basis for each app which has
310 * instantiated a WebView. An individual app can opt out of this feature by putting the following
311 * tag in its manifest:
Paul Millera4692182016-01-07 11:32:15 -0800312 * <pre>
Paul Miller9aca9ae2016-02-23 13:39:19 -0800313 * &lt;meta-data android:name="android.webkit.WebView.MetricsOptOut"
314 * android:value="true" /&gt;
Paul Millera4692182016-01-07 11:32:15 -0800315 * </pre>
Paul Miller9aca9ae2016-02-23 13:39:19 -0800316 * </p>
Paul Millera4692182016-01-07 11:32:15 -0800317 * <p>
318 * Data will only be uploaded for a given app if the user has consented AND the app has not opted
319 * out.
320 * </p>
321 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 */
Steve Block406aeb22012-04-23 18:17:19 +0100323// Implementation notes.
324// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
325// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
326// Methods are delegated to the provider implementation: all public API methods introduced in this
327// file are fully delegated, whereas public and protected methods from the View base classes are
328// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800329@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400330public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700332 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
Hui Shu22671772014-10-01 21:41:07 +0000334 /**
335 * Broadcast Action: Indicates the data reduction proxy setting changed.
336 * Sent by the settings app when user changes the data reduction proxy value. This intent will
337 * always stay as a hidden API.
338 * @hide
339 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000340 @SystemApi
Hui Shu22671772014-10-01 21:41:07 +0000341 public static final String DATA_REDUCTION_PROXY_SETTING_CHANGED =
342 "android.webkit.DATA_REDUCTION_PROXY_SETTING_CHANGED";
343
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700344 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700345
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700346 // Throwing an exception for incorrect thread usage if the
347 // build target is JB MR2 or newer. Defaults to false, and is
348 // set in the WebView constructor.
Jonathan Dixon0d6a1452013-08-21 13:09:36 -0700349 private static volatile boolean sEnforceThreadChecking = false;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /**
352 * Transportation object for returning WebView across thread boundaries.
353 */
354 public class WebViewTransport {
355 private WebView mWebview;
356
357 /**
Steve Block4e584df2012-04-24 23:12:47 +0100358 * Sets the WebView to the transportation object.
359 *
360 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 */
362 public synchronized void setWebView(WebView webview) {
363 mWebview = webview;
364 }
365
366 /**
Steve Block4e584df2012-04-24 23:12:47 +0100367 * Gets the WebView object.
368 *
369 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 */
371 public synchronized WebView getWebView() {
372 return mWebview;
373 }
374 }
375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 /**
Steve Block4e584df2012-04-24 23:12:47 +0100377 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 */
379 public static final String SCHEME_TEL = "tel:";
380 /**
Steve Block4e584df2012-04-24 23:12:47 +0100381 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 */
383 public static final String SCHEME_MAILTO = "mailto:";
384 /**
Steve Block4e584df2012-04-24 23:12:47 +0100385 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 */
387 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 /**
Victoria Leased405a432012-03-22 15:53:48 -0700390 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700391 */
392 public interface FindListener {
393 /**
Steve Block4e584df2012-04-24 23:12:47 +0100394 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700395 *
Steve Block4e584df2012-04-24 23:12:47 +0100396 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700397 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100398 * @param isDoneCounting whether the find operation has actually completed. The listener
399 * may be notified multiple times while the
400 * operation is underway, and the numberOfMatches
401 * value should not be considered final unless
402 * isDoneCounting is true.
Victoria Leased405a432012-03-22 15:53:48 -0700403 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700404 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700405 boolean isDoneCounting);
406 }
407
408 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +0100409 * Callback interface supplied to {@link #postVisualStateCallback} for receiving
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000410 * notifications about the visual state.
411 */
412 public static abstract class VisualStateCallback {
413 /**
414 * Invoked when the visual state is ready to be drawn in the next {@link #onDraw}.
415 *
Tobias Sargeantb3656042015-05-13 11:23:57 +0100416 * @param requestId The identifier passed to {@link #postVisualStateCallback} when this
417 * callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000418 */
419 public abstract void onComplete(long requestId);
420 }
421
422 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100424 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100425 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100427 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 public interface PictureListener {
429 /**
Steve Block72498ed2012-07-17 15:57:25 +0100430 * Used to provide notification that the WebView's picture has changed.
431 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100432 *
433 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000434 * @param picture the new picture. Applications targeting
435 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
436 * will always receive a null Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100437 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100439 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 public void onNewPicture(WebView view, Picture picture);
441 }
442
Jonathan Dixon19644b62011-12-21 14:21:36 +0000443 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 /**
Steve Block4e584df2012-04-24 23:12:47 +0100445 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 */
447 public static final int UNKNOWN_TYPE = 0;
448 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100449 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 */
Steve Block1854ddb2011-04-19 12:18:19 +0100451 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 public static final int ANCHOR_TYPE = 1;
453 /**
Steve Block4e584df2012-04-24 23:12:47 +0100454 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 */
456 public static final int PHONE_TYPE = 2;
457 /**
Steve Block4e584df2012-04-24 23:12:47 +0100458 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 */
460 public static final int GEO_TYPE = 3;
461 /**
Steve Block4e584df2012-04-24 23:12:47 +0100462 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 */
464 public static final int EMAIL_TYPE = 4;
465 /**
Steve Block4e584df2012-04-24 23:12:47 +0100466 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 */
468 public static final int IMAGE_TYPE = 5;
469 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100470 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 */
Steve Block1854ddb2011-04-19 12:18:19 +0100472 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 public static final int IMAGE_ANCHOR_TYPE = 6;
474 /**
Steve Block4e584df2012-04-24 23:12:47 +0100475 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 */
477 public static final int SRC_ANCHOR_TYPE = 7;
478 /**
Steve Block4e584df2012-04-24 23:12:47 +0100479 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 */
481 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
482 /**
Steve Block4e584df2012-04-24 23:12:47 +0100483 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 */
485 public static final int EDIT_TEXT_TYPE = 9;
486
487 private int mType;
488 private String mExtra;
489
Jonathan Dixon3c909522012-02-28 18:45:06 +0000490 /**
491 * @hide Only for use by WebViewProvider implementations
492 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000493 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000494 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 mType = UNKNOWN_TYPE;
496 }
497
Jonathan Dixon3c909522012-02-28 18:45:06 +0000498 /**
499 * @hide Only for use by WebViewProvider implementations
500 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000501 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000502 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 mType = type;
504 }
505
Jonathan Dixon3c909522012-02-28 18:45:06 +0000506 /**
507 * @hide Only for use by WebViewProvider implementations
508 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000509 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000510 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 mExtra = extra;
512 }
513
Jonathan Dixone230e542011-12-21 10:57:00 +0000514 /**
Steve Block4e584df2012-04-24 23:12:47 +0100515 * Gets the type of the hit test result. See the XXX_TYPE constants
516 * defined in this class.
517 *
518 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000519 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 public int getType() {
521 return mType;
522 }
523
Jonathan Dixone230e542011-12-21 10:57:00 +0000524 /**
Steve Block4e584df2012-04-24 23:12:47 +0100525 * Gets additional type-dependant information about the result. See
526 * {@link WebView#getHitTestResult()} for details. May either be null
527 * or contain extra information about this result.
528 *
529 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000530 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 public String getExtra() {
532 return mExtra;
533 }
534 }
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 /**
Steve Block4e584df2012-04-24 23:12:47 +0100537 * Constructs a new WebView with a Context object.
538 *
539 * @param context a Context object used to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 */
541 public WebView(Context context) {
542 this(context, null);
543 }
544
545 /**
Steve Block4e584df2012-04-24 23:12:47 +0100546 * Constructs a new WebView with layout parameters.
547 *
548 * @param context a Context object used to access application assets
549 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 */
551 public WebView(Context context, AttributeSet attrs) {
552 this(context, attrs, com.android.internal.R.attr.webViewStyle);
553 }
554
555 /**
Steve Block4e584df2012-04-24 23:12:47 +0100556 * Constructs a new WebView with layout parameters and a default style.
557 *
558 * @param context a Context object used to access application assets
559 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700560 * @param defStyleAttr an attribute in the current theme that contains a
561 * reference to a style resource that supplies default values for
562 * the view. Can be 0 to not look for defaults.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 */
Alan Viverette617feb92013-09-09 18:09:13 -0700564 public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
565 this(context, attrs, defStyleAttr, 0);
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700566 }
567
568 /**
Steve Block4e584df2012-04-24 23:12:47 +0100569 * Constructs a new WebView with layout parameters and a default style.
570 *
571 * @param context a Context object used to access application assets
572 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700573 * @param defStyleAttr an attribute in the current theme that contains a
574 * reference to a style resource that supplies default values for
575 * the view. Can be 0 to not look for defaults.
576 * @param defStyleRes a resource identifier of a style resource that
577 * supplies default values for the view, used only if
578 * defStyleAttr is 0 or can not be found in the theme. Can be 0
579 * to not look for defaults.
580 */
581 public WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
582 this(context, attrs, defStyleAttr, defStyleRes, null, false);
583 }
584
585 /**
586 * Constructs a new WebView with layout parameters and a default style.
587 *
588 * @param context a Context object used to access application assets
589 * @param attrs an AttributeSet passed to our parent
590 * @param defStyleAttr an attribute in the current theme that contains a
591 * reference to a style resource that supplies default values for
592 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100593 * @param privateBrowsing whether this WebView will be initialized in
594 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400595 *
Selim Gurunb6aa97e2014-03-26 14:10:28 -0700596 * @deprecated Private browsing is no longer supported directly via
Kristian Monsen5cc23512012-08-09 15:33:08 -0400597 * WebView and will be removed in a future release. Prefer using
598 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
599 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700600 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400601 @Deprecated
Alan Viverette617feb92013-09-09 18:09:13 -0700602 public WebView(Context context, AttributeSet attrs, int defStyleAttr,
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700603 boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700604 this(context, attrs, defStyleAttr, 0, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100605 }
606
607 /**
Steve Block4e584df2012-04-24 23:12:47 +0100608 * Constructs a new WebView with layout parameters, a default style and a set
Nate Fischerffb81c42016-09-26 12:35:47 -0700609 * of custom JavaScript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800610 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100611 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100612 *
613 * @param context a Context object used to access application assets
614 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700615 * @param defStyleAttr an attribute in the current theme that contains a
616 * reference to a style resource that supplies default values for
617 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100618 * @param javaScriptInterfaces a Map of interface names, as keys, and
619 * object implementing those interfaces, as
620 * values
621 * @param privateBrowsing whether this WebView will be initialized in
622 * private mode
Nate Fischerffb81c42016-09-26 12:35:47 -0700623 * @hide This is used internally by dumprendertree, as it requires the JavaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100624 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100625 */
Alan Viverette617feb92013-09-09 18:09:13 -0700626 protected WebView(Context context, AttributeSet attrs, int defStyleAttr,
Steve Block81f19ff2010-11-01 13:23:24 +0000627 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700628 this(context, attrs, defStyleAttr, 0, javaScriptInterfaces, privateBrowsing);
629 }
630
631 /**
632 * @hide
633 */
634 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
635 protected WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
636 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
637 super(context, attrs, defStyleAttr, defStyleRes);
Felipe Lemed04a6972017-03-02 12:56:18 -0800638
639 // WebView is important by default, unless app developer overrode attribute.
640 if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
641 setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
642 }
643
Kristian Monsen87af7312011-09-09 02:12:51 +0100644 if (context == null) {
645 throw new IllegalArgumentException("Invalid context argument");
646 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700647 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
648 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000649 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100650
Jonathan Dixon3c909522012-02-28 18:45:06 +0000651 ensureProviderCreated();
652 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100653 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
654 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 }
656
657 /**
Steve Block4e584df2012-04-24 23:12:47 +0100658 * Specifies whether the horizontal scrollbar has overlay style.
659 *
Paul Millerc8694a02015-06-05 11:23:03 -0700660 * @deprecated This method has no effect.
Steve Block4e584df2012-04-24 23:12:47 +0100661 * @param overlay true if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 */
Paul Millerc8694a02015-06-05 11:23:03 -0700663 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 public void setHorizontalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 }
666
667 /**
Steve Block4e584df2012-04-24 23:12:47 +0100668 * Specifies whether the vertical scrollbar has overlay style.
669 *
Paul Millerc8694a02015-06-05 11:23:03 -0700670 * @deprecated This method has no effect.
Steve Block4e584df2012-04-24 23:12:47 +0100671 * @param overlay true if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 */
Paul Millerc8694a02015-06-05 11:23:03 -0700673 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 public void setVerticalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676
677 /**
Steve Block4e584df2012-04-24 23:12:47 +0100678 * Gets whether horizontal scrollbar has overlay style.
679 *
Paul Millerc8694a02015-06-05 11:23:03 -0700680 * @deprecated This method is now obsolete.
681 * @return true
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 */
Paul Millerc8694a02015-06-05 11:23:03 -0700683 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 public boolean overlayHorizontalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700685 // The old implementation defaulted to true, so return true for consistency
686 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 }
688
689 /**
Steve Block4e584df2012-04-24 23:12:47 +0100690 * Gets whether vertical scrollbar has overlay style.
691 *
Paul Millerc8694a02015-06-05 11:23:03 -0700692 * @deprecated This method is now obsolete.
693 * @return false
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 */
Paul Millerc8694a02015-06-05 11:23:03 -0700695 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 public boolean overlayVerticalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700697 // The old implementation defaulted to false, so return false for consistency
698 return false;
Mike Reede8853fc2009-09-04 14:01:48 -0400699 }
700
Michael Kolbe54f6652011-03-16 09:11:51 -0700701 /**
Steve Block4e584df2012-04-24 23:12:47 +0100702 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700703 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700704 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400705 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400706 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700707 @Deprecated
Michael Kolb73980a92010-08-05 16:32:51 -0700708 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100709 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000710 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 }
712
713 /**
Steve Block4e584df2012-04-24 23:12:47 +0100714 * Gets the SSL certificate for the main top-level page or null if there is
715 * no certificate (the site is not secure).
716 *
717 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 */
719 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100720 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000721 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
723
724 /**
725 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400726 *
727 * @deprecated Calling this function has no useful effect, and will be
728 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400730 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100732 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000733 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 }
735
736 //-------------------------------------------------------------------------
737 // Methods called by activity
738 //-------------------------------------------------------------------------
739
740 /**
Steve Block32fe4102012-07-17 16:29:11 +0100741 * Sets a username and password pair for the specified host. This data is
Nate Fischerffb81c42016-09-26 12:35:47 -0700742 * used by the WebView to autocomplete username and password fields in web
Steve Block32fe4102012-07-17 16:29:11 +0100743 * forms. Note that this is unrelated to the credentials used for HTTP
744 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100745 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000746 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100747 * @param username the username for the given host
748 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100749 * @see WebViewDatabase#clearUsernamePassword
750 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800751 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800753 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100755 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000756 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
758
759 /**
Hui Shu433fb932016-08-29 11:49:46 -0700760 * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase}
761 * instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 *
Steve Block46ce1db2012-07-17 16:43:00 +0100763 * @param host the host to which the credentials apply
764 * @param realm the realm to which the credentials apply
765 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100766 * @param password the password
Nate Fischerc7edfb02016-09-23 15:59:21 -0700767 * @deprecated Use {@link WebViewDatabase#setHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700769 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 public void setHttpAuthUsernamePassword(String host, String realm,
771 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100772 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000773 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775
776 /**
Hui Shu433fb932016-08-29 11:49:46 -0700777 * Retrieves HTTP authentication credentials for a given host and realm from the {@link
778 * WebViewDatabase} instance.
Steve Block46ce1db2012-07-17 16:43:00 +0100779 * @param host the host to which the credentials apply
780 * @param realm the realm to which the credentials apply
781 * @return the credentials as a String array, if found. The first element
782 * is the username and the second element is the password. Null if
783 * no credentials are found.
Nate Fischerc7edfb02016-09-23 15:59:21 -0700784 * @deprecated Use {@link WebViewDatabase#getHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700786 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100788 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000789 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400790 }
791
792 /**
Steve Block4e584df2012-04-24 23:12:47 +0100793 * Destroys the internal state of this WebView. This method should be called
794 * after this WebView has been removed from the view system. No other
795 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 */
797 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100798 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000799 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 }
801
802 /**
803 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100804 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100805 *
806 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400807 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100809 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 public static void enablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700811 // noop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 }
813
814 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100815 * Disables platform notifications of data state and proxy changes.
816 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100817 *
818 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400819 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100821 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 public static void disablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700823 // noop
Feng Qianb3081372009-06-29 15:55:18 -0700824 }
825
826 /**
Primiano Tucci24426752013-09-05 12:01:51 +0100827 * Used only by internal tests to free up memory.
828 *
829 * @hide
830 */
831 public static void freeMemoryForTests() {
Primiano Tucci24426752013-09-05 12:01:51 +0100832 getFactory().getStatics().freeMemoryForTests();
833 }
834
835 /**
Steve Block4e584df2012-04-24 23:12:47 +0100836 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000837 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100839 *
840 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 */
842 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100843 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000844 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 }
846
847 /**
Steve Block4e584df2012-04-24 23:12:47 +0100848 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
850 * method no longer stores the display data for this WebView. The previous
851 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400852 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100853 *
854 * @param outState the Bundle to store this WebView's state
855 * @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 -0800856 * saveState fails, the returned list will be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 */
858 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100859 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000860 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 }
862
863 /**
Steve Block4e584df2012-04-24 23:12:47 +0100864 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100866 * @param b a Bundle to store the display data
867 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * overwritten with this WebView's picture data.
Steve Block4e584df2012-04-24 23:12:47 +0100869 * @return true if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100870 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400871 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100873 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400874 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100875 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000876 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
878
879 /**
Steve Block4e584df2012-04-24 23:12:47 +0100880 * Restores the display data that was saved in {@link #savePicture}. Used in
881 * conjunction with {@link #restoreState}. Note that this will not work if
882 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700883 *
Steve Block4e584df2012-04-24 23:12:47 +0100884 * @param b a Bundle containing the saved display data
885 * @param src the file where the picture data was stored
886 * @return true if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100887 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400888 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100890 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100892 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000893 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700894 }
895
896 /**
Steve Block42499062012-07-17 15:34:46 +0100897 * Restores the state of this WebView from the given Bundle. This method is
898 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
899 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100900 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400901 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400903 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100904 *
905 * @param inState the incoming Bundle of state
906 * @return the restored back/forward list or null if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 */
908 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100909 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000910 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 }
912
913 /**
Steve Block4e584df2012-04-24 23:12:47 +0100914 * Loads the given URL with the specified additional HTTP headers.
Bo Liue29d3132016-04-22 16:23:22 -0700915 * <p>
916 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100917 *
918 * @param url the URL of the resource to load
919 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100920 * HTTP request for this URL, specified as a map from name to
921 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100922 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100923 * controlling caching, accept types or the User-Agent, their
Nate Fischerffb81c42016-09-26 12:35:47 -0700924 * values may be overridden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800925 */
Steve Blockf71dea02011-08-01 12:29:14 +0100926 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100927 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000928 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800929 }
930
931 /**
Steve Block4e584df2012-04-24 23:12:47 +0100932 * Loads the given URL.
Bo Liue29d3132016-04-22 16:23:22 -0700933 * <p>
934 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100935 *
936 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 */
938 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100939 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000940 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
942
943 /**
Steve Block4e584df2012-04-24 23:12:47 +0100944 * Loads the URL with postData using "POST" method into this WebView. If url
Hui Shuc60ad9c2014-02-05 09:30:36 -0800945 * is not a network URL, it will be loaded with {@link #loadUrl(String)}
946 * instead, ignoring the postData param.
Cary Clarkd6982c92009-05-29 11:02:22 -0400947 *
Steve Block4e584df2012-04-24 23:12:47 +0100948 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100949 * @param postData the data will be passed to "POST" request, which must be
950 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700951 */
952 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100953 checkThread();
Hui Shuc60ad9c2014-02-05 09:30:36 -0800954 if (URLUtil.isNetworkUrl(url)) {
955 mProvider.postUrl(url, postData);
956 } else {
957 mProvider.loadUrl(url);
958 }
Grace Kloba57534302009-05-22 18:55:02 -0700959 }
960
961 /**
Steve Block4e584df2012-04-24 23:12:47 +0100962 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100963 * <p>
964 * Note that JavaScript's same origin policy means that script running in a
965 * page loaded using this method will be unable to access content loaded
966 * using any scheme other than 'data', including 'http(s)'. To avoid this
967 * restriction, use {@link
968 * #loadDataWithBaseURL(String,String,String,String,String)
969 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100970 * <p>
Steve Block27f3e322012-07-23 10:45:59 +0100971 * The encoding parameter specifies whether the data is base64 or URL
972 * encoded. If the data is base64 encoded, the value of the encoding
973 * parameter must be 'base64'. For all other values of the parameter,
974 * including null, it is assumed that the data uses ASCII encoding for
Steve Blockf95d4902011-06-09 11:53:26 +0100975 * octets inside the range of safe URL characters and use the standard %xx
Steve Block27f3e322012-07-23 10:45:59 +0100976 * hex encoding of URLs for octets outside that range. For example, '#',
977 * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
Steve Blockb19c7872011-10-10 14:09:44 +0100978 * <p>
979 * The 'data' scheme URL formed by this method uses the default US-ASCII
980 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100981 * 'data' scheme URL which explicitly specifies a charset parameter in the
982 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
983 * Note that the charset obtained from the mediatype portion of a data URL
984 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +0100985 *
986 * @param data a String of data in the given encoding
987 * @param mimeType the MIME type of the data, e.g. 'text/html'
988 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 */
990 public void loadData(String data, String mimeType, String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100991 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000992 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 }
994
995 /**
Steve Block4e584df2012-04-24 23:12:47 +0100996 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100997 * the content. The base URL is used both to resolve relative URLs and when
998 * applying JavaScript's same origin policy. The historyUrl is used for the
999 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 * <p>
Steve Blockae328572011-06-08 18:58:51 +01001001 * Note that content specified in this way can access local device files
1002 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
1003 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +01001004 * <p>
1005 * If the base URL uses the data scheme, this method is equivalent to
1006 * calling {@link #loadData(String,String,String) loadData()} and the
Ben Murdoch597256e2013-07-22 16:52:12 +01001007 * historyUrl is ignored, and the data will be treated as part of a data: URL.
1008 * If the base URL uses any other scheme, then the data will be loaded into
1009 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
1010 * entities in the string will not be decoded.
Mikhail Naganovb29e0f62015-09-16 13:05:53 -07001011 * <p>
1012 * Note that the baseUrl is sent in the 'Referer' HTTP header when
1013 * requesting subresources (images, etc.) of the page loaded using this method.
Steve Block4e584df2012-04-24 23:12:47 +01001014 *
1015 * @param baseUrl the URL to use as the page's base URL. If null defaults to
1016 * 'about:blank'.
1017 * @param data a String of data in the given encoding
1018 * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
1019 * defaults to 'text/html'.
1020 * @param encoding the encoding of the data
1021 * @param historyUrl the URL to use as the history entry. If null defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +00001022 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 */
1024 public void loadDataWithBaseURL(String baseUrl, String data,
Leon Scroggins1bb1a912010-03-23 15:39:46 -04001025 String mimeType, String encoding, String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +01001026 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001027 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
1029
1030 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +01001031 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
1032 * If non-null, |resultCallback| will be invoked with any result returned from that
1033 * execution. This method must be called on the UI thread and the callback will
1034 * be made on the UI thread.
Bo Liue29d3132016-04-22 16:23:22 -07001035 * <p>
1036 * Compatibility note. Applications targeting {@link android.os.Build.VERSION_CODES#N} or
1037 * later, JavaScript state from an empty WebView is no longer persisted across navigations like
1038 * {@link #loadUrl(String)}. For example, global variables and functions defined before calling
1039 * {@link #loadUrl(String)} will not exist in the loaded page. Applications should use
1040 * {@link #addJavascriptInterface} instead to persist JavaScript objects across navigations.
Ben Murdocha5cdd512013-07-17 16:25:07 +01001041 *
1042 * @param script the JavaScript to execute.
1043 * @param resultCallback A callback to be invoked when the script execution
1044 * completes with the result of the execution (if any).
Nate Fischerffb81c42016-09-26 12:35:47 -07001045 * May be null if no notification of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +01001046 */
1047 public void evaluateJavascript(String script, ValueCallback<String> resultCallback) {
1048 checkThread();
1049 mProvider.evaluateJavaScript(script, resultCallback);
1050 }
1051
1052 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001053 * Saves the current view as a web archive.
1054 *
Steve Block4e584df2012-04-24 23:12:47 +01001055 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001056 */
1057 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +01001058 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001059 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001060 }
1061
1062 /**
1063 * Saves the current view as a web archive.
1064 *
Steve Block4e584df2012-04-24 23:12:47 +01001065 * @param basename the filename where the archive should be placed
1066 * @param autoname if false, takes basename to be a file. If true, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001067 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +01001068 * chosen according to the URL of the current page.
1069 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001070 * parameter for onReceiveValue will either be the filename
1071 * under which the file was saved, or null if saving the
1072 * file failed.
1073 */
1074 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback) {
Steve Block51b08912011-04-27 15:04:48 +01001075 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001076 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001077 }
1078
1079 /**
Steve Block4e584df2012-04-24 23:12:47 +01001080 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 */
1082 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +01001083 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001084 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 }
1086
1087 /**
Steve Block4e584df2012-04-24 23:12:47 +01001088 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 */
1090 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +01001091 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001092 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 }
1094
1095 /**
Steve Block4e584df2012-04-24 23:12:47 +01001096 * Gets whether this WebView has a back history item.
1097 *
1098 * @return true iff this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 */
1100 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +01001101 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001102 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
1104
1105 /**
Steve Block4e584df2012-04-24 23:12:47 +01001106 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 */
1108 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +01001109 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001110 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
1112
1113 /**
Steve Block4e584df2012-04-24 23:12:47 +01001114 * Gets whether this WebView has a forward history item.
1115 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001116 * @return true iff this WebView has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 */
1118 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +01001119 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001120 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 }
1122
1123 /**
Steve Block4e584df2012-04-24 23:12:47 +01001124 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 */
1126 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +01001127 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001128 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 }
1130
1131 /**
Steve Block4e584df2012-04-24 23:12:47 +01001132 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +01001134 *
1135 * @param steps the negative or positive number of steps to move the
1136 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 */
1138 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001139 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001140 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142
1143 /**
Steve Block4e584df2012-04-24 23:12:47 +01001144 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 * the current item. Steps is negative if backward and positive
1146 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +01001147 *
1148 * @param steps the number of steps to take back or forward in the back
1149 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 */
1151 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001152 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001153 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001155
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001156 /**
Steve Block4e584df2012-04-24 23:12:47 +01001157 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001158 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -07001159 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +01001160 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001161 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 /**
Steve Block4e584df2012-04-24 23:12:47 +01001165 * Scrolls the contents of this WebView up by half the view size.
1166 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 * @param top true to jump to the top of the page
1168 * @return true if the page was scrolled
1169 */
1170 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +01001171 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001172 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 /**
Steve Block4e584df2012-04-24 23:12:47 +01001176 * Scrolls the contents of this WebView down by half the page size.
1177 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 * @param bottom true to jump to bottom of page
1179 * @return true if the page was scrolled
1180 */
1181 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001182 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001183 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
1185
1186 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +01001187 * Posts a {@link VisualStateCallback}, which will be called when
1188 * the current state of the WebView is ready to be drawn.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001189 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001190 * <p>Because updates to the DOM are processed asynchronously, updates to the DOM may not
Tobias Sargeantb3656042015-05-13 11:23:57 +01001191 * immediately be reflected visually by subsequent {@link WebView#onDraw} invocations. The
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001192 * {@link VisualStateCallback} provides a mechanism to notify the caller when the contents of
Tobias Sargeantb3656042015-05-13 11:23:57 +01001193 * the DOM at the current time are ready to be drawn the next time the {@link WebView}
1194 * draws.</p>
1195 *
1196 * <p>The next draw after the callback completes is guaranteed to reflect all the updates to the
Nate Fischerffb81c42016-09-26 12:35:47 -07001197 * DOM up to the point at which the {@link VisualStateCallback} was posted, but it may also
Tobias Sargeantb3656042015-05-13 11:23:57 +01001198 * contain updates applied after the callback was posted.</p>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001199 *
1200 * <p>The state of the DOM covered by this API includes the following:
1201 * <ul>
1202 * <li>primitive HTML elements (div, img, span, etc..)</li>
1203 * <li>images</li>
1204 * <li>CSS animations</li>
1205 * <li>WebGL</li>
1206 * <li>canvas</li>
1207 * </ul>
1208 * It does not include the state of:
1209 * <ul>
1210 * <li>the video tag</li>
1211 * </ul></p>
1212 *
1213 * <p>To guarantee that the {@link WebView} will successfully render the first frame
1214 * after the {@link VisualStateCallback#onComplete} method has been called a set of conditions
1215 * must be met:
1216 * <ul>
1217 * <li>If the {@link WebView}'s visibility is set to {@link View#VISIBLE VISIBLE} then
1218 * the {@link WebView} must be attached to the view hierarchy.</li>
1219 * <li>If the {@link WebView}'s visibility is set to {@link View#INVISIBLE INVISIBLE}
1220 * then the {@link WebView} must be attached to the view hierarchy and must be made
1221 * {@link View#VISIBLE VISIBLE} from the {@link VisualStateCallback#onComplete} method.</li>
1222 * <li>If the {@link WebView}'s visibility is set to {@link View#GONE GONE} then the
1223 * {@link WebView} must be attached to the view hierarchy and its
1224 * {@link AbsoluteLayout.LayoutParams LayoutParams}'s width and height need to be set to fixed
1225 * values and must be made {@link View#VISIBLE VISIBLE} from the
1226 * {@link VisualStateCallback#onComplete} method.</li>
1227 * </ul></p>
1228 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001229 * <p>When using this API it is also recommended to enable pre-rasterization if the {@link
Nate Fischerffb81c42016-09-26 12:35:47 -07001230 * WebView} is off screen to avoid flickering. See {@link WebSettings#setOffscreenPreRaster} for
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001231 * more details and do consider its caveats.</p>
1232 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001233 * @param requestId An id that will be returned in the callback to allow callers to match
1234 * requests with callbacks.
1235 * @param callback The callback to be invoked.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001236 */
Tobias Sargeantb3656042015-05-13 11:23:57 +01001237 public void postVisualStateCallback(long requestId, VisualStateCallback callback) {
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001238 checkThread();
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001239 mProvider.insertVisualStateCallback(requestId, callback);
1240 }
1241
1242 /**
Steve Block4e584df2012-04-24 23:12:47 +01001243 * Clears this WebView so that onDraw() will draw nothing but white background,
1244 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001245 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1246 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001248 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001250 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001251 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 /**
Steve Block72498ed2012-07-17 15:57:25 +01001255 * Gets a new picture that captures the current contents of this WebView.
1256 * The picture is of the entire document being displayed, and is not
1257 * limited to the area currently displayed by this WebView. Also, the
1258 * picture is a static copy and is unaffected by later changes to the
1259 * content being displayed.
1260 * <p>
1261 * Note that due to internal changes, for API levels between
1262 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1263 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1264 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001265 * <p>
1266 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1267 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
1268 * additional conversion at a cost in memory and performance. Also the
1269 * {@link android.graphics.Picture#createFromStream} and
1270 * {@link android.graphics.Picture#writeToStream} methods are not supported on the
1271 * returned object.
1272 *
1273 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001274 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 *
Steve Block72498ed2012-07-17 15:57:25 +01001276 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001278 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001280 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001281 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 }
1283
Cary Clarkd6982c92009-05-29 11:02:22 -04001284 /**
Selim Gurun23a1af62014-03-14 16:52:45 -07001285 * @deprecated Use {@link #createPrintDocumentAdapter(String)} which requires user
1286 * to provide a print document name.
1287 */
1288 @Deprecated
1289 public PrintDocumentAdapter createPrintDocumentAdapter() {
1290 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001291 return mProvider.createPrintDocumentAdapter("default");
1292 }
1293
1294 /**
Nate Fischerffb81c42016-09-26 12:35:47 -07001295 * Creates a PrintDocumentAdapter that provides the content of this WebView for printing.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001296 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001297 * The adapter works by converting the WebView contents to a PDF stream. The WebView cannot
Selim Gurunda7d6422013-09-06 14:39:05 -07001298 * be drawn during the conversion process - any such draws are undefined. It is recommended
Nate Fischerffb81c42016-09-26 12:35:47 -07001299 * to use a dedicated off screen WebView for the printing. If necessary, an application may
Selim Gurunda7d6422013-09-06 14:39:05 -07001300 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1301 * wrapped around the object returned and observing the onStart and onFinish methods. See
1302 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun23a1af62014-03-14 16:52:45 -07001303 *
1304 * @param documentName The user-facing name of the printed document. See
1305 * {@link android.print.PrintDocumentInfo}
Selim Gurun2167c0b2013-08-05 15:23:09 -07001306 */
Selim Gurun23a1af62014-03-14 16:52:45 -07001307 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName) {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001308 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001309 return mProvider.createPrintDocumentAdapter(documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -07001310 }
1311
1312 /**
Steve Block4e584df2012-04-24 23:12:47 +01001313 * Gets the current scale of this WebView.
1314 *
1315 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001316 *
1317 * @deprecated This method is prone to inaccuracy due to race conditions
1318 * between the web rendering and UI threads; prefer
1319 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001321 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001322 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001324 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001325 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001326 }
1327
1328 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001329 * Sets the initial scale for this WebView. 0 means default.
1330 * The behavior for the default scale depends on the state of
1331 * {@link WebSettings#getUseWideViewPort()} and
1332 * {@link WebSettings#getLoadWithOverviewMode()}.
1333 * If the content fits into the WebView control by width, then
Nate Fischerffb81c42016-09-26 12:35:47 -07001334 * the zoom is set to 100%. For wide content, the behavior
Mikhail Naganov00303362013-09-02 10:57:04 +01001335 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
1336 * If its value is true, the content will be zoomed out to be fit
1337 * by width into the WebView control, otherwise not.
1338 *
1339 * If initial scale is greater than 0, WebView starts with this value
1340 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001341 * Please note that unlike the scale properties in the viewport meta tag,
1342 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 *
Steve Block4e584df2012-04-24 23:12:47 +01001344 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 */
1346 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001347 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001348 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 }
1350
1351 /**
Steve Block4e584df2012-04-24 23:12:47 +01001352 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 * result in the zoom widget appearing on the screen to control the zoom
1354 * level of this WebView.
1355 */
1356 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001357 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001358 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 }
1360
1361 /**
Steve Block4e584df2012-04-24 23:12:47 +01001362 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1363 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1364 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1365 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1366 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001368 * 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 -08001369 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001370 * 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 -08001371 * a child node. If a phone number is found, the HitTestResult type is set
1372 * to PHONE_TYPE and the phone number is set in the "extra" field of
1373 * HitTestResult. If a map address is found, the HitTestResult type is set
1374 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1375 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1376 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1377 * HitTestResult type is set to UNKNOWN_TYPE.
1378 */
1379 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001380 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001381 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001382 }
1383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 /**
Steve Block4e584df2012-04-24 23:12:47 +01001385 * Requests the anchor or image element URL at the last tapped point.
Cary Clark861368a2010-12-15 11:24:37 -05001386 * If hrefMsg is null, this method returns immediately and does not
1387 * dispatch hrefMsg to its target. If the tapped point hits an image,
1388 * an anchor, or an image in an anchor, the message associates
1389 * strings in named keys in its data. The value paired with the key
1390 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001391 *
Steve Block4e584df2012-04-24 23:12:47 +01001392 * @param hrefMsg the message to be dispatched with the result of the
1393 * request. The message data contains three keys. "url"
1394 * returns the anchor's href attribute. "title" returns the
1395 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 */
1397 public void requestFocusNodeHref(Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001398 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001399 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 /**
Steve Block4e584df2012-04-24 23:12:47 +01001403 * Requests the URL of the image last touched by the user. msg will be sent
1404 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001405 *
Steve Block4e584df2012-04-24 23:12:47 +01001406 * @param msg the message to be dispatched with the result of the request
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 * as the data member with "url" as key. The result can be null.
1408 */
1409 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001410 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001411 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001412 }
1413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 /**
Steve Block4e584df2012-04-24 23:12:47 +01001415 * 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 -08001416 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001417 * that URL has begun, the current page may not have changed.
1418 *
1419 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 */
John Reck926cf562012-06-14 10:00:31 -07001421 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001423 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001424 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 /**
Steve Block4e584df2012-04-24 23:12:47 +01001428 * Gets the original URL for the current page. This is not always the same
1429 * as the URL passed to WebViewClient.onPageStarted because although the
1430 * load for that URL has begun, the current page may not have changed.
1431 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001433 *
1434 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 */
John Reck926cf562012-06-14 10:00:31 -07001436 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001438 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001439 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 }
1441
1442 /**
Steve Block4e584df2012-04-24 23:12:47 +01001443 * 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 -08001444 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001445 *
1446 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 */
John Reck926cf562012-06-14 10:00:31 -07001448 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001450 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001451 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 }
1453
1454 /**
Steve Block4e584df2012-04-24 23:12:47 +01001455 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001457 *
1458 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 */
1460 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001461 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001462 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464
1465 /**
Steve Block4e584df2012-04-24 23:12:47 +01001466 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001467 * a URL on this site's server pointing to the standard location of a
1468 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001469 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001470 * @hide
1471 */
1472 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001473 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001474 }
1475
1476 /**
Steve Block4e584df2012-04-24 23:12:47 +01001477 * Gets the progress for the current page.
1478 *
1479 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 */
1481 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001482 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001483 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 /**
Steve Block4e584df2012-04-24 23:12:47 +01001487 * Gets the height of the HTML content.
1488 *
1489 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 */
John Reck926cf562012-06-14 10:00:31 -07001491 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001493 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001494 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 }
1496
1497 /**
Steve Block4e584df2012-04-24 23:12:47 +01001498 * Gets the width of the HTML content.
1499 *
1500 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001501 * @hide
1502 */
John Reck926cf562012-06-14 10:00:31 -07001503 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001504 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001505 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001506 }
1507
1508 /**
Steve Block4e584df2012-04-24 23:12:47 +01001509 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1510 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001511 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 */
1513 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001514 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001515 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 }
1517
1518 /**
Steve Block4e584df2012-04-24 23:12:47 +01001519 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001520 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 */
1522 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001523 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001524 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 }
1526
1527 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001528 * Does a best-effort attempt to pause any processing that can be paused
1529 * safely, such as animations and geolocation. Note that this call
1530 * does not pause JavaScript. To pause JavaScript globally, use
1531 * {@link #pauseTimers}.
1532 *
1533 * To resume WebView, call {@link #onResume}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001534 */
1535 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001536 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001537 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001538 }
1539
1540 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001541 * Resumes a WebView after a previous call to {@link #onPause}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001542 */
1543 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001544 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001545 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001546 }
1547
1548 /**
Steve Block4e584df2012-04-24 23:12:47 +01001549 * Gets whether this WebView is paused, meaning onPause() was called.
1550 * Calling onResume() sets the paused state back to false.
1551 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001552 * @hide
1553 */
1554 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001555 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001556 }
1557
1558 /**
Steve Block4e584df2012-04-24 23:12:47 +01001559 * Informs this WebView that memory is low so that it can free any available
1560 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001561 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1562 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001563 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001564 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001565 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001566 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001567 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001568 }
1569
1570 /**
Steve Block4e584df2012-04-24 23:12:47 +01001571 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001572 * this will clear the cache for all WebViews used.
1573 *
Steve Block4e584df2012-04-24 23:12:47 +01001574 * @param includeDiskFiles if false, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 */
1576 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001577 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001578 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 }
1580
1581 /**
Steve Block219dfa42012-07-20 10:31:21 +01001582 * Removes the autocomplete popup from the currently focused form field, if
1583 * present. Note this only affects the display of the autocomplete popup,
1584 * it does not remove any saved form data from this WebView's store. To do
1585 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 */
1587 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001588 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001589 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 }
1591
1592 /**
Steve Block4e584df2012-04-24 23:12:47 +01001593 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 */
1595 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001596 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001597 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 }
1599
1600 /**
Steve Block4e584df2012-04-24 23:12:47 +01001601 * Clears the SSL preferences table stored in response to proceeding with
1602 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 */
1604 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001605 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001606 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 }
1608
1609 /**
Selim Gurunee89ab42014-06-13 10:53:55 -07001610 * Clears the client certificate preferences stored in response
Nate Fischerffb81c42016-09-26 12:35:47 -07001611 * to proceeding/cancelling client cert requests. Note that WebView
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001612 * automatically clears these preferences when it receives a
Selim Gurunee89ab42014-06-13 10:53:55 -07001613 * {@link KeyChain#ACTION_STORAGE_CHANGED} intent. The preferences are
Nate Fischerffb81c42016-09-26 12:35:47 -07001614 * shared by all the WebViews that are created by the embedder application.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001615 *
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001616 * @param onCleared A runnable to be invoked when client certs are cleared.
1617 * The embedder can pass null if not interested in the
1618 * callback. The runnable will be called in UI thread.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001619 */
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001620 public static void clearClientCertPreferences(Runnable onCleared) {
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001621 getFactory().getStatics().clearClientCertPreferences(onCleared);
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001622 }
1623
1624 /**
Nate Fischer3ca196a2017-07-12 18:45:03 -07001625 * Starts Safe Browsing initialization. This should only be called once. This does not require
1626 * an Activity Context, and will always use the application Context to do its work.
1627 * @param context Application Context.
Nate Fischer0e72c182017-05-30 11:25:17 -07001628 * @param callback will be called with the value true if initialization is
1629 * successful. The callback will be run on the UI thread.
1630 */
1631 public static void initSafeBrowsing(Context context, ValueCallback<Boolean> callback) {
1632 getFactory().getStatics().initSafeBrowsing(context, callback);
1633 }
1634
1635 /**
1636 * Shuts down Safe Browsing. This should only be called once.
1637 */
1638 public static void shutdownSafeBrowsing() {
1639 getFactory().getStatics().shutdownSafeBrowsing();
1640 }
1641
1642 /**
Nate Fischerbf158ec2017-06-27 22:52:20 -07001643 * Sets the list of domains that are exempt from SafeBrowsing checks. The list is
1644 * global for all the WebViews.
1645 * TODO: Add documentation for the format of the urls.
1646 *
1647 * @param urls the list of URLs
Nate Fischerd6385d32017-07-17 12:58:18 -07001648 * @param callback will be called with true if URLs are successfully added to the whitelist. It
1649 * will be called with false if any URLs are malformed. The callback will be run on the UI
1650 * thread.
Nate Fischerbf158ec2017-06-27 22:52:20 -07001651 */
Nate Fischerc5ec7452017-07-18 16:08:42 -07001652 public static void setSafeBrowsingWhitelist(@NonNull List<String> urls,
Nate Fischerd6385d32017-07-17 12:58:18 -07001653 @Nullable ValueCallback<Boolean> callback) {
1654 getFactory().getStatics().setSafeBrowsingWhitelist(urls, callback);
Nate Fischerbf158ec2017-06-27 22:52:20 -07001655 }
1656
1657 /**
Steve Block4e584df2012-04-24 23:12:47 +01001658 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 * back/forward list for use in querying each item in the history stack.
1660 * This is a copy of the private WebBackForwardList so it contains only a
1661 * snapshot of the current state. Multiple calls to this method may return
1662 * different objects. The object returned from this method will not be
1663 * updated to reflect any new state.
1664 */
1665 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001666 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001667 return mProvider.copyBackForwardList();
1668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 }
1670
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001671 /**
Steve Block4e584df2012-04-24 23:12:47 +01001672 * Registers the listener to be notified as find-on-page operations
1673 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001674 *
Steve Block4e584df2012-04-24 23:12:47 +01001675 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001676 */
1677 public void setFindListener(FindListener listener) {
1678 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001679 setupFindListenerIfNeeded();
1680 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001681 }
1682
1683 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001684 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001685 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001686 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1687 * has not been called yet, or if {@link #clearMatches} has been called since the
1688 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 *
Steve Block4e584df2012-04-24 23:12:47 +01001690 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001691 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 */
1693 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001694 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001695 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 }
1697
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001698 /**
Steve Block4e584df2012-04-24 23:12:47 +01001699 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001700 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001701 *
Steve Block4e584df2012-04-24 23:12:47 +01001702 * @param find the string to find
Nate Fischerffb81c42016-09-26 12:35:47 -07001703 * @return the number of occurrences of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001704 * @deprecated {@link #findAllAsync} is preferred.
1705 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001707 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001709 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001710 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001711 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 }
1713
Cary Clark3403eb32010-03-03 10:05:16 -05001714 /**
Steve Block4e584df2012-04-24 23:12:47 +01001715 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001716 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001717 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001718 *
Steve Block4e584df2012-04-24 23:12:47 +01001719 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001720 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001721 */
1722 public void findAllAsync(String find) {
1723 checkThread();
1724 mProvider.findAllAsync(find);
1725 }
1726
1727 /**
Steve Block4e584df2012-04-24 23:12:47 +01001728 * Starts an ActionMode for finding text in this WebView. Only works if this
1729 * WebView is attached to the view system.
1730 *
1731 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001732 * Otherwise, the last String searched for in this WebView will
1733 * be used to start.
Steve Block4e584df2012-04-24 23:12:47 +01001734 * @param showIme if true, show the IME, assuming the user will begin typing.
1735 * If false and text is non-null, perform a find all.
1736 * @return true if the find dialog is shown, false otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001737 * @deprecated This method does not work reliably on all Android versions;
1738 * implementing a custom find dialog using WebView.findAllAsync()
1739 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001740 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001741 @Deprecated
Leon Scroggins571354f2011-01-04 10:12:41 -05001742 public boolean showFindDialog(String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001743 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001744 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001745 }
1746
1747 /**
Steve Block4e584df2012-04-24 23:12:47 +01001748 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 * location. Currently, only addresses in the United States are detected,
1750 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001751 * <ul>
1752 * <li>a house number</li>
1753 * <li>a street name</li>
1754 * <li>a street type (Road, Circle, etc), either spelled out or
1755 * abbreviated</li>
1756 * <li>a city name</li>
1757 * <li>a state or territory, either spelled out or two-letter abbr</li>
1758 * <li>an optional 5 digit or 9 digit zip code</li>
1759 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 * All names must be correctly capitalized, and the zip code, if present,
1761 * must be valid for the state. The street type must be a standard USPS
1762 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001763 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 *
Steve Block4e584df2012-04-24 23:12:47 +01001766 * @param addr the string to search for addresses
1767 * @return the address, or if no address is found, null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 */
1769 public static String findAddress(String addr) {
Kristian Monsen10ca8082014-04-29 11:02:42 -07001770 // TODO: Rewrite this in Java so it is not needed to start up chromium
1771 // Could also be deprecated
Jonathan Dixon3c909522012-02-28 18:45:06 +00001772 return getFactory().getStatics().findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 }
1774
Victoria Lease0b8413b2012-03-26 13:04:10 -07001775 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -07001776 * For apps targeting the L release, WebView has a new default behavior that reduces
1777 * memory footprint and increases performance by intelligently choosing
1778 * the portion of the HTML document that needs to be drawn. These
1779 * optimizations are transparent to the developers. However, under certain
1780 * circumstances, an App developer may want to disable them:
Ben Murdoch574fa342015-01-07 14:20:45 +00001781 * <ol>
1782 * <li>When an app uses {@link #onDraw} to do own drawing and accesses portions
1783 * of the page that is way outside the visible portion of the page.</li>
1784 * <li>When an app uses {@link #capturePicture} to capture a very large HTML document.
1785 * Note that capturePicture is a deprecated API.</li>
1786 * </ol>
Selim Gurun17d1adb2014-08-27 11:22:26 -07001787 * Enabling drawing the entire HTML document has a significant performance
1788 * cost. This method should be called before any WebViews are created.
Bo Liu9f3ed852014-07-18 10:03:12 -07001789 */
1790 public static void enableSlowWholeDocumentDraw() {
1791 getFactory().getStatics().enableSlowWholeDocumentDraw();
1792 }
1793
1794 /**
Steve Block4e584df2012-04-24 23:12:47 +01001795 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001796 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 */
1798 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001799 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001800 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 }
1802
1803 /**
Steve Block4e584df2012-04-24 23:12:47 +01001804 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 * message object will be dispatched with arg1 being set to 1 if images
1806 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001807 *
1808 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 */
1810 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001811 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001812 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 }
1814
1815 /**
Steve Block4e584df2012-04-24 23:12:47 +01001816 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001818 *
1819 * @param client an implementation of WebViewClient
Nate Fischer6e585842016-09-29 18:30:58 -07001820 * @see #getWebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 */
1822 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001823 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001824 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001825 }
1826
1827 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001828 * Gets the WebViewClient.
1829 *
1830 * @return the WebViewClient, or a default client if not yet set
1831 * @see #setWebViewClient
1832 */
1833 public WebViewClient getWebViewClient() {
1834 checkThread();
1835 return mProvider.getWebViewClient();
1836 }
1837
1838 /**
Steve Block4e584df2012-04-24 23:12:47 +01001839 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 * the rendering engine, and should be downloaded instead. This will replace
1841 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001842 *
1843 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 */
1845 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001846 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001847 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 }
1849
1850 /**
Steve Block4e584df2012-04-24 23:12:47 +01001851 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001852 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001854 *
1855 * @param client an implementation of WebChromeClient
Nate Fischer6e585842016-09-29 18:30:58 -07001856 * @see #getWebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 */
1858 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001859 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001860 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001861 }
1862
1863 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001864 * Gets the chrome handler.
1865 *
1866 * @return the WebChromeClient, or null if not yet set
1867 * @see #setWebChromeClient
1868 */
1869 public WebChromeClient getWebChromeClient() {
1870 checkThread();
1871 return mProvider.getWebChromeClient();
1872 }
1873
1874 /**
Steve Block4e584df2012-04-24 23:12:47 +01001875 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001877 *
1878 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001879 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001881 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001883 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001884 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 }
1886
1887 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001888 * Injects the supplied Java object into this WebView. The object is
1889 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001890 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001891 * accessed from JavaScript. For applications targeted to API
1892 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001893 * and above, only public methods that are annotated with
1894 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001895 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001896 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001897 * important security note below for implications.
1898 * <p> Note that injected objects will not
Steve Block3aa800b2012-04-24 13:01:34 +01001899 * appear in JavaScript until the page is next (re)loaded. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001900 * <pre>
1901 * class JsObject {
1902 * {@literal @}JavascriptInterface
1903 * public String toString() { return "injectedObject"; }
1904 * }
1905 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001906 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1907 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001908 * <p>
1909 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001911 * <li> This method can be used to allow JavaScript to control the host
1912 * application. This is a powerful feature, but also presents a security
Scott Rowe607c17f2014-08-07 11:42:09 -07001913 * risk for apps targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or earlier.
1914 * Apps that target a version later than {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1915 * are still vulnerable if the app runs on a device running Android earlier than 4.2.
1916 * The most secure way to use this method is to target {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1917 * and to ensure the method is called only when running on Android 4.2 or later.
1918 * With these older versions, JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001919 * injected object's public fields. Use of this method in a WebView
1920 * containing untrusted content could allow an attacker to manipulate the
1921 * host application in unintended ways, executing Java code with the
1922 * permissions of the host application. Use extreme care when using this
1923 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001924 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001925 * thread of this WebView. Care is therefore required to maintain thread
Scott Rowe607c17f2014-08-07 11:42:09 -07001926 * safety.
1927 * </li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001928 * <li> The Java object's fields are not accessible.</li>
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001929 * <li> For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP}
Mikhail Naganovd380b202014-04-10 18:07:42 +01001930 * and above, methods of injected Java objects are enumerable from
1931 * JavaScript.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001932 * </ul>
1933 *
1934 * @param object the Java object to inject into this WebView's JavaScript
Steve Block4cd73c52011-11-09 13:06:52 +00001935 * context. Null values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001936 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 */
Steve Block4cd73c52011-11-09 13:06:52 +00001938 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001939 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001940 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 }
1942
1943 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001944 * Removes a previously injected Java object from this WebView. Note that
1945 * the removal will not be reflected in JavaScript until the page is next
1946 * (re)loaded. See {@link #addJavascriptInterface}.
1947 *
1948 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001949 */
Steve Block3aa800b2012-04-24 13:01:34 +01001950 public void removeJavascriptInterface(String name) {
Steve Block51b08912011-04-27 15:04:48 +01001951 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01001952 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001953 }
1954
1955 /**
Selim Gurun4c8093a2015-03-10 17:40:06 -07001956 * Creates a message channel to communicate with JS and returns the message
1957 * ports that represent the endpoints of this message channel. The HTML5 message
Selim Gurun0a814b62015-05-13 10:15:55 -07001958 * channel functionality is described
1959 * <a href="https://html.spec.whatwg.org/multipage/comms.html#messagechannel">here
1960 * </a>
Selim Gurun4c8093a2015-03-10 17:40:06 -07001961 *
Hui Shu86ea9c12015-10-08 10:23:08 -07001962 * <p>The returned message channels are entangled and already in started state.</p>
Selim Gurun4c8093a2015-03-10 17:40:06 -07001963 *
1964 * @return the two message ports that form the message channel.
1965 */
1966 public WebMessagePort[] createWebMessageChannel() {
1967 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001968 return mProvider.createWebMessageChannel();
1969 }
1970
1971 /**
1972 * Post a message to main frame. The embedded application can restrict the
1973 * messages to a certain target origin. See
Selim Gurun0a814b62015-05-13 10:15:55 -07001974 * <a href="https://html.spec.whatwg.org/multipage/comms.html#posting-messages">
1975 * HTML5 spec</a> for how target origin can be used.
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001976 * <p>
1977 * A target origin can be set as a wildcard ("*"). However this is not recommended.
1978 * See the page above for security issues.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001979 *
1980 * @param message the WebMessage
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001981 * @param targetOrigin the target origin.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001982 */
Selim Gurun26de90a2015-05-15 11:02:45 -07001983 public void postWebMessage(WebMessage message, Uri targetOrigin) {
Selim Gurun4c8093a2015-03-10 17:40:06 -07001984 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001985 mProvider.postMessageToMainFrame(message, targetOrigin);
1986 }
1987
1988 /**
Steve Block4e584df2012-04-24 23:12:47 +01001989 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001991 *
1992 * @return a WebSettings object that can be used to control this WebView's
1993 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 */
1995 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001996 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001997 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 }
1999
Jonathan Dixon3c909522012-02-28 18:45:06 +00002000 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07002001 * Enables debugging of web contents (HTML / CSS / JavaScript)
2002 * loaded into any WebViews of this application. This flag can be enabled
2003 * in order to facilitate debugging of web layouts and JavaScript
2004 * code running inside WebViews. Please refer to WebView documentation
2005 * for the debugging guide.
2006 *
2007 * The default is false.
2008 *
2009 * @param enabled whether to enable web contents debugging
2010 */
2011 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07002012 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
2013 }
2014
2015 /**
Steve Block4e584df2012-04-24 23:12:47 +01002016 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002017 *
Steve Block4e584df2012-04-24 23:12:47 +01002018 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00002019 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01002020 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00002021 */
Andrei Popescu385df692009-08-13 11:59:57 +01002022 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08002024 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 }
2026
Jonathan Dixon3c909522012-02-28 18:45:06 +00002027 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002028 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01002029 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00002030 */
Andrei Popescu385df692009-08-13 11:59:57 +01002031 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01002032 public void refreshPlugins(boolean reloadOpenPages) {
2033 checkThread();
2034 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035
Cary Clark966641a2010-03-04 08:41:56 -05002036 /**
Steve Block4e584df2012-04-24 23:12:47 +01002037 * Puts this WebView into text selection mode. Do not rely on this
2038 * functionality; it will be deprecated in the future.
2039 *
Kristian Monsenfc771652011-05-10 16:44:05 +01002040 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002041 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05002042 */
Kristian Monsenfc771652011-05-10 16:44:05 +01002043 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01002045 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07002046 }
2047
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002048 /**
2049 * @deprecated WebView no longer needs to implement
2050 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2051 */
George Mountfab67a12012-01-05 09:58:53 -08002052 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002053 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002054 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04002056
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002057 /**
2058 * @deprecated WebView no longer needs to implement
2059 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2060 */
George Mountfab67a12012-01-05 09:58:53 -08002061 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002062 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002063 @Deprecated
2064 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065
2066 /**
2067 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08002068 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 */
George Mountfab67a12012-01-05 09:58:53 -08002070 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002071 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002072 @Deprecated
2073 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
2074 }
2075
Kristian Monsen5cc23512012-08-09 15:33:08 -04002076 /**
2077 * @deprecated Only the default case, true, will be supported in a future version.
2078 */
2079 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01002081 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002082 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 }
2084
Derek Sollenberger03e48912010-05-18 17:03:42 -04002085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01002087 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002088 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 }
2090
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002091 /**
Steve Block4e584df2012-04-24 23:12:47 +01002092 * Gets the zoom controls for this WebView, as a separate View. The caller
2093 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002094 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01002095 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
2096 * built-in zoom mechanisms for the WebView, as opposed to these separate
2097 * zoom controls. The built-in mechanisms are preferred and can be enabled
2098 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07002099 *
Steve Block4e584df2012-04-24 23:12:47 +01002100 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01002101 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 */
The Android Open Source Project10592532009-03-18 17:39:46 -07002103 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01002105 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002106 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07002107 }
2108
2109 /**
Steve Block4e584df2012-04-24 23:12:47 +01002110 * Gets whether this WebView can be zoomed in.
2111 *
2112 * @return true if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04002113 *
2114 * @deprecated This method is prone to inaccuracy due to race conditions
2115 * between the web rendering and UI threads; prefer
2116 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002117 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002118 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002119 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002120 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002121 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07002122 }
2123
2124 /**
Steve Block4e584df2012-04-24 23:12:47 +01002125 * Gets whether this WebView can be zoomed out.
2126 *
2127 * @return true if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04002128 *
2129 * @deprecated This method is prone to inaccuracy due to race conditions
2130 * between the web rendering and UI threads; prefer
2131 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002132 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002133 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002134 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002135 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002136 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07002137 }
2138
2139 /**
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002140 * Performs a zoom operation in this WebView.
2141 *
Nate Fischerffb81c42016-09-26 12:35:47 -07002142 * @param zoomFactor the zoom factor to apply. The zoom factor will be clamped to the WebView's
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002143 * zoom limits. This value must be in the range 0.01 to 100.0 inclusive.
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002144 */
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002145 public void zoomBy(float zoomFactor) {
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002146 checkThread();
2147 if (zoomFactor < 0.01)
2148 throw new IllegalArgumentException("zoomFactor must be greater than 0.01.");
2149 if (zoomFactor > 100.0)
2150 throw new IllegalArgumentException("zoomFactor must be less than 100.");
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002151 mProvider.zoomBy(zoomFactor);
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002152 }
2153
2154 /**
Steve Block4e584df2012-04-24 23:12:47 +01002155 * Performs zoom in in this WebView.
2156 *
2157 * @return true if zoom in succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 */
2159 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002160 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002161 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
2163
2164 /**
Steve Block4e584df2012-04-24 23:12:47 +01002165 * Performs zoom out in this WebView.
2166 *
2167 * @return true if zoom out succeeds, false if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002168 */
2169 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002170 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002171 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 }
2173
Kristian Monsenfc771652011-05-10 16:44:05 +01002174 /**
2175 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002176 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01002177 */
2178 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01002180 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 }
Cary Clarkd6982c92009-05-29 11:02:22 -04002182
John Reck926cf562012-06-14 10:00:31 -07002183 /**
John Reckf2361152012-06-14 15:23:22 -07002184 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07002185 * @hide
2186 */
2187 @Override
2188 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
2189 mProvider.dumpViewHierarchyWithProperties(out, level);
2190 }
2191
2192 /**
2193 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
2194 * @hide
2195 */
2196 @Override
2197 public View findHierarchyView(String className, int hashCode) {
2198 return mProvider.findHierarchyView(className, hashCode);
2199 }
2200
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002201 /** @hide */
2202 @IntDef({
2203 RENDERER_PRIORITY_WAIVED,
2204 RENDERER_PRIORITY_BOUND,
2205 RENDERER_PRIORITY_IMPORTANT
2206 })
2207 @Retention(RetentionPolicy.SOURCE)
2208 public @interface RendererPriority {}
2209
2210 /**
2211 * The renderer associated with this WebView is bound with
2212 * {@link Context#BIND_WAIVE_PRIORITY}. At this priority level
2213 * {@link WebView} renderers will be strong targets for out of memory
2214 * killing.
2215 *
2216 * Use with {@link #setRendererPriorityPolicy}.
2217 */
2218 public static final int RENDERER_PRIORITY_WAIVED = 0;
2219 /**
2220 * The renderer associated with this WebView is bound with
2221 * the default priority for services.
2222 *
2223 * Use with {@link #setRendererPriorityPolicy}.
2224 */
2225 public static final int RENDERER_PRIORITY_BOUND = 1;
2226 /**
2227 * The renderer associated with this WebView is bound with
2228 * {@link Context#BIND_IMPORTANT}.
2229 *
2230 * Use with {@link #setRendererPriorityPolicy}.
2231 */
2232 public static final int RENDERER_PRIORITY_IMPORTANT = 2;
2233
2234 /**
2235 * Set the renderer priority policy for this {@link WebView}. The
2236 * priority policy will be used to determine whether an out of
2237 * process renderer should be considered to be a target for OOM
2238 * killing.
2239 *
2240 * Because a renderer can be associated with more than one
2241 * WebView, the final priority it is computed as the maximum of
2242 * any attached WebViews. When a WebView is destroyed it will
2243 * cease to be considerered when calculating the renderer
2244 * priority. Once no WebViews remain associated with the renderer,
2245 * the priority of the renderer will be reduced to
2246 * {@link #RENDERER_PRIORITY_WAIVED}.
2247 *
2248 * The default policy is to set the priority to
2249 * {@link #RENDERER_PRIORITY_IMPORTANT} regardless of visibility,
2250 * and this should not be changed unless the caller also handles
2251 * renderer crashes with
2252 * {@link WebViewClient#onRenderProcessGone}. Any other setting
2253 * will result in WebView renderers being killed by the system
2254 * more aggressively than the application.
2255 *
2256 * @param rendererRequestedPriority the minimum priority at which
2257 * this WebView desires the renderer process to be bound.
2258 * @param waivedWhenNotVisible if true, this flag specifies that
2259 * when this WebView is not visible, it will be treated as
2260 * if it had requested a priority of
2261 * {@link #RENDERER_PRIORITY_WAIVED}.
2262 */
2263 public void setRendererPriorityPolicy(
2264 @RendererPriority int rendererRequestedPriority,
2265 boolean waivedWhenNotVisible) {
2266 mProvider.setRendererPriorityPolicy(rendererRequestedPriority, waivedWhenNotVisible);
2267 }
2268
2269 /**
2270 * Get the requested renderer priority for this WebView.
2271 *
2272 * @return the requested renderer priority policy.
2273 */
2274 @RendererPriority
2275 public int getRendererRequestedPriority() {
2276 return mProvider.getRendererRequestedPriority();
2277 }
2278
2279 /**
2280 * Return whether this WebView requests a priority of
2281 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2282 *
2283 * @return whether this WebView requests a priority of
2284 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2285 */
2286 public boolean getRendererPriorityWaivedWhenNotVisible() {
2287 return mProvider.getRendererPriorityWaivedWhenNotVisible();
2288 }
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002289
2290 /**
2291 * Sets the {@link TextClassifier} for this WebView.
Tima Vaisburd2240ea62017-04-26 21:59:12 -07002292 * @hide
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002293 */
2294 public void setTextClassifier(@Nullable TextClassifier textClassifier) {
2295 mProvider.setTextClassifier(textClassifier);
2296 }
2297
2298 /**
2299 * Returns the {@link TextClassifier} used by this WebView.
2300 * If no TextClassifier has been set, this WebView uses the default set by the system.
Tima Vaisburd2240ea62017-04-26 21:59:12 -07002301 * @hide
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002302 */
2303 @NonNull
2304 public TextClassifier getTextClassifier() {
2305 return mProvider.getTextClassifier();
2306 }
2307
Jonathan Dixon3c909522012-02-28 18:45:06 +00002308 //-------------------------------------------------------------------------
2309 // Interface for WebView providers
2310 //-------------------------------------------------------------------------
2311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 /**
Steve Block4e584df2012-04-24 23:12:47 +01002313 * Gets the WebViewProvider. Used by providers to obtain the underlying
Nate Fischerffb81c42016-09-26 12:35:47 -07002314 * implementation, e.g. when the application responds to
Steve Block4e584df2012-04-24 23:12:47 +01002315 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04002316 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00002317 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04002318 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002319 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002320 public WebViewProvider getWebViewProvider() {
2321 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04002322 }
2323
2324 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002325 * Callback interface, allows the provider implementation to access non-public methods
2326 * and fields, and make super-class calls in this WebView instance.
2327 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002328 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002329 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002330 public class PrivateAccess {
2331 // ---- Access to super-class methods ----
2332 public int super_getScrollBarStyle() {
2333 return WebView.super.getScrollBarStyle();
2334 }
2335
2336 public void super_scrollTo(int scrollX, int scrollY) {
2337 WebView.super.scrollTo(scrollX, scrollY);
2338 }
2339
2340 public void super_computeScroll() {
2341 WebView.super.computeScroll();
2342 }
2343
alanveebebc92012-06-15 18:59:11 -07002344 public boolean super_onHoverEvent(MotionEvent event) {
2345 return WebView.super.onHoverEvent(event);
2346 }
2347
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002348 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
Alan Viverettea54956a2015-01-07 16:05:02 -08002349 return WebView.super.performAccessibilityActionInternal(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002350 }
2351
Jonathan Dixon3c909522012-02-28 18:45:06 +00002352 public boolean super_performLongClick() {
2353 return WebView.super.performLongClick();
2354 }
2355
2356 public boolean super_setFrame(int left, int top, int right, int bottom) {
2357 return WebView.super.setFrame(left, top, right, bottom);
2358 }
2359
2360 public boolean super_dispatchKeyEvent(KeyEvent event) {
2361 return WebView.super.dispatchKeyEvent(event);
2362 }
2363
2364 public boolean super_onGenericMotionEvent(MotionEvent event) {
2365 return WebView.super.onGenericMotionEvent(event);
2366 }
2367
2368 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
2369 return WebView.super.requestFocus(direction, previouslyFocusedRect);
2370 }
2371
2372 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
2373 WebView.super.setLayoutParams(params);
2374 }
2375
Hui Shuf119c522015-10-08 10:07:13 -07002376 public void super_startActivityForResult(Intent intent, int requestCode) {
2377 WebView.super.startActivityForResult(intent, requestCode);
2378 }
2379
Jonathan Dixon3c909522012-02-28 18:45:06 +00002380 // ---- Access to non-public methods ----
2381 public void overScrollBy(int deltaX, int deltaY,
2382 int scrollX, int scrollY,
2383 int scrollRangeX, int scrollRangeY,
2384 int maxOverScrollX, int maxOverScrollY,
2385 boolean isTouchEvent) {
2386 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
2387 maxOverScrollX, maxOverScrollY, isTouchEvent);
2388 }
2389
2390 public void awakenScrollBars(int duration) {
2391 WebView.this.awakenScrollBars(duration);
2392 }
2393
2394 public void awakenScrollBars(int duration, boolean invalidate) {
2395 WebView.this.awakenScrollBars(duration, invalidate);
2396 }
2397
2398 public float getVerticalScrollFactor() {
2399 return WebView.this.getVerticalScrollFactor();
2400 }
2401
2402 public float getHorizontalScrollFactor() {
2403 return WebView.this.getHorizontalScrollFactor();
2404 }
2405
2406 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
2407 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
2408 }
2409
2410 public void onScrollChanged(int l, int t, int oldl, int oldt) {
2411 WebView.this.onScrollChanged(l, t, oldl, oldt);
2412 }
2413
2414 public int getHorizontalScrollbarHeight() {
2415 return WebView.this.getHorizontalScrollbarHeight();
2416 }
2417
Martin Kosiba9a68f822013-08-08 14:02:41 +01002418 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2419 int l, int t, int r, int b) {
2420 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2421 }
2422
Jonathan Dixon3c909522012-02-28 18:45:06 +00002423 // ---- Access to (non-public) fields ----
2424 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
2425 public void setScrollXRaw(int scrollX) {
2426 WebView.this.mScrollX = scrollX;
2427 }
2428
2429 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
2430 public void setScrollYRaw(int scrollY) {
2431 WebView.this.mScrollY = scrollY;
2432 }
2433
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002434 }
2435
Jonathan Dixon3c909522012-02-28 18:45:06 +00002436 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002437 // Package-private internal stuff
2438 //-------------------------------------------------------------------------
2439
2440 // Only used by android.webkit.FindActionModeCallback.
2441 void setFindDialogFindListener(FindListener listener) {
2442 checkThread();
2443 setupFindListenerIfNeeded();
2444 mFindListener.mFindDialogFindListener = listener;
2445 }
2446
2447 // Only used by android.webkit.FindActionModeCallback.
2448 void notifyFindDialogDismissed() {
2449 checkThread();
2450 mProvider.notifyFindDialogDismissed();
2451 }
2452
2453 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002454 // Private internal stuff
2455 //-------------------------------------------------------------------------
2456
Jonathan Dixon3c909522012-02-28 18:45:06 +00002457 private WebViewProvider mProvider;
2458
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002459 /**
2460 * In addition to the FindListener that the user may set via the WebView.setFindListener
2461 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
Mark Dolinerd0646dc2014-08-27 16:04:02 -07002462 * via this class so that the two FindListeners can potentially exist at once.
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002463 */
2464 private class FindListenerDistributor implements FindListener {
2465 private FindListener mFindDialogFindListener;
2466 private FindListener mUserFindListener;
2467
2468 @Override
2469 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2470 boolean isDoneCounting) {
2471 if (mFindDialogFindListener != null) {
2472 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2473 isDoneCounting);
2474 }
2475
2476 if (mUserFindListener != null) {
2477 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2478 isDoneCounting);
2479 }
2480 }
2481 }
2482 private FindListenerDistributor mFindListener;
2483
2484 private void setupFindListenerIfNeeded() {
2485 if (mFindListener == null) {
2486 mFindListener = new FindListenerDistributor();
2487 mProvider.setFindListener(mFindListener);
2488 }
2489 }
2490
Jonathan Dixon3c909522012-02-28 18:45:06 +00002491 private void ensureProviderCreated() {
2492 checkThread();
2493 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002494 // As this can get called during the base class constructor chain, pass the minimum
2495 // number of dependencies here; the rest are deferred to init().
2496 mProvider = getFactory().createWebView(this, new PrivateAccess());
2497 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002498 }
2499
Torne (Richard Coles)59375a02016-07-18 18:34:02 +01002500 private static WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002501 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002502 }
2503
Jonathan Dixon517771b2013-10-08 13:32:11 -07002504 private final Looper mWebViewThread = Looper.myLooper();
2505
2506 private void checkThread() {
2507 // Ignore mWebViewThread == null because this can be called during in the super class
2508 // constructor, before this class's own constructor has even started.
2509 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002510 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002511 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002512 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002513 "All WebView methods must be called on the same thread. " +
2514 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2515 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002516 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2517 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002518
2519 if (sEnforceThreadChecking) {
2520 throw new RuntimeException(throwable);
2521 }
Steve Block51b08912011-04-27 15:04:48 +01002522 }
2523 }
2524
Jonathan Dixon3c909522012-02-28 18:45:06 +00002525 //-------------------------------------------------------------------------
2526 // Override View methods
2527 //-------------------------------------------------------------------------
2528
2529 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2530 // there's a corresponding override (or better, caller) for each of them in here.
2531
2532 @Override
2533 protected void onAttachedToWindow() {
2534 super.onAttachedToWindow();
2535 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002536 }
2537
John Reck34dbce12014-03-06 12:52:24 -08002538 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002539 @Override
John Reck34dbce12014-03-06 12:52:24 -08002540 protected void onDetachedFromWindowInternal() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002541 mProvider.getViewDelegate().onDetachedFromWindow();
John Reck34dbce12014-03-06 12:52:24 -08002542 super.onDetachedFromWindowInternal();
Chris Craik555c55e2011-07-28 15:39:43 -07002543 }
2544
Tima Vaisburd5544f6c2017-04-27 10:53:27 -07002545 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002546 @Override
Tima Vaisburd134752b2017-04-06 15:50:05 -07002547 public void onMovedToDisplay(int displayId, Configuration config) {
2548 mProvider.getViewDelegate().onMovedToDisplay(displayId, config);
2549 }
2550
2551 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002552 public void setLayoutParams(ViewGroup.LayoutParams params) {
2553 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002554 }
2555
Jonathan Dixon3c909522012-02-28 18:45:06 +00002556 @Override
2557 public void setOverScrollMode(int mode) {
2558 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002559 // This method may be called in the constructor chain, before the WebView provider is
2560 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002561 ensureProviderCreated();
2562 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002563 }
2564
Jonathan Dixon3c909522012-02-28 18:45:06 +00002565 @Override
2566 public void setScrollBarStyle(int style) {
2567 mProvider.getViewDelegate().setScrollBarStyle(style);
2568 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002569 }
2570
Jonathan Dixon3c909522012-02-28 18:45:06 +00002571 @Override
2572 protected int computeHorizontalScrollRange() {
2573 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002574 }
2575
Jonathan Dixon3c909522012-02-28 18:45:06 +00002576 @Override
2577 protected int computeHorizontalScrollOffset() {
2578 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2579 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002580
Jonathan Dixon3c909522012-02-28 18:45:06 +00002581 @Override
2582 protected int computeVerticalScrollRange() {
2583 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2584 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002585
Jonathan Dixon3c909522012-02-28 18:45:06 +00002586 @Override
2587 protected int computeVerticalScrollOffset() {
2588 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2589 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002590
Jonathan Dixon3c909522012-02-28 18:45:06 +00002591 @Override
2592 protected int computeVerticalScrollExtent() {
2593 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2594 }
2595
2596 @Override
2597 public void computeScroll() {
2598 mProvider.getScrollDelegate().computeScroll();
2599 }
2600
2601 @Override
2602 public boolean onHoverEvent(MotionEvent event) {
2603 return mProvider.getViewDelegate().onHoverEvent(event);
2604 }
2605
2606 @Override
2607 public boolean onTouchEvent(MotionEvent event) {
2608 return mProvider.getViewDelegate().onTouchEvent(event);
2609 }
2610
2611 @Override
2612 public boolean onGenericMotionEvent(MotionEvent event) {
2613 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2614 }
2615
2616 @Override
2617 public boolean onTrackballEvent(MotionEvent event) {
2618 return mProvider.getViewDelegate().onTrackballEvent(event);
2619 }
2620
2621 @Override
2622 public boolean onKeyDown(int keyCode, KeyEvent event) {
2623 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2624 }
2625
2626 @Override
2627 public boolean onKeyUp(int keyCode, KeyEvent event) {
2628 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2629 }
2630
2631 @Override
2632 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2633 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2634 }
2635
2636 /*
2637 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2638 to be delegating them too.
2639
2640 @Override
2641 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2642 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2643 }
2644 @Override
2645 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2646 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2647 }
2648 @Override
2649 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2650 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2651 }
2652 */
2653
Ben Murdoche3f90712013-06-05 14:19:48 +01002654 @Override
2655 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2656 AccessibilityNodeProvider provider =
2657 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2658 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2659 }
2660
Jonathan Dixon3c909522012-02-28 18:45:06 +00002661 @Deprecated
2662 @Override
2663 public boolean shouldDelayChildPressedState() {
2664 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2665 }
2666
Felipe Leme1ca634a2016-11-28 17:21:21 -08002667 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -08002668 public CharSequence getAccessibilityClassName() {
2669 return WebView.class.getName();
2670 }
2671
Selim Gurun1b650cb2015-04-06 20:13:37 -07002672 @Override
Dianne Hackborn49b043f2015-05-07 14:21:38 -07002673 public void onProvideVirtualStructure(ViewStructure structure) {
Selim Gurun50b26a52015-06-01 16:26:10 -07002674 mProvider.getViewDelegate().onProvideVirtualStructure(structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -07002675 }
2676
Felipe Leme1a1e4682017-03-13 16:34:03 -07002677 /**
2678 * {@inheritDoc}
2679 *
2680 * <p>The {@link ViewStructure} traditionally represents a {@link View}, while for web pages
2681 * it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is
2682 * understood by the {@link android.service.autofill.AutofillService} implementations:
2683 *
2684 * <ol>
Felipe Leme25bf7872017-03-28 15:32:29 -07002685 * <li>If the Android SDK provides a similar View, then should be set with the
2686 * fully-qualified class name of such view.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002687 * <li>The W3C autofill field ({@code autocomplete} tag attribute) maps to
Philip P. Moltmann81192b42017-03-29 13:58:59 -07002688 * {@link ViewStructure#setAutofillHints(String[])}.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002689 * <li>The {@code type} attribute of {@code INPUT} tags maps to
2690 * {@link ViewStructure#setInputType(int)}.
Felipe Leme6dcec872017-05-25 11:24:23 -07002691 * <li>The {@code value} attribute of {@code INPUT} tags maps to
2692 * {@link ViewStructure#setText(CharSequence)}.
2693 * <li>If the view is editalbe, the {@link ViewStructure#setAutofillType(int)} and
2694 * {@link ViewStructure#setAutofillValue(AutofillValue)} must be set.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002695 * <li>The {@code placeholder} attribute maps to {@link ViewStructure#setHint(CharSequence)}.
Felipe Leme25bf7872017-03-28 15:32:29 -07002696 * <li>Other HTML attributes can be represented through
2697 * {@link ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)}.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002698 * </ol>
2699 *
Felipe Leme6dcec872017-05-25 11:24:23 -07002700 * <p>It should also call {@code structure.setDataIsSensitive(false)} for fields whose value
2701 * were not dynamically changed (for example, through Javascript).
2702 *
Felipe Leme1a1e4682017-03-13 16:34:03 -07002703 * <p>Example1: an HTML form with 2 fields for username and password.
2704 *
2705 * <pre class="prettyprint">
Felipe Leme6dcec872017-05-25 11:24:23 -07002706 * &lt;input type="text" name="username" id="user" value="Type your username" autocomplete="username" placeholder="Email or username"&gt;
2707 * &lt;input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"&gt;
Felipe Leme1a1e4682017-03-13 16:34:03 -07002708 * </pre>
2709 *
2710 * <p>Would map to:
2711 *
2712 * <pre class="prettyprint">
Felipe Leme25bf7872017-03-28 15:32:29 -07002713 * int index = structure.addChildCount(2);
2714 * ViewStructure username = structure.newChild(index);
Felipe Leme6dcec872017-05-25 11:24:23 -07002715 * username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002716 * username.setClassName("input");
2717 * username.setInputType("android.widget.EditText");
2718 * username.setAutofillHints("username");
Felipe Leme6dcec872017-05-25 11:24:23 -07002719 * username.setHtmlInfo(username.newHtmlInfoBuilder("input")
2720 * .addAttribute("type", "text")
Felipe Leme25bf7872017-03-28 15:32:29 -07002721 * .addAttribute("name", "username")
2722 * .addAttribute("id", "user")
2723 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002724 * username.setHint("Email or username");
2725 * username.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme6dcec872017-05-25 11:24:23 -07002726 * username.setAutofillValue(AutofillValue.forText("Type your username"));
2727 * username.setText("Type your username");
2728 * // Value of the field is not sensitive because it was not dynamically changed:
2729 * username.setDataIsSensitive(false);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002730 *
Felipe Leme25bf7872017-03-28 15:32:29 -07002731 * ViewStructure password = structure.newChild(index + 1);
2732 * username.setAutofillId(structure, 2); // id 2 - second child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002733 * password.setInputType("android.widget.EditText");
2734 * password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
2735 * password.setAutofillHints("current-password");
Felipe Leme6dcec872017-05-25 11:24:23 -07002736 * password.setHtmlInfo(password.newHtmlInfoBuilder("input")
2737 * .addAttribute("type", "password")
Felipe Leme25bf7872017-03-28 15:32:29 -07002738 * .addAttribute("name", "password")
2739 * .addAttribute("id", "pass")
2740 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002741 * password.setHint("Password");
2742 * password.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002743 * </pre>
2744 *
2745 * <p>Example2: an IFRAME tag.
2746 *
2747 * <pre class="prettyprint">
Felipe Leme6dcec872017-05-25 11:24:23 -07002748 * &lt;iframe src="https://example.com/login"/&gt;
Felipe Leme1a1e4682017-03-13 16:34:03 -07002749 * </pre>
2750 *
2751 * <p>Would map to:
2752 *
2753 * <pre class="prettyprint">
Felipe Leme25bf7872017-03-28 15:32:29 -07002754 * int index = structure.addChildCount(1);
2755 * ViewStructure iframe = structure.newChildFor(index);
Felipe Leme6dcec872017-05-25 11:24:23 -07002756 * iframe.setAutofillId(structure.getAutofillId(), 1);
2757 * iframe.setHtmlInfo(iframe.newHtmlInfoBuilder("iframe")
2758 * .addAttribute("src", "https://example.com/login")
Felipe Leme25bf7872017-03-28 15:32:29 -07002759 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002760 * </pre>
2761 */
Felipe Leme1ca634a2016-11-28 17:21:21 -08002762 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08002763 public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
2764 mProvider.getViewDelegate().onProvideAutofillVirtualStructure(structure, flags);
Felipe Leme1ca634a2016-11-28 17:21:21 -08002765 }
2766
Tao Baia5717332017-03-30 14:58:53 -07002767 @Override
2768 public void autofill(SparseArray<AutofillValue>values) {
2769 mProvider.getViewDelegate().autofill(values);
2770 }
2771
Alan Viverettea54956a2015-01-07 16:05:02 -08002772 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002773 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002774 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2775 super.onInitializeAccessibilityNodeInfoInternal(info);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002776 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002777 }
2778
Alan Viverettea54956a2015-01-07 16:05:02 -08002779 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002780 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002781 public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
2782 super.onInitializeAccessibilityEventInternal(event);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002783 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002784 }
2785
Alan Viverettea54956a2015-01-07 16:05:02 -08002786 /** @hide */
alanv448902d2012-05-16 20:27:47 -07002787 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002788 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002789 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002790 }
2791
Jonathan Dixon3c909522012-02-28 18:45:06 +00002792 /** @hide */
2793 @Override
2794 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2795 int l, int t, int r, int b) {
2796 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2797 }
2798
2799 @Override
2800 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2801 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2802 }
2803
2804 @Override
2805 protected void onWindowVisibilityChanged(int visibility) {
2806 super.onWindowVisibilityChanged(visibility);
2807 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2808 }
2809
2810 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002811 protected void onDraw(Canvas canvas) {
2812 mProvider.getViewDelegate().onDraw(canvas);
2813 }
2814
2815 @Override
2816 public boolean performLongClick() {
2817 return mProvider.getViewDelegate().performLongClick();
2818 }
2819
2820 @Override
2821 protected void onConfigurationChanged(Configuration newConfig) {
2822 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2823 }
2824
Selim Gurunc92080b2016-10-20 11:53:14 -07002825 /**
2826 * Creates a new InputConnection for an InputMethod to interact with the WebView.
2827 * This is similar to {@link View#onCreateInputConnection} but note that WebView
2828 * calls InputConnection methods on a thread other than the UI thread.
2829 * If these methods are overridden, then the overriding methods should respect
2830 * thread restrictions when calling View methods or accessing data.
2831 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002832 @Override
2833 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2834 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2835 }
2836
2837 @Override
Hui Shuecdce962016-02-04 15:00:19 -08002838 public boolean onDragEvent(DragEvent event) {
2839 return mProvider.getViewDelegate().onDragEvent(event);
2840 }
2841
2842 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002843 protected void onVisibilityChanged(View changedView, int visibility) {
2844 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002845 // This method may be called in the constructor chain, before the WebView provider is
2846 // created.
2847 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002848 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2849 }
2850
2851 @Override
2852 public void onWindowFocusChanged(boolean hasWindowFocus) {
2853 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2854 super.onWindowFocusChanged(hasWindowFocus);
2855 }
2856
2857 @Override
2858 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2859 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2860 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2861 }
2862
2863 /** @hide */
2864 @Override
2865 protected boolean setFrame(int left, int top, int right, int bottom) {
2866 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2867 }
2868
2869 @Override
2870 protected void onSizeChanged(int w, int h, int ow, int oh) {
2871 super.onSizeChanged(w, h, ow, oh);
2872 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2873 }
2874
2875 @Override
2876 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2877 super.onScrollChanged(l, t, oldl, oldt);
2878 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2879 }
2880
2881 @Override
2882 public boolean dispatchKeyEvent(KeyEvent event) {
2883 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2884 }
2885
2886 @Override
2887 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2888 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2889 }
2890
Jonathan Dixon3c909522012-02-28 18:45:06 +00002891 @Override
2892 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2893 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2894 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2895 }
2896
2897 @Override
2898 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2899 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2900 }
2901
2902 @Override
2903 public void setBackgroundColor(int color) {
2904 mProvider.getViewDelegate().setBackgroundColor(color);
2905 }
John Recka5408e62012-03-16 14:18:44 -07002906
2907 @Override
2908 public void setLayerType(int layerType, Paint paint) {
2909 super.setLayerType(layerType, paint);
2910 mProvider.getViewDelegate().setLayerType(layerType, paint);
2911 }
Ben Murdoche623e242012-09-07 20:47:07 +01002912
2913 @Override
2914 protected void dispatchDraw(Canvas canvas) {
2915 mProvider.getViewDelegate().preDispatchDraw(canvas);
2916 super.dispatchDraw(canvas);
2917 }
Ben Murdoch7302f4f2014-07-03 14:47:44 +01002918
2919 @Override
2920 public void onStartTemporaryDetach() {
2921 super.onStartTemporaryDetach();
2922 mProvider.getViewDelegate().onStartTemporaryDetach();
2923 }
2924
2925 @Override
2926 public void onFinishTemporaryDetach() {
2927 super.onFinishTemporaryDetach();
2928 mProvider.getViewDelegate().onFinishTemporaryDetach();
2929 }
Siva Velusamy94a6d152015-05-05 15:07:00 -07002930
Selim Gurune319dad2016-03-17 01:40:40 +00002931 @Override
2932 public Handler getHandler() {
2933 return mProvider.getViewDelegate().getHandler(super.getHandler());
2934 }
2935
2936 @Override
2937 public View findFocus() {
2938 return mProvider.getViewDelegate().findFocus(super.findFocus());
2939 }
2940
Hui Shuf119c522015-10-08 10:07:13 -07002941 /**
Gustav Senntonbf683e02016-09-15 14:42:50 +01002942 * If WebView has already been loaded into the current process this method will return the
2943 * package that was used to load it. Otherwise, the package that would be used if the WebView
2944 * was loaded right now will be returned; this does not cause WebView to be loaded, so this
2945 * information may become outdated at any time.
Gustav Sennton4cbfe712017-03-07 14:22:01 +00002946 * The WebView package changes either when the current WebView package is updated, disabled, or
2947 * uninstalled. It can also be changed through a Developer Setting.
2948 * If the WebView package changes, any app process that has loaded WebView will be killed. The
2949 * next time the app starts and loads WebView it will use the new WebView package instead.
Gustav Senntonbf683e02016-09-15 14:42:50 +01002950 * @return the current WebView package, or null if there is none.
2951 */
2952 public static PackageInfo getCurrentWebViewPackage() {
2953 PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
2954 if (webviewPackage != null) {
2955 return webviewPackage;
2956 }
2957
2958 try {
2959 return WebViewFactory.getUpdateService().getCurrentWebViewPackage();
2960 } catch (RemoteException e) {
2961 throw e.rethrowFromSystemServer();
2962 }
2963 }
2964
2965 /**
Hui Shuf119c522015-10-08 10:07:13 -07002966 * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
2967 *
2968 * @param requestCode The integer request code originally supplied to
2969 * startActivityForResult(), allowing you to identify who this
2970 * result came from.
2971 * @param resultCode The integer result code returned by the child activity
2972 * through its setResult().
2973 * @param data An Intent, which can return result data to the caller
2974 * (various data can be attached to Intent "extras").
2975 * @hide
2976 */
2977 @Override
2978 public void onActivityResult(int requestCode, int resultCode, Intent data) {
2979 mProvider.getViewDelegate().onActivityResult(requestCode, resultCode, data);
2980 }
2981
Siva Velusamy94a6d152015-05-05 15:07:00 -07002982 /** @hide */
2983 @Override
2984 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
2985 super.encodeProperties(encoder);
2986
2987 checkThread();
2988 encoder.addProperty("webview:contentHeight", mProvider.getContentHeight());
2989 encoder.addProperty("webview:contentWidth", mProvider.getContentWidth());
2990 encoder.addProperty("webview:scale", mProvider.getScale());
2991 encoder.addProperty("webview:title", mProvider.getTitle());
2992 encoder.addProperty("webview:url", mProvider.getUrl());
2993 encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl());
2994 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995}