WebViewProvider.java revision 1b650cb6f99e0481ed20795ec19fc62bbf1191ba
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
17package android.webkit;
18
19import android.annotation.SystemApi;
20import android.content.res.Configuration;
21import android.graphics.Bitmap;
22import android.graphics.Canvas;
23import android.graphics.Paint;
24import android.graphics.Picture;
25import android.graphics.Rect;
26import android.graphics.drawable.Drawable;
27import android.net.http.SslCertificate;
28import android.net.Uri;
29import android.os.Bundle;
30import android.os.Message;
31import android.print.PrintDocumentAdapter;
32import android.view.KeyEvent;
33import android.view.MotionEvent;
34import android.view.View;
35import android.view.ViewAssistStructure;
36import android.view.ViewGroup.LayoutParams;
37import android.view.accessibility.AccessibilityEvent;
38import android.view.accessibility.AccessibilityNodeInfo;
39import android.view.accessibility.AccessibilityNodeProvider;
40import android.view.inputmethod.EditorInfo;
41import android.view.inputmethod.InputConnection;
42import android.webkit.WebView.HitTestResult;
43import android.webkit.WebView.PictureListener;
44import android.webkit.WebView.VisualStateCallback;
45
46
47import java.io.BufferedWriter;
48import java.io.File;
49import java.util.Map;
50
51/**
52 * WebView backend provider interface: this interface is the abstract backend to a WebView
53 * instance; each WebView object is bound to exactly one WebViewProvider object which implements
54 * the runtime behavior of that WebView.
55 *
56 * All methods must behave as per their namesake in {@link WebView}, unless otherwise noted.
57 *
58 * @hide Not part of the public API; only required by system implementors.
59 */
60@SystemApi
61public interface WebViewProvider {
62    //-------------------------------------------------------------------------
63    // Main interface for backend provider of the WebView class.
64    //-------------------------------------------------------------------------
65    /**
66     * Initialize this WebViewProvider instance. Called after the WebView has fully constructed.
67     * @param javaScriptInterfaces is a Map of interface names, as keys, and
68     * object implementing those interfaces, as values.
69     * @param privateBrowsing If true the web view will be initialized in private / incognito mode.
70     */
71    public void init(Map<String, Object> javaScriptInterfaces,
72            boolean privateBrowsing);
73
74    public void setHorizontalScrollbarOverlay(boolean overlay);
75
76    public void setVerticalScrollbarOverlay(boolean overlay);
77
78    public boolean overlayHorizontalScrollbar();
79
80    public boolean overlayVerticalScrollbar();
81
82    public int getVisibleTitleHeight();
83
84    public SslCertificate getCertificate();
85
86    public void setCertificate(SslCertificate certificate);
87
88    public void savePassword(String host, String username, String password);
89
90    public void setHttpAuthUsernamePassword(String host, String realm,
91            String username, String password);
92
93    public String[] getHttpAuthUsernamePassword(String host, String realm);
94
95    /**
96     * See {@link WebView#destroy()}.
97     * As well as releasing the internal state and resources held by the implementation,
98     * the provider should null all references it holds on the WebView proxy class, and ensure
99     * no further method calls are made to it.
100     */
101    public void destroy();
102
103    public void setNetworkAvailable(boolean networkUp);
104
105    public WebBackForwardList saveState(Bundle outState);
106
107    public boolean savePicture(Bundle b, final File dest);
108
109    public boolean restorePicture(Bundle b, File src);
110
111    public WebBackForwardList restoreState(Bundle inState);
112
113    public void loadUrl(String url, Map<String, String> additionalHttpHeaders);
114
115    public void loadUrl(String url);
116
117    public void postUrl(String url, byte[] postData);
118
119    public void loadData(String data, String mimeType, String encoding);
120
121    public void loadDataWithBaseURL(String baseUrl, String data,
122            String mimeType, String encoding, String historyUrl);
123
124    public void evaluateJavaScript(String script, ValueCallback<String> resultCallback);
125
126    public void saveWebArchive(String filename);
127
128    public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback);
129
130    public void stopLoading();
131
132    public void reload();
133
134    public boolean canGoBack();
135
136    public void goBack();
137
138    public boolean canGoForward();
139
140    public void goForward();
141
142    public boolean canGoBackOrForward(int steps);
143
144    public void goBackOrForward(int steps);
145
146    public boolean isPrivateBrowsingEnabled();
147
148    public boolean pageUp(boolean top);
149
150    public boolean pageDown(boolean bottom);
151
152    public void insertVisualStateCallback(long requestId, VisualStateCallback callback);
153
154    public void clearView();
155
156    public Picture capturePicture();
157
158    public PrintDocumentAdapter createPrintDocumentAdapter(String documentName);
159
160    public float getScale();
161
162    public void setInitialScale(int scaleInPercent);
163
164    public void invokeZoomPicker();
165
166    public HitTestResult getHitTestResult();
167
168    public void requestFocusNodeHref(Message hrefMsg);
169
170    public void requestImageRef(Message msg);
171
172    public String getUrl();
173
174    public String getOriginalUrl();
175
176    public String getTitle();
177
178    public Bitmap getFavicon();
179
180    public String getTouchIconUrl();
181
182    public int getProgress();
183
184    public int getContentHeight();
185
186    public int getContentWidth();
187
188    public void pauseTimers();
189
190    public void resumeTimers();
191
192    public void onPause();
193
194    public void onResume();
195
196    public boolean isPaused();
197
198    public void freeMemory();
199
200    public void clearCache(boolean includeDiskFiles);
201
202    public void clearFormData();
203
204    public void clearHistory();
205
206    public void clearSslPreferences();
207
208    public WebBackForwardList copyBackForwardList();
209
210    public void setFindListener(WebView.FindListener listener);
211
212    public void findNext(boolean forward);
213
214    public int findAll(String find);
215
216    public void findAllAsync(String find);
217
218    public boolean showFindDialog(String text, boolean showIme);
219
220    public void clearMatches();
221
222    public void documentHasImages(Message response);
223
224    public void setWebViewClient(WebViewClient client);
225
226    public void setDownloadListener(DownloadListener listener);
227
228    public void setWebChromeClient(WebChromeClient client);
229
230    public void setPictureListener(PictureListener listener);
231
232    public void addJavascriptInterface(Object obj, String interfaceName);
233
234    public void removeJavascriptInterface(String interfaceName);
235
236    public WebMessagePort[] createWebMessageChannel();
237
238    public void postMessageToMainFrame(WebMessage message, Uri targetOrigin);
239
240    public WebSettings getSettings();
241
242    public void setMapTrackballToArrowKeys(boolean setMap);
243
244    public void flingScroll(int vx, int vy);
245
246    public View getZoomControls();
247
248    public boolean canZoomIn();
249
250    public boolean canZoomOut();
251
252    public boolean zoomBy(float zoomFactor);
253
254    public boolean zoomIn();
255
256    public boolean zoomOut();
257
258    public void dumpViewHierarchyWithProperties(BufferedWriter out, int level);
259
260    public View findHierarchyView(String className, int hashCode);
261
262    //-------------------------------------------------------------------------
263    // Provider internal methods
264    //-------------------------------------------------------------------------
265
266    /**
267     * @return the ViewDelegate implementation. This provides the functionality to back all of
268     * the name-sake functions from the View and ViewGroup base classes of WebView.
269     */
270    /* package */ ViewDelegate getViewDelegate();
271
272    /**
273     * @return a ScrollDelegate implementation. Normally this would be same object as is
274     * returned by getViewDelegate().
275     */
276    /* package */ ScrollDelegate getScrollDelegate();
277
278    /**
279     * Only used by FindActionModeCallback to inform providers that the find dialog has
280     * been dismissed.
281     */
282    public void notifyFindDialogDismissed();
283
284    //-------------------------------------------------------------------------
285    // View / ViewGroup delegation methods
286    //-------------------------------------------------------------------------
287
288    /**
289     * Provides mechanism for the name-sake methods declared in View and ViewGroup to be delegated
290     * into the WebViewProvider instance.
291     * NOTE For many of these methods, the WebView will provide a super.Foo() call before or after
292     * making the call into the provider instance. This is done for convenience in the common case
293     * of maintaining backward compatibility. For remaining super class calls (e.g. where the
294     * provider may need to only conditionally make the call based on some internal state) see the
295     * {@link WebView.PrivateAccess} callback class.
296     */
297    // TODO: See if the pattern of the super-class calls can be rationalized at all, and document
298    // the remainder on the methods below.
299    interface ViewDelegate {
300        public boolean shouldDelayChildPressedState();
301
302        public void onProvideVirtualAssistStructure(ViewAssistStructure structure);
303
304        public AccessibilityNodeProvider getAccessibilityNodeProvider();
305
306        public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info);
307
308        public void onInitializeAccessibilityEvent(AccessibilityEvent event);
309
310        public boolean performAccessibilityAction(int action, Bundle arguments);
311
312        public void setOverScrollMode(int mode);
313
314        public void setScrollBarStyle(int style);
315
316        public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t,
317                int r, int b);
318
319        public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
320
321        public void onWindowVisibilityChanged(int visibility);
322
323        public void onDraw(Canvas canvas);
324
325        public void setLayoutParams(LayoutParams layoutParams);
326
327        public boolean performLongClick();
328
329        public void onConfigurationChanged(Configuration newConfig);
330
331        public InputConnection onCreateInputConnection(EditorInfo outAttrs);
332
333        public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
334
335        public boolean onKeyDown(int keyCode, KeyEvent event);
336
337        public boolean onKeyUp(int keyCode, KeyEvent event);
338
339        public void onAttachedToWindow();
340
341        public void onDetachedFromWindow();
342
343        public void onVisibilityChanged(View changedView, int visibility);
344
345        public void onWindowFocusChanged(boolean hasWindowFocus);
346
347        public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect);
348
349        public boolean setFrame(int left, int top, int right, int bottom);
350
351        public void onSizeChanged(int w, int h, int ow, int oh);
352
353        public void onScrollChanged(int l, int t, int oldl, int oldt);
354
355        public boolean dispatchKeyEvent(KeyEvent event);
356
357        public boolean onTouchEvent(MotionEvent ev);
358
359        public boolean onHoverEvent(MotionEvent event);
360
361        public boolean onGenericMotionEvent(MotionEvent event);
362
363        public boolean onTrackballEvent(MotionEvent ev);
364
365        public boolean requestFocus(int direction, Rect previouslyFocusedRect);
366
367        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
368
369        public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate);
370
371        public void setBackgroundColor(int color);
372
373        public void setLayerType(int layerType, Paint paint);
374
375        public void preDispatchDraw(Canvas canvas);
376
377        public void onStartTemporaryDetach();
378
379        public void onFinishTemporaryDetach();
380    }
381
382    interface ScrollDelegate {
383        // These methods are declared protected in the ViewGroup base class. This interface
384        // exists to promote them to public so they may be called by the WebView proxy class.
385        // TODO: Combine into ViewDelegate?
386        /**
387         * See {@link android.webkit.WebView#computeHorizontalScrollRange}
388         */
389        public int computeHorizontalScrollRange();
390
391        /**
392         * See {@link android.webkit.WebView#computeHorizontalScrollOffset}
393         */
394        public int computeHorizontalScrollOffset();
395
396        /**
397         * See {@link android.webkit.WebView#computeVerticalScrollRange}
398         */
399        public int computeVerticalScrollRange();
400
401        /**
402         * See {@link android.webkit.WebView#computeVerticalScrollOffset}
403         */
404        public int computeVerticalScrollOffset();
405
406        /**
407         * See {@link android.webkit.WebView#computeVerticalScrollExtent}
408         */
409        public int computeVerticalScrollExtent();
410
411        /**
412         * See {@link android.webkit.WebView#computeScroll}
413         */
414        public void computeScroll();
415    }
416}
417