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