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