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