• 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 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      */
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     // 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 {
shouldDelayChildPressedState()274         public boolean shouldDelayChildPressedState();
275 
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)276         public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info);
277 
onInitializeAccessibilityEvent(AccessibilityEvent event)278         public void onInitializeAccessibilityEvent(AccessibilityEvent event);
279 
performAccessibilityAction(int action, Bundle arguments)280         public boolean performAccessibilityAction(int action, Bundle arguments);
281 
setOverScrollMode(int mode)282         public void setOverScrollMode(int mode);
283 
setScrollBarStyle(int style)284         public void setScrollBarStyle(int style);
285 
onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t, int r, int b)286         public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t,
287                 int r, int b);
288 
onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY)289         public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY);
290 
onWindowVisibilityChanged(int visibility)291         public void onWindowVisibilityChanged(int visibility);
292 
onDraw(Canvas canvas)293         public void onDraw(Canvas canvas);
294 
setLayoutParams(LayoutParams layoutParams)295         public void setLayoutParams(LayoutParams layoutParams);
296 
performLongClick()297         public boolean performLongClick();
298 
onConfigurationChanged(Configuration newConfig)299         public void onConfigurationChanged(Configuration newConfig);
300 
onCreateInputConnection(EditorInfo outAttrs)301         public InputConnection onCreateInputConnection(EditorInfo outAttrs);
302 
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)303         public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event);
304 
onKeyDown(int keyCode, KeyEvent event)305         public boolean onKeyDown(int keyCode, KeyEvent event);
306 
onKeyUp(int keyCode, KeyEvent event)307         public boolean onKeyUp(int keyCode, KeyEvent event);
308 
onAttachedToWindow()309         public void onAttachedToWindow();
310 
onDetachedFromWindow()311         public void onDetachedFromWindow();
312 
onVisibilityChanged(View changedView, int visibility)313         public void onVisibilityChanged(View changedView, int visibility);
314 
onWindowFocusChanged(boolean hasWindowFocus)315         public void onWindowFocusChanged(boolean hasWindowFocus);
316 
onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)317         public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect);
318 
setFrame(int left, int top, int right, int bottom)319         public boolean setFrame(int left, int top, int right, int bottom);
320 
onSizeChanged(int w, int h, int ow, int oh)321         public void onSizeChanged(int w, int h, int ow, int oh);
322 
onScrollChanged(int l, int t, int oldl, int oldt)323         public void onScrollChanged(int l, int t, int oldl, int oldt);
324 
dispatchKeyEvent(KeyEvent event)325         public boolean dispatchKeyEvent(KeyEvent event);
326 
onTouchEvent(MotionEvent ev)327         public boolean onTouchEvent(MotionEvent ev);
328 
onHoverEvent(MotionEvent event)329         public boolean onHoverEvent(MotionEvent event);
330 
onGenericMotionEvent(MotionEvent event)331         public boolean onGenericMotionEvent(MotionEvent event);
332 
onTrackballEvent(MotionEvent ev)333         public boolean onTrackballEvent(MotionEvent ev);
334 
requestFocus(int direction, Rect previouslyFocusedRect)335         public boolean requestFocus(int direction, Rect previouslyFocusedRect);
336 
onMeasure(int widthMeasureSpec, int heightMeasureSpec)337         public void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
338 
requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)339         public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate);
340 
setBackgroundColor(int color)341         public void setBackgroundColor(int color);
342 
setLayerType(int layerType, Paint paint)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          */
computeHorizontalScrollRange()353         public int computeHorizontalScrollRange();
354 
355         /**
356          * See {@link android.webkit.WebView#computeHorizontalScrollOffset}
357          */
computeHorizontalScrollOffset()358         public int computeHorizontalScrollOffset();
359 
360         /**
361          * See {@link android.webkit.WebView#computeVerticalScrollRange}
362          */
computeVerticalScrollRange()363         public int computeVerticalScrollRange();
364 
365         /**
366          * See {@link android.webkit.WebView#computeVerticalScrollOffset}
367          */
computeVerticalScrollOffset()368         public int computeVerticalScrollOffset();
369 
370         /**
371          * See {@link android.webkit.WebView#computeVerticalScrollExtent}
372          */
computeVerticalScrollExtent()373         public int computeVerticalScrollExtent();
374 
375         /**
376          * See {@link android.webkit.WebView#computeScroll}
377          */
computeScroll()378         public void computeScroll();
379     }
380 }
381