Commit d29d5c72 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Introduce load error type for safe browsing errors

Safe browsing errors are currently folded into the OTHER_ERROR type by
Navigation#getLoadError(). In fact, embedders need to be able to
distinguish safe browsing errors from other types of errors. To do so,
this CL introduces a new SAFE_BROWSING_ERROR load error type and
configures the implementation to send this error type on safe browsing
errors.

Bug: 1149955
Change-Id: Ic70620ace6ebc79575f19dfe39898c9682146193
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551118
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830152}
parent 9e12d074
...@@ -182,6 +182,8 @@ public final class NavigationImpl extends INavigation.Stub { ...@@ -182,6 +182,8 @@ public final class NavigationImpl extends INavigation.Stub {
return LoadError.CONNECTIVITY_ERROR; return LoadError.CONNECTIVITY_ERROR;
case ImplLoadError.OTHER_ERROR: case ImplLoadError.OTHER_ERROR:
return LoadError.OTHER_ERROR; return LoadError.OTHER_ERROR;
case ImplLoadError.SAFE_BROWSING_ERROR:
return LoadError.SAFE_BROWSING_ERROR;
default: default:
throw new IllegalArgumentException("Unexpected load error " + loadError); throw new IllegalArgumentException("Unexpected load error " + loadError);
} }
......
...@@ -10,7 +10,8 @@ import java.lang.annotation.Retention; ...@@ -10,7 +10,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@IntDef({LoadError.NO_ERROR, LoadError.HTTP_CLIENT_ERROR, LoadError.HTTP_SERVER_ERROR, @IntDef({LoadError.NO_ERROR, LoadError.HTTP_CLIENT_ERROR, LoadError.HTTP_SERVER_ERROR,
LoadError.SSL_ERROR, LoadError.CONNECTIVITY_ERROR, LoadError.OTHER_ERROR}) LoadError.SSL_ERROR, LoadError.CONNECTIVITY_ERROR, LoadError.OTHER_ERROR,
LoadError.SAFE_BROWSING_ERROR})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface LoadError { public @interface LoadError {
int NO_ERROR = 0; int NO_ERROR = 0;
...@@ -19,4 +20,6 @@ public @interface LoadError { ...@@ -19,4 +20,6 @@ public @interface LoadError {
int SSL_ERROR = 3; int SSL_ERROR = 3;
int CONNECTIVITY_ERROR = 4; int CONNECTIVITY_ERROR = 4;
int OTHER_ERROR = 5; int OTHER_ERROR = 5;
// Sent since 89.
int SAFE_BROWSING_ERROR = 6;
} }
...@@ -166,6 +166,11 @@ Navigation::LoadError NavigationImpl::GetLoadError() { ...@@ -166,6 +166,11 @@ Navigation::LoadError NavigationImpl::GetLoadError() {
if (error_code == net::OK) if (error_code == net::OK)
return kNoError; return kNoError;
// The safe browsing navigation throttle fails navigations with
// ERR_BLOCKED_BY_CLIENT when showing safe browsing interstitials.
if (error_code == net::ERR_BLOCKED_BY_CLIENT)
return kSafeBrowsingError;
if (net::IsCertificateError(error_code)) if (net::IsCertificateError(error_code))
return kSSLError; return kSSLError;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "weblayer/browser/tab_impl.h" #include "weblayer/browser/tab_impl.h"
#include "weblayer/public/navigation.h" #include "weblayer/public/navigation.h"
#include "weblayer/public/navigation_controller.h" #include "weblayer/public/navigation_controller.h"
#include "weblayer/public/navigation_observer.h"
#include "weblayer/public/profile.h" #include "weblayer/public/profile.h"
#include "weblayer/public/tab.h" #include "weblayer/public/tab.h"
#include "weblayer/shell/browser/shell.h" #include "weblayer/shell/browser/shell.h"
...@@ -36,6 +37,38 @@ namespace weblayer { ...@@ -36,6 +37,38 @@ namespace weblayer {
namespace { namespace {
// Observer customized for safe browsing navigation failures.
class SafeBrowsingErrorNavigationObserver : public NavigationObserver {
public:
SafeBrowsingErrorNavigationObserver(const GURL& url, Shell* shell)
: url_(url), tab_(shell->tab()) {
tab_->GetNavigationController()->AddObserver(this);
}
~SafeBrowsingErrorNavigationObserver() override {
tab_->GetNavigationController()->RemoveObserver(this);
}
void NavigationFailed(Navigation* navigation) override {
if (navigation->GetURL() != url_)
return;
EXPECT_EQ(navigation->GetLoadError(),
Navigation::LoadError::kSafeBrowsingError);
run_loop_.Quit();
}
// Begins waiting for a Navigation within |shell_| and to |url_| to fail. In
// the failure callback verifies that the navigation failed with a safe
// browsing error.
void WaitForNavigationFailureWithSafeBrowsingError() { run_loop_.Run(); }
private:
const GURL url_;
Tab* tab_;
base::RunLoop run_loop_;
};
void RunCallbackOnIOThread( void RunCallbackOnIOThread(
std::unique_ptr<safe_browsing::SafeBrowsingApiHandler::URLCheckCallbackMeta> std::unique_ptr<safe_browsing::SafeBrowsingApiHandler::URLCheckCallbackMeta>
callback, callback,
...@@ -68,6 +101,8 @@ class FakeSafeBrowsingApiHandler ...@@ -68,6 +101,8 @@ class FakeSafeBrowsingApiHandler
restrictions_[url] = threat_type; restrictions_[url] = threat_type;
} }
void ClearRestrictions() { restrictions_.clear(); }
private: private:
safe_browsing::SBThreatType GetSafeBrowsingRestriction(const GURL& url) { safe_browsing::SBThreatType GetSafeBrowsingRestriction(const GURL& url) {
auto restrictions_iter = restrictions_.find(url); auto restrictions_iter = restrictions_.find(url);
...@@ -210,6 +245,25 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBrowserTest, ShowsInterstitial_Phishing) { ...@@ -210,6 +245,25 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBrowserTest, ShowsInterstitial_Phishing) {
NavigateWithThreatType(safe_browsing::SB_THREAT_TYPE_URL_PHISHING, true); NavigateWithThreatType(safe_browsing::SB_THREAT_TYPE_URL_PHISHING, true);
} }
IN_PROC_BROWSER_TEST_F(SafeBrowsingBrowserTest, CheckNavigationErrorType) {
auto threat_types = {
safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
safe_browsing::SB_THREAT_TYPE_URL_MALWARE,
safe_browsing::SB_THREAT_TYPE_URL_UNWANTED,
safe_browsing::SB_THREAT_TYPE_BILLING,
};
for (auto threat_type : threat_types) {
SafeBrowsingErrorNavigationObserver observer(url_, shell());
fake_handler_->ClearRestrictions();
fake_handler_->AddRestriction(url_, threat_type);
shell()->tab()->GetNavigationController()->Navigate(url_);
observer.WaitForNavigationFailureWithSafeBrowsingError();
}
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBrowserTest, ShowsInterstitial_Unwanted) { IN_PROC_BROWSER_TEST_F(SafeBrowsingBrowserTest, ShowsInterstitial_Unwanted) {
NavigateWithThreatType(safe_browsing::SB_THREAT_TYPE_URL_UNWANTED, true); NavigateWithThreatType(safe_browsing::SB_THREAT_TYPE_URL_UNWANTED, true);
} }
......
...@@ -41,7 +41,15 @@ public @interface LoadError { ...@@ -41,7 +41,15 @@ public @interface LoadError {
int CONNECTIVITY_ERROR = org.chromium.weblayer_private.interfaces.LoadError.CONNECTIVITY_ERROR; int CONNECTIVITY_ERROR = org.chromium.weblayer_private.interfaces.LoadError.CONNECTIVITY_ERROR;
/** /**
* An error not listed above occurred. * An error not listed above or below occurred.
*/ */
int OTHER_ERROR = org.chromium.weblayer_private.interfaces.LoadError.OTHER_ERROR; int OTHER_ERROR = org.chromium.weblayer_private.interfaces.LoadError.OTHER_ERROR;
/**
* Safe browsing error.
*
* @since 89
*/
int SAFE_BROWSING_ERROR =
org.chromium.weblayer_private.interfaces.LoadError.SAFE_BROWSING_ERROR;
} }
...@@ -82,7 +82,8 @@ class Navigation { ...@@ -82,7 +82,8 @@ class Navigation {
kHttpServerError = 2, // Server responded with 5xx status code. kHttpServerError = 2, // Server responded with 5xx status code.
kSSLError = 3, // Certificate error. kSSLError = 3, // Certificate error.
kConnectivityError = 4, // Problem connecting to server. kConnectivityError = 4, // Problem connecting to server.
kOtherError = 5, // An error not listed above occurred. kOtherError = 5, // An error not listed above or below occurred.
kSafeBrowsingError = 6, // Safe browsing error.
}; };
// Return information about the error, if any, that was encountered while // Return information about the error, if any, that was encountered while
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment