Commit 1a4e1171 authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

Build SafeBrowsingUrlCheckerImpl on iOS

This builds SafeBrowsingUrlCheckerImpl on iOS as part of components_unittests.

The remaining content/ dependencies in SafeBrowsingUrlCheckerImpl are all
in methods related to real-time checks. This CL moves the implementations of
these content-dependent methods to a content-specific file, and defines stubs
for these methods on iOS, where real-time checks won't be initially supported.

Change-Id: I5f83e99b586ff4c62876248d8933b2671c1eceb8
Bug: 1028755
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033332Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Ali Juma <ajuma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737774}
parent 8c091c44
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/safe_browsing/core/browser/safe_browsing_url_checker_impl.h"
#include "base/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/task/post_task.h"
#include "components/safe_browsing/content/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/common/safebrowsing_constants.h"
#include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/realtime/policy_engine.h"
#include "components/safe_browsing/core/realtime/url_lookup_service.h"
#include "components/safe_browsing/core/verdict_cache_manager.h"
#include "components/safe_browsing/core/web_ui/constants.h"
namespace safe_browsing {
bool SafeBrowsingUrlCheckerImpl::CanPerformFullURLLookup(const GURL& url) {
if (!real_time_lookup_enabled_)
return false;
if (!RealTimePolicyEngine::CanPerformFullURLLookupForResourceType(
resource_type_))
return false;
auto* rt_lookup_service = database_manager_->GetRealTimeUrlLookupService();
if (!rt_lookup_service || !rt_lookup_service->CanCheckUrl(url))
return false;
bool in_backoff = rt_lookup_service->IsInBackoffMode();
UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.RT.Backoff.State", in_backoff);
return !in_backoff;
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest(
std::unique_ptr<RTLookupRequest> request) {
DCHECK(CurrentlyOnThread(ThreadID::IO));
// The following is to log this RTLookupRequest on any open
// chrome://safe-browsing pages.
base::PostTaskAndReplyWithResult(
FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupPings,
base::Unretained(WebUIInfoSingleton::GetInstance()),
*request),
base::BindOnce(&SafeBrowsingUrlCheckerImpl::SetWebUIToken,
weak_factory_.GetWeakPtr()));
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse(
std::unique_ptr<RTLookupResponse> response) {
DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_EQ(ResourceType::kMainFrame, resource_type_);
if (url_web_ui_token_ != -1) {
// The following is to log this RTLookupResponse on any open
// chrome://safe-browsing pages.
base::PostTask(
FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupResponses,
base::Unretained(WebUIInfoSingleton::GetInstance()),
url_web_ui_token_, *response));
}
const GURL& url = urls_[next_index_].url;
SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE;
if (response && (response->threat_info_size() > 0)) {
base::PostTask(FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&VerdictCacheManager::CacheRealTimeUrlVerdict,
cache_manager_on_ui_, url, *response,
base::Time::Now()));
// TODO(crbug.com/1033692): Only take the first threat info into account
// because threat infos are returned in decreasing order of severity.
// Consider extend it to support multiple threat types.
if (response->threat_info(0).verdict_type() ==
RTLookupResponse::ThreatInfo::DANGEROUS) {
sb_threat_type = RealTimeUrlLookupService::GetSBThreatTypeForRTThreatType(
response->threat_info(0).threat_type());
}
}
OnUrlResult(url, sb_threat_type, ThreatMetadata());
}
} // namespace safe_browsing
......@@ -12,7 +12,6 @@ jumbo_source_set("browser") {
"url_checker_delegate.h",
]
deps = [
"//components/safe_browsing/content/web_ui:web_ui",
"//components/safe_browsing/core:csd_proto",
"//components/safe_browsing/core:features",
"//components/safe_browsing/core:realtimeapi_proto",
......@@ -21,28 +20,40 @@ jumbo_source_set("browser") {
"//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:database_manager",
"//components/safe_browsing/core/db:util",
"//components/safe_browsing/core/realtime:policy_engine",
"//components/safe_browsing/core/realtime:url_lookup_service",
"//components/safe_browsing/core/web_ui:constants",
"//components/security_interstitials/core:unsafe_resource",
"//components/signin/public/identity_manager",
"//content/public/browser:browser",
"//net:extras",
"//services/network/public/cpp",
]
if (is_ios) {
sources += [ "//components/safe_browsing/ios/browser/safe_browsing_url_checker_impl_ios.cc" ]
} else {
sources += [ "//components/safe_browsing/content/browser/safe_browsing_url_checker_impl_content.cc" ]
deps += [
"//components/safe_browsing/content/web_ui",
"//components/safe_browsing/core/realtime:policy_engine",
]
}
}
source_set("network_context") {
sources = [
"safe_browsing_network_context.cc",
"safe_browsing_network_context.h",
]
# TODO(crbug.com/1028755): Remove this condition once there are no longer any
# dependencies on content/.
if (!is_ios) {
source_set("network_context") {
sources = [
"safe_browsing_network_context.cc",
"safe_browsing_network_context.h",
]
deps = [
"//components/safe_browsing/core/common:common",
"//components/safe_browsing/core/common:thread_utils",
"//content/public/browser:browser",
"//net:extras",
]
deps = [
"//components/safe_browsing/core/common:common",
"//components/safe_browsing/core/common:thread_utils",
"//content/public/browser:browser",
"//net:extras",
]
}
}
source_set("referrer_chain_provider") {
......
......@@ -10,7 +10,6 @@
#include "base/metrics/histogram_macros_local.h"
#include "base/task/post_task.h"
#include "base/trace_event/trace_event.h"
#include "components/safe_browsing/content/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/browser/url_checker_delegate.h"
#include "components/safe_browsing/core/common/safebrowsing_constants.h"
#include "components/safe_browsing/core/common/thread_utils.h"
......@@ -20,9 +19,6 @@
#include "components/safe_browsing/core/web_ui/constants.h"
#include "components/security_interstitials/core/unsafe_resource.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
......@@ -385,23 +381,6 @@ void SafeBrowsingUrlCheckerImpl::BlockAndProcessUrls(bool showed_interstitial) {
}
}
bool SafeBrowsingUrlCheckerImpl::CanPerformFullURLLookup(const GURL& url) {
if (!real_time_lookup_enabled_)
return false;
if (!RealTimePolicyEngine::CanPerformFullURLLookupForResourceType(
resource_type_))
return false;
auto* rt_lookup_service = database_manager_->GetRealTimeUrlLookupService();
if (!rt_lookup_service || !rt_lookup_service->CanCheckUrl(url))
return false;
bool in_backoff = rt_lookup_service->IsInBackoffMode();
UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.RT.Backoff.State", in_backoff);
return !in_backoff;
}
void SafeBrowsingUrlCheckerImpl::OnBlockingPageComplete(
bool proceed,
bool showed_interstitial) {
......@@ -528,57 +507,6 @@ void SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO(
identity_manager_on_ui_);
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest(
std::unique_ptr<RTLookupRequest> request) {
DCHECK(CurrentlyOnThread(ThreadID::IO));
// The following is to log this RTLookupRequest on any open
// chrome://safe-browsing pages.
base::PostTaskAndReplyWithResult(
FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupPings,
base::Unretained(WebUIInfoSingleton::GetInstance()),
*request),
base::BindOnce(&SafeBrowsingUrlCheckerImpl::SetWebUIToken,
weak_factory_.GetWeakPtr()));
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse(
std::unique_ptr<RTLookupResponse> response) {
DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_EQ(ResourceType::kMainFrame, resource_type_);
if (url_web_ui_token_ != -1) {
// The following is to log this RTLookupResponse on any open
// chrome://safe-browsing pages.
base::PostTask(
FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupResponses,
base::Unretained(WebUIInfoSingleton::GetInstance()),
url_web_ui_token_, *response));
}
const GURL& url = urls_[next_index_].url;
SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE;
if (response && (response->threat_info_size() > 0)) {
base::PostTask(FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&VerdictCacheManager::CacheRealTimeUrlVerdict,
cache_manager_on_ui_, url, *response,
base::Time::Now()));
// TODO(crbug.com/1033692): Only take the first threat info into account
// because threat infos are returned in decreasing order of severity.
// Consider extend it to support multiple threat types.
if (response->threat_info(0).verdict_type() ==
RTLookupResponse::ThreatInfo::DANGEROUS) {
sb_threat_type = RealTimeUrlLookupService::GetSBThreatTypeForRTThreatType(
response->threat_info(0).threat_type());
}
}
OnUrlResult(url, sb_threat_type, ThreatMetadata());
}
void SafeBrowsingUrlCheckerImpl::SetWebUIToken(int token) {
url_web_ui_token_ = token;
}
......
......@@ -14,7 +14,6 @@
#include "components/safe_browsing/core/common/safe_browsing_url_checker.mojom.h"
#include "components/safe_browsing/core/db/database_manager.h"
#include "components/safe_browsing/core/proto/realtimeapi.pb.h"
#include "content/public/common/resource_type.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/http/http_request_headers.h"
#include "url/gurl.h"
......
......@@ -9,6 +9,7 @@ source_set("unit_tests") {
deps = [
"//components/safe_browsing/core:ping_manager_unittest",
"//components/safe_browsing/core:verdict_cache_manager_unittest",
"//components/safe_browsing/core/browser",
"//components/safe_browsing/core/common",
"//components/safe_browsing/core/common:unit_tests",
"//components/safe_browsing/core/db:unit_tests_local_db",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/safe_browsing/core/browser/safe_browsing_url_checker_impl.h"
namespace safe_browsing {
bool SafeBrowsingUrlCheckerImpl::CanPerformFullURLLookup(const GURL& url) {
// TODO(crbug.com/1028755): Support real-time checks on iOS.
return false;
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest(
std::unique_ptr<RTLookupRequest> request) {
NOTREACHED();
}
void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse(
std::unique_ptr<RTLookupResponse> response) {
NOTREACHED();
}
} // namespace safe_browsing
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