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