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