Class ShadowWebView


  • @Implements(android.webkit.WebView.class)
    public class ShadowWebView
    extends ShadowViewGroup
    • Constructor Detail

      • ShadowWebView

        public ShadowWebView()
    • Method Detail

      • ensureProviderCreated

        @HiddenApi
        @Implementation
        public void ensureProviderCreated()
      • setLayoutParams

        @Implementation
        protected void setLayoutParams​(android.view.ViewGroup.LayoutParams params)
      • loadUrl

        @Implementation
        protected void loadUrl​(java.lang.String url)
      • loadUrl

        @Implementation
        protected void loadUrl​(java.lang.String url,
                               java.util.Map<java.lang.String,​java.lang.String> additionalHttpHeaders)
        Fires a request to load the given url in WebView.

        The url is is not added to the history until pushEntryToHistory(String) is called. If you want to simulate a redirect you can pass the redirect URL to pushEntryToHistory(String).

      • loadDataWithBaseURL

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

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

        public void pushEntryToHistory​(java.lang.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 java.lang.String getLastLoadedUrl()
        Returns:
        the last loaded url
      • getOriginalUrl

        @Implementation
        protected java.lang.String getOriginalUrl()
      • getUrl

        @Implementation
        protected java.lang.String getUrl()
      • getTitle

        @Implementation
        protected java.lang.String getTitle()
      • getLastAdditionalHttpHeaders

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

        @Implementation
        protected android.webkit.WebSettings getSettings()
      • setWebViewClient

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

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

        public android.webkit.WebViewClient getWebViewClient()
      • addJavascriptInterface

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

        public java.lang.Object getJavascriptInterface​(java.lang.String interfaceName)
      • removeJavascriptInterface

        @Implementation
        protected void removeJavascriptInterface​(java.lang.String name)
      • 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

        public android.webkit.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 android.webkit.WebBackForwardList copyBackForwardList()
      • findAddress

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

        @Implementation(minSdk=26)
        protected static android.content.pm.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​(android.content.pm.PackageInfo webViewPackageInfo)
        Sets the value to return from #getCurrentWebviewPackage().
      • evaluateJavascript

        @Implementation(minSdk=19)
        protected void evaluateJavascript​(java.lang.String script,
                                          android.webkit.ValueCallback<java.lang.String> callback)
      • getLastEvaluatedJavascript

        public java.lang.String getLastEvaluatedJavascript()
      • 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.
      • saveState

        @Implementation
        protected android.webkit.WebBackForwardList saveState​(android.os.Bundle outState)
      • restoreState

        @Implementation
        protected android.webkit.WebBackForwardList restoreState​(android.os.Bundle inState)
      • getHitTestResult

        @Implementation
        protected android.webkit.WebView.HitTestResult getHitTestResult()
      • createHitTestResult

        public static android.webkit.WebView.HitTestResult createHitTestResult​(int type,
                                                                               java.lang.String extra)
        Creates an instance of WebView.HitTestResult.
      • setHitTestResult

        public void setHitTestResult​(android.webkit.WebView.HitTestResult hitTestResult)
        Sets the WebView.HitTestResult that should be returned from getHitTestResult().
      • reset

        @Resetter
        public static void reset()
      • setWebContentsDebuggingEnabled

        public static void setWebContentsDebuggingEnabled​(boolean enabled)