#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include <stddef.h>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_item_warning_data.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service_factory.h"
#include "chrome/browser/safe_browsing/chrome_ping_manager_factory.h"
#include "chrome/browser/safe_browsing/chrome_safe_browsing_blocking_page_factory.h"
#include "chrome/browser/safe_browsing/chrome_ui_manager_delegate.h"
#include "chrome/browser/safe_browsing/chrome_user_population_helper.h"
#include "chrome/browser/safe_browsing/chrome_v4_protocol_config_provider.h"
#include "chrome/browser/safe_browsing/network_context_service.h"
#include "chrome/browser/safe_browsing/network_context_service_factory.h"
#include "chrome/browser/safe_browsing/safe_browsing_metrics_collector_factory.h"
#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager_factory.h"
#include "chrome/browser/safe_browsing/services_delegate.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "components/download/public/common/download_item.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/content/browser/safe_browsing_navigation_observer_manager.h"
#include "components/safe_browsing/content/browser/triggers/trigger_manager.h"
#include "components/safe_browsing/content/browser/ui_manager.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/content/common/file_type_policies.h"
#include "components/safe_browsing/core/browser/db/database_manager.h"
#include "components/safe_browsing/core/browser/ping_manager.h"
#include "components/safe_browsing/core/browser/realtime/policy_engine.h"
#include "components/safe_browsing/core/browser/referrer_chain_provider.h"
#include "components/safe_browsing/core/browser/safe_browsing_metrics_collector.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_policy_handler.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/safebrowsing_constants.h"
#include "components/unified_consent/pref_names.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.h"
#include "services/network/public/cpp/cross_thread_pending_shared_url_loader_factory.h"
#include "services/network/public/cpp/features.h"
#include "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/install_static/install_util.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/safe_browsing/android/safe_browsing_referring_app_bridge_android.h"
#endif
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#include "components/safe_browsing/content/browser/password_protection/password_protection_service.h"
#endif
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "chrome/browser/safe_browsing/hash_realtime_service_factory.h"
#include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/browser_context_helper/browser_context_types.h"
#endif
BrowserThread;
namespace safe_browsing {
using enum ExtendedReportingLevel;
namespace {
const int kReferrerChainUserGestureLimit = …;
#if BUILDFLAG(FULL_SAFE_BROWSING)
void PopulateDownloadWarningActions(download::DownloadItem* download,
ClientSafeBrowsingReportRequest* report) { … }
std::unique_ptr<ClientSafeBrowsingReportRequest> CreateDownloadReport(
download::DownloadItem* download,
ClientSafeBrowsingReportRequest::ReportType report_type,
bool did_proceed,
std::optional<bool> show_download_in_folder) { … }
#endif
void OnGotCookies(
std::unique_ptr<mojo::Remote<network::mojom::CookieManager>> remote,
const std::vector<net::CanonicalCookie>& cookies) { … }
}
base::FilePath SafeBrowsingService::GetCookieFilePathForTesting() { … }
base::FilePath SafeBrowsingService::GetBaseFilename() { … }
bool SafeBrowsingService::IsUserEligibleForESBPromo(Profile* profile) { … }
SafeBrowsingService::SafeBrowsingService()
: … { … }
SafeBrowsingService::~SafeBrowsingService() { … }
void SafeBrowsingService::Initialize() { … }
void SafeBrowsingService::ShutDown() { … }
network::mojom::NetworkContext* SafeBrowsingService::GetNetworkContext(
content::BrowserContext* browser_context) { … }
scoped_refptr<network::SharedURLLoaderFactory>
SafeBrowsingService::GetURLLoaderFactory(
content::BrowserContext* browser_context) { … }
void SafeBrowsingService::FlushNetworkInterfaceForTesting(
content::BrowserContext* browser_context) { … }
const scoped_refptr<SafeBrowsingUIManager>& SafeBrowsingService::ui_manager()
const { … }
const scoped_refptr<SafeBrowsingDatabaseManager>&
SafeBrowsingService::database_manager() const { … }
ReferrerChainProvider*
SafeBrowsingService::GetReferrerChainProviderFromBrowserContext(
content::BrowserContext* browser_context) { … }
#if BUILDFLAG(IS_ANDROID)
ReferringAppInfo SafeBrowsingService::GetReferringAppInfo(
content::WebContents* web_contents) {
return safe_browsing::GetReferringAppInfo(web_contents);
}
#endif
TriggerManager* SafeBrowsingService::trigger_manager() const { … }
PasswordProtectionService* SafeBrowsingService::GetPasswordProtectionService(
Profile* profile) const { … }
std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate>
SafeBrowsingService::CreatePreferenceValidationDelegate(
Profile* profile) const { … }
void SafeBrowsingService::RegisterDelayedAnalysisCallback(
DelayedAnalysisCallback callback) { … }
void SafeBrowsingService::AddDownloadManager(
content::DownloadManager* download_manager) { … }
HashRealTimeService* SafeBrowsingService::GetHashRealTimeService(
Profile* profile) { … }
SafeBrowsingUIManager* SafeBrowsingService::CreateUIManager() { … }
void SafeBrowsingService::RegisterAllDelayedAnalysis() { … }
V4ProtocolConfig SafeBrowsingService::GetV4ProtocolConfig() const { … }
void SafeBrowsingService::SetDatabaseManagerForTest(
SafeBrowsingDatabaseManager* database_manager) { … }
void SafeBrowsingService::Start() { … }
void SafeBrowsingService::Stop(bool shutdown) { … }
void SafeBrowsingService::OnProfileAdded(Profile* profile) { … }
void SafeBrowsingService::OnOffTheRecordProfileCreated(
Profile* off_the_record) { … }
void SafeBrowsingService::OnProfileWillBeDestroyed(Profile* profile) { … }
void SafeBrowsingService::CreateServicesForProfile(Profile* profile) { … }
base::CallbackListSubscription SafeBrowsingService::RegisterStateCallback(
const base::RepeatingClosure& callback) { … }
void SafeBrowsingService::RefreshState() { … }
#if BUILDFLAG(FULL_SAFE_BROWSING)
bool SafeBrowsingService::SendDownloadReport(
download::DownloadItem* download,
ClientSafeBrowsingReportRequest::ReportType report_type,
bool did_proceed,
std::optional<bool> show_download_in_folder) { … }
bool SafeBrowsingService::PersistDownloadReportAndSendOnNextStartup(
download::DownloadItem* download,
ClientSafeBrowsingReportRequest::ReportType report_type,
bool did_proceed,
std::optional<bool> show_download_in_folder) { … }
bool SafeBrowsingService::SendPhishyInteractionsReport(
Profile* profile,
const GURL& url,
const GURL& page_url,
const PhishySiteInteractionMap& phishy_interaction_data) { … }
#endif
bool SafeBrowsingService::MaybeSendNotificationsAcceptedReport(
content::RenderFrameHost* render_frame_host,
Profile* profile,
const GURL& url,
const GURL& page_url,
const GURL& permission_prompt_origin,
base::TimeDelta permission_prompt_display_duration_sec) { … }
void SafeBrowsingService::CreateTriggerManager() { … }
network::mojom::NetworkContextParamsPtr
SafeBrowsingService::CreateNetworkContextParams() { … }
void SafeBrowsingService::RecordStartupCookieMetrics(Profile* profile) { … }
void SafeBrowsingService::FillReferrerChain(
Profile* profile,
content::RenderFrameHost* render_frame_host,
google::protobuf::RepeatedPtrField<ReferrerChainEntry>*
out_referrer_chain) { … }
bool SafeBrowsingService::IsURLAllowlisted(
const GURL& url,
content::RenderFrameHost* primary_main_frame) { … }
class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { … };
SafeBrowsingServiceFactory* GetSafeBrowsingServiceFactory() { … }
}