blob: 00e782bd5046ccc7d062e2f969af2a04e3e9852e [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;
57
58/**
59 * WebView backend provider interface: this interface is the abstract backend to a WebView
60 * instance; each WebView object is bound to exactly one WebViewProvider object which implements
61 * the runtime behavior of that WebView.
62 *
63 * All methods must behave as per their namesake in {@link WebView}, unless otherwise noted.
64 *
65 * @hide Not part of the public API; only required by system implementors.
66 */
Ignacio Solla451e3382014-11-10 10:35:54 +000067@SystemApi
Jonathan Dixon3c909522012-02-28 18:45:06 +000068public interface WebViewProvider {
69 //-------------------------------------------------------------------------
70 // Main interface for backend provider of the WebView class.
71 //-------------------------------------------------------------------------
72 /**
73 * Initialize this WebViewProvider instance. Called after the WebView has fully constructed.
74 * @param javaScriptInterfaces is a Map of interface names, as keys, and
75 * object implementing those interfaces, as values.
Nate Fischer0a6140d2017-09-05 12:37:49 -070076 * @param privateBrowsing If {@code true} the web view will be initialized in private /
77 * incognito mode.
Jonathan Dixon3c909522012-02-28 18:45:06 +000078 */
79 public void init(Map<String, Object> javaScriptInterfaces,
80 boolean privateBrowsing);
81
Paul Millerc8694a02015-06-05 11:23:03 -070082 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000083 public void setHorizontalScrollbarOverlay(boolean overlay);
84
Paul Millerc8694a02015-06-05 11:23:03 -070085 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000086 public void setVerticalScrollbarOverlay(boolean overlay);
87
Paul Millerc8694a02015-06-05 11:23:03 -070088 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000089 public boolean overlayHorizontalScrollbar();
90
Paul Millerc8694a02015-06-05 11:23:03 -070091 // Deprecated - should never be called
Jonathan Dixon3c909522012-02-28 18:45:06 +000092 public boolean overlayVerticalScrollbar();
93
94 public int getVisibleTitleHeight();
95
96 public SslCertificate getCertificate();
97
98 public void setCertificate(SslCertificate certificate);
99
100 public void savePassword(String host, String username, String password);
101
102 public void setHttpAuthUsernamePassword(String host, String realm,
103 String username, String password);
104
105 public String[] getHttpAuthUsernamePassword(String host, String realm);
106
107 /**
108 * See {@link WebView#destroy()}.
109 * As well as releasing the internal state and resources held by the implementation,
110 * the provider should null all references it holds on the WebView proxy class, and ensure
111 * no further method calls are made to it.
112 */
113 public void destroy();
114
115 public void setNetworkAvailable(boolean networkUp);
116
117 public WebBackForwardList saveState(Bundle outState);
118
119 public boolean savePicture(Bundle b, final File dest);
120
121 public boolean restorePicture(Bundle b, File src);
122
123 public WebBackForwardList restoreState(Bundle inState);
124
125 public void loadUrl(String url, Map<String, String> additionalHttpHeaders);
126
127 public void loadUrl(String url);
128
129 public void postUrl(String url, byte[] postData);
130
131 public void loadData(String data, String mimeType, String encoding);
132
133 public void loadDataWithBaseURL(String baseUrl, String data,
134 String mimeType, String encoding, String historyUrl);
135
Ben Murdocha5cdd512013-07-17 16:25:07 +0100136 public void evaluateJavaScript(String script, ValueCallback<String> resultCallback);
137
Jonathan Dixon3c909522012-02-28 18:45:06 +0000138 public void saveWebArchive(String filename);
139
140 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback);
141
142 public void stopLoading();
143
144 public void reload();
145
146 public boolean canGoBack();
147
148 public void goBack();
149
150 public boolean canGoForward();
151
152 public void goForward();
153
154 public boolean canGoBackOrForward(int steps);
155
156 public void goBackOrForward(int steps);
157
158 public boolean isPrivateBrowsingEnabled();
159
160 public boolean pageUp(boolean top);
161
162 public boolean pageDown(boolean bottom);
163
Tobias Sargeanta8352f42015-03-03 18:07:40 +0000164 public void insertVisualStateCallback(long requestId, VisualStateCallback callback);
165
Jonathan Dixon3c909522012-02-28 18:45:06 +0000166 public void clearView();
167
168 public Picture capturePicture();
169
Selim Gurun23a1af62014-03-14 16:52:45 -0700170 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName);
Selim Gurun2167c0b2013-08-05 15:23:09 -0700171
Jonathan Dixon3c909522012-02-28 18:45:06 +0000172 public float getScale();
173
174 public void setInitialScale(int scaleInPercent);
175
176 public void invokeZoomPicker();
177
178 public HitTestResult getHitTestResult();
179
180 public void requestFocusNodeHref(Message hrefMsg);
181
182 public void requestImageRef(Message msg);
183
184 public String getUrl();
185
186 public String getOriginalUrl();
187
188 public String getTitle();
189
190 public Bitmap getFavicon();
191
192 public String getTouchIconUrl();
193
194 public int getProgress();
195
196 public int getContentHeight();
197
198 public int getContentWidth();
199
200 public void pauseTimers();
201
202 public void resumeTimers();
203
204 public void onPause();
205
206 public void onResume();
207
208 public boolean isPaused();
209
210 public void freeMemory();
211
212 public void clearCache(boolean includeDiskFiles);
213
214 public void clearFormData();
215
216 public void clearHistory();
217
218 public void clearSslPreferences();
219
220 public WebBackForwardList copyBackForwardList();
221
Victoria Leased405a432012-03-22 15:53:48 -0700222 public void setFindListener(WebView.FindListener listener);
Victoria Leaseabeb6a72012-03-05 16:29:12 -0800223
Jonathan Dixon3c909522012-02-28 18:45:06 +0000224 public void findNext(boolean forward);
225
226 public int findAll(String find);
227
Victoria Leaseabeb6a72012-03-05 16:29:12 -0800228 public void findAllAsync(String find);
229
Jonathan Dixon3c909522012-02-28 18:45:06 +0000230 public boolean showFindDialog(String text, boolean showIme);
231
232 public void clearMatches();
233
234 public void documentHasImages(Message response);
235
236 public void setWebViewClient(WebViewClient client);
237
Nate Fischer6e585842016-09-29 18:30:58 -0700238 public WebViewClient getWebViewClient();
239
Jonathan Dixon3c909522012-02-28 18:45:06 +0000240 public void setDownloadListener(DownloadListener listener);
241
242 public void setWebChromeClient(WebChromeClient client);
243
Nate Fischer6e585842016-09-29 18:30:58 -0700244 public WebChromeClient getWebChromeClient();
245
Jonathan Dixon3c909522012-02-28 18:45:06 +0000246 public void setPictureListener(PictureListener listener);
247
248 public void addJavascriptInterface(Object obj, String interfaceName);
249
250 public void removeJavascriptInterface(String interfaceName);
251
Selim Gurun4c8093a2015-03-10 17:40:06 -0700252 public WebMessagePort[] createWebMessageChannel();
253
254 public void postMessageToMainFrame(WebMessage message, Uri targetOrigin);
255
Jonathan Dixon3c909522012-02-28 18:45:06 +0000256 public WebSettings getSettings();
257
Jonathan Dixon3c909522012-02-28 18:45:06 +0000258 public void setMapTrackballToArrowKeys(boolean setMap);
259
260 public void flingScroll(int vx, int vy);
261
262 public View getZoomControls();
263
264 public boolean canZoomIn();
265
266 public boolean canZoomOut();
267
Marcin Kosiba3ee06ef2014-07-15 17:59:51 +0100268 public boolean zoomBy(float zoomFactor);
269
Jonathan Dixon3c909522012-02-28 18:45:06 +0000270 public boolean zoomIn();
271
272 public boolean zoomOut();
273
John Reck926cf562012-06-14 10:00:31 -0700274 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level);
275
276 public View findHierarchyView(String className, int hashCode);
277
Tobias Sargeantd10e4af2017-01-19 14:03:09 +0000278 public void setRendererPriorityPolicy(int rendererRequestedPriority, boolean waivedWhenNotVisible);
279
280 public int getRendererRequestedPriority();
281
282 public boolean getRendererPriorityWaivedWhenNotVisible();
283
Tima Vaisburdcf49a232017-03-28 11:35:58 -0700284 @SuppressWarnings("unused")
285 public default void setTextClassifier(@Nullable TextClassifier textClassifier) {}
286
287 @NonNull
288 public default TextClassifier getTextClassifier() { return TextClassifier.NO_OP; }
289
Jonathan Dixon3c909522012-02-28 18:45:06 +0000290 //-------------------------------------------------------------------------
Ben Murdoch52c9f7f2013-01-18 00:50:37 +0000291 // Provider internal methods
Jonathan Dixon3c909522012-02-28 18:45:06 +0000292 //-------------------------------------------------------------------------
293
294 /**
295 * @return the ViewDelegate implementation. This provides the functionality to back all of
296 * the name-sake functions from the View and ViewGroup base classes of WebView.
297 */
298 /* package */ ViewDelegate getViewDelegate();
299
300 /**
301 * @return a ScrollDelegate implementation. Normally this would be same object as is
302 * returned by getViewDelegate().
303 */
304 /* package */ ScrollDelegate getScrollDelegate();
305
Ben Murdoch52c9f7f2013-01-18 00:50:37 +0000306 /**
307 * Only used by FindActionModeCallback to inform providers that the find dialog has
308 * been dismissed.
309 */
310 public void notifyFindDialogDismissed();
311
Jonathan Dixon3c909522012-02-28 18:45:06 +0000312 //-------------------------------------------------------------------------
313 // View / ViewGroup delegation methods
314 //-------------------------------------------------------------------------
315
316 /**
317 * Provides mechanism for the name-sake methods declared in View and ViewGroup to be delegated
318 * into the WebViewProvider instance.
Nate Fischer7051dd12017-10-26 14:51:25 -0700319 * NOTE: For many of these methods, the WebView will provide a super.Foo() call before or after
Jonathan Dixon3c909522012-02-28 18:45:06 +0000320 * making the call into the provider instance. This is done for convenience in the common case
321 * of maintaining backward compatibility. For remaining super class calls (e.g. where the
322 * provider may need to only conditionally make the call based on some internal state) see the
323 * {@link WebView.PrivateAccess} callback class.
324 */
325 // TODO: See if the pattern of the super-class calls can be rationalized at all, and document
326 // the remainder on the methods below.
327 interface ViewDelegate {
328 public boolean shouldDelayChildPressedState();
329
Selim Gurun50b26a52015-06-01 16:26:10 -0700330 public void onProvideVirtualStructure(android.view.ViewStructure structure);
Selim Gurun1b650cb2015-04-06 20:13:37 -0700331
Felipe Lemeef335262018-03-07 11:49:44 -0800332 default void onProvideAutofillVirtualStructure(
333 @SuppressWarnings("unused") android.view.ViewStructure structure,
334 @SuppressWarnings("unused") int flags) {
Felipe Leme1ca634a2016-11-28 17:21:21 -0800335 }
336
Felipe Lemeef335262018-03-07 11:49:44 -0800337 default void autofill(@SuppressWarnings("unused") SparseArray<AutofillValue> values) {
338 }
339
340 default boolean isVisibleToUserForAutofill(@SuppressWarnings("unused") int virtualId) {
341 return true; // true is the default value returned by View.isVisibleToUserForAutofill()
Tao Baia5717332017-03-30 14:58:53 -0700342 }
343
Ben Murdoche3f90712013-06-05 14:19:48 +0100344 public AccessibilityNodeProvider getAccessibilityNodeProvider();
345
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000346 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000347
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000348 public void onInitializeAccessibilityEvent(AccessibilityEvent event);
Jonathan Dixon3c909522012-02-28 18:45:06 +0000349
Marcin Kosiba3e853fb2015-01-08 12:45:40 +0000350 public boolean performAccessibilityAction(int action, Bundle arguments);
alanv448902d2012-05-16 20:27:47 -0700351
Jonathan Dixon3c909522012-02-28 18:45:06 +0000352 public void setOverScrollMode(int mode);
353
354 public void setScrollBarStyle(int style);
355
356 public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t,
357 int r, int b);
358
359 public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
360
361 public void onWindowVisibilityChanged(int visibility);
362
Jonathan Dixon3c909522012-02-28 18:45:06 +0000363 public void onDraw(Canvas canvas);
364
365 public void setLayoutParams(LayoutParams layoutParams);
366
367 public boolean performLongClick();
368
369 public void onConfigurationChanged(Configuration newConfig);
370
371 public InputConnection onCreateInputConnection(EditorInfo outAttrs);
372
Hui Shuecdce962016-02-04 15:00:19 -0800373 public boolean onDragEvent(DragEvent event);
374
Jonathan Dixon3c909522012-02-28 18:45:06 +0000375 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
376
377 public boolean onKeyDown(int keyCode, KeyEvent event);
378
379 public boolean onKeyUp(int keyCode, KeyEvent event);
380
381 public void onAttachedToWindow();
382
383 public void onDetachedFromWindow();
384
Tima Vaisburd134752b2017-04-06 15:50:05 -0700385 public default void onMovedToDisplay(int displayId, Configuration config) {}
386
Jonathan Dixon3c909522012-02-28 18:45:06 +0000387 public void onVisibilityChanged(View changedView, int visibility);
388
389 public void onWindowFocusChanged(boolean hasWindowFocus);
390
391 public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect);
392
393 public boolean setFrame(int left, int top, int right, int bottom);
394
395 public void onSizeChanged(int w, int h, int ow, int oh);
396
397 public void onScrollChanged(int l, int t, int oldl, int oldt);
398
399 public boolean dispatchKeyEvent(KeyEvent event);
400
401 public boolean onTouchEvent(MotionEvent ev);
402
403 public boolean onHoverEvent(MotionEvent event);
404
405 public boolean onGenericMotionEvent(MotionEvent event);
406
407 public boolean onTrackballEvent(MotionEvent ev);
408
409 public boolean requestFocus(int direction, Rect previouslyFocusedRect);
410
411 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
412
413 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate);
414
415 public void setBackgroundColor(int color);
John Recka5408e62012-03-16 14:18:44 -0700416
417 public void setLayerType(int layerType, Paint paint);
Ben Murdoche623e242012-09-07 20:47:07 +0100418
419 public void preDispatchDraw(Canvas canvas);
Ben Murdoch7302f4f2014-07-03 14:47:44 +0100420
421 public void onStartTemporaryDetach();
422
423 public void onFinishTemporaryDetach();
Hui Shuf119c522015-10-08 10:07:13 -0700424
425 public void onActivityResult(int requestCode, int resultCode, Intent data);
Selim Gurune319dad2016-03-17 01:40:40 +0000426
427 public Handler getHandler(Handler originalHandler);
428
429 public View findFocus(View originalFocusedView);
Changwan Ryu15e9afc2018-03-06 15:55:19 -0800430
431 @SuppressWarnings("unused")
432 default boolean onCheckIsTextEditor() {
433 return false;
434 }
Jonathan Dixon3c909522012-02-28 18:45:06 +0000435 }
436
437 interface ScrollDelegate {
438 // These methods are declared protected in the ViewGroup base class. This interface
439 // exists to promote them to public so they may be called by the WebView proxy class.
440 // TODO: Combine into ViewDelegate?
441 /**
442 * See {@link android.webkit.WebView#computeHorizontalScrollRange}
443 */
444 public int computeHorizontalScrollRange();
445
446 /**
447 * See {@link android.webkit.WebView#computeHorizontalScrollOffset}
448 */
449 public int computeHorizontalScrollOffset();
450
451 /**
452 * See {@link android.webkit.WebView#computeVerticalScrollRange}
453 */
454 public int computeVerticalScrollRange();
455
456 /**
457 * See {@link android.webkit.WebView#computeVerticalScrollOffset}
458 */
459 public int computeVerticalScrollOffset();
460
461 /**
462 * See {@link android.webkit.WebView#computeVerticalScrollExtent}
463 */
464 public int computeVerticalScrollExtent();
465
466 /**
467 * See {@link android.webkit.WebView#computeScroll}
468 */
469 public void computeScroll();
470 }
471}