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