blob: 8f03b693e587d27a69c4510d3a871ca0b7e04f50 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000019import android.annotation.IntDef;
Siva Velusamy94a6d152015-05-05 15:07:00 -070020import android.annotation.NonNull;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070021import android.annotation.Nullable;
Ignacio Solla451e3382014-11-10 10:35:54 +000022import android.annotation.SystemApi;
Mathew Inwood42afea22018-08-16 19:18:28 +010023import android.annotation.UnsupportedAppUsage;
Raphael30df2372010-03-06 10:09:54 -080024import android.annotation.Widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.Context;
Hui Shuf119c522015-10-08 10:07:13 -070026import android.content.Intent;
Gustav Senntonbf683e02016-09-15 14:42:50 +010027import android.content.pm.PackageInfo;
Cary Clarkc5cd5e92010-11-22 15:20:02 -050028import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.graphics.Bitmap;
30import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070031import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.graphics.Picture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.graphics.Rect;
Mike Reede8853fc2009-09-04 14:01:48 -040034import android.graphics.drawable.Drawable;
Selim Gurun4c8093a2015-03-10 17:40:06 -070035import android.net.Uri;
Nate Fischer0e72c182017-05-30 11:25:17 -070036import android.net.http.SslCertificate;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -070037import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.Bundle;
Selim Gurune319dad2016-03-17 01:40:40 +000039import android.os.Handler;
Steve Block08d584c2011-05-17 19:05:03 +010040import android.os.Looper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.Message;
Gustav Senntonbf683e02016-09-15 14:42:50 +010042import android.os.RemoteException;
Nate Fischer0e72c182017-05-30 11:25:17 -070043import android.os.StrictMode;
Selim Gurunda7d6422013-09-06 14:39:05 -070044import android.print.PrintDocumentAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.util.Log;
Tao Baia5717332017-03-30 14:58:53 -070047import android.util.SparseArray;
Hui Shuecdce962016-02-04 15:00:19 -080048import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.view.KeyEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.view.View;
John Reck926cf562012-06-14 10:00:31 -070052import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070054import android.view.ViewHierarchyEncoder;
Nate Fischer0e72c182017-05-30 11:25:17 -070055import android.view.ViewStructure;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.view.ViewTreeObserver;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070057import android.view.accessibility.AccessibilityEvent;
Svetoslav Ganovd9ee72f2011-10-05 22:26:05 -070058import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010059import android.view.accessibility.AccessibilityNodeProvider;
Tao Baia5717332017-03-30 14:58:53 -070060import android.view.autofill.AutofillValue;
Derek Sollenberger7cabb032010-01-21 10:37:38 -050061import android.view.inputmethod.EditorInfo;
62import android.view.inputmethod.InputConnection;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070063import android.view.textclassifier.TextClassifier;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.widget.AbsoluteLayout;
Steve Blockf95d4902011-06-09 11:53:26 +010065
John Reck926cf562012-06-14 10:00:31 -070066import java.io.BufferedWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import java.io.File;
Tobias Sargeantd10e4af2017-01-19 14:03:09 +000068import java.lang.annotation.Retention;
69import java.lang.annotation.RetentionPolicy;
Nate Fischer520a8ba2017-07-12 17:37:07 -070070import java.util.List;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010071import java.util.Map;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
73/**
Laura Davisb444e2d2018-07-13 15:12:35 -070074 * A View that displays web pages.
Scott Main41ec6532010-08-19 16:57:07 -070075 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010076 * <h3>Basic usage</h3>
77 *
Mike Hearnadcd2ed2009-01-21 16:44:36 +010078 *
Laura Davisb444e2d2018-07-13 15:12:35 -070079 * <p>In most cases, we recommend using a standard web browser, like Chrome, to deliver
80 * content to the user. To learn more about web browsers, read the guide on
81 * <a href="/guide/components/intents-common#Browser">
82 * invoking a browser with an intent</a>.
Nate Fischerf02f8462017-09-11 15:16:33 -070083 *
Laura Davisb444e2d2018-07-13 15:12:35 -070084 * <p>WebView objects allow you to display web content as part of your activity layout, but
85 * lack some of the features of fully-developed browsers. A WebView is useful when
86 * you need increased control over the UI and advanced configuration options that will allow
87 * you to embed web pages in a specially-designed environment for your app.
Mike Hearnadcd2ed2009-01-21 16:44:36 +010088 *
Laura Davisb444e2d2018-07-13 15:12:35 -070089 * <p>To learn more about WebView and alternatives for serving web content, read the
90 * documentation on
91 * <a href="/guide/webapps/">
92 * Web-based content</a>.
Nate Fischerfb92ee12018-01-18 12:01:19 -080093 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 */
Steve Block406aeb22012-04-23 18:17:19 +010095// Implementation notes.
96// The WebView is a thin API class that delegates its public API to a backend WebViewProvider
97// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.
98// Methods are delegated to the provider implementation: all public API methods introduced in this
99// file are fully delegated, whereas public and protected methods from the View base classes are
100// only delegated where a specific need exists for them to do so.
Raphael30df2372010-03-06 10:09:54 -0800101@Widget
Cary Clarkd6982c92009-05-29 11:02:22 -0400102public class WebView extends AbsoluteLayout
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 implements ViewTreeObserver.OnGlobalFocusChangeListener,
John Reck926cf562012-06-14 10:00:31 -0700104 ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
Jonathan Dixon69f9f932013-08-28 15:54:29 -0700106 private static final String LOGTAG = "WebView";
Nicolas Roard12c18e62010-10-13 20:14:31 -0700107
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700108 // Throwing an exception for incorrect thread usage if the
109 // build target is JB MR2 or newer. Defaults to false, and is
110 // set in the WebView constructor.
Mathew Inwood42afea22018-08-16 19:18:28 +0100111 @UnsupportedAppUsage
Jonathan Dixon0d6a1452013-08-21 13:09:36 -0700112 private static volatile boolean sEnforceThreadChecking = false;
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 /**
115 * Transportation object for returning WebView across thread boundaries.
116 */
117 public class WebViewTransport {
118 private WebView mWebview;
119
120 /**
Steve Block4e584df2012-04-24 23:12:47 +0100121 * Sets the WebView to the transportation object.
122 *
123 * @param webview the WebView to transport
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 */
125 public synchronized void setWebView(WebView webview) {
126 mWebview = webview;
127 }
128
129 /**
Steve Block4e584df2012-04-24 23:12:47 +0100130 * Gets the WebView object.
131 *
132 * @return the transported WebView object
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 */
134 public synchronized WebView getWebView() {
135 return mWebview;
136 }
137 }
138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 /**
Steve Block4e584df2012-04-24 23:12:47 +0100140 * URI scheme for telephone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 */
142 public static final String SCHEME_TEL = "tel:";
143 /**
Steve Block4e584df2012-04-24 23:12:47 +0100144 * URI scheme for email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
146 public static final String SCHEME_MAILTO = "mailto:";
147 /**
Steve Block4e584df2012-04-24 23:12:47 +0100148 * URI scheme for map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 */
150 public static final String SCHEME_GEO = "geo:0,0?q=";
Cary Clarkd6982c92009-05-29 11:02:22 -0400151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 /**
Victoria Leased405a432012-03-22 15:53:48 -0700153 * Interface to listen for find results.
Victoria Leased405a432012-03-22 15:53:48 -0700154 */
155 public interface FindListener {
156 /**
Steve Block4e584df2012-04-24 23:12:47 +0100157 * Notifies the listener about progress made by a find operation.
Victoria Leased405a432012-03-22 15:53:48 -0700158 *
Steve Block4e584df2012-04-24 23:12:47 +0100159 * @param activeMatchOrdinal the zero-based ordinal of the currently selected match
Selim Gurun92b81a32012-08-21 17:32:35 -0700160 * @param numberOfMatches how many matches have been found
Steve Block4e584df2012-04-24 23:12:47 +0100161 * @param isDoneCounting whether the find operation has actually completed. The listener
162 * may be notified multiple times while the
163 * operation is underway, and the numberOfMatches
164 * value should not be considered final unless
Nate Fischer0a6140d2017-09-05 12:37:49 -0700165 * isDoneCounting is {@code true}.
Victoria Leased405a432012-03-22 15:53:48 -0700166 */
Selim Gurun92b81a32012-08-21 17:32:35 -0700167 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
Victoria Leased405a432012-03-22 15:53:48 -0700168 boolean isDoneCounting);
169 }
170
171 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +0100172 * Callback interface supplied to {@link #postVisualStateCallback} for receiving
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000173 * notifications about the visual state.
174 */
175 public static abstract class VisualStateCallback {
176 /**
177 * Invoked when the visual state is ready to be drawn in the next {@link #onDraw}.
178 *
Tobias Sargeantb3656042015-05-13 11:23:57 +0100179 * @param requestId The identifier passed to {@link #postVisualStateCallback} when this
180 * callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000181 */
182 public abstract void onComplete(long requestId);
183 }
184
185 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 * Interface to listen for new pictures as they change.
Steve Block4e584df2012-04-24 23:12:47 +0100187 *
Kristian Monsenfc771652011-05-10 16:44:05 +0100188 * @deprecated This interface is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100190 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 public interface PictureListener {
192 /**
Steve Block72498ed2012-07-17 15:57:25 +0100193 * Used to provide notification that the WebView's picture has changed.
194 * See {@link WebView#capturePicture} for details of the picture.
Steve Block4e584df2012-04-24 23:12:47 +0100195 *
196 * @param view the WebView that owns the picture
Ben Murdoch52643e02013-02-26 12:01:00 +0000197 * @param picture the new picture. Applications targeting
198 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} or above
Nate Fischer0a6140d2017-09-05 12:37:49 -0700199 * will always receive a {@code null} Picture.
Steve Block72498ed2012-07-17 15:57:25 +0100200 * @deprecated Deprecated due to internal changes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100202 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700203 void onNewPicture(WebView view, @Nullable Picture picture);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 }
205
Jonathan Dixon19644b62011-12-21 14:21:36 +0000206 public static class HitTestResult {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 /**
Steve Block4e584df2012-04-24 23:12:47 +0100208 * Default HitTestResult, where the target is unknown.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 */
210 public static final int UNKNOWN_TYPE = 0;
211 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100212 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 */
Steve Block1854ddb2011-04-19 12:18:19 +0100214 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 public static final int ANCHOR_TYPE = 1;
216 /**
Steve Block4e584df2012-04-24 23:12:47 +0100217 * HitTestResult for hitting a phone number.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 */
219 public static final int PHONE_TYPE = 2;
220 /**
Steve Block4e584df2012-04-24 23:12:47 +0100221 * HitTestResult for hitting a map address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
223 public static final int GEO_TYPE = 3;
224 /**
Steve Block4e584df2012-04-24 23:12:47 +0100225 * HitTestResult for hitting an email address.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 */
227 public static final int EMAIL_TYPE = 4;
228 /**
Steve Block4e584df2012-04-24 23:12:47 +0100229 * HitTestResult for hitting an HTML::img tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
231 public static final int IMAGE_TYPE = 5;
232 /**
Steve Block1854ddb2011-04-19 12:18:19 +0100233 * @deprecated This type is no longer used.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 */
Steve Block1854ddb2011-04-19 12:18:19 +0100235 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 public static final int IMAGE_ANCHOR_TYPE = 6;
237 /**
Steve Block4e584df2012-04-24 23:12:47 +0100238 * HitTestResult for hitting a HTML::a tag with src=http.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 */
240 public static final int SRC_ANCHOR_TYPE = 7;
241 /**
Steve Block4e584df2012-04-24 23:12:47 +0100242 * HitTestResult for hitting a HTML::a tag with src=http + HTML::img.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 */
244 public static final int SRC_IMAGE_ANCHOR_TYPE = 8;
245 /**
Steve Block4e584df2012-04-24 23:12:47 +0100246 * HitTestResult for hitting an edit text area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 */
248 public static final int EDIT_TEXT_TYPE = 9;
249
250 private int mType;
251 private String mExtra;
252
Jonathan Dixon3c909522012-02-28 18:45:06 +0000253 /**
254 * @hide Only for use by WebViewProvider implementations
255 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000256 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000257 public HitTestResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 mType = UNKNOWN_TYPE;
259 }
260
Jonathan Dixon3c909522012-02-28 18:45:06 +0000261 /**
262 * @hide Only for use by WebViewProvider implementations
263 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000264 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000265 public void setType(int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 mType = type;
267 }
268
Jonathan Dixon3c909522012-02-28 18:45:06 +0000269 /**
270 * @hide Only for use by WebViewProvider implementations
271 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000272 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +0000273 public void setExtra(String extra) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 mExtra = extra;
275 }
276
Jonathan Dixone230e542011-12-21 10:57:00 +0000277 /**
Steve Block4e584df2012-04-24 23:12:47 +0100278 * Gets the type of the hit test result. See the XXX_TYPE constants
279 * defined in this class.
280 *
281 * @return the type of the hit test result
Jonathan Dixone230e542011-12-21 10:57:00 +0000282 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 public int getType() {
284 return mType;
285 }
286
Jonathan Dixone230e542011-12-21 10:57:00 +0000287 /**
Steve Block4e584df2012-04-24 23:12:47 +0100288 * Gets additional type-dependant information about the result. See
Nate Fischer0a6140d2017-09-05 12:37:49 -0700289 * {@link WebView#getHitTestResult()} for details. May either be {@code null}
Steve Block4e584df2012-04-24 23:12:47 +0100290 * or contain extra information about this result.
291 *
292 * @return additional type-dependant information about the result
Jonathan Dixone230e542011-12-21 10:57:00 +0000293 */
Nate Fischer3442c742017-09-08 17:02:00 -0700294 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 public String getExtra() {
296 return mExtra;
297 }
298 }
299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 /**
Nate Fischer674561a2017-10-26 12:28:01 -0700301 * Constructs a new WebView with an Activity Context object.
Steve Block4e584df2012-04-24 23:12:47 +0100302 *
Nate Fischer674561a2017-10-26 12:28:01 -0700303 * <p class="note"><b>Note:</b> WebView should always be instantiated with an Activity Context.
304 * If instantiated with an Application Context, WebView will be unable to provide several
305 * features, such as JavaScript dialogs and autofill.
306 *
307 * @param context an Activity Context to access application assets
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 */
309 public WebView(Context context) {
310 this(context, null);
311 }
312
313 /**
Steve Block4e584df2012-04-24 23:12:47 +0100314 * Constructs a new WebView with layout parameters.
315 *
Nate Fischer674561a2017-10-26 12:28:01 -0700316 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100317 * @param attrs an AttributeSet passed to our parent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 */
319 public WebView(Context context, AttributeSet attrs) {
320 this(context, attrs, com.android.internal.R.attr.webViewStyle);
321 }
322
323 /**
Steve Block4e584df2012-04-24 23:12:47 +0100324 * Constructs a new WebView with layout parameters and a default style.
325 *
Nate Fischer674561a2017-10-26 12:28:01 -0700326 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100327 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700328 * @param defStyleAttr an attribute in the current theme that contains a
329 * reference to a style resource that supplies default values for
330 * the view. Can be 0 to not look for defaults.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 */
Alan Viverette617feb92013-09-09 18:09:13 -0700332 public WebView(Context context, AttributeSet attrs, int defStyleAttr) {
333 this(context, attrs, defStyleAttr, 0);
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700334 }
335
336 /**
Steve Block4e584df2012-04-24 23:12:47 +0100337 * Constructs a new WebView with layout parameters and a default style.
338 *
Nate Fischer674561a2017-10-26 12:28:01 -0700339 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100340 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700341 * @param defStyleAttr an attribute in the current theme that contains a
342 * reference to a style resource that supplies default values for
343 * the view. Can be 0 to not look for defaults.
344 * @param defStyleRes a resource identifier of a style resource that
345 * supplies default values for the view, used only if
346 * defStyleAttr is 0 or can not be found in the theme. Can be 0
347 * to not look for defaults.
348 */
349 public WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
350 this(context, attrs, defStyleAttr, defStyleRes, null, false);
351 }
352
353 /**
354 * Constructs a new WebView with layout parameters and a default style.
355 *
Nate Fischer674561a2017-10-26 12:28:01 -0700356 * @param context an Activity Context to access application assets
Alan Viverette617feb92013-09-09 18:09:13 -0700357 * @param attrs an AttributeSet passed to our parent
358 * @param defStyleAttr an attribute in the current theme that contains a
359 * reference to a style resource that supplies default values for
360 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100361 * @param privateBrowsing whether this WebView will be initialized in
362 * private mode
Kristian Monsen5cc23512012-08-09 15:33:08 -0400363 *
Selim Gurunb6aa97e2014-03-26 14:10:28 -0700364 * @deprecated Private browsing is no longer supported directly via
Kristian Monsen5cc23512012-08-09 15:33:08 -0400365 * WebView and will be removed in a future release. Prefer using
366 * {@link WebSettings}, {@link WebViewDatabase}, {@link CookieManager}
367 * and {@link WebStorage} for fine-grained control of privacy data.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700368 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400369 @Deprecated
Alan Viverette617feb92013-09-09 18:09:13 -0700370 public WebView(Context context, AttributeSet attrs, int defStyleAttr,
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700371 boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700372 this(context, attrs, defStyleAttr, 0, null, privateBrowsing);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100373 }
374
375 /**
Steve Block4e584df2012-04-24 23:12:47 +0100376 * Constructs a new WebView with layout parameters, a default style and a set
Nate Fischerffb81c42016-09-26 12:35:47 -0700377 * of custom JavaScript interfaces to be added to this WebView at initialization
Romain Guy01d0fbf2009-12-01 14:52:19 -0800378 * time. This guarantees that these interfaces will be available when the JS
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100379 * context is initialized.
Steve Block4e584df2012-04-24 23:12:47 +0100380 *
Nate Fischer674561a2017-10-26 12:28:01 -0700381 * @param context an Activity Context to access application assets
Steve Block4e584df2012-04-24 23:12:47 +0100382 * @param attrs an AttributeSet passed to our parent
Alan Viverette617feb92013-09-09 18:09:13 -0700383 * @param defStyleAttr an attribute in the current theme that contains a
384 * reference to a style resource that supplies default values for
385 * the view. Can be 0 to not look for defaults.
Steve Block4e584df2012-04-24 23:12:47 +0100386 * @param javaScriptInterfaces a Map of interface names, as keys, and
387 * object implementing those interfaces, as
388 * values
389 * @param privateBrowsing whether this WebView will be initialized in
390 * private mode
Nate Fischerffb81c42016-09-26 12:35:47 -0700391 * @hide This is used internally by dumprendertree, as it requires the JavaScript interfaces to
Steve Block4e584df2012-04-24 23:12:47 +0100392 * be added synchronously, before a subsequent loadUrl call takes effect.
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100393 */
Mathew Inwood42afea22018-08-16 19:18:28 +0100394 @UnsupportedAppUsage
Alan Viverette617feb92013-09-09 18:09:13 -0700395 protected WebView(Context context, AttributeSet attrs, int defStyleAttr,
Steve Block81f19ff2010-11-01 13:23:24 +0000396 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
Alan Viverette617feb92013-09-09 18:09:13 -0700397 this(context, attrs, defStyleAttr, 0, javaScriptInterfaces, privateBrowsing);
398 }
399
400 /**
401 * @hide
402 */
403 @SuppressWarnings("deprecation") // for super() call into deprecated base class constructor.
Mathew Inwood42afea22018-08-16 19:18:28 +0100404 @UnsupportedAppUsage
Alan Viverette617feb92013-09-09 18:09:13 -0700405 protected WebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
406 Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
407 super(context, attrs, defStyleAttr, defStyleRes);
Felipe Lemed04a6972017-03-02 12:56:18 -0800408
409 // WebView is important by default, unless app developer overrode attribute.
410 if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
411 setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
412 }
413
Kristian Monsen87af7312011-09-09 02:12:51 +0100414 if (context == null) {
415 throw new IllegalArgumentException("Invalid context argument");
416 }
Gustav Sennton01673692018-01-19 12:11:25 +0000417 if (mWebViewThread == null) {
418 throw new RuntimeException(
419 "WebView cannot be initialized on a thread that has no Looper.");
420 }
Kristian Monsenb5cd8c02013-04-09 17:57:37 -0700421 sEnforceThreadChecking = context.getApplicationInfo().targetSdkVersion >=
422 Build.VERSION_CODES.JELLY_BEAN_MR2;
Jonathan Dixon3c909522012-02-28 18:45:06 +0000423 checkThread();
Kristian Monsen87af7312011-09-09 02:12:51 +0100424
Jonathan Dixon3c909522012-02-28 18:45:06 +0000425 ensureProviderCreated();
426 mProvider.init(javaScriptInterfaces, privateBrowsing);
Jonathan Dixoneb9e8012013-10-03 11:03:31 +0100427 // Post condition of creating a webview is the CookieSyncManager.getInstance() is allowed.
428 CookieSyncManager.setGetInstanceIsAllowed();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430
431 /**
Steve Block4e584df2012-04-24 23:12:47 +0100432 * Specifies whether the horizontal scrollbar has overlay style.
433 *
Paul Millerc8694a02015-06-05 11:23:03 -0700434 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700435 * @param overlay {@code true} if horizontal scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 */
Paul Millerc8694a02015-06-05 11:23:03 -0700437 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 public void setHorizontalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 }
440
441 /**
Steve Block4e584df2012-04-24 23:12:47 +0100442 * Specifies whether the vertical scrollbar has overlay style.
443 *
Paul Millerc8694a02015-06-05 11:23:03 -0700444 * @deprecated This method has no effect.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700445 * @param overlay {@code true} if vertical scrollbar should have overlay style
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 */
Paul Millerc8694a02015-06-05 11:23:03 -0700447 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 public void setVerticalScrollbarOverlay(boolean overlay) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 }
450
451 /**
Steve Block4e584df2012-04-24 23:12:47 +0100452 * Gets whether horizontal scrollbar has overlay style.
453 *
Paul Millerc8694a02015-06-05 11:23:03 -0700454 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700455 * @return {@code true}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 */
Paul Millerc8694a02015-06-05 11:23:03 -0700457 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 public boolean overlayHorizontalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700459 // The old implementation defaulted to true, so return true for consistency
460 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 }
462
463 /**
Steve Block4e584df2012-04-24 23:12:47 +0100464 * Gets whether vertical scrollbar has overlay style.
465 *
Paul Millerc8694a02015-06-05 11:23:03 -0700466 * @deprecated This method is now obsolete.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700467 * @return {@code false}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 */
Paul Millerc8694a02015-06-05 11:23:03 -0700469 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 public boolean overlayVerticalScrollbar() {
Paul Millerc8694a02015-06-05 11:23:03 -0700471 // The old implementation defaulted to false, so return false for consistency
472 return false;
Mike Reede8853fc2009-09-04 14:01:48 -0400473 }
474
Michael Kolbe54f6652011-03-16 09:11:51 -0700475 /**
Steve Block4e584df2012-04-24 23:12:47 +0100476 * Gets the visible height (in pixels) of the embedded title bar (if any).
Michael Kolb73980a92010-08-05 16:32:51 -0700477 *
Michael Kolb24e53b02011-03-16 12:52:04 -0700478 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400479 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Mike Reede8853fc2009-09-04 14:01:48 -0400480 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700481 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +0100482 @UnsupportedAppUsage
Michael Kolb73980a92010-08-05 16:32:51 -0700483 public int getVisibleTitleHeight() {
Steve Block51b08912011-04-27 15:04:48 +0100484 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000485 return mProvider.getVisibleTitleHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 }
487
488 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -0700489 * Gets the SSL certificate for the main top-level page or {@code null} if there is
Steve Block4e584df2012-04-24 23:12:47 +0100490 * no certificate (the site is not secure).
491 *
492 * @return the SSL certificate for the main top-level page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 */
Nate Fischer3442c742017-09-08 17:02:00 -0700494 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 public SslCertificate getCertificate() {
Steve Block51b08912011-04-27 15:04:48 +0100496 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000497 return mProvider.getCertificate();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499
500 /**
501 * Sets the SSL certificate for the main top-level page.
Kristian Monsen5cc23512012-08-09 15:33:08 -0400502 *
503 * @deprecated Calling this function has no useful effect, and will be
504 * ignored in future releases.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 */
Kristian Monsen5cc23512012-08-09 15:33:08 -0400506 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 public void setCertificate(SslCertificate certificate) {
Steve Block51b08912011-04-27 15:04:48 +0100508 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000509 mProvider.setCertificate(certificate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511
512 //-------------------------------------------------------------------------
513 // Methods called by activity
514 //-------------------------------------------------------------------------
515
516 /**
Steve Block32fe4102012-07-17 16:29:11 +0100517 * Sets a username and password pair for the specified host. This data is
Nate Fischerffb81c42016-09-26 12:35:47 -0700518 * used by the WebView to autocomplete username and password fields in web
Steve Block32fe4102012-07-17 16:29:11 +0100519 * forms. Note that this is unrelated to the credentials used for HTTP
520 * authentication.
Steve Block4e584df2012-04-24 23:12:47 +0100521 *
Selim Gurun38915fd2013-04-04 17:14:29 +0000522 * @param host the host that required the credentials
Steve Block4e584df2012-04-24 23:12:47 +0100523 * @param username the username for the given host
524 * @param password the password for the given host
Steve Block32fe4102012-07-17 16:29:11 +0100525 * @see WebViewDatabase#clearUsernamePassword
526 * @see WebViewDatabase#hasUsernamePassword
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800527 * @deprecated Saving passwords in WebView will not be supported in future versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -0800529 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 public void savePassword(String host, String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100531 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000532 mProvider.savePassword(host, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 }
534
535 /**
Hui Shu433fb932016-08-29 11:49:46 -0700536 * Stores HTTP authentication credentials for a given host and realm to the {@link WebViewDatabase}
537 * instance.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 *
Steve Block46ce1db2012-07-17 16:43:00 +0100539 * @param host the host to which the credentials apply
540 * @param realm the realm to which the credentials apply
541 * @param username the username
Steve Block4e584df2012-04-24 23:12:47 +0100542 * @param password the password
Nate Fischerc7edfb02016-09-23 15:59:21 -0700543 * @deprecated Use {@link WebViewDatabase#setHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700545 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 public void setHttpAuthUsernamePassword(String host, String realm,
547 String username, String password) {
Steve Block51b08912011-04-27 15:04:48 +0100548 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000549 mProvider.setHttpAuthUsernamePassword(host, realm, username, password);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 }
551
552 /**
Hui Shu433fb932016-08-29 11:49:46 -0700553 * Retrieves HTTP authentication credentials for a given host and realm from the {@link
554 * WebViewDatabase} instance.
Steve Block46ce1db2012-07-17 16:43:00 +0100555 * @param host the host to which the credentials apply
556 * @param realm the realm to which the credentials apply
557 * @return the credentials as a String array, if found. The first element
Nate Fischer0a6140d2017-09-05 12:37:49 -0700558 * is the username and the second element is the password. {@code null} if
Steve Block46ce1db2012-07-17 16:43:00 +0100559 * no credentials are found.
Nate Fischerc7edfb02016-09-23 15:59:21 -0700560 * @deprecated Use {@link WebViewDatabase#getHttpAuthUsernamePassword} instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 */
Nate Fischerc7edfb02016-09-23 15:59:21 -0700562 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -0700563 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 public String[] getHttpAuthUsernamePassword(String host, String realm) {
Steve Block51b08912011-04-27 15:04:48 +0100565 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000566 return mProvider.getHttpAuthUsernamePassword(host, realm);
Leon Scroggins05919f22010-09-14 17:22:36 -0400567 }
568
569 /**
Steve Block4e584df2012-04-24 23:12:47 +0100570 * Destroys the internal state of this WebView. This method should be called
571 * after this WebView has been removed from the view system. No other
572 * methods may be called on this WebView after destroy.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 */
574 public void destroy() {
Steve Block51b08912011-04-27 15:04:48 +0100575 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000576 mProvider.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 }
578
579 /**
580 * Enables platform notifications of data state and proxy changes.
Kristian Monsencbb59db2011-05-09 16:04:34 +0100581 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100582 *
583 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400584 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100586 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +0100587 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 public static void enablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700589 // noop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 }
591
592 /**
Kristian Monsencbb59db2011-05-09 16:04:34 +0100593 * Disables platform notifications of data state and proxy changes.
594 * Notifications are enabled by default.
Kristian Monsenfc771652011-05-10 16:44:05 +0100595 *
596 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400597 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100599 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +0100600 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 public static void disablePlatformNotifications() {
Kristian Monsen10ca8082014-04-29 11:02:42 -0700602 // noop
Feng Qianb3081372009-06-29 15:55:18 -0700603 }
604
605 /**
Primiano Tucci24426752013-09-05 12:01:51 +0100606 * Used only by internal tests to free up memory.
607 *
608 * @hide
609 */
Mathew Inwood42afea22018-08-16 19:18:28 +0100610 @UnsupportedAppUsage
Primiano Tucci24426752013-09-05 12:01:51 +0100611 public static void freeMemoryForTests() {
Primiano Tucci24426752013-09-05 12:01:51 +0100612 getFactory().getStatics().freeMemoryForTests();
613 }
614
615 /**
Steve Block4e584df2012-04-24 23:12:47 +0100616 * Informs WebView of the network state. This is used to set
Steve Block81f19ff2010-11-01 13:23:24 +0000617 * the JavaScript property window.navigator.isOnline and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 * generates the online/offline event as specified in HTML5, sec. 5.7.7
Steve Block4e584df2012-04-24 23:12:47 +0100619 *
620 * @param networkUp a boolean indicating if network is available
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 */
622 public void setNetworkAvailable(boolean networkUp) {
Steve Block51b08912011-04-27 15:04:48 +0100623 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000624 mProvider.setNetworkAvailable(networkUp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 }
626
627 /**
Steve Block4e584df2012-04-24 23:12:47 +0100628 * Saves the state of this WebView used in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 * {@link android.app.Activity#onSaveInstanceState}. Please note that this
630 * method no longer stores the display data for this WebView. The previous
631 * behavior could potentially leak files if {@link #restoreState} was never
Kristian Monsenf4912582012-08-16 15:26:24 -0400632 * called.
Steve Block4e584df2012-04-24 23:12:47 +0100633 *
634 * @param outState the Bundle to store this WebView's state
Nate Fischer3442c742017-09-08 17:02:00 -0700635 * @return the same copy of the back/forward list used to save the state, {@code null} if the
636 * method fails.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 */
Nate Fischer3442c742017-09-08 17:02:00 -0700638 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 public WebBackForwardList saveState(Bundle outState) {
Steve Block51b08912011-04-27 15:04:48 +0100640 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000641 return mProvider.saveState(outState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 }
643
644 /**
Steve Block4e584df2012-04-24 23:12:47 +0100645 * Saves the current display data to the Bundle given. Used in conjunction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 * with {@link #saveState}.
Steve Block4e584df2012-04-24 23:12:47 +0100647 * @param b a Bundle to store the display data
648 * @param dest the file to store the serialized picture data. Will be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 * overwritten with this WebView's picture data.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700650 * @return {@code true} if the picture was successfully saved
Kristian Monsenfc771652011-05-10 16:44:05 +0100651 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400652 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100654 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +0100655 @UnsupportedAppUsage
Patrick Scottda9a22b2010-04-08 08:32:52 -0400656 public boolean savePicture(Bundle b, final File dest) {
Steve Block51b08912011-04-27 15:04:48 +0100657 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000658 return mProvider.savePicture(b, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
661 /**
Steve Block4e584df2012-04-24 23:12:47 +0100662 * Restores the display data that was saved in {@link #savePicture}. Used in
663 * conjunction with {@link #restoreState}. Note that this will not work if
664 * this WebView is hardware accelerated.
John Reck2df8f422011-09-22 19:50:41 -0700665 *
Steve Block4e584df2012-04-24 23:12:47 +0100666 * @param b a Bundle containing the saved display data
667 * @param src the file where the picture data was stored
Nate Fischer0a6140d2017-09-05 12:37:49 -0700668 * @return {@code true} if the picture was successfully restored
Kristian Monsenfc771652011-05-10 16:44:05 +0100669 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -0400670 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 */
Kristian Monsenfc771652011-05-10 16:44:05 +0100672 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +0100673 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 public boolean restorePicture(Bundle b, File src) {
Steve Block51b08912011-04-27 15:04:48 +0100675 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000676 return mProvider.restorePicture(b, src);
John Reck95b7d6f2011-06-03 15:23:43 -0700677 }
678
679 /**
Steve Block42499062012-07-17 15:34:46 +0100680 * Restores the state of this WebView from the given Bundle. This method is
681 * intended for use in {@link android.app.Activity#onRestoreInstanceState}
682 * and should be called to restore the state of this WebView. If
Steve Block4e584df2012-04-24 23:12:47 +0100683 * it is called after this WebView has had a chance to build state (load
Cary Clarkd6982c92009-05-29 11:02:22 -0400684 * pages, create a back/forward list, etc.) there may be undesirable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 * side-effects. Please note that this method no longer restores the
Kristian Monsenf4912582012-08-16 15:26:24 -0400686 * display data for this WebView.
Steve Block4e584df2012-04-24 23:12:47 +0100687 *
688 * @param inState the incoming Bundle of state
Nate Fischer0a6140d2017-09-05 12:37:49 -0700689 * @return the restored back/forward list or {@code null} if restoreState failed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 */
Nate Fischer3442c742017-09-08 17:02:00 -0700691 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 public WebBackForwardList restoreState(Bundle inState) {
Steve Block51b08912011-04-27 15:04:48 +0100693 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000694 return mProvider.restoreState(inState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 }
696
697 /**
Steve Block4e584df2012-04-24 23:12:47 +0100698 * Loads the given URL with the specified additional HTTP headers.
Bo Liue29d3132016-04-22 16:23:22 -0700699 * <p>
700 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100701 *
702 * @param url the URL of the resource to load
703 * @param additionalHttpHeaders the additional headers to be used in the
Steve Blockf71dea02011-08-01 12:29:14 +0100704 * HTTP request for this URL, specified as a map from name to
705 * value. Note that if this map contains any of the headers
Steve Block4e584df2012-04-24 23:12:47 +0100706 * that are set by default by this WebView, such as those
Steve Blockf71dea02011-08-01 12:29:14 +0100707 * controlling caching, accept types or the User-Agent, their
Nate Fischerffb81c42016-09-26 12:35:47 -0700708 * values may be overridden by this WebView's defaults.
Grace Klobad0d9bc22010-01-26 18:08:28 -0800709 */
Steve Blockf71dea02011-08-01 12:29:14 +0100710 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
Steve Block51b08912011-04-27 15:04:48 +0100711 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000712 mProvider.loadUrl(url, additionalHttpHeaders);
Grace Klobad0d9bc22010-01-26 18:08:28 -0800713 }
714
715 /**
Steve Block4e584df2012-04-24 23:12:47 +0100716 * Loads the given URL.
Bo Liue29d3132016-04-22 16:23:22 -0700717 * <p>
718 * Also see compatibility note on {@link #evaluateJavascript}.
Steve Block4e584df2012-04-24 23:12:47 +0100719 *
720 * @param url the URL of the resource to load
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 */
722 public void loadUrl(String url) {
Steve Block51b08912011-04-27 15:04:48 +0100723 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000724 mProvider.loadUrl(url);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 }
726
727 /**
Steve Block4e584df2012-04-24 23:12:47 +0100728 * Loads the URL with postData using "POST" method into this WebView. If url
Hui Shuc60ad9c2014-02-05 09:30:36 -0800729 * is not a network URL, it will be loaded with {@link #loadUrl(String)}
730 * instead, ignoring the postData param.
Cary Clarkd6982c92009-05-29 11:02:22 -0400731 *
Steve Block4e584df2012-04-24 23:12:47 +0100732 * @param url the URL of the resource to load
Ben Murdoch851004a2013-08-16 16:43:22 +0100733 * @param postData the data will be passed to "POST" request, which must be
734 * be "application/x-www-form-urlencoded" encoded.
Grace Kloba57534302009-05-22 18:55:02 -0700735 */
736 public void postUrl(String url, byte[] postData) {
Steve Block51b08912011-04-27 15:04:48 +0100737 checkThread();
Hui Shuc60ad9c2014-02-05 09:30:36 -0800738 if (URLUtil.isNetworkUrl(url)) {
739 mProvider.postUrl(url, postData);
740 } else {
741 mProvider.loadUrl(url);
742 }
Grace Kloba57534302009-05-22 18:55:02 -0700743 }
744
745 /**
Steve Block4e584df2012-04-24 23:12:47 +0100746 * Loads the given data into this WebView using a 'data' scheme URL.
Steve Blockb28b22a2011-07-04 13:01:25 +0100747 * <p>
748 * Note that JavaScript's same origin policy means that script running in a
749 * page loaded using this method will be unable to access content loaded
750 * using any scheme other than 'data', including 'http(s)'. To avoid this
751 * restriction, use {@link
752 * #loadDataWithBaseURL(String,String,String,String,String)
753 * loadDataWithBaseURL()} with an appropriate base URL.
Steve Blockf95d4902011-06-09 11:53:26 +0100754 * <p>
Nate Fischer867d1092018-01-04 21:57:33 -0800755 * The {@code encoding} parameter specifies whether the data is base64 or URL
Steve Block27f3e322012-07-23 10:45:59 +0100756 * encoded. If the data is base64 encoded, the value of the encoding
Nate Fischer867d1092018-01-04 21:57:33 -0800757 * parameter must be 'base64'. HTML can be encoded with {@link
758 * android.util.Base64#encodeToString(byte[],int)} like so:
759 * <pre>
760 * String unencodedHtml =
761 * "&lt;html&gt;&lt;body&gt;'%28' is the code for '('&lt;/body&gt;&lt;/html&gt;";
762 * String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
763 * webView.loadData(encodedHtml, "text/html", "base64");
764 * </pre>
765 * <p>
766 * For all other values of {@code encoding} (including {@code null}) it is assumed that the
767 * data uses ASCII encoding for octets inside the range of safe URL characters and use the
768 * standard %xx hex encoding of URLs for octets outside that range. See <a
769 * href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC 3986</a> for more information.
Steve Blockb19c7872011-10-10 14:09:44 +0100770 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800771 * The {@code mimeType} parameter specifies the format of the data.
772 * If WebView can't handle the specified MIME type, it will download the data.
773 * If {@code null}, defaults to 'text/html'.
774 * <p>
Steve Blockb19c7872011-10-10 14:09:44 +0100775 * The 'data' scheme URL formed by this method uses the default US-ASCII
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400776 * charset. If you need to set a different charset, you should form a
Steve Block33f962b2011-10-11 14:49:47 +0100777 * 'data' scheme URL which explicitly specifies a charset parameter in the
778 * mediatype portion of the URL and call {@link #loadUrl(String)} instead.
779 * Note that the charset obtained from the mediatype portion of a data URL
780 * always overrides that specified in the HTML or XML document itself.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400781 * <p>
782 * Content loaded using this method will have a {@code window.origin} value
783 * of {@code "null"}. This must not be considered to be a trusted origin
784 * by the application or by any JavaScript code running inside the WebView
785 * (for example, event sources in DOM event handlers or web messages),
786 * because malicious content can also create frames with a null origin. If
787 * you need to identify the main frame's origin in a trustworthy way, you
788 * should use {@link #loadDataWithBaseURL(String,String,String,String,String)
789 * loadDataWithBaseURL()} with a valid HTTP or HTTPS base URL to set the
790 * origin.
Steve Block4e584df2012-04-24 23:12:47 +0100791 *
792 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800793 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +0100794 * @param encoding the encoding of the data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 */
Nate Fischer3442c742017-09-08 17:02:00 -0700796 public void loadData(String data, @Nullable String mimeType, @Nullable String encoding) {
Steve Block51b08912011-04-27 15:04:48 +0100797 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000798 mProvider.loadData(data, mimeType, encoding);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 }
800
801 /**
Steve Block4e584df2012-04-24 23:12:47 +0100802 * Loads the given data into this WebView, using baseUrl as the base URL for
Steve Blockb28b22a2011-07-04 13:01:25 +0100803 * the content. The base URL is used both to resolve relative URLs and when
804 * applying JavaScript's same origin policy. The historyUrl is used for the
805 * history entry.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 * <p>
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800807 * The {@code mimeType} parameter specifies the format of the data.
808 * If WebView can't handle the specified MIME type, it will download the data.
809 * If {@code null}, defaults to 'text/html'.
810 * <p>
Steve Blockae328572011-06-08 18:58:51 +0100811 * Note that content specified in this way can access local device files
812 * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
813 * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
Steve Blocke482d892011-07-01 13:57:32 +0100814 * <p>
815 * If the base URL uses the data scheme, this method is equivalent to
816 * calling {@link #loadData(String,String,String) loadData()} and the
Ben Murdoch597256e2013-07-22 16:52:12 +0100817 * historyUrl is ignored, and the data will be treated as part of a data: URL.
818 * If the base URL uses any other scheme, then the data will be loaded into
819 * the WebView as a plain string (i.e. not part of a data URL) and any URL-encoded
820 * entities in the string will not be decoded.
Mikhail Naganovb29e0f62015-09-16 13:05:53 -0700821 * <p>
822 * Note that the baseUrl is sent in the 'Referer' HTTP header when
823 * requesting subresources (images, etc.) of the page loaded using this method.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400824 * <p>
825 * If a valid HTTP or HTTPS base URL is not specified in {@code baseUrl}, then
826 * content loaded using this method will have a {@code window.origin} value
827 * of {@code "null"}. This must not be considered to be a trusted origin
828 * by the application or by any JavaScript code running inside the WebView
829 * (for example, event sources in DOM event handlers or web messages),
830 * because malicious content can also create frames with a null origin. If
831 * you need to identify the main frame's origin in a trustworthy way, you
832 * should use a valid HTTP or HTTPS base URL to set the origin.
Steve Block4e584df2012-04-24 23:12:47 +0100833 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700834 * @param baseUrl the URL to use as the page's base URL. If {@code null} defaults to
Steve Block4e584df2012-04-24 23:12:47 +0100835 * 'about:blank'.
836 * @param data a String of data in the given encoding
James Wallace-Leed38c2e32017-12-11 16:11:15 -0800837 * @param mimeType the MIME type of the data, e.g. 'text/html'.
Steve Block4e584df2012-04-24 23:12:47 +0100838 * @param encoding the encoding of the data
Nate Fischer0a6140d2017-09-05 12:37:49 -0700839 * @param historyUrl the URL to use as the history entry. If {@code null} defaults
Ben Murdoch95afb3b2013-02-25 19:18:19 +0000840 * to 'about:blank'. If non-null, this must be a valid URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 */
Nate Fischer3442c742017-09-08 17:02:00 -0700842 public void loadDataWithBaseURL(@Nullable String baseUrl, String data,
843 @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl) {
Steve Block51b08912011-04-27 15:04:48 +0100844 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000845 mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 }
847
848 /**
Ben Murdocha5cdd512013-07-17 16:25:07 +0100849 * Asynchronously evaluates JavaScript in the context of the currently displayed page.
850 * If non-null, |resultCallback| will be invoked with any result returned from that
851 * execution. This method must be called on the UI thread and the callback will
852 * be made on the UI thread.
Bo Liue29d3132016-04-22 16:23:22 -0700853 * <p>
854 * Compatibility note. Applications targeting {@link android.os.Build.VERSION_CODES#N} or
855 * later, JavaScript state from an empty WebView is no longer persisted across navigations like
856 * {@link #loadUrl(String)}. For example, global variables and functions defined before calling
857 * {@link #loadUrl(String)} will not exist in the loaded page. Applications should use
858 * {@link #addJavascriptInterface} instead to persist JavaScript objects across navigations.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100859 *
860 * @param script the JavaScript to execute.
861 * @param resultCallback A callback to be invoked when the script execution
862 * completes with the result of the execution (if any).
Nate Fischer0a6140d2017-09-05 12:37:49 -0700863 * May be {@code null} if no notification of the result is required.
Ben Murdocha5cdd512013-07-17 16:25:07 +0100864 */
Nate Fischer3442c742017-09-08 17:02:00 -0700865 public void evaluateJavascript(String script, @Nullable ValueCallback<String> resultCallback) {
Ben Murdocha5cdd512013-07-17 16:25:07 +0100866 checkThread();
867 mProvider.evaluateJavaScript(script, resultCallback);
868 }
869
870 /**
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700871 * Saves the current view as a web archive.
872 *
Steve Block4e584df2012-04-24 23:12:47 +0100873 * @param filename the filename where the archive should be placed
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700874 */
875 public void saveWebArchive(String filename) {
Steve Block51b08912011-04-27 15:04:48 +0100876 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000877 mProvider.saveWebArchive(filename);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700878 }
879
880 /**
881 * Saves the current view as a web archive.
882 *
Steve Block4e584df2012-04-24 23:12:47 +0100883 * @param basename the filename where the archive should be placed
Nate Fischer0a6140d2017-09-05 12:37:49 -0700884 * @param autoname if {@code false}, takes basename to be a file. If {@code true}, basename
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700885 * is assumed to be a directory in which a filename will be
Steve Block4e584df2012-04-24 23:12:47 +0100886 * chosen according to the URL of the current page.
887 * @param callback called after the web archive has been saved. The
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700888 * parameter for onReceiveValue will either be the filename
Nate Fischer0a6140d2017-09-05 12:37:49 -0700889 * under which the file was saved, or {@code null} if saving the
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700890 * file failed.
891 */
Nate Fischer3442c742017-09-08 17:02:00 -0700892 public void saveWebArchive(String basename, boolean autoname, @Nullable ValueCallback<String>
893 callback) {
Steve Block51b08912011-04-27 15:04:48 +0100894 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000895 mProvider.saveWebArchive(basename, autoname, callback);
Elliott Slaughterb48fdbe2010-06-30 11:39:52 -0700896 }
897
898 /**
Steve Block4e584df2012-04-24 23:12:47 +0100899 * Stops the current load.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 */
901 public void stopLoading() {
Steve Block51b08912011-04-27 15:04:48 +0100902 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000903 mProvider.stopLoading();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
905
906 /**
Steve Block4e584df2012-04-24 23:12:47 +0100907 * Reloads the current URL.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 */
909 public void reload() {
Steve Block51b08912011-04-27 15:04:48 +0100910 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000911 mProvider.reload();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 }
913
914 /**
Steve Block4e584df2012-04-24 23:12:47 +0100915 * Gets whether this WebView has a back history item.
916 *
Nate Fischer2be201e2017-10-26 10:43:00 -0700917 * @return {@code true} if this WebView has a back history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 */
919 public boolean canGoBack() {
Steve Block51b08912011-04-27 15:04:48 +0100920 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000921 return mProvider.canGoBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 }
923
924 /**
Steve Block4e584df2012-04-24 23:12:47 +0100925 * Goes back in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 */
927 public void goBack() {
Steve Block51b08912011-04-27 15:04:48 +0100928 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000929 mProvider.goBack();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 }
931
932 /**
Steve Block4e584df2012-04-24 23:12:47 +0100933 * Gets whether this WebView has a forward history item.
934 *
Nate Fischer2be201e2017-10-26 10:43:00 -0700935 * @return {@code true} if this WebView has a forward history item
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 */
937 public boolean canGoForward() {
Steve Block51b08912011-04-27 15:04:48 +0100938 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000939 return mProvider.canGoForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941
942 /**
Steve Block4e584df2012-04-24 23:12:47 +0100943 * Goes forward in the history of this WebView.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 */
945 public void goForward() {
Steve Block51b08912011-04-27 15:04:48 +0100946 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000947 mProvider.goForward();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
949
950 /**
Steve Block4e584df2012-04-24 23:12:47 +0100951 * Gets whether the page can go back or forward the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 * number of steps.
Steve Block4e584df2012-04-24 23:12:47 +0100953 *
954 * @param steps the negative or positive number of steps to move the
955 * history
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 */
957 public boolean canGoBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100958 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000959 return mProvider.canGoBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 }
961
962 /**
Steve Block4e584df2012-04-24 23:12:47 +0100963 * Goes to the history item that is the number of steps away from
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 * the current item. Steps is negative if backward and positive
965 * if forward.
Steve Block4e584df2012-04-24 23:12:47 +0100966 *
967 * @param steps the number of steps to take back or forward in the back
968 * forward list
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 */
970 public void goBackOrForward(int steps) {
Steve Block51b08912011-04-27 15:04:48 +0100971 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000972 mProvider.goBackOrForward(steps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400974
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700975 /**
Steve Block4e584df2012-04-24 23:12:47 +0100976 * Gets whether private browsing is enabled in this WebView.
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700977 */
Elliott Slaughter7c2d1352010-08-20 15:57:18 -0700978 public boolean isPrivateBrowsingEnabled() {
Steve Block51b08912011-04-27 15:04:48 +0100979 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000980 return mProvider.isPrivateBrowsingEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 /**
Steve Block4e584df2012-04-24 23:12:47 +0100984 * Scrolls the contents of this WebView up by half the view size.
985 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700986 * @param top {@code true} to jump to the top of the page
987 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 */
989 public boolean pageUp(boolean top) {
Steve Block51b08912011-04-27 15:04:48 +0100990 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +0000991 return mProvider.pageUp(top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 }
Cary Clarkd6982c92009-05-29 11:02:22 -0400993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 /**
Steve Block4e584df2012-04-24 23:12:47 +0100995 * Scrolls the contents of this WebView down by half the page size.
996 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700997 * @param bottom {@code true} to jump to bottom of page
998 * @return {@code true} if the page was scrolled
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 */
1000 public boolean pageDown(boolean bottom) {
Steve Block51b08912011-04-27 15:04:48 +01001001 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001002 return mProvider.pageDown(bottom);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 }
1004
1005 /**
Tobias Sargeantb3656042015-05-13 11:23:57 +01001006 * Posts a {@link VisualStateCallback}, which will be called when
1007 * the current state of the WebView is ready to be drawn.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001008 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001009 * <p>Because updates to the DOM are processed asynchronously, updates to the DOM may not
Tobias Sargeantb3656042015-05-13 11:23:57 +01001010 * immediately be reflected visually by subsequent {@link WebView#onDraw} invocations. The
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001011 * {@link VisualStateCallback} provides a mechanism to notify the caller when the contents of
Tobias Sargeantb3656042015-05-13 11:23:57 +01001012 * the DOM at the current time are ready to be drawn the next time the {@link WebView}
Nate Fischerf02f8462017-09-11 15:16:33 -07001013 * draws.
Tobias Sargeantb3656042015-05-13 11:23:57 +01001014 *
1015 * <p>The next draw after the callback completes is guaranteed to reflect all the updates to the
Nate Fischerffb81c42016-09-26 12:35:47 -07001016 * DOM up to the point at which the {@link VisualStateCallback} was posted, but it may also
Nate Fischerf02f8462017-09-11 15:16:33 -07001017 * contain updates applied after the callback was posted.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001018 *
1019 * <p>The state of the DOM covered by this API includes the following:
1020 * <ul>
1021 * <li>primitive HTML elements (div, img, span, etc..)</li>
1022 * <li>images</li>
1023 * <li>CSS animations</li>
1024 * <li>WebGL</li>
1025 * <li>canvas</li>
1026 * </ul>
1027 * It does not include the state of:
1028 * <ul>
1029 * <li>the video tag</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001030 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001031 *
1032 * <p>To guarantee that the {@link WebView} will successfully render the first frame
1033 * after the {@link VisualStateCallback#onComplete} method has been called a set of conditions
1034 * must be met:
1035 * <ul>
1036 * <li>If the {@link WebView}'s visibility is set to {@link View#VISIBLE VISIBLE} then
1037 * the {@link WebView} must be attached to the view hierarchy.</li>
1038 * <li>If the {@link WebView}'s visibility is set to {@link View#INVISIBLE INVISIBLE}
1039 * then the {@link WebView} must be attached to the view hierarchy and must be made
1040 * {@link View#VISIBLE VISIBLE} from the {@link VisualStateCallback#onComplete} method.</li>
1041 * <li>If the {@link WebView}'s visibility is set to {@link View#GONE GONE} then the
1042 * {@link WebView} must be attached to the view hierarchy and its
1043 * {@link AbsoluteLayout.LayoutParams LayoutParams}'s width and height need to be set to fixed
1044 * values and must be made {@link View#VISIBLE VISIBLE} from the
1045 * {@link VisualStateCallback#onComplete} method.</li>
Nate Fischerf02f8462017-09-11 15:16:33 -07001046 * </ul>
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001047 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001048 * <p>When using this API it is also recommended to enable pre-rasterization if the {@link
Nate Fischerffb81c42016-09-26 12:35:47 -07001049 * WebView} is off screen to avoid flickering. See {@link WebSettings#setOffscreenPreRaster} for
Nate Fischerf02f8462017-09-11 15:16:33 -07001050 * more details and do consider its caveats.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001051 *
Tobias Sargeantb3656042015-05-13 11:23:57 +01001052 * @param requestId An id that will be returned in the callback to allow callers to match
1053 * requests with callbacks.
1054 * @param callback The callback to be invoked.
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001055 */
Tobias Sargeantb3656042015-05-13 11:23:57 +01001056 public void postVisualStateCallback(long requestId, VisualStateCallback callback) {
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001057 checkThread();
Tobias Sargeanta8352f42015-03-03 18:07:40 +00001058 mProvider.insertVisualStateCallback(requestId, callback);
1059 }
1060
1061 /**
Steve Block4e584df2012-04-24 23:12:47 +01001062 * Clears this WebView so that onDraw() will draw nothing but white background,
1063 * and onMeasure() will return 0 if MeasureSpec is not MeasureSpec.EXACTLY.
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001064 * @deprecated Use WebView.loadUrl("about:blank") to reliably reset the view state
1065 * and release page resources (including any running JavaScript).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001067 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 public void clearView() {
Steve Block51b08912011-04-27 15:04:48 +01001069 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001070 mProvider.clearView();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 /**
Steve Block72498ed2012-07-17 15:57:25 +01001074 * Gets a new picture that captures the current contents of this WebView.
1075 * The picture is of the entire document being displayed, and is not
1076 * limited to the area currently displayed by this WebView. Also, the
1077 * picture is a static copy and is unaffected by later changes to the
1078 * content being displayed.
1079 * <p>
1080 * Note that due to internal changes, for API levels between
1081 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and
1082 * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} inclusive, the
1083 * picture does not include fixed position elements or scrollable divs.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001084 * <p>
1085 * Note that from {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} the returned picture
1086 * should only be drawn into bitmap-backed Canvas - using any other type of Canvas will involve
1087 * additional conversion at a cost in memory and performance. Also the
1088 * {@link android.graphics.Picture#createFromStream} and
1089 * {@link android.graphics.Picture#writeToStream} methods are not supported on the
1090 * returned object.
1091 *
1092 * @deprecated Use {@link #onDraw} to obtain a bitmap snapshot of the WebView, or
Jonathan Dixondf3859e2013-09-18 12:51:47 -07001093 * {@link #saveWebArchive} to save the content to a file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 *
Steve Block72498ed2012-07-17 15:57:25 +01001095 * @return a picture that captures the current contents of this WebView
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001097 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 public Picture capturePicture() {
Steve Block51b08912011-04-27 15:04:48 +01001099 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001100 return mProvider.capturePicture();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
1102
Cary Clarkd6982c92009-05-29 11:02:22 -04001103 /**
Selim Gurun23a1af62014-03-14 16:52:45 -07001104 * @deprecated Use {@link #createPrintDocumentAdapter(String)} which requires user
1105 * to provide a print document name.
1106 */
1107 @Deprecated
1108 public PrintDocumentAdapter createPrintDocumentAdapter() {
1109 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001110 return mProvider.createPrintDocumentAdapter("default");
1111 }
1112
1113 /**
Nate Fischerffb81c42016-09-26 12:35:47 -07001114 * Creates a PrintDocumentAdapter that provides the content of this WebView for printing.
Selim Gurun2167c0b2013-08-05 15:23:09 -07001115 *
Nate Fischerffb81c42016-09-26 12:35:47 -07001116 * The adapter works by converting the WebView contents to a PDF stream. The WebView cannot
Selim Gurunda7d6422013-09-06 14:39:05 -07001117 * be drawn during the conversion process - any such draws are undefined. It is recommended
Nate Fischerffb81c42016-09-26 12:35:47 -07001118 * to use a dedicated off screen WebView for the printing. If necessary, an application may
Selim Gurunda7d6422013-09-06 14:39:05 -07001119 * temporarily hide a visible WebView by using a custom PrintDocumentAdapter instance
1120 * wrapped around the object returned and observing the onStart and onFinish methods. See
1121 * {@link android.print.PrintDocumentAdapter} for more information.
Selim Gurun23a1af62014-03-14 16:52:45 -07001122 *
1123 * @param documentName The user-facing name of the printed document. See
1124 * {@link android.print.PrintDocumentInfo}
Selim Gurun2167c0b2013-08-05 15:23:09 -07001125 */
Selim Gurun23a1af62014-03-14 16:52:45 -07001126 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName) {
Selim Gurun2167c0b2013-08-05 15:23:09 -07001127 checkThread();
Selim Gurun23a1af62014-03-14 16:52:45 -07001128 return mProvider.createPrintDocumentAdapter(documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -07001129 }
1130
1131 /**
Steve Block4e584df2012-04-24 23:12:47 +01001132 * Gets the current scale of this WebView.
1133 *
1134 * @return the current scale
Kristian Monsen5cc23512012-08-09 15:33:08 -04001135 *
1136 * @deprecated This method is prone to inaccuracy due to race conditions
1137 * between the web rendering and UI threads; prefer
1138 * {@link WebViewClient#onScaleChanged}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04001140 @Deprecated
John Reck926cf562012-06-14 10:00:31 -07001141 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 public float getScale() {
Steve Block51b08912011-04-27 15:04:48 +01001143 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001144 return mProvider.getScale();
Mangesh Ghiwareb5f9fc32011-08-31 17:49:07 -07001145 }
1146
1147 /**
Mikhail Naganov00303362013-09-02 10:57:04 +01001148 * Sets the initial scale for this WebView. 0 means default.
1149 * The behavior for the default scale depends on the state of
1150 * {@link WebSettings#getUseWideViewPort()} and
1151 * {@link WebSettings#getLoadWithOverviewMode()}.
1152 * If the content fits into the WebView control by width, then
Nate Fischerffb81c42016-09-26 12:35:47 -07001153 * the zoom is set to 100%. For wide content, the behavior
Mikhail Naganov00303362013-09-02 10:57:04 +01001154 * depends on the state of {@link WebSettings#getLoadWithOverviewMode()}.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001155 * If its value is {@code true}, the content will be zoomed out to be fit
Mikhail Naganov00303362013-09-02 10:57:04 +01001156 * by width into the WebView control, otherwise not.
1157 *
1158 * If initial scale is greater than 0, WebView starts with this value
1159 * as initial scale.
Mangesh Ghiwaree832b632011-11-16 11:46:39 -08001160 * Please note that unlike the scale properties in the viewport meta tag,
1161 * this method doesn't take the screen density into account.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 *
Steve Block4e584df2012-04-24 23:12:47 +01001163 * @param scaleInPercent the initial scale in percent
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 */
1165 public void setInitialScale(int scaleInPercent) {
Steve Block51b08912011-04-27 15:04:48 +01001166 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001167 mProvider.setInitialScale(scaleInPercent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 }
1169
1170 /**
Steve Block4e584df2012-04-24 23:12:47 +01001171 * Invokes the graphical zoom picker widget for this WebView. This will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 * result in the zoom widget appearing on the screen to control the zoom
1173 * level of this WebView.
1174 */
1175 public void invokeZoomPicker() {
Steve Block51b08912011-04-27 15:04:48 +01001176 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001177 mProvider.invokeZoomPicker();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 }
1179
1180 /**
Steve Block4e584df2012-04-24 23:12:47 +01001181 * Gets a HitTestResult based on the current cursor node. If a HTML::a
1182 * tag is found and the anchor has a non-JavaScript URL, the HitTestResult
1183 * type is set to SRC_ANCHOR_TYPE and the URL is set in the "extra" field.
1184 * If the anchor does not have a URL or if it is a JavaScript URL, the type
1185 * will be UNKNOWN_TYPE and the URL has to be retrieved through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 * {@link #requestFocusNodeHref} asynchronously. If a HTML::img tag is
Steve Block4e584df2012-04-24 23:12:47 +01001187 * 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 -08001188 * the "extra" field. A type of
Steve Block4e584df2012-04-24 23:12:47 +01001189 * 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 -08001190 * a child node. If a phone number is found, the HitTestResult type is set
1191 * to PHONE_TYPE and the phone number is set in the "extra" field of
1192 * HitTestResult. If a map address is found, the HitTestResult type is set
1193 * to GEO_TYPE and the address is set in the "extra" field of HitTestResult.
1194 * If an email address is found, the HitTestResult type is set to EMAIL_TYPE
1195 * and the email is set in the "extra" field of HitTestResult. Otherwise,
1196 * HitTestResult type is set to UNKNOWN_TYPE.
1197 */
1198 public HitTestResult getHitTestResult() {
Steve Block51b08912011-04-27 15:04:48 +01001199 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001200 return mProvider.getHitTestResult();
Cary Clarkb8491342010-11-29 16:23:19 -05001201 }
1202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 /**
Steve Block4e584df2012-04-24 23:12:47 +01001204 * Requests the anchor or image element URL at the last tapped point.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001205 * If hrefMsg is {@code null}, this method returns immediately and does not
Cary Clark861368a2010-12-15 11:24:37 -05001206 * dispatch hrefMsg to its target. If the tapped point hits an image,
1207 * an anchor, or an image in an anchor, the message associates
1208 * strings in named keys in its data. The value paired with the key
1209 * may be an empty string.
Cary Clarkd6982c92009-05-29 11:02:22 -04001210 *
Steve Block4e584df2012-04-24 23:12:47 +01001211 * @param hrefMsg the message to be dispatched with the result of the
1212 * request. The message data contains three keys. "url"
1213 * returns the anchor's href attribute. "title" returns the
1214 * anchor's text. "src" returns the image's src attribute.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 */
Nate Fischer3442c742017-09-08 17:02:00 -07001216 public void requestFocusNodeHref(@Nullable Message hrefMsg) {
Steve Block51b08912011-04-27 15:04:48 +01001217 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001218 mProvider.requestFocusNodeHref(hrefMsg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 /**
Steve Block4e584df2012-04-24 23:12:47 +01001222 * Requests the URL of the image last touched by the user. msg will be sent
1223 * to its target with a String representing the URL as its object.
Cary Clarkd6982c92009-05-29 11:02:22 -04001224 *
Steve Block4e584df2012-04-24 23:12:47 +01001225 * @param msg the message to be dispatched with the result of the request
Nate Fischer0a6140d2017-09-05 12:37:49 -07001226 * as the data member with "url" as key. The result can be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 */
1228 public void requestImageRef(Message msg) {
Steve Block51b08912011-04-27 15:04:48 +01001229 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001230 mProvider.requestImageRef(msg);
Adam Powell637d3372010-08-25 14:37:03 -07001231 }
1232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 /**
Steve Block4e584df2012-04-24 23:12:47 +01001234 * 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 -08001235 * passed to WebViewClient.onPageStarted because although the load for
Steve Block4e584df2012-04-24 23:12:47 +01001236 * that URL has begun, the current page may not have changed.
1237 *
1238 * @return the URL for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 */
John Reck926cf562012-06-14 10:00:31 -07001240 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 public String getUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001242 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001243 return mProvider.getUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 /**
Steve Block4e584df2012-04-24 23:12:47 +01001247 * Gets the original URL for the current page. This is not always the same
1248 * as the URL passed to WebViewClient.onPageStarted because although the
1249 * load for that URL has begun, the current page may not have changed.
1250 * Also, there may have been redirects resulting in a different URL to that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 * originally requested.
Steve Block4e584df2012-04-24 23:12:47 +01001252 *
1253 * @return the URL that was originally requested for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 */
John Reck926cf562012-06-14 10:00:31 -07001255 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 public String getOriginalUrl() {
Steve Block51b08912011-04-27 15:04:48 +01001257 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001258 return mProvider.getOriginalUrl();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260
1261 /**
Steve Block4e584df2012-04-24 23:12:47 +01001262 * 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 -08001263 * until WebViewClient.onReceivedTitle is called.
Steve Block4e584df2012-04-24 23:12:47 +01001264 *
1265 * @return the title for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 */
John Reck926cf562012-06-14 10:00:31 -07001267 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 public String getTitle() {
Steve Block51b08912011-04-27 15:04:48 +01001269 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001270 return mProvider.getTitle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 }
1272
1273 /**
Steve Block4e584df2012-04-24 23:12:47 +01001274 * Gets the favicon for the current page. This is the favicon of the current
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 * page until WebViewClient.onReceivedIcon is called.
Steve Block4e584df2012-04-24 23:12:47 +01001276 *
1277 * @return the favicon for the current page
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 */
1279 public Bitmap getFavicon() {
Steve Block51b08912011-04-27 15:04:48 +01001280 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001281 return mProvider.getFavicon();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 }
1283
1284 /**
Steve Block4e584df2012-04-24 23:12:47 +01001285 * Gets the touch icon URL for the apple-touch-icon <link> element, or
Ben Murdoch372dfc82010-07-01 15:56:01 +01001286 * a URL on this site's server pointing to the standard location of a
1287 * touch icon.
Steve Block4e584df2012-04-24 23:12:47 +01001288 *
Patrick Scott2ba12622009-08-04 13:20:05 -04001289 * @hide
1290 */
Mathew Inwood42afea22018-08-16 19:18:28 +01001291 @UnsupportedAppUsage
Patrick Scott2ba12622009-08-04 13:20:05 -04001292 public String getTouchIconUrl() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001293 return mProvider.getTouchIconUrl();
Patrick Scott2ba12622009-08-04 13:20:05 -04001294 }
1295
1296 /**
Steve Block4e584df2012-04-24 23:12:47 +01001297 * Gets the progress for the current page.
1298 *
1299 * @return the progress for the current page between 0 and 100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 */
1301 public int getProgress() {
Steve Block51b08912011-04-27 15:04:48 +01001302 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001303 return mProvider.getProgress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 }
Cary Clarkd6982c92009-05-29 11:02:22 -04001305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 /**
Steve Block4e584df2012-04-24 23:12:47 +01001307 * Gets the height of the HTML content.
1308 *
1309 * @return the height of the HTML content
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 */
John Reck926cf562012-06-14 10:00:31 -07001311 @ViewDebug.ExportedProperty(category = "webview")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 public int getContentHeight() {
Steve Block51b08912011-04-27 15:04:48 +01001313 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001314 return mProvider.getContentHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 }
1316
1317 /**
Steve Block4e584df2012-04-24 23:12:47 +01001318 * Gets the width of the HTML content.
1319 *
1320 * @return the width of the HTML content
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001321 * @hide
1322 */
John Reck926cf562012-06-14 10:00:31 -07001323 @ViewDebug.ExportedProperty(category = "webview")
Mathew Inwood42afea22018-08-16 19:18:28 +01001324 @UnsupportedAppUsage
Leon Scrogginsea96d1e2009-09-23 13:41:01 -04001325 public int getContentWidth() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001326 return mProvider.getContentWidth();
John Reck9b90d552011-06-14 15:19:17 -07001327 }
1328
1329 /**
Steve Block4e584df2012-04-24 23:12:47 +01001330 * Pauses all layout, parsing, and JavaScript timers for all WebViews. This
1331 * is a global requests, not restricted to just this WebView. This can be
Mike Reedd205d5b2009-05-27 11:02:29 -04001332 * useful if the application has been paused.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 */
1334 public void pauseTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001335 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001336 mProvider.pauseTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 }
1338
1339 /**
Steve Block4e584df2012-04-24 23:12:47 +01001340 * Resumes all layout, parsing, and JavaScript timers for all WebViews.
Mike Reedd205d5b2009-05-27 11:02:29 -04001341 * This will resume dispatching all timers.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 */
1343 public void resumeTimers() {
Steve Block51b08912011-04-27 15:04:48 +01001344 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001345 mProvider.resumeTimers();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 }
1347
1348 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001349 * Does a best-effort attempt to pause any processing that can be paused
1350 * safely, such as animations and geolocation. Note that this call
1351 * does not pause JavaScript. To pause JavaScript globally, use
1352 * {@link #pauseTimers}.
1353 *
1354 * To resume WebView, call {@link #onResume}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001355 */
1356 public void onPause() {
Steve Block51b08912011-04-27 15:04:48 +01001357 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001358 mProvider.onPause();
Mike Reedd205d5b2009-05-27 11:02:29 -04001359 }
1360
1361 /**
Selim Gurun922cb582015-07-31 11:49:22 -07001362 * Resumes a WebView after a previous call to {@link #onPause}.
Mike Reedd205d5b2009-05-27 11:02:29 -04001363 */
1364 public void onResume() {
Steve Block51b08912011-04-27 15:04:48 +01001365 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001366 mProvider.onResume();
Mike Reedd205d5b2009-05-27 11:02:29 -04001367 }
1368
1369 /**
Steve Block4e584df2012-04-24 23:12:47 +01001370 * Gets whether this WebView is paused, meaning onPause() was called.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001371 * Calling onResume() sets the paused state back to {@code false}.
Steve Block4e584df2012-04-24 23:12:47 +01001372 *
Mike Reedd205d5b2009-05-27 11:02:29 -04001373 * @hide
1374 */
Mathew Inwood42afea22018-08-16 19:18:28 +01001375 @UnsupportedAppUsage
Mike Reedd205d5b2009-05-27 11:02:29 -04001376 public boolean isPaused() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00001377 return mProvider.isPaused();
Mike Reedd205d5b2009-05-27 11:02:29 -04001378 }
1379
1380 /**
Steve Block4e584df2012-04-24 23:12:47 +01001381 * Informs this WebView that memory is low so that it can free any available
1382 * memory.
Jonathan Dixon5545d082013-08-31 22:43:11 -07001383 * @deprecated Memory caches are automatically dropped when no longer needed, and in response
1384 * to system memory pressure.
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001385 */
Jonathan Dixon5545d082013-08-31 22:43:11 -07001386 @Deprecated
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001387 public void freeMemory() {
Steve Block51b08912011-04-27 15:04:48 +01001388 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001389 mProvider.freeMemory();
Derek Sollenbergere0155e92009-06-10 15:35:45 -04001390 }
1391
1392 /**
Steve Block4e584df2012-04-24 23:12:47 +01001393 * Clears the resource cache. Note that the cache is per-application, so
Mike Hearnadcd2ed2009-01-21 16:44:36 +01001394 * this will clear the cache for all WebViews used.
1395 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001396 * @param includeDiskFiles if {@code false}, only the RAM cache is cleared
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 */
1398 public void clearCache(boolean includeDiskFiles) {
Steve Block51b08912011-04-27 15:04:48 +01001399 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001400 mProvider.clearCache(includeDiskFiles);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 }
1402
1403 /**
Steve Block219dfa42012-07-20 10:31:21 +01001404 * Removes the autocomplete popup from the currently focused form field, if
1405 * present. Note this only affects the display of the autocomplete popup,
1406 * it does not remove any saved form data from this WebView's store. To do
1407 * that, use {@link WebViewDatabase#clearFormData}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 */
1409 public void clearFormData() {
Steve Block51b08912011-04-27 15:04:48 +01001410 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001411 mProvider.clearFormData();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 }
1413
1414 /**
Steve Block4e584df2012-04-24 23:12:47 +01001415 * Tells this WebView to clear its internal back/forward list.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 */
1417 public void clearHistory() {
Steve Block51b08912011-04-27 15:04:48 +01001418 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001419 mProvider.clearHistory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 }
1421
1422 /**
Steve Block4e584df2012-04-24 23:12:47 +01001423 * Clears the SSL preferences table stored in response to proceeding with
1424 * SSL certificate errors.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 */
1426 public void clearSslPreferences() {
Steve Block51b08912011-04-27 15:04:48 +01001427 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001428 mProvider.clearSslPreferences();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 }
1430
1431 /**
Selim Gurunee89ab42014-06-13 10:53:55 -07001432 * Clears the client certificate preferences stored in response
Nate Fischerffb81c42016-09-26 12:35:47 -07001433 * to proceeding/cancelling client cert requests. Note that WebView
Torne (Richard Coles)53267722018-06-20 15:31:49 -04001434 * automatically clears these preferences when the system keychain is updated.
1435 * The preferences are shared by all the WebViews that are created by the embedder application.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001436 *
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001437 * @param onCleared A runnable to be invoked when client certs are cleared.
Nate Fischer3442c742017-09-08 17:02:00 -07001438 * The runnable will be called in UI thread.
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001439 */
Nate Fischer3442c742017-09-08 17:02:00 -07001440 public static void clearClientCertPreferences(@Nullable Runnable onCleared) {
Selim Gurune1c6c3a2014-04-28 14:21:21 -07001441 getFactory().getStatics().clearClientCertPreferences(onCleared);
Selim Gurunb6aa97e2014-03-26 14:10:28 -07001442 }
1443
1444 /**
Nate Fischer2b108d82017-08-21 17:59:55 -07001445 * Starts Safe Browsing initialization.
Nate Fischer471891d2017-07-18 19:15:52 -07001446 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001447 * URL loads are not guaranteed to be protected by Safe Browsing until after {@code callback} is
1448 * invoked with {@code true}. Safe Browsing is not fully supported on all devices. For those
1449 * devices {@code callback} will receive {@code false}.
Nate Fischer471891d2017-07-18 19:15:52 -07001450 * <p>
Nate Fischerfb92ee12018-01-18 12:01:19 -08001451 * This should not be called if Safe Browsing has been disabled by manifest tag or {@link
1452 * WebSettings#setSafeBrowsingEnabled}. This prepares resources used for Safe Browsing.
Nate Fischer471891d2017-07-18 19:15:52 -07001453 * <p>
Nate Fischer2b108d82017-08-21 17:59:55 -07001454 * This should be called with the Application Context (and will always use the Application
1455 * context to do its work regardless).
Nate Fischer471891d2017-07-18 19:15:52 -07001456 *
Nate Fischer3ca196a2017-07-12 18:45:03 -07001457 * @param context Application Context.
Nate Fischer2b108d82017-08-21 17:59:55 -07001458 * @param callback will be called on the UI thread with {@code true} if initialization is
1459 * successful, {@code false} otherwise.
Nate Fischer0e72c182017-05-30 11:25:17 -07001460 */
Nate Fischer65e3be02018-03-01 00:55:35 -08001461 public static void startSafeBrowsing(@NonNull Context context,
Nate Fischer3442c742017-09-08 17:02:00 -07001462 @Nullable ValueCallback<Boolean> callback) {
Nate Fischer0e72c182017-05-30 11:25:17 -07001463 getFactory().getStatics().initSafeBrowsing(context, callback);
1464 }
1465
1466 /**
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001467 * Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks.
1468 * The list is global for all the WebViews.
Selim Gurun89e93592017-07-28 10:33:58 -07001469 * <p>
1470 * Each rule should take one of these:
1471 * <table>
1472 * <tr><th> Rule </th> <th> Example </th> <th> Matches Subdomain</th> </tr>
Nate Fischerfbebfa92017-08-29 16:17:22 -07001473 * <tr><td> HOSTNAME </td> <td> example.com </td> <td> Yes </td> </tr>
1474 * <tr><td> .HOSTNAME </td> <td> .example.com </td> <td> No </td> </tr>
1475 * <tr><td> IPV4_LITERAL </td> <td> 192.168.1.1 </td> <td> No </td></tr>
1476 * <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 -07001477 * </table>
1478 * <p>
1479 * All other rules, including wildcards, are invalid.
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001480 * <p>
1481 * The correct syntax for hosts is defined by <a
1482 * href="https://tools.ietf.org/html/rfc3986#section-3.2.2">RFC 3986</a>.
Nate Fischerbf158ec2017-06-27 22:52:20 -07001483 *
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001484 * @param hosts the list of hosts
1485 * @param callback will be called with {@code true} if hosts are successfully added to the
1486 * whitelist. It will be called with {@code false} if any hosts are malformed. The callback
1487 * will be run on the UI thread
Nate Fischerbf158ec2017-06-27 22:52:20 -07001488 */
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001489 public static void setSafeBrowsingWhitelist(@NonNull List<String> hosts,
Nate Fischerd6385d32017-07-17 12:58:18 -07001490 @Nullable ValueCallback<Boolean> callback) {
Nate Fischer5a6ae8c2018-02-21 15:27:01 -08001491 getFactory().getStatics().setSafeBrowsingWhitelist(hosts, callback);
Nate Fischerbf158ec2017-06-27 22:52:20 -07001492 }
1493
1494 /**
Nate Fischer3898ac12017-08-09 23:02:36 -07001495 * Returns a URL pointing to the privacy policy for Safe Browsing reporting.
1496 *
1497 * @return the url pointing to a privacy policy document which can be displayed to users.
1498 */
1499 @NonNull
1500 public static Uri getSafeBrowsingPrivacyPolicyUrl() {
1501 return getFactory().getStatics().getSafeBrowsingPrivacyPolicyUrl();
1502 }
1503
1504 /**
Steve Block4e584df2012-04-24 23:12:47 +01001505 * Gets the WebBackForwardList for this WebView. This contains the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 * back/forward list for use in querying each item in the history stack.
1507 * This is a copy of the private WebBackForwardList so it contains only a
1508 * snapshot of the current state. Multiple calls to this method may return
1509 * different objects. The object returned from this method will not be
1510 * updated to reflect any new state.
1511 */
1512 public WebBackForwardList copyBackForwardList() {
Steve Block51b08912011-04-27 15:04:48 +01001513 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001514 return mProvider.copyBackForwardList();
1515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 }
1517
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001518 /**
Steve Block4e584df2012-04-24 23:12:47 +01001519 * Registers the listener to be notified as find-on-page operations
1520 * progress. This will replace the current listener.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001521 *
Steve Block4e584df2012-04-24 23:12:47 +01001522 * @param listener an implementation of {@link FindListener}
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001523 */
1524 public void setFindListener(FindListener listener) {
1525 checkThread();
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00001526 setupFindListenerIfNeeded();
1527 mFindListener.mUserFindListener = listener;
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001528 }
1529
1530 /**
Kristian Monsenf4912582012-08-16 15:26:24 -04001531 * Highlights and scrolls to the next match found by
Victoria Lease0b8413b2012-03-26 13:04:10 -07001532 * {@link #findAllAsync}, wrapping around page boundaries as necessary.
Kristian Monsenf4912582012-08-16 15:26:24 -04001533 * Notifies any registered {@link FindListener}. If {@link #findAllAsync(String)}
1534 * has not been called yet, or if {@link #clearMatches} has been called since the
1535 * last find operation, this function does nothing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 *
Steve Block4e584df2012-04-24 23:12:47 +01001537 * @param forward the direction to search
Victoria Lease0b8413b2012-03-26 13:04:10 -07001538 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 */
1540 public void findNext(boolean forward) {
Steve Block51b08912011-04-27 15:04:48 +01001541 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001542 mProvider.findNext(forward);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 }
1544
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001545 /**
Steve Block4e584df2012-04-24 23:12:47 +01001546 * Finds all instances of find on the page and highlights them.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001547 * Notifies any registered {@link FindListener}.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001548 *
Steve Block4e584df2012-04-24 23:12:47 +01001549 * @param find the string to find
Nate Fischerffb81c42016-09-26 12:35:47 -07001550 * @return the number of occurrences of the String "find" that were found
Victoria Lease0b8413b2012-03-26 13:04:10 -07001551 * @deprecated {@link #findAllAsync} is preferred.
1552 * @see #setFindListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 */
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001554 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 public int findAll(String find) {
Steve Block51b08912011-04-27 15:04:48 +01001556 checkThread();
Jonathan Dixon9f21c1c2012-04-12 11:14:20 +01001557 StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
Jonathan Dixon3c909522012-02-28 18:45:06 +00001558 return mProvider.findAll(find);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 }
1560
Cary Clark3403eb32010-03-03 10:05:16 -05001561 /**
Steve Block4e584df2012-04-24 23:12:47 +01001562 * Finds all instances of find on the page and highlights them,
Victoria Lease0b8413b2012-03-26 13:04:10 -07001563 * asynchronously. Notifies any registered {@link FindListener}.
Kristian Monsenf4912582012-08-16 15:26:24 -04001564 * Successive calls to this will cancel any pending searches.
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001565 *
Steve Block4e584df2012-04-24 23:12:47 +01001566 * @param find the string to find.
Victoria Lease0b8413b2012-03-26 13:04:10 -07001567 * @see #setFindListener
Victoria Leaseabeb6a72012-03-05 16:29:12 -08001568 */
1569 public void findAllAsync(String find) {
1570 checkThread();
1571 mProvider.findAllAsync(find);
1572 }
1573
1574 /**
Steve Block4e584df2012-04-24 23:12:47 +01001575 * Starts an ActionMode for finding text in this WebView. Only works if this
1576 * WebView is attached to the view system.
1577 *
1578 * @param text if non-null, will be the initial text to search for.
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001579 * Otherwise, the last String searched for in this WebView will
1580 * be used to start.
Nate Fischer0a6140d2017-09-05 12:37:49 -07001581 * @param showIme if {@code true}, show the IME, assuming the user will begin typing.
1582 * If {@code false} and text is non-null, perform a find all.
1583 * @return {@code true} if the find dialog is shown, {@code false} otherwise
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001584 * @deprecated This method does not work reliably on all Android versions;
1585 * implementing a custom find dialog using WebView.findAllAsync()
1586 * provides a more robust solution.
Cary Clarkde023c12010-03-03 10:05:16 -05001587 */
Jonathan Dixon835b1fc2013-02-25 12:29:33 -08001588 @Deprecated
Nate Fischer3442c742017-09-08 17:02:00 -07001589 public boolean showFindDialog(@Nullable String text, boolean showIme) {
Steve Block51b08912011-04-27 15:04:48 +01001590 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001591 return mProvider.showFindDialog(text, showIme);
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001592 }
1593
1594 /**
Steve Block4e584df2012-04-24 23:12:47 +01001595 * Gets the first substring consisting of the address of a physical
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 * location. Currently, only addresses in the United States are detected,
1597 * and consist of:
Steve Block4e584df2012-04-24 23:12:47 +01001598 * <ul>
1599 * <li>a house number</li>
1600 * <li>a street name</li>
1601 * <li>a street type (Road, Circle, etc), either spelled out or
1602 * abbreviated</li>
1603 * <li>a city name</li>
1604 * <li>a state or territory, either spelled out or two-letter abbr</li>
1605 * <li>an optional 5 digit or 9 digit zip code</li>
1606 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 * All names must be correctly capitalized, and the zip code, if present,
1608 * must be valid for the state. The street type must be a standard USPS
1609 * spelling or abbreviation. The state or territory must also be spelled
Cary Clarkd6982c92009-05-29 11:02:22 -04001610 * or abbreviated using USPS standards. The house number may not exceed
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 * five digits.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 *
Steve Block4e584df2012-04-24 23:12:47 +01001613 * @param addr the string to search for addresses
Nate Fischer0a6140d2017-09-05 12:37:49 -07001614 * @return the address, or if no address is found, {@code null}
Jan Althaus003889a2018-04-04 15:29:10 +02001615 * @deprecated this method is superseded by {@link TextClassifier#generateLinks(
1616 * android.view.textclassifier.TextLinks.Request)}. Avoid using this method even when targeting
1617 * API levels where no alternative is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 */
Nate Fischer3442c742017-09-08 17:02:00 -07001619 @Nullable
Jan Althaus003889a2018-04-04 15:29:10 +02001620 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 public static String findAddress(String addr) {
Tobias Sargeantf4d85d82018-01-05 14:34:38 +00001622 if (addr == null) {
1623 throw new NullPointerException("addr is null");
1624 }
1625 return FindAddress.findAddress(addr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 }
1627
Victoria Lease0b8413b2012-03-26 13:04:10 -07001628 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -07001629 * For apps targeting the L release, WebView has a new default behavior that reduces
1630 * memory footprint and increases performance by intelligently choosing
1631 * the portion of the HTML document that needs to be drawn. These
1632 * optimizations are transparent to the developers. However, under certain
1633 * circumstances, an App developer may want to disable them:
Ben Murdoch574fa342015-01-07 14:20:45 +00001634 * <ol>
1635 * <li>When an app uses {@link #onDraw} to do own drawing and accesses portions
1636 * of the page that is way outside the visible portion of the page.</li>
1637 * <li>When an app uses {@link #capturePicture} to capture a very large HTML document.
1638 * Note that capturePicture is a deprecated API.</li>
1639 * </ol>
Selim Gurun17d1adb2014-08-27 11:22:26 -07001640 * Enabling drawing the entire HTML document has a significant performance
1641 * cost. This method should be called before any WebViews are created.
Bo Liu9f3ed852014-07-18 10:03:12 -07001642 */
1643 public static void enableSlowWholeDocumentDraw() {
1644 getFactory().getStatics().enableSlowWholeDocumentDraw();
1645 }
1646
1647 /**
Steve Block4e584df2012-04-24 23:12:47 +01001648 * Clears the highlighting surrounding text matches created by
Kristian Monsenf4912582012-08-16 15:26:24 -04001649 * {@link #findAllAsync}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 */
1651 public void clearMatches() {
Steve Block51b08912011-04-27 15:04:48 +01001652 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001653 mProvider.clearMatches();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 }
1655
1656 /**
Steve Block4e584df2012-04-24 23:12:47 +01001657 * Queries the document to see if it contains any image references. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001658 * message object will be dispatched with arg1 being set to 1 if images
1659 * were found and 0 if the document does not reference any images.
Steve Block4e584df2012-04-24 23:12:47 +01001660 *
1661 * @param response the message that will be dispatched with the result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 */
1663 public void documentHasImages(Message response) {
Steve Block51b08912011-04-27 15:04:48 +01001664 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001665 mProvider.documentHasImages(response);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 }
1667
1668 /**
Steve Block4e584df2012-04-24 23:12:47 +01001669 * Sets the WebViewClient that will receive various notifications and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 * requests. This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001671 *
1672 * @param client an implementation of WebViewClient
Nate Fischer6e585842016-09-29 18:30:58 -07001673 * @see #getWebViewClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 */
1675 public void setWebViewClient(WebViewClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001676 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001677 mProvider.setWebViewClient(client);
Grace Kloba94ab3b62009-10-07 18:00:19 -07001678 }
1679
1680 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001681 * Gets the WebViewClient.
1682 *
1683 * @return the WebViewClient, or a default client if not yet set
1684 * @see #setWebViewClient
1685 */
1686 public WebViewClient getWebViewClient() {
1687 checkThread();
1688 return mProvider.getWebViewClient();
1689 }
1690
1691 /**
Steve Block4e584df2012-04-24 23:12:47 +01001692 * Registers the interface to be used when content can not be handled by
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 * the rendering engine, and should be downloaded instead. This will replace
1694 * the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001695 *
1696 * @param listener an implementation of DownloadListener
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 */
1698 public void setDownloadListener(DownloadListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001699 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001700 mProvider.setDownloadListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 }
1702
1703 /**
Steve Block4e584df2012-04-24 23:12:47 +01001704 * Sets the chrome handler. This is an implementation of WebChromeClient for
Steve Block81f19ff2010-11-01 13:23:24 +00001705 * use in handling JavaScript dialogs, favicons, titles, and the progress.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 * This will replace the current handler.
Steve Block4e584df2012-04-24 23:12:47 +01001707 *
1708 * @param client an implementation of WebChromeClient
Nate Fischer6e585842016-09-29 18:30:58 -07001709 * @see #getWebChromeClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 */
1711 public void setWebChromeClient(WebChromeClient client) {
Steve Block51b08912011-04-27 15:04:48 +01001712 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001713 mProvider.setWebChromeClient(client);
Patrick Scott0b2e84b2010-03-02 08:58:44 -05001714 }
1715
1716 /**
Nate Fischer6e585842016-09-29 18:30:58 -07001717 * Gets the chrome handler.
1718 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001719 * @return the WebChromeClient, or {@code null} if not yet set
Nate Fischer6e585842016-09-29 18:30:58 -07001720 * @see #setWebChromeClient
1721 */
Nate Fischer3442c742017-09-08 17:02:00 -07001722 @Nullable
Nate Fischer6e585842016-09-29 18:30:58 -07001723 public WebChromeClient getWebChromeClient() {
1724 checkThread();
1725 return mProvider.getWebChromeClient();
1726 }
1727
1728 /**
Steve Block4e584df2012-04-24 23:12:47 +01001729 * Sets the Picture listener. This is an interface used to receive
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 * notifications of a new Picture.
Steve Block4e584df2012-04-24 23:12:47 +01001731 *
1732 * @param listener an implementation of WebView.PictureListener
Kristian Monsenfc771652011-05-10 16:44:05 +01001733 * @deprecated This method is now obsolete.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001735 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 public void setPictureListener(PictureListener listener) {
Steve Block51b08912011-04-27 15:04:48 +01001737 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001738 mProvider.setPictureListener(listener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 }
1740
1741 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001742 * Injects the supplied Java object into this WebView. The object is
1743 * injected into the JavaScript context of the main frame, using the
Selim Gurune91d5be2012-09-11 16:11:22 -07001744 * supplied name. This allows the Java object's methods to be
Selim Gurunb4c02e62012-09-12 13:36:21 -07001745 * accessed from JavaScript. For applications targeted to API
1746 * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Selim Gurune91d5be2012-09-11 16:11:22 -07001747 * and above, only public methods that are annotated with
1748 * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript.
Selim Gurunb4c02e62012-09-12 13:36:21 -07001749 * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below,
Selim Gurune91d5be2012-09-11 16:11:22 -07001750 * all public methods (including the inherited ones) can be accessed, see the
Selim Gurunb4c02e62012-09-12 13:36:21 -07001751 * important security note below for implications.
Nate Fischer02e281a2017-08-21 12:03:58 -07001752 * <p> Note that injected objects will not appear in JavaScript until the page is next
1753 * (re)loaded. JavaScript should be enabled before injecting the object. For example:
Selim Gurune91d5be2012-09-11 16:11:22 -07001754 * <pre>
1755 * class JsObject {
1756 * {@literal @}JavascriptInterface
1757 * public String toString() { return "injectedObject"; }
1758 * }
Nate Fischer02e281a2017-08-21 12:03:58 -07001759 * webview.getSettings().setJavaScriptEnabled(true);
Selim Gurune91d5be2012-09-11 16:11:22 -07001760 * webView.addJavascriptInterface(new JsObject(), "injectedObject");
Steve Block4cd73c52011-11-09 13:06:52 +00001761 * webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
1762 * webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
Steve Block3aa800b2012-04-24 13:01:34 +01001763 * <p>
1764 * <strong>IMPORTANT:</strong>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 * <ul>
Steve Block3aa800b2012-04-24 13:01:34 +01001766 * <li> This method can be used to allow JavaScript to control the host
1767 * application. This is a powerful feature, but also presents a security
Scott Rowe607c17f2014-08-07 11:42:09 -07001768 * risk for apps targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or earlier.
1769 * Apps that target a version later than {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
1770 * are still vulnerable if the app runs on a device running Android earlier than 4.2.
1771 * The most secure way to use this method is to target {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
1772 * and to ensure the method is called only when running on Android 4.2 or later.
1773 * With these older versions, JavaScript could use reflection to access an
Steve Block3aa800b2012-04-24 13:01:34 +01001774 * injected object's public fields. Use of this method in a WebView
1775 * containing untrusted content could allow an attacker to manipulate the
1776 * host application in unintended ways, executing Java code with the
1777 * permissions of the host application. Use extreme care when using this
1778 * method in a WebView which could contain untrusted content.</li>
Steve Block4cd73c52011-11-09 13:06:52 +00001779 * <li> JavaScript interacts with Java object on a private, background
Steve Block4e584df2012-04-24 23:12:47 +01001780 * thread of this WebView. Care is therefore required to maintain thread
Scott Rowe607c17f2014-08-07 11:42:09 -07001781 * safety.
1782 * </li>
Selim Gurune91d5be2012-09-11 16:11:22 -07001783 * <li> The Java object's fields are not accessible.</li>
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001784 * <li> For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP}
Mikhail Naganovd380b202014-04-10 18:07:42 +01001785 * and above, methods of injected Java objects are enumerable from
1786 * JavaScript.</li>
Steve Block3aa800b2012-04-24 13:01:34 +01001787 * </ul>
1788 *
1789 * @param object the Java object to inject into this WebView's JavaScript
Nate Fischer0a6140d2017-09-05 12:37:49 -07001790 * context. {@code null} values are ignored.
Steve Block3aa800b2012-04-24 13:01:34 +01001791 * @param name the name used to expose the object in JavaScript
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 */
Steve Block4cd73c52011-11-09 13:06:52 +00001793 public void addJavascriptInterface(Object object, String name) {
Steve Block51b08912011-04-27 15:04:48 +01001794 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001795 mProvider.addJavascriptInterface(object, name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 }
1797
1798 /**
Steve Block3aa800b2012-04-24 13:01:34 +01001799 * Removes a previously injected Java object from this WebView. Note that
1800 * the removal will not be reflected in JavaScript until the page is next
1801 * (re)loaded. See {@link #addJavascriptInterface}.
1802 *
1803 * @param name the name used to expose the object in JavaScript
Steve Block689a3422010-12-07 18:18:26 +00001804 */
Nate Fischer3442c742017-09-08 17:02:00 -07001805 public void removeJavascriptInterface(@NonNull String name) {
Steve Block51b08912011-04-27 15:04:48 +01001806 checkThread();
Steve Block3aa800b2012-04-24 13:01:34 +01001807 mProvider.removeJavascriptInterface(name);
Steve Block689a3422010-12-07 18:18:26 +00001808 }
1809
1810 /**
Selim Gurun4c8093a2015-03-10 17:40:06 -07001811 * Creates a message channel to communicate with JS and returns the message
1812 * ports that represent the endpoints of this message channel. The HTML5 message
Selim Gurun0a814b62015-05-13 10:15:55 -07001813 * channel functionality is described
1814 * <a href="https://html.spec.whatwg.org/multipage/comms.html#messagechannel">here
1815 * </a>
Selim Gurun4c8093a2015-03-10 17:40:06 -07001816 *
Nate Fischerf02f8462017-09-11 15:16:33 -07001817 * <p>The returned message channels are entangled and already in started state.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001818 *
1819 * @return the two message ports that form the message channel.
1820 */
1821 public WebMessagePort[] createWebMessageChannel() {
1822 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001823 return mProvider.createWebMessageChannel();
1824 }
1825
1826 /**
1827 * Post a message to main frame. The embedded application can restrict the
1828 * messages to a certain target origin. See
Selim Gurun0a814b62015-05-13 10:15:55 -07001829 * <a href="https://html.spec.whatwg.org/multipage/comms.html#posting-messages">
1830 * HTML5 spec</a> for how target origin can be used.
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001831 * <p>
1832 * A target origin can be set as a wildcard ("*"). However this is not recommended.
1833 * See the page above for security issues.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -04001834 * <p>
1835 * Content loaded via {@link #loadData(String,String,String)} will not have a
1836 * valid origin, and thus cannot be sent messages securely. If you need to send
1837 * messages using this function, you should use
1838 * {@link #loadDataWithBaseURL(String,String,String,String,String)} with a valid
1839 * HTTP or HTTPS {@code baseUrl} to define a valid origin that can be used for
1840 * messaging.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001841 *
1842 * @param message the WebMessage
Selim Gurunb18fbfa2017-05-18 11:50:26 -07001843 * @param targetOrigin the target origin.
Selim Gurun4c8093a2015-03-10 17:40:06 -07001844 */
Selim Gurun26de90a2015-05-15 11:02:45 -07001845 public void postWebMessage(WebMessage message, Uri targetOrigin) {
Selim Gurun4c8093a2015-03-10 17:40:06 -07001846 checkThread();
Selim Gurun4c8093a2015-03-10 17:40:06 -07001847 mProvider.postMessageToMainFrame(message, targetOrigin);
1848 }
1849
1850 /**
Steve Block4e584df2012-04-24 23:12:47 +01001851 * Gets the WebSettings object used to control the settings for this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 * WebView.
Steve Block4e584df2012-04-24 23:12:47 +01001853 *
1854 * @return a WebSettings object that can be used to control this WebView's
1855 * settings
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 */
1857 public WebSettings getSettings() {
Steve Block51b08912011-04-27 15:04:48 +01001858 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00001859 return mProvider.getSettings();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 }
1861
Jonathan Dixon3c909522012-02-28 18:45:06 +00001862 /**
Mikhail Naganov057989e2013-09-06 16:35:25 -07001863 * Enables debugging of web contents (HTML / CSS / JavaScript)
1864 * loaded into any WebViews of this application. This flag can be enabled
1865 * in order to facilitate debugging of web layouts and JavaScript
1866 * code running inside WebViews. Please refer to WebView documentation
1867 * for the debugging guide.
1868 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07001869 * The default is {@code false}.
Mikhail Naganov057989e2013-09-06 16:35:25 -07001870 *
1871 * @param enabled whether to enable web contents debugging
1872 */
1873 public static void setWebContentsDebuggingEnabled(boolean enabled) {
Mikhail Naganov057989e2013-09-06 16:35:25 -07001874 getFactory().getStatics().setWebContentsDebuggingEnabled(enabled);
1875 }
1876
1877 /**
Steve Block4e584df2012-04-24 23:12:47 +01001878 * Gets the list of currently loaded plugins.
Jonathan Dixon3c909522012-02-28 18:45:06 +00001879 *
Steve Block4e584df2012-04-24 23:12:47 +01001880 * @return the list of currently loaded plugins
Jonathan Dixon3c909522012-02-28 18:45:06 +00001881 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001882 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001883 */
Andrei Popescu385df692009-08-13 11:59:57 +01001884 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +01001885 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 public static synchronized PluginList getPluginList() {
Grace Klobabb245ea2009-11-10 13:13:24 -08001887 return new PluginList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 }
1889
Jonathan Dixon3c909522012-02-28 18:45:06 +00001890 /**
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04001891 * Define the directory used to store WebView data for the current process.
1892 * The provided suffix will be used when constructing data and cache
1893 * directory paths. If this API is not called, no suffix will be used.
1894 * Each directory can be used by only one process in the application. If more
1895 * than one process in an app wishes to use WebView, only one process can use
1896 * the default directory, and other processes must call this API to define
1897 * a unique suffix.
1898 * <p>
Torne (Richard Coles)de956b72018-01-29 16:58:44 -05001899 * This means that different processes in the same application cannot directly
1900 * share WebView-related data, since the data directories must be distinct.
1901 * Applications that use this API may have to explicitly pass data between
1902 * processes. For example, login cookies may have to be copied from one
1903 * process's cookie jar to the other using {@link CookieManager} if both
1904 * processes' WebViews are intended to be logged in.
1905 * <p>
1906 * Most applications should simply ensure that all components of the app
1907 * that rely on WebView are in the same process, to avoid needing multiple
1908 * data directories. The {@link #disableWebView} method can be used to ensure
1909 * that the other processes do not use WebView by accident in this case.
1910 * <p>
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04001911 * This API must be called before any instances of WebView are created in
1912 * this process and before any other methods in the android.webkit package
1913 * are called by this process.
1914 *
1915 * @param suffix The directory name suffix to be used for the current
1916 * process. Must not contain a path separator.
1917 * @throws IllegalStateException if WebView has already been initialized
1918 * in the current process.
1919 * @throws IllegalArgumentException if the suffix contains a path separator.
1920 */
1921 public static void setDataDirectorySuffix(String suffix) {
1922 WebViewFactory.setDataDirectorySuffix(suffix);
1923 }
1924
1925 /**
1926 * Indicate that the current process does not intend to use WebView, and
1927 * that an exception should be thrown if a WebView is created or any other
1928 * methods in the android.webkit package are used.
1929 * <p>
1930 * Applications with multiple processes may wish to call this in processes
Torne (Richard Coles)de956b72018-01-29 16:58:44 -05001931 * that are not intended to use WebView to avoid accidentally incurring
1932 * the memory usage of initializing WebView in long-lived processes that
1933 * have no need for it, and to prevent potential data directory conflicts
1934 * (see {@link #setDataDirectorySuffix}).
1935 * <p>
1936 * For example, an audio player application with one process for its
1937 * activities and another process for its playback service may wish to call
1938 * this method in the playback service's {@link android.app.Service#onCreate}.
Torne (Richard Coles)12f64da2017-10-24 14:59:07 -04001939 *
1940 * @throws IllegalStateException if WebView has already been initialized
1941 * in the current process.
1942 */
1943 public static void disableWebView() {
1944 WebViewFactory.disableWebView();
1945 }
1946
1947
1948 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00001949 * @deprecated This was used for Gears, which has been deprecated.
Steve Block4e584df2012-04-24 23:12:47 +01001950 * @hide
Jonathan Dixon3c909522012-02-28 18:45:06 +00001951 */
Andrei Popescu385df692009-08-13 11:59:57 +01001952 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +01001953 @UnsupportedAppUsage
Steve Block51b08912011-04-27 15:04:48 +01001954 public void refreshPlugins(boolean reloadOpenPages) {
1955 checkThread();
1956 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957
Cary Clark966641a2010-03-04 08:41:56 -05001958 /**
Steve Block4e584df2012-04-24 23:12:47 +01001959 * Puts this WebView into text selection mode. Do not rely on this
1960 * functionality; it will be deprecated in the future.
1961 *
Kristian Monsenfc771652011-05-10 16:44:05 +01001962 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04001963 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Cary Clark966641a2010-03-04 08:41:56 -05001964 */
Kristian Monsenfc771652011-05-10 16:44:05 +01001965 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +01001966 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 public void emulateShiftHeld() {
Steve Block51b08912011-04-27 15:04:48 +01001968 checkThread();
Steve Howard16bd9372010-04-12 14:46:09 -07001969 }
1970
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001971 /**
1972 * @deprecated WebView no longer needs to implement
1973 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1974 */
George Mountfab67a12012-01-05 09:58:53 -08001975 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001976 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001977 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 public void onChildViewAdded(View parent, View child) {}
Cary Clarkd6982c92009-05-29 11:02:22 -04001979
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001980 /**
1981 * @deprecated WebView no longer needs to implement
1982 * ViewGroup.OnHierarchyChangeListener. This method does nothing now.
1983 */
George Mountfab67a12012-01-05 09:58:53 -08001984 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001985 // Cannot add @hide as this can always be accessed via the interface.
Leon Scrogginsa57632f2009-11-16 10:51:12 -05001986 @Deprecated
1987 public void onChildViewRemoved(View p, View child) {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988
1989 /**
1990 * @deprecated WebView should not have implemented
Gilles Debunne0e7d652d2011-02-22 15:26:14 -08001991 * ViewTreeObserver.OnGlobalFocusChangeListener. This method does nothing now.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 */
George Mountfab67a12012-01-05 09:58:53 -08001993 @Override
Jonathan Dixone230e542011-12-21 10:57:00 +00001994 // Cannot add @hide as this can always be accessed via the interface.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 @Deprecated
1996 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
1997 }
1998
Kristian Monsen5cc23512012-08-09 15:33:08 -04001999 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -07002000 * @deprecated Only the default case, {@code true}, will be supported in a future version.
Kristian Monsen5cc23512012-08-09 15:33:08 -04002001 */
2002 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 public void setMapTrackballToArrowKeys(boolean setMap) {
Steve Block51b08912011-04-27 15:04:48 +01002004 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002005 mProvider.setMapTrackballToArrowKeys(setMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 }
2007
Derek Sollenberger03e48912010-05-18 17:03:42 -04002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 public void flingScroll(int vx, int vy) {
Steve Block51b08912011-04-27 15:04:48 +01002010 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002011 mProvider.flingScroll(vx, vy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 }
2013
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002014 /**
Steve Block4e584df2012-04-24 23:12:47 +01002015 * Gets the zoom controls for this WebView, as a separate View. The caller
2016 * is responsible for inserting this View into the layout hierarchy.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002017 * <p/>
Steve Blockb838aef2012-04-23 18:22:15 +01002018 * API level {@link android.os.Build.VERSION_CODES#CUPCAKE} introduced
2019 * built-in zoom mechanisms for the WebView, as opposed to these separate
2020 * zoom controls. The built-in mechanisms are preferred and can be enabled
2021 * using {@link WebSettings#setBuiltInZoomControls}.
The Android Open Source Project10592532009-03-18 17:39:46 -07002022 *
Steve Block4e584df2012-04-24 23:12:47 +01002023 * @deprecated the built-in zoom mechanisms are preferred
Steve Blockb838aef2012-04-23 18:22:15 +01002024 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 */
The Android Open Source Project10592532009-03-18 17:39:46 -07002026 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +01002027 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 public View getZoomControls() {
Steve Block51b08912011-04-27 15:04:48 +01002029 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002030 return mProvider.getZoomControls();
Mangesh Ghiwarefaab93d2011-09-21 13:58:47 -07002031 }
2032
2033 /**
Steve Block4e584df2012-04-24 23:12:47 +01002034 * Gets whether this WebView can be zoomed in.
2035 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002036 * @return {@code true} if this WebView can be zoomed in
Kristian Monsen5cc23512012-08-09 15:33:08 -04002037 *
2038 * @deprecated This method is prone to inaccuracy due to race conditions
2039 * between the web rendering and UI threads; prefer
2040 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002041 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002042 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002043 public boolean canZoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002044 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002045 return mProvider.canZoomIn();
Grace Kloba6164ef12010-06-01 15:59:13 -07002046 }
2047
2048 /**
Steve Block4e584df2012-04-24 23:12:47 +01002049 * Gets whether this WebView can be zoomed out.
2050 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002051 * @return {@code true} if this WebView can be zoomed out
Kristian Monsen5cc23512012-08-09 15:33:08 -04002052 *
2053 * @deprecated This method is prone to inaccuracy due to race conditions
2054 * between the web rendering and UI threads; prefer
2055 * {@link WebViewClient#onScaleChanged}.
Grace Kloba6164ef12010-06-01 15:59:13 -07002056 */
Kristian Monsen5cc23512012-08-09 15:33:08 -04002057 @Deprecated
Grace Kloba6164ef12010-06-01 15:59:13 -07002058 public boolean canZoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002059 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002060 return mProvider.canZoomOut();
Grace Kloba6164ef12010-06-01 15:59:13 -07002061 }
2062
2063 /**
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002064 * Performs a zoom operation in this WebView.
2065 *
Nate Fischerffb81c42016-09-26 12:35:47 -07002066 * @param zoomFactor the zoom factor to apply. The zoom factor will be clamped to the WebView's
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002067 * zoom limits. This value must be in the range 0.01 to 100.0 inclusive.
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002068 */
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002069 public void zoomBy(float zoomFactor) {
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002070 checkThread();
2071 if (zoomFactor < 0.01)
2072 throw new IllegalArgumentException("zoomFactor must be greater than 0.01.");
2073 if (zoomFactor > 100.0)
2074 throw new IllegalArgumentException("zoomFactor must be less than 100.");
Martin Kosiba3a82acd2014-09-05 11:03:58 +01002075 mProvider.zoomBy(zoomFactor);
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +01002076 }
2077
2078 /**
Steve Block4e584df2012-04-24 23:12:47 +01002079 * Performs zoom in in this WebView.
2080 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002081 * @return {@code true} if zoom in succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 */
2083 public boolean zoomIn() {
Steve Block51b08912011-04-27 15:04:48 +01002084 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002085 return mProvider.zoomIn();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086 }
2087
2088 /**
Steve Block4e584df2012-04-24 23:12:47 +01002089 * Performs zoom out in this WebView.
2090 *
Nate Fischer0a6140d2017-09-05 12:37:49 -07002091 * @return {@code true} if zoom out succeeds, {@code false} if no zoom changes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 */
2093 public boolean zoomOut() {
Steve Block51b08912011-04-27 15:04:48 +01002094 checkThread();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002095 return mProvider.zoomOut();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 }
2097
Kristian Monsenfc771652011-05-10 16:44:05 +01002098 /**
2099 * @deprecated This method is now obsolete.
Kristian Monsenf4912582012-08-16 15:26:24 -04002100 * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}
Kristian Monsenfc771652011-05-10 16:44:05 +01002101 */
2102 @Deprecated
Mathew Inwood42afea22018-08-16 19:18:28 +01002103 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 public void debugDump() {
Steve Block51b08912011-04-27 15:04:48 +01002105 checkThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 }
Cary Clarkd6982c92009-05-29 11:02:22 -04002107
John Reck926cf562012-06-14 10:00:31 -07002108 /**
John Reckf2361152012-06-14 15:23:22 -07002109 * See {@link ViewDebug.HierarchyHandler#dumpViewHierarchyWithProperties(BufferedWriter, int)}
John Reck926cf562012-06-14 10:00:31 -07002110 * @hide
2111 */
2112 @Override
2113 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level) {
2114 mProvider.dumpViewHierarchyWithProperties(out, level);
2115 }
2116
2117 /**
2118 * See {@link ViewDebug.HierarchyHandler#findHierarchyView(String, int)}
2119 * @hide
2120 */
2121 @Override
2122 public View findHierarchyView(String className, int hashCode) {
2123 return mProvider.findHierarchyView(className, hashCode);
2124 }
2125
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002126 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07002127 @IntDef(prefix = { "RENDERER_PRIORITY_" }, value = {
2128 RENDERER_PRIORITY_WAIVED,
2129 RENDERER_PRIORITY_BOUND,
2130 RENDERER_PRIORITY_IMPORTANT
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002131 })
2132 @Retention(RetentionPolicy.SOURCE)
2133 public @interface RendererPriority {}
2134
2135 /**
2136 * The renderer associated with this WebView is bound with
2137 * {@link Context#BIND_WAIVE_PRIORITY}. At this priority level
2138 * {@link WebView} renderers will be strong targets for out of memory
2139 * killing.
2140 *
2141 * Use with {@link #setRendererPriorityPolicy}.
2142 */
2143 public static final int RENDERER_PRIORITY_WAIVED = 0;
2144 /**
2145 * The renderer associated with this WebView is bound with
2146 * the default priority for services.
2147 *
2148 * Use with {@link #setRendererPriorityPolicy}.
2149 */
2150 public static final int RENDERER_PRIORITY_BOUND = 1;
2151 /**
2152 * The renderer associated with this WebView is bound with
2153 * {@link Context#BIND_IMPORTANT}.
2154 *
2155 * Use with {@link #setRendererPriorityPolicy}.
2156 */
2157 public static final int RENDERER_PRIORITY_IMPORTANT = 2;
2158
2159 /**
2160 * Set the renderer priority policy for this {@link WebView}. The
2161 * priority policy will be used to determine whether an out of
2162 * process renderer should be considered to be a target for OOM
2163 * killing.
2164 *
2165 * Because a renderer can be associated with more than one
2166 * WebView, the final priority it is computed as the maximum of
2167 * any attached WebViews. When a WebView is destroyed it will
2168 * cease to be considerered when calculating the renderer
2169 * priority. Once no WebViews remain associated with the renderer,
2170 * the priority of the renderer will be reduced to
2171 * {@link #RENDERER_PRIORITY_WAIVED}.
2172 *
2173 * The default policy is to set the priority to
2174 * {@link #RENDERER_PRIORITY_IMPORTANT} regardless of visibility,
2175 * and this should not be changed unless the caller also handles
2176 * renderer crashes with
2177 * {@link WebViewClient#onRenderProcessGone}. Any other setting
2178 * will result in WebView renderers being killed by the system
2179 * more aggressively than the application.
2180 *
2181 * @param rendererRequestedPriority the minimum priority at which
2182 * this WebView desires the renderer process to be bound.
Nate Fischer0a6140d2017-09-05 12:37:49 -07002183 * @param waivedWhenNotVisible if {@code true}, this flag specifies that
Tobias Sargeantd10e4af2017-01-19 14:03:09 +00002184 * when this WebView is not visible, it will be treated as
2185 * if it had requested a priority of
2186 * {@link #RENDERER_PRIORITY_WAIVED}.
2187 */
2188 public void setRendererPriorityPolicy(
2189 @RendererPriority int rendererRequestedPriority,
2190 boolean waivedWhenNotVisible) {
2191 mProvider.setRendererPriorityPolicy(rendererRequestedPriority, waivedWhenNotVisible);
2192 }
2193
2194 /**
2195 * Get the requested renderer priority for this WebView.
2196 *
2197 * @return the requested renderer priority policy.
2198 */
2199 @RendererPriority
2200 public int getRendererRequestedPriority() {
2201 return mProvider.getRendererRequestedPriority();
2202 }
2203
2204 /**
2205 * Return whether this WebView requests a priority of
2206 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2207 *
2208 * @return whether this WebView requests a priority of
2209 * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
2210 */
2211 public boolean getRendererPriorityWaivedWhenNotVisible() {
2212 return mProvider.getRendererPriorityWaivedWhenNotVisible();
2213 }
Tima Vaisburdcf49a232017-03-28 11:35:58 -07002214
2215 /**
2216 * Sets the {@link TextClassifier} for this WebView.
2217 */
2218 public void setTextClassifier(@Nullable TextClassifier textClassifier) {
2219 mProvider.setTextClassifier(textClassifier);
2220 }
2221
2222 /**
2223 * Returns the {@link TextClassifier} used by this WebView.
2224 * If no TextClassifier has been set, this WebView uses the default set by the system.
2225 */
2226 @NonNull
2227 public TextClassifier getTextClassifier() {
2228 return mProvider.getTextClassifier();
2229 }
2230
Gustav Sennton265afdb2018-01-19 11:56:55 +00002231 /**
2232 * Returns the {@link ClassLoader} used to load internal WebView classes.
2233 * This method is meant for use by the WebView Support Library, there is no reason to use this
2234 * method otherwise.
2235 */
2236 @NonNull
2237 public static ClassLoader getWebViewClassLoader() {
2238 return getFactory().getWebViewClassLoader();
2239 }
2240
Gustav Sennton01673692018-01-19 12:11:25 +00002241 /**
2242 * Returns the {@link Looper} corresponding to the thread on which WebView calls must be made.
2243 */
2244 @NonNull
Gustav Sennton6abde8b2018-03-15 13:56:03 +00002245 public Looper getWebViewLooper() {
2246 return mWebViewThread;
2247 }
2248
Jonathan Dixon3c909522012-02-28 18:45:06 +00002249 //-------------------------------------------------------------------------
2250 // Interface for WebView providers
2251 //-------------------------------------------------------------------------
2252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 /**
Steve Block4e584df2012-04-24 23:12:47 +01002254 * Gets the WebViewProvider. Used by providers to obtain the underlying
Nate Fischerffb81c42016-09-26 12:35:47 -07002255 * implementation, e.g. when the application responds to
Steve Block4e584df2012-04-24 23:12:47 +01002256 * WebViewClient.onCreateWindow() request.
Mike Reedefe2c722009-10-14 09:42:02 -04002257 *
Jonathan Dixon3c909522012-02-28 18:45:06 +00002258 * @hide WebViewProvider is not public API.
Mike Reedefe2c722009-10-14 09:42:02 -04002259 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002260 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002261 public WebViewProvider getWebViewProvider() {
2262 return mProvider;
Mike Reedefe2c722009-10-14 09:42:02 -04002263 }
2264
2265 /**
Jonathan Dixon3c909522012-02-28 18:45:06 +00002266 * Callback interface, allows the provider implementation to access non-public methods
2267 * and fields, and make super-class calls in this WebView instance.
2268 * @hide Only for use by WebViewProvider implementations
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002269 */
Ignacio Solla451e3382014-11-10 10:35:54 +00002270 @SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +00002271 public class PrivateAccess {
2272 // ---- Access to super-class methods ----
2273 public int super_getScrollBarStyle() {
2274 return WebView.super.getScrollBarStyle();
2275 }
2276
2277 public void super_scrollTo(int scrollX, int scrollY) {
2278 WebView.super.scrollTo(scrollX, scrollY);
2279 }
2280
2281 public void super_computeScroll() {
2282 WebView.super.computeScroll();
2283 }
2284
alanveebebc92012-06-15 18:59:11 -07002285 public boolean super_onHoverEvent(MotionEvent event) {
2286 return WebView.super.onHoverEvent(event);
2287 }
2288
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002289 public boolean super_performAccessibilityAction(int action, Bundle arguments) {
Alan Viverettea54956a2015-01-07 16:05:02 -08002290 return WebView.super.performAccessibilityActionInternal(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002291 }
2292
Jonathan Dixon3c909522012-02-28 18:45:06 +00002293 public boolean super_performLongClick() {
2294 return WebView.super.performLongClick();
2295 }
2296
2297 public boolean super_setFrame(int left, int top, int right, int bottom) {
2298 return WebView.super.setFrame(left, top, right, bottom);
2299 }
2300
2301 public boolean super_dispatchKeyEvent(KeyEvent event) {
2302 return WebView.super.dispatchKeyEvent(event);
2303 }
2304
2305 public boolean super_onGenericMotionEvent(MotionEvent event) {
2306 return WebView.super.onGenericMotionEvent(event);
2307 }
2308
2309 public boolean super_requestFocus(int direction, Rect previouslyFocusedRect) {
2310 return WebView.super.requestFocus(direction, previouslyFocusedRect);
2311 }
2312
2313 public void super_setLayoutParams(ViewGroup.LayoutParams params) {
2314 WebView.super.setLayoutParams(params);
2315 }
2316
Hui Shuf119c522015-10-08 10:07:13 -07002317 public void super_startActivityForResult(Intent intent, int requestCode) {
2318 WebView.super.startActivityForResult(intent, requestCode);
2319 }
2320
Jonathan Dixon3c909522012-02-28 18:45:06 +00002321 // ---- Access to non-public methods ----
2322 public void overScrollBy(int deltaX, int deltaY,
2323 int scrollX, int scrollY,
2324 int scrollRangeX, int scrollRangeY,
2325 int maxOverScrollX, int maxOverScrollY,
2326 boolean isTouchEvent) {
2327 WebView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY,
2328 maxOverScrollX, maxOverScrollY, isTouchEvent);
2329 }
2330
2331 public void awakenScrollBars(int duration) {
2332 WebView.this.awakenScrollBars(duration);
2333 }
2334
2335 public void awakenScrollBars(int duration, boolean invalidate) {
2336 WebView.this.awakenScrollBars(duration, invalidate);
2337 }
2338
2339 public float getVerticalScrollFactor() {
2340 return WebView.this.getVerticalScrollFactor();
2341 }
2342
2343 public float getHorizontalScrollFactor() {
2344 return WebView.this.getHorizontalScrollFactor();
2345 }
2346
2347 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
2348 WebView.this.setMeasuredDimension(measuredWidth, measuredHeight);
2349 }
2350
2351 public void onScrollChanged(int l, int t, int oldl, int oldt) {
2352 WebView.this.onScrollChanged(l, t, oldl, oldt);
2353 }
2354
2355 public int getHorizontalScrollbarHeight() {
2356 return WebView.this.getHorizontalScrollbarHeight();
2357 }
2358
Martin Kosiba9a68f822013-08-08 14:02:41 +01002359 public void super_onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2360 int l, int t, int r, int b) {
2361 WebView.super.onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2362 }
2363
Jonathan Dixon3c909522012-02-28 18:45:06 +00002364 // ---- Access to (non-public) fields ----
2365 /** Raw setter for the scroll X value, without invoking onScrollChanged handlers etc. */
2366 public void setScrollXRaw(int scrollX) {
2367 WebView.this.mScrollX = scrollX;
2368 }
2369
2370 /** Raw setter for the scroll Y value, without invoking onScrollChanged handlers etc. */
2371 public void setScrollYRaw(int scrollY) {
2372 WebView.this.mScrollY = scrollY;
2373 }
2374
Teng-Hui Zhu661e8b12011-03-02 15:09:34 -08002375 }
2376
Jonathan Dixon3c909522012-02-28 18:45:06 +00002377 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002378 // Package-private internal stuff
2379 //-------------------------------------------------------------------------
2380
2381 // Only used by android.webkit.FindActionModeCallback.
2382 void setFindDialogFindListener(FindListener listener) {
2383 checkThread();
2384 setupFindListenerIfNeeded();
2385 mFindListener.mFindDialogFindListener = listener;
2386 }
2387
2388 // Only used by android.webkit.FindActionModeCallback.
Mathew Inwood42afea22018-08-16 19:18:28 +01002389 @UnsupportedAppUsage
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002390 void notifyFindDialogDismissed() {
2391 checkThread();
2392 mProvider.notifyFindDialogDismissed();
2393 }
2394
2395 //-------------------------------------------------------------------------
Jonathan Dixon3c909522012-02-28 18:45:06 +00002396 // Private internal stuff
2397 //-------------------------------------------------------------------------
2398
Mathew Inwood42afea22018-08-16 19:18:28 +01002399 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002400 private WebViewProvider mProvider;
2401
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002402 /**
2403 * In addition to the FindListener that the user may set via the WebView.setFindListener
2404 * API, FindActionModeCallback will register it's own FindListener. We keep them separate
Mark Dolinerd0646dc2014-08-27 16:04:02 -07002405 * via this class so that the two FindListeners can potentially exist at once.
Ben Murdoch52c9f7f2013-01-18 00:50:37 +00002406 */
2407 private class FindListenerDistributor implements FindListener {
2408 private FindListener mFindDialogFindListener;
2409 private FindListener mUserFindListener;
2410
2411 @Override
2412 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
2413 boolean isDoneCounting) {
2414 if (mFindDialogFindListener != null) {
2415 mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2416 isDoneCounting);
2417 }
2418
2419 if (mUserFindListener != null) {
2420 mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
2421 isDoneCounting);
2422 }
2423 }
2424 }
2425 private FindListenerDistributor mFindListener;
2426
2427 private void setupFindListenerIfNeeded() {
2428 if (mFindListener == null) {
2429 mFindListener = new FindListenerDistributor();
2430 mProvider.setFindListener(mFindListener);
2431 }
2432 }
2433
Jonathan Dixon3c909522012-02-28 18:45:06 +00002434 private void ensureProviderCreated() {
2435 checkThread();
2436 if (mProvider == null) {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002437 // As this can get called during the base class constructor chain, pass the minimum
2438 // number of dependencies here; the rest are deferred to init().
2439 mProvider = getFactory().createWebView(this, new PrivateAccess());
2440 }
Ben Murdochecbc65c2010-01-13 10:54:56 +00002441 }
2442
Mathew Inwood42afea22018-08-16 19:18:28 +01002443 @UnsupportedAppUsage
Torne (Richard Coles)59375a02016-07-18 18:34:02 +01002444 private static WebViewFactoryProvider getFactory() {
Jonathan Dixond3101b12012-04-12 20:51:51 +01002445 return WebViewFactory.getProvider();
Ben Murdoch1708ad52010-11-11 15:56:16 +00002446 }
2447
Mathew Inwood42afea22018-08-16 19:18:28 +01002448 @UnsupportedAppUsage
Jonathan Dixon517771b2013-10-08 13:32:11 -07002449 private final Looper mWebViewThread = Looper.myLooper();
2450
Mathew Inwood42afea22018-08-16 19:18:28 +01002451 @UnsupportedAppUsage
Jonathan Dixon517771b2013-10-08 13:32:11 -07002452 private void checkThread() {
2453 // Ignore mWebViewThread == null because this can be called during in the super class
2454 // constructor, before this class's own constructor has even started.
2455 if (mWebViewThread != null && Looper.myLooper() != mWebViewThread) {
Steve Block7a01d942011-09-26 12:30:31 +01002456 Throwable throwable = new Throwable(
Jonathan Dixon517771b2013-10-08 13:32:11 -07002457 "A WebView method was called on thread '" +
Steve Block08d584c2011-05-17 19:05:03 +01002458 Thread.currentThread().getName() + "'. " +
Jonathan Dixon517771b2013-10-08 13:32:11 -07002459 "All WebView methods must be called on the same thread. " +
2460 "(Expected Looper " + mWebViewThread + " called on " + Looper.myLooper() +
2461 ", FYI main Looper is " + Looper.getMainLooper() + ")");
Steve Block7a01d942011-09-26 12:30:31 +01002462 Log.w(LOGTAG, Log.getStackTraceString(throwable));
2463 StrictMode.onWebViewMethodCalledOnWrongThread(throwable);
Kristian Monsenb5cd8c02013-04-09 17:57:37 -07002464
2465 if (sEnforceThreadChecking) {
2466 throw new RuntimeException(throwable);
2467 }
Steve Block51b08912011-04-27 15:04:48 +01002468 }
2469 }
2470
Jonathan Dixon3c909522012-02-28 18:45:06 +00002471 //-------------------------------------------------------------------------
2472 // Override View methods
2473 //-------------------------------------------------------------------------
2474
2475 // TODO: Add a test that enumerates all methods in ViewDelegte & ScrollDelegate, and ensures
2476 // there's a corresponding override (or better, caller) for each of them in here.
2477
2478 @Override
2479 protected void onAttachedToWindow() {
2480 super.onAttachedToWindow();
2481 mProvider.getViewDelegate().onAttachedToWindow();
Chris Craik555c55e2011-07-28 15:39:43 -07002482 }
2483
John Reck34dbce12014-03-06 12:52:24 -08002484 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002485 @Override
John Reck34dbce12014-03-06 12:52:24 -08002486 protected void onDetachedFromWindowInternal() {
Jonathan Dixon3c909522012-02-28 18:45:06 +00002487 mProvider.getViewDelegate().onDetachedFromWindow();
John Reck34dbce12014-03-06 12:52:24 -08002488 super.onDetachedFromWindowInternal();
Chris Craik555c55e2011-07-28 15:39:43 -07002489 }
2490
Tima Vaisburd5544f6c2017-04-27 10:53:27 -07002491 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002492 @Override
Tima Vaisburd134752b2017-04-06 15:50:05 -07002493 public void onMovedToDisplay(int displayId, Configuration config) {
2494 mProvider.getViewDelegate().onMovedToDisplay(displayId, config);
2495 }
2496
2497 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002498 public void setLayoutParams(ViewGroup.LayoutParams params) {
2499 mProvider.getViewDelegate().setLayoutParams(params);
Chris Craik445ab742011-07-13 13:19:37 -07002500 }
2501
Jonathan Dixon3c909522012-02-28 18:45:06 +00002502 @Override
2503 public void setOverScrollMode(int mode) {
2504 super.setOverScrollMode(mode);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002505 // This method may be called in the constructor chain, before the WebView provider is
2506 // created.
Jonathan Dixon3c909522012-02-28 18:45:06 +00002507 ensureProviderCreated();
2508 mProvider.getViewDelegate().setOverScrollMode(mode);
Chris Craik445ab742011-07-13 13:19:37 -07002509 }
2510
Jonathan Dixon3c909522012-02-28 18:45:06 +00002511 @Override
2512 public void setScrollBarStyle(int style) {
2513 mProvider.getViewDelegate().setScrollBarStyle(style);
2514 super.setScrollBarStyle(style);
George Mount3d095312012-01-10 11:24:02 -08002515 }
2516
Jonathan Dixon3c909522012-02-28 18:45:06 +00002517 @Override
2518 protected int computeHorizontalScrollRange() {
2519 return mProvider.getScrollDelegate().computeHorizontalScrollRange();
John Reck5528d7c2012-02-28 11:29:29 -08002520 }
2521
Jonathan Dixon3c909522012-02-28 18:45:06 +00002522 @Override
2523 protected int computeHorizontalScrollOffset() {
2524 return mProvider.getScrollDelegate().computeHorizontalScrollOffset();
2525 }
Grace Kloba8abd50b2010-07-08 15:02:14 -07002526
Jonathan Dixon3c909522012-02-28 18:45:06 +00002527 @Override
2528 protected int computeVerticalScrollRange() {
2529 return mProvider.getScrollDelegate().computeVerticalScrollRange();
2530 }
Patrick Scotta3ebcc92010-07-16 11:52:22 -04002531
Jonathan Dixon3c909522012-02-28 18:45:06 +00002532 @Override
2533 protected int computeVerticalScrollOffset() {
2534 return mProvider.getScrollDelegate().computeVerticalScrollOffset();
2535 }
Ben Murdochfa148f62011-02-01 20:51:27 +00002536
Jonathan Dixon3c909522012-02-28 18:45:06 +00002537 @Override
2538 protected int computeVerticalScrollExtent() {
2539 return mProvider.getScrollDelegate().computeVerticalScrollExtent();
2540 }
2541
2542 @Override
2543 public void computeScroll() {
2544 mProvider.getScrollDelegate().computeScroll();
2545 }
2546
2547 @Override
2548 public boolean onHoverEvent(MotionEvent event) {
2549 return mProvider.getViewDelegate().onHoverEvent(event);
2550 }
2551
2552 @Override
2553 public boolean onTouchEvent(MotionEvent event) {
2554 return mProvider.getViewDelegate().onTouchEvent(event);
2555 }
2556
2557 @Override
2558 public boolean onGenericMotionEvent(MotionEvent event) {
2559 return mProvider.getViewDelegate().onGenericMotionEvent(event);
2560 }
2561
2562 @Override
2563 public boolean onTrackballEvent(MotionEvent event) {
2564 return mProvider.getViewDelegate().onTrackballEvent(event);
2565 }
2566
2567 @Override
2568 public boolean onKeyDown(int keyCode, KeyEvent event) {
2569 return mProvider.getViewDelegate().onKeyDown(keyCode, event);
2570 }
2571
2572 @Override
2573 public boolean onKeyUp(int keyCode, KeyEvent event) {
2574 return mProvider.getViewDelegate().onKeyUp(keyCode, event);
2575 }
2576
2577 @Override
2578 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
2579 return mProvider.getViewDelegate().onKeyMultiple(keyCode, repeatCount, event);
2580 }
2581
2582 /*
2583 TODO: These are not currently implemented in WebViewClassic, but it seems inconsistent not
2584 to be delegating them too.
2585
2586 @Override
2587 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
2588 return mProvider.getViewDelegate().onKeyPreIme(keyCode, event);
2589 }
2590 @Override
2591 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
2592 return mProvider.getViewDelegate().onKeyLongPress(keyCode, event);
2593 }
2594 @Override
2595 public boolean onKeyShortcut(int keyCode, KeyEvent event) {
2596 return mProvider.getViewDelegate().onKeyShortcut(keyCode, event);
2597 }
2598 */
2599
Ben Murdoche3f90712013-06-05 14:19:48 +01002600 @Override
2601 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
2602 AccessibilityNodeProvider provider =
2603 mProvider.getViewDelegate().getAccessibilityNodeProvider();
2604 return provider == null ? super.getAccessibilityNodeProvider() : provider;
2605 }
2606
Jonathan Dixon3c909522012-02-28 18:45:06 +00002607 @Deprecated
2608 @Override
2609 public boolean shouldDelayChildPressedState() {
2610 return mProvider.getViewDelegate().shouldDelayChildPressedState();
2611 }
2612
Felipe Leme1ca634a2016-11-28 17:21:21 -08002613 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -08002614 public CharSequence getAccessibilityClassName() {
2615 return WebView.class.getName();
2616 }
2617
Selim Gurun1b650cb2015-04-06 20:13:37 -07002618 @Override
Dianne Hackborn49b043f2015-05-07 14:21:38 -07002619 public void onProvideVirtualStructure(ViewStructure structure) {
Selim Gurun50b26a52015-06-01 16:26:10 -07002620 mProvider.getViewDelegate().onProvideVirtualStructure(structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -07002621 }
2622
Felipe Leme1a1e4682017-03-13 16:34:03 -07002623 /**
2624 * {@inheritDoc}
2625 *
2626 * <p>The {@link ViewStructure} traditionally represents a {@link View}, while for web pages
2627 * it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is
2628 * understood by the {@link android.service.autofill.AutofillService} implementations:
2629 *
2630 * <ol>
Felipe Leme303b6092017-07-31 18:01:15 -07002631 * <li>Only the HTML nodes inside a {@code FORM} are generated.
2632 * <li>The source of the HTML is set using {@link ViewStructure#setWebDomain(String)} in the
2633 * node representing the WebView.
2634 * <li>If a web page has multiple {@code FORM}s, only the data for the current form is
2635 * represented&mdash;if the user taps a field from another form, then the current autofill
2636 * context is canceled (by calling {@link android.view.autofill.AutofillManager#cancel()} and
2637 * a new context is created for that {@code FORM}.
2638 * <li>Similarly, if the page has {@code IFRAME} nodes, they are not initially represented in
2639 * the view structure until the user taps a field from a {@code FORM} inside the
2640 * {@code IFRAME}, in which case it would be treated the same way as multiple forms described
2641 * above, except that the {@link ViewStructure#setWebDomain(String) web domain} of the
2642 * {@code FORM} contains the {@code src} attribute from the {@code IFRAME} node.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002643 * <li>The W3C autofill field ({@code autocomplete} tag attribute) maps to
Felipe Leme58390fe2017-09-15 15:16:28 -07002644 * {@link ViewStructure#setAutofillHints(String[])}.
2645 * <li>If the view is editable, the {@link ViewStructure#setAutofillType(int)} and
Felipe Leme6dcec872017-05-25 11:24:23 -07002646 * {@link ViewStructure#setAutofillValue(AutofillValue)} must be set.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002647 * <li>The {@code placeholder} attribute maps to {@link ViewStructure#setHint(CharSequence)}.
Felipe Leme25bf7872017-03-28 15:32:29 -07002648 * <li>Other HTML attributes can be represented through
2649 * {@link ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)}.
Felipe Leme1a1e4682017-03-13 16:34:03 -07002650 * </ol>
2651 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002652 * <p>If the WebView implementation can determine that the value of a field was set statically
2653 * (for example, not through Javascript), it should also call
2654 * {@code structure.setDataIsSensitive(false)}.
Felipe Leme6dcec872017-05-25 11:24:23 -07002655 *
Felipe Leme58390fe2017-09-15 15:16:28 -07002656 * <p>For example, an HTML form with 2 fields for username and password:
Felipe Leme1a1e4682017-03-13 16:34:03 -07002657 *
2658 * <pre class="prettyprint">
Felipe Lemef485f892017-11-22 08:15:59 -08002659 * &lt;label&gt;Username:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002660 * &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 -08002661 * &lt;label&gt;Password:&lt;/label&gt;
Felipe Leme6dcec872017-05-25 11:24:23 -07002662 * &lt;input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"&gt;
Felipe Leme1a1e4682017-03-13 16:34:03 -07002663 * </pre>
2664 *
2665 * <p>Would map to:
2666 *
2667 * <pre class="prettyprint">
Felipe Leme25bf7872017-03-28 15:32:29 -07002668 * int index = structure.addChildCount(2);
2669 * ViewStructure username = structure.newChild(index);
Felipe Leme6dcec872017-05-25 11:24:23 -07002670 * username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002671 * username.setAutofillHints("username");
Felipe Leme6dcec872017-05-25 11:24:23 -07002672 * username.setHtmlInfo(username.newHtmlInfoBuilder("input")
2673 * .addAttribute("type", "text")
Felipe Leme25bf7872017-03-28 15:32:29 -07002674 * .addAttribute("name", "username")
Felipe Lemef485f892017-11-22 08:15:59 -08002675 * .addAttribute("label", "Username:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002676 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002677 * username.setHint("Email or username");
2678 * username.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme6dcec872017-05-25 11:24:23 -07002679 * username.setAutofillValue(AutofillValue.forText("Type your username"));
Felipe Leme58390fe2017-09-15 15:16:28 -07002680 * // Value of the field is not sensitive because it was created statically and not changed.
Felipe Leme6dcec872017-05-25 11:24:23 -07002681 * username.setDataIsSensitive(false);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002682 *
Felipe Leme25bf7872017-03-28 15:32:29 -07002683 * ViewStructure password = structure.newChild(index + 1);
2684 * username.setAutofillId(structure, 2); // id 2 - second child
Felipe Leme1a1e4682017-03-13 16:34:03 -07002685 * password.setAutofillHints("current-password");
Felipe Leme6dcec872017-05-25 11:24:23 -07002686 * password.setHtmlInfo(password.newHtmlInfoBuilder("input")
2687 * .addAttribute("type", "password")
Felipe Leme25bf7872017-03-28 15:32:29 -07002688 * .addAttribute("name", "password")
Felipe Lemef485f892017-11-22 08:15:59 -08002689 * .addAttribute("label", "Password:")
Felipe Leme25bf7872017-03-28 15:32:29 -07002690 * .build());
Felipe Leme1a1e4682017-03-13 16:34:03 -07002691 * password.setHint("Password");
2692 * password.setAutofillType(View.AUTOFILL_TYPE_TEXT);
Felipe Leme1a1e4682017-03-13 16:34:03 -07002693 * </pre>
Felipe Leme1a1e4682017-03-13 16:34:03 -07002694 */
Felipe Leme1ca634a2016-11-28 17:21:21 -08002695 @Override
Felipe Leme640f30a2017-03-06 15:44:06 -08002696 public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
2697 mProvider.getViewDelegate().onProvideAutofillVirtualStructure(structure, flags);
Felipe Leme1ca634a2016-11-28 17:21:21 -08002698 }
2699
Tao Baia5717332017-03-30 14:58:53 -07002700 @Override
2701 public void autofill(SparseArray<AutofillValue>values) {
2702 mProvider.getViewDelegate().autofill(values);
2703 }
2704
Felipe Lemeef335262018-03-07 11:49:44 -08002705 @Override
2706 public boolean isVisibleToUserForAutofill(int virtualId) {
2707 return mProvider.getViewDelegate().isVisibleToUserForAutofill(virtualId);
2708 }
2709
Alan Viverettea54956a2015-01-07 16:05:02 -08002710 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002711 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002712 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2713 super.onInitializeAccessibilityNodeInfoInternal(info);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002714 mProvider.getViewDelegate().onInitializeAccessibilityNodeInfo(info);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002715 }
2716
Alan Viverettea54956a2015-01-07 16:05:02 -08002717 /** @hide */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002718 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002719 public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
2720 super.onInitializeAccessibilityEventInternal(event);
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002721 mProvider.getViewDelegate().onInitializeAccessibilityEvent(event);
Jonathan Dixon3c909522012-02-28 18:45:06 +00002722 }
2723
Alan Viverettea54956a2015-01-07 16:05:02 -08002724 /** @hide */
alanv448902d2012-05-16 20:27:47 -07002725 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08002726 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
Marcin Kosiba3e853fb2015-01-08 12:45:40 +00002727 return mProvider.getViewDelegate().performAccessibilityAction(action, arguments);
alanv448902d2012-05-16 20:27:47 -07002728 }
2729
Jonathan Dixon3c909522012-02-28 18:45:06 +00002730 /** @hide */
2731 @Override
Mathew Inwood42afea22018-08-16 19:18:28 +01002732 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002733 protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
2734 int l, int t, int r, int b) {
2735 mProvider.getViewDelegate().onDrawVerticalScrollBar(canvas, scrollBar, l, t, r, b);
2736 }
2737
2738 @Override
2739 protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
2740 mProvider.getViewDelegate().onOverScrolled(scrollX, scrollY, clampedX, clampedY);
2741 }
2742
2743 @Override
2744 protected void onWindowVisibilityChanged(int visibility) {
2745 super.onWindowVisibilityChanged(visibility);
2746 mProvider.getViewDelegate().onWindowVisibilityChanged(visibility);
2747 }
2748
2749 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002750 protected void onDraw(Canvas canvas) {
2751 mProvider.getViewDelegate().onDraw(canvas);
2752 }
2753
2754 @Override
2755 public boolean performLongClick() {
2756 return mProvider.getViewDelegate().performLongClick();
2757 }
2758
2759 @Override
2760 protected void onConfigurationChanged(Configuration newConfig) {
2761 mProvider.getViewDelegate().onConfigurationChanged(newConfig);
2762 }
2763
Selim Gurunc92080b2016-10-20 11:53:14 -07002764 /**
2765 * Creates a new InputConnection for an InputMethod to interact with the WebView.
2766 * This is similar to {@link View#onCreateInputConnection} but note that WebView
2767 * calls InputConnection methods on a thread other than the UI thread.
2768 * If these methods are overridden, then the overriding methods should respect
2769 * thread restrictions when calling View methods or accessing data.
2770 */
Jonathan Dixon3c909522012-02-28 18:45:06 +00002771 @Override
2772 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
2773 return mProvider.getViewDelegate().onCreateInputConnection(outAttrs);
2774 }
2775
2776 @Override
Hui Shuecdce962016-02-04 15:00:19 -08002777 public boolean onDragEvent(DragEvent event) {
2778 return mProvider.getViewDelegate().onDragEvent(event);
2779 }
2780
2781 @Override
Jonathan Dixon3c909522012-02-28 18:45:06 +00002782 protected void onVisibilityChanged(View changedView, int visibility) {
2783 super.onVisibilityChanged(changedView, visibility);
Martin Kosiba5ee743e2012-12-21 12:39:50 +00002784 // This method may be called in the constructor chain, before the WebView provider is
2785 // created.
2786 ensureProviderCreated();
Jonathan Dixon3c909522012-02-28 18:45:06 +00002787 mProvider.getViewDelegate().onVisibilityChanged(changedView, visibility);
2788 }
2789
2790 @Override
2791 public void onWindowFocusChanged(boolean hasWindowFocus) {
2792 mProvider.getViewDelegate().onWindowFocusChanged(hasWindowFocus);
2793 super.onWindowFocusChanged(hasWindowFocus);
2794 }
2795
2796 @Override
2797 protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
2798 mProvider.getViewDelegate().onFocusChanged(focused, direction, previouslyFocusedRect);
2799 super.onFocusChanged(focused, direction, previouslyFocusedRect);
2800 }
2801
2802 /** @hide */
2803 @Override
Mathew Inwood42afea22018-08-16 19:18:28 +01002804 @UnsupportedAppUsage
Jonathan Dixon3c909522012-02-28 18:45:06 +00002805 protected boolean setFrame(int left, int top, int right, int bottom) {
2806 return mProvider.getViewDelegate().setFrame(left, top, right, bottom);
2807 }
2808
2809 @Override
2810 protected void onSizeChanged(int w, int h, int ow, int oh) {
2811 super.onSizeChanged(w, h, ow, oh);
2812 mProvider.getViewDelegate().onSizeChanged(w, h, ow, oh);
2813 }
2814
2815 @Override
2816 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
2817 super.onScrollChanged(l, t, oldl, oldt);
2818 mProvider.getViewDelegate().onScrollChanged(l, t, oldl, oldt);
2819 }
2820
2821 @Override
2822 public boolean dispatchKeyEvent(KeyEvent event) {
2823 return mProvider.getViewDelegate().dispatchKeyEvent(event);
2824 }
2825
2826 @Override
2827 public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
2828 return mProvider.getViewDelegate().requestFocus(direction, previouslyFocusedRect);
2829 }
2830
Jonathan Dixon3c909522012-02-28 18:45:06 +00002831 @Override
2832 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2833 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
2834 mProvider.getViewDelegate().onMeasure(widthMeasureSpec, heightMeasureSpec);
2835 }
2836
2837 @Override
2838 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
2839 return mProvider.getViewDelegate().requestChildRectangleOnScreen(child, rect, immediate);
2840 }
2841
2842 @Override
2843 public void setBackgroundColor(int color) {
2844 mProvider.getViewDelegate().setBackgroundColor(color);
2845 }
John Recka5408e62012-03-16 14:18:44 -07002846
2847 @Override
2848 public void setLayerType(int layerType, Paint paint) {
2849 super.setLayerType(layerType, paint);
2850 mProvider.getViewDelegate().setLayerType(layerType, paint);
2851 }
Ben Murdoche623e242012-09-07 20:47:07 +01002852
2853 @Override
2854 protected void dispatchDraw(Canvas canvas) {
2855 mProvider.getViewDelegate().preDispatchDraw(canvas);
2856 super.dispatchDraw(canvas);
2857 }
Ben Murdoch7302f4f2014-07-03 14:47:44 +01002858
2859 @Override
2860 public void onStartTemporaryDetach() {
2861 super.onStartTemporaryDetach();
2862 mProvider.getViewDelegate().onStartTemporaryDetach();
2863 }
2864
2865 @Override
2866 public void onFinishTemporaryDetach() {
2867 super.onFinishTemporaryDetach();
2868 mProvider.getViewDelegate().onFinishTemporaryDetach();
2869 }
Siva Velusamy94a6d152015-05-05 15:07:00 -07002870
Selim Gurune319dad2016-03-17 01:40:40 +00002871 @Override
2872 public Handler getHandler() {
2873 return mProvider.getViewDelegate().getHandler(super.getHandler());
2874 }
2875
2876 @Override
2877 public View findFocus() {
2878 return mProvider.getViewDelegate().findFocus(super.findFocus());
2879 }
2880
Hui Shuf119c522015-10-08 10:07:13 -07002881 /**
Gustav Senntonbf683e02016-09-15 14:42:50 +01002882 * If WebView has already been loaded into the current process this method will return the
2883 * package that was used to load it. Otherwise, the package that would be used if the WebView
2884 * was loaded right now will be returned; this does not cause WebView to be loaded, so this
2885 * information may become outdated at any time.
Gustav Sennton4cbfe712017-03-07 14:22:01 +00002886 * The WebView package changes either when the current WebView package is updated, disabled, or
2887 * uninstalled. It can also be changed through a Developer Setting.
2888 * If the WebView package changes, any app process that has loaded WebView will be killed. The
2889 * next time the app starts and loads WebView it will use the new WebView package instead.
Nate Fischer0a6140d2017-09-05 12:37:49 -07002890 * @return the current WebView package, or {@code null} if there is none.
Gustav Senntonbf683e02016-09-15 14:42:50 +01002891 */
Nate Fischer3442c742017-09-08 17:02:00 -07002892 @Nullable
Gustav Senntonbf683e02016-09-15 14:42:50 +01002893 public static PackageInfo getCurrentWebViewPackage() {
2894 PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
2895 if (webviewPackage != null) {
2896 return webviewPackage;
2897 }
2898
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04002899 IWebViewUpdateService service = WebViewFactory.getUpdateService();
2900 if (service == null) {
2901 return null;
2902 }
Gustav Senntonbf683e02016-09-15 14:42:50 +01002903 try {
Torne (Richard Coles)ff937ac2017-10-02 17:09:32 -04002904 return service.getCurrentWebViewPackage();
Gustav Senntonbf683e02016-09-15 14:42:50 +01002905 } catch (RemoteException e) {
2906 throw e.rethrowFromSystemServer();
2907 }
2908 }
2909
2910 /**
Hui Shuf119c522015-10-08 10:07:13 -07002911 * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
2912 *
2913 * @param requestCode The integer request code originally supplied to
2914 * startActivityForResult(), allowing you to identify who this
2915 * result came from.
2916 * @param resultCode The integer result code returned by the child activity
2917 * through its setResult().
2918 * @param data An Intent, which can return result data to the caller
2919 * (various data can be attached to Intent "extras").
2920 * @hide
2921 */
2922 @Override
2923 public void onActivityResult(int requestCode, int resultCode, Intent data) {
2924 mProvider.getViewDelegate().onActivityResult(requestCode, resultCode, data);
2925 }
2926
Changwan Ryu15e9afc2018-03-06 15:55:19 -08002927 @Override
2928 public boolean onCheckIsTextEditor() {
2929 return mProvider.getViewDelegate().onCheckIsTextEditor();
2930 }
2931
Siva Velusamy94a6d152015-05-05 15:07:00 -07002932 /** @hide */
2933 @Override
2934 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
2935 super.encodeProperties(encoder);
2936
2937 checkThread();
2938 encoder.addProperty("webview:contentHeight", mProvider.getContentHeight());
2939 encoder.addProperty("webview:contentWidth", mProvider.getContentWidth());
2940 encoder.addProperty("webview:scale", mProvider.getScale());
2941 encoder.addProperty("webview:title", mProvider.getTitle());
2942 encoder.addProperty("webview:url", mProvider.getUrl());
2943 encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl());
2944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945}