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