#include "components/safe_browsing/core/browser/safe_browsing_url_checker_impl.h"
#include <memory>
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/rand_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "components/safe_browsing/core/browser/database_manager_mechanism.h"
#include "components/safe_browsing/core/browser/db/database_manager.h"
#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include "components/safe_browsing/core/browser/hash_realtime_mechanism.h"
#include "components/safe_browsing/core/browser/realtime/policy_engine.h"
#include "components/safe_browsing/core/browser/realtime/url_lookup_service_base.h"
#include "components/safe_browsing/core/browser/safe_browsing_lookup_mechanism.h"
#include "components/safe_browsing/core/browser/url_checker_delegate.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/common/scheme_logger.h"
#include "components/safe_browsing/core/common/web_ui_constants.h"
#include "components/security_interstitials/core/unsafe_resource.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/cpp/request_destination.h"
UnsafeResource;
namespace safe_browsing {
CompleteCheckResult;
HashRealTimeSelection;
namespace {
enum class CheckUrlAction { … };
void RecordCheckUrlTimeout(bool timed_out) { … }
void RecordCheckUrlAction(CheckUrlAction action) { … }
std::string GetPerformedCheckSuffix(
SafeBrowsingUrlCheckerImpl::PerformedCheck performed_check) { … }
void MaybeRecordFirstRequestMetrics(SBThreatType threat_type,
std::optional<ThreatSource> threat_source,
bool timed_out) { … }
}
SafeBrowsingUrlCheckerImpl::Notifier::Notifier(CheckUrlCallback callback)
: … { … }
SafeBrowsingUrlCheckerImpl::Notifier::Notifier(
NativeCheckUrlCallback native_callback)
: … { … }
SafeBrowsingUrlCheckerImpl::Notifier::~Notifier() = default;
SafeBrowsingUrlCheckerImpl::Notifier::Notifier(Notifier&& other) = default;
SafeBrowsingUrlCheckerImpl::Notifier&
SafeBrowsingUrlCheckerImpl::Notifier::operator=(Notifier&& other) = default;
void SafeBrowsingUrlCheckerImpl::Notifier::OnCompleteCheck(
bool proceed,
bool showed_interstitial,
bool has_post_commit_interstitial_skipped,
PerformedCheck performed_check) { … }
SafeBrowsingUrlCheckerImpl::UrlInfo::UrlInfo(const GURL& in_url,
const std::string& in_method,
Notifier in_notifier)
: … { … }
SafeBrowsingUrlCheckerImpl::UrlInfo::UrlInfo(UrlInfo&& other) = default;
SafeBrowsingUrlCheckerImpl::UrlInfo::~UrlInfo() = default;
SafeBrowsingUrlCheckerImpl::KickOffLookupMechanismResult::
KickOffLookupMechanismResult(
SafeBrowsingLookupMechanism::StartCheckResult start_check_result,
PerformedCheck performed_check)
: … { … }
SafeBrowsingUrlCheckerImpl::KickOffLookupMechanismResult::
~KickOffLookupMechanismResult() = default;
SafeBrowsingUrlCheckerImpl::SafeBrowsingUrlCheckerImpl(
const net::HttpRequestHeaders& headers,
int load_flags,
bool has_user_gesture,
scoped_refptr<UrlCheckerDelegate> url_checker_delegate,
const base::RepeatingCallback<content::WebContents*()>& web_contents_getter,
base::WeakPtr<web::WebState> weak_web_state,
UnsafeResource::RenderProcessId render_process_id,
const UnsafeResource::RenderFrameToken& render_frame_token,
UnsafeResource::FrameTreeNodeId frame_tree_node_id,
std::optional<int64_t> navigation_id,
bool url_real_time_lookup_enabled,
bool can_check_db,
bool can_check_high_confidence_allowlist,
std::string url_lookup_service_metric_suffix,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
base::WeakPtr<RealTimeUrlLookupServiceBase> url_lookup_service_on_ui,
base::WeakPtr<HashRealTimeService> hash_realtime_service_on_ui,
HashRealTimeSelection hash_realtime_selection,
bool is_async_check,
SessionID tab_id)
: … { … }
SafeBrowsingUrlCheckerImpl::~SafeBrowsingUrlCheckerImpl() { … }
void SafeBrowsingUrlCheckerImpl::CheckUrl(const GURL& url,
const std::string& method,
CheckUrlCallback callback) { … }
void SafeBrowsingUrlCheckerImpl::CheckUrl(const GURL& url,
const std::string& method,
NativeCheckUrlCallback callback) { … }
base::WeakPtr<SafeBrowsingUrlCheckerImpl>
SafeBrowsingUrlCheckerImpl::WeakPtr() { … }
UnsafeResource SafeBrowsingUrlCheckerImpl::MakeUnsafeResource(
const GURL& url,
SBThreatType threat_type,
const ThreatMetadata& metadata,
ThreatSource threat_source,
std::unique_ptr<RTLookupResponse> rt_lookup_response,
PerformedCheck performed_check) { … }
void SafeBrowsingUrlCheckerImpl::OnUrlResultAndMaybeDeleteSelf(
PerformedCheck performed_check,
bool timed_out,
std::optional<std::unique_ptr<CompleteCheckResult>> result) { … }
void SafeBrowsingUrlCheckerImpl::OnUrlResultInternalAndMaybeDeleteSelf(
const GURL& url,
SBThreatType threat_type,
const ThreatMetadata& metadata,
std::optional<ThreatSource> threat_source,
std::unique_ptr<RTLookupResponse> rt_lookup_response,
bool timed_out,
PerformedCheck performed_check) { … }
void SafeBrowsingUrlCheckerImpl::CheckUrlImplAndMaybeDeleteSelf(
const GURL& url,
const std::string& method,
Notifier notifier) { … }
void SafeBrowsingUrlCheckerImpl::ProcessUrlsAndMaybeDeleteSelf() { … }
std::unique_ptr<SafeBrowsingLookupMechanism>
SafeBrowsingUrlCheckerImpl::GetHashRealTimeLookupMechanism(
const GURL& url,
bool can_use_hash_real_time_service,
bool can_use_hash_real_time_db_manager) { … }
SafeBrowsingUrlCheckerImpl::KickOffLookupMechanismResult
SafeBrowsingUrlCheckerImpl::KickOffLookupMechanism(const GURL& url) { … }
void SafeBrowsingUrlCheckerImpl::BlockAndProcessUrlsAndMaybeDeleteSelf(
bool showed_interstitial,
bool has_post_commit_interstitial_skipped,
PerformedCheck performed_check) { … }
void SafeBrowsingUrlCheckerImpl::OnBlockingPageCompleteAndMaybeDeleteSelf(
PerformedCheck performed_check,
UnsafeResource::UrlCheckResult result) { … }
SBThreatType SafeBrowsingUrlCheckerImpl::CheckWebUIUrls(const GURL& url) { … }
bool SafeBrowsingUrlCheckerImpl::RunNextCallbackAndMaybeDeleteSelf(
bool proceed,
bool showed_interstitial,
bool has_post_commit_interstitial_skipped,
PerformedCheck performed_check) { … }
bool SafeBrowsingUrlCheckerImpl::CanPerformFullURLLookup(const GURL& url) { … }
}