#include "chrome/browser/safe_browsing/download_protection/deep_scanning_request.h"
#include <memory>
#include <optional>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/bubble/download_bubble_ui_controller.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_item_warning_data.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/offline_item_utils.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_features.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/file_analysis_request.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/file_opening_job.h"
#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/download_protection/download_request_maker.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/download/bubble/download_toolbar_button_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/safe_browsing/deep_scanning_failure_modal_dialog.h"
#include "chrome/common/pref_names.h"
#include "components/download/public/common/download_item.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/policy/core/common/cloud/dm_token.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/url_matcher/url_matcher.h"
#include "content/public/browser/download_item_utils.h"
DeepScanTrigger;
namespace safe_browsing {
namespace {
DownloadCheckResult GetHighestPrecedenceResult(DownloadCheckResult result_1,
DownloadCheckResult result_2) { … }
void ResponseToDownloadCheckResult(
const enterprise_connectors::ContentAnalysisResponse& response,
DownloadCheckResult* download_result) { … }
EventResult GetEventResult(download::DownloadDangerType danger_type,
download::DownloadItem* item) { … }
EventResult GetEventResult(DownloadCheckResult download_result,
Profile* profile) { … }
std::string GetTriggerName(DeepScanTrigger trigger) { … }
enterprise_connectors::ContentAnalysisAcknowledgement::FinalAction
GetFinalAction(EventResult event_result) { … }
void PromptForPassword(download::DownloadItem* item) { … }
void LogDeepScanResult(DownloadCheckResult download_result,
DeepScanTrigger trigger,
bool is_encrypted_archive) { … }
bool HasDecryptionFailedResult(
enterprise_connectors::ContentAnalysisResponse response) { … }
bool EnterpriseResultIsFailure(BinaryUploadService::Result result,
bool block_large_files,
bool block_password_protected_files) { … }
void RecordEnterpriseScan(std::unique_ptr<FileAnalysisRequest> request,
BinaryUploadService::Result result) { … }
}
std::optional<enterprise_connectors::AnalysisSettings>
DeepScanningRequest::ShouldUploadBinary(download::DownloadItem* item) { … }
DeepScanningRequest::DeepScanningRequest(
download::DownloadItem* item,
DeepScanTrigger trigger,
DownloadCheckResult pre_scan_download_check_result,
CheckDownloadRepeatingCallback callback,
DownloadProtectionService* download_service,
enterprise_connectors::AnalysisSettings settings,
base::optional_ref<const std::string> password)
: … { … }
DeepScanningRequest::DeepScanningRequest(
download::DownloadItem* item,
DownloadCheckResult pre_scan_download_check_result,
CheckDownloadRepeatingCallback callback,
DownloadProtectionService* download_service,
enterprise_connectors::AnalysisSettings settings,
base::flat_map<base::FilePath, base::FilePath> save_package_files)
: … { … }
DeepScanningRequest::~DeepScanningRequest() { … }
void DeepScanningRequest::AddObserver(Observer* observer) { … }
void DeepScanningRequest::RemoveObserver(Observer* observer) { … }
void DeepScanningRequest::Start() { … }
void DeepScanningRequest::StartSingleFileScan() { … }
void DeepScanningRequest::StartSavePackageScan() { … }
void DeepScanningRequest::PopulateRequest(FileAnalysisRequest* request,
Profile* profile,
const base::FilePath& path) { … }
void DeepScanningRequest::PrepareClientDownloadRequest(
const base::FilePath& current_path,
std::unique_ptr<FileAnalysisRequest> request) { … }
void DeepScanningRequest::OnGetPackageFileRequestData(
const base::FilePath& final_path,
const base::FilePath& current_path,
std::unique_ptr<FileAnalysisRequest> request,
BinaryUploadService::Result result,
BinaryUploadService::Request::Data data) { … }
void DeepScanningRequest::OnGetFileRequestData(
const base::FilePath& file_path,
std::unique_ptr<FileAnalysisRequest> request,
BinaryUploadService::Result result,
BinaryUploadService::Request::Data data) { … }
void DeepScanningRequest::OnDownloadRequestReady(
const base::FilePath& current_path,
std::unique_ptr<FileAnalysisRequest> deep_scan_request,
std::unique_ptr<ClientDownloadRequest> download_request) { … }
void DeepScanningRequest::OnScanComplete(
const base::FilePath& current_path,
BinaryUploadService::Result result,
enterprise_connectors::ContentAnalysisResponse response) { … }
void DeepScanningRequest::OnConsumerScanComplete(
const base::FilePath& current_path,
BinaryUploadService::Result result,
enterprise_connectors::ContentAnalysisResponse response) { … }
void DeepScanningRequest::OnEnterpriseScanComplete(
const base::FilePath& current_path,
BinaryUploadService::Result result,
enterprise_connectors::ContentAnalysisResponse response) { … }
void DeepScanningRequest::OnDownloadUpdated(download::DownloadItem* download) { … }
void DeepScanningRequest::OnDownloadDestroyed(
download::DownloadItem* download) { … }
void DeepScanningRequest::MaybeFinishRequest(DownloadCheckResult result) { … }
void DeepScanningRequest::FinishRequest(DownloadCheckResult result) { … }
bool DeepScanningRequest::ReportOnlyScan() { … }
void DeepScanningRequest::AcknowledgeRequest(EventResult event_result) { … }
bool DeepScanningRequest::IsConsumerTriggered() const { … }
bool DeepScanningRequest::IsEnterpriseTriggered() const { … }
bool DeepScanningRequest::MaybeShowDeepScanFailureModalDialog(
base::OnceClosure accept_callback,
base::OnceClosure cancel_callback,
base::OnceClosure close_callback,
base::OnceClosure open_now_callback) { … }
bool DeepScanningRequest::ShouldTerminateEarly(
BinaryUploadService::Result result) { … }
void DeepScanningRequest::OpenDownload() { … }
}