Class ShadowWebView

    • Constructor Detail

      • ShadowWebView

        public ShadowWebView()
    • Method Detail

      • ensureProviderCreated

        @HiddenApi
        @Implementation
        public void ensureProviderCreated()
      • loadUrl

        @Implementation
        protected void loadUrl​(String url)
      • loadDataWithBaseURL

        @Implementation
        protected void loadDataWithBaseURL​(String baseUrl,
                                           String data,
                                           String mimeType,
                                           String encoding,
                                           String historyUrl)
      • loadData

        @Implementation
        protected void loadData​(String data,
                                String mimeType,
                                String encoding)
      • pushEntryToHistory

        public void pushEntryToHistory​(String url)
        Pushes an entry to the history with the given url.

        This method can be used after a loadUrl(String) call to push that navigation into the history. This matches the prod behaviour of WebView, a navigation is never committed to history inline and can take an arbitrary amount of time depending on the network connection. Notice that the given url does not need to match that of the loadUrl(String) as URL can be changed e.g. through server-side redirects without WebView being notified by the time it is committed.

        This method can also be used to simulate navigations started by user interaction, as these would still add an entry to the history themselves.

        If there are any entries ahead of the current index (for forward navigation) these are removed.

      • getLastLoadedUrl

        public String getLastLoadedUrl()
        Returns:
        the last loaded url
      • getOriginalUrl

        @Implementation
        protected String getOriginalUrl()
      • getUrl

        @Implementation
        protected String getUrl()
      • getTitle

        @Implementation
        protected String getTitle()
      • getLastAdditionalHttpHeaders

        public Map<String,​String> getLastAdditionalHttpHeaders()
        Returns:
        the additional Http headers that in the same request with last loaded url
      • getSettings

        @Implementation
        protected WebSettings getSettings()
      • setWebViewClient

        @Implementation
        protected void setWebViewClient​(WebViewClient client)
      • setWebChromeClient

        @Implementation
        protected void setWebChromeClient​(WebChromeClient client)
      • getWebViewClient

        @Implementation(minSdk=26)
        public WebViewClient getWebViewClient()
      • addJavascriptInterface

        @Implementation
        protected void addJavascriptInterface​(Object obj,
                                              String interfaceName)
      • getJavascriptInterface

        public Object getJavascriptInterface​(String interfaceName)
      • removeJavascriptInterface

        @Implementation
        protected void removeJavascriptInterface​(String name)
      • createWebMessageChannel

        @Implementation(minSdk=23)
        protected WebMessagePort[] createWebMessageChannel()
      • clearCache

        @Implementation
        protected void clearCache​(boolean includeDiskFiles)
      • wasClearCacheCalled

        public boolean wasClearCacheCalled()
      • didClearCacheIncludeDiskFiles

        public boolean didClearCacheIncludeDiskFiles()
      • clearFormData

        @Implementation
        protected void clearFormData()
      • wasClearFormDataCalled

        public boolean wasClearFormDataCalled()
      • clearHistory

        @Implementation
        protected void clearHistory()
      • wasClearHistoryCalled

        public boolean wasClearHistoryCalled()
      • reload

        @Implementation
        protected void reload()
      • getReloadInvocations

        public int getReloadInvocations()
        Returns the number of times android.webkit.WebView#reload() was invoked
      • clearView

        @Implementation
        protected void clearView()
      • wasClearViewCalled

        public boolean wasClearViewCalled()
      • onPause

        @Implementation
        protected void onPause()
      • wasOnPauseCalled

        public boolean wasOnPauseCalled()
      • onResume

        @Implementation
        protected void onResume()
      • wasOnResumeCalled

        public boolean wasOnResumeCalled()
      • destroy

        @Implementation
        protected void destroy()
      • wasDestroyCalled

        public boolean wasDestroyCalled()
      • getWebChromeClient

        @Implementation(minSdk=26)
        public WebChromeClient getWebChromeClient()
        Returns:
        webChromeClient
      • canGoBack

        @Implementation
        protected boolean canGoBack()
      • canGoForward

        @Implementation
        protected boolean canGoForward()
      • goBack

        @Implementation
        protected void goBack()
      • goForward

        @Implementation
        protected void goForward()
      • goBackOrForward

        @Implementation
        protected void goBackOrForward​(int steps)
      • copyBackForwardList

        @Implementation
        protected WebBackForwardList copyBackForwardList()
      • findAddress

        @Implementation
        protected static String findAddress​(String addr)
      • getCurrentWebViewPackage

        @Implementation(minSdk=26)
        protected static PackageInfo getCurrentWebViewPackage()
        Overrides the system implementation for getting the WebView package.

        Returns null by default, but this can be changed with #setCurrentWebviewPackage().

      • setCurrentWebViewPackage

        public static void setCurrentWebViewPackage​(PackageInfo webViewPackageInfo)
        Sets the value to return from #getCurrentWebviewPackage().
      • setFavicon

        public void setFavicon​(Bitmap favicon)
        Sets the favicon to return from getFavicon().
      • evaluateJavascript

        @Implementation(minSdk=19)
        protected void evaluateJavascript​(String script,
                                          ValueCallback<String> callback)
      • setCanGoBack

        @Deprecated
        public void setCanGoBack​(boolean canGoBack)
        Deprecated.
        Do not depend on this method as it will be removed in a future update. The preferered method is to populate a fake web history to use for going back.
        Sets the value to return from android.webkit.WebView#canGoBack()
        Parameters:
        canGoBack - Value to return from android.webkit.WebView#canGoBack()
      • getGoBackInvocations

        public int getGoBackInvocations()
        Returns the number of times android.webkit.WebView#goBack() was invoked.
      • getGoForwardInvocations

        public int getGoForwardInvocations()
        Returns the number of times android.webkit.WebView#goForward() was invoked.
      • reset

        @Resetter
        public static void reset()
      • setWebContentsDebuggingEnabled

        @Implementation(minSdk=19)
        public static void setWebContentsDebuggingEnabled​(boolean enabled)
      • setBackgroundColor

        @Implementation
        protected void setBackgroundColor​(int backgroundColor)
        Sets the Color int that should be returned from getBackgroundColor().

        WebView uses the background color set by the WebView.setBackgroundColor(int) method to internally tint the background color of web pages until they are drawn. The way this API works is completely independent of the View.setBackgroundColor(int) method and it interacts directly with WebView renderers. Tests can access the set background color using the getBackgroundColor() method.

      • setDownloadListener

        @Implementation
        protected void setDownloadListener​(DownloadListener downloadListener)