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