From 03257a7ccad428cf6e4947b1cc1a427d884e30d9 Mon Sep 17 00:00:00 2001 From: Pranjal Date: Mon, 11 Dec 2017 07:47:51 -0800 Subject: [PATCH] Enable safe_browsing_api for muon --- atom/browser/BUILD.gn | 17 + atom/browser/api/atom_api_download_item.cc | 14 +- atom/browser/api/atom_api_download_item.h | 1 + .../browser/atom_download_manager_delegate.cc | 446 +++++++++++++++++- atom/browser/atom_download_manager_delegate.h | 76 ++- .../atom_resource_dispatcher_host_delegate.cc | 93 +++- .../atom_resource_dispatcher_host_delegate.h | 25 + brave/browser/brave_browser_context.cc | 3 +- brave/browser/brave_content_browser_client.cc | 5 +- .../brave_password_manager_client.cc | 5 +- .../brave_password_manager_client.h | 5 +- chromium_src/BUILD.gn | 130 ++++- .../browser/prerender/prerender_contents.cc | 7 + .../safe_browsing/safe_browsing_service.cc | 20 - muon/browser/muon_browser_process_impl.cc | 49 +- muon/browser/muon_browser_process_impl.h | 16 + patches/master_patch.patch | 407 ++++++++++++++++ 17 files changed, 1260 insertions(+), 59 deletions(-) delete mode 100644 chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index 0d7b8d07cd..06eb5dc0c8 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -22,22 +22,39 @@ source_set("browser") { ] deps = [ + "../../chromium_src/chrome/browser/prerender", "//electron:common", "//electron/muon/app", # @todo(bridiver) fix circular dep # "//electron/muon/browser", "//base", + "//chrome/browser:resource_prefetch_predictor_proto", "//chrome/common:constants", "//storage/browser", "//storage/common", "//components/prefs", "//components/metrics", + "//components/safe_browsing/common:safe_browsing_prefs", ":importer", "//electron/vendor/ad-block/muon:ad_block", "//electron/vendor/tracking-protection/muon:tp_node_addon", ] sources = [ + "//chrome/browser/download/download_completion_blocker.cc", + "//chrome/browser/download/download_completion_blocker.h", + "//chrome/browser/loader/safe_browsing_resource_throttle.h", + "//chrome/browser/loader/safe_browsing_resource_throttle.cc", + "//chrome/browser/safe_browsing/url_checker_delegate_impl.cc", + "//chrome/browser/safe_browsing/url_checker_delegate_impl.h", + "//chrome/browser/download/download_item_model.cc", + "//chrome/browser/download/download_item_model.h", + "//chrome/browser/download/download_stats.cc", + "//chrome/browser/download/download_stats.h", + "//chrome/browser/download/download_target_determiner.cc", + "//chrome/browser/download/download_target_determiner.h", + "//chrome/browser/download/download_target_info.cc", + "//chrome/browser/download/download_target_info.h", "api/atom_api_app.cc", "api/atom_api_app.h", "api/atom_api_autofill.cc", diff --git a/atom/browser/api/atom_api_download_item.cc b/atom/browser/api/atom_api_download_item.cc index 569af620dd..090f49684b 100644 --- a/atom/browser/api/atom_api_download_item.cc +++ b/atom/browser/api/atom_api_download_item.cc @@ -12,9 +12,12 @@ #include "atom/common/native_mate_converters/gurl_converter.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" +#include "content/browser/download/download_item_impl.h" +#include "content/public/browser/download_danger_type.h" #include "native_mate/dictionary.h" #include "net/base/filename_util.h" + #include "atom/common/node_includes.h" namespace mate { @@ -78,9 +81,10 @@ DownloadItem::~DownloadItem() { } void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) { - if (download_item_->IsDone()) { - Emit("done", item->GetState()); - + if (download_item_->IsDangerous()) { + Emit("done", 4, item->IsDangerous()); + } else if (download_item_->IsDone()) { + Emit("done", item->GetState(), false); // Destroy the item once item is downloaded. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, GetDestroyClosure()); @@ -164,6 +168,10 @@ bool DownloadItem::IsDone() const { return download_item_->IsDone(); } +bool DownloadItem::IsDangerous() const { + return download_item_->IsDangerous(); +} + void DownloadItem::SetSavePath(const base::FilePath& path) { save_path_ = path; } diff --git a/atom/browser/api/atom_api_download_item.h b/atom/browser/api/atom_api_download_item.h index f93cf22063..edc82a7ee2 100644 --- a/atom/browser/api/atom_api_download_item.h +++ b/atom/browser/api/atom_api_download_item.h @@ -46,6 +46,7 @@ class DownloadItem : public mate::TrackableObject, std::string GetGuid() const; void SetPrompt(bool prompt); bool ShouldPrompt(); + bool IsDangerous() const; protected: DownloadItem(v8::Isolate* isolate, content::DownloadItem* download_item); diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index 2e1fc884bb..b1edc89299 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -9,25 +9,372 @@ #include "atom/browser/api/atom_api_download_item.h" #include "atom/browser/native_window.h" #include "atom/browser/ui/file_dialog.h" +#include "atom/browser/ui/message_box.h" #include "base/bind.h" #include "base/files/file_util.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/download/download_completion_blocker.h" +#include "chrome/browser/download/download_item_model.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h" +#include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/common/pref_names.h" +#include "chrome/common/safe_browsing/file_type_policies.h" +#include "chrome/grit/generated_resources.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/download_danger_type.h" #include "content/public/browser/download_manager.h" #include "net/base/filename_util.h" +#include "ui/base/l10n/l10n_util.h" namespace atom { namespace { +using content::BrowserThread; +using content::DownloadItem; +using content::DownloadManager; +using safe_browsing::DownloadFileType; +using safe_browsing::DownloadProtectionService; + +#if defined(FULL_SAFE_BROWSING) + +const base::string16 safeBrowsingError = base::ASCIIToUTF16("Malware Download"); +const base::string16 safeBrowsingContent + = base::ASCIIToUTF16("Downloading Malicious Content"); + +// String pointer used for identifying safebrowing data associated with +// a download item. +const char kSafeBrowsingUserDataKey[] = "Safe Browsing ID"; + +// The state of a safebrowsing check. +class SafeBrowsingState : public DownloadCompletionBlocker { + public: + SafeBrowsingState() {} + ~SafeBrowsingState() override; + + private: + DISALLOW_COPY_AND_ASSIGN(SafeBrowsingState); +}; + +SafeBrowsingState::~SafeBrowsingState() {} + +#endif // FULL_SAFE_BROWSING + +// Used with GetPlatformDownloadPath() to indicate which platform path to +// return. +enum PlatformDownloadPathType { + // Return the platform specific target path. + PLATFORM_TARGET_PATH, + + // Return the platform specific current path. If the download is in-progress + // and the download location is a local filesystem path, then + // GetPlatformDownloadPath will return the path to the intermediate file. + PLATFORM_CURRENT_PATH +}; + +base::FilePath GetPlatformDownloadPath(Profile* profile, + const DownloadItem* download, + PlatformDownloadPathType path_type) { + if (path_type == PLATFORM_TARGET_PATH) + return download->GetTargetFilePath(); + return download->GetFullPath(); +} + +// Reason for why danger type is DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE. +// Used by "Download.DangerousFile.Reason" UMA metric. +// Do not change the ordering or remove items. +enum DangerousFileReason { + SB_NOT_AVAILABLE = 0, + SB_RETURNS_UNKOWN = 1, + SB_RETURNS_SAFE = 2, + DANGEROUS_FILE_REASON_MAX +}; + +#if defined(FULL_SAFE_BROWSING) +// Callback invoked by DownloadProtectionService::CheckClientDownload. +// |is_content_check_supported| is true if the SB service supports scanning the +// download for malicious content. +// |callback| is invoked with a danger type determined as follows: +// +// Danger type is (in order of preference): +// * DANGEROUS_URL, if the URL is a known malware site. +// * MAYBE_DANGEROUS_CONTENT, if the content will be scanned for +// malware. I.e. |is_content_check_supported| is true. +// * NOT_DANGEROUS. +void CheckDownloadUrlDone( + const DownloadTargetDeterminerDelegate::CheckDownloadUrlCallback& callback, + safe_browsing::DownloadCheckResult result) { + content::DownloadDangerType danger_type; + if (result != safe_browsing::DownloadCheckResult::SAFE && + result != safe_browsing::DownloadCheckResult::UNKNOWN) { + // If this type of files is handled by the enhanced SafeBrowsing download + // protection, mark it as potentially dangerous content until we are done + // with scanning it. + ShowErrorBox(safeBrowsingError, safeBrowsingContent); + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; + } else { + // If the URL is malicious, we'll use that as the danger type. The results + // of the content check, if one is performed, will be ignored. + danger_type = content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; + } + callback.Run(danger_type); +} + +#endif // FULL_SAFE_BROWSING + const DownloadPathReservationTracker::FilenameConflictAction kDefaultPlatformConflictAction = DownloadPathReservationTracker::UNIQUIFY; } // namespace +void AtomDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { + download_manager_ = dm; + + safe_browsing::SafeBrowsingService* sb_service = + g_browser_process->safe_browsing_service(); + if (sb_service) { + // Include this download manager in the set monitored by safe browsing. + sb_service->AddDownloadManager(dm); + } +} + +// static +void AtomDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(FULL_SAFE_BROWSING) + SafeBrowsingState* state = static_cast( + item->GetUserData(&kSafeBrowsingUserDataKey)); + if (!state) { + state = new SafeBrowsingState(); + item->SetUserData(&kSafeBrowsingUserDataKey, base::WrapUnique(state)); + } + state->CompleteDownload(); +#endif +} + +bool AtomDownloadManagerDelegate::IsDownloadReadyForCompletion( + DownloadItem* item, + const base::Closure& internal_complete_callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(FULL_SAFE_BROWSING) + SafeBrowsingState* state = static_cast( + item->GetUserData(&kSafeBrowsingUserDataKey)); + if (!state) { + // Begin the safe browsing download protection check. + DownloadProtectionService* service = GetDownloadProtectionService(); + if (service) { + DVLOG(2) << __func__ << "() Start SB download check for download = " + << item->DebugString(false); + state = new SafeBrowsingState(); + state->set_callback(internal_complete_callback); + item->SetUserData(&kSafeBrowsingUserDataKey, base::WrapUnique(state)); + service->CheckClientDownload( + item, + base::Bind(&AtomDownloadManagerDelegate::CheckClientDownloadDone, + weak_ptr_factory_.GetWeakPtr(), + item->GetId())); + return false; + } + + // In case the service was disabled between the download starting and now, + // we need to restore the danger state. + content::DownloadDangerType danger_type = item->GetDangerType(); + if (DownloadItemModel(item).GetDangerLevel() != + DownloadFileType::NOT_DANGEROUS && + (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || + danger_type == + content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { + DVLOG(2) << __func__ + << "() SB service disabled. Marking download as DANGEROUS FILE"; + if (ShouldBlockFile(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE)) { + item->OnContentCheckCompleted( + // Specifying a dangerous type here would take precendence over the + // blocking of the file. + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); + } else { + item->OnContentCheckCompleted( + content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, + content::DOWNLOAD_INTERRUPT_REASON_NONE); + } + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + internal_complete_callback); + return false; + } + } else if (!state->is_complete()) { + // Don't complete the download until we have an answer. + state->set_callback(internal_complete_callback); + return false; + } + +#endif + return true; +} + +bool AtomDownloadManagerDelegate::GenerateFileHash() { +#if defined(FULL_SAFE_BROWSING) + return g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); +#else + return false; +#endif +} + +void AtomDownloadManagerDelegate::SanitizeSavePackageResourceName( + base::FilePath* filename) { + safe_browsing::FileTypePolicies* file_type_policies = + safe_browsing::FileTypePolicies::GetInstance(); + + if (file_type_policies->GetFileDangerLevel(*filename) == + safe_browsing::DownloadFileType::NOT_DANGEROUS) + return; + + base::FilePath default_filename = base::FilePath::FromUTF8Unsafe( + l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); + *filename = filename->AddExtension(default_filename.BaseName().value()); +} + +DownloadProtectionService* + AtomDownloadManagerDelegate::GetDownloadProtectionService() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(FULL_SAFE_BROWSING) + safe_browsing::SafeBrowsingService* sb_service = + g_browser_process->safe_browsing_service(); + if (sb_service && sb_service->download_protection_service()) { + return sb_service->download_protection_service(); + } +#endif + return NULL; +} + +void AtomDownloadManagerDelegate::ShouldCompleteDownloadInternal( + uint32_t download_id, + const base::Closure& user_complete_callback) { + DownloadItem* item = download_manager_->GetDownload(download_id); + if (!item) + return; + if (ShouldCompleteDownload(item, user_complete_callback)) + user_complete_callback.Run(); +} + +bool AtomDownloadManagerDelegate::ShouldCompleteDownload( + DownloadItem* item, + const base::Closure& user_complete_callback) { + return IsDownloadReadyForCompletion(item, base::Bind( + &AtomDownloadManagerDelegate::ShouldCompleteDownloadInternal, + weak_ptr_factory_.GetWeakPtr(), item->GetId(), user_complete_callback)); +} + +void AtomDownloadManagerDelegate::CheckDownloadUrl( + DownloadItem* download, + const base::FilePath& suggested_path, + const CheckDownloadUrlCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + +#if defined(FULL_SAFE_BROWSING) + safe_browsing::DownloadProtectionService* service = + GetDownloadProtectionService(); + if (service) { + DVLOG(2) << __func__ << "() Start SB URL check for download = " + << download->DebugString(false); + service->CheckDownloadUrl(download, + base::Bind(&CheckDownloadUrlDone, callback)); + return; + } +#endif + callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); +} + +#if defined(FULL_SAFE_BROWSING) +void AtomDownloadManagerDelegate::CheckClientDownloadDone( + uint32_t download_id, + safe_browsing::DownloadCheckResult result) { + DownloadItem* item = download_manager_->GetDownload(download_id); + if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) + return; + + DVLOG(2) << __func__ << "() download = " << item->DebugString(false) + << " verdict = " << static_cast(result); + // We only mark the content as being dangerous if the download's safety state + // has not been set to DANGEROUS yet. We don't want to show two warnings. + if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || + item->GetDangerType() == + content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { + content::DownloadDangerType danger_type = + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; + switch (result) { + case safe_browsing::DownloadCheckResult::UNKNOWN: + // The check failed or was inconclusive. + if (DownloadItemModel(item).GetDangerLevel() != + DownloadFileType::NOT_DANGEROUS) { + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; + } + break; + case safe_browsing::DownloadCheckResult::SAFE: + // If this file type require explicit consent, then set the danger type + // to DANGEROUS_FILE so that the user be required to manually vet + // whether the download is intended or not. + if (DownloadItemModel(item).GetDangerLevel() == + DownloadFileType::DANGEROUS) { + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; + } + break; + case safe_browsing::DownloadCheckResult::DANGEROUS: + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; + break; + case safe_browsing::DownloadCheckResult::UNCOMMON: + danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; + break; + case safe_browsing::DownloadCheckResult::DANGEROUS_HOST: + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST; + break; + case safe_browsing::DownloadCheckResult::POTENTIALLY_UNWANTED: + danger_type = content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED; + break; + } + DCHECK_NE(danger_type, + content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT); + + if (danger_type != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { + if (ShouldBlockFile(danger_type)) { + item->OnContentCheckCompleted( + danger_type, + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); + } else { + item->OnContentCheckCompleted(danger_type, + content::DOWNLOAD_INTERRUPT_REASON_NONE); + } + } + } + + SafeBrowsingState* state = static_cast( + item->GetUserData(&kSafeBrowsingUserDataKey)); + state->CompleteDownload(); +} +#endif // FULL_SAFE_BROWSING + +bool AtomDownloadManagerDelegate::ShouldBlockFile( + content::DownloadDangerType danger_type) const { + return (danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || + danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || + danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); +} + +void AtomDownloadManagerDelegate::MaybeSendDangerousDownloadOpenedReport( + DownloadItem* download, + bool show_download_in_folder) { +#if defined(FULL_SAFE_BROWSING) + safe_browsing::DownloadProtectionService* service = + GetDownloadProtectionService(); + if (service) { + service->MaybeSendDangerousDownloadOpenedReport(download, + show_download_in_folder); + } +#endif +} + AtomDownloadManagerDelegate::AtomDownloadManagerDelegate( content::DownloadManager* manager) : download_manager_(manager), @@ -53,17 +400,44 @@ void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item, *path = download->GetSavePath(); } -void AtomDownloadManagerDelegate::OnDownloadPathGenerated( +void AtomDownloadManagerDelegate::DetermineLocalPath( + DownloadItem* download, + const base::FilePath& virtual_path, + const DownloadTargetDeterminerDelegate::LocalPathCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(OS_CHROMEOS) + drive::DownloadHandler* drive_download_handler = + drive::DownloadHandler::GetForProfile(profile_); + if (drive_download_handler) { + drive_download_handler->SubstituteDriveDownloadPath( + virtual_path, download, callback); + return; + } +#endif + callback.Run(virtual_path); +} + +void AtomDownloadManagerDelegate::OnDownloadTargetDetermined( int32_t download_id, const content::DownloadTargetCallback& callback, - PathValidationResult result, - const base::FilePath& target_path) { + std::unique_ptr target_info) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - auto item = download_manager_->GetDownload(download_id); if (!item) return; + if (ShouldBlockFile(target_info->danger_type)) { + item->OnContentCheckCompleted( + // Specifying a dangerous type here would take precendence over the + // blocking of the file. + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); + } else { + item->OnContentCheckCompleted( + content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, + content::DOWNLOAD_INTERRUPT_REASON_NONE); + } + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::HandleScope handle_scope(isolate); @@ -73,11 +447,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( if (!download_item) download_item = atom::api::DownloadItem::Create(isolate, item).get(); - base::FilePath path; - if (result == PathValidationResult::SUCCESS && - !download_item->ShouldPrompt()) { - path = target_path; - } + base::FilePath path = target_info->target_path; NativeWindow* window = nullptr; content::WebContents* web_contents = item->GetWebContents(); @@ -92,7 +462,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( file_dialog::DialogSettings settings; settings.parent_window = window; settings.title = item->GetURL().spec(); - settings.default_path = target_path; + settings.default_path = path; if (path.empty() && file_dialog::ShowSaveDialog(settings, &path)) { // Remember the last selected download directory. Profile* profile = static_cast( @@ -109,10 +479,8 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( callback.Run(path, content::DownloadItem::TARGET_DISPOSITION_PROMPT, - content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path, - path.empty() - ? content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED - : content::DOWNLOAD_INTERRUPT_REASON_NONE); + target_info->danger_type, path, + target_info->result); } void AtomDownloadManagerDelegate::Shutdown() { @@ -121,7 +489,7 @@ void AtomDownloadManagerDelegate::Shutdown() { } bool AtomDownloadManagerDelegate::DetermineDownloadTarget( - content::DownloadItem* download, + DownloadItem* download, const content::DownloadTargetCallback& callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -153,19 +521,51 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget( virtual_path = default_download_path.Append(generated_filename); } - DownloadPathReservationTracker::GetReservedPath( - download, - virtual_path, - default_download_path, - true, - conflict_action, - base::Bind(&AtomDownloadManagerDelegate::OnDownloadPathGenerated, + DownloadTargetDeterminer::CompletionCallback target_determined_callback = + base::Bind(&AtomDownloadManagerDelegate::OnDownloadTargetDetermined, weak_ptr_factory_.GetWeakPtr(), download->GetId(), - callback)); + callback); + + DownloadTargetDeterminer::Start( + download, + virtual_path, + kDefaultPlatformConflictAction, nullptr, this, + target_determined_callback); + return true; } +void AtomDownloadManagerDelegate::ReserveVirtualPath( + content::DownloadItem* download, + const base::FilePath& virtual_path, + bool create_directory, + DownloadPathReservationTracker::FilenameConflictAction conflict_action, + const ReservedPathCallback& callback) { + Profile* browser_context = static_cast( + download_manager_->GetBrowserContext()); + base::FilePath default_download_path( + browser_context->GetPrefs()->GetFilePath( + prefs::kDownloadDefaultDirectory)); + + DownloadPathReservationTracker::GetReservedPath( + download, + virtual_path, + default_download_path, + true, + conflict_action, + callback); +} + +bool AtomDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( + const base::FilePath& path) { +#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) + if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) { + return true; + } +#endif +} + bool AtomDownloadManagerDelegate::ShouldOpenDownload( content::DownloadItem* download, const content::DownloadOpenDelayedCallback& callback) { diff --git a/atom/browser/atom_download_manager_delegate.h b/atom/browser/atom_download_manager_delegate.h index 12675487fd..33d9d940b2 100644 --- a/atom/browser/atom_download_manager_delegate.h +++ b/atom/browser/atom_download_manager_delegate.h @@ -5,28 +5,45 @@ #ifndef ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_ #define ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_ +#include #include #include "base/memory/weak_ptr.h" +#include "base/strings/utf_string_conversions.h" #include "chrome/browser/download/download_path_reservation_tracker.h" +#include "chrome/browser/download/download_prefs.h" +#include "chrome/browser/download/download_target_determiner.h" +#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" +#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h" #include "content/public/browser/download_manager_delegate.h" +class DownloadPrefs; +class Profile; + namespace content { class DownloadManager; } namespace atom { -class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate { +class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate, + public DownloadTargetDeterminerDelegate { public: explicit AtomDownloadManagerDelegate(content::DownloadManager* manager); virtual ~AtomDownloadManagerDelegate(); - void OnDownloadPathGenerated( + // Should be called before the first call to ShouldCompleteDownload() to + // disable SafeBrowsing checks for |item|. + static void DisableSafeBrowsing(content::DownloadItem* item); + + void SetDownloadManager(content::DownloadManager* dm); + bool GenerateFileHash() override; + void SanitizeSavePackageResourceName(base::FilePath* filename) override; + + void OnDownloadTargetDetermined( int32_t download_id, const content::DownloadTargetCallback& callback, - PathValidationResult result, - const base::FilePath& target_path); + std::unique_ptr target_info); // content::DownloadManagerDelegate: void Shutdown() override; @@ -37,11 +54,62 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate { content::DownloadItem* download, const content::DownloadOpenDelayedCallback& callback) override; void GetNextId(const content::DownloadIdCallback& callback) override; + bool ShouldCompleteDownload(content::DownloadItem* item, + const base::Closure& complete_callback) override; + + protected: + virtual safe_browsing::DownloadProtectionService* + GetDownloadProtectionService(); + void CheckDownloadUrl(content::DownloadItem* download, + const base::FilePath& suggested_virtual_path, + const CheckDownloadUrlCallback& callback) override; + void NotifyExtensions(content::DownloadItem* download, + const base::FilePath& suggested_virtual_path, + const NotifyExtensionsCallback& callback) override {} + void ReserveVirtualPath( + content::DownloadItem* download, + const base::FilePath& virtual_path, + bool create_directory, + DownloadPathReservationTracker::FilenameConflictAction conflict_action, + const ReservedPathCallback& callback) override; + + void RequestConfirmation(content::DownloadItem* download, + const base::FilePath& suggested_virtual_path, + DownloadConfirmationReason reason, + const ConfirmationCallback& callback) override {} + void DetermineLocalPath(content::DownloadItem* download, + const base::FilePath& virtual_path, + const LocalPathCallback& callback) override; + + void GetFileMimeType(const base::FilePath& path, + const GetFileMimeTypeCallback& callback) override {} private: + // Internal gateways for ShouldCompleteDownload(). + bool IsDownloadReadyForCompletion( + content::DownloadItem* item, + const base::Closure& internal_complete_callback); + + // Returns true if |path| should open in the browser. + bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path); + void MaybeSendDangerousDownloadOpenedReport(content::DownloadItem* download, + bool show_download_in_folder); + // Get the save path set on the associated api::DownloadItem object void GetItemSavePath(content::DownloadItem* item, base::FilePath* path); + // Callback function after the DownloadProtectionService completes. + void CheckClientDownloadDone(uint32_t download_id, + safe_browsing::DownloadCheckResult result); + + // Return true if the downloaded file should be blocked based on the current + // download restriction pref and |danger_type|. + bool ShouldBlockFile(content::DownloadDangerType danger_type) const; + + void ShouldCompleteDownloadInternal( + uint32_t download_id, + const base::Closure& user_complete_callback); + content::DownloadManager* download_manager_; base::WeakPtrFactory weak_ptr_factory_; diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 98c3dcce09..2cec79be43 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -10,7 +10,16 @@ #include "atom/browser/web_contents_permission_helper.h" #include "atom/common/platform_util.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/browser_process_impl.h" +#include "chrome/browser/loader/predictor_resource_throttle.h" +#include "chrome/browser/loader/safe_browsing_resource_throttle.h" +#include "chrome/browser/safe_browsing/safe_browsing_service.h" +#include "components/offline_pages/features/features.h" +#include "components/policy/core/common/cloud/policy_header_io_helper.h" +#include "components/variations/net/variations_http_headers.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/resource_request_info.h" + #include "net/base/escape.h" #include "net/ssl/client_cert_store.h" #include "url/gurl.h" @@ -24,6 +33,8 @@ #endif using content::BrowserThread; +using content::ResourceRequestInfo; +using content::ResourceType; namespace atom { @@ -61,7 +72,87 @@ void HandleExternalProtocolInUI( } // namespace -AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() { +AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() : + safe_browsing_(g_browser_process->safe_browsing_service()) { +} + +void AtomResourceDispatcherHostDelegate::RequestBeginning( + net::URLRequest* request, + content::ResourceContext* resource_context, + content::AppCacheService* appcache_service, + ResourceType resource_type, + std::vector>* throttles) { + if (safe_browsing_.get()) + safe_browsing_->OnResourceRequest(request); + + const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); + +#if BUILDFLAG(ENABLE_OFFLINE_PAGES) + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::BindOnce(&NotifyUIThreadOfRequestStarted, + info->GetWebContentsGetterForRequest(), + info->GetResourceType())); +#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) + +#if defined(OS_ANDROID) + if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME) + InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request); +#endif + +#if defined(OS_CHROMEOS) + // Check if we need to add merge session throttle. This throttle will postpone + // loading of XHR requests. + if (resource_type == content::RESOURCE_TYPE_XHR) { + // Add interstitial page while merge session process (cookie + // reconstruction from OAuth2 refresh token in ChromeOS login) is still in + // progress while we are attempting to load a google property. + if (!merge_session_throttling_utils::AreAllSessionMergedAlready() && + request->url().SchemeIsHTTPOrHTTPS()) { + throttles->push_back( + base::MakeUnique(request)); + } + } +#endif + + if (!request->is_pending()) { + net::HttpRequestHeaders headers; + headers.CopyFrom(request->extra_request_headers()); + request->SetExtraRequestHeaders(headers); + } + + AppendStandardResourceThrottles(request, + resource_context, + resource_type, + throttles); +#if BUILDFLAG(ENABLE_NACL) + AppendComponentUpdaterThrottles(request, *info, resource_context, + resource_type, throttles); +#endif // BUILDFLAG(ENABLE_NACL) +} + +void AtomResourceDispatcherHostDelegate::AppendStandardResourceThrottles( + net::URLRequest* request, + content::ResourceContext* resource_context, + ResourceType resource_type, + std::vector>* throttles) { + + // Insert either safe browsing or data reduction proxy throttle at the front + // of the list, so one of them gets to decide if the resource is safe. + content::ResourceThrottle* first_throttle = NULL; +#if defined(OS_ANDROID) + first_throttle = DataReductionProxyResourceThrottle::MaybeCreate( + request, resource_context, resource_type, safe_browsing_.get()); +#endif // defined(OS_ANDROID) + +#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) + if (!first_throttle) { + first_throttle = MaybeCreateSafeBrowsingResourceThrottle( + request, resource_type, safe_browsing_.get()); + } +#endif // defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE) + + if (first_throttle) + throttles->push_back(base::WrapUnique(first_throttle)); } bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol( diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.h b/atom/browser/atom_resource_dispatcher_host_delegate.h index f021e69549..6a409ae0b9 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.h +++ b/atom/browser/atom_resource_dispatcher_host_delegate.h @@ -6,9 +6,15 @@ #define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ #include +#include +#include "base/memory/ref_counted.h" #include "content/public/browser/resource_dispatcher_host_delegate.h" +namespace safe_browsing { +class SafeBrowsingService; +} + namespace atom { class AtomResourceDispatcherHostDelegate @@ -16,6 +22,15 @@ class AtomResourceDispatcherHostDelegate public: AtomResourceDispatcherHostDelegate(); + void RequestBeginning(net::URLRequest* request, + content::ResourceContext* resource_context, + content::AppCacheService* appcache_service, + content::ResourceType resource_type, + std::vector>* + throttles) override; + + + // content::ResourceDispatcherHostDelegate: bool HandleExternalProtocol( const GURL& url, @@ -25,6 +40,16 @@ class AtomResourceDispatcherHostDelegate net::URLRequest* request) override; std::unique_ptr CreateClientCertStore( content::ResourceContext* resource_context) override; + + protected: + virtual void AppendStandardResourceThrottles( + net::URLRequest* request, + content::ResourceContext* resource_context, + content::ResourceType resource_type, + std::vector>* throttles); + + private: + scoped_refptr safe_browsing_; }; } // namespace atom diff --git a/brave/browser/brave_browser_context.cc b/brave/browser/brave_browser_context.cc index dfee246b31..9f0468da22 100644 --- a/brave/browser/brave_browser_context.cc +++ b/brave/browser/brave_browser_context.cc @@ -36,6 +36,7 @@ #include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_filter.h" #include "components/pref_registry/pref_registry_syncable.h" +#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable_factory.h" #include "components/user_prefs/user_prefs.h" @@ -449,6 +450,7 @@ void BraveBrowserContext::CreateProfilePrefs( pref_registry_->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels); pref_registry_->RegisterBooleanPref(prefs::kPrintingEnabled, true); pref_registry_->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false); + pref_registry_->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true); #if BUILDFLAG(ENABLE_PLUGINS) PluginInfoMessageFilter::RegisterUserPrefs(pref_registry_.get()); PepperFlashSettingsManager::RegisterProfilePrefs(pref_registry_.get()); @@ -724,4 +726,3 @@ AtomBrowserContext* AtomBrowserContext::From( } } // namespace atom - diff --git a/brave/browser/brave_content_browser_client.cc b/brave/browser/brave_content_browser_client.cc index ed07faf6c1..99d13747b8 100644 --- a/brave/browser/brave_content_browser_client.cc +++ b/brave/browser/brave_content_browser_client.cc @@ -30,6 +30,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/env_vars.h" #include "chrome/common/importer/profile_import.mojom.h" +#include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/renderer_configuration.mojom.h" #include "chrome/grit/generated_resources.h" @@ -664,7 +665,9 @@ void BraveContentBrowserClient::OverrideWebkitPrefs( prefs->hyperlink_auditing_enabled = false; // Custom preferences of guest page. auto web_contents = content::WebContents::FromRenderViewHost(host); - atom::WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs); + if (web_contents) { + atom::WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs); + } #if BUILDFLAG(ENABLE_EXTENSIONS) extensions_part_->OverrideWebkitPrefs(host, prefs); #endif diff --git a/brave/browser/password_manager/brave_password_manager_client.cc b/brave/browser/password_manager/brave_password_manager_client.cc index 86684443c3..30875668d0 100644 --- a/brave/browser/password_manager/brave_password_manager_client.cc +++ b/brave/browser/password_manager/brave_password_manager_client.cc @@ -378,8 +378,11 @@ void BravePasswordManagerClient::CheckSafeBrowsingReputation( const GURL& form_action, const GURL& frame_url) {} +void BravePasswordManagerClient::LogPasswordReuseDetectedEvent() {} + void BravePasswordManagerClient::CheckProtectedPasswordEntry( - const std::string& password_saved_domain, + bool matches_sync_password, + const std::vector& matching_domains, bool password_field_exists) {} #endif diff --git a/brave/browser/password_manager/brave_password_manager_client.h b/brave/browser/password_manager/brave_password_manager_client.h index 4477db8fb4..b835d0594d 100644 --- a/brave/browser/password_manager/brave_password_manager_client.h +++ b/brave/browser/password_manager/brave_password_manager_client.h @@ -112,9 +112,12 @@ class BravePasswordManagerClient void CheckSafeBrowsingReputation(const GURL& form_action, const GURL& frame_url) override; void CheckProtectedPasswordEntry( - const std::string& password_saved_domain, + bool matches_sync_password, + const std::vector& matching_domains, bool password_field_exists) override; + void LogPasswordReuseDetectedEvent() override; + #endif password_manager::PasswordSyncState GetPasswordSyncState() const override; bool WasLastNavigationHTTPError() const override; diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index d30f13251d..1a2e94746f 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -147,7 +147,6 @@ source_set("browser") { ":password_manager", ":sessions", ":web_data", - "chrome/browser/safe_browsing", "//electron/brave/browser:tab_manager", "//base", "//chrome/common", @@ -163,7 +162,6 @@ source_set("browser") { "//components/prefs", "//components/ssl_config", "//components/spellcheck:build_features", - "//components/safe_browsing:csd_proto", "//components/storage_monitor", "//content/public/browser", "//electron/atom/browser", @@ -194,6 +192,8 @@ source_set("browser") { "//chrome/browser/extensions/global_shortcut_listener_mac.mm", "//chrome/browser/extensions/global_shortcut_listener_win.cc", "//chrome/browser/extensions/global_shortcut_listener_win.h", + "//chrome/browser/extensions/install_signer.cc", + "//chrome/browser/extensions/install_signer.h", "//chrome/browser/file_select_helper.cc", "//chrome/browser/file_select_helper_mac.mm", @@ -290,8 +290,121 @@ source_set("browser") { "chrome/browser/content_settings/host_content_settings_map_factory.cc", "chrome/browser/content_settings/host_content_settings_map_factory.h", - "//chrome/browser/ssl/security_state_tab_helper.cc", + "//chrome/browser/interstitials/chrome_metrics_helper.cc", + "//chrome/browser/interstitials/chrome_metrics_helper.h", + + "//chrome/browser/renderer_preferences_util.cc", + "//chrome/browser/renderer_preferences_util.h", + + "//chrome/browser/safe_browsing/chunk_range.cc", + "//chrome/browser/safe_browsing/chunk_range.h", + "//chrome/browser/safe_browsing/client_side_model_loader.cc", + "//chrome/browser/safe_browsing/client_side_model_loader.h", + "//chrome/browser/safe_browsing/client_side_detection_service.cc", + "//chrome/browser/safe_browsing/client_side_detection_service.h", + "//chrome/browser/safe_browsing/download_protection/check_client_download_request.cc", + "//chrome/browser/safe_browsing/download_protection/check_client_download_request.h", + "//chrome/browser/safe_browsing/download_protection/disk_image_type_sniffer_mac.cc", + "//chrome/browser/safe_browsing/download_protection/disk_image_type_sniffer_mac.h", + "//chrome/browser/safe_browsing/download_protection/download_feedback.cc", + "//chrome/browser/safe_browsing/download_protection/download_feedback.h", + "//chrome/browser/safe_browsing/download_protection/download_feedback_service.cc", + "//chrome/browser/safe_browsing/download_protection/download_feedback_service.h", + "//chrome/browser/safe_browsing/download_protection/download_protection_service.cc", + "//chrome/browser/safe_browsing/download_protection/download_protection_service.h", + "//chrome/browser/safe_browsing/download_protection/download_protection_util.cc", + "//chrome/browser/safe_browsing/download_protection/download_protection_util.h", + "//chrome/browser/safe_browsing/download_protection/download_url_sb_client.cc", + "//chrome/browser/safe_browsing/download_protection/download_url_sb_client.h", + "//chrome/browser/safe_browsing/download_protection/path_sanitizer.cc", + "//chrome/browser/safe_browsing/download_protection/path_sanitizer.h", + "//chrome/browser/safe_browsing/download_protection/ppapi_download_request.cc", + "//chrome/browser/safe_browsing/download_protection/ppapi_download_request.h", + "//chrome/browser/safe_browsing/download_protection/sandboxed_dmg_analyzer_mac.cc", + "//chrome/browser/safe_browsing/download_protection/sandboxed_dmg_analyzer_mac.h", + "//chrome/browser/safe_browsing/download_protection/sandboxed_zip_analyzer.cc", + "//chrome/browser/safe_browsing/download_protection/sandboxed_zip_analyzer.h", + "//chrome/browser/safe_browsing/download_protection/two_phase_uploader.cc", + "//chrome/browser/safe_browsing/download_protection/two_phase_uploader.h", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.cc", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer.h", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer_mac.cc", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_analyzer_mac.h", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.cc", + "//chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h", + "//chrome/browser/safe_browsing/incident_reporting/delayed_callback_runner.cc", + "//chrome/browser/safe_browsing/incident_reporting/delayed_callback_runner.h", + "//chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.cc", + "//chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.h", + "//chrome/browser/safe_browsing/incident_reporting/environment_data_collection.cc", + "//chrome/browser/safe_browsing/incident_reporting/environment_data_collection.h", + "//chrome/browser/safe_browsing/incident_reporting/extension_data_collection.cc", + "//chrome/browser/safe_browsing/incident_reporting/extension_data_collection.h", + "//chrome/browser/safe_browsing/incident_reporting/incident.cc", + "//chrome/browser/safe_browsing/incident_reporting/incident.h", + "//chrome/browser/safe_browsing/incident_reporting/incident_handler_util.cc", + "//chrome/browser/safe_browsing/incident_reporting/incident_handler_util.h", + "//chrome/browser/safe_browsing/incident_reporting/incident_report_uploader.cc", + "//chrome/browser/safe_browsing/incident_reporting/incident_report_uploader.h", + "//chrome/browser/safe_browsing/incident_reporting/incident_report_uploader_impl.cc", + "//chrome/browser/safe_browsing/incident_reporting/incident_report_uploader_impl.h", + "//chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc", + "//chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.h", + "//chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc", + "//chrome/browser/safe_browsing/incident_reporting/last_download_finder.h", + "//chrome/browser/safe_browsing/incident_reporting/platform_state_store.cc", + "//chrome/browser/safe_browsing/incident_reporting/platform_state_store.h", + "//chrome/browser/safe_browsing/incident_reporting/preference_validation_delegate.cc", + "//chrome/browser/safe_browsing/incident_reporting/preference_validation_delegate.h", + "//chrome/browser/safe_browsing/incident_reporting/resource_request_detector.cc", + "//chrome/browser/safe_browsing/incident_reporting/resource_request_detector.h", + "//chrome/browser/safe_browsing/incident_reporting/resource_request_incident.cc", + "//chrome/browser/safe_browsing/incident_reporting/resource_request_incident.h", + "//chrome/browser/safe_browsing/incident_reporting/state_store.cc", + "//chrome/browser/safe_browsing/incident_reporting/state_store.h", + "//chrome/browser/safe_browsing/incident_reporting/tracked_preference_incident.cc", + "//chrome/browser/safe_browsing/incident_reporting/tracked_preference_incident.h", + "//chrome/browser/safe_browsing/notification_image_reporter.cc", + "//chrome/browser/safe_browsing/notification_image_reporter.h", + "//chrome/browser/safe_browsing/local_database_manager.cc", + "//chrome/browser/safe_browsing/local_database_manager.h", + "//chrome/browser/safe_browsing/permission_reporter.cc", + "//chrome/browser/safe_browsing/permission_reporter.h", + "//chrome/browser/safe_browsing/ping_manager.cc", + "//chrome/browser/safe_browsing/ping_manager.h", + "//chrome/browser/safe_browsing/protocol_manager.cc", + "//chrome/browser/safe_browsing/protocol_manager.h", + "//chrome/browser/safe_browsing/protocol_parser.cc", + "//chrome/browser/safe_browsing/protocol_parser.h", + "//chrome/browser/safe_browsing/ui_manager.cc", + "//chrome/browser/safe_browsing/ui_manager.h", + "//chrome/browser/safe_browsing/safe_browsing_blocking_page.cc", + "//chrome/browser/safe_browsing/safe_browsing_blocking_page.h", + "//chrome/browser/safe_browsing/safe_browsing_database.cc", + "//chrome/browser/safe_browsing/safe_browsing_database.h", + "//chrome/browser/safe_browsing/safe_browsing_service.cc", + "//chrome/browser/safe_browsing/safe_browsing_service.h", + "//chrome/browser/safe_browsing/safe_browsing_store.cc", + "//chrome/browser/safe_browsing/safe_browsing_store.h", + "//chrome/browser/safe_browsing/safe_browsing_store_file.cc", + "//chrome/browser/safe_browsing/safe_browsing_store_file.h", + "//chrome/browser/safe_browsing/safe_browsing_navigation_observer.cc", + "//chrome/browser/safe_browsing/safe_browsing_navigation_observer.h", + "//chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc", + "//chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h", + "//chrome/browser/safe_browsing/safe_browsing_util.cc", + "//chrome/browser/safe_browsing/safe_browsing_util.h", + "//chrome/browser/safe_browsing/services_delegate_impl.cc", + "//chrome/browser/safe_browsing/services_delegate_impl.h", + "//chrome/browser/safe_browsing/signature_evaluator_mac.mm", + "//chrome/browser/safe_browsing/signature_evaluator_mac.h", + + "//chrome/browser/ssl/captive_portal_metrics_recorder.cc", + "//chrome/browser/ssl/captive_portal_metrics_recorder.h", + "chrome/browser/ssl/security_state_tab_helper.cc", "//chrome/browser/ssl/security_state_tab_helper.h", + "//chrome/browser/sync/user_event_service_factory.cc", + "//chrome/browser/sync/user_event_service_factory.h", "//chrome/browser/tab_contents/tab_util.cc", "//chrome/browser/tab_contents/tab_util.h", "//chrome/browser/win/chrome_process_finder.cc", @@ -369,9 +482,20 @@ source_set("browser") { deps += [ "//base", + "//chrome/browser/safe_browsing:chunk_proto", + "//chrome/common/safe_browsing:proto", + "//components/safe_browsing/password_protection", + "//components/safe_browsing:safe_browsing", + "//components/safe_browsing/browser:browser", + "//components/safe_browsing/triggers:triggers", + "//components/safe_browsing/db:v4_feature_list", + "//components/safe_browsing/db:prefix_set", + "//components/safe_browsing/db:metadata_proto", + "//content/public/browser:browser", "//net:extras", "//net:net_browser_services", "//skia", + "//third_party/cacheinvalidation", "//ui/base", "//ui/events", "//ui/gfx", diff --git a/chromium_src/chrome/browser/prerender/prerender_contents.cc b/chromium_src/chrome/browser/prerender/prerender_contents.cc index d73c4789c1..8bcd1dcc6b 100644 --- a/chromium_src/chrome/browser/prerender/prerender_contents.cc +++ b/chromium_src/chrome/browser/prerender/prerender_contents.cc @@ -14,4 +14,11 @@ namespace prerender { void PrerenderContents::DidNavigate( const history::HistoryAddPageArgs& add_page_args) {} +void PrerenderContents::Destroy(FinalStatus final_status) {} + +PrerenderContents* PrerenderContents::FromWebContents( + content::WebContents* web_contents) { + return NULL; +} + } // namespace prerender diff --git a/chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc b/chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc deleted file mode 100644 index 677d0da055..0000000000 --- a/chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 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 "chrome/browser/safe_browsing/safe_browsing_service.h" - -#include - -#include "chrome/browser/safe_browsing/ui_manager.h" - -namespace safe_browsing { - -const scoped_refptr& -SafeBrowsingService::ui_manager() const { - return nullptr; -} - -void SafeBrowsingService::DisableQuicOnIOThread() {} - -} // namespace safe_browsing diff --git a/muon/browser/muon_browser_process_impl.cc b/muon/browser/muon_browser_process_impl.cc index 20b9a7b041..493f7f05e6 100644 --- a/muon/browser/muon_browser_process_impl.cc +++ b/muon/browser/muon_browser_process_impl.cc @@ -6,25 +6,61 @@ #include "atom/browser/api/atom_api_app.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h" +#include "base/path_service.h" #include "brave/browser/component_updater/brave_component_updater_configurator.h" +//#include "chromium_src/chrome/browser/prefs/browser_prefs.cc" #include "chrome/browser/io_thread.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/safe_browsing/safe_browsing_service.h" +#include "chrome/common/pref_names.h" #include "components/component_updater/component_updater_service.h" +#include "components/metrics/metrics_pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_dispatcher_host.h" +using content::ResourceDispatcherHost; + MuonBrowserProcessImpl::MuonBrowserProcessImpl( base::SequencedTaskRunner* local_state_task_runner, const base::CommandLine& command_line) : - BrowserProcessImpl(local_state_task_runner, command_line) { + BrowserProcessImpl(local_state_task_runner, command_line), + created_safe_browsing_service_(false) { g_browser_process = this; } MuonBrowserProcessImpl::~MuonBrowserProcessImpl() { + if (safe_browsing_service_.get()) + safe_browsing_service()->ShutDown(); g_browser_process = NULL; } +safe_browsing::SafeBrowsingService* +MuonBrowserProcessImpl::safe_browsing_service() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (!created_safe_browsing_service_) + CreateSafeBrowsingService(); + return safe_browsing_service_.get(); +} + +safe_browsing::ClientSideDetectionService* + MuonBrowserProcessImpl::safe_browsing_detection_service() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (safe_browsing_service()) + return safe_browsing_service()->safe_browsing_detection_service(); + return NULL; +} + +void MuonBrowserProcessImpl::CreateSafeBrowsingService() { + DCHECK(!safe_browsing_service_); + // Set this flag to true so that we don't retry indefinitely to + // create the service class if there was an error. + created_safe_browsing_service_ = true; + safe_browsing_service_ = + safe_browsing::SafeBrowsingService::CreateSafeBrowsingService(); + safe_browsing_service_->Initialize(); +} + component_updater::ComponentUpdateService* MuonBrowserProcessImpl::component_updater( std::unique_ptr &component_updater, @@ -55,9 +91,20 @@ MuonBrowserProcessImpl::component_updater() { return component_updater(component_updater_, false); } +void MuonBrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() { + bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); + ResourceDispatcherHost::Get()->SetAllowCrossOriginAuthPrompt(value); +} + void MuonBrowserProcessImpl::ResourceDispatcherHostCreated() { resource_dispatcher_host_delegate_.reset( new atom::AtomResourceDispatcherHostDelegate); + content::ResourceDispatcherHost::Get()->SetDelegate( resource_dispatcher_host_delegate_.get()); + pref_change_registrar_.Add( + prefs::kAllowCrossOriginAuthPrompt, + base::Bind(&MuonBrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy, + base::Unretained(this))); + ApplyAllowCrossOriginAuthPromptPolicy(); } diff --git a/muon/browser/muon_browser_process_impl.h b/muon/browser/muon_browser_process_impl.h index 5d4de792fe..6ff5d20141 100644 --- a/muon/browser/muon_browser_process_impl.h +++ b/muon/browser/muon_browser_process_impl.h @@ -7,6 +7,7 @@ #include "build/build_config.h" #include "chrome/browser/browser_process_impl.h" +#include "net/socket/client_socket_pool_manager.h" namespace atom { namespace api { @@ -32,7 +33,16 @@ class MuonBrowserProcessImpl : public BrowserProcessImpl { component_updater::ComponentUpdateService* component_updater() override; void ResourceDispatcherHostCreated() override; + safe_browsing::SafeBrowsingService* safe_browsing_service() override; + safe_browsing::ClientSideDetectionService* safe_browsing_detection_service() + override; + private: + void ApplyAllowCrossOriginAuthPromptPolicy(); + void CreateSafeBrowsingService(); + void CreateSafeBrowsingDetectionService(); + + std::unique_ptr local_state_; atom::api::App* app_; // not owned std::unique_ptr @@ -46,6 +56,12 @@ class MuonBrowserProcessImpl : public BrowserProcessImpl { std::unique_ptr &, bool use_brave_server); + bool created_safe_browsing_service_; + scoped_refptr safe_browsing_service_; + + // Ensures that the observers of plugin/print disable/enable state + // notifications are properly added and removed. + PrefChangeRegistrar pref_change_registrar_; DISALLOW_COPY_AND_ASSIGN(MuonBrowserProcessImpl); }; diff --git a/patches/master_patch.patch b/patches/master_patch.patch index 5a3e6e58d2..a7fa8cc06f 100644 --- a/patches/master_patch.patch +++ b/patches/master_patch.patch @@ -159,6 +159,203 @@ index 751043efd8038573b2870dc60e5d7ad737887d5f..321971b975659028005aabd8a9163ac8 "safe_browsing::mojom::SafeBrowsing", "spellcheck::mojom::SpellCheckHost", "spellcheck::mojom::SpellCheckPanelHost", +diff --git a/chrome/browser/download/download_target_determiner.cc b/chrome/browser/download/download_target_determiner.cc +index 4f4dadd98fd997e9659d10e6989916dbb0bb899e..67b849f05827a057ad28d3908a0805aab478a808 100644 +--- a/chrome/browser/download/download_target_determiner.cc ++++ b/chrome/browser/download/download_target_determiner.cc +@@ -16,7 +16,6 @@ + #include "base/threading/thread_task_runner_handle.h" + #include "base/time/time.h" + #include "chrome/browser/download/chrome_download_manager_delegate.h" +-#include "chrome/browser/download/download_crx_util.h" + #include "chrome/browser/download/download_prefs.h" + #include "chrome/browser/download/download_stats.h" + #include "chrome/browser/history/history_service_factory.h" +@@ -92,7 +91,7 @@ DownloadTargetDeterminer::DownloadTargetDeterminer( + DownloadPrefs* download_prefs, + DownloadTargetDeterminerDelegate* delegate, + const CompletionCallback& callback) +- : next_state_(STATE_GENERATE_TARGET_PATH), ++ : next_state_(STATE_CHECK_DOWNLOAD_URL), + confirmation_reason_(DownloadConfirmationReason::NONE), + should_notify_extensions_(false), + create_target_directory_(false), +@@ -219,43 +218,6 @@ DownloadTargetDeterminer::Result + conflict_action_ = DownloadPathReservationTracker::OVERWRITE; + RecordDownloadPathGeneration( + DownloadPathGenerationEvent::USE_EXISTING_VIRTUAL_PATH, false); +- } else if (!is_forced_path) { +- // If we don't have a forced path, we should construct a path for the +- // download. Forced paths are only specified for programmatic downloads +- // (WebStore, Drag&Drop). Treat the path as a virtual path. We will +- // eventually determine whether this is a local path and if not, figure out +- // a local path. +- std::string suggested_filename = download_->GetSuggestedFilename(); +- if (suggested_filename.empty() && +- download_->GetMimeType() == "application/x-x509-user-cert") { +- suggested_filename = "user.crt"; +- } +- +- std::string default_filename( +- l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); +- base::FilePath generated_filename = net::GenerateFileName( +- download_->GetURL(), +- download_->GetContentDisposition(), +- GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset), +- suggested_filename, +- download_->GetMimeType(), +- default_filename); +- confirmation_reason_ = NeedsConfirmation(generated_filename); +- base::FilePath target_directory; +- if (confirmation_reason_ != DownloadConfirmationReason::NONE) { +- DCHECK(!download_prefs_->IsDownloadPathManaged()); +- // If the user is going to be prompted and the user has been prompted +- // before, then always prefer the last directory that the user selected. +- target_directory = download_prefs_->SaveFilePath(); +- RecordDownloadPathGeneration( +- DownloadPathGenerationEvent::USE_LAST_PROMPT_DIRECTORY, false); +- } else { +- target_directory = download_prefs_->DownloadPath(); +- RecordDownloadPathGeneration( +- DownloadPathGenerationEvent::USE_DEFAULTL_DOWNLOAD_DIRECTORY, false); +- } +- virtual_path_ = target_directory.Append(generated_filename); +- should_notify_extensions_ = true; + } else { + conflict_action_ = DownloadPathReservationTracker::OVERWRITE; + virtual_path_ = download_->GetForcedFilePath(); +@@ -278,15 +240,7 @@ DownloadTargetDeterminer::Result + DCHECK(!virtual_path_.empty()); + + next_state_ = STATE_RESERVE_VIRTUAL_PATH; +- +- if (!should_notify_extensions_ || +- download_->GetState() != DownloadItem::IN_PROGRESS) +- return CONTINUE; +- +- delegate_->NotifyExtensions(download_, virtual_path_, +- base::Bind(&DownloadTargetDeterminer::NotifyExtensionsDone, +- weak_ptr_factory_.GetWeakPtr())); +- return QUIT_DOLOOP; ++ return CONTINUE; + } + + void DownloadTargetDeterminer::NotifyExtensionsDone( +@@ -306,8 +260,7 @@ void DownloadTargetDeterminer::NotifyExtensionsDone( + // last_download_path/music/foo.mp3, then last_download_path will accumulate + // the subdirectory /music/ so that the next download may end up in + // Downloads/music/music/music/bar.mp3. +- base::FilePath new_path(download_prefs_->DownloadPath().Append( +- suggested_path).NormalizePathSeparators()); ++ base::FilePath new_path(suggested_path.NormalizePathSeparators()); + // Do not pass a mime type to GenerateSafeFileName so that it does not force + // the filename to have an extension if the (Chrome) extension does not + // suggest it. +@@ -327,7 +280,7 @@ DownloadTargetDeterminer::Result + DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(!virtual_path_.empty()); + +- next_state_ = STATE_PROMPT_USER_FOR_DOWNLOAD_PATH; ++ next_state_ = STATE_DETERMINE_LOCAL_PATH; + if (download_->GetState() != DownloadItem::IN_PROGRESS) + return CONTINUE; + +@@ -392,7 +345,6 @@ void DownloadTargetDeterminer::ReserveVirtualPathDone( + NOTREACHED(); + } + } +- + DoLoop(); + } + +@@ -439,7 +391,6 @@ void DownloadTargetDeterminer::RequestConfirmationDone( + confirmation_reason_ = DownloadConfirmationReason::NONE; + + virtual_path_ = virtual_path; +- download_prefs_->SetSaveFilePath(virtual_path_.DirName()); + DoLoop(); + } + +@@ -449,7 +400,7 @@ DownloadTargetDeterminer::Result + DCHECK(!virtual_path_.empty()); + DCHECK(local_path_.empty()); + +- next_state_ = STATE_DETERMINE_MIME_TYPE; ++ next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE; + + delegate_->DetermineLocalPath( + download_, +@@ -650,7 +601,7 @@ DownloadTargetDeterminer::Result + DownloadTargetDeterminer::DoCheckDownloadUrl() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(!virtual_path_.empty()); +- next_state_ = STATE_CHECK_VISITED_REFERRER_BEFORE; ++ next_state_ = STATE_RESERVE_VIRTUAL_PATH; + + // If user has validated a dangerous download, don't check. + if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED) +@@ -888,35 +839,12 @@ DownloadConfirmationReason DownloadTargetDeterminer::NeedsConfirmation( + return DownloadConfirmationReason::NONE; + } + +- // Don't ask where to save if the download path is managed. Even if the user +- // wanted to be prompted for "all" downloads, or if this was a 'Save As' +- // download. +- if (download_prefs_->IsDownloadPathManaged()) +- return DownloadConfirmationReason::NONE; +- + // Prompt if this is a 'Save As' download. + if (download_->GetTargetDisposition() == + DownloadItem::TARGET_DISPOSITION_PROMPT) + return DownloadConfirmationReason::SAVE_AS; + +-#if BUILDFLAG(ENABLE_EXTENSIONS) +- // Don't prompt for extension downloads. +- if (download_crx_util::IsExtensionDownload(*download_) || +- filename.MatchesExtension(extensions::kExtensionFileExtension)) +- return DownloadConfirmationReason::NONE; +-#endif +- +- // Don't prompt for file types that are marked for opening automatically. +- if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(filename)) +- return DownloadConfirmationReason::NONE; +- +- // For everything else, prompting is controlled by the PromptForDownload pref. +- // The user may still be prompted even if this pref is disabled due to, for +- // example, there being an unresolvable filename conflict or the target path +- // is not writeable. +- return download_prefs_->PromptForDownload() +- ? DownloadConfirmationReason::PREFERENCE +- : DownloadConfirmationReason::NONE; ++ return DownloadConfirmationReason::NONE; + } + + bool DownloadTargetDeterminer::HasPromptedForPath() const { +@@ -936,23 +864,12 @@ DownloadFileType::DangerLevel DownloadTargetDeterminer::GetDangerLevel( + !download_->GetForcedFilePath().empty()) + return DownloadFileType::NOT_DANGEROUS; + +- const bool is_extension_download = +- download_crx_util::IsExtensionDownload(*download_); +- + // User-initiated extension downloads from pref-whitelisted sources are not + // considered dangerous. +- if (download_->HasUserGesture() && +- is_extension_download && +- download_crx_util::OffStoreInstallAllowedByPrefs( +- GetProfile(), *download_)) { ++ if (download_->HasUserGesture()) { + return DownloadFileType::NOT_DANGEROUS; + } + +- // Anything the user has marked auto-open is OK if it's user-initiated. +- if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(virtual_path_) && +- download_->HasUserGesture()) +- return DownloadFileType::NOT_DANGEROUS; +- + DownloadFileType::DangerLevel danger_level = + safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( + virtual_path_.BaseName()); diff --git a/chrome/browser/importer/external_process_importer_client.h b/chrome/browser/importer/external_process_importer_client.h index 864a6951115dda5ed74963f18b35692960397d50..3e1a2b719521ac2c60bae05f94e409bc4c7da022 100644 --- a/chrome/browser/importer/external_process_importer_client.h @@ -201,6 +398,105 @@ index 247d24220beb7d176b890d7c2d45bdd2dfd8db99..c270bba0fabb557e8d3d1df8ac166bbb ProfileWriter* const writer_; // weak const base::WeakPtr host_; +diff --git a/chrome/browser/interstitials/chrome_metrics_helper.cc b/chrome/browser/interstitials/chrome_metrics_helper.cc +index 860c919d1a656acf63a5a0875484d59d5dd40515..35c9a27119148fbce09e70771d301a3817a932f2 100644 +--- a/chrome/browser/interstitials/chrome_metrics_helper.cc ++++ b/chrome/browser/interstitials/chrome_metrics_helper.cc +@@ -12,10 +12,6 @@ + #include "content/public/browser/web_contents.h" + #include "extensions/features/features.h" + +-#if BUILDFLAG(ENABLE_EXTENSIONS) +-#include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h" +-#endif +- + #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) + #include "chrome/browser/ssl/captive_portal_metrics_recorder.h" + #endif +@@ -59,58 +55,8 @@ void ChromeMetricsHelper::RecordExtraShutdownMetrics() { + + void ChromeMetricsHelper::RecordExtraUserDecisionMetrics( + security_interstitials::MetricsHelper::Decision decision) { +-#if BUILDFLAG(ENABLE_EXTENSIONS) +- if (!sampling_event_.get()) { +- sampling_event_.reset(new extensions::ExperienceSamplingEvent( +- sampling_event_name_, request_url_, +- web_contents_->GetLastCommittedURL(), +- web_contents_->GetBrowserContext())); +- } +- switch (decision) { +- case PROCEED: +- sampling_event_->CreateUserDecisionEvent( +- extensions::ExperienceSamplingEvent::kProceed); +- break; +- case DONT_PROCEED: +- sampling_event_->CreateUserDecisionEvent( +- extensions::ExperienceSamplingEvent::kDeny); +- break; +- case SHOW: +- case PROCEEDING_DISABLED: +- case MAX_DECISION: +- break; +- } +-#endif + } + + void ChromeMetricsHelper::RecordExtraUserInteractionMetrics( + security_interstitials::MetricsHelper::Interaction interaction) { +-#if BUILDFLAG(ENABLE_EXTENSIONS) +- if (!sampling_event_.get()) { +- sampling_event_.reset(new extensions::ExperienceSamplingEvent( +- sampling_event_name_, request_url_, +- web_contents_->GetLastCommittedURL(), +- web_contents_->GetBrowserContext())); +- } +- switch (interaction) { +- case SHOW_LEARN_MORE: +- sampling_event_->set_has_viewed_learn_more(true); +- break; +- case SHOW_ADVANCED: +- sampling_event_->set_has_viewed_details(true); +- break; +- case SHOW_PRIVACY_POLICY: +- case SHOW_DIAGNOSTIC: +- case RELOAD: +- case OPEN_TIME_SETTINGS: +- case TOTAL_VISITS: +- case SET_EXTENDED_REPORTING_ENABLED: +- case SET_EXTENDED_REPORTING_DISABLED: +- case EXTENDED_REPORTING_IS_ENABLED: +- case REPORT_PHISHING_ERROR: +- case SHOW_WHITEPAPER: +- case MAX_INTERACTION: +- break; +- } +-#endif + } +diff --git a/chrome/browser/interstitials/chrome_metrics_helper.h b/chrome/browser/interstitials/chrome_metrics_helper.h +index 641f7d9f74656271a9271c57bbd0f216ddc8dc0a..18e3785ee539d5a267f0a8a94784c1d1f7f3612a 100644 +--- a/chrome/browser/interstitials/chrome_metrics_helper.h ++++ b/chrome/browser/interstitials/chrome_metrics_helper.h +@@ -17,10 +17,6 @@ namespace content { + class WebContents; + } + +-namespace extensions { +-class ExperienceSamplingEvent; +-} +- + class CaptivePortalMetricsRecorder; + + // This class adds desktop-Chrome-specific metrics (extension experience +@@ -53,9 +49,6 @@ class ChromeMetricsHelper : public security_interstitials::MetricsHelper { + #endif + const GURL request_url_; + const std::string sampling_event_name_; +-#if BUILDFLAG(ENABLE_EXTENSIONS) +- std::unique_ptr sampling_event_; +-#endif + #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) + std::unique_ptr captive_portal_recorder_; + #endif diff --git a/chrome/browser/metrics/metrics_reporting_state.cc b/chrome/browser/metrics/metrics_reporting_state.cc index 183a1e7a246c01a1500a9a05e055f892deaffe56..5172ed442244f26a674c650705d96282ae6ec836 100644 --- a/chrome/browser/metrics/metrics_reporting_state.cc @@ -509,6 +805,104 @@ index 7ee1ec91e6ecb8cd9e237f0e67063ed704566ea6..9198607c50f23d7757016dcfb7526993 // Finds TabStripModel which has a WebContents whose id is the given // web_contents_id, and returns the WebContents index and the TabStripModel. int FindTabStripModelById(int64_t target_web_contents_id, +diff --git a/chrome/browser/safe_browsing/download_protection/check_client_download_request.cc b/chrome/browser/safe_browsing/download_protection/check_client_download_request.cc +index ea9b0d6e9c8666c91cf2704915da95d682d633d2..a1032d258a02ae66dbbeca8a362afab5a39d837e 100644 +--- a/chrome/browser/safe_browsing/download_protection/check_client_download_request.cc ++++ b/chrome/browser/safe_browsing/download_protection/check_client_download_request.cc +@@ -290,11 +290,6 @@ bool CheckClientDownloadRequest::IsSupportedDownload( + *reason = final_url.has_host() ? REASON_REMOTE_FILE : REASON_LOCAL_FILE; + return false; + } +- // This check should be last, so we know the earlier checks passed. +- if (!FileTypePolicies::GetInstance()->IsCheckedBinaryFile(target_path)) { +- *reason = REASON_NOT_BINARY_FILE; +- return false; +- } + *type = download_protection_util::GetDownloadType(target_path); + return true; + } +diff --git a/chrome/browser/safe_browsing/download_protection/download_url_sb_client.cc b/chrome/browser/safe_browsing/download_protection/download_url_sb_client.cc +index 9763c38c680c69044ed89c89ea09e10255439fcb..3d6b7015996c864f86209650db00c65bcad942cd 100644 +--- a/chrome/browser/safe_browsing/download_protection/download_url_sb_client.cc ++++ b/chrome/browser/safe_browsing/download_protection/download_url_sb_client.cc +@@ -120,8 +120,6 @@ void DownloadUrlSBClient::ReportMalware(SBThreatType threat_type) { + hit_report.extended_reporting_level = extended_reporting_level_; + hit_report.is_metrics_reporting_active = + ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); +- +- ui_manager_->MaybeReportSafeBrowsingHit(hit_report, item_->GetWebContents()); + } + + void DownloadUrlSBClient::IdentifyReferrerChain() { +diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +index 5b50863736f2306202e8345d83be2f399ed2c371..655cb90ef69156802b1f227f7f31210c6d83beae 100644 +--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ++++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +@@ -194,20 +194,6 @@ void SafeBrowsingBlockingPage::FinishThreatDetails(const base::TimeDelta& delay, + // shutting down. + if (!g_browser_process->safe_browsing_service()) + return; +- +- // Finish computing threat details. TriggerManager will decide if its safe to +- // send the report. +- bool report_sent = g_browser_process->safe_browsing_service() +- ->trigger_manager() +- ->FinishCollectingThreatDetails( +- TriggerType::SECURITY_INTERSTITIAL, web_contents(), +- delay, did_proceed, num_visits, +- sb_error_ui()->get_error_display_options()); +- +- if (report_sent) { +- controller()->metrics_helper()->RecordUserInteraction( +- security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); +- } + } + + // static +diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc +index b30ec89669e6734f1f319d49ac2568858685a30f..a349124807aa0725a25aefc0bc0804cb9af7f1db 100644 +--- a/chrome/browser/safe_browsing/safe_browsing_service.cc ++++ b/chrome/browser/safe_browsing/safe_browsing_service.cc +@@ -469,17 +469,13 @@ void SafeBrowsingService::Observe(int type, + case chrome::NOTIFICATION_PROFILE_CREATED: { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + Profile* profile = content::Source(source).ptr(); +- services_delegate_->CreatePasswordProtectionService(profile); +- if (!profile->IsOffTheRecord()) +- AddPrefService(profile->GetPrefs()); ++ AddPrefService(profile->GetPrefs()); + break; + } + case chrome::NOTIFICATION_PROFILE_DESTROYED: { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + Profile* profile = content::Source(source).ptr(); +- services_delegate_->RemovePasswordProtectionService(profile); +- if (!profile->IsOffTheRecord()) +- RemovePrefService(profile->GetPrefs()); ++ RemovePrefService(profile->GetPrefs()); + break; + } + default: +diff --git a/chrome/browser/safe_browsing/services_delegate_impl.cc b/chrome/browser/safe_browsing/services_delegate_impl.cc +index d3814b98f3590ea9a888d654a35dae7ecaac04a1..53cffdc8e82045ba7dd830fac45e70e27325dc3a 100644 +--- a/chrome/browser/safe_browsing/services_delegate_impl.cc ++++ b/chrome/browser/safe_browsing/services_delegate_impl.cc +@@ -183,14 +183,7 @@ void ServicesDelegateImpl::StopOnIOThread(bool shutdown) { + } + + void ServicesDelegateImpl::CreatePasswordProtectionService(Profile* profile) { +- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +- DCHECK(profile); +- auto it = password_protection_service_map_.find(profile); +- DCHECK(it == password_protection_service_map_.end()); +- std::unique_ptr service = +- base::MakeUnique(safe_browsing_service_, +- profile); +- password_protection_service_map_[profile] = std::move(service); ++ return; + } + + void ServicesDelegateImpl::RemovePasswordProtectionService(Profile* profile) { diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn index 476a165dd2b1f4d724c3b2a5d8fd30b994d1dd05..d9dd99e293a4adcd357927023f38f289718bdfad 100644 --- a/chrome/common/BUILD.gn @@ -1814,6 +2208,19 @@ index bf0ece1e723ba1a0644961cfd3a01ce3c14c892a..5e7d3dbb9da51a5abb0447bc04c90c9b HolderIsFirstArgument); } static void SetAsFunctionHandler(v8::Isolate* isolate, +diff --git a/google_apis/google_api_keys.cc b/google_apis/google_api_keys.cc +index 2e8437ed136e682540835ef4738e3519f9cb6051..4ec8bd06b4ee76a398947540c76e2450ed4cdcca 100644 +--- a/google_apis/google_api_keys.cc ++++ b/google_apis/google_api_keys.cc +@@ -28,7 +28,7 @@ + + // Used to indicate an unset key/id/secret. This works better with + // various unit tests than leaving the token empty. +-#define DUMMY_API_TOKEN "dummytoken" ++#define DUMMY_API_TOKEN "AIzaSyAH90V94EcZBP5oH7oc-mXQrSKgASVxER8" + + #if !defined(GOOGLE_API_KEY) + #define GOOGLE_API_KEY DUMMY_API_TOKEN diff --git a/media/base/media_switches.cc b/media/base/media_switches.cc index f1a096e649290ef2e2ce2cc30891f547a6dc196f..1338eb43287476a108454e316dbfb853c000f1b4 100644 --- a/media/base/media_switches.cc