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