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