Commit 1f0bf6ad authored by csharrison's avatar csharrison Committed by Commit Bot

[subresource_filter] Remove "pass-through" mode on throttle

This CL makes sure the safe browsing throttle always has a
database manager that can make checks. For the (extremely rare) case
where the manager is not supported on the platform, checks are
completely synchronously as SAFE.

A follow-up will remove DatabaseManager::CanCheckSubresourceFilter
from safe browsing internals (resolving the TODO here).

This CL changes when a throttle can be created, since we won't
create one unless there is a SafeBrowsing service. Most platforms
should have one though.

TBR=jkarlin@chromium.org

Change-Id: Ic4c2d174af8980d088507976ff903ee0bf9dff16
Reviewed-on: https://chromium-review.googlesource.com/1067152
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560259}
parent c365bd25
...@@ -37,21 +37,6 @@ ...@@ -37,21 +37,6 @@
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSubresourceFilterClient); DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSubresourceFilterClient);
namespace {
scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> GetDatabaseManager() {
safe_browsing::SafeBrowsingService* safe_browsing_service =
g_browser_process->safe_browsing_service();
bool has_supported_manager =
safe_browsing_service &&
safe_browsing_service->database_manager()->IsSupported() &&
safe_browsing_service->database_manager()->CanCheckSubresourceFilter();
return has_supported_manager ? safe_browsing_service->database_manager()
: nullptr;
}
} // namespace
ChromeSubresourceFilterClient::ChromeSubresourceFilterClient( ChromeSubresourceFilterClient::ChromeSubresourceFilterClient(
content::WebContents* web_contents) content::WebContents* web_contents)
: web_contents_(web_contents) { : web_contents_(web_contents) {
...@@ -69,14 +54,16 @@ ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() {} ...@@ -69,14 +54,16 @@ ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() {}
void ChromeSubresourceFilterClient::MaybeAppendNavigationThrottles( void ChromeSubresourceFilterClient::MaybeAppendNavigationThrottles(
content::NavigationHandle* navigation_handle, content::NavigationHandle* navigation_handle,
std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) {
if (navigation_handle->IsInMainFrame()) { safe_browsing::SafeBrowsingService* safe_browsing_service =
g_browser_process->safe_browsing_service();
if (navigation_handle->IsInMainFrame() && safe_browsing_service) {
throttles->push_back( throttles->push_back(
std::make_unique<subresource_filter:: std::make_unique<subresource_filter::
SubresourceFilterSafeBrowsingActivationThrottle>( SubresourceFilterSafeBrowsingActivationThrottle>(
navigation_handle, this, navigation_handle, this,
content::BrowserThread::GetTaskRunnerForThread( content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::IO), content::BrowserThread::IO),
GetDatabaseManager())); safe_browsing_service->database_manager()));
} }
auto* driver_factory = auto* driver_factory =
......
...@@ -59,21 +59,17 @@ SubresourceFilterSafeBrowsingActivationThrottle:: ...@@ -59,21 +59,17 @@ SubresourceFilterSafeBrowsingActivationThrottle::
database_manager) database_manager)
: NavigationThrottle(handle), : NavigationThrottle(handle),
io_task_runner_(std::move(io_task_runner)), io_task_runner_(std::move(io_task_runner)),
// The throttle can be created without a valid database manager. If so, it database_client_(new SubresourceFilterSafeBrowsingClient(
// becomes a pass-through throttle and should never defer. std::move(database_manager),
database_client_(database_manager AsWeakPtr(),
? new SubresourceFilterSafeBrowsingClient( io_task_runner_,
std::move(database_manager), base::ThreadTaskRunnerHandle::Get()),
AsWeakPtr(),
io_task_runner_,
base::ThreadTaskRunnerHandle::Get())
: nullptr,
base::OnTaskRunnerDeleter(io_task_runner_)), base::OnTaskRunnerDeleter(io_task_runner_)),
client_(client) { client_(client) {
DCHECK(handle->IsInMainFrame()); DCHECK(handle->IsInMainFrame());
CheckCurrentUrl(); CheckCurrentUrl();
DCHECK(!database_client_ || !check_results_.empty()); DCHECK(!check_results_.empty());
} }
SubresourceFilterSafeBrowsingActivationThrottle:: SubresourceFilterSafeBrowsingActivationThrottle::
...@@ -124,15 +120,13 @@ SubresourceFilterSafeBrowsingActivationThrottle:: ...@@ -124,15 +120,13 @@ SubresourceFilterSafeBrowsingActivationThrottle::
content::NavigationThrottle::ThrottleCheckResult content::NavigationThrottle::ThrottleCheckResult
SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() { SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() {
CheckCurrentUrl(); CheckCurrentUrl();
DCHECK(!database_client_ || !check_results_.empty());
return PROCEED; return PROCEED;
} }
content::NavigationThrottle::ThrottleCheckResult content::NavigationThrottle::ThrottleCheckResult
SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() { SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() {
DCHECK(!database_client_ || !check_results_.empty());
// No need to defer the navigation if the check already happened. // No need to defer the navigation if the check already happened.
if (!database_client_ || HasFinishedAllSafeBrowsingChecks()) { if (HasFinishedAllSafeBrowsingChecks()) {
NotifyResult(); NotifyResult();
return PROCEED; return PROCEED;
} }
...@@ -169,8 +163,7 @@ void SubresourceFilterSafeBrowsingActivationThrottle::OnCheckUrlResultOnUI( ...@@ -169,8 +163,7 @@ void SubresourceFilterSafeBrowsingActivationThrottle::OnCheckUrlResultOnUI(
} }
void SubresourceFilterSafeBrowsingActivationThrottle::CheckCurrentUrl() { void SubresourceFilterSafeBrowsingActivationThrottle::CheckCurrentUrl() {
if (!database_client_) DCHECK(database_client_);
return;
check_start_times_.push_back(base::TimeTicks::Now()); check_start_times_.push_back(base::TimeTicks::Now());
check_results_.emplace_back(); check_results_.emplace_back();
size_t id = check_results_.size() - 1; size_t id = check_results_.size() - 1;
...@@ -184,20 +177,18 @@ void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() { ...@@ -184,20 +177,18 @@ void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"),
"SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult"); "SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult");
// Compute the matched list and notify observers of the check result. // Compute the matched list and notify observers of the check result.
DCHECK(!database_client_ || !check_results_.empty()); DCHECK(!check_results_.empty());
ActivationList matched_list = ActivationList::NONE; ActivationList matched_list = ActivationList::NONE;
bool warning = false; bool warning = false;
if (!check_results_.empty()) { const auto& check_result = check_results_.back();
const auto& check_result = check_results_.back(); DCHECK(check_result.finished);
DCHECK(check_result.finished); matched_list = GetListForThreatTypeAndMetadata(
matched_list = GetListForThreatTypeAndMetadata( check_result.threat_type, check_result.threat_metadata, &warning);
check_result.threat_type, check_result.threat_metadata, &warning); SubresourceFilterObserverManager::FromWebContents(
SubresourceFilterObserverManager::FromWebContents( navigation_handle()->GetWebContents())
navigation_handle()->GetWebContents()) ->NotifySafeBrowsingCheckComplete(navigation_handle(),
->NotifySafeBrowsingCheckComplete(navigation_handle(), check_result.threat_type,
check_result.threat_type, check_result.threat_metadata);
check_result.threat_metadata);
}
Configuration matched_configuration; Configuration matched_configuration;
ActivationDecision activation_decision = ActivationDecision::UNKNOWN; ActivationDecision activation_decision = ActivationDecision::UNKNOWN;
......
...@@ -337,9 +337,6 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest ...@@ -337,9 +337,6 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
fake_safe_browsing_database_->RemoveAllBlacklistedUrls(); fake_safe_browsing_database_->RemoveAllBlacklistedUrls();
} }
// With a null database the throttle becomes pass-through.
void UsePassThroughThrottle() { fake_safe_browsing_database_ = nullptr; }
void RunUntilIdle() { void RunUntilIdle() {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
test_io_task_runner_->RunUntilIdle(); test_io_task_runner_->RunUntilIdle();
...@@ -473,26 +470,6 @@ class SubresourceFilterSafeBrowsingActivationThrottleScopeTest ...@@ -473,26 +470,6 @@ class SubresourceFilterSafeBrowsingActivationThrottleScopeTest
SubresourceFilterSafeBrowsingActivationThrottleScopeTest); SubresourceFilterSafeBrowsingActivationThrottleScopeTest);
}; };
TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
PassThroughThrottle) {
UsePassThroughThrottle();
SimulateNavigateAndCommit({GURL(kURL), GURL(kRedirectURL)}, main_rfh());
EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET,
*observer()->GetPageActivationForLastCommittedLoad());
scoped_configuration()->ResetConfiguration(
Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES));
SimulateNavigateAndCommit({GURL(kURL), GURL(kRedirectURL)}, main_rfh());
EXPECT_EQ(ActivationDecision::ACTIVATED,
*observer()->GetPageActivationForLastCommittedLoad());
scoped_configuration()->ResetConfiguration(
Configuration(ActivationLevel::ENABLED, ActivationScope::NO_SITES));
SimulateNavigateAndCommit({GURL(kURL), GURL(kRedirectURL)}, main_rfh());
EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET,
*observer()->GetPageActivationForLastCommittedLoad());
}
TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, NoConfigs) { TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, NoConfigs) {
scoped_configuration()->ResetConfiguration(std::vector<Configuration>()); scoped_configuration()->ResetConfiguration(std::vector<Configuration>());
SimulateNavigateAndCommit({GURL(kURL)}, main_rfh()); SimulateNavigateAndCommit({GURL(kURL)}, main_rfh());
......
...@@ -37,7 +37,9 @@ SubresourceFilterSafeBrowsingClient::SubresourceFilterSafeBrowsingClient( ...@@ -37,7 +37,9 @@ SubresourceFilterSafeBrowsingClient::SubresourceFilterSafeBrowsingClient(
: database_manager_(std::move(database_manager)), : database_manager_(std::move(database_manager)),
throttle_(std::move(throttle)), throttle_(std::move(throttle)),
io_task_runner_(std::move(io_task_runner)), io_task_runner_(std::move(io_task_runner)),
throttle_task_runner_(std::move(throttle_task_runner)) {} throttle_task_runner_(std::move(throttle_task_runner)) {
DCHECK(database_manager_);
}
SubresourceFilterSafeBrowsingClient::~SubresourceFilterSafeBrowsingClient() {} SubresourceFilterSafeBrowsingClient::~SubresourceFilterSafeBrowsingClient() {}
......
...@@ -46,7 +46,13 @@ SubresourceFilterSafeBrowsingClientRequest:: ...@@ -46,7 +46,13 @@ SubresourceFilterSafeBrowsingClientRequest::
void SubresourceFilterSafeBrowsingClientRequest::Start(const GURL& url) { void SubresourceFilterSafeBrowsingClientRequest::Start(const GURL& url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
start_time_ = base::TimeTicks::Now(); start_time_ = base::TimeTicks::Now();
// Just return SAFE if the database is not supported.
// TODO(csharrison): Remove CanCheckSubresourceFilter now that V4 has fully
// shipped.
bool synchronous_finish = bool synchronous_finish =
!database_manager_->IsSupported() ||
!database_manager_->CanCheckSubresourceFilter() ||
database_manager_->CheckUrlForSubresourceFilter(url, this); database_manager_->CheckUrlForSubresourceFilter(url, this);
if (synchronous_finish) { if (synchronous_finish) {
request_completed_ = true; request_completed_ = true;
......
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