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