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