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