blob: baf582693bd8cf3af6bf1a40b169c55a1ed3a1e1 [file] [log] [blame]
Jonathan Dixon3c909522012-02-28 18:45:06 +00001/*
2 * Copyright (C) 2012 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
Tima Vaisburdcf49a232017-03-28 11:35:58 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Ignacio Solla451e3382014-11-10 10:35:54 +000021import android.annotation.SystemApi;
Hui Shuf119c522015-10-08 10:07:13 -070022import android.content.Intent;
Nate Fischer0a6140d2017-09-05 12:37:49 -070023import android.content.res.Configuration;
Jonathan Dixon3c909522012-02-28 18:45:06 +000024import android.graphics.Bitmap;
25import android.graphics.Canvas;
John Recka5408e62012-03-16 14:18:44 -070026import android.graphics.Paint;
Jonathan Dixon3c909522012-02-28 18:45:06 +000027import android.graphics.Picture;
28import android.graphics.Rect;
29import android.graphics.drawable.Drawable;
Selim Gurun4c8093a2015-03-10 17:40:06 -070030import android.net.Uri;
Nate Fischer0a6140d2017-09-05 12:37:49 -070031import android.net.http.SslCertificate;
Jonathan Dixon3c909522012-02-28 18:45:06 +000032import android.os.Bundle;
Selim Gurune319dad2016-03-17 01:40:40 +000033import android.os.Handler;
Jonathan Dixon3c909522012-02-28 18:45:06 +000034import android.os.Message;
Selim Gurunda7d6422013-09-06 14:39:05 -070035import android.print.PrintDocumentAdapter;
Tao Baia5717332017-03-30 14:58:53 -070036import android.util.SparseArray;
Hui Shuecdce962016-02-04 15:00:19 -080037import android.view.DragEvent;
Jonathan Dixon3c909522012-02-28 18:45:06 +000038import android.view.KeyEvent;
39import android.view.MotionEvent;
40import android.view.View;
41import android.view.ViewGroup.LayoutParams;
42import android.view.accessibility.AccessibilityEvent;
43import android.view.accessibility.AccessibilityNodeInfo;
Ben Murdoche3f90712013-06-05 14:19:48 +010044import android.view.accessibility.AccessibilityNodeProvider;
Tao Baia5717332017-03-30 14:58:53 -070045import android.view.autofill.AutofillValue;
Jonathan Dixon3c909522012-02-28 18:45:06 +000046import android.view.inputmethod.EditorInfo;
47import android.view.inputmethod.InputConnection;
Tima Vaisburdcf49a232017-03-28 11:35:58 -070048import android.view.textclassifier.TextClassifier;
Jonathan Dixon3c909522012-02-28 18:45:06 +000049import android.webkit.WebView.HitTestResult;
50import android.webkit.WebView.PictureListener;
Tobias Sargeanta8352f42015-03-03 18:07:40 +000051import android.webkit.WebView.VisualStateCallback;
52
Jonathan Dixon3c909522012-02-28 18:45:06 +000053
John Reck926cf562012-06-14 10:00:31 -070054import java.io.BufferedWriter;
Jonathan Dixon3c909522012-02-28 18:45:06 +000055import java.io.File;
56import java.util.Map;
Tobias Sargeant740b53f2019-01-14 21:49:15 +000057import java.util.concurrent.Executor;
Jonathan Dixon3c909522012-02-28 18:45:06 +000058
59/**
60 * WebView backend provider interface: this interface is the abstract backend to a WebView
61 * instance; each WebView object is bound to exactly one WebViewProvider object which implements
62 * the runtime behavior of that WebView.
63 *
64 * All methods must behave as per their namesake in {@link WebView}, unless otherwise noted.
65 *
66 * @hide Not part of the public API; only required by system implementors.
67 */
Ignacio Solla451e3382014-11-10 10:35:54 +000068@SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +000069public interface WebViewProvider {
70 //-------------------------------------------------------------------------
71 // Main interface for backend provider of the WebView class.
72 //-------------------------------------------------------------------------
73 /**
74 * Initialize this WebViewProvider instance. Called after the WebView has fully constructed.
75 * @param javaScriptInterfaces is a Map of interface names, as keys, and
76 * object implementing those interfaces, as values.
Nate Fischer0a6140d2017-09-05 12:37:49 -070077 * @param privateBrowsing If {@code true} the web view will be initialized in private /
78 * incognito mode.
Jonathan Dixon3c909522012-02-28 18:45:06 +000079 */
80 public void init(Map<String, Object> javaScriptInterfaces,
81 boolean privateBrowsing);
82
Paul Millerc8694a02015-06-05 11:23:03 -070083 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000084 public void setHorizontalScrollbarOverlay(boolean overlay);
85
Paul Millerc8694a02015-06-05 11:23:03 -070086 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000087 public void setVerticalScrollbarOverlay(boolean overlay);
88
Paul Millerc8694a02015-06-05 11:23:03 -070089 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000090 public boolean overlayHorizontalScrollbar();
91
Paul Millerc8694a02015-06-05 11:23:03 -070092 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000093 public boolean overlayVerticalScrollbar();
94
95 public int getVisibleTitleHeight();
96
97 public SslCertificate getCertificate();
98
99 public void setCertificate(SslCertificate certificate);
100
101 public void savePassword(String host, String username, String password);
102
103 public void setHttpAuthUsernamePassword(String host, String realm,
104 String username, String password);
105
106 public String[] getHttpAuthUsernamePassword(String host, String realm);
107
108 /**
109 * See {@link WebView#destroy()}.
110 * As well as releasing the internal state and resources held by the implementation,
111 * the provider should null all references it holds on the WebView proxy class, and ensure
112 * no further method calls are made to it.
113 */
114 public void destroy();
115
116 public void setNetworkAvailable(boolean networkUp);
117
118 public WebBackForwardList saveState(Bundle outState);
119
120 public boolean savePicture(Bundle b, final File dest);
121
122 public boolean restorePicture(Bundle b, File src);
123
124 public WebBackForwardList restoreState(Bundle inState);
125
126 public void loadUrl(String url, Map<String, String> additionalHttpHeaders);
127
128 public void loadUrl(String url);
129
130 public void postUrl(String url, byte[] postData);
131
132 public void loadData(String data, String mimeType, String encoding);
133
134 public void loadDataWithBaseURL(String baseUrl, String data,
135 String mimeType, String encoding, String historyUrl);
136
Ben Murdocha5cdd512013-07-17 16:25:07 +0100137 public void evaluateJavaScript(String script, ValueCallback<String> resultCallback);
138
Jonathan Dixon3c909522012-02-28 18:45:06 +0000139 public void saveWebArchive(String filename);
140
141 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback);
142
143 public void stopLoading();
144
145 public void reload();
146
147 public boolean canGoBack();
148
149 public void goBack();
150
151 public boolean canGoForward();
152
153 public void goForward();
154
155 public boolean canGoBackOrForward(int steps);
156
157 public void goBackOrForward(int steps);
158
159 public boolean isPrivateBrowsingEnabled();
160
161 public boolean pageUp(boolean top);
162
163 public boolean pageDown(boolean bottom);
164
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000165 public void insertVisualStateCallback(long requestId, VisualStateCallback callback);
166
Jonathan Dixon3c909522012-02-28 18:45:06 +0000167 public void clearView();
168
169 public Picture capturePicture();
170
Selim Gurun23a1af62014-03-14 16:52:45 -0700171 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -0700172
Jonathan Dixon3c909522012-02-28 18:45:06 +0000173 public float getScale();
174
175 public void setInitialScale(int scaleInPercent);
176
177 public void invokeZoomPicker();
178
179 public HitTestResult getHitTestResult();
180
181 public void requestFocusNodeHref(Message hrefMsg);
182
183 public void requestImageRef(Message msg);
184
185 public String getUrl();
186
187 public String getOriginalUrl();
188
189 public String getTitle();
190
191 public Bitmap getFavicon();
192
193 public String getTouchIconUrl();
194
195 public int getProgress();
196
197 public int getContentHeight();
198
199 public int getContentWidth();
200
201 public void pauseTimers();
202
203 public void resumeTimers();
204
205 public void onPause();
206
207 public void onResume();
208
209 public boolean isPaused();
210
211 public void freeMemory();
212
213 public void clearCache(boolean includeDiskFiles);
214
215 public void clearFormData();
216
217 public void clearHistory();
218
219 public void clearSslPreferences();
220
221 public WebBackForwardList copyBackForwardList();
222
Victoria Leased405a432012-03-22 15:53:48 -0700223 public void setFindListener(WebView.FindListener listener);
Victoria Leaseabeb6a72012-03-05 16:29:12 -0800224
Jonathan Dixon3c909522012-02-28 18:45:06 +0000225 public void findNext(boolean forward);
226
227 public int findAll(String find);
228
Victoria Leaseabeb6a72012-03-05 16:29:12 -0800229 public void findAllAsync(String find);
230
Jonathan Dixon3c909522012-02-28 18:45:06 +0000231 public boolean showFindDialog(String text, boolean showIme);
232
233 public void clearMatches();
234
235 public void documentHasImages(Message response);
236
237 public void setWebViewClient(WebViewClient client);
238
Nate Fischer6e585842016-09-29 18:30:58 -0700239 public WebViewClient getWebViewClient();
240
Tobias Sargeant740b53f2019-01-14 21:49:15 +0000241 public WebViewRenderer getWebViewRenderer();
242
243 public void setWebViewRendererClient(
244 @Nullable Executor executor,
245 @Nullable WebViewRendererClient client);
246
247 public WebViewRendererClient getWebViewRendererClient();
248
Jonathan Dixon3c909522012-02-28 18:45:06 +0000249 public void setDownloadListener(DownloadListener listener);
250
251 public void setWebChromeClient(WebChromeClient client);
252
Nate Fischer6e585842016-09-29 18:30:58 -0700253 public WebChromeClient getWebChromeClient();
254
Jonathan Dixon3c909522012-02-28 18:45:06 +0000255 public void setPictureListener(PictureListener listener);
256
257 public void addJavascriptInterface(Object obj, String interfaceName);
258
259 public void removeJavascriptInterface(String interfaceName);
260
Selim Gurun4c8093a2015-03-10 17:40:06 -0700261 public WebMessagePort[] createWebMessageChannel();
262
263 public void postMessageToMainFrame(WebMessage message, Uri targetOrigin);
264
Jonathan Dixon3c909522012-02-28 18:45:06 +0000265 public WebSettings getSettings();
266
Jonathan Dixon3c909522012-02-28 18:45:06 +0000267 public void setMapTrackballToArrowKeys(boolean setMap);
268
269 public void flingScroll(int vx, int vy);
270
271 public View getZoomControls();
272
273 public boolean canZoomIn();
274
275 public boolean canZoomOut();
276
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +0100277 public boolean zoomBy(float zoomFactor);
278
Jonathan Dixon3c909522012-02-28 18:45:06 +0000279 public boolean zoomIn();
280
281 public boolean zoomOut();
282
John Reck926cf562012-06-14 10:00:31 -0700283 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level);
284
285 public View findHierarchyView(String className, int hashCode);
286
Tobias Sargeantd10e4af2017-01-19 14:03:09 +0000287 public void setRendererPriorityPolicy(int rendererRequestedPriority, boolean waivedWhenNotVisible);
288
289 public int getRendererRequestedPriority();
290
291 public boolean getRendererPriorityWaivedWhenNotVisible();
292
Tima Vaisburdcf49a232017-03-28 11:35:58 -0700293 @SuppressWarnings("unused")
294 public default void setTextClassifier(@Nullable TextClassifier textClassifier) {}
295
296 @NonNull
297 public default TextClassifier getTextClassifier() { return TextClassifier.NO_OP; }
298
Jonathan Dixon3c909522012-02-28 18:45:06 +0000299 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +0000300 // Provider internal methods
Jonathan Dixon3c909522012-02-28 18:45:06 +0000301 //-------------------------------------------------------------------------
302
303 /**
304 * @return the ViewDelegate implementation. This provides the functionality to back all of
305 * the name-sake functions from the View and ViewGroup base classes of WebView.
306 */
307 /* package */ ViewDelegate getViewDelegate();
308
309 /**
310 * @return a ScrollDelegate implementation. Normally this would be same object as is
311 * returned by getViewDelegate().
312 */
313 /* package */ ScrollDelegate getScrollDelegate();
314
Ben Murdoch52c9f7f2013-01-18 00:50:37 +0000315 /**
316 * Only used by FindActionModeCallback to inform providers that the find dialog has
317 * been dismissed.
318 */
319 public void notifyFindDialogDismissed();
320
Jonathan Dixon3c909522012-02-28 18:45:06 +0000321 //-------------------------------------------------------------------------
322 // View / ViewGroup delegation methods
323 //-------------------------------------------------------------------------
324
325 /**
326 * Provides mechanism for the name-sake methods declared in View and ViewGroup to be delegated
327 * into the WebViewProvider instance.
Nate Fischer7051dd12017-10-26 14:51:25 -0700328 * NOTE: For many of these methods, the WebView will provide a super.Foo() call before or after
Jonathan Dixon3c909522012-02-28 18:45:06 +0000329 * making the call into the provider instance. This is done for convenience in the common case
330 * of maintaining backward compatibility. For remaining super class calls (e.g. where the
331 * provider may need to only conditionally make the call based on some internal state) see the
332 * {@link WebView.PrivateAccess} callback class.
333 */
334 // TODO: See if the pattern of the super-class calls can be rationalized at all, and document
335 // the remainder on the methods below.
336 interface ViewDelegate {
337 public boolean shouldDelayChildPressedState();
338
Selim Gurun50b26a52015-06-01 16:26:10 -0700339 public void onProvideVirtualStructure(android.view.ViewStructure structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -0700340
Felipe Lemeef335262018-03-07 11:49:44 -0800341 default void onProvideAutofillVirtualStructure(
342 @SuppressWarnings("unused") android.view.ViewStructure structure,
343 @SuppressWarnings("unused") int flags) {
Felipe Leme1ca634a2016-11-28 17:21:21 -0800344 }
345
Felipe Lemeef335262018-03-07 11:49:44 -0800346 default void autofill(@SuppressWarnings("unused") SparseArray<AutofillValue> values) {
347 }
348
349 default boolean isVisibleToUserForAutofill(@SuppressWarnings("unused") int virtualId) {
350 return true; // true is the default value returned by View.isVisibleToUserForAutofill()
Tao Baia5717332017-03-30 14:58:53 -0700351 }
352
Felipe Leme92ab3852018-11-15 11:30:40 -0800353 default void onProvideContentCaptureStructure(
Felipe Leme1b0e7e82018-11-13 13:13:32 -0800354 @SuppressWarnings("unused") android.view.ViewStructure structure,
355 @SuppressWarnings("unused") int flags) {
Felipe Leme1b0e7e82018-11-13 13:13:32 -0800356 }
357
Ben Murdoche3f90712013-06-05 14:19:48 +0100358 public AccessibilityNodeProvider getAccessibilityNodeProvider();
359
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000360 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000361
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000362 public void onInitializeAccessibilityEvent(AccessibilityEvent event);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000363
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000364 public boolean performAccessibilityAction(int action, Bundle arguments);
alanv448902d2012-05-16 20:27:47 -0700365
Jonathan Dixon3c909522012-02-28 18:45:06 +0000366 public void setOverScrollMode(int mode);
367
368 public void setScrollBarStyle(int style);
369
370 public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t,
371 int r, int b);
372
373 public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
374
375 public void onWindowVisibilityChanged(int visibility);
376
Jonathan Dixon3c909522012-02-28 18:45:06 +0000377 public void onDraw(Canvas canvas);
378
379 public void setLayoutParams(LayoutParams layoutParams);
380
381 public boolean performLongClick();
382
383 public void onConfigurationChanged(Configuration newConfig);
384
385 public InputConnection onCreateInputConnection(EditorInfo outAttrs);
386
Hui Shuecdce962016-02-04 15:00:19 -0800387 public boolean onDragEvent(DragEvent event);
388
Jonathan Dixon3c909522012-02-28 18:45:06 +0000389 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
390
391 public boolean onKeyDown(int keyCode, KeyEvent event);
392
393 public boolean onKeyUp(int keyCode, KeyEvent event);
394
395 public void onAttachedToWindow();
396
397 public void onDetachedFromWindow();
398
Tima Vaisburd134752b2017-04-06 15:50:05 -0700399 public default void onMovedToDisplay(int displayId, Configuration config) {}
400
Jonathan Dixon3c909522012-02-28 18:45:06 +0000401 public void onVisibilityChanged(View changedView, int visibility);
402
403 public void onWindowFocusChanged(boolean hasWindowFocus);
404
405 public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect);
406
407 public boolean setFrame(int left, int top, int right, int bottom);
408
409 public void onSizeChanged(int w, int h, int ow, int oh);
410
411 public void onScrollChanged(int l, int t, int oldl, int oldt);
412
413 public boolean dispatchKeyEvent(KeyEvent event);
414
415 public boolean onTouchEvent(MotionEvent ev);
416
417 public boolean onHoverEvent(MotionEvent event);
418
419 public boolean onGenericMotionEvent(MotionEvent event);
420
421 public boolean onTrackballEvent(MotionEvent ev);
422
423 public boolean requestFocus(int direction, Rect previouslyFocusedRect);
424
425 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
426
427 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate);
428
429 public void setBackgroundColor(int color);
John Recka5408e62012-03-16 14:18:44 -0700430
431 public void setLayerType(int layerType, Paint paint);
Ben Murdoche623e242012-09-07 20:47:07 +0100432
433 public void preDispatchDraw(Canvas canvas);
Ben Murdoch7302f4f2014-07-03 14:47:44 +0100434
435 public void onStartTemporaryDetach();
436
437 public void onFinishTemporaryDetach();
Hui Shuf119c522015-10-08 10:07:13 -0700438
439 public void onActivityResult(int requestCode, int resultCode, Intent data);
Selim Gurune319dad2016-03-17 01:40:40 +0000440
441 public Handler getHandler(Handler originalHandler);
442
443 public View findFocus(View originalFocusedView);
Changwan Ryu15e9afc2018-03-06 15:55:19 -0800444
445 @SuppressWarnings("unused")
446 default boolean onCheckIsTextEditor() {
447 return false;
448 }
Jonathan Dixon3c909522012-02-28 18:45:06 +0000449 }
450
451 interface ScrollDelegate {
452 // These methods are declared protected in the ViewGroup base class. This interface
453 // exists to promote them to public so they may be called by the WebView proxy class.
454 // TODO: Combine into ViewDelegate?
455 /**
456 * See {@link android.webkit.WebView#computeHorizontalScrollRange}
457 */
458 public int computeHorizontalScrollRange();
459
460 /**
461 * See {@link android.webkit.WebView#computeHorizontalScrollOffset}
462 */
463 public int computeHorizontalScrollOffset();
464
465 /**
466 * See {@link android.webkit.WebView#computeVerticalScrollRange}
467 */
468 public int computeVerticalScrollRange();
469
470 /**
471 * See {@link android.webkit.WebView#computeVerticalScrollOffset}
472 */
473 public int computeVerticalScrollOffset();
474
475 /**
476 * See {@link android.webkit.WebView#computeVerticalScrollExtent}
477 */
478 public int computeVerticalScrollExtent();
479
480 /**
481 * See {@link android.webkit.WebView#computeScroll}
482 */
483 public void computeScroll();
484 }
485}