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