Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 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; |
John Reck | a5408e6 | 2012-03-16 14:18:44 -0700 | [diff] [blame] | 22 | import android.graphics.Paint; |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 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; |
Ben Murdoch | e3f9071 | 2013-06-05 14:19:48 +0100 | [diff] [blame] | 35 | import android.view.accessibility.AccessibilityNodeProvider; |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 36 | import android.view.inputmethod.EditorInfo; |
| 37 | import android.view.inputmethod.InputConnection; |
| 38 | import android.webkit.WebView.HitTestResult; |
| 39 | import android.webkit.WebView.PictureListener; |
| 40 | |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 41 | import java.io.BufferedWriter; |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 42 | import java.io.File; |
| 43 | import 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 | */ |
| 54 | public 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 | |
Ben Murdoch | a5cdd51 | 2013-07-17 16:25:07 +0100 | [diff] [blame] | 117 | public void evaluateJavaScript(String script, ValueCallback<String> resultCallback); |
| 118 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 119 | public void saveWebArchive(String filename); |
| 120 | |
| 121 | public void saveWebArchive(String basename, boolean autoname, ValueCallback<String> callback); |
| 122 | |
| 123 | public void stopLoading(); |
| 124 | |
| 125 | public void reload(); |
| 126 | |
| 127 | public boolean canGoBack(); |
| 128 | |
| 129 | public void goBack(); |
| 130 | |
| 131 | public boolean canGoForward(); |
| 132 | |
| 133 | public void goForward(); |
| 134 | |
| 135 | public boolean canGoBackOrForward(int steps); |
| 136 | |
| 137 | public void goBackOrForward(int steps); |
| 138 | |
| 139 | public boolean isPrivateBrowsingEnabled(); |
| 140 | |
| 141 | public boolean pageUp(boolean top); |
| 142 | |
| 143 | public boolean pageDown(boolean bottom); |
| 144 | |
| 145 | public void clearView(); |
| 146 | |
| 147 | public Picture capturePicture(); |
| 148 | |
| 149 | public float getScale(); |
| 150 | |
| 151 | public void setInitialScale(int scaleInPercent); |
| 152 | |
| 153 | public void invokeZoomPicker(); |
| 154 | |
| 155 | public HitTestResult getHitTestResult(); |
| 156 | |
| 157 | public void requestFocusNodeHref(Message hrefMsg); |
| 158 | |
| 159 | public void requestImageRef(Message msg); |
| 160 | |
| 161 | public String getUrl(); |
| 162 | |
| 163 | public String getOriginalUrl(); |
| 164 | |
| 165 | public String getTitle(); |
| 166 | |
| 167 | public Bitmap getFavicon(); |
| 168 | |
| 169 | public String getTouchIconUrl(); |
| 170 | |
| 171 | public int getProgress(); |
| 172 | |
| 173 | public int getContentHeight(); |
| 174 | |
| 175 | public int getContentWidth(); |
| 176 | |
| 177 | public void pauseTimers(); |
| 178 | |
| 179 | public void resumeTimers(); |
| 180 | |
| 181 | public void onPause(); |
| 182 | |
| 183 | public void onResume(); |
| 184 | |
| 185 | public boolean isPaused(); |
| 186 | |
| 187 | public void freeMemory(); |
| 188 | |
| 189 | public void clearCache(boolean includeDiskFiles); |
| 190 | |
| 191 | public void clearFormData(); |
| 192 | |
| 193 | public void clearHistory(); |
| 194 | |
| 195 | public void clearSslPreferences(); |
| 196 | |
| 197 | public WebBackForwardList copyBackForwardList(); |
| 198 | |
Victoria Lease | d405a43 | 2012-03-22 15:53:48 -0700 | [diff] [blame] | 199 | public void setFindListener(WebView.FindListener listener); |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 200 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 201 | public void findNext(boolean forward); |
| 202 | |
| 203 | public int findAll(String find); |
| 204 | |
Victoria Lease | abeb6a7 | 2012-03-05 16:29:12 -0800 | [diff] [blame] | 205 | public void findAllAsync(String find); |
| 206 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 207 | public boolean showFindDialog(String text, boolean showIme); |
| 208 | |
| 209 | public void clearMatches(); |
| 210 | |
| 211 | public void documentHasImages(Message response); |
| 212 | |
| 213 | public void setWebViewClient(WebViewClient client); |
| 214 | |
| 215 | public void setDownloadListener(DownloadListener listener); |
| 216 | |
| 217 | public void setWebChromeClient(WebChromeClient client); |
| 218 | |
| 219 | public void setPictureListener(PictureListener listener); |
| 220 | |
| 221 | public void addJavascriptInterface(Object obj, String interfaceName); |
| 222 | |
| 223 | public void removeJavascriptInterface(String interfaceName); |
| 224 | |
| 225 | public WebSettings getSettings(); |
| 226 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 227 | public void setMapTrackballToArrowKeys(boolean setMap); |
| 228 | |
| 229 | public void flingScroll(int vx, int vy); |
| 230 | |
| 231 | public View getZoomControls(); |
| 232 | |
| 233 | public boolean canZoomIn(); |
| 234 | |
| 235 | public boolean canZoomOut(); |
| 236 | |
| 237 | public boolean zoomIn(); |
| 238 | |
| 239 | public boolean zoomOut(); |
| 240 | |
John Reck | 926cf56 | 2012-06-14 10:00:31 -0700 | [diff] [blame] | 241 | public void dumpViewHierarchyWithProperties(BufferedWriter out, int level); |
| 242 | |
| 243 | public View findHierarchyView(String className, int hashCode); |
| 244 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 245 | //------------------------------------------------------------------------- |
Ben Murdoch | 52c9f7f | 2013-01-18 00:50:37 +0000 | [diff] [blame] | 246 | // Provider internal methods |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 247 | //------------------------------------------------------------------------- |
| 248 | |
| 249 | /** |
| 250 | * @return the ViewDelegate implementation. This provides the functionality to back all of |
| 251 | * the name-sake functions from the View and ViewGroup base classes of WebView. |
| 252 | */ |
| 253 | /* package */ ViewDelegate getViewDelegate(); |
| 254 | |
| 255 | /** |
| 256 | * @return a ScrollDelegate implementation. Normally this would be same object as is |
| 257 | * returned by getViewDelegate(). |
| 258 | */ |
| 259 | /* package */ ScrollDelegate getScrollDelegate(); |
| 260 | |
Ben Murdoch | 52c9f7f | 2013-01-18 00:50:37 +0000 | [diff] [blame] | 261 | /** |
| 262 | * Only used by FindActionModeCallback to inform providers that the find dialog has |
| 263 | * been dismissed. |
| 264 | */ |
| 265 | public void notifyFindDialogDismissed(); |
| 266 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 267 | //------------------------------------------------------------------------- |
| 268 | // View / ViewGroup delegation methods |
| 269 | //------------------------------------------------------------------------- |
| 270 | |
| 271 | /** |
| 272 | * Provides mechanism for the name-sake methods declared in View and ViewGroup to be delegated |
| 273 | * into the WebViewProvider instance. |
| 274 | * NOTE For many of these methods, the WebView will provide a super.Foo() call before or after |
| 275 | * making the call into the provider instance. This is done for convenience in the common case |
| 276 | * of maintaining backward compatibility. For remaining super class calls (e.g. where the |
| 277 | * provider may need to only conditionally make the call based on some internal state) see the |
| 278 | * {@link WebView.PrivateAccess} callback class. |
| 279 | */ |
| 280 | // TODO: See if the pattern of the super-class calls can be rationalized at all, and document |
| 281 | // the remainder on the methods below. |
| 282 | interface ViewDelegate { |
| 283 | public boolean shouldDelayChildPressedState(); |
| 284 | |
Ben Murdoch | e3f9071 | 2013-06-05 14:19:48 +0100 | [diff] [blame] | 285 | public AccessibilityNodeProvider getAccessibilityNodeProvider(); |
| 286 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 287 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info); |
| 288 | |
| 289 | public void onInitializeAccessibilityEvent(AccessibilityEvent event); |
| 290 | |
alanv | 448902d | 2012-05-16 20:27:47 -0700 | [diff] [blame] | 291 | public boolean performAccessibilityAction(int action, Bundle arguments); |
| 292 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 293 | public void setOverScrollMode(int mode); |
| 294 | |
| 295 | public void setScrollBarStyle(int style); |
| 296 | |
| 297 | public void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l, int t, |
| 298 | int r, int b); |
| 299 | |
| 300 | public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY); |
| 301 | |
| 302 | public void onWindowVisibilityChanged(int visibility); |
| 303 | |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 304 | public void onDraw(Canvas canvas); |
| 305 | |
| 306 | public void setLayoutParams(LayoutParams layoutParams); |
| 307 | |
| 308 | public boolean performLongClick(); |
| 309 | |
| 310 | public void onConfigurationChanged(Configuration newConfig); |
| 311 | |
| 312 | public InputConnection onCreateInputConnection(EditorInfo outAttrs); |
| 313 | |
| 314 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event); |
| 315 | |
| 316 | public boolean onKeyDown(int keyCode, KeyEvent event); |
| 317 | |
| 318 | public boolean onKeyUp(int keyCode, KeyEvent event); |
| 319 | |
| 320 | public void onAttachedToWindow(); |
| 321 | |
| 322 | public void onDetachedFromWindow(); |
| 323 | |
| 324 | public void onVisibilityChanged(View changedView, int visibility); |
| 325 | |
| 326 | public void onWindowFocusChanged(boolean hasWindowFocus); |
| 327 | |
| 328 | public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect); |
| 329 | |
| 330 | public boolean setFrame(int left, int top, int right, int bottom); |
| 331 | |
| 332 | public void onSizeChanged(int w, int h, int ow, int oh); |
| 333 | |
| 334 | public void onScrollChanged(int l, int t, int oldl, int oldt); |
| 335 | |
| 336 | public boolean dispatchKeyEvent(KeyEvent event); |
| 337 | |
| 338 | public boolean onTouchEvent(MotionEvent ev); |
| 339 | |
| 340 | public boolean onHoverEvent(MotionEvent event); |
| 341 | |
| 342 | public boolean onGenericMotionEvent(MotionEvent event); |
| 343 | |
| 344 | public boolean onTrackballEvent(MotionEvent ev); |
| 345 | |
| 346 | public boolean requestFocus(int direction, Rect previouslyFocusedRect); |
| 347 | |
| 348 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec); |
| 349 | |
| 350 | public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate); |
| 351 | |
| 352 | public void setBackgroundColor(int color); |
John Reck | a5408e6 | 2012-03-16 14:18:44 -0700 | [diff] [blame] | 353 | |
| 354 | public void setLayerType(int layerType, Paint paint); |
Ben Murdoch | e623e24 | 2012-09-07 20:47:07 +0100 | [diff] [blame] | 355 | |
| 356 | public void preDispatchDraw(Canvas canvas); |
Jonathan Dixon | 3c90952 | 2012-02-28 18:45:06 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | interface ScrollDelegate { |
| 360 | // These methods are declared protected in the ViewGroup base class. This interface |
| 361 | // exists to promote them to public so they may be called by the WebView proxy class. |
| 362 | // TODO: Combine into ViewDelegate? |
| 363 | /** |
| 364 | * See {@link android.webkit.WebView#computeHorizontalScrollRange} |
| 365 | */ |
| 366 | public int computeHorizontalScrollRange(); |
| 367 | |
| 368 | /** |
| 369 | * See {@link android.webkit.WebView#computeHorizontalScrollOffset} |
| 370 | */ |
| 371 | public int computeHorizontalScrollOffset(); |
| 372 | |
| 373 | /** |
| 374 | * See {@link android.webkit.WebView#computeVerticalScrollRange} |
| 375 | */ |
| 376 | public int computeVerticalScrollRange(); |
| 377 | |
| 378 | /** |
| 379 | * See {@link android.webkit.WebView#computeVerticalScrollOffset} |
| 380 | */ |
| 381 | public int computeVerticalScrollOffset(); |
| 382 | |
| 383 | /** |
| 384 | * See {@link android.webkit.WebView#computeVerticalScrollExtent} |
| 385 | */ |
| 386 | public int computeVerticalScrollExtent(); |
| 387 | |
| 388 | /** |
| 389 | * See {@link android.webkit.WebView#computeScroll} |
| 390 | */ |
| 391 | public void computeScroll(); |
| 392 | } |
| 393 | } |