blob: 14be73dec41cdeb8875a75fe7abc31bb3d7cc44c [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 Sargeant740b53f2019-01-14 21:49:15 +000019import android.annotation.CallbackExecutor;
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000020import android.annotation.IntDef;
Siva Velusamy94a6d152015-05-05 15:07:00 -070021import android.annotation.NonNull;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070022import android.annotation.Nullable;
Ignacio Solla451e3382014-11-10 10:35:54 +000023import android.annotation.SystemApi;
Mathew Inwood62d83fb2018-08-16 19:09:48 +010024import android.annotation.UnsupportedAppUsage;
Raphael30df2372010-03-06 10:09:54 -080025import android.annotation.Widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Context;
Hui Shuf119c522015-10-08 10:07:13 -070027import android.content.Intent;
Gustav Senntonbf683e02016-09-15 14:42:50 +010028import android.content.pm.PackageInfo;
Cary Clarkc5cd5e92010-11-22 15:20:02 -050029import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.graphics.Bitmap;
31import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070032import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.graphics.Picture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.graphics.Rect;
Mike Reede8853fc2009-09-04 14:01:48 -040035import android.graphics.drawable.Drawable;
Selim Gurun4c8093a2015-03-10 17:40:06 -070036import android.net.Uri;
Nate Fischer0e72c182017-05-30 11:25:17 -070037import android.net.http.SslCertificate;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -070038import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.Bundle;
Selim Gurune319dad2016-03-17 01:40:40 +000040import android.os.Handler;
Steve Block08d584c2011-05-17 19:05:03 +010041import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.os.Message;
Gustav Senntonbf683e02016-09-15 14:42:50 +010043import android.os.RemoteException;
Nate Fischer0e72c182017-05-30 11:25:17 -070044import android.os.StrictMode;
Selim Gurunda7d6422013-09-06 14:39:05 -070045import android.print.PrintDocumentAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.util.Log;
Tao Baia5717332017-03-30 14:58:53 -070048import android.util.SparseArray;
Hui Shuecdce962016-02-04 15:00:19 -080049import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070053import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070055import android.view.ViewHierarchyEncoder;
Nate Fischer0e72c182017-05-30 11:25:17 -070056import android.view.ViewStructure;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070058import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070059import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010060import android.view.accessibility.AccessibilityNodeProvider;
Tao Baia5717332017-03-30 14:58:53 -070061import android.view.autofill.AutofillValue;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050062import android.view.inputmethod.EditorInfo;
63import android.view.inputmethod.InputConnection;
Ashley Rose22f0d532019-02-04 19:29:03 -050064import android.view.inspector.InspectableProperty;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070065import android.view.textclassifier.TextClassifier;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010067
John Reck926cf562012-06-14 10:00:31 -070068import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import java.io.File;
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000070import java.lang.annotation.Retention;
71import java.lang.annotation.RetentionPolicy;
Nate Fischer520a8ba2017-07-12 17:37:07 -070072import java.util.List;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010073import java.util.Map;
Tobias Sargeant740b53f2019-01-14 21:49:15 +000074import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
76/**
Laura Davisb444e2d2018-07-13 15:12:35 -070077 * A View that displays web pages.
Scott Main41ec6532010-08-19 16:57:07 -070078 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010079 * <h3>Basic usage</h3>
80 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010081 *
Laura Davisb444e2d2018-07-13 15:12:35 -070082 * <p>In most cases, we recommend using a standard web browser, like Chrome, to deliver
83 * content to the user. To learn more about web browsers, read the guide on
84 * <a href="/guide/components/intents-common#Browser">
85 * invoking a browser with an intent</a>.
Nate Fischerf02f8462017-09-11 15:16:33 -070086 *
Laura Davisb444e2d2018-07-13 15:12:35 -070087 * <p>WebView objects allow you to display web content as part of your activity layout, but
88 * lack some of the features of fully-developed browsers. A WebView is useful when
89 * you need increased control over the UI and advanced configuration options that will allow
90 * you to embed web pages in a specially-designed environment for your app.
Mike Hearnadcd2ed2009-01-21 16:44:36 +010091 *
Laura Davisb444e2d2018-07-13 15:12:35 -070092 * <p>To learn more about WebView and alternatives for serving web content, read the
93 * documentation on
94 * <a href="/guide/webapps/">
95 * Web-based content</a>.
Nate Fischerfb92ee12018-01-18 12:01:19 -080096 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 */
Steve Block406aeb22012-04-23 18:17:19 +010098// Implementation notes.
99// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
100// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
101// Methods are delegated to the provider implementation: all public API methods introduced in this
102// file are fully delegated, whereas public and protected methods from the View base classes are
103// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800104@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400105public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700107 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700109 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700110
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700111 // Throwing an exception for incorrect thread usage if the
112 // build target is JB MR2 or newer. Defaults to false, and is
113 // set in the WebView constructor.
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100114 @UnsupportedAppUsage
Jonathan Dixon0d6a1452013-08-21 13:09:36 -0700115 private static volatile boolean sEnforceThreadChecking = false;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 /**
118 * Transportation object for returning WebView across thread boundaries.
119 */
120 public class WebViewTransport {
121 private WebView mWebview;
122
123 /**
Steve Block4e584df2012-04-24 23:12:47 +0100124 * Sets the WebView to the transportation object.
125 *
126 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 */
128 public synchronized void setWebView(WebView webview) {
129 mWebview = webview;
130 }
131
132 /**
Steve Block4e584df2012-04-24 23:12:47 +0100133 * Gets the WebView object.
134 *
135 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 */
137 public synchronized WebView getWebView() {
138 return mWebview;
139 }
140 }
141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 /**
Steve Block4e584df2012-04-24 23:12:47 +0100143 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 */
145 public static final String SCHEME_TEL = "tel:";
146 /**
Steve Block4e584df2012-04-24 23:12:47 +0100147 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 */
149 public static final String SCHEME_MAILTO = "mailto:";
150 /**
Steve Block4e584df2012-04-24 23:12:47 +0100151 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 */
153 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 /**
Victoria Leased405a432012-03-22 15:53:48 -0700156 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700157 */
158 public interface FindListener {
159 /**
Steve Block4e584df2012-04-24 23:12:47 +0100160 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700161 *
Steve Block4e584df2012-04-24 23:12:47 +0100162 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700163 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100164 * @param isDoneCounting whether the find operation has actually completed. The listener
165 * may be notified multiple times while the
166 * operation is underway, and the numberOfMatches
167 * value should not be considered final unless
Nate Fischer0a6140d2017-09-05 12:37:49 -0700168 * isDoneCounting is {@code true}.
Victoria Leased405a432012-03-22 15:53:48 -0700169 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700170 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700171 boolean isDoneCounting);
172 }
173
174 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +0100175 * Callback interface supplied to {@link #postVisualStateCallback} for receiving
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000176 * notifications about the visual state.
177 */
178 public static abstract class VisualStateCallback {
179 /**
180 * Invoked when the visual state is ready to be drawn in the next {@link #onDraw}.
181 *
Tobias Sargeantb3656042015-05-13 11:23:57 +0100182 * @param requestId The identifier passed to {@link #postVisualStateCallback} when this
183 * callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000184 */
185 public abstract void onComplete(long requestId);
186 }
187
188 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100190 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100191 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100193 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 public interface PictureListener {
195 /**
Steve Block72498ed2012-07-17 15:57:25 +0100196 * Used to provide notification that the WebView's picture has changed.
197 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100198 *
199 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000200 * @param picture the new picture. Applications targeting
201 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
Nate Fischer0a6140d2017-09-05 12:37:49 -0700202 * will always receive a {@code null} Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100203 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100205 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700206 void onNewPicture(WebView view, @Nullable Picture picture);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208
Jonathan Dixon19644b62011-12-21 14:21:36 +0000209 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /**
Steve Block4e584df2012-04-24 23:12:47 +0100211 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 */
213 public static final int UNKNOWN_TYPE = 0;
214 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100215 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 */
Steve Block1854ddb2011-04-19 12:18:19 +0100217 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 public static final int ANCHOR_TYPE = 1;
219 /**
Steve Block4e584df2012-04-24 23:12:47 +0100220 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
222 public static final int PHONE_TYPE = 2;
223 /**
Steve Block4e584df2012-04-24 23:12:47 +0100224 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 */
226 public static final int GEO_TYPE = 3;
227 /**
Steve Block4e584df2012-04-24 23:12:47 +0100228 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
230 public static final int EMAIL_TYPE = 4;
231 /**
Steve Block4e584df2012-04-24 23:12:47 +0100232 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 */
234 public static final int IMAGE_TYPE = 5;
235 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100236 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 */
Steve Block1854ddb2011-04-19 12:18:19 +0100238 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public static final int IMAGE_ANCHOR_TYPE = 6;
240 /**
Steve Block4e584df2012-04-24 23:12:47 +0100241 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 */
243 public static final int SRC_ANCHOR_TYPE = 7;
244 /**
Steve Block4e584df2012-04-24 23:12:47 +0100245 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 */
247 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
248 /**
Steve Block4e584df2012-04-24 23:12:47 +0100249 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 */
251 public static final int EDIT_TEXT_TYPE = 9;
252
253 private int mType;
254 private String mExtra;
255
Jonathan Dixon3c909522012-02-28 18:45:06 +0000256 /**
257 * @hide Only for use by WebViewProvider implementations
258 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000259 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000260 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 mType = UNKNOWN_TYPE;
262 }
263
Jonathan Dixon3c909522012-02-28 18:45:06 +0000264 /**
265 * @hide Only for use by WebViewProvider implementations
266 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000267 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000268 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 mType = type;
270 }
271
Jonathan Dixon3c909522012-02-28 18:45:06 +0000272 /**
273 * @hide Only for use by WebViewProvider implementations
274 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000275 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000276 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 mExtra = extra;
278 }
279
Jonathan Dixone230e542011-12-21 10:57:00 +0000280 /**
Steve Block4e584df2012-04-24 23:12:47 +0100281 * Gets the type of the hit test result. See the XXX_TYPE constants
282 * defined in this class.
283 *
284 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000285 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 public int getType() {
287 return mType;
288 }
289
Jonathan Dixone230e542011-12-21 10:57:00 +0000290 /**
Steve Block4e584df2012-04-24 23:12:47 +0100291 * Gets additional type-dependant information about the result. See
Nate Fischer0a6140d2017-09-05 12:37:49 -0700292 * {@link WebView#getHitTestResult()} for details. May either be {@code null}
Steve Block4e584df2012-04-24 23:12:47 +0100293 * or contain extra information about this result.
294 *
295 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000296 */
Nate Fischer3442c742017-09-08 17:02:00 -0700297 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 public String getExtra() {
299 return mExtra;
300 }
301 }
302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
Nate Fischer674561a2017-10-26 12:28:01 -0700304 * Constructs a new WebView with an Activity Context object.
Steve Block4e584df2012-04-24 23:12:47 +0100305 *
Nate Fischer674561a2017-10-26 12:28:01 -0700306 * <p class="note"><b>Note:</b> WebView should always be instantiated with an Activity Context.
307 * If instantiated with an Application Context, WebView will be unable to provide several
308 * features, such as JavaScript dialogs and autofill.
309 *
310 * @param context an Activity Context to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 */
312 public WebView(Context context) {
313 this(context, null);
314 }
315
316 /**
Steve Block4e584df2012-04-24 23:12:47 +0100317 * Constructs a new WebView with layout parameters.
318 *
Nate Fischer674561a2017-10-26 12:28:01 -0700319 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100320 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 */
322 public WebView(Context context, AttributeSet attrs) {
323 this(context, attrs, com.android.internal.R.attr.webViewStyle);
324 }
325
326 /**
Steve Block4e584df2012-04-24 23:12:47 +0100327 * Constructs a new WebView with layout parameters and a default style.
328 *
Nate Fischer674561a2017-10-26 12:28:01 -0700329 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100330 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700331 * @param defStyleAttr an attribute in the current theme that contains a
332 * reference to a style resource that supplies default values for
333 * the view. Can be 0 to not look for defaults.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 */
Alan Viverette617feb92013-09-09 18:09:13 -0700335 public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
336 this(context, attrs, defStyleAttr, 0);
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700337 }
338
339 /**
Steve Block4e584df2012-04-24 23:12:47 +0100340 * Constructs a new WebView with layout parameters and a default style.
341 *
Nate Fischer674561a2017-10-26 12:28:01 -0700342 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100343 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700344 * @param defStyleAttr an attribute in the current theme that contains a
345 * reference to a style resource that supplies default values for
346 * the view. Can be 0 to not look for defaults.
347 * @param defStyleRes a resource identifier of a style resource that
348 * supplies default values for the view, used only if
349 * defStyleAttr is 0 or can not be found in the theme. Can be 0
350 * to not look for defaults.
351 */
352 public WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
353 this(context, attrs, defStyleAttr, defStyleRes, null, false);
354 }
355
356 /**
357 * Constructs a new WebView with layout parameters and a default style.
358 *
Nate Fischer674561a2017-10-26 12:28:01 -0700359 * @param context an Activity Context to access application assets
Alan Viverette617feb92013-09-09 18:09:13 -0700360 * @param attrs an AttributeSet passed to our parent
361 * @param defStyleAttr an attribute in the current theme that contains a
362 * reference to a style resource that supplies default values for
363 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100364 * @param privateBrowsing whether this WebView will be initialized in
365 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400366 *
Selim Gurunb6aa97e2014-03-26 14:10:28 -0700367 * @deprecated Private browsing is no longer supported directly via
Kristian Monsen5cc23512012-08-09 15:33:08 -0400368 * WebView and will be removed in a future release. Prefer using
369 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
370 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700371 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400372 @Deprecated
Alan Viverette617feb92013-09-09 18:09:13 -0700373 public WebView(Context context, AttributeSet attrs, int defStyleAttr,
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700374 boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700375 this(context, attrs, defStyleAttr, 0, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100376 }
377
378 /**
Steve Block4e584df2012-04-24 23:12:47 +0100379 * Constructs a new WebView with layout parameters, a default style and a set
Nate Fischerffb81c42016-09-26 12:35:47 -0700380 * of custom JavaScript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800381 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100382 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100383 *
Nate Fischer674561a2017-10-26 12:28:01 -0700384 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100385 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700386 * @param defStyleAttr an attribute in the current theme that contains a
387 * reference to a style resource that supplies default values for
388 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100389 * @param javaScriptInterfaces a Map of interface names, as keys, and
390 * object implementing those interfaces, as
391 * values
392 * @param privateBrowsing whether this WebView will be initialized in
393 * private mode
Nate Fischerffb81c42016-09-26 12:35:47 -0700394 * @hide This is used internally by dumprendertree, as it requires the JavaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100395 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100396 */
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100397 @UnsupportedAppUsage
Alan Viverette617feb92013-09-09 18:09:13 -0700398 protected WebView(Context context, AttributeSet attrs, int defStyleAttr,
Steve Block81f19ff2010-11-01 13:23:24 +0000399 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700400 this(context, attrs, defStyleAttr, 0, javaScriptInterfaces, privateBrowsing);
401 }
402
403 /**
404 * @hide
405 */
406 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100407 @UnsupportedAppUsage
Alan Viverette617feb92013-09-09 18:09:13 -0700408 protected WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
409 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
410 super(context, attrs, defStyleAttr, defStyleRes);
Felipe Lemed04a6972017-03-02 12:56:18 -0800411
412 // WebView is important by default, unless app developer overrode attribute.
413 if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
414 setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
415 }
416
Kristian Monsen87af7312011-09-09 02:12:51 +0100417 if (context == null) {
418 throw new IllegalArgumentException("Invalid context argument");
419 }
Gustav Sennton01673692018-01-19 12:11:25 +0000420 if (mWebViewThread == null) {
421 throw new RuntimeException(
422 "WebView cannot be initialized on a thread that has no Looper.");
423 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700424 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
425 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000426 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100427
Jonathan Dixon3c909522012-02-28 18:45:06 +0000428 ensureProviderCreated();
429 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100430 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
431 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
433
434 /**
Steve Block4e584df2012-04-24 23:12:47 +0100435 * Specifies whether the horizontal scrollbar has overlay style.
436 *
Paul Millerc8694a02015-06-05 11:23:03 -0700437 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700438 * @param overlay {@code true} if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 */
Paul Millerc8694a02015-06-05 11:23:03 -0700440 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 public void setHorizontalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 }
443
444 /**
Steve Block4e584df2012-04-24 23:12:47 +0100445 * Specifies whether the vertical scrollbar has overlay style.
446 *
Paul Millerc8694a02015-06-05 11:23:03 -0700447 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700448 * @param overlay {@code true} if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 */
Paul Millerc8694a02015-06-05 11:23:03 -0700450 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 public void setVerticalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 }
453
454 /**
Steve Block4e584df2012-04-24 23:12:47 +0100455 * Gets whether horizontal scrollbar has overlay style.
456 *
Paul Millerc8694a02015-06-05 11:23:03 -0700457 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700458 * @return {@code true}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 */
Paul Millerc8694a02015-06-05 11:23:03 -0700460 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 public boolean overlayHorizontalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700462 // The old implementation defaulted to true, so return true for consistency
463 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 }
465
466 /**
Steve Block4e584df2012-04-24 23:12:47 +0100467 * Gets whether vertical scrollbar has overlay style.
468 *
Paul Millerc8694a02015-06-05 11:23:03 -0700469 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700470 * @return {@code false}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 */
Paul Millerc8694a02015-06-05 11:23:03 -0700472 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 public boolean overlayVerticalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700474 // The old implementation defaulted to false, so return false for consistency
475 return false;
Mike Reede8853fc2009-09-04 14:01:48 -0400476 }
477
Michael Kolbe54f6652011-03-16 09:11:51 -0700478 /**
Steve Block4e584df2012-04-24 23:12:47 +0100479 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700480 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700481 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400482 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400483 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700484 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100485 @UnsupportedAppUsage
Michael Kolb73980a92010-08-05 16:32:51 -0700486 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100487 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000488 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 }
490
491 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -0700492 * Gets the SSL certificate for the main top-level page or {@code null} if there is
Steve Block4e584df2012-04-24 23:12:47 +0100493 * no certificate (the site is not secure).
494 *
495 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 */
Nate Fischer3442c742017-09-08 17:02:00 -0700497 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100499 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000500 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
502
503 /**
504 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400505 *
506 * @deprecated Calling this function has no useful effect, and will be
507 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400509 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100511 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000512 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 }
514
515 //-------------------------------------------------------------------------
516 // Methods called by activity
517 //-------------------------------------------------------------------------
518
519 /**
Steve Block32fe4102012-07-17 16:29:11 +0100520 * Sets a username and password pair for the specified host. This data is
Nate Fischerffb81c42016-09-26 12:35:47 -0700521 * used by the WebView to autocomplete username and password fields in web
Steve Block32fe4102012-07-17 16:29:11 +0100522 * forms. Note that this is unrelated to the credentials used for HTTP
523 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100524 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000525 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100526 * @param username the username for the given host
527 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100528 * @see WebViewDatabase#clearUsernamePassword
529 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800530 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800532 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100534 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000535 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 }
537
538 /**
Hui Shu433fb932016-08-29 11:49:46 -0700539 * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase}
540 * instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 *
Steve Block46ce1db2012-07-17 16:43:00 +0100542 * @param host the host to which the credentials apply
543 * @param realm the realm to which the credentials apply
544 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100545 * @param password the password
Nate Fischerc7edfb02016-09-23 15:59:21 -0700546 * @deprecated Use {@link WebViewDatabase#setHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700548 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 public void setHttpAuthUsernamePassword(String host, String realm,
550 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100551 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000552 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 }
554
555 /**
Hui Shu433fb932016-08-29 11:49:46 -0700556 * Retrieves HTTP authentication credentials for a given host and realm from the {@link
557 * WebViewDatabase} instance.
Steve Block46ce1db2012-07-17 16:43:00 +0100558 * @param host the host to which the credentials apply
559 * @param realm the realm to which the credentials apply
560 * @return the credentials as a String array, if found. The first element
Nate Fischer0a6140d2017-09-05 12:37:49 -0700561 * is the username and the second element is the password. {@code null} if
Steve Block46ce1db2012-07-17 16:43:00 +0100562 * no credentials are found.
Nate Fischerc7edfb02016-09-23 15:59:21 -0700563 * @deprecated Use {@link WebViewDatabase#getHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700565 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700566 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100568 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000569 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400570 }
571
572 /**
Steve Block4e584df2012-04-24 23:12:47 +0100573 * Destroys the internal state of this WebView. This method should be called
574 * after this WebView has been removed from the view system. No other
575 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 */
577 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100578 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000579 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
581
582 /**
583 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100584 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100585 *
586 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400587 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100589 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100590 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 public static void enablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700592 // noop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
594
595 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100596 * Disables platform notifications of data state and proxy changes.
597 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100598 *
599 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400600 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100602 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100603 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 public static void disablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700605 // noop
Feng Qianb3081372009-06-29 15:55:18 -0700606 }
607
608 /**
Primiano Tucci24426752013-09-05 12:01:51 +0100609 * Used only by internal tests to free up memory.
610 *
611 * @hide
612 */
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100613 @UnsupportedAppUsage
Primiano Tucci24426752013-09-05 12:01:51 +0100614 public static void freeMemoryForTests() {
Primiano Tucci24426752013-09-05 12:01:51 +0100615 getFactory().getStatics().freeMemoryForTests();
616 }
617
618 /**
Steve Block4e584df2012-04-24 23:12:47 +0100619 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000620 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100622 *
623 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 */
625 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100626 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000627 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 }
629
630 /**
Steve Block4e584df2012-04-24 23:12:47 +0100631 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
633 * method no longer stores the display data for this WebView. The previous
634 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400635 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100636 *
637 * @param outState the Bundle to store this WebView's state
Nate Fischer3442c742017-09-08 17:02:00 -0700638 * @return the same copy of the back/forward list used to save the state, {@code null} if the
639 * method fails.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 */
Nate Fischer3442c742017-09-08 17:02:00 -0700641 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100643 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000644 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 }
646
647 /**
Steve Block4e584df2012-04-24 23:12:47 +0100648 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100650 * @param b a Bundle to store the display data
651 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 * overwritten with this WebView's picture data.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700653 * @return {@code true} if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100654 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400655 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100657 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100658 @UnsupportedAppUsage
Patrick Scottda9a22b2010-04-08 08:32:52 -0400659 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100660 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000661 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 }
663
664 /**
Steve Block4e584df2012-04-24 23:12:47 +0100665 * Restores the display data that was saved in {@link #savePicture}. Used in
666 * conjunction with {@link #restoreState}. Note that this will not work if
667 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700668 *
Steve Block4e584df2012-04-24 23:12:47 +0100669 * @param b a Bundle containing the saved display data
670 * @param src the file where the picture data was stored
Nate Fischer0a6140d2017-09-05 12:37:49 -0700671 * @return {@code true} if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100672 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400673 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100675 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +0100676 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100678 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000679 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700680 }
681
682 /**
Steve Block42499062012-07-17 15:34:46 +0100683 * Restores the state of this WebView from the given Bundle. This method is
684 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
685 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100686 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400687 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400689 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100690 *
691 * @param inState the incoming Bundle of state
Nate Fischer0a6140d2017-09-05 12:37:49 -0700692 * @return the restored back/forward list or {@code null} if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 */
Nate Fischer3442c742017-09-08 17:02:00 -0700694 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100696 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000697 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 }
699
700 /**
Steve Block4e584df2012-04-24 23:12:47 +0100701 * Loads the given URL with the specified additional HTTP headers.
Bo Liue29d3132016-04-22 16:23:22 -0700702 * <p>
703 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100704 *
705 * @param url the URL of the resource to load
706 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100707 * HTTP request for this URL, specified as a map from name to
708 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100709 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100710 * controlling caching, accept types or the User-Agent, their
Nate Fischerffb81c42016-09-26 12:35:47 -0700711 * values may be overridden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800712 */
Steve Blockf71dea02011-08-01 12:29:14 +0100713 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100714 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000715 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800716 }
717
718 /**
Steve Block4e584df2012-04-24 23:12:47 +0100719 * Loads the given URL.
Bo Liue29d3132016-04-22 16:23:22 -0700720 * <p>
721 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100722 *
723 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 */
725 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100726 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000727 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 }
729
730 /**
Steve Block4e584df2012-04-24 23:12:47 +0100731 * Loads the URL with postData using "POST" method into this WebView. If url
Hui Shuc60ad9c2014-02-05 09:30:36 -0800732 * is not a network URL, it will be loaded with {@link #loadUrl(String)}
733 * instead, ignoring the postData param.
Cary Clarkd6982c92009-05-29 11:02:22 -0400734 *
Steve Block4e584df2012-04-24 23:12:47 +0100735 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100736 * @param postData the data will be passed to "POST" request, which must be
737 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700738 */
739 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100740 checkThread();
Hui Shuc60ad9c2014-02-05 09:30:36 -0800741 if (URLUtil.isNetworkUrl(url)) {
742 mProvider.postUrl(url, postData);
743 } else {
744 mProvider.loadUrl(url);
745 }
Grace Kloba57534302009-05-22 18:55:02 -0700746 }
747
748 /**
Steve Block4e584df2012-04-24 23:12:47 +0100749 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100750 * <p>
751 * Note that JavaScript's same origin policy means that script running in a
752 * page loaded using this method will be unable to access content loaded
753 * using any scheme other than 'data', including 'http(s)'. To avoid this
754 * restriction, use {@link
755 * #loadDataWithBaseURL(String,String,String,String,String)
756 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100757 * <p>
Nate Fischer867d1092018-01-04 21:57:33 -0800758 * The {@code encoding} parameter specifies whether the data is base64 or URL
Steve Block27f3e322012-07-23 10:45:59 +0100759 * encoded. If the data is base64 encoded, the value of the encoding
Torne (Richard Coles)08dc4c662019-02-13 12:15:43 -0500760 * parameter must be {@code "base64"}. HTML can be encoded with {@link
Nate Fischer867d1092018-01-04 21:57:33 -0800761 * android.util.Base64#encodeToString(byte[],int)} like so:
762 * <pre>
763 * String unencodedHtml =
764 * "&lt;html&gt;&lt;body&gt;'%28' is the code for '('&lt;/body&gt;&lt;/html&gt;";
765 * String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
766 * webView.loadData(encodedHtml, "text/html", "base64");
767 * </pre>
Torne (Richard Coles)08dc4c662019-02-13 12:15:43 -0500768 * <p class="note">
Nate Fischer867d1092018-01-04 21:57:33 -0800769 * For all other values of {@code encoding} (including {@code null}) it is assumed that the
770 * data uses ASCII encoding for octets inside the range of safe URL characters and use the
771 * standard %xx hex encoding of URLs for octets outside that range. See <a
772 * href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC 3986</a> for more information.
Torne (Richard Coles)08dc4c662019-02-13 12:15:43 -0500773 * Applications targeting {@link android.os.Build.VERSION_CODES#Q} or later must either use
774 * base64 or encode any {@code #} characters in the content as {@code %23}, otherwise they
775 * will be treated as the end of the content and the remaining text used as a document
776 * fragment identifier.
Steve Blockb19c7872011-10-10 14:09:44 +0100777 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800778 * The {@code mimeType} parameter specifies the format of the data.
779 * If WebView can't handle the specified MIME type, it will download the data.
780 * If {@code null}, defaults to 'text/html'.
781 * <p>
Steve Blockb19c7872011-10-10 14:09:44 +0100782 * The 'data' scheme URL formed by this method uses the default US-ASCII
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400783 * charset. If you need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100784 * 'data' scheme URL which explicitly specifies a charset parameter in the
785 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
786 * Note that the charset obtained from the mediatype portion of a data URL
787 * always overrides that specified in the HTML or XML document itself.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400788 * <p>
789 * Content loaded using this method will have a {@code window.origin} value
790 * of {@code "null"}. This must not be considered to be a trusted origin
791 * by the application or by any JavaScript code running inside the WebView
792 * (for example, event sources in DOM event handlers or web messages),
793 * because malicious content can also create frames with a null origin. If
794 * you need to identify the main frame's origin in a trustworthy way, you
795 * should use {@link #loadDataWithBaseURL(String,String,String,String,String)
796 * loadDataWithBaseURL()} with a valid HTTP or HTTPS base URL to set the
797 * origin.
Steve Block4e584df2012-04-24 23:12:47 +0100798 *
799 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800800 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +0100801 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 */
Nate Fischer3442c742017-09-08 17:02:00 -0700803 public void loadData(String data, @Nullable String mimeType, @Nullable String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100804 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000805 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 }
807
808 /**
Steve Block4e584df2012-04-24 23:12:47 +0100809 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100810 * the content. The base URL is used both to resolve relative URLs and when
811 * applying JavaScript's same origin policy. The historyUrl is used for the
812 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800814 * The {@code mimeType} parameter specifies the format of the data.
815 * If WebView can't handle the specified MIME type, it will download the data.
816 * If {@code null}, defaults to 'text/html'.
817 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100818 * Note that content specified in this way can access local device files
819 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
820 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100821 * <p>
822 * If the base URL uses the data scheme, this method is equivalent to
823 * calling {@link #loadData(String,String,String) loadData()} and the
Torne (Richard Coles)08dc4c662019-02-13 12:15:43 -0500824 * historyUrl is ignored, and the data will be treated as part of a data: URL,
825 * including the requirement that the content be URL-encoded or base64 encoded.
Ben Murdoch597256e2013-07-22 16:52:12 +0100826 * If the base URL uses any other scheme, then the data will be loaded into
827 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
828 * entities in the string will not be decoded.
Mikhail Naganovb29e0f62015-09-16 13:05:53 -0700829 * <p>
830 * Note that the baseUrl is sent in the 'Referer' HTTP header when
831 * requesting subresources (images, etc.) of the page loaded using this method.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400832 * <p>
833 * If a valid HTTP or HTTPS base URL is not specified in {@code baseUrl}, then
834 * content loaded using this method will have a {@code window.origin} value
835 * of {@code "null"}. This must not be considered to be a trusted origin
836 * by the application or by any JavaScript code running inside the WebView
837 * (for example, event sources in DOM event handlers or web messages),
838 * because malicious content can also create frames with a null origin. If
839 * you need to identify the main frame's origin in a trustworthy way, you
840 * should use a valid HTTP or HTTPS base URL to set the origin.
Steve Block4e584df2012-04-24 23:12:47 +0100841 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700842 * @param baseUrl the URL to use as the page's base URL. If {@code null} defaults to
Steve Block4e584df2012-04-24 23:12:47 +0100843 * 'about:blank'.
844 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800845 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +0100846 * @param encoding the encoding of the data
Nate Fischer0a6140d2017-09-05 12:37:49 -0700847 * @param historyUrl the URL to use as the history entry. If {@code null} defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000848 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 */
Nate Fischer3442c742017-09-08 17:02:00 -0700850 public void loadDataWithBaseURL(@Nullable String baseUrl, String data,
851 @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100852 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000853 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
856 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +0100857 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
Nate Fischere0938b82018-12-26 15:36:35 -0800858 * If non-null, {@code resultCallback} will be invoked with any result returned from that
Ben Murdocha5cdd512013-07-17 16:25:07 +0100859 * execution. This method must be called on the UI thread and the callback will
860 * be made on the UI thread.
Bo Liue29d3132016-04-22 16:23:22 -0700861 * <p>
862 * Compatibility note. Applications targeting {@link android.os.Build.VERSION_CODES#N} or
863 * later, JavaScript state from an empty WebView is no longer persisted across navigations like
864 * {@link #loadUrl(String)}. For example, global variables and functions defined before calling
865 * {@link #loadUrl(String)} will not exist in the loaded page. Applications should use
866 * {@link #addJavascriptInterface} instead to persist JavaScript objects across navigations.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100867 *
868 * @param script the JavaScript to execute.
869 * @param resultCallback A callback to be invoked when the script execution
870 * completes with the result of the execution (if any).
Nate Fischer0a6140d2017-09-05 12:37:49 -0700871 * May be {@code null} if no notification of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100872 */
Nate Fischer3442c742017-09-08 17:02:00 -0700873 public void evaluateJavascript(String script, @Nullable ValueCallback<String> resultCallback) {
Ben Murdocha5cdd512013-07-17 16:25:07 +0100874 checkThread();
875 mProvider.evaluateJavaScript(script, resultCallback);
876 }
877
878 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700879 * Saves the current view as a web archive.
880 *
Steve Block4e584df2012-04-24 23:12:47 +0100881 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700882 */
883 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100884 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000885 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700886 }
887
888 /**
889 * Saves the current view as a web archive.
890 *
Steve Block4e584df2012-04-24 23:12:47 +0100891 * @param basename the filename where the archive should be placed
Nate Fischer0a6140d2017-09-05 12:37:49 -0700892 * @param autoname if {@code false}, takes basename to be a file. If {@code true}, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700893 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100894 * chosen according to the URL of the current page.
895 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700896 * parameter for onReceiveValue will either be the filename
Nate Fischer0a6140d2017-09-05 12:37:49 -0700897 * under which the file was saved, or {@code null} if saving the
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700898 * file failed.
899 */
Nate Fischer3442c742017-09-08 17:02:00 -0700900 public void saveWebArchive(String basename, boolean autoname, @Nullable ValueCallback<String>
901 callback) {
Steve Block51b08912011-04-27 15:04:48 +0100902 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000903 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700904 }
905
906 /**
Steve Block4e584df2012-04-24 23:12:47 +0100907 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 */
909 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100910 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000911 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913
914 /**
Steve Block4e584df2012-04-24 23:12:47 +0100915 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 */
917 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100918 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000919 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 }
921
922 /**
Steve Block4e584df2012-04-24 23:12:47 +0100923 * Gets whether this WebView has a back history item.
924 *
Nate Fischer2be201e2017-10-26 10:43:00 -0700925 * @return {@code true} if this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 */
927 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +0100928 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000929 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931
932 /**
Steve Block4e584df2012-04-24 23:12:47 +0100933 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 */
935 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +0100936 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000937 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
939
940 /**
Steve Block4e584df2012-04-24 23:12:47 +0100941 * Gets whether this WebView has a forward history item.
942 *
Nate Fischer2be201e2017-10-26 10:43:00 -0700943 * @return {@code true} if this WebView has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 */
945 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +0100946 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000947 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
949
950 /**
Steve Block4e584df2012-04-24 23:12:47 +0100951 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 */
953 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +0100954 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000955 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 }
957
958 /**
Steve Block4e584df2012-04-24 23:12:47 +0100959 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +0100961 *
962 * @param steps the negative or positive number of steps to move the
963 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 */
965 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100966 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000967 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 }
969
970 /**
Steve Block4e584df2012-04-24 23:12:47 +0100971 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 * the current item. Steps is negative if backward and positive
973 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +0100974 *
975 * @param steps the number of steps to take back or forward in the back
976 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 */
978 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100979 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000980 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400982
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700983 /**
Steve Block4e584df2012-04-24 23:12:47 +0100984 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700985 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -0700986 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +0100987 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000988 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 /**
Steve Block4e584df2012-04-24 23:12:47 +0100992 * Scrolls the contents of this WebView up by half the view size.
993 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700994 * @param top {@code true} to jump to the top of the page
995 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 */
997 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +0100998 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000999 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 /**
Steve Block4e584df2012-04-24 23:12:47 +01001003 * Scrolls the contents of this WebView down by half the page size.
1004 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001005 * @param bottom {@code true} to jump to bottom of page
1006 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 */
1008 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001009 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001010 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 }
1012
1013 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +01001014 * Posts a {@link VisualStateCallback}, which will be called when
1015 * the current state of the WebView is ready to be drawn.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001016 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001017 * <p>Because updates to the DOM are processed asynchronously, updates to the DOM may not
Tobias Sargeantb3656042015-05-13 11:23:57 +01001018 * immediately be reflected visually by subsequent {@link WebView#onDraw} invocations. The
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001019 * {@link VisualStateCallback} provides a mechanism to notify the caller when the contents of
Tobias Sargeantb3656042015-05-13 11:23:57 +01001020 * the DOM at the current time are ready to be drawn the next time the {@link WebView}
Nate Fischerf02f8462017-09-11 15:16:33 -07001021 * draws.
Tobias Sargeantb3656042015-05-13 11:23:57 +01001022 *
1023 * <p>The next draw after the callback completes is guaranteed to reflect all the updates to the
Nate Fischerffb81c42016-09-26 12:35:47 -07001024 * DOM up to the point at which the {@link VisualStateCallback} was posted, but it may also
Nate Fischerf02f8462017-09-11 15:16:33 -07001025 * contain updates applied after the callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001026 *
1027 * <p>The state of the DOM covered by this API includes the following:
1028 * <ul>
1029 * <li>primitive HTML elements (div, img, span, etc..)</li>
1030 * <li>images</li>
1031 * <li>CSS animations</li>
1032 * <li>WebGL</li>
1033 * <li>canvas</li>
1034 * </ul>
1035 * It does not include the state of:
1036 * <ul>
1037 * <li>the video tag</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001038 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001039 *
1040 * <p>To guarantee that the {@link WebView} will successfully render the first frame
1041 * after the {@link VisualStateCallback#onComplete} method has been called a set of conditions
1042 * must be met:
1043 * <ul>
1044 * <li>If the {@link WebView}'s visibility is set to {@link View#VISIBLE VISIBLE} then
1045 * the {@link WebView} must be attached to the view hierarchy.</li>
1046 * <li>If the {@link WebView}'s visibility is set to {@link View#INVISIBLE INVISIBLE}
1047 * then the {@link WebView} must be attached to the view hierarchy and must be made
1048 * {@link View#VISIBLE VISIBLE} from the {@link VisualStateCallback#onComplete} method.</li>
1049 * <li>If the {@link WebView}'s visibility is set to {@link View#GONE GONE} then the
1050 * {@link WebView} must be attached to the view hierarchy and its
1051 * {@link AbsoluteLayout.LayoutParams LayoutParams}'s width and height need to be set to fixed
1052 * values and must be made {@link View#VISIBLE VISIBLE} from the
1053 * {@link VisualStateCallback#onComplete} method.</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001054 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001055 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001056 * <p>When using this API it is also recommended to enable pre-rasterization if the {@link
Nate Fischerffb81c42016-09-26 12:35:47 -07001057 * WebView} is off screen to avoid flickering. See {@link WebSettings#setOffscreenPreRaster} for
Nate Fischerf02f8462017-09-11 15:16:33 -07001058 * more details and do consider its caveats.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001059 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001060 * @param requestId An id that will be returned in the callback to allow callers to match
1061 * requests with callbacks.
1062 * @param callback The callback to be invoked.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001063 */
Tobias Sargeantb3656042015-05-13 11:23:57 +01001064 public void postVisualStateCallback(long requestId, VisualStateCallback callback) {
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001065 checkThread();
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001066 mProvider.insertVisualStateCallback(requestId, callback);
1067 }
1068
1069 /**
Steve Block4e584df2012-04-24 23:12:47 +01001070 * Clears this WebView so that onDraw() will draw nothing but white background,
1071 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001072 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1073 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001075 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001077 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001078 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 /**
Steve Block72498ed2012-07-17 15:57:25 +01001082 * Gets a new picture that captures the current contents of this WebView.
1083 * The picture is of the entire document being displayed, and is not
1084 * limited to the area currently displayed by this WebView. Also, the
1085 * picture is a static copy and is unaffected by later changes to the
1086 * content being displayed.
1087 * <p>
1088 * Note that due to internal changes, for API levels between
1089 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1090 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1091 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001092 * <p>
1093 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1094 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
Mike Reed99a83d22018-02-26 15:42:00 -05001095 * additional conversion at a cost in memory and performance.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001096 *
1097 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001098 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 *
Steve Block72498ed2012-07-17 15:57:25 +01001100 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001102 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001104 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001105 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107
Cary Clarkd6982c92009-05-29 11:02:22 -04001108 /**
Selim Gurun23a1af62014-03-14 16:52:45 -07001109 * @deprecated Use {@link #createPrintDocumentAdapter(String)} which requires user
1110 * to provide a print document name.
1111 */
1112 @Deprecated
1113 public PrintDocumentAdapter createPrintDocumentAdapter() {
1114 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001115 return mProvider.createPrintDocumentAdapter("default");
1116 }
1117
1118 /**
Nate Fischerffb81c42016-09-26 12:35:47 -07001119 * Creates a PrintDocumentAdapter that provides the content of this WebView for printing.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001120 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001121 * The adapter works by converting the WebView contents to a PDF stream. The WebView cannot
Selim Gurunda7d6422013-09-06 14:39:05 -07001122 * be drawn during the conversion process - any such draws are undefined. It is recommended
Nate Fischerffb81c42016-09-26 12:35:47 -07001123 * to use a dedicated off screen WebView for the printing. If necessary, an application may
Selim Gurunda7d6422013-09-06 14:39:05 -07001124 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1125 * wrapped around the object returned and observing the onStart and onFinish methods. See
1126 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun23a1af62014-03-14 16:52:45 -07001127 *
1128 * @param documentName The user-facing name of the printed document. See
1129 * {@link android.print.PrintDocumentInfo}
Selim Gurun2167c0b2013-08-05 15:23:09 -07001130 */
Selim Gurun23a1af62014-03-14 16:52:45 -07001131 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName) {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001132 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001133 return mProvider.createPrintDocumentAdapter(documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -07001134 }
1135
1136 /**
Steve Block4e584df2012-04-24 23:12:47 +01001137 * Gets the current scale of this WebView.
1138 *
1139 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001140 *
1141 * @deprecated This method is prone to inaccuracy due to race conditions
1142 * between the web rendering and UI threads; prefer
1143 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001145 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001146 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001148 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001149 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001150 }
1151
1152 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001153 * Sets the initial scale for this WebView. 0 means default.
1154 * The behavior for the default scale depends on the state of
1155 * {@link WebSettings#getUseWideViewPort()} and
1156 * {@link WebSettings#getLoadWithOverviewMode()}.
1157 * If the content fits into the WebView control by width, then
Nate Fischerffb81c42016-09-26 12:35:47 -07001158 * the zoom is set to 100%. For wide content, the behavior
Mikhail Naganov00303362013-09-02 10:57:04 +01001159 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001160 * If its value is {@code true}, the content will be zoomed out to be fit
Mikhail Naganov00303362013-09-02 10:57:04 +01001161 * by width into the WebView control, otherwise not.
1162 *
1163 * If initial scale is greater than 0, WebView starts with this value
1164 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001165 * Please note that unlike the scale properties in the viewport meta tag,
1166 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 *
Steve Block4e584df2012-04-24 23:12:47 +01001168 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 */
1170 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001171 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001172 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 }
1174
1175 /**
Steve Block4e584df2012-04-24 23:12:47 +01001176 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 * result in the zoom widget appearing on the screen to control the zoom
1178 * level of this WebView.
1179 */
1180 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001181 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001182 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 }
1184
1185 /**
Steve Block4e584df2012-04-24 23:12:47 +01001186 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1187 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1188 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1189 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1190 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001192 * 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 -08001193 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001194 * 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 -08001195 * a child node. If a phone number is found, the HitTestResult type is set
1196 * to PHONE_TYPE and the phone number is set in the "extra" field of
1197 * HitTestResult. If a map address is found, the HitTestResult type is set
1198 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1199 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1200 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1201 * HitTestResult type is set to UNKNOWN_TYPE.
1202 */
1203 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001204 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001205 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001206 }
1207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 /**
Steve Block4e584df2012-04-24 23:12:47 +01001209 * Requests the anchor or image element URL at the last tapped point.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001210 * If hrefMsg is {@code null}, this method returns immediately and does not
Cary Clark861368a2010-12-15 11:24:37 -05001211 * dispatch hrefMsg to its target. If the tapped point hits an image,
1212 * an anchor, or an image in an anchor, the message associates
1213 * strings in named keys in its data. The value paired with the key
1214 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001215 *
Steve Block4e584df2012-04-24 23:12:47 +01001216 * @param hrefMsg the message to be dispatched with the result of the
1217 * request. The message data contains three keys. "url"
1218 * returns the anchor's href attribute. "title" returns the
1219 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 */
Nate Fischer3442c742017-09-08 17:02:00 -07001221 public void requestFocusNodeHref(@Nullable Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001222 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001223 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 /**
Steve Block4e584df2012-04-24 23:12:47 +01001227 * Requests the URL of the image last touched by the user. msg will be sent
1228 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001229 *
Steve Block4e584df2012-04-24 23:12:47 +01001230 * @param msg the message to be dispatched with the result of the request
Nate Fischer0a6140d2017-09-05 12:37:49 -07001231 * as the data member with "url" as key. The result can be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 */
1233 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001234 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001235 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001236 }
1237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 /**
Steve Block4e584df2012-04-24 23:12:47 +01001239 * 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 -08001240 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001241 * that URL has begun, the current page may not have changed.
1242 *
1243 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001245 @InspectableProperty(hasAttributeId = false)
John Reck926cf562012-06-14 10:00:31 -07001246 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001248 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001249 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 /**
Steve Block4e584df2012-04-24 23:12:47 +01001253 * Gets the original URL for the current page. This is not always the same
1254 * as the URL passed to WebViewClient.onPageStarted because although the
1255 * load for that URL has begun, the current page may not have changed.
1256 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001258 *
1259 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001261 @InspectableProperty(hasAttributeId = false)
John Reck926cf562012-06-14 10:00:31 -07001262 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001264 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001265 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 }
1267
1268 /**
Steve Block4e584df2012-04-24 23:12:47 +01001269 * 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 -08001270 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001271 *
1272 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001274 @InspectableProperty(hasAttributeId = false)
John Reck926cf562012-06-14 10:00:31 -07001275 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001277 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001278 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 }
1280
1281 /**
Steve Block4e584df2012-04-24 23:12:47 +01001282 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001284 *
1285 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001287 @InspectableProperty(hasAttributeId = false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001289 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001290 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 }
1292
1293 /**
Steve Block4e584df2012-04-24 23:12:47 +01001294 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001295 * a URL on this site's server pointing to the standard location of a
1296 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001297 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001298 * @hide
1299 */
Mathew Inwood62d83fb2018-08-16 19:09:48 +01001300 @UnsupportedAppUsage
Patrick Scott2ba12622009-08-04 13:20:05 -04001301 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001302 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001303 }
1304
1305 /**
Steve Block4e584df2012-04-24 23:12:47 +01001306 * Gets the progress for the current page.
1307 *
1308 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001310 @InspectableProperty(hasAttributeId = false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001312 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001313 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 /**
Steve Block4e584df2012-04-24 23:12:47 +01001317 * Gets the height of the HTML content.
1318 *
1319 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 */
Ashley Rose22f0d532019-02-04 19:29:03 -05001321 @InspectableProperty(hasAttributeId = false)
John Reck926cf562012-06-14 10:00:31 -07001322 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001324 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001325 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 }
1327
1328 /**
Steve Block4e584df2012-04-24 23:12:47 +01001329 * Gets the width of the HTML content.
1330 *
1331 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001332 * @hide
1333 */
John Reck926cf562012-06-14 10:00:31 -07001334 @ViewDebug.ExportedProperty(category = "webview")
Mathew Inwood62d83fb2018-08-16 19:09:48 +01001335 @UnsupportedAppUsage
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001336 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001337 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001338 }
1339
1340 /**
Steve Block4e584df2012-04-24 23:12:47 +01001341 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1342 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001343 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 */
1345 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001346 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001347 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 }
1349
1350 /**
Steve Block4e584df2012-04-24 23:12:47 +01001351 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001352 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 */
1354 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001355 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001356 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 }
1358
1359 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001360 * Does a best-effort attempt to pause any processing that can be paused
1361 * safely, such as animations and geolocation. Note that this call
1362 * does not pause JavaScript. To pause JavaScript globally, use
1363 * {@link #pauseTimers}.
1364 *
1365 * To resume WebView, call {@link #onResume}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001366 */
1367 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001368 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001369 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001370 }
1371
1372 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001373 * Resumes a WebView after a previous call to {@link #onPause}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001374 */
1375 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001376 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001377 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001378 }
1379
1380 /**
Steve Block4e584df2012-04-24 23:12:47 +01001381 * Gets whether this WebView is paused, meaning onPause() was called.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001382 * Calling onResume() sets the paused state back to {@code false}.
Steve Block4e584df2012-04-24 23:12:47 +01001383 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001384 * @hide
1385 */
Mathew Inwood62d83fb2018-08-16 19:09:48 +01001386 @UnsupportedAppUsage
Mike Reedd205d5b2009-05-27 11:02:29 -04001387 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001388 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001389 }
1390
1391 /**
Steve Block4e584df2012-04-24 23:12:47 +01001392 * Informs this WebView that memory is low so that it can free any available
1393 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001394 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1395 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001396 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001397 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001398 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001399 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001400 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001401 }
1402
1403 /**
Steve Block4e584df2012-04-24 23:12:47 +01001404 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001405 * this will clear the cache for all WebViews used.
1406 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001407 * @param includeDiskFiles if {@code false}, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 */
1409 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001410 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001411 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 }
1413
1414 /**
Steve Block219dfa42012-07-20 10:31:21 +01001415 * Removes the autocomplete popup from the currently focused form field, if
1416 * present. Note this only affects the display of the autocomplete popup,
1417 * it does not remove any saved form data from this WebView's store. To do
1418 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 */
1420 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001421 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001422 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 }
1424
1425 /**
Steve Block4e584df2012-04-24 23:12:47 +01001426 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 */
1428 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001429 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001430 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 }
1432
1433 /**
Steve Block4e584df2012-04-24 23:12:47 +01001434 * Clears the SSL preferences table stored in response to proceeding with
1435 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 */
1437 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001438 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001439 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 }
1441
1442 /**
Selim Gurunee89ab42014-06-13 10:53:55 -07001443 * Clears the client certificate preferences stored in response
Nate Fischerffb81c42016-09-26 12:35:47 -07001444 * to proceeding/cancelling client cert requests. Note that WebView
Torne (Richard Coles)01eb1282018-06-20 15:31:49 -04001445 * automatically clears these preferences when the system keychain is updated.
1446 * The preferences are shared by all the WebViews that are created by the embedder application.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001447 *
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001448 * @param onCleared A runnable to be invoked when client certs are cleared.
Nate Fischer3442c742017-09-08 17:02:00 -07001449 * The runnable will be called in UI thread.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001450 */
Nate Fischer3442c742017-09-08 17:02:00 -07001451 public static void clearClientCertPreferences(@Nullable Runnable onCleared) {
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001452 getFactory().getStatics().clearClientCertPreferences(onCleared);
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001453 }
1454
1455 /**
Nate Fischer2b108d82017-08-21 17:59:55 -07001456 * Starts Safe Browsing initialization.
Nate Fischer471891d2017-07-18 19:15:52 -07001457 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001458 * URL loads are not guaranteed to be protected by Safe Browsing until after {@code callback} is
1459 * invoked with {@code true}. Safe Browsing is not fully supported on all devices. For those
1460 * devices {@code callback} will receive {@code false}.
Nate Fischer471891d2017-07-18 19:15:52 -07001461 * <p>
Nate Fischerfb92ee12018-01-18 12:01:19 -08001462 * This should not be called if Safe Browsing has been disabled by manifest tag or {@link
1463 * WebSettings#setSafeBrowsingEnabled}. This prepares resources used for Safe Browsing.
Nate Fischer471891d2017-07-18 19:15:52 -07001464 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001465 * This should be called with the Application Context (and will always use the Application
1466 * context to do its work regardless).
Nate Fischer471891d2017-07-18 19:15:52 -07001467 *
Nate Fischer3ca196a2017-07-12 18:45:03 -07001468 * @param context Application Context.
Nate Fischer2b108d82017-08-21 17:59:55 -07001469 * @param callback will be called on the UI thread with {@code true} if initialization is
1470 * successful, {@code false} otherwise.
Nate Fischer0e72c182017-05-30 11:25:17 -07001471 */
Nate Fischer65e3be02018-03-01 00:55:35 -08001472 public static void startSafeBrowsing(@NonNull Context context,
Nate Fischer3442c742017-09-08 17:02:00 -07001473 @Nullable ValueCallback<Boolean> callback) {
Nate Fischer0e72c182017-05-30 11:25:17 -07001474 getFactory().getStatics().initSafeBrowsing(context, callback);
1475 }
1476
1477 /**
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001478 * Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks.
1479 * The list is global for all the WebViews.
Selim Gurun89e93592017-07-28 10:33:58 -07001480 * <p>
1481 * Each rule should take one of these:
1482 * <table>
1483 * <tr><th> Rule </th> <th> Example </th> <th> Matches Subdomain</th> </tr>
Nate Fischerfbebfa92017-08-29 16:17:22 -07001484 * <tr><td> HOSTNAME </td> <td> example.com </td> <td> Yes </td> </tr>
1485 * <tr><td> .HOSTNAME </td> <td> .example.com </td> <td> No </td> </tr>
1486 * <tr><td> IPV4_LITERAL </td> <td> 192.168.1.1 </td> <td> No </td></tr>
1487 * <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 -07001488 * </table>
1489 * <p>
1490 * All other rules, including wildcards, are invalid.
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001491 * <p>
1492 * The correct syntax for hosts is defined by <a
1493 * href="https://tools.ietf.org/html/rfc3986#section-3.2.2">RFC 3986</a>.
Nate Fischerbf158ec2017-06-27 22:52:20 -07001494 *
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001495 * @param hosts the list of hosts
1496 * @param callback will be called with {@code true} if hosts are successfully added to the
1497 * whitelist. It will be called with {@code false} if any hosts are malformed. The callback
1498 * will be run on the UI thread
Nate Fischerbf158ec2017-06-27 22:52:20 -07001499 */
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001500 public static void setSafeBrowsingWhitelist(@NonNull List<String> hosts,
Nate Fischerd6385d32017-07-17 12:58:18 -07001501 @Nullable ValueCallback<Boolean> callback) {
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001502 getFactory().getStatics().setSafeBrowsingWhitelist(hosts, callback);
Nate Fischerbf158ec2017-06-27 22:52:20 -07001503 }
1504
1505 /**
Nate Fischer3898ac12017-08-09 23:02:36 -07001506 * Returns a URL pointing to the privacy policy for Safe Browsing reporting.
1507 *
1508 * @return the url pointing to a privacy policy document which can be displayed to users.
1509 */
1510 @NonNull
1511 public static Uri getSafeBrowsingPrivacyPolicyUrl() {
1512 return getFactory().getStatics().getSafeBrowsingPrivacyPolicyUrl();
1513 }
1514
1515 /**
Steve Block4e584df2012-04-24 23:12:47 +01001516 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 * back/forward list for use in querying each item in the history stack.
1518 * This is a copy of the private WebBackForwardList so it contains only a
1519 * snapshot of the current state. Multiple calls to this method may return
1520 * different objects. The object returned from this method will not be
1521 * updated to reflect any new state.
1522 */
1523 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001524 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001525 return mProvider.copyBackForwardList();
1526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 }
1528
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001529 /**
Steve Block4e584df2012-04-24 23:12:47 +01001530 * Registers the listener to be notified as find-on-page operations
1531 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001532 *
Steve Block4e584df2012-04-24 23:12:47 +01001533 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001534 */
1535 public void setFindListener(FindListener listener) {
1536 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001537 setupFindListenerIfNeeded();
1538 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001539 }
1540
1541 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001542 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001543 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001544 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1545 * has not been called yet, or if {@link #clearMatches} has been called since the
1546 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 *
Steve Block4e584df2012-04-24 23:12:47 +01001548 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001549 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 */
1551 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001552 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001553 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 }
1555
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001556 /**
Steve Block4e584df2012-04-24 23:12:47 +01001557 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001558 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001559 *
Steve Block4e584df2012-04-24 23:12:47 +01001560 * @param find the string to find
Nate Fischerffb81c42016-09-26 12:35:47 -07001561 * @return the number of occurrences of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001562 * @deprecated {@link #findAllAsync} is preferred.
1563 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001565 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001567 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001568 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001569 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 }
1571
Cary Clark3403eb32010-03-03 10:05:16 -05001572 /**
Steve Block4e584df2012-04-24 23:12:47 +01001573 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001574 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001575 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001576 *
Steve Block4e584df2012-04-24 23:12:47 +01001577 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001578 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001579 */
1580 public void findAllAsync(String find) {
1581 checkThread();
1582 mProvider.findAllAsync(find);
1583 }
1584
1585 /**
Steve Block4e584df2012-04-24 23:12:47 +01001586 * Starts an ActionMode for finding text in this WebView. Only works if this
1587 * WebView is attached to the view system.
1588 *
1589 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001590 * Otherwise, the last String searched for in this WebView will
1591 * be used to start.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001592 * @param showIme if {@code true}, show the IME, assuming the user will begin typing.
1593 * If {@code false} and text is non-null, perform a find all.
1594 * @return {@code true} if the find dialog is shown, {@code false} otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001595 * @deprecated This method does not work reliably on all Android versions;
1596 * implementing a custom find dialog using WebView.findAllAsync()
1597 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001598 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001599 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -07001600 public boolean showFindDialog(@Nullable String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001601 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001602 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001603 }
1604
1605 /**
Torne (Richard Coles)aa68ab82019-06-04 14:14:05 -04001606 * Gets the first substring which appears to be the address of a physical
1607 * location. Only addresses in the United States can be detected, which
1608 * must consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001609 * <ul>
1610 * <li>a house number</li>
1611 * <li>a street name</li>
1612 * <li>a street type (Road, Circle, etc), either spelled out or
1613 * abbreviated</li>
1614 * <li>a city name</li>
1615 * <li>a state or territory, either spelled out or two-letter abbr</li>
1616 * <li>an optional 5 digit or 9 digit zip code</li>
1617 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 * All names must be correctly capitalized, and the zip code, if present,
1619 * must be valid for the state. The street type must be a standard USPS
1620 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001621 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 *
Torne (Richard Coles)aa68ab82019-06-04 14:14:05 -04001624 * <p class="note"><b>Note:</b> This function is deprecated and should be
1625 * avoided on all API levels, as it cannot detect addresses outside of the
1626 * United States and has a high rate of false positives. On API level
1627 * {@link android.os.Build.VERSION_CODES#O_MR1} and earlier, it also causes
1628 * the entire WebView implementation to be loaded and initialized, which
1629 * can throw {@link android.util.AndroidRuntimeException} or other exceptions
1630 * if the WebView implementation is currently being updated.
1631 *
Steve Block4e584df2012-04-24 23:12:47 +01001632 * @param addr the string to search for addresses
Nate Fischer0a6140d2017-09-05 12:37:49 -07001633 * @return the address, or if no address is found, {@code null}
Torne (Richard Coles)aa68ab82019-06-04 14:14:05 -04001634 * @deprecated This method is superseded by {@link TextClassifier#generateLinks(
Jan Althaus003889a2018-04-04 15:29:10 +02001635 * android.view.textclassifier.TextLinks.Request)}. Avoid using this method even when targeting
1636 * API levels where no alternative is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 */
Nate Fischer3442c742017-09-08 17:02:00 -07001638 @Nullable
Jan Althaus003889a2018-04-04 15:29:10 +02001639 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 public static String findAddress(String addr) {
Tobias Sargeantf4d85d82018-01-05 14:34:38 +00001641 if (addr == null) {
1642 throw new NullPointerException("addr is null");
1643 }
1644 return FindAddress.findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 }
1646
Victoria Lease0b8413b2012-03-26 13:04:10 -07001647 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -07001648 * For apps targeting the L release, WebView has a new default behavior that reduces
1649 * memory footprint and increases performance by intelligently choosing
1650 * the portion of the HTML document that needs to be drawn. These
1651 * optimizations are transparent to the developers. However, under certain
1652 * circumstances, an App developer may want to disable them:
Ben Murdoch574fa342015-01-07 14:20:45 +00001653 * <ol>
1654 * <li>When an app uses {@link #onDraw} to do own drawing and accesses portions
1655 * of the page that is way outside the visible portion of the page.</li>
1656 * <li>When an app uses {@link #capturePicture} to capture a very large HTML document.
1657 * Note that capturePicture is a deprecated API.</li>
1658 * </ol>
Selim Gurun17d1adb2014-08-27 11:22:26 -07001659 * Enabling drawing the entire HTML document has a significant performance
1660 * cost. This method should be called before any WebViews are created.
Bo Liu9f3ed852014-07-18 10:03:12 -07001661 */
1662 public static void enableSlowWholeDocumentDraw() {
1663 getFactory().getStatics().enableSlowWholeDocumentDraw();
1664 }
1665
1666 /**
Steve Block4e584df2012-04-24 23:12:47 +01001667 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001668 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 */
1670 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001671 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001672 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 }
1674
1675 /**
Steve Block4e584df2012-04-24 23:12:47 +01001676 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 * message object will be dispatched with arg1 being set to 1 if images
1678 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001679 *
1680 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 */
1682 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001683 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001684 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 }
1686
1687 /**
Steve Block4e584df2012-04-24 23:12:47 +01001688 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001690 *
1691 * @param client an implementation of WebViewClient
Nate Fischer6e585842016-09-29 18:30:58 -07001692 * @see #getWebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 */
1694 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001695 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001696 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001697 }
1698
1699 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001700 * Gets the WebViewClient.
1701 *
1702 * @return the WebViewClient, or a default client if not yet set
1703 * @see #setWebViewClient
1704 */
1705 public WebViewClient getWebViewClient() {
1706 checkThread();
1707 return mProvider.getWebViewClient();
1708 }
1709
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001710
1711 /**
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001712 * Gets a handle to the WebView renderer process associated with this WebView.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001713 *
1714 * <p>In {@link android.os.Build.VERSION_CODES#O} and above, WebView may
1715 * run in "multiprocess" mode. In multiprocess mode, rendering of web
1716 * content is performed by a sandboxed renderer process separate to the
1717 * application process. This renderer process may be shared with other
1718 * WebViews in the application, but is not shared with other application
1719 * processes.
1720 *
1721 * <p>If WebView is running in multiprocess mode, this method returns a
1722 * handle to the renderer process associated with the WebView, which can
1723 * be used to control the renderer process.
1724 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001725 * @return the {@link WebViewRenderProcess} renderer handle associated
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001726 * with this {@link WebView}, or {@code null} if
1727 * WebView is not runing in multiprocess mode.
1728 */
1729 @Nullable
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001730 public WebViewRenderProcess getWebViewRenderProcess() {
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001731 checkThread();
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001732 return mProvider.getWebViewRenderProcess();
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001733 }
1734
1735 /**
1736 * Sets the renderer client object associated with this WebView.
1737 *
1738 * <p>The renderer client encapsulates callbacks relevant to WebView renderer
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001739 * state. See {@link WebViewRenderProcessClient} for details.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001740 *
1741 * <p>Although many WebView instances may share a single underlying
1742 * renderer, and renderers may live either in the application
1743 * process, or in a sandboxed process that is isolated from the
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001744 * application process, instances of {@link WebViewRenderProcessClient}
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001745 * are set per-WebView. Callbacks represent renderer events from
1746 * the perspective of this WebView, and may or may not be correlated
1747 * with renderer events affecting other WebViews.
1748 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001749 * @param executor the Executor on which {@link WebViewRenderProcessClient}
1750 * callbacks will execute.
1751 * @param webViewRenderProcessClient the {@link WebViewRenderProcessClient}
1752 * object.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001753 */
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001754 public void setWebViewRenderProcessClient(
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001755 @NonNull @CallbackExecutor Executor executor,
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001756 @NonNull WebViewRenderProcessClient webViewRenderProcessClient) {
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001757 checkThread();
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001758 mProvider.setWebViewRenderProcessClient(
1759 executor, webViewRenderProcessClient);
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001760 }
1761
1762 /**
1763 * Sets the renderer client object associated with this WebView.
1764 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001765 * See {@link #setWebViewRenderProcessClient(Executor,WebViewRenderProcessClient)} for details.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001766 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001767 * <p> {@link WebViewRenderProcessClient} callbacks will run on the thread that this WebView was
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001768 * initialized on.
1769 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001770 * @param webViewRenderProcessClient the {@link WebViewRenderProcessClient} object.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001771 */
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001772 public void setWebViewRenderProcessClient(
1773 @Nullable WebViewRenderProcessClient webViewRenderProcessClient) {
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001774 checkThread();
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001775 mProvider.setWebViewRenderProcessClient(null, webViewRenderProcessClient);
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001776 }
1777
1778 /**
1779 * Gets the renderer client object associated with this WebView.
1780 *
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001781 * @return the {@link WebViewRenderProcessClient} object associated with this WebView, if one
1782 * has been set via {@link #setWebViewRenderProcessClient(WebViewRenderProcessClient)}
1783 * or {@code null} otherwise.
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001784 */
1785 @Nullable
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001786 public WebViewRenderProcessClient getWebViewRenderProcessClient() {
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001787 checkThread();
Tobias Sargeant39b68ef2019-03-07 21:29:31 +00001788 return mProvider.getWebViewRenderProcessClient();
Tobias Sargeant740b53f2019-01-14 21:49:15 +00001789 }
1790
Nate Fischer6e585842016-09-29 18:30:58 -07001791 /**
Steve Block4e584df2012-04-24 23:12:47 +01001792 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 * the rendering engine, and should be downloaded instead. This will replace
1794 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001795 *
1796 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 */
1798 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001799 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001800 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 }
1802
1803 /**
Steve Block4e584df2012-04-24 23:12:47 +01001804 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001805 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001807 *
1808 * @param client an implementation of WebChromeClient
Nate Fischer6e585842016-09-29 18:30:58 -07001809 * @see #getWebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 */
1811 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001812 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001813 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001814 }
1815
1816 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001817 * Gets the chrome handler.
1818 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001819 * @return the WebChromeClient, or {@code null} if not yet set
Nate Fischer6e585842016-09-29 18:30:58 -07001820 * @see #setWebChromeClient
1821 */
Nate Fischer3442c742017-09-08 17:02:00 -07001822 @Nullable
Nate Fischer6e585842016-09-29 18:30:58 -07001823 public WebChromeClient getWebChromeClient() {
1824 checkThread();
1825 return mProvider.getWebChromeClient();
1826 }
1827
1828 /**
Steve Block4e584df2012-04-24 23:12:47 +01001829 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001831 *
1832 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001833 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001835 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001837 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001838 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 }
1840
1841 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001842 * Injects the supplied Java object into this WebView. The object is
1843 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001844 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001845 * accessed from JavaScript. For applications targeted to API
1846 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001847 * and above, only public methods that are annotated with
1848 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001849 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001850 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001851 * important security note below for implications.
Nate Fischer02e281a2017-08-21 12:03:58 -07001852 * <p> Note that injected objects will not appear in JavaScript until the page is next
1853 * (re)loaded. JavaScript should be enabled before injecting the object. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001854 * <pre>
1855 * class JsObject {
1856 * {@literal @}JavascriptInterface
1857 * public String toString() { return "injectedObject"; }
1858 * }
Nate Fischer02e281a2017-08-21 12:03:58 -07001859 * webview.getSettings().setJavaScriptEnabled(true);
Selim Gurune91d5be2012-09-11 16:11:22 -07001860 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001861 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1862 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001863 * <p>
1864 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001866 * <li> This method can be used to allow JavaScript to control the host
1867 * application. This is a powerful feature, but also presents a security
Scott Rowe607c17f2014-08-07 11:42:09 -07001868 * risk for apps targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or earlier.
1869 * Apps that target a version later than {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1870 * are still vulnerable if the app runs on a device running Android earlier than 4.2.
1871 * The most secure way to use this method is to target {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1872 * and to ensure the method is called only when running on Android 4.2 or later.
1873 * With these older versions, JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001874 * injected object's public fields. Use of this method in a WebView
1875 * containing untrusted content could allow an attacker to manipulate the
1876 * host application in unintended ways, executing Java code with the
1877 * permissions of the host application. Use extreme care when using this
1878 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001879 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001880 * thread of this WebView. Care is therefore required to maintain thread
Scott Rowe607c17f2014-08-07 11:42:09 -07001881 * safety.
1882 * </li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001883 * <li> The Java object's fields are not accessible.</li>
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001884 * <li> For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP}
Mikhail Naganovd380b202014-04-10 18:07:42 +01001885 * and above, methods of injected Java objects are enumerable from
1886 * JavaScript.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001887 * </ul>
1888 *
1889 * @param object the Java object to inject into this WebView's JavaScript
Nate Fischer0a6140d2017-09-05 12:37:49 -07001890 * context. {@code null} values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001891 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 */
Steve Block4cd73c52011-11-09 13:06:52 +00001893 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001894 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001895 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 }
1897
1898 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001899 * Removes a previously injected Java object from this WebView. Note that
1900 * the removal will not be reflected in JavaScript until the page is next
1901 * (re)loaded. See {@link #addJavascriptInterface}.
1902 *
1903 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001904 */
Nate Fischer3442c742017-09-08 17:02:00 -07001905 public void removeJavascriptInterface(@NonNull String name) {
Steve Block51b08912011-04-27 15:04:48 +01001906 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01001907 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001908 }
1909
1910 /**
Selim Gurun4c8093a2015-03-10 17:40:06 -07001911 * Creates a message channel to communicate with JS and returns the message
1912 * ports that represent the endpoints of this message channel. The HTML5 message
Selim Gurun0a814b62015-05-13 10:15:55 -07001913 * channel functionality is described
1914 * <a href="https://html.spec.whatwg.org/multipage/comms.html#messagechannel">here
1915 * </a>
Selim Gurun4c8093a2015-03-10 17:40:06 -07001916 *
Nate Fischerf02f8462017-09-11 15:16:33 -07001917 * <p>The returned message channels are entangled and already in started state.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001918 *
1919 * @return the two message ports that form the message channel.
1920 */
1921 public WebMessagePort[] createWebMessageChannel() {
1922 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001923 return mProvider.createWebMessageChannel();
1924 }
1925
1926 /**
1927 * Post a message to main frame. The embedded application can restrict the
1928 * messages to a certain target origin. See
Selim Gurun0a814b62015-05-13 10:15:55 -07001929 * <a href="https://html.spec.whatwg.org/multipage/comms.html#posting-messages">
1930 * HTML5 spec</a> for how target origin can be used.
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001931 * <p>
1932 * A target origin can be set as a wildcard ("*"). However this is not recommended.
1933 * See the page above for security issues.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -04001934 * <p>
1935 * Content loaded via {@link #loadData(String,String,String)} will not have a
1936 * valid origin, and thus cannot be sent messages securely. If you need to send
1937 * messages using this function, you should use
1938 * {@link #loadDataWithBaseURL(String,String,String,String,String)} with a valid
1939 * HTTP or HTTPS {@code baseUrl} to define a valid origin that can be used for
1940 * messaging.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001941 *
1942 * @param message the WebMessage
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001943 * @param targetOrigin the target origin.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001944 */
Selim Gurun26de90a2015-05-15 11:02:45 -07001945 public void postWebMessage(WebMessage message, Uri targetOrigin) {
Selim Gurun4c8093a2015-03-10 17:40:06 -07001946 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001947 mProvider.postMessageToMainFrame(message, targetOrigin);
1948 }
1949
1950 /**
Steve Block4e584df2012-04-24 23:12:47 +01001951 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001953 *
1954 * @return a WebSettings object that can be used to control this WebView's
1955 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 */
1957 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001958 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001959 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 }
1961
Jonathan Dixon3c909522012-02-28 18:45:06 +00001962 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07001963 * Enables debugging of web contents (HTML / CSS / JavaScript)
1964 * loaded into any WebViews of this application. This flag can be enabled
1965 * in order to facilitate debugging of web layouts and JavaScript
1966 * code running inside WebViews. Please refer to WebView documentation
1967 * for the debugging guide.
1968 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001969 * The default is {@code false}.
Mikhail Naganov057989e2013-09-06 16:35:25 -07001970 *
1971 * @param enabled whether to enable web contents debugging
1972 */
1973 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07001974 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
1975 }
1976
1977 /**
Steve Block4e584df2012-04-24 23:12:47 +01001978 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001979 *
Steve Block4e584df2012-04-24 23:12:47 +01001980 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001981 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001982 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001983 */
Andrei Popescu385df692009-08-13 11:59:57 +01001984 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +01001985 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08001987 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 }
1989
Jonathan Dixon3c909522012-02-28 18:45:06 +00001990 /**
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04001991 * Define the directory used to store WebView data for the current process.
1992 * The provided suffix will be used when constructing data and cache
1993 * directory paths. If this API is not called, no suffix will be used.
1994 * Each directory can be used by only one process in the application. If more
1995 * than one process in an app wishes to use WebView, only one process can use
1996 * the default directory, and other processes must call this API to define
1997 * a unique suffix.
1998 * <p>
Torne (Richard Coles)de956b72018-01-29 16:58:44 -05001999 * This means that different processes in the same application cannot directly
2000 * share WebView-related data, since the data directories must be distinct.
2001 * Applications that use this API may have to explicitly pass data between
2002 * processes. For example, login cookies may have to be copied from one
2003 * process's cookie jar to the other using {@link CookieManager} if both
2004 * processes' WebViews are intended to be logged in.
2005 * <p>
2006 * Most applications should simply ensure that all components of the app
2007 * that rely on WebView are in the same process, to avoid needing multiple
2008 * data directories. The {@link #disableWebView} method can be used to ensure
2009 * that the other processes do not use WebView by accident in this case.
2010 * <p>
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04002011 * This API must be called before any instances of WebView are created in
2012 * this process and before any other methods in the android.webkit package
2013 * are called by this process.
2014 *
2015 * @param suffix The directory name suffix to be used for the current
2016 * process. Must not contain a path separator.
2017 * @throws IllegalStateException if WebView has already been initialized
2018 * in the current process.
2019 * @throws IllegalArgumentException if the suffix contains a path separator.
2020 */
2021 public static void setDataDirectorySuffix(String suffix) {
2022 WebViewFactory.setDataDirectorySuffix(suffix);
2023 }
2024
2025 /**
2026 * Indicate that the current process does not intend to use WebView, and
2027 * that an exception should be thrown if a WebView is created or any other
2028 * methods in the android.webkit package are used.
2029 * <p>
2030 * Applications with multiple processes may wish to call this in processes
Torne (Richard Coles)de956b72018-01-29 16:58:44 -05002031 * that are not intended to use WebView to avoid accidentally incurring
2032 * the memory usage of initializing WebView in long-lived processes that
2033 * have no need for it, and to prevent potential data directory conflicts
2034 * (see {@link #setDataDirectorySuffix}).
2035 * <p>
2036 * For example, an audio player application with one process for its
2037 * activities and another process for its playback service may wish to call
2038 * this method in the playback service's {@link android.app.Service#onCreate}.
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04002039 *
2040 * @throws IllegalStateException if WebView has already been initialized
2041 * in the current process.
2042 */
2043 public static void disableWebView() {
2044 WebViewFactory.disableWebView();
2045 }
2046
2047
2048 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002049 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01002050 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00002051 */
Andrei Popescu385df692009-08-13 11:59:57 +01002052 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002053 @UnsupportedAppUsage
Steve Block51b08912011-04-27 15:04:48 +01002054 public void refreshPlugins(boolean reloadOpenPages) {
2055 checkThread();
2056 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057
Cary Clark966641a2010-03-04 08:41:56 -05002058 /**
Steve Block4e584df2012-04-24 23:12:47 +01002059 * Puts this WebView into text selection mode. Do not rely on this
2060 * functionality; it will be deprecated in the future.
2061 *
Kristian Monsenfc771652011-05-10 16:44:05 +01002062 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002063 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05002064 */
Kristian Monsenfc771652011-05-10 16:44:05 +01002065 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002066 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01002068 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07002069 }
2070
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002071 /**
2072 * @deprecated WebView no longer needs to implement
2073 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2074 */
George Mountfab67a12012-01-05 09:58:53 -08002075 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002076 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002077 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04002079
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002080 /**
2081 * @deprecated WebView no longer needs to implement
2082 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
2083 */
George Mountfab67a12012-01-05 09:58:53 -08002084 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002085 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05002086 @Deprecated
2087 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088
2089 /**
2090 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08002091 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 */
George Mountfab67a12012-01-05 09:58:53 -08002093 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00002094 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 @Deprecated
2096 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
2097 }
2098
Kristian Monsen5cc23512012-08-09 15:33:08 -04002099 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -07002100 * @deprecated Only the default case, {@code true}, will be supported in a future version.
Kristian Monsen5cc23512012-08-09 15:33:08 -04002101 */
2102 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01002104 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002105 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 }
2107
Derek Sollenberger03e48912010-05-18 17:03:42 -04002108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01002110 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002111 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 }
2113
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002114 /**
Steve Block4e584df2012-04-24 23:12:47 +01002115 * Gets the zoom controls for this WebView, as a separate View. The caller
2116 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002117 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01002118 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
2119 * built-in zoom mechanisms for the WebView, as opposed to these separate
2120 * zoom controls. The built-in mechanisms are preferred and can be enabled
2121 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07002122 *
Steve Block4e584df2012-04-24 23:12:47 +01002123 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01002124 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 */
The Android Open Source Project10592532009-03-18 17:39:46 -07002126 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002127 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01002129 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002130 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07002131 }
2132
2133 /**
Steve Block4e584df2012-04-24 23:12:47 +01002134 * Gets whether this WebView can be zoomed in.
2135 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002136 * @return {@code true} if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04002137 *
2138 * @deprecated This method is prone to inaccuracy due to race conditions
2139 * between the web rendering and UI threads; prefer
2140 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002141 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002142 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002143 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002144 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002145 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07002146 }
2147
2148 /**
Steve Block4e584df2012-04-24 23:12:47 +01002149 * Gets whether this WebView can be zoomed out.
2150 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002151 * @return {@code true} if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04002152 *
2153 * @deprecated This method is prone to inaccuracy due to race conditions
2154 * between the web rendering and UI threads; prefer
2155 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002156 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002157 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002158 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002159 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002160 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07002161 }
2162
2163 /**
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002164 * Performs a zoom operation in this WebView.
2165 *
Nate Fischerffb81c42016-09-26 12:35:47 -07002166 * @param zoomFactor the zoom factor to apply. The zoom factor will be clamped to the WebView's
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002167 * zoom limits. This value must be in the range 0.01 to 100.0 inclusive.
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002168 */
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002169 public void zoomBy(float zoomFactor) {
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002170 checkThread();
2171 if (zoomFactor < 0.01)
2172 throw new IllegalArgumentException("zoomFactor must be greater than 0.01.");
2173 if (zoomFactor > 100.0)
2174 throw new IllegalArgumentException("zoomFactor must be less than 100.");
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002175 mProvider.zoomBy(zoomFactor);
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002176 }
2177
2178 /**
Steve Block4e584df2012-04-24 23:12:47 +01002179 * Performs zoom in in this WebView.
2180 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002181 * @return {@code true} if zoom in succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 */
2183 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002184 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002185 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 }
2187
2188 /**
Steve Block4e584df2012-04-24 23:12:47 +01002189 * Performs zoom out in this WebView.
2190 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002191 * @return {@code true} if zoom out succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 */
2193 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002194 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002195 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 }
2197
Kristian Monsenfc771652011-05-10 16:44:05 +01002198 /**
2199 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002200 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01002201 */
2202 @Deprecated
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002203 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01002205 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
Cary Clarkd6982c92009-05-29 11:02:22 -04002207
John Reck926cf562012-06-14 10:00:31 -07002208 /**
John Reckf2361152012-06-14 15:23:22 -07002209 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07002210 * @hide
2211 */
2212 @Override
2213 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
2214 mProvider.dumpViewHierarchyWithProperties(out, level);
2215 }
2216
2217 /**
2218 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
2219 * @hide
2220 */
2221 @Override
2222 public View findHierarchyView(String className, int hashCode) {
2223 return mProvider.findHierarchyView(className, hashCode);
2224 }
2225
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002226 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07002227 @IntDef(prefix = { "RENDERER_PRIORITY_" }, value = {
2228 RENDERER_PRIORITY_WAIVED,
2229 RENDERER_PRIORITY_BOUND,
2230 RENDERER_PRIORITY_IMPORTANT
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002231 })
2232 @Retention(RetentionPolicy.SOURCE)
2233 public @interface RendererPriority {}
2234
2235 /**
2236 * The renderer associated with this WebView is bound with
2237 * {@link Context#BIND_WAIVE_PRIORITY}. At this priority level
2238 * {@link WebView} renderers will be strong targets for out of memory
2239 * killing.
2240 *
2241 * Use with {@link #setRendererPriorityPolicy}.
2242 */
2243 public static final int RENDERER_PRIORITY_WAIVED = 0;
2244 /**
2245 * The renderer associated with this WebView is bound with
2246 * the default priority for services.
2247 *
2248 * Use with {@link #setRendererPriorityPolicy}.
2249 */
2250 public static final int RENDERER_PRIORITY_BOUND = 1;
2251 /**
2252 * The renderer associated with this WebView is bound with
2253 * {@link Context#BIND_IMPORTANT}.
2254 *
2255 * Use with {@link #setRendererPriorityPolicy}.
2256 */
2257 public static final int RENDERER_PRIORITY_IMPORTANT = 2;
2258
2259 /**
2260 * Set the renderer priority policy for this {@link WebView}. The
2261 * priority policy will be used to determine whether an out of
2262 * process renderer should be considered to be a target for OOM
2263 * killing.
2264 *
2265 * Because a renderer can be associated with more than one
2266 * WebView, the final priority it is computed as the maximum of
2267 * any attached WebViews. When a WebView is destroyed it will
2268 * cease to be considerered when calculating the renderer
2269 * priority. Once no WebViews remain associated with the renderer,
2270 * the priority of the renderer will be reduced to
2271 * {@link #RENDERER_PRIORITY_WAIVED}.
2272 *
2273 * The default policy is to set the priority to
2274 * {@link #RENDERER_PRIORITY_IMPORTANT} regardless of visibility,
2275 * and this should not be changed unless the caller also handles
2276 * renderer crashes with
2277 * {@link WebViewClient#onRenderProcessGone}. Any other setting
2278 * will result in WebView renderers being killed by the system
2279 * more aggressively than the application.
2280 *
2281 * @param rendererRequestedPriority the minimum priority at which
2282 * this WebView desires the renderer process to be bound.
Nate Fischer0a6140d2017-09-05 12:37:49 -07002283 * @param waivedWhenNotVisible if {@code true}, this flag specifies that
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002284 * when this WebView is not visible, it will be treated as
2285 * if it had requested a priority of
2286 * {@link #RENDERER_PRIORITY_WAIVED}.
2287 */
2288 public void setRendererPriorityPolicy(
2289 @RendererPriority int rendererRequestedPriority,
2290 boolean waivedWhenNotVisible) {
2291 mProvider.setRendererPriorityPolicy(rendererRequestedPriority, waivedWhenNotVisible);
2292 }
2293
2294 /**
2295 * Get the requested renderer priority for this WebView.
2296 *
2297 * @return the requested renderer priority policy.
2298 */
Ashley Rose22f0d532019-02-04 19:29:03 -05002299 @InspectableProperty(hasAttributeId = false, enumMapping = {
Ashley Rose73abdd3c2019-03-15 17:32:56 -04002300 @InspectableProperty.EnumEntry(name = "waived", value = RENDERER_PRIORITY_WAIVED),
2301 @InspectableProperty.EnumEntry(name = "bound", value = RENDERER_PRIORITY_BOUND),
2302 @InspectableProperty.EnumEntry(name = "important", value = RENDERER_PRIORITY_IMPORTANT)
Ashley Rose22f0d532019-02-04 19:29:03 -05002303 })
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002304 @RendererPriority
2305 public int getRendererRequestedPriority() {
2306 return mProvider.getRendererRequestedPriority();
2307 }
2308
2309 /**
2310 * Return whether this WebView requests a priority of
2311 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2312 *
2313 * @return whether this WebView requests a priority of
2314 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2315 */
Ashley Rose22f0d532019-02-04 19:29:03 -05002316 @InspectableProperty(hasAttributeId = false)
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002317 public boolean getRendererPriorityWaivedWhenNotVisible() {
2318 return mProvider.getRendererPriorityWaivedWhenNotVisible();
2319 }
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002320
2321 /**
2322 * Sets the {@link TextClassifier} for this WebView.
2323 */
2324 public void setTextClassifier(@Nullable TextClassifier textClassifier) {
2325 mProvider.setTextClassifier(textClassifier);
2326 }
2327
2328 /**
2329 * Returns the {@link TextClassifier} used by this WebView.
2330 * If no TextClassifier has been set, this WebView uses the default set by the system.
2331 */
2332 @NonNull
2333 public TextClassifier getTextClassifier() {
2334 return mProvider.getTextClassifier();
2335 }
2336
Gustav Sennton265afdb2018-01-19 11:56:55 +00002337 /**
2338 * Returns the {@link ClassLoader} used to load internal WebView classes.
2339 * This method is meant for use by the WebView Support Library, there is no reason to use this
2340 * method otherwise.
2341 */
2342 @NonNull
2343 public static ClassLoader getWebViewClassLoader() {
2344 return getFactory().getWebViewClassLoader();
2345 }
2346
Gustav Sennton01673692018-01-19 12:11:25 +00002347 /**
2348 * Returns the {@link Looper} corresponding to the thread on which WebView calls must be made.
2349 */
2350 @NonNull
Gustav Sennton6abde8b2018-03-15 13:56:03 +00002351 public Looper getWebViewLooper() {
2352 return mWebViewThread;
2353 }
2354
Jonathan Dixon3c909522012-02-28 18:45:06 +00002355 //-------------------------------------------------------------------------
2356 // Interface for WebView providers
2357 //-------------------------------------------------------------------------
2358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 /**
Steve Block4e584df2012-04-24 23:12:47 +01002360 * Gets the WebViewProvider. Used by providers to obtain the underlying
Nate Fischerffb81c42016-09-26 12:35:47 -07002361 * implementation, e.g. when the application responds to
Steve Block4e584df2012-04-24 23:12:47 +01002362 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04002363 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00002364 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04002365 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002366 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002367 public WebViewProvider getWebViewProvider() {
2368 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04002369 }
2370
2371 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002372 * Callback interface, allows the provider implementation to access non-public methods
2373 * and fields, and make super-class calls in this WebView instance.
2374 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002375 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002376 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002377 public class PrivateAccess {
2378 // ---- Access to super-class methods ----
2379 public int super_getScrollBarStyle() {
2380 return WebView.super.getScrollBarStyle();
2381 }
2382
2383 public void super_scrollTo(int scrollX, int scrollY) {
2384 WebView.super.scrollTo(scrollX, scrollY);
2385 }
2386
2387 public void super_computeScroll() {
2388 WebView.super.computeScroll();
2389 }
2390
alanveebebc92012-06-15 18:59:11 -07002391 public boolean super_onHoverEvent(MotionEvent event) {
2392 return WebView.super.onHoverEvent(event);
2393 }
2394
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002395 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
Alan Viverettea54956a2015-01-07 16:05:02 -08002396 return WebView.super.performAccessibilityActionInternal(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002397 }
2398
Jonathan Dixon3c909522012-02-28 18:45:06 +00002399 public boolean super_performLongClick() {
2400 return WebView.super.performLongClick();
2401 }
2402
2403 public boolean super_setFrame(int left, int top, int right, int bottom) {
2404 return WebView.super.setFrame(left, top, right, bottom);
2405 }
2406
2407 public boolean super_dispatchKeyEvent(KeyEvent event) {
2408 return WebView.super.dispatchKeyEvent(event);
2409 }
2410
2411 public boolean super_onGenericMotionEvent(MotionEvent event) {
2412 return WebView.super.onGenericMotionEvent(event);
2413 }
2414
2415 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
2416 return WebView.super.requestFocus(direction, previouslyFocusedRect);
2417 }
2418
2419 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
2420 WebView.super.setLayoutParams(params);
2421 }
2422
Hui Shuf119c522015-10-08 10:07:13 -07002423 public void super_startActivityForResult(Intent intent, int requestCode) {
2424 WebView.super.startActivityForResult(intent, requestCode);
2425 }
2426
Jonathan Dixon3c909522012-02-28 18:45:06 +00002427 // ---- Access to non-public methods ----
2428 public void overScrollBy(int deltaX, int deltaY,
2429 int scrollX, int scrollY,
2430 int scrollRangeX, int scrollRangeY,
2431 int maxOverScrollX, int maxOverScrollY,
2432 boolean isTouchEvent) {
2433 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
2434 maxOverScrollX, maxOverScrollY, isTouchEvent);
2435 }
2436
2437 public void awakenScrollBars(int duration) {
2438 WebView.this.awakenScrollBars(duration);
2439 }
2440
2441 public void awakenScrollBars(int duration, boolean invalidate) {
2442 WebView.this.awakenScrollBars(duration, invalidate);
2443 }
2444
2445 public float getVerticalScrollFactor() {
2446 return WebView.this.getVerticalScrollFactor();
2447 }
2448
2449 public float getHorizontalScrollFactor() {
2450 return WebView.this.getHorizontalScrollFactor();
2451 }
2452
2453 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
2454 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
2455 }
2456
2457 public void onScrollChanged(int l, int t, int oldl, int oldt) {
2458 WebView.this.onScrollChanged(l, t, oldl, oldt);
2459 }
2460
2461 public int getHorizontalScrollbarHeight() {
2462 return WebView.this.getHorizontalScrollbarHeight();
2463 }
2464
Martin Kosiba9a68f822013-08-08 14:02:41 +01002465 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2466 int l, int t, int r, int b) {
2467 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2468 }
2469
Jonathan Dixon3c909522012-02-28 18:45:06 +00002470 // ---- Access to (non-public) fields ----
2471 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
2472 public void setScrollXRaw(int scrollX) {
2473 WebView.this.mScrollX = scrollX;
2474 }
2475
2476 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
2477 public void setScrollYRaw(int scrollY) {
2478 WebView.this.mScrollY = scrollY;
2479 }
2480
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002481 }
2482
Jonathan Dixon3c909522012-02-28 18:45:06 +00002483 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002484 // Package-private internal stuff
2485 //-------------------------------------------------------------------------
2486
2487 // Only used by android.webkit.FindActionModeCallback.
2488 void setFindDialogFindListener(FindListener listener) {
2489 checkThread();
2490 setupFindListenerIfNeeded();
2491 mFindListener.mFindDialogFindListener = listener;
2492 }
2493
2494 // Only used by android.webkit.FindActionModeCallback.
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002495 @UnsupportedAppUsage
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002496 void notifyFindDialogDismissed() {
2497 checkThread();
2498 mProvider.notifyFindDialogDismissed();
2499 }
2500
2501 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002502 // Private internal stuff
2503 //-------------------------------------------------------------------------
2504
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002505 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002506 private WebViewProvider mProvider;
2507
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002508 /**
2509 * In addition to the FindListener that the user may set via the WebView.setFindListener
2510 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
Mark Dolinerd0646dc2014-08-27 16:04:02 -07002511 * via this class so that the two FindListeners can potentially exist at once.
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002512 */
2513 private class FindListenerDistributor implements FindListener {
2514 private FindListener mFindDialogFindListener;
2515 private FindListener mUserFindListener;
2516
2517 @Override
2518 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2519 boolean isDoneCounting) {
2520 if (mFindDialogFindListener != null) {
2521 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2522 isDoneCounting);
2523 }
2524
2525 if (mUserFindListener != null) {
2526 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2527 isDoneCounting);
2528 }
2529 }
2530 }
2531 private FindListenerDistributor mFindListener;
2532
2533 private void setupFindListenerIfNeeded() {
2534 if (mFindListener == null) {
2535 mFindListener = new FindListenerDistributor();
2536 mProvider.setFindListener(mFindListener);
2537 }
2538 }
2539
Jonathan Dixon3c909522012-02-28 18:45:06 +00002540 private void ensureProviderCreated() {
2541 checkThread();
2542 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002543 // As this can get called during the base class constructor chain, pass the minimum
2544 // number of dependencies here; the rest are deferred to init().
2545 mProvider = getFactory().createWebView(this, new PrivateAccess());
2546 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002547 }
2548
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002549 @UnsupportedAppUsage
Torne (Richard Coles)59375a02016-07-18 18:34:02 +01002550 private static WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002551 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002552 }
2553
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002554 @UnsupportedAppUsage
Jonathan Dixon517771b2013-10-08 13:32:11 -07002555 private final Looper mWebViewThread = Looper.myLooper();
2556
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002557 @UnsupportedAppUsage
Jonathan Dixon517771b2013-10-08 13:32:11 -07002558 private void checkThread() {
2559 // Ignore mWebViewThread == null because this can be called during in the super class
2560 // constructor, before this class's own constructor has even started.
2561 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002562 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002563 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002564 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002565 "All WebView methods must be called on the same thread. " +
2566 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2567 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002568 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2569 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002570
2571 if (sEnforceThreadChecking) {
2572 throw new RuntimeException(throwable);
2573 }
Steve Block51b08912011-04-27 15:04:48 +01002574 }
2575 }
2576
Jonathan Dixon3c909522012-02-28 18:45:06 +00002577 //-------------------------------------------------------------------------
2578 // Override View methods
2579 //-------------------------------------------------------------------------
2580
2581 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2582 // there's a corresponding override (or better, caller) for each of them in here.
2583
2584 @Override
2585 protected void onAttachedToWindow() {
2586 super.onAttachedToWindow();
2587 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002588 }
2589
John Reck34dbce12014-03-06 12:52:24 -08002590 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002591 @Override
John Reck34dbce12014-03-06 12:52:24 -08002592 protected void onDetachedFromWindowInternal() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002593 mProvider.getViewDelegate().onDetachedFromWindow();
John Reck34dbce12014-03-06 12:52:24 -08002594 super.onDetachedFromWindowInternal();
Chris Craik555c55e2011-07-28 15:39:43 -07002595 }
2596
Tima Vaisburd5544f6c2017-04-27 10:53:27 -07002597 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002598 @Override
Tima Vaisburd134752b2017-04-06 15:50:05 -07002599 public void onMovedToDisplay(int displayId, Configuration config) {
2600 mProvider.getViewDelegate().onMovedToDisplay(displayId, config);
2601 }
2602
2603 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002604 public void setLayoutParams(ViewGroup.LayoutParams params) {
2605 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002606 }
2607
Jonathan Dixon3c909522012-02-28 18:45:06 +00002608 @Override
2609 public void setOverScrollMode(int mode) {
2610 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002611 // This method may be called in the constructor chain, before the WebView provider is
2612 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002613 ensureProviderCreated();
2614 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002615 }
2616
Jonathan Dixon3c909522012-02-28 18:45:06 +00002617 @Override
2618 public void setScrollBarStyle(int style) {
2619 mProvider.getViewDelegate().setScrollBarStyle(style);
2620 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002621 }
2622
Jonathan Dixon3c909522012-02-28 18:45:06 +00002623 @Override
2624 protected int computeHorizontalScrollRange() {
2625 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002626 }
2627
Jonathan Dixon3c909522012-02-28 18:45:06 +00002628 @Override
2629 protected int computeHorizontalScrollOffset() {
2630 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2631 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002632
Jonathan Dixon3c909522012-02-28 18:45:06 +00002633 @Override
2634 protected int computeVerticalScrollRange() {
2635 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2636 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002637
Jonathan Dixon3c909522012-02-28 18:45:06 +00002638 @Override
2639 protected int computeVerticalScrollOffset() {
2640 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2641 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002642
Jonathan Dixon3c909522012-02-28 18:45:06 +00002643 @Override
2644 protected int computeVerticalScrollExtent() {
2645 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2646 }
2647
2648 @Override
2649 public void computeScroll() {
2650 mProvider.getScrollDelegate().computeScroll();
2651 }
2652
2653 @Override
2654 public boolean onHoverEvent(MotionEvent event) {
2655 return mProvider.getViewDelegate().onHoverEvent(event);
2656 }
2657
2658 @Override
2659 public boolean onTouchEvent(MotionEvent event) {
2660 return mProvider.getViewDelegate().onTouchEvent(event);
2661 }
2662
2663 @Override
2664 public boolean onGenericMotionEvent(MotionEvent event) {
2665 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2666 }
2667
2668 @Override
2669 public boolean onTrackballEvent(MotionEvent event) {
2670 return mProvider.getViewDelegate().onTrackballEvent(event);
2671 }
2672
2673 @Override
2674 public boolean onKeyDown(int keyCode, KeyEvent event) {
2675 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2676 }
2677
2678 @Override
2679 public boolean onKeyUp(int keyCode, KeyEvent event) {
2680 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2681 }
2682
2683 @Override
2684 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2685 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2686 }
2687
2688 /*
2689 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2690 to be delegating them too.
2691
2692 @Override
2693 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2694 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2695 }
2696 @Override
2697 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2698 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2699 }
2700 @Override
2701 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2702 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2703 }
2704 */
2705
Ben Murdoche3f90712013-06-05 14:19:48 +01002706 @Override
2707 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2708 AccessibilityNodeProvider provider =
2709 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2710 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2711 }
2712
Jonathan Dixon3c909522012-02-28 18:45:06 +00002713 @Deprecated
2714 @Override
2715 public boolean shouldDelayChildPressedState() {
2716 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2717 }
2718
Felipe Leme1ca634a2016-11-28 17:21:21 -08002719 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -08002720 public CharSequence getAccessibilityClassName() {
2721 return WebView.class.getName();
2722 }
2723
Selim Gurun1b650cb2015-04-06 20:13:37 -07002724 @Override
Dianne Hackborn49b043f2015-05-07 14:21:38 -07002725 public void onProvideVirtualStructure(ViewStructure structure) {
Selim Gurun50b26a52015-06-01 16:26:10 -07002726 mProvider.getViewDelegate().onProvideVirtualStructure(structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -07002727 }
2728
Felipe Leme1a1e4682017-03-13 16:34:03 -07002729 /**
2730 * {@inheritDoc}
2731 *
2732 * <p>The {@link ViewStructure} traditionally represents a {@link View}, while for web pages
2733 * it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is
2734 * understood by the {@link android.service.autofill.AutofillService} implementations:
2735 *
2736 * <ol>
Felipe Leme303b6092017-07-31 18:01:15 -07002737 * <li>Only the HTML nodes inside a {@code FORM} are generated.
2738 * <li>The source of the HTML is set using {@link ViewStructure#setWebDomain(String)} in the
2739 * node representing the WebView.
2740 * <li>If a web page has multiple {@code FORM}s, only the data for the current form is
2741 * represented&mdash;if the user taps a field from another form, then the current autofill
2742 * context is canceled (by calling {@link android.view.autofill.AutofillManager#cancel()} and
2743 * a new context is created for that {@code FORM}.
2744 * <li>Similarly, if the page has {@code IFRAME} nodes, they are not initially represented in
2745 * the view structure until the user taps a field from a {@code FORM} inside the
2746 * {@code IFRAME}, in which case it would be treated the same way as multiple forms described
2747 * above, except that the {@link ViewStructure#setWebDomain(String) web domain} of the
2748 * {@code FORM} contains the {@code src} attribute from the {@code IFRAME} node.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002749 * <li>The W3C autofill field ({@code autocomplete} tag attribute) maps to
Felipe Leme58390fe2017-09-15 15:16:28 -07002750 * {@link ViewStructure#setAutofillHints(String[])}.
2751 * <li>If the view is editable, the {@link ViewStructure#setAutofillType(int)} and
Felipe Leme6dcec872017-05-25 11:24:23 -07002752 * {@link ViewStructure#setAutofillValue(AutofillValue)} must be set.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002753 * <li>The {@code placeholder} attribute maps to {@link ViewStructure#setHint(CharSequence)}.
Felipe Leme25bf7872017-03-28 15:32:29 -07002754 * <li>Other HTML attributes can be represented through
2755 * {@link ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)}.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002756 * </ol>
2757 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002758 * <p>If the WebView implementation can determine that the value of a field was set statically
2759 * (for example, not through Javascript), it should also call
2760 * {@code structure.setDataIsSensitive(false)}.
Felipe Leme6dcec872017-05-25 11:24:23 -07002761 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002762 * <p>For example, an HTML form with 2 fields for username and password:
Felipe Leme1a1e4682017-03-13 16:34:03 -07002763 *
2764 * <pre class="prettyprint">
Felipe Lemef485f892017-11-22 08:15:59 -08002765 * &lt;label&gt;Username:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002766 * &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 -08002767 * &lt;label&gt;Password:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002768 * &lt;input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"&gt;
Felipe Leme1a1e4682017-03-13 16:34:03 -07002769 * </pre>
2770 *
2771 * <p>Would map to:
2772 *
2773 * <pre class="prettyprint">
Felipe Leme25bf7872017-03-28 15:32:29 -07002774 * int index = structure.addChildCount(2);
2775 * ViewStructure username = structure.newChild(index);
Felipe Leme6dcec872017-05-25 11:24:23 -07002776 * username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002777 * username.setAutofillHints("username");
Felipe Leme6dcec872017-05-25 11:24:23 -07002778 * username.setHtmlInfo(username.newHtmlInfoBuilder("input")
2779 * .addAttribute("type", "text")
Felipe Leme25bf7872017-03-28 15:32:29 -07002780 * .addAttribute("name", "username")
Felipe Lemef485f892017-11-22 08:15:59 -08002781 * .addAttribute("label", "Username:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002782 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002783 * username.setHint("Email or username");
2784 * username.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme6dcec872017-05-25 11:24:23 -07002785 * username.setAutofillValue(AutofillValue.forText("Type your username"));
Felipe Leme58390fe2017-09-15 15:16:28 -07002786 * // Value of the field is not sensitive because it was created statically and not changed.
Felipe Leme6dcec872017-05-25 11:24:23 -07002787 * username.setDataIsSensitive(false);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002788 *
Felipe Leme25bf7872017-03-28 15:32:29 -07002789 * ViewStructure password = structure.newChild(index + 1);
2790 * username.setAutofillId(structure, 2); // id 2 - second child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002791 * password.setAutofillHints("current-password");
Felipe Leme6dcec872017-05-25 11:24:23 -07002792 * password.setHtmlInfo(password.newHtmlInfoBuilder("input")
2793 * .addAttribute("type", "password")
Felipe Leme25bf7872017-03-28 15:32:29 -07002794 * .addAttribute("name", "password")
Felipe Lemef485f892017-11-22 08:15:59 -08002795 * .addAttribute("label", "Password:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002796 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002797 * password.setHint("Password");
2798 * password.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002799 * </pre>
Felipe Leme1a1e4682017-03-13 16:34:03 -07002800 */
Felipe Leme1ca634a2016-11-28 17:21:21 -08002801 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08002802 public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
2803 mProvider.getViewDelegate().onProvideAutofillVirtualStructure(structure, flags);
Felipe Leme1ca634a2016-11-28 17:21:21 -08002804 }
2805
Tao Baia5717332017-03-30 14:58:53 -07002806 @Override
2807 public void autofill(SparseArray<AutofillValue>values) {
2808 mProvider.getViewDelegate().autofill(values);
2809 }
2810
Felipe Lemeef335262018-03-07 11:49:44 -08002811 @Override
2812 public boolean isVisibleToUserForAutofill(int virtualId) {
2813 return mProvider.getViewDelegate().isVisibleToUserForAutofill(virtualId);
2814 }
2815
Alan Viverettea54956a2015-01-07 16:05:02 -08002816 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002817 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002818 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2819 super.onInitializeAccessibilityNodeInfoInternal(info);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002820 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002821 }
2822
Alan Viverettea54956a2015-01-07 16:05:02 -08002823 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002824 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002825 public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
2826 super.onInitializeAccessibilityEventInternal(event);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002827 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002828 }
2829
Alan Viverettea54956a2015-01-07 16:05:02 -08002830 /** @hide */
alanv448902d2012-05-16 20:27:47 -07002831 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002832 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002833 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002834 }
2835
Jonathan Dixon3c909522012-02-28 18:45:06 +00002836 /** @hide */
2837 @Override
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002838 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002839 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2840 int l, int t, int r, int b) {
2841 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2842 }
2843
2844 @Override
2845 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2846 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2847 }
2848
2849 @Override
2850 protected void onWindowVisibilityChanged(int visibility) {
2851 super.onWindowVisibilityChanged(visibility);
2852 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2853 }
2854
2855 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002856 protected void onDraw(Canvas canvas) {
2857 mProvider.getViewDelegate().onDraw(canvas);
2858 }
2859
2860 @Override
2861 public boolean performLongClick() {
2862 return mProvider.getViewDelegate().performLongClick();
2863 }
2864
2865 @Override
2866 protected void onConfigurationChanged(Configuration newConfig) {
2867 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2868 }
2869
Selim Gurunc92080b2016-10-20 11:53:14 -07002870 /**
2871 * Creates a new InputConnection for an InputMethod to interact with the WebView.
2872 * This is similar to {@link View#onCreateInputConnection} but note that WebView
2873 * calls InputConnection methods on a thread other than the UI thread.
2874 * If these methods are overridden, then the overriding methods should respect
2875 * thread restrictions when calling View methods or accessing data.
2876 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002877 @Override
2878 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2879 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2880 }
2881
2882 @Override
Hui Shuecdce962016-02-04 15:00:19 -08002883 public boolean onDragEvent(DragEvent event) {
2884 return mProvider.getViewDelegate().onDragEvent(event);
2885 }
2886
2887 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002888 protected void onVisibilityChanged(View changedView, int visibility) {
2889 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002890 // This method may be called in the constructor chain, before the WebView provider is
2891 // created.
2892 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002893 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2894 }
2895
2896 @Override
2897 public void onWindowFocusChanged(boolean hasWindowFocus) {
2898 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2899 super.onWindowFocusChanged(hasWindowFocus);
2900 }
2901
2902 @Override
2903 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2904 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2905 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2906 }
2907
2908 /** @hide */
2909 @Override
Mathew Inwood62d83fb2018-08-16 19:09:48 +01002910 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002911 protected boolean setFrame(int left, int top, int right, int bottom) {
2912 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2913 }
2914
2915 @Override
2916 protected void onSizeChanged(int w, int h, int ow, int oh) {
2917 super.onSizeChanged(w, h, ow, oh);
2918 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2919 }
2920
2921 @Override
2922 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2923 super.onScrollChanged(l, t, oldl, oldt);
2924 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2925 }
2926
2927 @Override
2928 public boolean dispatchKeyEvent(KeyEvent event) {
2929 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2930 }
2931
2932 @Override
2933 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2934 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2935 }
2936
Jonathan Dixon3c909522012-02-28 18:45:06 +00002937 @Override
2938 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2939 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2940 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2941 }
2942
2943 @Override
2944 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2945 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2946 }
2947
2948 @Override
2949 public void setBackgroundColor(int color) {
2950 mProvider.getViewDelegate().setBackgroundColor(color);
2951 }
John Recka5408e62012-03-16 14:18:44 -07002952
2953 @Override
2954 public void setLayerType(int layerType, Paint paint) {
2955 super.setLayerType(layerType, paint);
2956 mProvider.getViewDelegate().setLayerType(layerType, paint);
2957 }
Ben Murdoche623e242012-09-07 20:47:07 +01002958
2959 @Override
2960 protected void dispatchDraw(Canvas canvas) {
2961 mProvider.getViewDelegate().preDispatchDraw(canvas);
2962 super.dispatchDraw(canvas);
2963 }
Ben Murdoch7302f4f2014-07-03 14:47:44 +01002964
2965 @Override
2966 public void onStartTemporaryDetach() {
2967 super.onStartTemporaryDetach();
2968 mProvider.getViewDelegate().onStartTemporaryDetach();
2969 }
2970
2971 @Override
2972 public void onFinishTemporaryDetach() {
2973 super.onFinishTemporaryDetach();
2974 mProvider.getViewDelegate().onFinishTemporaryDetach();
2975 }
Siva Velusamy94a6d152015-05-05 15:07:00 -07002976
Selim Gurune319dad2016-03-17 01:40:40 +00002977 @Override
2978 public Handler getHandler() {
2979 return mProvider.getViewDelegate().getHandler(super.getHandler());
2980 }
2981
2982 @Override
2983 public View findFocus() {
2984 return mProvider.getViewDelegate().findFocus(super.findFocus());
2985 }
2986
Hui Shuf119c522015-10-08 10:07:13 -07002987 /**
Gustav Senntonbf683e02016-09-15 14:42:50 +01002988 * If WebView has already been loaded into the current process this method will return the
2989 * package that was used to load it. Otherwise, the package that would be used if the WebView
2990 * was loaded right now will be returned; this does not cause WebView to be loaded, so this
2991 * information may become outdated at any time.
Gustav Sennton4cbfe712017-03-07 14:22:01 +00002992 * The WebView package changes either when the current WebView package is updated, disabled, or
2993 * uninstalled. It can also be changed through a Developer Setting.
2994 * If the WebView package changes, any app process that has loaded WebView will be killed. The
2995 * next time the app starts and loads WebView it will use the new WebView package instead.
Nate Fischer0a6140d2017-09-05 12:37:49 -07002996 * @return the current WebView package, or {@code null} if there is none.
Gustav Senntonbf683e02016-09-15 14:42:50 +01002997 */
Nate Fischer3442c742017-09-08 17:02:00 -07002998 @Nullable
Gustav Senntonbf683e02016-09-15 14:42:50 +01002999 public static PackageInfo getCurrentWebViewPackage() {
3000 PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
3001 if (webviewPackage != null) {
3002 return webviewPackage;
3003 }
3004
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04003005 IWebViewUpdateService service = WebViewFactory.getUpdateService();
3006 if (service == null) {
3007 return null;
3008 }
Gustav Senntonbf683e02016-09-15 14:42:50 +01003009 try {
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04003010 return service.getCurrentWebViewPackage();
Gustav Senntonbf683e02016-09-15 14:42:50 +01003011 } catch (RemoteException e) {
3012 throw e.rethrowFromSystemServer();
3013 }
3014 }
3015
3016 /**
Hui Shuf119c522015-10-08 10:07:13 -07003017 * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
3018 *
3019 * @param requestCode The integer request code originally supplied to
3020 * startActivityForResult(), allowing you to identify who this
3021 * result came from.
3022 * @param resultCode The integer result code returned by the child activity
3023 * through its setResult().
3024 * @param data An Intent, which can return result data to the caller
3025 * (various data can be attached to Intent "extras").
3026 * @hide
3027 */
3028 @Override
3029 public void onActivityResult(int requestCode, int resultCode, Intent data) {
3030 mProvider.getViewDelegate().onActivityResult(requestCode, resultCode, data);
3031 }
3032
Changwan Ryu15e9afc2018-03-06 15:55:19 -08003033 @Override
3034 public boolean onCheckIsTextEditor() {
3035 return mProvider.getViewDelegate().onCheckIsTextEditor();
3036 }
3037
Siva Velusamy94a6d152015-05-05 15:07:00 -07003038 /** @hide */
3039 @Override
3040 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
3041 super.encodeProperties(encoder);
3042
3043 checkThread();
3044 encoder.addProperty("webview:contentHeight", mProvider.getContentHeight());
3045 encoder.addProperty("webview:contentWidth", mProvider.getContentWidth());
3046 encoder.addProperty("webview:scale", mProvider.getScale());
3047 encoder.addProperty("webview:title", mProvider.getTitle());
3048 encoder.addProperty("webview:url", mProvider.getUrl());
3049 encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl());
3050 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051}