Debian Codegraph @

core/java/android/webkit/WebViewProvider.java

raw symbols SCIP
1 /*
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
17 package android.webkit;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SuppressLint;
22 import android.annotation.SystemApi;
23 import android.content.Intent;
24 import android.content.res.Configuration;
25 import android.graphics.Bitmap;
26 import android.graphics.Canvas;
27 import android.graphics.Paint;
28 import android.graphics.Picture;
29 import android.graphics.Rect;
30 import android.graphics.drawable.Drawable;
31 import android.net.Uri;
32 import android.net.http.SslCertificate;
33 import android.os.Bundle;
34 import android.os.Handler;
35 import android.os.Message;
36 import android.print.PrintDocumentAdapter;
37 import android.util.LongSparseArray;
38 import android.util.SparseArray;
39 import android.view.DragEvent;
40 import android.view.KeyEvent;
41 import android.view.MotionEvent;
42 import android.view.View;
43 import android.view.ViewGroup.LayoutParams;
44 import android.view.WindowInsets;
45 import android.view.accessibility.AccessibilityEvent;
46 import android.view.accessibility.AccessibilityNodeInfo;
47 import android.view.accessibility.AccessibilityNodeProvider;
48 import android.view.autofill.AutofillId;
49 import android.view.autofill.AutofillValue;
50 import android.view.inputmethod.EditorInfo;
51 import android.view.inputmethod.InputConnection;
52 import android.view.textclassifier.TextClassifier;
53 import android.view.translation.TranslationCapability;
54 import android.view.translation.TranslationSpec.DataFormat;
55 import android.view.translation.ViewTranslationRequest;
56 import android.view.translation.ViewTranslationResponse;
57 import android.webkit.WebView.HitTestResult;
58 import android.webkit.WebView.PictureListener;
59 import android.webkit.WebView.VisualStateCallback;
60
61
62 import java.io.BufferedWriter;
63 import java.io.File;
64 import java.util.List;
65 import java.util.Map;
66 import java.util.concurrent.Executor;
67 import java.util.function.Consumer;
68
69 /**
70 * WebView backend provider interface: this interface is the abstract backend to a WebView
71 * instance; each WebView object is bound to exactly one WebViewProvider object which implements
72 * the runtime behavior of that WebView.
73 *
74 * All methods must behave as per their namesake in {@link WebView}, unless otherwise noted.
75 *
76 * @hide Not part of the public API; only required by system implementors.
77 */
78 @SystemApi
79 public interface WebViewProvider {
80 //-------------------------------------------------------------------------
81 // Main interface for backend provider of the WebView class.
82 //-------------------------------------------------------------------------
83 /**
84 * Initialize this WebViewProvider instance. Called after the WebView has fully constructed.
85 * @param javaScriptInterfaces is a Map of interface names, as keys, and
86 * object implementing those interfaces, as values.
87 * @param privateBrowsing If {@code true} the web view will be initialized in private /
88 * incognito mode.
89 */
90 public void init(Map<String, Object> javaScriptInterfaces,
91 boolean privateBrowsing);
92
93 // Deprecated - should never be called
94 public void setHorizontalScrollbarOverlay(boolean overlay);
95
96 // Deprecated - should never be called
97 public void setVerticalScrollbarOverlay(boolean overlay);
98
99 // Deprecated - should never be called
100 public boolean overlayHorizontalScrollbar();
101
102 // Deprecated - should never be called
103 public boolean overlayVerticalScrollbar();
104
105 public int getVisibleTitleHeight();
106
107 public SslCertificate getCertificate();
108
109 public void setCertificate(SslCertificate certificate);
110
111 public void savePassword(String host, String username, String password);
112
113 public void setHttpAuthUsernamePassword(String host, String realm,
114 String username, String password);
115
116 public String[] getHttpAuthUsernamePassword(String host, String realm);
117
118 /**
119 * See {@link WebView#destroy()}.
120 * As well as releasing the internal state and resources held by the implementation,
121 * the provider should null all references it holds on the WebView proxy class, and ensure
122 * no further method calls are made to it.
123 */
124 public void destroy();
125
126 public void setNetworkAvailable(boolean networkUp);
127
128 public WebBackForwardList saveState(Bundle outState);
129
130 public boolean savePicture(Bundle b, final File dest);
131
132 public boolean restorePicture(Bundle b, File src);
133
134 public WebBackForwardList restoreState(Bundle inState);
135
136 public void loadUrl(String url, Map<String, String> additionalHttpHeaders);
137
138 public void loadUrl(String url);
139
140 public void postUrl(String url, byte[] postData);
141
142 public void loadData(String data, String mimeType, String encoding);
143
144 public void loadDataWithBaseURL(String baseUrl, String data,
145 String mimeType, String encoding, String historyUrl);
146
147 public void evaluateJavaScript(String script, ValueCallback<String> resultCallback);
148
149 public void saveWebArchive(String filename);
150
151 public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback);
152
153 public void stopLoading();
154
155 public void reload();
156
157 public boolean canGoBack();
158
159 public void goBack();
160
161 public boolean canGoForward();
162
163 public void goForward();
164
165 public boolean canGoBackOrForward(int steps);
166
167 public void goBackOrForward(int steps);
168
169 public boolean isPrivateBrowsingEnabled();
170
171 public boolean pageUp(boolean top);
172
173 public boolean pageDown(boolean bottom);
174
175 public void insertVisualStateCallback(long requestId, VisualStateCallback callback);
176
177 public void clearView();
178
179 public Picture capturePicture();
180
181 public PrintDocumentAdapter createPrintDocumentAdapter(String documentName);
182
183 public float getScale();
184
185 public void setInitialScale(int scaleInPercent);
186
187 public void invokeZoomPicker();
188
189 public HitTestResult getHitTestResult();
190
191 public void requestFocusNodeHref(Message hrefMsg);
192
193 public void requestImageRef(Message msg);
194
195 public String getUrl();
196
197 public String getOriginalUrl();
198
199 public String getTitle();
200
201 public Bitmap getFavicon();
202
203 public String getTouchIconUrl();
204
205 public int getProgress();
206
207 public int getContentHeight();
208
209 public int getContentWidth();
210
211 public void pauseTimers();
212
213 public void resumeTimers();
214
215 public void onPause();
216
217 public void onResume();
218
219 public boolean isPaused();
220
221 public void freeMemory();
222
223 public void clearCache(boolean includeDiskFiles);
224
225 public void clearFormData();
226
227 public void clearHistory();
228
229 public void clearSslPreferences();
230
231 public WebBackForwardList copyBackForwardList();
232
233 public void setFindListener(WebView.FindListener listener);
234
235 public void findNext(boolean forward);
236
237 public int findAll(String find);
238
239 public void findAllAsync(String find);
240
241 public boolean showFindDialog(String text, boolean showIme);
242
243 public void clearMatches();
244
245 public void documentHasImages(Message response);
246
247 public void setWebViewClient(WebViewClient client);
248
249 public WebViewClient getWebViewClient();
250
251 @Nullable
252 public WebViewRenderProcess getWebViewRenderProcess();
253
254 public void setWebViewRenderProcessClient(
255 @Nullable Executor executor,
256 @Nullable WebViewRenderProcessClient client);
257
258 @Nullable
259 public WebViewRenderProcessClient getWebViewRenderProcessClient();
260
261 public void setDownloadListener(DownloadListener listener);
262
263 public void setWebChromeClient(WebChromeClient client);
264
265 public WebChromeClient getWebChromeClient();
266
267 public void setPictureListener(PictureListener listener);
268
269 public void addJavascriptInterface(Object obj, String interfaceName);
270
271 public void removeJavascriptInterface(String interfaceName);
272
273 public WebMessagePort[] createWebMessageChannel();
274
275 public void postMessageToMainFrame(WebMessage message, Uri targetOrigin);
276
277 public WebSettings getSettings();
278
279 public void setMapTrackballToArrowKeys(boolean setMap);
280
281 public void flingScroll(int vx, int vy);
282
283 public View getZoomControls();
284
285 public boolean canZoomIn();
286
287 public boolean canZoomOut();
288
289 public boolean zoomBy(float zoomFactor);
290
291 public boolean zoomIn();
292
293 public boolean zoomOut();
294
295 public void dumpViewHierarchyWithProperties(BufferedWriter out, int level);
296
297 public View findHierarchyView(String className, int hashCode);
298
299 public void setRendererPriorityPolicy(int rendererRequestedPriority, boolean waivedWhenNotVisible);
300
301 public int getRendererRequestedPriority();
302
303 public boolean getRendererPriorityWaivedWhenNotVisible();
304
305 @SuppressWarnings("unused")
306 public default void setTextClassifier(@Nullable TextClassifier textClassifier) {}
307
308 @NonNull
309 public default TextClassifier getTextClassifier() { return TextClassifier.NO_OP; }
310
311 //-------------------------------------------------------------------------
312 // Provider internal methods
313 //-------------------------------------------------------------------------
314
315 /**
316 * @return the ViewDelegate implementation. This provides the functionality to back all of
317 * the name-sake functions from the View and ViewGroup base classes of WebView.
318 */
319 /* package */ ViewDelegate getViewDelegate();
320
321 /**
322 * @return a ScrollDelegate implementation. Normally this would be same object as is
323 * returned by getViewDelegate().
324 */
325 /* package */ ScrollDelegate getScrollDelegate();
326
327 /**
328 * Only used by FindActionModeCallback to inform providers that the find dialog has
329 * been dismissed.
330 */
331 public void notifyFindDialogDismissed();
332
333 //-------------------------------------------------------------------------
334 // View / ViewGroup delegation methods
335 //-------------------------------------------------------------------------
336
337 /**
338 * Provides mechanism for the name-sake methods declared in View and ViewGroup to be delegated
339 * into the WebViewProvider instance.
340 * NOTE: For many of these methods, the WebView will provide a super.Foo() call before or after
341 * making the call into the provider instance. This is done for convenience in the common case
342 * of maintaining backward compatibility. For remaining super class calls (e.g. where the
343 * provider may need to only conditionally make the call based on some internal state) see the
344 * {@link WebView.PrivateAccess} callback class.
345 */
346 // TODO: See if the pattern of the super-class calls can be rationalized at all, and document
347 // the remainder on the methods below.
348 interface ViewDelegate {
349 public boolean shouldDelayChildPressedState();
350
351 public void onProvideVirtualStructure(android.view.ViewStructure structure);
352
353 default void onProvideAutofillVirtualStructure(
354 @SuppressWarnings("unused") android.view.ViewStructure structure,
355 @SuppressWarnings("unused") int flags) {
356 }
357
358 default void autofill(@SuppressWarnings("unused") SparseArray<AutofillValue> values) {
359 }
360
361 default boolean isVisibleToUserForAutofill(@SuppressWarnings("unused") int virtualId) {
362 return true; // true is the default value returned by View.isVisibleToUserForAutofill()
363 }
364
365 default void onProvideContentCaptureStructure(
366 @NonNull @SuppressWarnings("unused") android.view.ViewStructure structure,
367 @SuppressWarnings("unused") int flags) {
368 }
369
370 @SuppressLint("NullableCollection")
371 default void onCreateVirtualViewTranslationRequests(
372 @NonNull @SuppressWarnings("unused") long[] virtualIds,
373 @NonNull @SuppressWarnings("unused") @DataFormat int[] supportedFormats,
374 @NonNull @SuppressWarnings("unused")
375 Consumer<ViewTranslationRequest> requestsCollector) {
376 }
377
378 default void onVirtualViewTranslationResponses(
379 @NonNull @SuppressWarnings("unused")
380 LongSparseArray<ViewTranslationResponse> response) {
381 }
382
383 default void dispatchCreateViewTranslationRequest(
384 @NonNull @SuppressWarnings("unused") Map<AutofillId, long[]> viewIds,
385 @NonNull @SuppressWarnings("unused") @DataFormat int[] supportedFormats,
386 @Nullable @SuppressWarnings("unused") TranslationCapability capability,
387 @NonNull @SuppressWarnings("unused") List<ViewTranslationRequest> requests) {
388
389 }
390
391 public AccessibilityNodeProvider getAccessibilityNodeProvider();
392
393 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info);
394
395 public void onInitializeAccessibilityEvent(AccessibilityEvent event);
396
397 public boolean performAccessibilityAction(int action, Bundle arguments);
398
399 public void setOverScrollMode(int mode);
400
401 public void setScrollBarStyle(int style);
402
403 public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t,
404 int r, int b);
405
406 public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
407
408 public void onWindowVisibilityChanged(int visibility);
409
410 public void onDraw(Canvas canvas);
411
412 public void setLayoutParams(LayoutParams layoutParams);
413
414 public boolean performLongClick();
415
416 public void onConfigurationChanged(Configuration newConfig);
417
418 public InputConnection onCreateInputConnection(EditorInfo outAttrs);
419
420 public boolean onDragEvent(DragEvent event);
421
422 public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
423
424 public boolean onKeyDown(int keyCode, KeyEvent event);
425
426 public boolean onKeyUp(int keyCode, KeyEvent event);
427
428 public void onAttachedToWindow();
429
430 public void onDetachedFromWindow();
431
432 public default void onMovedToDisplay(int displayId, Configuration config) {}
433
434 public void onVisibilityChanged(View changedView, int visibility);
435
436 public void onWindowFocusChanged(boolean hasWindowFocus);
437
438 public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect);
439
440 public boolean setFrame(int left, int top, int right, int bottom);
441
442 public void onSizeChanged(int w, int h, int ow, int oh);
443
444 public void onScrollChanged(int l, int t, int oldl, int oldt);
445
446 public boolean dispatchKeyEvent(KeyEvent event);
447
448 public boolean onTouchEvent(MotionEvent ev);
449
450 public boolean onHoverEvent(MotionEvent event);
451
452 public boolean onGenericMotionEvent(MotionEvent event);
453
454 public boolean onTrackballEvent(MotionEvent ev);
455
456 public boolean requestFocus(int direction, Rect previouslyFocusedRect);
457
458 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
459
460 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate);
461
462 public void setBackgroundColor(int color);
463
464 public void setLayerType(int layerType, Paint paint);
465
466 public void preDispatchDraw(Canvas canvas);
467
468 public void onStartTemporaryDetach();
469
470 public void onFinishTemporaryDetach();
471
472 public void onActivityResult(int requestCode, int resultCode, Intent data);
473
474 public Handler getHandler(Handler originalHandler);
475
476 public View findFocus(View originalFocusedView);
477
478 @SuppressWarnings("unused")
479 default boolean onCheckIsTextEditor() {
480 return false;
481 }
482
483 /**
484 * @see View#onApplyWindowInsets(WindowInsets).
485 *
486 * <p>This is the entry point for the WebView implementation to override. It returns
487 * {@code null} when the WebView implementation hasn't implemented the WindowInsets support
488 * on S yet. In this case, the {@link View#onApplyWindowInsets()} super method will be
489 * called instead.
490 *
491 * @param insets Insets to apply
492 * @return The supplied insets with any applied insets consumed.
493 */
494 @SuppressWarnings("unused")
495 @Nullable
496 default WindowInsets onApplyWindowInsets(@Nullable WindowInsets insets) {
497 return null;
498 }
499 }
500
501 interface ScrollDelegate {
502 // These methods are declared protected in the ViewGroup base class. This interface
503 // exists to promote them to public so they may be called by the WebView proxy class.
504 // TODO: Combine into ViewDelegate?
505 /**
506 * See {@link android.webkit.WebView#computeHorizontalScrollRange}
507 */
508 public int computeHorizontalScrollRange();
509
510 /**
511 * See {@link android.webkit.WebView#computeHorizontalScrollOffset}
512 */
513 public int computeHorizontalScrollOffset();
514
515 /**
516 * See {@link android.webkit.WebView#computeVerticalScrollRange}
517 */
518 public int computeVerticalScrollRange();
519
520 /**
521 * See {@link android.webkit.WebView#computeVerticalScrollOffset}
522 */
523 public int computeVerticalScrollOffset();
524
525 /**
526 * See {@link android.webkit.WebView#computeVerticalScrollExtent}
527 */
528 public int computeVerticalScrollExtent();
529
530 /**
531 * See {@link android.webkit.WebView#computeScroll}
532 */
533 public void computeScroll();
534 }
535 }