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