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