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