Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b851929c authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Add new version of WebViewClient.shouldOverrideUrlLoading callback

The new version provides more information about the origin of
the load, which helps making more secure decision on how to proceed
with it.

Bug: 22346196
Change-Id: I27f591bf5e846bde14335a2c929758a2b48d0763
parent 7d428c86
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -39212,6 +39212,7 @@ package android.webkit {
    method public abstract android.net.Uri getUrl();
    method public abstract boolean hasGesture();
    method public abstract boolean isForMainFrame();
    method public abstract boolean isRedirect();
  }
  public class WebResourceResponse {
@@ -39574,7 +39575,8 @@ package android.webkit {
    method public deprecated android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView, java.lang.String);
    method public android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest);
    method public boolean shouldOverrideKeyEvent(android.webkit.WebView, android.view.KeyEvent);
    method public boolean shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String);
    method public deprecated boolean shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String);
    method public boolean shouldOverrideUrlLoading(android.webkit.WebView, android.webkit.WebResourceRequest);
    field public static final int ERROR_AUTHENTICATION = -4; // 0xfffffffc
    field public static final int ERROR_BAD_URL = -12; // 0xfffffff4
    field public static final int ERROR_CONNECT = -6; // 0xfffffffa
+3 −1
Original line number Diff line number Diff line
@@ -41572,6 +41572,7 @@ package android.webkit {
    method public abstract android.net.Uri getUrl();
    method public abstract boolean hasGesture();
    method public abstract boolean isForMainFrame();
    method public abstract boolean isRedirect();
  }
  public class WebResourceResponse {
@@ -41981,7 +41982,8 @@ package android.webkit {
    method public deprecated android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView, java.lang.String);
    method public android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest);
    method public boolean shouldOverrideKeyEvent(android.webkit.WebView, android.view.KeyEvent);
    method public boolean shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String);
    method public deprecated boolean shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String);
    method public boolean shouldOverrideUrlLoading(android.webkit.WebView, android.webkit.WebResourceRequest);
    field public static final int ERROR_AUTHENTICATION = -4; // 0xfffffffc
    field public static final int ERROR_BAD_URL = -12; // 0xfffffff4
    field public static final int ERROR_CONNECT = -6; // 0xfffffffa
+7 −0
Original line number Diff line number Diff line
@@ -39,6 +39,13 @@ public interface WebResourceRequest {
     */
    boolean isForMainFrame();

    /**
     * Gets whether the request was a result of a redirect.
     *
     * @return whether the request was a result of a redirect.
     */
    boolean isRedirect();

    /**
     * Gets whether a gesture (such as a click) was associated with the request.
     * For security reasons in certain situations this method may return false even though the
+30 −0
Original line number Diff line number Diff line
@@ -38,11 +38,41 @@ public class WebViewClient {
     * @param url The url to be loaded.
     * @return True if the host application wants to leave the current WebView
     *         and handle the url itself, otherwise return false.
     * @deprecated Use {@link #shouldOverrideUrlLoading(WebView, WebResourceRequest)
     *             shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead.
     */
    @Deprecated
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }

    /**
     * Give the host application a chance to take over the control when a new
     * url is about to be loaded in the current WebView. If WebViewClient is not
     * provided, by default WebView will ask Activity Manager to choose the
     * proper handler for the url. If WebViewClient is provided, return true
     * means the host application handles the url, while return false means the
     * current WebView handles the url.
     *
     * <p>Notes:
     * <ul>
     * <li>This method is not called for requests using the POST &quot;method&quot;.</li>
     * <li>This method is also called for subframes with non-http schemes, thus it is
     * strongly disadvised to unconditionally call {@link WebView#loadUrl(String)}
     * with the request's url from inside the method and then return true,
     * as this will make WebView to attempt loading a non-http url, and thus fail.</li>
     * </ul>
     * </p>
     *
     * @param view The WebView that is initiating the callback.
     * @param request Object containing the details of the request.
     * @return True if the host application wants to leave the current WebView
     *         and handle the url itself, otherwise return false.
     */
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        return shouldOverrideUrlLoading(view, request.getUrl().toString());
    }

    /**
     * Notify the host application that a page has started loading. This method
     * is called once for each main frame load so a page with iframes or