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