blob: deb94e816a69d5f7f5886bc6a8003fe0bd1ca7ff [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
Nate Fischerf02f8462017-09-11 15:16:33 -070078 * through a history, zoom in and out, perform text searches and more.
79 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 * <p>Note that, in order for your Activity to access the Internet and load web pages
Scott Main8b3cea02010-05-14 14:12:43 -070081 * in a WebView, you must add the {@code INTERNET} permissions to your
Nate Fischerf02f8462017-09-11 15:16:33 -070082 * Android Manifest file:
83 *
84 * <pre>
85 * {@code <uses-permission android:name="android.permission.INTERNET" />}
86 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +010087 *
Scott Main8b3cea02010-05-14 14:12:43 -070088 * <p>This must be a child of the <a
Ben Dodson4e8620f2010-08-25 10:55:47 -070089 * href="{@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
Nate Fischerf02f8462017-09-11 15:16:33 -070090 * element.
Mike Hearnadcd2ed2009-01-21 16:44:36 +010091 *
Scott Main4c359b72012-07-24 15:51:27 -070092 * <p>For more information, read
Nate Fischerf02f8462017-09-11 15:16:33 -070093 * <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in WebView</a>.
Scott Main41ec6532010-08-19 16:57:07 -070094 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010095 * <h3>Basic usage</h3>
96 *
97 * <p>By default, a WebView provides no browser-like widgets, does not
Scott Main8b3cea02010-05-14 14:12:43 -070098 * enable JavaScript and web page errors are ignored. If your goal is only
Mike Hearnadcd2ed2009-01-21 16:44:36 +010099 * to display some HTML as a part of your UI, this is probably fine;
100 * the user won't need to interact with the web page beyond reading
101 * it, and the web page won't need to interact with the user. If you
Scott Main8b3cea02010-05-14 14:12:43 -0700102 * actually want a full-blown web browser, then you probably want to
103 * invoke the Browser application with a URL Intent rather than show it
104 * with a WebView. For example:
105 * <pre>
Andrew Solovay51142572017-05-05 16:55:43 -0700106 * Uri uri = Uri.parse("https://www.example.com");
Scott Main8b3cea02010-05-14 14:12:43 -0700107 * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
108 * startActivity(intent);
109 * </pre>
Nate Fischerf02f8462017-09-11 15:16:33 -0700110 * <p>See {@link android.content.Intent} for more information.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100111 *
Neil Fuller71fbb812015-11-30 09:51:33 +0000112 * <p>To provide a WebView in your own Activity, include a {@code <WebView>} in your layout,
Scott Main8b3cea02010-05-14 14:12:43 -0700113 * or set the entire Activity window as a WebView during {@link
Nate Fischerf02f8462017-09-11 15:16:33 -0700114 * android.app.Activity#onCreate(Bundle) onCreate()}:
115 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100116 * <pre class="prettyprint">
117 * WebView webview = new WebView(this);
118 * setContentView(webview);
Scott Main8b3cea02010-05-14 14:12:43 -0700119 * </pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100120 *
Nate Fischerf02f8462017-09-11 15:16:33 -0700121 * <p>Then load the desired web page:
122 *
Scott Maine3b9f8b2010-05-18 08:41:36 -0700123 * <pre>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100124 * // Simplest usage: note that an exception will NOT be thrown
125 * // if there is an error loading this page (see below).
Andrew Solovay51142572017-05-05 16:55:43 -0700126 * webview.loadUrl("https://example.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100127 *
Scott Main8b3cea02010-05-14 14:12:43 -0700128 * // OR, you can also load from an HTML string:
Scott Maine3b9f8b2010-05-18 08:41:36 -0700129 * 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 +0100130 * webview.loadData(summary, "text/html", null);
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100131 * // ... although note that there are restrictions on what this HTML can do.
Nate Fischer867d1092018-01-04 21:57:33 -0800132 * // See {@link #loadData(String,String,String)} and {@link
133 * #loadDataWithBaseURL(String,String,String,String,String)} for more info.
134 * // Also see {@link #loadData(String,String,String)} for information on encoding special
135 * // characters.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100136 * </pre>
137 *
138 * <p>A WebView has several customization points where you can add your
Nate Fischerf02f8462017-09-11 15:16:33 -0700139 * own behavior. These are:
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100140 *
141 * <ul>
142 * <li>Creating and setting a {@link android.webkit.WebChromeClient} subclass.
143 * This class is called when something that might impact a
144 * browser UI happens, for instance, progress updates and
Scott Main8b3cea02010-05-14 14:12:43 -0700145 * JavaScript alerts are sent here (see <a
146 * href="{@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging Tasks</a>).
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100147 * </li>
148 * <li>Creating and setting a {@link android.webkit.WebViewClient} subclass.
149 * It will be called when things happen that impact the
150 * rendering of the content, eg, errors or form submissions. You
Scott Main8b3cea02010-05-14 14:12:43 -0700151 * can also intercept URL loading here (via {@link
152 * android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String)
153 * shouldOverrideUrlLoading()}).</li>
154 * <li>Modifying the {@link android.webkit.WebSettings}, such as
155 * enabling JavaScript with {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
156 * setJavaScriptEnabled()}. </li>
Steve Block4cd73c52011-11-09 13:06:52 +0000157 * <li>Injecting Java objects into the WebView using the
158 * {@link android.webkit.WebView#addJavascriptInterface} method. This
159 * method allows you to inject Java objects into a page's JavaScript
160 * context, so that they can be accessed by JavaScript in the page.</li>
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100161 * </ul>
162 *
163 * <p>Here's a more complicated example, showing error handling,
Nate Fischerf02f8462017-09-11 15:16:33 -0700164 * settings, and progress notification:
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100165 *
166 * <pre class="prettyprint">
167 * // Let's display the progress in the activity title bar, like the
168 * // browser app does.
169 * getWindow().requestFeature(Window.FEATURE_PROGRESS);
170 *
171 * webview.getSettings().setJavaScriptEnabled(true);
172 *
173 * final Activity activity = this;
174 * webview.setWebChromeClient(new WebChromeClient() {
175 * public void onProgressChanged(WebView view, int progress) {
176 * // Activities and WebViews measure progress with different scales.
177 * // The progress meter will automatically disappear when we reach 100%
178 * activity.setProgress(progress * 1000);
179 * }
180 * });
181 * webview.setWebViewClient(new WebViewClient() {
182 * public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
183 * Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
184 * }
185 * });
186 *
Andrew Solovay51142572017-05-05 16:55:43 -0700187 * webview.loadUrl("https://developer.android.com/");
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100188 * </pre>
189 *
Martin Kosiba0d147d92013-09-19 19:05:00 -0700190 * <h3>Zoom</h3>
191 *
192 * <p>To enable the built-in zoom, set
193 * {@link #getSettings() WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)}
Nate Fischerf02f8462017-09-11 15:16:33 -0700194 * (introduced in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}).
195 *
Nate Fischer7051dd12017-10-26 14:51:25 -0700196 * <p class="note"><b>Note:</b> Using zoom if either the height or width is set to
Martin Kosiba0d147d92013-09-19 19:05:00 -0700197 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} may lead to undefined behavior
Nate Fischerf02f8462017-09-11 15:16:33 -0700198 * and should be avoided.
Martin Kosiba0d147d92013-09-19 19:05:00 -0700199 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100200 * <h3>Cookie and window management</h3>
201 *
202 * <p>For obvious security reasons, your application has its own
Scott Main8b3cea02010-05-14 14:12:43 -0700203 * cache, cookie store etc.&mdash;it does not share the Browser
Steve Blockc723e352012-08-14 14:48:05 +0100204 * application's data.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100205 *
206 * <p>By default, requests by the HTML to open new windows are
Nate Fischer0a6140d2017-09-05 12:37:49 -0700207 * ignored. This is {@code true} whether they be opened by JavaScript or by
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100208 * the target attribute on a link. You can customize your
Nate Fischerffb81c42016-09-26 12:35:47 -0700209 * {@link WebChromeClient} to provide your own behavior for opening multiple windows,
Nate Fischerf02f8462017-09-11 15:16:33 -0700210 * and render them in whatever manner you want.
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100211 *
Scott Main8b3cea02010-05-14 14:12:43 -0700212 * <p>The standard behavior for an Activity is to be destroyed and
213 * recreated when the device orientation or any other configuration changes. This will cause
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100214 * the WebView to reload the current page. If you don't want that, you
Scott Main8b3cea02010-05-14 14:12:43 -0700215 * can set your Activity to handle the {@code orientation} and {@code keyboardHidden}
Mike Hearnadcd2ed2009-01-21 16:44:36 +0100216 * changes, and then just leave the WebView alone. It'll automatically
Scott Main8b3cea02010-05-14 14:12:43 -0700217 * re-orient itself as appropriate. Read <a
218 * href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for
Nate Fischerf02f8462017-09-11 15:16:33 -0700219 * more information about how to handle configuration changes during runtime.
Scott Main8b3cea02010-05-14 14:12:43 -0700220 *
221 *
222 * <h3>Building web pages to support different screen densities</h3>
223 *
224 * <p>The screen density of a device is based on the screen resolution. A screen with low density
225 * has fewer available pixels per inch, where a screen with high density
Brad Fitzpatrick438d0592010-06-10 12:19:19 -0700226 * has more &mdash; sometimes significantly more &mdash; pixels per inch. The density of a
Scott Main8b3cea02010-05-14 14:12:43 -0700227 * screen is important because, other things being equal, a UI element (such as a button) whose
228 * height and width are defined in terms of screen pixels will appear larger on the lower density
229 * screen and smaller on the higher density screen.
230 * For simplicity, Android collapses all actual screen densities into three generalized densities:
Nate Fischerf02f8462017-09-11 15:16:33 -0700231 * high, medium, and low.
Scott Main8b3cea02010-05-14 14:12:43 -0700232 * <p>By default, WebView scales a web page so that it is drawn at a size that matches the default
233 * appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen
234 * (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels
235 * are bigger).
Steve Blockb838aef2012-04-23 18:22:15 +0100236 * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, WebView supports DOM, CSS,
237 * and meta tag features to help you (as a web developer) target screens with different screen
Nate Fischerf02f8462017-09-11 15:16:33 -0700238 * densities.
239 * <p>Here's a summary of the features you can use to handle different screen densities:
Scott Main8b3cea02010-05-14 14:12:43 -0700240 * <ul>
241 * <li>The {@code window.devicePixelRatio} DOM property. The value of this property specifies the
242 * default scaling factor used for the current device. For example, if the value of {@code
243 * window.devicePixelRatio} is "1.0", then the device is considered a medium density (mdpi) device
244 * and default scaling is not applied to the web page; if the value is "1.5", then the device is
245 * considered a high density device (hdpi) and the page content is scaled 1.5x; if the
246 * 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 -0800247 * scaled 0.75x.</li>
Scott Main8b3cea02010-05-14 14:12:43 -0700248 * <li>The {@code -webkit-device-pixel-ratio} CSS media query. Use this to specify the screen
249 * densities for which this style sheet is to be used. The corresponding value should be either
250 * "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium
251 * density, or high density screens, respectively. For example:
252 * <pre>
253 * &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;</pre>
254 * <p>The {@code hdpi.css} stylesheet is only used for devices with a screen pixel ration of 1.5,
Nate Fischerf02f8462017-09-11 15:16:33 -0700255 * which is the high density pixel ratio.
Scott Main8b3cea02010-05-14 14:12:43 -0700256 * </li>
Martin Kosiba0d147d92013-09-19 19:05:00 -0700257 * </ul>
Scott Main8b3cea02010-05-14 14:12:43 -0700258 *
Teng-Hui Zhu50ba5a22012-01-11 15:57:21 -0800259 * <h3>HTML5 Video support</h3>
260 *
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000261 * <p>In order to support inline HTML5 video in your application you need to have hardware
262 * acceleration turned on.
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000263 *
264 * <h3>Full screen support</h3>
265 *
266 * <p>In order to support full screen &mdash; for video or other HTML content &mdash; you need to set a
267 * {@link android.webkit.WebChromeClient} and implement both
268 * {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)}
269 * and {@link WebChromeClient#onHideCustomView()}. If the implementation of either of these two methods is
270 * missing then the web contents will not be allowed to enter full screen. Optionally you can implement
271 * {@link WebChromeClient#getVideoLoadingProgressView()} to customize the View displayed whilst a video
272 * is loading.
Marcin Kosiba84644f12014-09-08 18:37:36 +0100273 *
Tim Volodineb0e97982016-04-27 14:14:09 +0100274 * <h3>HTML5 Geolocation API support</h3>
275 *
276 * <p>For applications targeting Android N and later releases
277 * (API level > {@link android.os.Build.VERSION_CODES#M}) the geolocation api is only supported on
278 * secure origins such as https. For such applications requests to geolocation api on non-secure
279 * origins are automatically denied without invoking the corresponding
280 * {@link WebChromeClient#onGeolocationPermissionsShowPrompt(String, GeolocationPermissions.Callback)}
281 * method.
Tim Volodineb0e97982016-04-27 14:14:09 +0100282 *
Marcin Kosiba84644f12014-09-08 18:37:36 +0100283 * <h3>Layout size</h3>
284 * <p>
285 * It is recommended to set the WebView layout height to a fixed value or to
286 * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT} instead of using
287 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}.
288 * When using {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
289 * for the height none of the WebView's parents should use a
290 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} layout height since that could result in
291 * incorrect sizing of the views.
Marcin Kosiba84644f12014-09-08 18:37:36 +0100292 *
293 * <p>Setting the WebView's height to {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}
294 * enables the following behaviors:
295 * <ul>
296 * <li>The HTML body layout height is set to a fixed value. This means that elements with a height
297 * relative to the HTML body may not be sized correctly. </li>
Nate Fischerffb81c42016-09-26 12:35:47 -0700298 * <li>For applications targeting {@link android.os.Build.VERSION_CODES#KITKAT} and earlier SDKs the
Marcin Kosiba84644f12014-09-08 18:37:36 +0100299 * HTML viewport meta tag will be ignored in order to preserve backwards compatibility. </li>
300 * </ul>
Marcin Kosiba84644f12014-09-08 18:37:36 +0100301 *
302 * <p>
303 * Using a layout width of {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} is not
304 * supported. If such a width is used the WebView will attempt to use the width of the parent
305 * instead.
Marcin Kosiba84644f12014-09-08 18:37:36 +0100306 *
Paul Millera4692182016-01-07 11:32:15 -0800307 * <h3>Metrics</h3>
308 *
309 * <p>
310 * WebView may upload anonymous diagnostic data to Google when the user has consented. This data
311 * helps Google improve WebView. Data is collected on a per-app basis for each app which has
312 * instantiated a WebView. An individual app can opt out of this feature by putting the following
Nate Fischer20635082017-11-08 13:39:08 -0800313 * tag in its manifest's {@code <application>} element:
Paul Millera4692182016-01-07 11:32:15 -0800314 * <pre>
Nate Fischer20635082017-11-08 13:39:08 -0800315 * &lt;manifest&gt;
316 * &lt;application&gt;
317 * ...
318 * &lt;meta-data android:name=&quot;android.webkit.WebView.MetricsOptOut&quot;
319 * android:value=&quot;true&quot; /&gt;
320 * &lt;/application&gt;
321 * &lt;/manifest&gt;
Paul Millera4692182016-01-07 11:32:15 -0800322 * </pre>
323 * <p>
324 * Data will only be uploaded for a given app if the user has consented AND the app has not opted
325 * out.
Paul Millera4692182016-01-07 11:32:15 -0800326 *
Nate Fischer471891d2017-07-18 19:15:52 -0700327 * <h3>Safe Browsing</h3>
328 *
329 * <p>
330 * If Safe Browsing is enabled, WebView will block malicious URLs and present a warning UI to the
331 * user to allow them to navigate back safely or proceed to the malicious page.
Nate Fischer471891d2017-07-18 19:15:52 -0700332 * <p>
Nate Fischer20635082017-11-08 13:39:08 -0800333 * The recommended way for apps to enable the feature is putting the following tag in the manifest's
334 * {@code <application>} element:
Nate Fischer471891d2017-07-18 19:15:52 -0700335 * <p>
336 * <pre>
Nate Fischer20635082017-11-08 13:39:08 -0800337 * &lt;manifest&gt;
338 * &lt;application&gt;
339 * ...
340 * &lt;meta-data android:name=&quot;android.webkit.WebView.EnableSafeBrowsing&quot;
341 * android:value=&quot;true&quot; /&gt;
342 * &lt;/application&gt;
343 * &lt;/manifest&gt;
Nate Fischer471891d2017-07-18 19:15:52 -0700344 * </pre>
Nate Fischer471891d2017-07-18 19:15:52 -0700345 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 */
Steve Block406aeb22012-04-23 18:17:19 +0100347// Implementation notes.
348// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
349// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
350// Methods are delegated to the provider implementation: all public API methods introduced in this
351// file are fully delegated, whereas public and protected methods from the View base classes are
352// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800353@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400354public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700356 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700358 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700359
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700360 // Throwing an exception for incorrect thread usage if the
361 // build target is JB MR2 or newer. Defaults to false, and is
362 // set in the WebView constructor.
Jonathan Dixon0d6a1452013-08-21 13:09:36 -0700363 private static volatile boolean sEnforceThreadChecking = false;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 /**
366 * Transportation object for returning WebView across thread boundaries.
367 */
368 public class WebViewTransport {
369 private WebView mWebview;
370
371 /**
Steve Block4e584df2012-04-24 23:12:47 +0100372 * Sets the WebView to the transportation object.
373 *
374 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 */
376 public synchronized void setWebView(WebView webview) {
377 mWebview = webview;
378 }
379
380 /**
Steve Block4e584df2012-04-24 23:12:47 +0100381 * Gets the WebView object.
382 *
383 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 */
385 public synchronized WebView getWebView() {
386 return mWebview;
387 }
388 }
389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 /**
Steve Block4e584df2012-04-24 23:12:47 +0100391 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 */
393 public static final String SCHEME_TEL = "tel:";
394 /**
Steve Block4e584df2012-04-24 23:12:47 +0100395 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 */
397 public static final String SCHEME_MAILTO = "mailto:";
398 /**
Steve Block4e584df2012-04-24 23:12:47 +0100399 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 */
401 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 /**
Victoria Leased405a432012-03-22 15:53:48 -0700404 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700405 */
406 public interface FindListener {
407 /**
Steve Block4e584df2012-04-24 23:12:47 +0100408 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700409 *
Steve Block4e584df2012-04-24 23:12:47 +0100410 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700411 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100412 * @param isDoneCounting whether the find operation has actually completed. The listener
413 * may be notified multiple times while the
414 * operation is underway, and the numberOfMatches
415 * value should not be considered final unless
Nate Fischer0a6140d2017-09-05 12:37:49 -0700416 * isDoneCounting is {@code true}.
Victoria Leased405a432012-03-22 15:53:48 -0700417 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700418 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700419 boolean isDoneCounting);
420 }
421
422 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +0100423 * Callback interface supplied to {@link #postVisualStateCallback} for receiving
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000424 * notifications about the visual state.
425 */
426 public static abstract class VisualStateCallback {
427 /**
428 * Invoked when the visual state is ready to be drawn in the next {@link #onDraw}.
429 *
Tobias Sargeantb3656042015-05-13 11:23:57 +0100430 * @param requestId The identifier passed to {@link #postVisualStateCallback} when this
431 * callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000432 */
433 public abstract void onComplete(long requestId);
434 }
435
436 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100438 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100439 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100441 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 public interface PictureListener {
443 /**
Steve Block72498ed2012-07-17 15:57:25 +0100444 * Used to provide notification that the WebView's picture has changed.
445 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100446 *
447 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000448 * @param picture the new picture. Applications targeting
449 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
Nate Fischer0a6140d2017-09-05 12:37:49 -0700450 * will always receive a {@code null} Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100451 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100453 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700454 void onNewPicture(WebView view, @Nullable Picture picture);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 }
456
Jonathan Dixon19644b62011-12-21 14:21:36 +0000457 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 /**
Steve Block4e584df2012-04-24 23:12:47 +0100459 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 */
461 public static final int UNKNOWN_TYPE = 0;
462 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100463 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 */
Steve Block1854ddb2011-04-19 12:18:19 +0100465 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 public static final int ANCHOR_TYPE = 1;
467 /**
Steve Block4e584df2012-04-24 23:12:47 +0100468 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 */
470 public static final int PHONE_TYPE = 2;
471 /**
Steve Block4e584df2012-04-24 23:12:47 +0100472 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 */
474 public static final int GEO_TYPE = 3;
475 /**
Steve Block4e584df2012-04-24 23:12:47 +0100476 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 */
478 public static final int EMAIL_TYPE = 4;
479 /**
Steve Block4e584df2012-04-24 23:12:47 +0100480 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 */
482 public static final int IMAGE_TYPE = 5;
483 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100484 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 */
Steve Block1854ddb2011-04-19 12:18:19 +0100486 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 public static final int IMAGE_ANCHOR_TYPE = 6;
488 /**
Steve Block4e584df2012-04-24 23:12:47 +0100489 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 */
491 public static final int SRC_ANCHOR_TYPE = 7;
492 /**
Steve Block4e584df2012-04-24 23:12:47 +0100493 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 */
495 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
496 /**
Steve Block4e584df2012-04-24 23:12:47 +0100497 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 */
499 public static final int EDIT_TEXT_TYPE = 9;
500
501 private int mType;
502 private String mExtra;
503
Jonathan Dixon3c909522012-02-28 18:45:06 +0000504 /**
505 * @hide Only for use by WebViewProvider implementations
506 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000507 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000508 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 mType = UNKNOWN_TYPE;
510 }
511
Jonathan Dixon3c909522012-02-28 18:45:06 +0000512 /**
513 * @hide Only for use by WebViewProvider implementations
514 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000515 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000516 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 mType = type;
518 }
519
Jonathan Dixon3c909522012-02-28 18:45:06 +0000520 /**
521 * @hide Only for use by WebViewProvider implementations
522 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000523 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000524 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 mExtra = extra;
526 }
527
Jonathan Dixone230e542011-12-21 10:57:00 +0000528 /**
Steve Block4e584df2012-04-24 23:12:47 +0100529 * Gets the type of the hit test result. See the XXX_TYPE constants
530 * defined in this class.
531 *
532 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000533 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 public int getType() {
535 return mType;
536 }
537
Jonathan Dixone230e542011-12-21 10:57:00 +0000538 /**
Steve Block4e584df2012-04-24 23:12:47 +0100539 * Gets additional type-dependant information about the result. See
Nate Fischer0a6140d2017-09-05 12:37:49 -0700540 * {@link WebView#getHitTestResult()} for details. May either be {@code null}
Steve Block4e584df2012-04-24 23:12:47 +0100541 * or contain extra information about this result.
542 *
543 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000544 */
Nate Fischer3442c742017-09-08 17:02:00 -0700545 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 public String getExtra() {
547 return mExtra;
548 }
549 }
550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 /**
Nate Fischer674561a2017-10-26 12:28:01 -0700552 * Constructs a new WebView with an Activity Context object.
Steve Block4e584df2012-04-24 23:12:47 +0100553 *
Nate Fischer674561a2017-10-26 12:28:01 -0700554 * <p class="note"><b>Note:</b> WebView should always be instantiated with an Activity Context.
555 * If instantiated with an Application Context, WebView will be unable to provide several
556 * features, such as JavaScript dialogs and autofill.
557 *
558 * @param context an Activity Context to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 */
560 public WebView(Context context) {
561 this(context, null);
562 }
563
564 /**
Steve Block4e584df2012-04-24 23:12:47 +0100565 * Constructs a new WebView with layout parameters.
566 *
Nate Fischer674561a2017-10-26 12:28:01 -0700567 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100568 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 */
570 public WebView(Context context, AttributeSet attrs) {
571 this(context, attrs, com.android.internal.R.attr.webViewStyle);
572 }
573
574 /**
Steve Block4e584df2012-04-24 23:12:47 +0100575 * Constructs a new WebView with layout parameters and a default style.
576 *
Nate Fischer674561a2017-10-26 12:28:01 -0700577 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100578 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700579 * @param defStyleAttr an attribute in the current theme that contains a
580 * reference to a style resource that supplies default values for
581 * the view. Can be 0 to not look for defaults.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 */
Alan Viverette617feb92013-09-09 18:09:13 -0700583 public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
584 this(context, attrs, defStyleAttr, 0);
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700585 }
586
587 /**
Steve Block4e584df2012-04-24 23:12:47 +0100588 * Constructs a new WebView with layout parameters and a default style.
589 *
Nate Fischer674561a2017-10-26 12:28:01 -0700590 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100591 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700592 * @param defStyleAttr an attribute in the current theme that contains a
593 * reference to a style resource that supplies default values for
594 * the view. Can be 0 to not look for defaults.
595 * @param defStyleRes a resource identifier of a style resource that
596 * supplies default values for the view, used only if
597 * defStyleAttr is 0 or can not be found in the theme. Can be 0
598 * to not look for defaults.
599 */
600 public WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
601 this(context, attrs, defStyleAttr, defStyleRes, null, false);
602 }
603
604 /**
605 * Constructs a new WebView with layout parameters and a default style.
606 *
Nate Fischer674561a2017-10-26 12:28:01 -0700607 * @param context an Activity Context to access application assets
Alan Viverette617feb92013-09-09 18:09:13 -0700608 * @param attrs an AttributeSet passed to our parent
609 * @param defStyleAttr an attribute in the current theme that contains a
610 * reference to a style resource that supplies default values for
611 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100612 * @param privateBrowsing whether this WebView will be initialized in
613 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400614 *
Selim Gurunb6aa97e2014-03-26 14:10:28 -0700615 * @deprecated Private browsing is no longer supported directly via
Kristian Monsen5cc23512012-08-09 15:33:08 -0400616 * WebView and will be removed in a future release. Prefer using
617 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
618 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700619 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400620 @Deprecated
Alan Viverette617feb92013-09-09 18:09:13 -0700621 public WebView(Context context, AttributeSet attrs, int defStyleAttr,
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700622 boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700623 this(context, attrs, defStyleAttr, 0, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100624 }
625
626 /**
Steve Block4e584df2012-04-24 23:12:47 +0100627 * Constructs a new WebView with layout parameters, a default style and a set
Nate Fischerffb81c42016-09-26 12:35:47 -0700628 * of custom JavaScript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800629 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100630 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100631 *
Nate Fischer674561a2017-10-26 12:28:01 -0700632 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100633 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700634 * @param defStyleAttr an attribute in the current theme that contains a
635 * reference to a style resource that supplies default values for
636 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100637 * @param javaScriptInterfaces a Map of interface names, as keys, and
638 * object implementing those interfaces, as
639 * values
640 * @param privateBrowsing whether this WebView will be initialized in
641 * private mode
Nate Fischerffb81c42016-09-26 12:35:47 -0700642 * @hide This is used internally by dumprendertree, as it requires the JavaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100643 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100644 */
Alan Viverette617feb92013-09-09 18:09:13 -0700645 protected WebView(Context context, AttributeSet attrs, int defStyleAttr,
Steve Block81f19ff2010-11-01 13:23:24 +0000646 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700647 this(context, attrs, defStyleAttr, 0, javaScriptInterfaces, privateBrowsing);
648 }
649
650 /**
651 * @hide
652 */
653 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
654 protected WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
655 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
656 super(context, attrs, defStyleAttr, defStyleRes);
Felipe Lemed04a6972017-03-02 12:56:18 -0800657
658 // WebView is important by default, unless app developer overrode attribute.
659 if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
660 setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
661 }
662
Kristian Monsen87af7312011-09-09 02:12:51 +0100663 if (context == null) {
664 throw new IllegalArgumentException("Invalid context argument");
665 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700666 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
667 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000668 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100669
Jonathan Dixon3c909522012-02-28 18:45:06 +0000670 ensureProviderCreated();
671 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100672 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
673 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 }
675
676 /**
Steve Block4e584df2012-04-24 23:12:47 +0100677 * Specifies whether the horizontal scrollbar has overlay style.
678 *
Paul Millerc8694a02015-06-05 11:23:03 -0700679 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700680 * @param overlay {@code true} if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 */
Paul Millerc8694a02015-06-05 11:23:03 -0700682 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 public void setHorizontalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 /**
Steve Block4e584df2012-04-24 23:12:47 +0100687 * Specifies whether the vertical scrollbar has overlay style.
688 *
Paul Millerc8694a02015-06-05 11:23:03 -0700689 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700690 * @param overlay {@code true} if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 */
Paul Millerc8694a02015-06-05 11:23:03 -0700692 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 public void setVerticalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 }
695
696 /**
Steve Block4e584df2012-04-24 23:12:47 +0100697 * Gets whether horizontal scrollbar has overlay style.
698 *
Paul Millerc8694a02015-06-05 11:23:03 -0700699 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700700 * @return {@code true}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 */
Paul Millerc8694a02015-06-05 11:23:03 -0700702 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 public boolean overlayHorizontalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700704 // The old implementation defaulted to true, so return true for consistency
705 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 }
707
708 /**
Steve Block4e584df2012-04-24 23:12:47 +0100709 * Gets whether vertical scrollbar has overlay style.
710 *
Paul Millerc8694a02015-06-05 11:23:03 -0700711 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700712 * @return {@code false}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 */
Paul Millerc8694a02015-06-05 11:23:03 -0700714 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 public boolean overlayVerticalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700716 // The old implementation defaulted to false, so return false for consistency
717 return false;
Mike Reede8853fc2009-09-04 14:01:48 -0400718 }
719
Michael Kolbe54f6652011-03-16 09:11:51 -0700720 /**
Steve Block4e584df2012-04-24 23:12:47 +0100721 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700722 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700723 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400724 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400725 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700726 @Deprecated
Michael Kolb73980a92010-08-05 16:32:51 -0700727 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100728 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000729 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 }
731
732 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -0700733 * Gets the SSL certificate for the main top-level page or {@code null} if there is
Steve Block4e584df2012-04-24 23:12:47 +0100734 * no certificate (the site is not secure).
735 *
736 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 */
Nate Fischer3442c742017-09-08 17:02:00 -0700738 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100740 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000741 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 }
743
744 /**
745 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400746 *
747 * @deprecated Calling this function has no useful effect, and will be
748 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400750 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100752 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000753 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 }
755
756 //-------------------------------------------------------------------------
757 // Methods called by activity
758 //-------------------------------------------------------------------------
759
760 /**
Steve Block32fe4102012-07-17 16:29:11 +0100761 * Sets a username and password pair for the specified host. This data is
Nate Fischerffb81c42016-09-26 12:35:47 -0700762 * used by the WebView to autocomplete username and password fields in web
Steve Block32fe4102012-07-17 16:29:11 +0100763 * forms. Note that this is unrelated to the credentials used for HTTP
764 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100765 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000766 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100767 * @param username the username for the given host
768 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100769 * @see WebViewDatabase#clearUsernamePassword
770 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800771 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800773 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100775 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000776 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 }
778
779 /**
Hui Shu433fb932016-08-29 11:49:46 -0700780 * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase}
781 * instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 *
Steve Block46ce1db2012-07-17 16:43:00 +0100783 * @param host the host to which the credentials apply
784 * @param realm the realm to which the credentials apply
785 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100786 * @param password the password
Nate Fischerc7edfb02016-09-23 15:59:21 -0700787 * @deprecated Use {@link WebViewDatabase#setHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700789 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 public void setHttpAuthUsernamePassword(String host, String realm,
791 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100792 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000793 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 }
795
796 /**
Hui Shu433fb932016-08-29 11:49:46 -0700797 * Retrieves HTTP authentication credentials for a given host and realm from the {@link
798 * WebViewDatabase} instance.
Steve Block46ce1db2012-07-17 16:43:00 +0100799 * @param host the host to which the credentials apply
800 * @param realm the realm to which the credentials apply
801 * @return the credentials as a String array, if found. The first element
Nate Fischer0a6140d2017-09-05 12:37:49 -0700802 * is the username and the second element is the password. {@code null} if
Steve Block46ce1db2012-07-17 16:43:00 +0100803 * no credentials are found.
Nate Fischerc7edfb02016-09-23 15:59:21 -0700804 * @deprecated Use {@link WebViewDatabase#getHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700806 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700807 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100809 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000810 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400811 }
812
813 /**
Steve Block4e584df2012-04-24 23:12:47 +0100814 * Destroys the internal state of this WebView. This method should be called
815 * after this WebView has been removed from the view system. No other
816 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 */
818 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100819 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000820 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 }
822
823 /**
824 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100825 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100826 *
827 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400828 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100830 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 public static void enablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700832 // noop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
834
835 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100836 * Disables platform notifications of data state and proxy changes.
837 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100838 *
839 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400840 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100842 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 public static void disablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700844 // noop
Feng Qianb3081372009-06-29 15:55:18 -0700845 }
846
847 /**
Primiano Tucci24426752013-09-05 12:01:51 +0100848 * Used only by internal tests to free up memory.
849 *
850 * @hide
851 */
852 public static void freeMemoryForTests() {
Primiano Tucci24426752013-09-05 12:01:51 +0100853 getFactory().getStatics().freeMemoryForTests();
854 }
855
856 /**
Steve Block4e584df2012-04-24 23:12:47 +0100857 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000858 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800859 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100860 *
861 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 */
863 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100864 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000865 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 }
867
868 /**
Steve Block4e584df2012-04-24 23:12:47 +0100869 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
871 * method no longer stores the display data for this WebView. The previous
872 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400873 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100874 *
875 * @param outState the Bundle to store this WebView's state
Nate Fischer3442c742017-09-08 17:02:00 -0700876 * @return the same copy of the back/forward list used to save the state, {@code null} if the
877 * method fails.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 */
Nate Fischer3442c742017-09-08 17:02:00 -0700879 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100881 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000882 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 }
884
885 /**
Steve Block4e584df2012-04-24 23:12:47 +0100886 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100888 * @param b a Bundle to store the display data
889 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 * overwritten with this WebView's picture data.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700891 * @return {@code true} if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100892 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400893 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100895 @Deprecated
Patrick Scottda9a22b2010-04-08 08:32:52 -0400896 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100897 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000898 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 }
900
901 /**
Steve Block4e584df2012-04-24 23:12:47 +0100902 * Restores the display data that was saved in {@link #savePicture}. Used in
903 * conjunction with {@link #restoreState}. Note that this will not work if
904 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700905 *
Steve Block4e584df2012-04-24 23:12:47 +0100906 * @param b a Bundle containing the saved display data
907 * @param src the file where the picture data was stored
Nate Fischer0a6140d2017-09-05 12:37:49 -0700908 * @return {@code true} if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100909 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400910 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100912 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100914 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000915 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700916 }
917
918 /**
Steve Block42499062012-07-17 15:34:46 +0100919 * Restores the state of this WebView from the given Bundle. This method is
920 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
921 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100922 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400923 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400925 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100926 *
927 * @param inState the incoming Bundle of state
Nate Fischer0a6140d2017-09-05 12:37:49 -0700928 * @return the restored back/forward list or {@code null} if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 */
Nate Fischer3442c742017-09-08 17:02:00 -0700930 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100932 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000933 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 }
935
936 /**
Steve Block4e584df2012-04-24 23:12:47 +0100937 * Loads the given URL with the specified additional HTTP headers.
Bo Liue29d3132016-04-22 16:23:22 -0700938 * <p>
939 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100940 *
941 * @param url the URL of the resource to load
942 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100943 * HTTP request for this URL, specified as a map from name to
944 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100945 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100946 * controlling caching, accept types or the User-Agent, their
Nate Fischerffb81c42016-09-26 12:35:47 -0700947 * values may be overridden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800948 */
Steve Blockf71dea02011-08-01 12:29:14 +0100949 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100950 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000951 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800952 }
953
954 /**
Steve Block4e584df2012-04-24 23:12:47 +0100955 * Loads the given URL.
Bo Liue29d3132016-04-22 16:23:22 -0700956 * <p>
957 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100958 *
959 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 */
961 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100962 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000963 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
965
966 /**
Steve Block4e584df2012-04-24 23:12:47 +0100967 * Loads the URL with postData using "POST" method into this WebView. If url
Hui Shuc60ad9c2014-02-05 09:30:36 -0800968 * is not a network URL, it will be loaded with {@link #loadUrl(String)}
969 * instead, ignoring the postData param.
Cary Clarkd6982c92009-05-29 11:02:22 -0400970 *
Steve Block4e584df2012-04-24 23:12:47 +0100971 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100972 * @param postData the data will be passed to "POST" request, which must be
973 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700974 */
975 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100976 checkThread();
Hui Shuc60ad9c2014-02-05 09:30:36 -0800977 if (URLUtil.isNetworkUrl(url)) {
978 mProvider.postUrl(url, postData);
979 } else {
980 mProvider.loadUrl(url);
981 }
Grace Kloba57534302009-05-22 18:55:02 -0700982 }
983
984 /**
Steve Block4e584df2012-04-24 23:12:47 +0100985 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100986 * <p>
987 * Note that JavaScript's same origin policy means that script running in a
988 * page loaded using this method will be unable to access content loaded
989 * using any scheme other than 'data', including 'http(s)'. To avoid this
990 * restriction, use {@link
991 * #loadDataWithBaseURL(String,String,String,String,String)
992 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100993 * <p>
Nate Fischer867d1092018-01-04 21:57:33 -0800994 * The {@code encoding} parameter specifies whether the data is base64 or URL
Steve Block27f3e322012-07-23 10:45:59 +0100995 * encoded. If the data is base64 encoded, the value of the encoding
Nate Fischer867d1092018-01-04 21:57:33 -0800996 * parameter must be 'base64'. HTML can be encoded with {@link
997 * android.util.Base64#encodeToString(byte[],int)} like so:
998 * <pre>
999 * String unencodedHtml =
1000 * "&lt;html&gt;&lt;body&gt;'%28' is the code for '('&lt;/body&gt;&lt;/html&gt;";
1001 * String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
1002 * webView.loadData(encodedHtml, "text/html", "base64");
1003 * </pre>
1004 * <p>
1005 * For all other values of {@code encoding} (including {@code null}) it is assumed that the
1006 * data uses ASCII encoding for octets inside the range of safe URL characters and use the
1007 * standard %xx hex encoding of URLs for octets outside that range. See <a
1008 * href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC 3986</a> for more information.
Steve Blockb19c7872011-10-10 14:09:44 +01001009 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -08001010 * The {@code mimeType} parameter specifies the format of the data.
1011 * If WebView can't handle the specified MIME type, it will download the data.
1012 * If {@code null}, defaults to 'text/html'.
1013 * <p>
Steve Blockb19c7872011-10-10 14:09:44 +01001014 * The 'data' scheme URL formed by this method uses the default US-ASCII
1015 * charset. If you need need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +01001016 * 'data' scheme URL which explicitly specifies a charset parameter in the
1017 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
1018 * Note that the charset obtained from the mediatype portion of a data URL
1019 * always overrides that specified in the HTML or XML document itself.
Steve Block4e584df2012-04-24 23:12:47 +01001020 *
1021 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -08001022 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +01001023 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 */
Nate Fischer3442c742017-09-08 17:02:00 -07001025 public void loadData(String data, @Nullable String mimeType, @Nullable String encoding) {
Steve Block51b08912011-04-27 15:04:48 +01001026 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001027 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
1029
1030 /**
Steve Block4e584df2012-04-24 23:12:47 +01001031 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +01001032 * the content. The base URL is used both to resolve relative URLs and when
1033 * applying JavaScript's same origin policy. The historyUrl is used for the
1034 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -08001036 * The {@code mimeType} parameter specifies the format of the data.
1037 * If WebView can't handle the specified MIME type, it will download the data.
1038 * If {@code null}, defaults to 'text/html'.
1039 * <p>
Steve Blockae328572011-06-08 18:58:51 +01001040 * Note that content specified in this way can access local device files
1041 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
1042 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +01001043 * <p>
1044 * If the base URL uses the data scheme, this method is equivalent to
1045 * calling {@link #loadData(String,String,String) loadData()} and the
Ben Murdoch597256e2013-07-22 16:52:12 +01001046 * historyUrl is ignored, and the data will be treated as part of a data: URL.
1047 * If the base URL uses any other scheme, then the data will be loaded into
1048 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
1049 * entities in the string will not be decoded.
Mikhail Naganovb29e0f62015-09-16 13:05:53 -07001050 * <p>
1051 * Note that the baseUrl is sent in the 'Referer' HTTP header when
1052 * requesting subresources (images, etc.) of the page loaded using this method.
Steve Block4e584df2012-04-24 23:12:47 +01001053 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001054 * @param baseUrl the URL to use as the page's base URL. If {@code null} defaults to
Steve Block4e584df2012-04-24 23:12:47 +01001055 * 'about:blank'.
1056 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -08001057 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +01001058 * @param encoding the encoding of the data
Nate Fischer0a6140d2017-09-05 12:37:49 -07001059 * @param historyUrl the URL to use as the history entry. If {@code null} defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +00001060 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 */
Nate Fischer3442c742017-09-08 17:02:00 -07001062 public void loadDataWithBaseURL(@Nullable String baseUrl, String data,
1063 @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +01001064 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001065 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 }
1067
1068 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +01001069 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
1070 * If non-null, |resultCallback| will be invoked with any result returned from that
1071 * execution. This method must be called on the UI thread and the callback will
1072 * be made on the UI thread.
Bo Liue29d3132016-04-22 16:23:22 -07001073 * <p>
1074 * Compatibility note. Applications targeting {@link android.os.Build.VERSION_CODES#N} or
1075 * later, JavaScript state from an empty WebView is no longer persisted across navigations like
1076 * {@link #loadUrl(String)}. For example, global variables and functions defined before calling
1077 * {@link #loadUrl(String)} will not exist in the loaded page. Applications should use
1078 * {@link #addJavascriptInterface} instead to persist JavaScript objects across navigations.
Ben Murdocha5cdd512013-07-17 16:25:07 +01001079 *
1080 * @param script the JavaScript to execute.
1081 * @param resultCallback A callback to be invoked when the script execution
1082 * completes with the result of the execution (if any).
Nate Fischer0a6140d2017-09-05 12:37:49 -07001083 * May be {@code null} if no notification of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +01001084 */
Nate Fischer3442c742017-09-08 17:02:00 -07001085 public void evaluateJavascript(String script, @Nullable ValueCallback<String> resultCallback) {
Ben Murdocha5cdd512013-07-17 16:25:07 +01001086 checkThread();
1087 mProvider.evaluateJavaScript(script, resultCallback);
1088 }
1089
1090 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001091 * Saves the current view as a web archive.
1092 *
Steve Block4e584df2012-04-24 23:12:47 +01001093 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001094 */
1095 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +01001096 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001097 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001098 }
1099
1100 /**
1101 * Saves the current view as a web archive.
1102 *
Steve Block4e584df2012-04-24 23:12:47 +01001103 * @param basename the filename where the archive should be placed
Nate Fischer0a6140d2017-09-05 12:37:49 -07001104 * @param autoname if {@code false}, takes basename to be a file. If {@code true}, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001105 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +01001106 * chosen according to the URL of the current page.
1107 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001108 * parameter for onReceiveValue will either be the filename
Nate Fischer0a6140d2017-09-05 12:37:49 -07001109 * under which the file was saved, or {@code null} if saving the
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001110 * file failed.
1111 */
Nate Fischer3442c742017-09-08 17:02:00 -07001112 public void saveWebArchive(String basename, boolean autoname, @Nullable ValueCallback<String>
1113 callback) {
Steve Block51b08912011-04-27 15:04:48 +01001114 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001115 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -07001116 }
1117
1118 /**
Steve Block4e584df2012-04-24 23:12:47 +01001119 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 */
1121 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +01001122 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001123 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 }
1125
1126 /**
Steve Block4e584df2012-04-24 23:12:47 +01001127 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 */
1129 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +01001130 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001131 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
1134 /**
Steve Block4e584df2012-04-24 23:12:47 +01001135 * Gets whether this WebView has a back history item.
1136 *
Nate Fischer2be201e2017-10-26 10:43:00 -07001137 * @return {@code true} if this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 */
1139 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +01001140 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001141 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 }
1143
1144 /**
Steve Block4e584df2012-04-24 23:12:47 +01001145 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 */
1147 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +01001148 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001149 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
1151
1152 /**
Steve Block4e584df2012-04-24 23:12:47 +01001153 * Gets whether this WebView has a forward history item.
1154 *
Nate Fischer2be201e2017-10-26 10:43:00 -07001155 * @return {@code true} if this WebView has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 */
1157 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +01001158 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001159 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 }
1161
1162 /**
Steve Block4e584df2012-04-24 23:12:47 +01001163 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 */
1165 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +01001166 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001167 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
1169
1170 /**
Steve Block4e584df2012-04-24 23:12:47 +01001171 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +01001173 *
1174 * @param steps the negative or positive number of steps to move the
1175 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 */
1177 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001178 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001179 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 }
1181
1182 /**
Steve Block4e584df2012-04-24 23:12:47 +01001183 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 * the current item. Steps is negative if backward and positive
1185 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +01001186 *
1187 * @param steps the number of steps to take back or forward in the back
1188 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 */
1190 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +01001191 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001192 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001194
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001195 /**
Steve Block4e584df2012-04-24 23:12:47 +01001196 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -07001197 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -07001198 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +01001199 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001200 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 /**
Steve Block4e584df2012-04-24 23:12:47 +01001204 * Scrolls the contents of this WebView up by half the view size.
1205 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001206 * @param top {@code true} to jump to the top of the page
1207 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 */
1209 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +01001210 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001211 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 /**
Steve Block4e584df2012-04-24 23:12:47 +01001215 * Scrolls the contents of this WebView down by half the page size.
1216 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001217 * @param bottom {@code true} to jump to bottom of page
1218 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 */
1220 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001221 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001222 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 }
1224
1225 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +01001226 * Posts a {@link VisualStateCallback}, which will be called when
1227 * the current state of the WebView is ready to be drawn.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001228 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001229 * <p>Because updates to the DOM are processed asynchronously, updates to the DOM may not
Tobias Sargeantb3656042015-05-13 11:23:57 +01001230 * immediately be reflected visually by subsequent {@link WebView#onDraw} invocations. The
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001231 * {@link VisualStateCallback} provides a mechanism to notify the caller when the contents of
Tobias Sargeantb3656042015-05-13 11:23:57 +01001232 * the DOM at the current time are ready to be drawn the next time the {@link WebView}
Nate Fischerf02f8462017-09-11 15:16:33 -07001233 * draws.
Tobias Sargeantb3656042015-05-13 11:23:57 +01001234 *
1235 * <p>The next draw after the callback completes is guaranteed to reflect all the updates to the
Nate Fischerffb81c42016-09-26 12:35:47 -07001236 * DOM up to the point at which the {@link VisualStateCallback} was posted, but it may also
Nate Fischerf02f8462017-09-11 15:16:33 -07001237 * contain updates applied after the callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001238 *
1239 * <p>The state of the DOM covered by this API includes the following:
1240 * <ul>
1241 * <li>primitive HTML elements (div, img, span, etc..)</li>
1242 * <li>images</li>
1243 * <li>CSS animations</li>
1244 * <li>WebGL</li>
1245 * <li>canvas</li>
1246 * </ul>
1247 * It does not include the state of:
1248 * <ul>
1249 * <li>the video tag</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001250 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001251 *
1252 * <p>To guarantee that the {@link WebView} will successfully render the first frame
1253 * after the {@link VisualStateCallback#onComplete} method has been called a set of conditions
1254 * must be met:
1255 * <ul>
1256 * <li>If the {@link WebView}'s visibility is set to {@link View#VISIBLE VISIBLE} then
1257 * the {@link WebView} must be attached to the view hierarchy.</li>
1258 * <li>If the {@link WebView}'s visibility is set to {@link View#INVISIBLE INVISIBLE}
1259 * then the {@link WebView} must be attached to the view hierarchy and must be made
1260 * {@link View#VISIBLE VISIBLE} from the {@link VisualStateCallback#onComplete} method.</li>
1261 * <li>If the {@link WebView}'s visibility is set to {@link View#GONE GONE} then the
1262 * {@link WebView} must be attached to the view hierarchy and its
1263 * {@link AbsoluteLayout.LayoutParams LayoutParams}'s width and height need to be set to fixed
1264 * values and must be made {@link View#VISIBLE VISIBLE} from the
1265 * {@link VisualStateCallback#onComplete} method.</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001266 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001267 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001268 * <p>When using this API it is also recommended to enable pre-rasterization if the {@link
Nate Fischerffb81c42016-09-26 12:35:47 -07001269 * WebView} is off screen to avoid flickering. See {@link WebSettings#setOffscreenPreRaster} for
Nate Fischerf02f8462017-09-11 15:16:33 -07001270 * more details and do consider its caveats.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001271 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001272 * @param requestId An id that will be returned in the callback to allow callers to match
1273 * requests with callbacks.
1274 * @param callback The callback to be invoked.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001275 */
Tobias Sargeantb3656042015-05-13 11:23:57 +01001276 public void postVisualStateCallback(long requestId, VisualStateCallback callback) {
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001277 checkThread();
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001278 mProvider.insertVisualStateCallback(requestId, callback);
1279 }
1280
1281 /**
Steve Block4e584df2012-04-24 23:12:47 +01001282 * Clears this WebView so that onDraw() will draw nothing but white background,
1283 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001284 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1285 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001287 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001289 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001290 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 /**
Steve Block72498ed2012-07-17 15:57:25 +01001294 * Gets a new picture that captures the current contents of this WebView.
1295 * The picture is of the entire document being displayed, and is not
1296 * limited to the area currently displayed by this WebView. Also, the
1297 * picture is a static copy and is unaffected by later changes to the
1298 * content being displayed.
1299 * <p>
1300 * Note that due to internal changes, for API levels between
1301 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1302 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1303 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001304 * <p>
1305 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1306 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
1307 * additional conversion at a cost in memory and performance. Also the
1308 * {@link android.graphics.Picture#createFromStream} and
1309 * {@link android.graphics.Picture#writeToStream} methods are not supported on the
1310 * returned object.
1311 *
1312 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001313 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 *
Steve Block72498ed2012-07-17 15:57:25 +01001315 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001317 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001319 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001320 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 }
1322
Cary Clarkd6982c92009-05-29 11:02:22 -04001323 /**
Selim Gurun23a1af62014-03-14 16:52:45 -07001324 * @deprecated Use {@link #createPrintDocumentAdapter(String)} which requires user
1325 * to provide a print document name.
1326 */
1327 @Deprecated
1328 public PrintDocumentAdapter createPrintDocumentAdapter() {
1329 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001330 return mProvider.createPrintDocumentAdapter("default");
1331 }
1332
1333 /**
Nate Fischerffb81c42016-09-26 12:35:47 -07001334 * Creates a PrintDocumentAdapter that provides the content of this WebView for printing.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001335 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001336 * The adapter works by converting the WebView contents to a PDF stream. The WebView cannot
Selim Gurunda7d6422013-09-06 14:39:05 -07001337 * be drawn during the conversion process - any such draws are undefined. It is recommended
Nate Fischerffb81c42016-09-26 12:35:47 -07001338 * to use a dedicated off screen WebView for the printing. If necessary, an application may
Selim Gurunda7d6422013-09-06 14:39:05 -07001339 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1340 * wrapped around the object returned and observing the onStart and onFinish methods. See
1341 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun23a1af62014-03-14 16:52:45 -07001342 *
1343 * @param documentName The user-facing name of the printed document. See
1344 * {@link android.print.PrintDocumentInfo}
Selim Gurun2167c0b2013-08-05 15:23:09 -07001345 */
Selim Gurun23a1af62014-03-14 16:52:45 -07001346 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName) {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001347 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001348 return mProvider.createPrintDocumentAdapter(documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -07001349 }
1350
1351 /**
Steve Block4e584df2012-04-24 23:12:47 +01001352 * Gets the current scale of this WebView.
1353 *
1354 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001355 *
1356 * @deprecated This method is prone to inaccuracy due to race conditions
1357 * between the web rendering and UI threads; prefer
1358 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001360 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001361 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001363 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001364 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001365 }
1366
1367 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001368 * Sets the initial scale for this WebView. 0 means default.
1369 * The behavior for the default scale depends on the state of
1370 * {@link WebSettings#getUseWideViewPort()} and
1371 * {@link WebSettings#getLoadWithOverviewMode()}.
1372 * If the content fits into the WebView control by width, then
Nate Fischerffb81c42016-09-26 12:35:47 -07001373 * the zoom is set to 100%. For wide content, the behavior
Mikhail Naganov00303362013-09-02 10:57:04 +01001374 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001375 * If its value is {@code true}, the content will be zoomed out to be fit
Mikhail Naganov00303362013-09-02 10:57:04 +01001376 * by width into the WebView control, otherwise not.
1377 *
1378 * If initial scale is greater than 0, WebView starts with this value
1379 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001380 * Please note that unlike the scale properties in the viewport meta tag,
1381 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 *
Steve Block4e584df2012-04-24 23:12:47 +01001383 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 */
1385 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001386 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001387 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 }
1389
1390 /**
Steve Block4e584df2012-04-24 23:12:47 +01001391 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 * result in the zoom widget appearing on the screen to control the zoom
1393 * level of this WebView.
1394 */
1395 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001396 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001397 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 }
1399
1400 /**
Steve Block4e584df2012-04-24 23:12:47 +01001401 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1402 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1403 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1404 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1405 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001407 * 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 -08001408 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001409 * 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 -08001410 * a child node. If a phone number is found, the HitTestResult type is set
1411 * to PHONE_TYPE and the phone number is set in the "extra" field of
1412 * HitTestResult. If a map address is found, the HitTestResult type is set
1413 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1414 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1415 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1416 * HitTestResult type is set to UNKNOWN_TYPE.
1417 */
1418 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001419 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001420 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001421 }
1422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 /**
Steve Block4e584df2012-04-24 23:12:47 +01001424 * Requests the anchor or image element URL at the last tapped point.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001425 * If hrefMsg is {@code null}, this method returns immediately and does not
Cary Clark861368a2010-12-15 11:24:37 -05001426 * dispatch hrefMsg to its target. If the tapped point hits an image,
1427 * an anchor, or an image in an anchor, the message associates
1428 * strings in named keys in its data. The value paired with the key
1429 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001430 *
Steve Block4e584df2012-04-24 23:12:47 +01001431 * @param hrefMsg the message to be dispatched with the result of the
1432 * request. The message data contains three keys. "url"
1433 * returns the anchor's href attribute. "title" returns the
1434 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 */
Nate Fischer3442c742017-09-08 17:02:00 -07001436 public void requestFocusNodeHref(@Nullable Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001437 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001438 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 /**
Steve Block4e584df2012-04-24 23:12:47 +01001442 * Requests the URL of the image last touched by the user. msg will be sent
1443 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001444 *
Steve Block4e584df2012-04-24 23:12:47 +01001445 * @param msg the message to be dispatched with the result of the request
Nate Fischer0a6140d2017-09-05 12:37:49 -07001446 * as the data member with "url" as key. The result can be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 */
1448 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001449 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001450 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001451 }
1452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 /**
Steve Block4e584df2012-04-24 23:12:47 +01001454 * 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 -08001455 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001456 * that URL has begun, the current page may not have changed.
1457 *
1458 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 */
John Reck926cf562012-06-14 10:00:31 -07001460 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001462 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001463 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 /**
Steve Block4e584df2012-04-24 23:12:47 +01001467 * Gets the original URL for the current page. This is not always the same
1468 * as the URL passed to WebViewClient.onPageStarted because although the
1469 * load for that URL has begun, the current page may not have changed.
1470 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001472 *
1473 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 */
John Reck926cf562012-06-14 10:00:31 -07001475 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001477 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001478 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 }
1480
1481 /**
Steve Block4e584df2012-04-24 23:12:47 +01001482 * 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 -08001483 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001484 *
1485 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 */
John Reck926cf562012-06-14 10:00:31 -07001487 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001489 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001490 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 }
1492
1493 /**
Steve Block4e584df2012-04-24 23:12:47 +01001494 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001496 *
1497 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 */
1499 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001500 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001501 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
1503
1504 /**
Steve Block4e584df2012-04-24 23:12:47 +01001505 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001506 * a URL on this site's server pointing to the standard location of a
1507 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001508 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001509 * @hide
1510 */
1511 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001512 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001513 }
1514
1515 /**
Steve Block4e584df2012-04-24 23:12:47 +01001516 * Gets the progress for the current page.
1517 *
1518 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 */
1520 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001521 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001522 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 /**
Steve Block4e584df2012-04-24 23:12:47 +01001526 * Gets the height of the HTML content.
1527 *
1528 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 */
John Reck926cf562012-06-14 10:00:31 -07001530 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001532 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001533 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 }
1535
1536 /**
Steve Block4e584df2012-04-24 23:12:47 +01001537 * Gets the width of the HTML content.
1538 *
1539 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001540 * @hide
1541 */
John Reck926cf562012-06-14 10:00:31 -07001542 @ViewDebug.ExportedProperty(category = "webview")
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001543 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001544 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001545 }
1546
1547 /**
Steve Block4e584df2012-04-24 23:12:47 +01001548 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1549 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001550 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 */
1552 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001553 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001554 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 }
1556
1557 /**
Steve Block4e584df2012-04-24 23:12:47 +01001558 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001559 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 */
1561 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001562 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001563 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 }
1565
1566 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001567 * Does a best-effort attempt to pause any processing that can be paused
1568 * safely, such as animations and geolocation. Note that this call
1569 * does not pause JavaScript. To pause JavaScript globally, use
1570 * {@link #pauseTimers}.
1571 *
1572 * To resume WebView, call {@link #onResume}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001573 */
1574 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001575 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001576 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001577 }
1578
1579 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001580 * Resumes a WebView after a previous call to {@link #onPause}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001581 */
1582 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001583 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001584 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001585 }
1586
1587 /**
Steve Block4e584df2012-04-24 23:12:47 +01001588 * Gets whether this WebView is paused, meaning onPause() was called.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001589 * Calling onResume() sets the paused state back to {@code false}.
Steve Block4e584df2012-04-24 23:12:47 +01001590 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001591 * @hide
1592 */
1593 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001594 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001595 }
1596
1597 /**
Steve Block4e584df2012-04-24 23:12:47 +01001598 * Informs this WebView that memory is low so that it can free any available
1599 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001600 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1601 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001602 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001603 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001604 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001605 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001606 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001607 }
1608
1609 /**
Steve Block4e584df2012-04-24 23:12:47 +01001610 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001611 * this will clear the cache for all WebViews used.
1612 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001613 * @param includeDiskFiles if {@code false}, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 */
1615 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001616 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001617 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 }
1619
1620 /**
Steve Block219dfa42012-07-20 10:31:21 +01001621 * Removes the autocomplete popup from the currently focused form field, if
1622 * present. Note this only affects the display of the autocomplete popup,
1623 * it does not remove any saved form data from this WebView's store. To do
1624 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 */
1626 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001627 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001628 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 }
1630
1631 /**
Steve Block4e584df2012-04-24 23:12:47 +01001632 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 */
1634 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001635 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001636 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 }
1638
1639 /**
Steve Block4e584df2012-04-24 23:12:47 +01001640 * Clears the SSL preferences table stored in response to proceeding with
1641 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 */
1643 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001644 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001645 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 }
1647
1648 /**
Selim Gurunee89ab42014-06-13 10:53:55 -07001649 * Clears the client certificate preferences stored in response
Nate Fischerffb81c42016-09-26 12:35:47 -07001650 * to proceeding/cancelling client cert requests. Note that WebView
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001651 * automatically clears these preferences when it receives a
Selim Gurunee89ab42014-06-13 10:53:55 -07001652 * {@link KeyChain#ACTION_STORAGE_CHANGED} intent. The preferences are
Nate Fischerffb81c42016-09-26 12:35:47 -07001653 * shared by all the WebViews that are created by the embedder application.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001654 *
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001655 * @param onCleared A runnable to be invoked when client certs are cleared.
Nate Fischer3442c742017-09-08 17:02:00 -07001656 * The runnable will be called in UI thread.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001657 */
Nate Fischer3442c742017-09-08 17:02:00 -07001658 public static void clearClientCertPreferences(@Nullable Runnable onCleared) {
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001659 getFactory().getStatics().clearClientCertPreferences(onCleared);
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001660 }
1661
1662 /**
Nate Fischer2b108d82017-08-21 17:59:55 -07001663 * Starts Safe Browsing initialization.
Nate Fischer471891d2017-07-18 19:15:52 -07001664 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001665 * URL loads are not guaranteed to be protected by Safe Browsing until after {@code callback} is
1666 * invoked with {@code true}. Safe Browsing is not fully supported on all devices. For those
1667 * devices {@code callback} will receive {@code false}.
Nate Fischer471891d2017-07-18 19:15:52 -07001668 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001669 * This does not enable the Safe Browsing feature itself, and should only be called if Safe
1670 * Browsing is enabled by the manifest tag or {@link WebSettings#setSafeBrowsingEnabled}. This
1671 * prepares resources used for Safe Browsing.
Nate Fischer471891d2017-07-18 19:15:52 -07001672 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001673 * This should be called with the Application Context (and will always use the Application
1674 * context to do its work regardless).
Nate Fischer471891d2017-07-18 19:15:52 -07001675 *
Nate Fischer3ca196a2017-07-12 18:45:03 -07001676 * @param context Application Context.
Nate Fischer2b108d82017-08-21 17:59:55 -07001677 * @param callback will be called on the UI thread with {@code true} if initialization is
1678 * successful, {@code false} otherwise.
Nate Fischer0e72c182017-05-30 11:25:17 -07001679 */
Nate Fischer3442c742017-09-08 17:02:00 -07001680 public static void startSafeBrowsing(Context context,
1681 @Nullable ValueCallback<Boolean> callback) {
Nate Fischer0e72c182017-05-30 11:25:17 -07001682 getFactory().getStatics().initSafeBrowsing(context, callback);
1683 }
1684
1685 /**
Nate Fischerbf158ec2017-06-27 22:52:20 -07001686 * Sets the list of domains that are exempt from SafeBrowsing checks. The list is
1687 * global for all the WebViews.
Selim Gurun89e93592017-07-28 10:33:58 -07001688 * <p>
1689 * Each rule should take one of these:
1690 * <table>
1691 * <tr><th> Rule </th> <th> Example </th> <th> Matches Subdomain</th> </tr>
Nate Fischerfbebfa92017-08-29 16:17:22 -07001692 * <tr><td> HOSTNAME </td> <td> example.com </td> <td> Yes </td> </tr>
1693 * <tr><td> .HOSTNAME </td> <td> .example.com </td> <td> No </td> </tr>
1694 * <tr><td> IPV4_LITERAL </td> <td> 192.168.1.1 </td> <td> No </td></tr>
1695 * <tr><td> IPV6_LITERAL_WITH_BRACKETS </td><td>[10:20:30:40:50:60:70:80]</td><td>No</td></tr>
Selim Gurun89e93592017-07-28 10:33:58 -07001696 * </table>
1697 * <p>
1698 * All other rules, including wildcards, are invalid.
Nate Fischerbf158ec2017-06-27 22:52:20 -07001699 *
1700 * @param urls the list of URLs
Nate Fischer0a6140d2017-09-05 12:37:49 -07001701 * @param callback will be called with {@code true} if URLs are successfully added to the
1702 * whitelist. It will be called with {@code false} if any URLs are malformed. The callback will
1703 * be run on the UI thread
Nate Fischerbf158ec2017-06-27 22:52:20 -07001704 */
Nate Fischerc5ec7452017-07-18 16:08:42 -07001705 public static void setSafeBrowsingWhitelist(@NonNull List<String> urls,
Nate Fischerd6385d32017-07-17 12:58:18 -07001706 @Nullable ValueCallback<Boolean> callback) {
1707 getFactory().getStatics().setSafeBrowsingWhitelist(urls, callback);
Nate Fischerbf158ec2017-06-27 22:52:20 -07001708 }
1709
1710 /**
Nate Fischer3898ac12017-08-09 23:02:36 -07001711 * Returns a URL pointing to the privacy policy for Safe Browsing reporting.
1712 *
1713 * @return the url pointing to a privacy policy document which can be displayed to users.
1714 */
1715 @NonNull
1716 public static Uri getSafeBrowsingPrivacyPolicyUrl() {
1717 return getFactory().getStatics().getSafeBrowsingPrivacyPolicyUrl();
1718 }
1719
1720 /**
Steve Block4e584df2012-04-24 23:12:47 +01001721 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 * back/forward list for use in querying each item in the history stack.
1723 * This is a copy of the private WebBackForwardList so it contains only a
1724 * snapshot of the current state. Multiple calls to this method may return
1725 * different objects. The object returned from this method will not be
1726 * updated to reflect any new state.
1727 */
1728 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001729 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001730 return mProvider.copyBackForwardList();
1731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 }
1733
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001734 /**
Steve Block4e584df2012-04-24 23:12:47 +01001735 * Registers the listener to be notified as find-on-page operations
1736 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001737 *
Steve Block4e584df2012-04-24 23:12:47 +01001738 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001739 */
1740 public void setFindListener(FindListener listener) {
1741 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001742 setupFindListenerIfNeeded();
1743 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001744 }
1745
1746 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001747 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001748 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001749 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1750 * has not been called yet, or if {@link #clearMatches} has been called since the
1751 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 *
Steve Block4e584df2012-04-24 23:12:47 +01001753 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001754 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001755 */
1756 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001757 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001758 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 }
1760
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001761 /**
Steve Block4e584df2012-04-24 23:12:47 +01001762 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001763 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001764 *
Steve Block4e584df2012-04-24 23:12:47 +01001765 * @param find the string to find
Nate Fischerffb81c42016-09-26 12:35:47 -07001766 * @return the number of occurrences of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001767 * @deprecated {@link #findAllAsync} is preferred.
1768 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001770 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001772 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001773 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001774 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 }
1776
Cary Clark3403eb32010-03-03 10:05:16 -05001777 /**
Steve Block4e584df2012-04-24 23:12:47 +01001778 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001779 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001780 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001781 *
Steve Block4e584df2012-04-24 23:12:47 +01001782 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001783 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001784 */
1785 public void findAllAsync(String find) {
1786 checkThread();
1787 mProvider.findAllAsync(find);
1788 }
1789
1790 /**
Steve Block4e584df2012-04-24 23:12:47 +01001791 * Starts an ActionMode for finding text in this WebView. Only works if this
1792 * WebView is attached to the view system.
1793 *
1794 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001795 * Otherwise, the last String searched for in this WebView will
1796 * be used to start.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001797 * @param showIme if {@code true}, show the IME, assuming the user will begin typing.
1798 * If {@code false} and text is non-null, perform a find all.
1799 * @return {@code true} if the find dialog is shown, {@code false} otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001800 * @deprecated This method does not work reliably on all Android versions;
1801 * implementing a custom find dialog using WebView.findAllAsync()
1802 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001803 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001804 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -07001805 public boolean showFindDialog(@Nullable String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001806 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001807 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001808 }
1809
1810 /**
Steve Block4e584df2012-04-24 23:12:47 +01001811 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 * location. Currently, only addresses in the United States are detected,
1813 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001814 * <ul>
1815 * <li>a house number</li>
1816 * <li>a street name</li>
1817 * <li>a street type (Road, Circle, etc), either spelled out or
1818 * abbreviated</li>
1819 * <li>a city name</li>
1820 * <li>a state or territory, either spelled out or two-letter abbr</li>
1821 * <li>an optional 5 digit or 9 digit zip code</li>
1822 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 * All names must be correctly capitalized, and the zip code, if present,
1824 * must be valid for the state. The street type must be a standard USPS
1825 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001826 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 *
Steve Block4e584df2012-04-24 23:12:47 +01001829 * @param addr the string to search for addresses
Nate Fischer0a6140d2017-09-05 12:37:49 -07001830 * @return the address, or if no address is found, {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 */
Nate Fischer3442c742017-09-08 17:02:00 -07001832 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 public static String findAddress(String addr) {
Tobias Sargeantf4d85d82018-01-05 14:34:38 +00001834 if (addr == null) {
1835 throw new NullPointerException("addr is null");
1836 }
1837 return FindAddress.findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 }
1839
Victoria Lease0b8413b2012-03-26 13:04:10 -07001840 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -07001841 * For apps targeting the L release, WebView has a new default behavior that reduces
1842 * memory footprint and increases performance by intelligently choosing
1843 * the portion of the HTML document that needs to be drawn. These
1844 * optimizations are transparent to the developers. However, under certain
1845 * circumstances, an App developer may want to disable them:
Ben Murdoch574fa342015-01-07 14:20:45 +00001846 * <ol>
1847 * <li>When an app uses {@link #onDraw} to do own drawing and accesses portions
1848 * of the page that is way outside the visible portion of the page.</li>
1849 * <li>When an app uses {@link #capturePicture} to capture a very large HTML document.
1850 * Note that capturePicture is a deprecated API.</li>
1851 * </ol>
Selim Gurun17d1adb2014-08-27 11:22:26 -07001852 * Enabling drawing the entire HTML document has a significant performance
1853 * cost. This method should be called before any WebViews are created.
Bo Liu9f3ed852014-07-18 10:03:12 -07001854 */
1855 public static void enableSlowWholeDocumentDraw() {
1856 getFactory().getStatics().enableSlowWholeDocumentDraw();
1857 }
1858
1859 /**
Steve Block4e584df2012-04-24 23:12:47 +01001860 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001861 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 */
1863 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001864 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001865 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001866 }
1867
1868 /**
Steve Block4e584df2012-04-24 23:12:47 +01001869 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 * message object will be dispatched with arg1 being set to 1 if images
1871 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001872 *
1873 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 */
1875 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001876 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001877 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 }
1879
1880 /**
Steve Block4e584df2012-04-24 23:12:47 +01001881 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001883 *
1884 * @param client an implementation of WebViewClient
Nate Fischer6e585842016-09-29 18:30:58 -07001885 * @see #getWebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 */
1887 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001888 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001889 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001890 }
1891
1892 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001893 * Gets the WebViewClient.
1894 *
1895 * @return the WebViewClient, or a default client if not yet set
1896 * @see #setWebViewClient
1897 */
1898 public WebViewClient getWebViewClient() {
1899 checkThread();
1900 return mProvider.getWebViewClient();
1901 }
1902
1903 /**
Steve Block4e584df2012-04-24 23:12:47 +01001904 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 * the rendering engine, and should be downloaded instead. This will replace
1906 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001907 *
1908 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001909 */
1910 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001911 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001912 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 }
1914
1915 /**
Steve Block4e584df2012-04-24 23:12:47 +01001916 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001917 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001919 *
1920 * @param client an implementation of WebChromeClient
Nate Fischer6e585842016-09-29 18:30:58 -07001921 * @see #getWebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 */
1923 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001924 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001925 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001926 }
1927
1928 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001929 * Gets the chrome handler.
1930 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001931 * @return the WebChromeClient, or {@code null} if not yet set
Nate Fischer6e585842016-09-29 18:30:58 -07001932 * @see #setWebChromeClient
1933 */
Nate Fischer3442c742017-09-08 17:02:00 -07001934 @Nullable
Nate Fischer6e585842016-09-29 18:30:58 -07001935 public WebChromeClient getWebChromeClient() {
1936 checkThread();
1937 return mProvider.getWebChromeClient();
1938 }
1939
1940 /**
Steve Block4e584df2012-04-24 23:12:47 +01001941 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001943 *
1944 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001945 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001947 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001949 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001950 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 }
1952
1953 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001954 * Injects the supplied Java object into this WebView. The object is
1955 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001956 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001957 * accessed from JavaScript. For applications targeted to API
1958 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001959 * and above, only public methods that are annotated with
1960 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001961 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001962 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001963 * important security note below for implications.
Nate Fischer02e281a2017-08-21 12:03:58 -07001964 * <p> Note that injected objects will not appear in JavaScript until the page is next
1965 * (re)loaded. JavaScript should be enabled before injecting the object. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001966 * <pre>
1967 * class JsObject {
1968 * {@literal @}JavascriptInterface
1969 * public String toString() { return "injectedObject"; }
1970 * }
Nate Fischer02e281a2017-08-21 12:03:58 -07001971 * webview.getSettings().setJavaScriptEnabled(true);
Selim Gurune91d5be2012-09-11 16:11:22 -07001972 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001973 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1974 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001975 * <p>
1976 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001978 * <li> This method can be used to allow JavaScript to control the host
1979 * application. This is a powerful feature, but also presents a security
Scott Rowe607c17f2014-08-07 11:42:09 -07001980 * risk for apps targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or earlier.
1981 * Apps that target a version later than {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1982 * are still vulnerable if the app runs on a device running Android earlier than 4.2.
1983 * The most secure way to use this method is to target {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1984 * and to ensure the method is called only when running on Android 4.2 or later.
1985 * With these older versions, JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001986 * injected object's public fields. Use of this method in a WebView
1987 * containing untrusted content could allow an attacker to manipulate the
1988 * host application in unintended ways, executing Java code with the
1989 * permissions of the host application. Use extreme care when using this
1990 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001991 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001992 * thread of this WebView. Care is therefore required to maintain thread
Scott Rowe607c17f2014-08-07 11:42:09 -07001993 * safety.
1994 * </li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001995 * <li> The Java object's fields are not accessible.</li>
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001996 * <li> For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP}
Mikhail Naganovd380b202014-04-10 18:07:42 +01001997 * and above, methods of injected Java objects are enumerable from
1998 * JavaScript.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001999 * </ul>
2000 *
2001 * @param object the Java object to inject into this WebView's JavaScript
Nate Fischer0a6140d2017-09-05 12:37:49 -07002002 * context. {@code null} values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01002003 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 */
Steve Block4cd73c52011-11-09 13:06:52 +00002005 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01002006 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002007 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 }
2009
2010 /**
Steve Block3aa800b2012-04-24 13:01:34 +01002011 * Removes a previously injected Java object from this WebView. Note that
2012 * the removal will not be reflected in JavaScript until the page is next
2013 * (re)loaded. See {@link #addJavascriptInterface}.
2014 *
2015 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00002016 */
Nate Fischer3442c742017-09-08 17:02:00 -07002017 public void removeJavascriptInterface(@NonNull String name) {
Steve Block51b08912011-04-27 15:04:48 +01002018 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01002019 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00002020 }
2021
2022 /**
Selim Gurun4c8093a2015-03-10 17:40:06 -07002023 * Creates a message channel to communicate with JS and returns the message
2024 * ports that represent the endpoints of this message channel. The HTML5 message
Selim Gurun0a814b62015-05-13 10:15:55 -07002025 * channel functionality is described
2026 * <a href="https://html.spec.whatwg.org/multipage/comms.html#messagechannel">here
2027 * </a>
Selim Gurun4c8093a2015-03-10 17:40:06 -07002028 *
Nate Fischerf02f8462017-09-11 15:16:33 -07002029 * <p>The returned message channels are entangled and already in started state.
Selim Gurun4c8093a2015-03-10 17:40:06 -07002030 *
2031 * @return the two message ports that form the message channel.
2032 */
2033 public WebMessagePort[] createWebMessageChannel() {
2034 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07002035 return mProvider.createWebMessageChannel();
2036 }
2037
2038 /**
2039 * Post a message to main frame. The embedded application can restrict the
2040 * messages to a certain target origin. See
Selim Gurun0a814b62015-05-13 10:15:55 -07002041 * <a href="https://html.spec.whatwg.org/multipage/comms.html#posting-messages">
2042 * HTML5 spec</a> for how target origin can be used.
Selim Gurunb18fbfa2017-05-18 11:50:26 -07002043 * <p>
2044 * A target origin can be set as a wildcard ("*"). However this is not recommended.
2045 * See the page above for security issues.
Selim Gurun4c8093a2015-03-10 17:40:06 -07002046 *
2047 * @param message the WebMessage
Selim Gurunb18fbfa2017-05-18 11:50:26 -07002048 * @param targetOrigin the target origin.
Selim Gurun4c8093a2015-03-10 17:40:06 -07002049 */
Selim Gurun26de90a2015-05-15 11:02:45 -07002050 public void postWebMessage(WebMessage message, Uri targetOrigin) {
Selim Gurun4c8093a2015-03-10 17:40:06 -07002051 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07002052 mProvider.postMessageToMainFrame(message, targetOrigin);
2053 }
2054
2055 /**
Steve Block4e584df2012-04-24 23:12:47 +01002056 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01002058 *
2059 * @return a WebSettings object that can be used to control this WebView's
2060 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 */
2062 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01002063 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002064 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 }
2066
Jonathan Dixon3c909522012-02-28 18:45:06 +00002067 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07002068 * Enables debugging of web contents (HTML / CSS / JavaScript)
2069 * loaded into any WebViews of this application. This flag can be enabled
2070 * in order to facilitate debugging of web layouts and JavaScript
2071 * code running inside WebViews. Please refer to WebView documentation
2072 * for the debugging guide.
2073 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002074 * The default is {@code false}.
Mikhail Naganov057989e2013-09-06 16:35:25 -07002075 *
2076 * @param enabled whether to enable web contents debugging
2077 */
2078 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07002079 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
2080 }
2081
2082 /**
Steve Block4e584df2012-04-24 23:12:47 +01002083 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002084 *
Steve Block4e584df2012-04-24 23:12:47 +01002085 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00002086 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01002087 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00002088 */
Andrei Popescu385df692009-08-13 11:59:57 +01002089 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08002091 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 }
2093
Jonathan Dixon3c909522012-02-28 18:45:06 +00002094 /**
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04002095 * Define the directory used to store WebView data for the current process.
2096 * The provided suffix will be used when constructing data and cache
2097 * directory paths. If this API is not called, no suffix will be used.
2098 * Each directory can be used by only one process in the application. If more
2099 * than one process in an app wishes to use WebView, only one process can use
2100 * the default directory, and other processes must call this API to define
2101 * a unique suffix.
2102 * <p>
2103 * This API must be called before any instances of WebView are created in
2104 * this process and before any other methods in the android.webkit package
2105 * are called by this process.
2106 *
2107 * @param suffix The directory name suffix to be used for the current
2108 * process. Must not contain a path separator.
2109 * @throws IllegalStateException if WebView has already been initialized
2110 * in the current process.
2111 * @throws IllegalArgumentException if the suffix contains a path separator.
2112 */
2113 public static void setDataDirectorySuffix(String suffix) {
2114 WebViewFactory.setDataDirectorySuffix(suffix);
2115 }
2116
2117 /**
2118 * Indicate that the current process does not intend to use WebView, and
2119 * that an exception should be thrown if a WebView is created or any other
2120 * methods in the android.webkit package are used.
2121 * <p>
2122 * Applications with multiple processes may wish to call this in processes
2123 * which are not intended to use WebView to prevent potential data directory
2124 * conflicts (see {@link #setDataDirectorySuffix}) and to avoid accidentally
2125 * incurring the memory usage of initializing WebView in long-lived
2126 * processes which have no need for it.
2127 *
2128 * @throws IllegalStateException if WebView has already been initialized
2129 * in the current process.
2130 */
2131 public static void disableWebView() {
2132 WebViewFactory.disableWebView();
2133 }
2134
2135
2136 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002137 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01002138 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00002139 */
Andrei Popescu385df692009-08-13 11:59:57 +01002140 @Deprecated
Steve Block51b08912011-04-27 15:04:48 +01002141 public void refreshPlugins(boolean reloadOpenPages) {
2142 checkThread();
2143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144
Cary Clark966641a2010-03-04 08:41:56 -05002145 /**
Steve Block4e584df2012-04-24 23:12:47 +01002146 * Puts this WebView into text selection mode. Do not rely on this
2147 * functionality; it will be deprecated in the future.
2148 *
Kristian Monsenfc771652011-05-10 16:44:05 +01002149 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002150 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05002151 */
Kristian Monsenfc771652011-05-10 16:44:05 +01002152 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01002154 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07002155 }
2156
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002157 /**
2158 * @deprecated WebView no longer needs to implement
2159 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2160 */
George Mountfab67a12012-01-05 09:58:53 -08002161 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002162 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002163 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04002165
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002166 /**
2167 * @deprecated WebView no longer needs to implement
2168 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2169 */
George Mountfab67a12012-01-05 09:58:53 -08002170 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002171 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002172 @Deprecated
2173 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174
2175 /**
2176 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08002177 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 */
George Mountfab67a12012-01-05 09:58:53 -08002179 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002180 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 @Deprecated
2182 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
2183 }
2184
Kristian Monsen5cc23512012-08-09 15:33:08 -04002185 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -07002186 * @deprecated Only the default case, {@code true}, will be supported in a future version.
Kristian Monsen5cc23512012-08-09 15:33:08 -04002187 */
2188 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01002190 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002191 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 }
2193
Derek Sollenberger03e48912010-05-18 17:03:42 -04002194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01002196 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002197 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198 }
2199
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002200 /**
Steve Block4e584df2012-04-24 23:12:47 +01002201 * Gets the zoom controls for this WebView, as a separate View. The caller
2202 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002203 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01002204 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
2205 * built-in zoom mechanisms for the WebView, as opposed to these separate
2206 * zoom controls. The built-in mechanisms are preferred and can be enabled
2207 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07002208 *
Steve Block4e584df2012-04-24 23:12:47 +01002209 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01002210 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 */
The Android Open Source Project10592532009-03-18 17:39:46 -07002212 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01002214 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002215 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07002216 }
2217
2218 /**
Steve Block4e584df2012-04-24 23:12:47 +01002219 * Gets whether this WebView can be zoomed in.
2220 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002221 * @return {@code true} if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04002222 *
2223 * @deprecated This method is prone to inaccuracy due to race conditions
2224 * between the web rendering and UI threads; prefer
2225 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002226 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002227 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002228 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002229 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002230 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07002231 }
2232
2233 /**
Steve Block4e584df2012-04-24 23:12:47 +01002234 * Gets whether this WebView can be zoomed out.
2235 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002236 * @return {@code true} if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04002237 *
2238 * @deprecated This method is prone to inaccuracy due to race conditions
2239 * between the web rendering and UI threads; prefer
2240 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002241 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002242 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002243 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002244 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002245 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07002246 }
2247
2248 /**
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002249 * Performs a zoom operation in this WebView.
2250 *
Nate Fischerffb81c42016-09-26 12:35:47 -07002251 * @param zoomFactor the zoom factor to apply. The zoom factor will be clamped to the WebView's
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002252 * zoom limits. This value must be in the range 0.01 to 100.0 inclusive.
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002253 */
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002254 public void zoomBy(float zoomFactor) {
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002255 checkThread();
2256 if (zoomFactor < 0.01)
2257 throw new IllegalArgumentException("zoomFactor must be greater than 0.01.");
2258 if (zoomFactor > 100.0)
2259 throw new IllegalArgumentException("zoomFactor must be less than 100.");
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002260 mProvider.zoomBy(zoomFactor);
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002261 }
2262
2263 /**
Steve Block4e584df2012-04-24 23:12:47 +01002264 * Performs zoom in in this WebView.
2265 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002266 * @return {@code true} if zoom in succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 */
2268 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002269 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002270 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 }
2272
2273 /**
Steve Block4e584df2012-04-24 23:12:47 +01002274 * Performs zoom out in this WebView.
2275 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002276 * @return {@code true} if zoom out succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 */
2278 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002279 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002280 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 }
2282
Kristian Monsenfc771652011-05-10 16:44:05 +01002283 /**
2284 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002285 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01002286 */
2287 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01002289 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 }
Cary Clarkd6982c92009-05-29 11:02:22 -04002291
John Reck926cf562012-06-14 10:00:31 -07002292 /**
John Reckf2361152012-06-14 15:23:22 -07002293 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07002294 * @hide
2295 */
2296 @Override
2297 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
2298 mProvider.dumpViewHierarchyWithProperties(out, level);
2299 }
2300
2301 /**
2302 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
2303 * @hide
2304 */
2305 @Override
2306 public View findHierarchyView(String className, int hashCode) {
2307 return mProvider.findHierarchyView(className, hashCode);
2308 }
2309
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002310 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07002311 @IntDef(prefix = { "RENDERER_PRIORITY_" }, value = {
2312 RENDERER_PRIORITY_WAIVED,
2313 RENDERER_PRIORITY_BOUND,
2314 RENDERER_PRIORITY_IMPORTANT
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002315 })
2316 @Retention(RetentionPolicy.SOURCE)
2317 public @interface RendererPriority {}
2318
2319 /**
2320 * The renderer associated with this WebView is bound with
2321 * {@link Context#BIND_WAIVE_PRIORITY}. At this priority level
2322 * {@link WebView} renderers will be strong targets for out of memory
2323 * killing.
2324 *
2325 * Use with {@link #setRendererPriorityPolicy}.
2326 */
2327 public static final int RENDERER_PRIORITY_WAIVED = 0;
2328 /**
2329 * The renderer associated with this WebView is bound with
2330 * the default priority for services.
2331 *
2332 * Use with {@link #setRendererPriorityPolicy}.
2333 */
2334 public static final int RENDERER_PRIORITY_BOUND = 1;
2335 /**
2336 * The renderer associated with this WebView is bound with
2337 * {@link Context#BIND_IMPORTANT}.
2338 *
2339 * Use with {@link #setRendererPriorityPolicy}.
2340 */
2341 public static final int RENDERER_PRIORITY_IMPORTANT = 2;
2342
2343 /**
2344 * Set the renderer priority policy for this {@link WebView}. The
2345 * priority policy will be used to determine whether an out of
2346 * process renderer should be considered to be a target for OOM
2347 * killing.
2348 *
2349 * Because a renderer can be associated with more than one
2350 * WebView, the final priority it is computed as the maximum of
2351 * any attached WebViews. When a WebView is destroyed it will
2352 * cease to be considerered when calculating the renderer
2353 * priority. Once no WebViews remain associated with the renderer,
2354 * the priority of the renderer will be reduced to
2355 * {@link #RENDERER_PRIORITY_WAIVED}.
2356 *
2357 * The default policy is to set the priority to
2358 * {@link #RENDERER_PRIORITY_IMPORTANT} regardless of visibility,
2359 * and this should not be changed unless the caller also handles
2360 * renderer crashes with
2361 * {@link WebViewClient#onRenderProcessGone}. Any other setting
2362 * will result in WebView renderers being killed by the system
2363 * more aggressively than the application.
2364 *
2365 * @param rendererRequestedPriority the minimum priority at which
2366 * this WebView desires the renderer process to be bound.
Nate Fischer0a6140d2017-09-05 12:37:49 -07002367 * @param waivedWhenNotVisible if {@code true}, this flag specifies that
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002368 * when this WebView is not visible, it will be treated as
2369 * if it had requested a priority of
2370 * {@link #RENDERER_PRIORITY_WAIVED}.
2371 */
2372 public void setRendererPriorityPolicy(
2373 @RendererPriority int rendererRequestedPriority,
2374 boolean waivedWhenNotVisible) {
2375 mProvider.setRendererPriorityPolicy(rendererRequestedPriority, waivedWhenNotVisible);
2376 }
2377
2378 /**
2379 * Get the requested renderer priority for this WebView.
2380 *
2381 * @return the requested renderer priority policy.
2382 */
2383 @RendererPriority
2384 public int getRendererRequestedPriority() {
2385 return mProvider.getRendererRequestedPriority();
2386 }
2387
2388 /**
2389 * Return whether this WebView requests a priority of
2390 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2391 *
2392 * @return whether this WebView requests a priority of
2393 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2394 */
2395 public boolean getRendererPriorityWaivedWhenNotVisible() {
2396 return mProvider.getRendererPriorityWaivedWhenNotVisible();
2397 }
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002398
2399 /**
2400 * Sets the {@link TextClassifier} for this WebView.
2401 */
2402 public void setTextClassifier(@Nullable TextClassifier textClassifier) {
2403 mProvider.setTextClassifier(textClassifier);
2404 }
2405
2406 /**
2407 * Returns the {@link TextClassifier} used by this WebView.
2408 * If no TextClassifier has been set, this WebView uses the default set by the system.
2409 */
2410 @NonNull
2411 public TextClassifier getTextClassifier() {
2412 return mProvider.getTextClassifier();
2413 }
2414
Jonathan Dixon3c909522012-02-28 18:45:06 +00002415 //-------------------------------------------------------------------------
2416 // Interface for WebView providers
2417 //-------------------------------------------------------------------------
2418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 /**
Steve Block4e584df2012-04-24 23:12:47 +01002420 * Gets the WebViewProvider. Used by providers to obtain the underlying
Nate Fischerffb81c42016-09-26 12:35:47 -07002421 * implementation, e.g. when the application responds to
Steve Block4e584df2012-04-24 23:12:47 +01002422 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04002423 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00002424 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04002425 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002426 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002427 public WebViewProvider getWebViewProvider() {
2428 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04002429 }
2430
2431 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002432 * Callback interface, allows the provider implementation to access non-public methods
2433 * and fields, and make super-class calls in this WebView instance.
2434 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002435 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002436 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002437 public class PrivateAccess {
2438 // ---- Access to super-class methods ----
2439 public int super_getScrollBarStyle() {
2440 return WebView.super.getScrollBarStyle();
2441 }
2442
2443 public void super_scrollTo(int scrollX, int scrollY) {
2444 WebView.super.scrollTo(scrollX, scrollY);
2445 }
2446
2447 public void super_computeScroll() {
2448 WebView.super.computeScroll();
2449 }
2450
alanveebebc92012-06-15 18:59:11 -07002451 public boolean super_onHoverEvent(MotionEvent event) {
2452 return WebView.super.onHoverEvent(event);
2453 }
2454
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002455 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
Alan Viverettea54956a2015-01-07 16:05:02 -08002456 return WebView.super.performAccessibilityActionInternal(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002457 }
2458
Jonathan Dixon3c909522012-02-28 18:45:06 +00002459 public boolean super_performLongClick() {
2460 return WebView.super.performLongClick();
2461 }
2462
2463 public boolean super_setFrame(int left, int top, int right, int bottom) {
2464 return WebView.super.setFrame(left, top, right, bottom);
2465 }
2466
2467 public boolean super_dispatchKeyEvent(KeyEvent event) {
2468 return WebView.super.dispatchKeyEvent(event);
2469 }
2470
2471 public boolean super_onGenericMotionEvent(MotionEvent event) {
2472 return WebView.super.onGenericMotionEvent(event);
2473 }
2474
2475 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
2476 return WebView.super.requestFocus(direction, previouslyFocusedRect);
2477 }
2478
2479 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
2480 WebView.super.setLayoutParams(params);
2481 }
2482
Hui Shuf119c522015-10-08 10:07:13 -07002483 public void super_startActivityForResult(Intent intent, int requestCode) {
2484 WebView.super.startActivityForResult(intent, requestCode);
2485 }
2486
Jonathan Dixon3c909522012-02-28 18:45:06 +00002487 // ---- Access to non-public methods ----
2488 public void overScrollBy(int deltaX, int deltaY,
2489 int scrollX, int scrollY,
2490 int scrollRangeX, int scrollRangeY,
2491 int maxOverScrollX, int maxOverScrollY,
2492 boolean isTouchEvent) {
2493 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
2494 maxOverScrollX, maxOverScrollY, isTouchEvent);
2495 }
2496
2497 public void awakenScrollBars(int duration) {
2498 WebView.this.awakenScrollBars(duration);
2499 }
2500
2501 public void awakenScrollBars(int duration, boolean invalidate) {
2502 WebView.this.awakenScrollBars(duration, invalidate);
2503 }
2504
2505 public float getVerticalScrollFactor() {
2506 return WebView.this.getVerticalScrollFactor();
2507 }
2508
2509 public float getHorizontalScrollFactor() {
2510 return WebView.this.getHorizontalScrollFactor();
2511 }
2512
2513 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
2514 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
2515 }
2516
2517 public void onScrollChanged(int l, int t, int oldl, int oldt) {
2518 WebView.this.onScrollChanged(l, t, oldl, oldt);
2519 }
2520
2521 public int getHorizontalScrollbarHeight() {
2522 return WebView.this.getHorizontalScrollbarHeight();
2523 }
2524
Martin Kosiba9a68f822013-08-08 14:02:41 +01002525 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2526 int l, int t, int r, int b) {
2527 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2528 }
2529
Jonathan Dixon3c909522012-02-28 18:45:06 +00002530 // ---- Access to (non-public) fields ----
2531 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
2532 public void setScrollXRaw(int scrollX) {
2533 WebView.this.mScrollX = scrollX;
2534 }
2535
2536 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
2537 public void setScrollYRaw(int scrollY) {
2538 WebView.this.mScrollY = scrollY;
2539 }
2540
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002541 }
2542
Jonathan Dixon3c909522012-02-28 18:45:06 +00002543 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002544 // Package-private internal stuff
2545 //-------------------------------------------------------------------------
2546
2547 // Only used by android.webkit.FindActionModeCallback.
2548 void setFindDialogFindListener(FindListener listener) {
2549 checkThread();
2550 setupFindListenerIfNeeded();
2551 mFindListener.mFindDialogFindListener = listener;
2552 }
2553
2554 // Only used by android.webkit.FindActionModeCallback.
2555 void notifyFindDialogDismissed() {
2556 checkThread();
2557 mProvider.notifyFindDialogDismissed();
2558 }
2559
2560 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002561 // Private internal stuff
2562 //-------------------------------------------------------------------------
2563
Jonathan Dixon3c909522012-02-28 18:45:06 +00002564 private WebViewProvider mProvider;
2565
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002566 /**
2567 * In addition to the FindListener that the user may set via the WebView.setFindListener
2568 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
Mark Dolinerd0646dc2014-08-27 16:04:02 -07002569 * via this class so that the two FindListeners can potentially exist at once.
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002570 */
2571 private class FindListenerDistributor implements FindListener {
2572 private FindListener mFindDialogFindListener;
2573 private FindListener mUserFindListener;
2574
2575 @Override
2576 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2577 boolean isDoneCounting) {
2578 if (mFindDialogFindListener != null) {
2579 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2580 isDoneCounting);
2581 }
2582
2583 if (mUserFindListener != null) {
2584 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2585 isDoneCounting);
2586 }
2587 }
2588 }
2589 private FindListenerDistributor mFindListener;
2590
2591 private void setupFindListenerIfNeeded() {
2592 if (mFindListener == null) {
2593 mFindListener = new FindListenerDistributor();
2594 mProvider.setFindListener(mFindListener);
2595 }
2596 }
2597
Jonathan Dixon3c909522012-02-28 18:45:06 +00002598 private void ensureProviderCreated() {
2599 checkThread();
2600 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002601 // As this can get called during the base class constructor chain, pass the minimum
2602 // number of dependencies here; the rest are deferred to init().
2603 mProvider = getFactory().createWebView(this, new PrivateAccess());
2604 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002605 }
2606
Torne (Richard Coles)59375a02016-07-18 18:34:02 +01002607 private static WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002608 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002609 }
2610
Jonathan Dixon517771b2013-10-08 13:32:11 -07002611 private final Looper mWebViewThread = Looper.myLooper();
2612
2613 private void checkThread() {
2614 // Ignore mWebViewThread == null because this can be called during in the super class
2615 // constructor, before this class's own constructor has even started.
2616 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002617 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002618 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002619 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002620 "All WebView methods must be called on the same thread. " +
2621 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2622 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002623 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2624 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002625
2626 if (sEnforceThreadChecking) {
2627 throw new RuntimeException(throwable);
2628 }
Steve Block51b08912011-04-27 15:04:48 +01002629 }
2630 }
2631
Jonathan Dixon3c909522012-02-28 18:45:06 +00002632 //-------------------------------------------------------------------------
2633 // Override View methods
2634 //-------------------------------------------------------------------------
2635
2636 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2637 // there's a corresponding override (or better, caller) for each of them in here.
2638
2639 @Override
2640 protected void onAttachedToWindow() {
2641 super.onAttachedToWindow();
2642 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002643 }
2644
John Reck34dbce12014-03-06 12:52:24 -08002645 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002646 @Override
John Reck34dbce12014-03-06 12:52:24 -08002647 protected void onDetachedFromWindowInternal() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002648 mProvider.getViewDelegate().onDetachedFromWindow();
John Reck34dbce12014-03-06 12:52:24 -08002649 super.onDetachedFromWindowInternal();
Chris Craik555c55e2011-07-28 15:39:43 -07002650 }
2651
Tima Vaisburd5544f6c2017-04-27 10:53:27 -07002652 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002653 @Override
Tima Vaisburd134752b2017-04-06 15:50:05 -07002654 public void onMovedToDisplay(int displayId, Configuration config) {
2655 mProvider.getViewDelegate().onMovedToDisplay(displayId, config);
2656 }
2657
2658 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002659 public void setLayoutParams(ViewGroup.LayoutParams params) {
2660 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002661 }
2662
Jonathan Dixon3c909522012-02-28 18:45:06 +00002663 @Override
2664 public void setOverScrollMode(int mode) {
2665 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002666 // This method may be called in the constructor chain, before the WebView provider is
2667 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002668 ensureProviderCreated();
2669 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002670 }
2671
Jonathan Dixon3c909522012-02-28 18:45:06 +00002672 @Override
2673 public void setScrollBarStyle(int style) {
2674 mProvider.getViewDelegate().setScrollBarStyle(style);
2675 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002676 }
2677
Jonathan Dixon3c909522012-02-28 18:45:06 +00002678 @Override
2679 protected int computeHorizontalScrollRange() {
2680 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002681 }
2682
Jonathan Dixon3c909522012-02-28 18:45:06 +00002683 @Override
2684 protected int computeHorizontalScrollOffset() {
2685 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2686 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002687
Jonathan Dixon3c909522012-02-28 18:45:06 +00002688 @Override
2689 protected int computeVerticalScrollRange() {
2690 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2691 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002692
Jonathan Dixon3c909522012-02-28 18:45:06 +00002693 @Override
2694 protected int computeVerticalScrollOffset() {
2695 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2696 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002697
Jonathan Dixon3c909522012-02-28 18:45:06 +00002698 @Override
2699 protected int computeVerticalScrollExtent() {
2700 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2701 }
2702
2703 @Override
2704 public void computeScroll() {
2705 mProvider.getScrollDelegate().computeScroll();
2706 }
2707
2708 @Override
2709 public boolean onHoverEvent(MotionEvent event) {
2710 return mProvider.getViewDelegate().onHoverEvent(event);
2711 }
2712
2713 @Override
2714 public boolean onTouchEvent(MotionEvent event) {
2715 return mProvider.getViewDelegate().onTouchEvent(event);
2716 }
2717
2718 @Override
2719 public boolean onGenericMotionEvent(MotionEvent event) {
2720 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2721 }
2722
2723 @Override
2724 public boolean onTrackballEvent(MotionEvent event) {
2725 return mProvider.getViewDelegate().onTrackballEvent(event);
2726 }
2727
2728 @Override
2729 public boolean onKeyDown(int keyCode, KeyEvent event) {
2730 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2731 }
2732
2733 @Override
2734 public boolean onKeyUp(int keyCode, KeyEvent event) {
2735 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2736 }
2737
2738 @Override
2739 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2740 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2741 }
2742
2743 /*
2744 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2745 to be delegating them too.
2746
2747 @Override
2748 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2749 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2750 }
2751 @Override
2752 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2753 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2754 }
2755 @Override
2756 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2757 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2758 }
2759 */
2760
Ben Murdoche3f90712013-06-05 14:19:48 +01002761 @Override
2762 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2763 AccessibilityNodeProvider provider =
2764 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2765 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2766 }
2767
Jonathan Dixon3c909522012-02-28 18:45:06 +00002768 @Deprecated
2769 @Override
2770 public boolean shouldDelayChildPressedState() {
2771 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2772 }
2773
Felipe Leme1ca634a2016-11-28 17:21:21 -08002774 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -08002775 public CharSequence getAccessibilityClassName() {
2776 return WebView.class.getName();
2777 }
2778
Selim Gurun1b650cb2015-04-06 20:13:37 -07002779 @Override
Dianne Hackborn49b043f2015-05-07 14:21:38 -07002780 public void onProvideVirtualStructure(ViewStructure structure) {
Selim Gurun50b26a52015-06-01 16:26:10 -07002781 mProvider.getViewDelegate().onProvideVirtualStructure(structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -07002782 }
2783
Felipe Leme1a1e4682017-03-13 16:34:03 -07002784 /**
2785 * {@inheritDoc}
2786 *
2787 * <p>The {@link ViewStructure} traditionally represents a {@link View}, while for web pages
2788 * it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is
2789 * understood by the {@link android.service.autofill.AutofillService} implementations:
2790 *
2791 * <ol>
Felipe Leme303b6092017-07-31 18:01:15 -07002792 * <li>Only the HTML nodes inside a {@code FORM} are generated.
2793 * <li>The source of the HTML is set using {@link ViewStructure#setWebDomain(String)} in the
2794 * node representing the WebView.
2795 * <li>If a web page has multiple {@code FORM}s, only the data for the current form is
2796 * represented&mdash;if the user taps a field from another form, then the current autofill
2797 * context is canceled (by calling {@link android.view.autofill.AutofillManager#cancel()} and
2798 * a new context is created for that {@code FORM}.
2799 * <li>Similarly, if the page has {@code IFRAME} nodes, they are not initially represented in
2800 * the view structure until the user taps a field from a {@code FORM} inside the
2801 * {@code IFRAME}, in which case it would be treated the same way as multiple forms described
2802 * above, except that the {@link ViewStructure#setWebDomain(String) web domain} of the
2803 * {@code FORM} contains the {@code src} attribute from the {@code IFRAME} node.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002804 * <li>The W3C autofill field ({@code autocomplete} tag attribute) maps to
Felipe Leme58390fe2017-09-15 15:16:28 -07002805 * {@link ViewStructure#setAutofillHints(String[])}.
2806 * <li>If the view is editable, the {@link ViewStructure#setAutofillType(int)} and
Felipe Leme6dcec872017-05-25 11:24:23 -07002807 * {@link ViewStructure#setAutofillValue(AutofillValue)} must be set.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002808 * <li>The {@code placeholder} attribute maps to {@link ViewStructure#setHint(CharSequence)}.
Felipe Leme25bf7872017-03-28 15:32:29 -07002809 * <li>Other HTML attributes can be represented through
2810 * {@link ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)}.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002811 * </ol>
2812 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002813 * <p>If the WebView implementation can determine that the value of a field was set statically
2814 * (for example, not through Javascript), it should also call
2815 * {@code structure.setDataIsSensitive(false)}.
Felipe Leme6dcec872017-05-25 11:24:23 -07002816 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002817 * <p>For example, an HTML form with 2 fields for username and password:
Felipe Leme1a1e4682017-03-13 16:34:03 -07002818 *
2819 * <pre class="prettyprint">
Felipe Lemef485f892017-11-22 08:15:59 -08002820 * &lt;label&gt;Username:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002821 * &lt;input type="text" name="username" id="user" value="Type your username" autocomplete="username" placeholder="Email or username"&gt;
Felipe Lemef485f892017-11-22 08:15:59 -08002822 * &lt;label&gt;Password:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002823 * &lt;input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"&gt;
Felipe Leme1a1e4682017-03-13 16:34:03 -07002824 * </pre>
2825 *
2826 * <p>Would map to:
2827 *
2828 * <pre class="prettyprint">
Felipe Leme25bf7872017-03-28 15:32:29 -07002829 * int index = structure.addChildCount(2);
2830 * ViewStructure username = structure.newChild(index);
Felipe Leme6dcec872017-05-25 11:24:23 -07002831 * username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002832 * username.setAutofillHints("username");
Felipe Leme6dcec872017-05-25 11:24:23 -07002833 * username.setHtmlInfo(username.newHtmlInfoBuilder("input")
2834 * .addAttribute("type", "text")
Felipe Leme25bf7872017-03-28 15:32:29 -07002835 * .addAttribute("name", "username")
Felipe Lemef485f892017-11-22 08:15:59 -08002836 * .addAttribute("label", "Username:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002837 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002838 * username.setHint("Email or username");
2839 * username.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme6dcec872017-05-25 11:24:23 -07002840 * username.setAutofillValue(AutofillValue.forText("Type your username"));
Felipe Leme58390fe2017-09-15 15:16:28 -07002841 * // Value of the field is not sensitive because it was created statically and not changed.
Felipe Leme6dcec872017-05-25 11:24:23 -07002842 * username.setDataIsSensitive(false);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002843 *
Felipe Leme25bf7872017-03-28 15:32:29 -07002844 * ViewStructure password = structure.newChild(index + 1);
2845 * username.setAutofillId(structure, 2); // id 2 - second child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002846 * password.setAutofillHints("current-password");
Felipe Leme6dcec872017-05-25 11:24:23 -07002847 * password.setHtmlInfo(password.newHtmlInfoBuilder("input")
2848 * .addAttribute("type", "password")
Felipe Leme25bf7872017-03-28 15:32:29 -07002849 * .addAttribute("name", "password")
Felipe Lemef485f892017-11-22 08:15:59 -08002850 * .addAttribute("label", "Password:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002851 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002852 * password.setHint("Password");
2853 * password.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002854 * </pre>
Felipe Leme1a1e4682017-03-13 16:34:03 -07002855 */
Felipe Leme1ca634a2016-11-28 17:21:21 -08002856 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08002857 public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
2858 mProvider.getViewDelegate().onProvideAutofillVirtualStructure(structure, flags);
Felipe Leme1ca634a2016-11-28 17:21:21 -08002859 }
2860
Tao Baia5717332017-03-30 14:58:53 -07002861 @Override
2862 public void autofill(SparseArray<AutofillValue>values) {
2863 mProvider.getViewDelegate().autofill(values);
2864 }
2865
Alan Viverettea54956a2015-01-07 16:05:02 -08002866 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002867 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002868 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2869 super.onInitializeAccessibilityNodeInfoInternal(info);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002870 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002871 }
2872
Alan Viverettea54956a2015-01-07 16:05:02 -08002873 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002874 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002875 public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
2876 super.onInitializeAccessibilityEventInternal(event);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002877 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002878 }
2879
Alan Viverettea54956a2015-01-07 16:05:02 -08002880 /** @hide */
alanv448902d2012-05-16 20:27:47 -07002881 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002882 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002883 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002884 }
2885
Jonathan Dixon3c909522012-02-28 18:45:06 +00002886 /** @hide */
2887 @Override
2888 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2889 int l, int t, int r, int b) {
2890 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2891 }
2892
2893 @Override
2894 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2895 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2896 }
2897
2898 @Override
2899 protected void onWindowVisibilityChanged(int visibility) {
2900 super.onWindowVisibilityChanged(visibility);
2901 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2902 }
2903
2904 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002905 protected void onDraw(Canvas canvas) {
2906 mProvider.getViewDelegate().onDraw(canvas);
2907 }
2908
2909 @Override
2910 public boolean performLongClick() {
2911 return mProvider.getViewDelegate().performLongClick();
2912 }
2913
2914 @Override
2915 protected void onConfigurationChanged(Configuration newConfig) {
2916 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2917 }
2918
Selim Gurunc92080b2016-10-20 11:53:14 -07002919 /**
2920 * Creates a new InputConnection for an InputMethod to interact with the WebView.
2921 * This is similar to {@link View#onCreateInputConnection} but note that WebView
2922 * calls InputConnection methods on a thread other than the UI thread.
2923 * If these methods are overridden, then the overriding methods should respect
2924 * thread restrictions when calling View methods or accessing data.
2925 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002926 @Override
2927 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2928 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2929 }
2930
2931 @Override
Hui Shuecdce962016-02-04 15:00:19 -08002932 public boolean onDragEvent(DragEvent event) {
2933 return mProvider.getViewDelegate().onDragEvent(event);
2934 }
2935
2936 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002937 protected void onVisibilityChanged(View changedView, int visibility) {
2938 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002939 // This method may be called in the constructor chain, before the WebView provider is
2940 // created.
2941 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002942 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2943 }
2944
2945 @Override
2946 public void onWindowFocusChanged(boolean hasWindowFocus) {
2947 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2948 super.onWindowFocusChanged(hasWindowFocus);
2949 }
2950
2951 @Override
2952 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2953 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2954 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2955 }
2956
2957 /** @hide */
2958 @Override
2959 protected boolean setFrame(int left, int top, int right, int bottom) {
2960 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2961 }
2962
2963 @Override
2964 protected void onSizeChanged(int w, int h, int ow, int oh) {
2965 super.onSizeChanged(w, h, ow, oh);
2966 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2967 }
2968
2969 @Override
2970 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2971 super.onScrollChanged(l, t, oldl, oldt);
2972 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2973 }
2974
2975 @Override
2976 public boolean dispatchKeyEvent(KeyEvent event) {
2977 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2978 }
2979
2980 @Override
2981 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2982 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2983 }
2984
Jonathan Dixon3c909522012-02-28 18:45:06 +00002985 @Override
2986 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2987 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2988 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2989 }
2990
2991 @Override
2992 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2993 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2994 }
2995
2996 @Override
2997 public void setBackgroundColor(int color) {
2998 mProvider.getViewDelegate().setBackgroundColor(color);
2999 }
John Recka5408e62012-03-16 14:18:44 -07003000
3001 @Override
3002 public void setLayerType(int layerType, Paint paint) {
3003 super.setLayerType(layerType, paint);
3004 mProvider.getViewDelegate().setLayerType(layerType, paint);
3005 }
Ben Murdoche623e242012-09-07 20:47:07 +01003006
3007 @Override
3008 protected void dispatchDraw(Canvas canvas) {
3009 mProvider.getViewDelegate().preDispatchDraw(canvas);
3010 super.dispatchDraw(canvas);
3011 }
Ben Murdoch7302f4f2014-07-03 14:47:44 +01003012
3013 @Override
3014 public void onStartTemporaryDetach() {
3015 super.onStartTemporaryDetach();
3016 mProvider.getViewDelegate().onStartTemporaryDetach();
3017 }
3018
3019 @Override
3020 public void onFinishTemporaryDetach() {
3021 super.onFinishTemporaryDetach();
3022 mProvider.getViewDelegate().onFinishTemporaryDetach();
3023 }
Siva Velusamy94a6d152015-05-05 15:07:00 -07003024
Selim Gurune319dad2016-03-17 01:40:40 +00003025 @Override
3026 public Handler getHandler() {
3027 return mProvider.getViewDelegate().getHandler(super.getHandler());
3028 }
3029
3030 @Override
3031 public View findFocus() {
3032 return mProvider.getViewDelegate().findFocus(super.findFocus());
3033 }
3034
Hui Shuf119c522015-10-08 10:07:13 -07003035 /**
Gustav Senntonbf683e02016-09-15 14:42:50 +01003036 * If WebView has already been loaded into the current process this method will return the
3037 * package that was used to load it. Otherwise, the package that would be used if the WebView
3038 * was loaded right now will be returned; this does not cause WebView to be loaded, so this
3039 * information may become outdated at any time.
Gustav Sennton4cbfe712017-03-07 14:22:01 +00003040 * The WebView package changes either when the current WebView package is updated, disabled, or
3041 * uninstalled. It can also be changed through a Developer Setting.
3042 * If the WebView package changes, any app process that has loaded WebView will be killed. The
3043 * next time the app starts and loads WebView it will use the new WebView package instead.
Nate Fischer0a6140d2017-09-05 12:37:49 -07003044 * @return the current WebView package, or {@code null} if there is none.
Gustav Senntonbf683e02016-09-15 14:42:50 +01003045 */
Nate Fischer3442c742017-09-08 17:02:00 -07003046 @Nullable
Gustav Senntonbf683e02016-09-15 14:42:50 +01003047 public static PackageInfo getCurrentWebViewPackage() {
3048 PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
3049 if (webviewPackage != null) {
3050 return webviewPackage;
3051 }
3052
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04003053 IWebViewUpdateService service = WebViewFactory.getUpdateService();
3054 if (service == null) {
3055 return null;
3056 }
Gustav Senntonbf683e02016-09-15 14:42:50 +01003057 try {
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04003058 return service.getCurrentWebViewPackage();
Gustav Senntonbf683e02016-09-15 14:42:50 +01003059 } catch (RemoteException e) {
3060 throw e.rethrowFromSystemServer();
3061 }
3062 }
3063
3064 /**
Hui Shuf119c522015-10-08 10:07:13 -07003065 * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
3066 *
3067 * @param requestCode The integer request code originally supplied to
3068 * startActivityForResult(), allowing you to identify who this
3069 * result came from.
3070 * @param resultCode The integer result code returned by the child activity
3071 * through its setResult().
3072 * @param data An Intent, which can return result data to the caller
3073 * (various data can be attached to Intent "extras").
3074 * @hide
3075 */
3076 @Override
3077 public void onActivityResult(int requestCode, int resultCode, Intent data) {
3078 mProvider.getViewDelegate().onActivityResult(requestCode, resultCode, data);
3079 }
3080
Siva Velusamy94a6d152015-05-05 15:07:00 -07003081 /** @hide */
3082 @Override
3083 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
3084 super.encodeProperties(encoder);
3085
3086 checkThread();
3087 encoder.addProperty("webview:contentHeight", mProvider.getContentHeight());
3088 encoder.addProperty("webview:contentWidth", mProvider.getContentWidth());
3089 encoder.addProperty("webview:scale", mProvider.getScale());
3090 encoder.addProperty("webview:title", mProvider.getTitle());
3091 encoder.addProperty("webview:url", mProvider.getUrl());
3092 encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl());
3093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094}