From 66439d79773b97dd5d4aac97ab49e4885a4c96b4 Mon Sep 17 00:00:00 2001 From: Pranjal Date: Mon, 26 Mar 2018 13:59:25 -0700 Subject: [PATCH] Enable Safe Browsing API in muon --- atom/browser/BUILD.gn | 1 + atom/browser/api/atom_api_dialog.cc | 27 +- atom/browser/api/atom_api_download_item.cc | 14 +- atom/browser/api/atom_api_download_item.h | 5 + .../browser/atom_download_manager_delegate.cc | 339 +++++++++++++++--- atom/browser/atom_download_manager_delegate.h | 62 +++- .../atom_resource_dispatcher_host_delegate.cc | 66 +++- .../atom_resource_dispatcher_host_delegate.h | 25 ++ .../atom_extensions_browser_client.cc | 2 - brave/brave_resources.grd | 1 + brave/browser/brave_browser_context.cc | 9 +- brave/browser/brave_browser_context.h | 7 +- brave/browser/brave_content_browser_client.cc | 4 +- .../brave_password_manager_client.cc | 5 +- .../brave_password_manager_client.h | 5 +- chromium_src/BUILD.gn | 54 ++- .../chrome/browser/browser_process_impl.cc | 38 +- .../chrome_download_manager_delegate.cc | 7 + .../browser/download/download_commands.cc | 11 + .../download/download_core_service_factory.cc | 7 + .../browser/download/download_crx_util.cc | 19 + .../browser/download/download_history.cc | 8 + .../browser/download/download_item_model.cc | 5 + .../experience_sampling.cc | 12 + .../chrome/browser/interstitials/BUILD.gn | 13 + .../interstitials/chrome_metrics_helper.cc | 44 +++ .../permissions/permission_uma_util.cc | 4 + .../chrome/browser/prerender/BUILD.gn | 2 + .../browser/prerender/prerender_contents.cc | 2 + .../chrome/browser/profiles/profile.h | 2 + .../chrome/browser/safe_browsing/BUILD.gn | 66 +++- .../password_reuse_modal_warning_dialog.cc | 15 + .../safe_browsing/safe_browsing_service.cc | 21 -- chromium_src/chrome/browser/signin/BUILD.gn | 14 + .../browser/signin/signin_manager_factory.cc | 13 + .../sync/user_event_service_factory.cc | 15 + chromium_src/chrome/browser/ui/browser.h | 1 + .../chrome/browser/ui/browser_commands.cc | 9 + .../hosted_app_browser_controller.cc | 7 + .../browser/ui/page_info/page_info_ui.cc | 6 + muon/browser/muon_browser_process_impl.cc | 1 + 41 files changed, 829 insertions(+), 139 deletions(-) create mode 100644 chromium_src/chrome/browser/download/chrome_download_manager_delegate.cc create mode 100644 chromium_src/chrome/browser/download/download_commands.cc create mode 100644 chromium_src/chrome/browser/download/download_core_service_factory.cc create mode 100644 chromium_src/chrome/browser/download/download_crx_util.cc create mode 100644 chromium_src/chrome/browser/download/download_history.cc create mode 100644 chromium_src/chrome/browser/download/download_item_model.cc create mode 100644 chromium_src/chrome/browser/extensions/api/experience_sampling_private/experience_sampling.cc create mode 100644 chromium_src/chrome/browser/interstitials/BUILD.gn create mode 100644 chromium_src/chrome/browser/interstitials/chrome_metrics_helper.cc create mode 100644 chromium_src/chrome/browser/permissions/permission_uma_util.cc create mode 100644 chromium_src/chrome/browser/safe_browsing/password_reuse_modal_warning_dialog.cc delete mode 100644 chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc create mode 100644 chromium_src/chrome/browser/signin/BUILD.gn create mode 100644 chromium_src/chrome/browser/signin/signin_manager_factory.cc create mode 100644 chromium_src/chrome/browser/sync/user_event_service_factory.cc create mode 100644 chromium_src/chrome/browser/ui/browser_commands.cc create mode 100644 chromium_src/chrome/browser/ui/extensions/hosted_app_browser_controller.cc create mode 100644 chromium_src/chrome/browser/ui/page_info/page_info_ui.cc diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index 0e367dbbdc..0d667a68ad 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -11,6 +11,7 @@ source_set("browser") { public_deps = [ "//content/public/browser", "//content/public/common", + "//net", "//electron/vendor/brightray:browser", "//ui/events", "//components/security_state/content", diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index d1c28d3658..8ea4fca139 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -87,23 +87,6 @@ struct Converter { namespace { -// Consider downloads 'dangerous' if they go to the home directory on Linux and -// to the desktop on any platform. -bool DownloadPathIsDangerous(const base::FilePath& download_path) { -#if defined(OS_LINUX) - base::FilePath home_dir = base::GetHomeDir(); - if (download_path == home_dir) { - return true; - } -#endif - base::FilePath desktop_dir; - if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_dir)) { - NOTREACHED(); - return false; - } - return (download_path == desktop_dir); -} - void ShowMessageBox(int type, const std::vector& buttons, int default_id, @@ -173,12 +156,10 @@ void ShowDialog(const file_dialog::DialogSettings& settings, NOTREACHED(); } } - if (DownloadPathIsDangerous(default_path)) { - // This is only useful on platforms that support - // DIR_DEFAULT_DOWNLOADS_SAFE. - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &default_path)) { - NOTREACHED(); - } + // This is only useful on platforms that support + // DIR_DEFAULT_DOWNLOADS_SAFE. + if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &default_path)) { + NOTREACHED(); } file_type_info.include_all_files = settings.include_all_files; file_type_info.extension_description_overrides = diff --git a/atom/browser/api/atom_api_download_item.cc b/atom/browser/api/atom_api_download_item.cc index 569af620dd..4894569939 100644 --- a/atom/browser/api/atom_api_download_item.cc +++ b/atom/browser/api/atom_api_download_item.cc @@ -12,6 +12,7 @@ #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/public/browser/download_item.h" #include "native_mate/dictionary.h" #include "net/base/filename_util.h" @@ -78,9 +79,10 @@ DownloadItem::~DownloadItem() { } void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) { - if (download_item_->IsDone()) { + if (download_item_->IsDangerous()) { + Emit("dangerous"); + } else if (download_item_->IsDone()) { Emit("done", item->GetState()); - // Destroy the item once item is downloaded. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, GetDestroyClosure()); @@ -89,6 +91,10 @@ void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) { } } +DownloadDangerType DownloadItem::GetDangerType() const { + return download_item_->GetDangerType(); +} + void DownloadItem::OnDownloadRemoved(content::DownloadItem* download) { Emit("removed"); } @@ -164,6 +170,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..30de34fdc1 100644 --- a/atom/browser/api/atom_api_download_item.h +++ b/atom/browser/api/atom_api_download_item.h @@ -9,6 +9,7 @@ #include "atom/browser/api/trackable_object.h" #include "base/files/file_path.h" +#include "content/public/browser/download_danger_type.h" #include "content/public/browser/download_item.h" #include "native_mate/handle.h" #include "url/gurl.h" @@ -17,6 +18,8 @@ namespace atom { namespace api { +using content::DownloadDangerType; + class DownloadItem : public mate::TrackableObject, public content::DownloadItem::Observer { public: @@ -46,6 +49,8 @@ class DownloadItem : public mate::TrackableObject, std::string GetGuid() const; void SetPrompt(bool prompt); bool ShouldPrompt(); + bool IsDangerous() const; + DownloadDangerType GetDangerType() 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 c980648b3f..77651205f1 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -5,17 +5,24 @@ #include "atom/browser/atom_download_manager_delegate.h" #include +#include #include #include "atom/browser/native_window.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/extensions/api/file_system/file_entry_picker.h" #include "chrome/browser/profiles/profile.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 "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 "net/base/mime_util.h" @@ -25,10 +32,33 @@ 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 char kSafeBrowsingUserDataKey[] = "Safe Browsing ID"; + +void CheckDownloadUrlDone( + const DownloadTargetDeterminerDelegate::CheckDownloadUrlCallback& callback, + safe_browsing::DownloadCheckResult result) { + if (result == safe_browsing::DownloadCheckResult::SAFE || + result == safe_browsing::DownloadCheckResult::UNKNOWN) { + callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); + } else { + callback.Run(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); + } +} +#endif // FULL_SAFE_BROWSING + const DownloadPathReservationTracker::FilenameConflictAction kDefaultPlatformConflictAction = DownloadPathReservationTracker::UNIQUIFY; -NativeWindow* GetNativeWindowFromWebContents(content::WebContents* web_contents) { +NativeWindow* GetNativeWindowFromWebContents(content::WebContents* web_contents) +{ DCHECK(web_contents); auto relay = NativeWindowRelay::FromWebContents(web_contents); return relay ? relay->window.get() : nullptr; @@ -43,9 +73,185 @@ void CloseWebContentsIfNeeded(content::WebContents* web_contents) { } // namespace +void AtomDownloadManagerDelegate::RequestConfirmation( + DownloadItem* download, + const base::FilePath& suggested_path, + DownloadConfirmationReason reason, + const DownloadTargetDeterminerDelegate::ConfirmationCallback& callback) { + callback.Run(DownloadConfirmationResult::CONTINUE_WITHOUT_CONFIRMATION, + suggested_path); +} + +bool AtomDownloadManagerDelegate::IsDownloadReadyForCompletion( + DownloadItem* item, + const base::Closure& internal_complete_callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(FULL_SAFE_BROWSING) + DownloadCompletionBlocker* state = static_cast( + item->GetUserData(&kSafeBrowsingUserDataKey)); + if (!state) { + // Begin the safe browsing download protection check. + DownloadProtectionService* service = GetDownloadProtectionService(); + if (service) { + state = new DownloadCompletionBlocker(); + 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)) { + item->OnContentCheckCompleted( + content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); + + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + internal_complete_callback); + return false; + } + } else if (!state->is_complete()) { + state->set_callback(internal_complete_callback); + return false; + } + +#endif + return true; +} + +bool AtomDownloadManagerDelegate::GenerateFileHash() { +#if defined(FULL_SAFE_BROWSING) + Profile* profile = static_cast( + download_manager_->GetBrowserContext()); + return profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) + && g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); +#else + return false; +#endif +} + +DownloadProtectionService* + AtomDownloadManagerDelegate::GetDownloadProtectionService() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +#if defined(FULL_SAFE_BROWSING) + Profile* profile = static_cast( + download_manager_->GetBrowserContext()); + + safe_browsing::SafeBrowsingService* sb_service = + g_browser_process->safe_browsing_service(); + if (sb_service && sb_service->download_protection_service() && + profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { + 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) { + 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; + + 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: + if (DownloadItemModel(item).GetDangerLevel() != + DownloadFileType::NOT_DANGEROUS) { + danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; + } + break; + case safe_browsing::DownloadCheckResult::SAFE: + 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; + } + + if (danger_type != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { + item->OnContentCheckCompleted( + danger_type, + content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); + } + } + + DownloadCompletionBlocker* state = static_cast( + item->GetUserData(&kSafeBrowsingUserDataKey)); + state->CompleteDownload(); +} +#endif // FULL_SAFE_BROWSING + AtomDownloadManagerDelegate::AtomDownloadManagerDelegate( content::DownloadManager* manager) : download_manager_(manager), + download_prefs_(new DownloadPrefs( + static_cast(manager->GetBrowserContext()))), weak_ptr_factory_(this) {} AtomDownloadManagerDelegate::~AtomDownloadManagerDelegate() { @@ -57,7 +263,7 @@ AtomDownloadManagerDelegate::~AtomDownloadManagerDelegate() { } } -void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item, +void AtomDownloadManagerDelegate::GetItemSavePath(DownloadItem* item, base::FilePath* path) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); @@ -94,6 +300,7 @@ bool AtomDownloadManagerDelegate::GetExtension( void AtomDownloadManagerDelegate:: OnDownloadItemSelected( const content::DownloadTargetCallback& callback, + std::unique_ptr target_info, api::DownloadItem* download_item, const std::vector& paths) { DCHECK(!paths.empty()); @@ -106,29 +313,58 @@ void AtomDownloadManagerDelegate:: OnDownloadItemSelected( download_item->SetSavePath(paths[0]); callback.Run(paths[0], - content::DownloadItem::TARGET_DISPOSITION_PROMPT, - content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, paths[0], - content::DOWNLOAD_INTERRUPT_REASON_NONE); + target_info->target_disposition, + target_info->danger_type, paths[0], + target_info->result); } void AtomDownloadManagerDelegate::OnDownloadItemSelectionCancelled( const content::DownloadTargetCallback& callback, - content::DownloadItem* item) { + DownloadItem* item) { item->Remove(); base::FilePath path; callback.Run(path, - content::DownloadItem::TARGET_DISPOSITION_PROMPT, + DownloadItem::TARGET_DISPOSITION_PROMPT, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path, content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); } -void AtomDownloadManagerDelegate::OnDownloadPathGenerated( +void AtomDownloadManagerDelegate::DetermineLocalPath( + DownloadItem* download, + const base::FilePath& virtual_path, + const DownloadTargetDeterminerDelegate::LocalPathCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + callback.Run(virtual_path); +} + +void AtomDownloadManagerDelegate::NotifyExtensions( + DownloadItem* download, + const base::FilePath& virtual_path, + const NotifyExtensionsCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + DCHECK(!download->IsTransient()); + callback.Run(base::FilePath(), DownloadPathReservationTracker::UNIQUIFY); +} + +std::string GetMimeType(const base::FilePath& path) { + std::string mime_type; + net::GetMimeTypeFromFile(path, &mime_type); + return mime_type; +} + +void AtomDownloadManagerDelegate::GetFileMimeType( + const base::FilePath& path, + const GetFileMimeTypeCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + base::PostTaskWithTraitsAndReplyWithResult( + FROM_HERE, {base::MayBlock()}, base::Bind(&GetMimeType, path), callback); +} + +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; @@ -142,11 +378,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; GetItemSavePath(item, &path); @@ -176,32 +408,25 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( // Show save dialog if save path was not set already on item ui::SelectFileDialog::FileTypeInfo file_type_info; - if (path.empty()) { - std::vector extensions; - base::FilePath::StringType extension; - if (GetExtension(item, target_path, &extension)) { - extensions.push_back(extension); - file_type_info.extensions.push_back(extensions); - } - file_type_info.include_all_files = true; - new extensions::FileEntryPicker( + std::vector extensions; + base::FilePath::StringType extension; + + if (GetExtension(item, path, &extension)) { + extensions.push_back(extension); + file_type_info.extensions.push_back(extensions); + } + file_type_info.include_all_files = true; + + new extensions::FileEntryPicker( window->inspectable_web_contents()->GetWebContents(), - target_path, + path, file_type_info, ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::Bind(&AtomDownloadManagerDelegate::OnDownloadItemSelected, - base::Unretained(this), callback, download_item), + base::Unretained(this), callback, + base::Passed(std::move(target_info)), download_item), base::Bind(&AtomDownloadManagerDelegate::OnDownloadItemSelectionCancelled, base::Unretained(this), callback, item)); - } else { - if (download_item) - download_item->SetSavePath(path); - - callback.Run(path, - content::DownloadItem::TARGET_DISPOSITION_PROMPT, - content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path, - content::DOWNLOAD_INTERRUPT_REASON_NONE); - } } void AtomDownloadManagerDelegate::Shutdown() { @@ -210,7 +435,7 @@ void AtomDownloadManagerDelegate::Shutdown() { } bool AtomDownloadManagerDelegate::DetermineDownloadTarget( - content::DownloadItem* download, + DownloadItem* download, const content::DownloadTargetCallback& callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -219,8 +444,6 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget( base::FilePath default_download_path(browser_context->GetPrefs()->GetFilePath( prefs::kDownloadDefaultDirectory)); - DownloadPathReservationTracker::FilenameConflictAction conflict_action = - DownloadPathReservationTracker::OVERWRITE; base::FilePath virtual_path = download->GetForcedFilePath(); if (virtual_path.empty()) { @@ -238,32 +461,48 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget( download->GetMimeType(), std::string()); - conflict_action = kDefaultPlatformConflictAction; 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, download_prefs_.get(), this, + target_determined_callback); + return true; } +void AtomDownloadManagerDelegate::ReserveVirtualPath( + DownloadItem* download, + const base::FilePath& virtual_path, + bool create_directory, + DownloadPathReservationTracker::FilenameConflictAction conflict_action, + const ReservedPathCallback& callback) { + DownloadPathReservationTracker::GetReservedPath( + download, + virtual_path, + download_prefs_->DownloadPath(), + true, + conflict_action, + callback); +} + bool AtomDownloadManagerDelegate::ShouldOpenDownload( - content::DownloadItem* download, + DownloadItem* download, const content::DownloadOpenDelayedCallback& callback) { return true; } void AtomDownloadManagerDelegate::GetNextId( const content::DownloadIdCallback& callback) { - static uint32_t next_id = content::DownloadItem::kInvalidId + 1; + static uint32_t next_id = DownloadItem::kInvalidId + 1; callback.Run(next_id++); } diff --git a/atom/browser/atom_download_manager_delegate.h b/atom/browser/atom_download_manager_delegate.h index a43a8a0958..7efd91f2ab 100644 --- a/atom/browser/atom_download_manager_delegate.h +++ b/atom/browser/atom_download_manager_delegate.h @@ -5,30 +5,42 @@ #ifndef ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_ #define ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_ +#include #include #include #include "atom/browser/api/atom_api_download_item.h" #include "base/memory/weak_ptr.h" +#include "base/strings/utf_string_conversions.h" +#include "base/task_scheduler/post_task.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( + bool GenerateFileHash() 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; @@ -39,9 +51,41 @@ 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: - // Get the save path set on the associated api::DownloadItem object + bool IsDownloadReadyForCompletion( + content::DownloadItem* item, + const base::Closure& internal_complete_callback); + void GetItemSavePath(content::DownloadItem* item, base::FilePath* path); bool GetExtension(content::DownloadItem* item, @@ -49,6 +93,7 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate { base::FilePath::StringType* extension); void OnDownloadItemSelected(const content::DownloadTargetCallback& callback, + std::unique_ptr target_info, api::DownloadItem* download_item, const std::vector& paths); @@ -56,8 +101,15 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate { const content::DownloadTargetCallback& callback, content::DownloadItem* item); + void CheckClientDownloadDone(uint32_t download_id, + safe_browsing::DownloadCheckResult result); + + void ShouldCompleteDownloadInternal( + uint32_t download_id, + const base::Closure& user_complete_callback); content::DownloadManager* download_manager_; + std::unique_ptr download_prefs_; base::WeakPtrFactory weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(AtomDownloadManagerDelegate); diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 69cae4df65..361c713755 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -10,8 +10,14 @@ #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/safe_browsing_resource_throttle.h" +#include "chrome/browser/safe_browsing/safe_browsing_service.h" +#include "components/offline_pages/features/features.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_frame_host.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" @@ -25,6 +31,8 @@ #endif using content::BrowserThread; +using content::ResourceRequestInfo; +using content::ResourceType; namespace atom { @@ -79,12 +87,66 @@ 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 (!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) { + + content::ResourceThrottle* first_throttle = NULL; + +#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( const GURL& url, - content::ResourceRequestInfo* info) { + ResourceRequestInfo* info) { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(&HandleExternalProtocolInUI, url, 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/atom/browser/extensions/atom_extensions_browser_client.cc b/atom/browser/extensions/atom_extensions_browser_client.cc index 32c1a5560d..8c52275245 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.cc +++ b/atom/browser/extensions/atom_extensions_browser_client.cc @@ -69,8 +69,6 @@ #include "chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h" #include "extensions/common/file_util.h" #include "net/url_request/url_request_simple_job.h" - - #include "electron/brave/common/extensions/api/generated_api_registration.h" #include "extensions/browser/api/generated_api_registration.h" diff --git a/brave/brave_resources.grd b/brave/brave_resources.grd index 7773bfad00..6ebe2b6ada 100644 --- a/brave/brave_resources.grd +++ b/brave/brave_resources.grd @@ -23,6 +23,7 @@ + diff --git a/brave/browser/brave_browser_context.cc b/brave/browser/brave_browser_context.cc index be847b7deb..9b6a20a07f 100644 --- a/brave/browser/brave_browser_context.cc +++ b/brave/browser/brave_browser_context.cc @@ -18,6 +18,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" +#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_paths.h" @@ -36,6 +37,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" @@ -438,10 +440,6 @@ void BraveBrowserContext::CreateProfilePrefs( extension_prefs, overlay_pref_names, std::move(delegate))); user_prefs::UserPrefs::Set(this, user_prefs_.get()); } else { - base::FilePath download_dir; - PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir); - pref_registry_->RegisterFilePathPref(prefs::kDownloadDefaultDirectory, - download_dir); pref_registry_->RegisterDictionaryPref("app_state"); pref_registry_->RegisterDictionaryPref( extensions::pref_names::kPrefContentSettings); @@ -453,6 +451,8 @@ void BraveBrowserContext::CreateProfilePrefs( pref_registry_->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels); pref_registry_->RegisterBooleanPref(prefs::kPrintingEnabled, true); pref_registry_->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false); + safe_browsing::RegisterProfilePrefs(pref_registry_.get()); + DownloadPrefs::RegisterProfilePrefs(pref_registry_.get()); #if BUILDFLAG(ENABLE_PLUGINS) PluginInfoHostImpl::RegisterUserPrefs(pref_registry_.get()); PepperFlashSettingsManager::RegisterProfilePrefs(pref_registry_.get()); @@ -728,4 +728,3 @@ AtomBrowserContext* AtomBrowserContext::From( } } // namespace atom - diff --git a/brave/browser/brave_browser_context.h b/brave/browser/brave_browser_context.h index 6824e101cf..36e52a380e 100644 --- a/brave/browser/brave_browser_context.h +++ b/brave/browser/brave_browser_context.h @@ -100,11 +100,12 @@ class BraveBrowserContext : public Profile { sync_preferences::PrefServiceSyncable* user_prefs() const { return user_prefs_.get(); } - sync_preferences::PrefServiceSyncable* GetPrefs() { - return user_prefs_.get(); } + sync_preferences::PrefServiceSyncable* GetPrefs() override { + return const_cast( + static_cast(this)->GetPrefs()); } const sync_preferences::PrefServiceSyncable* GetPrefs() const override { - return static_cast(this)->GetPrefs(); + return user_prefs_.get(); } PrefChangeRegistrar* user_prefs_change_registrar() const override { diff --git a/brave/browser/brave_content_browser_client.cc b/brave/browser/brave_content_browser_client.cc index 0a651870e6..6bad67b218 100644 --- a/brave/browser/brave_content_browser_client.cc +++ b/brave/browser/brave_content_browser_client.cc @@ -650,7 +650,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 a3b295fd3a..43c3ff8709 100644 --- a/brave/browser/password_manager/brave_password_manager_client.cc +++ b/brave/browser/password_manager/brave_password_manager_client.cc @@ -404,8 +404,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 c0e3258c64..703ec69e56 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 73bde456d3..d17f24899e 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -56,7 +56,6 @@ source_set("app") { deps = [ "//base", "//chrome/common", - "//components/metrics", "//components/crash/content/app", "//components/crash/content/browser", "//content/public/common", @@ -104,6 +103,8 @@ source_set("renderer") { configs += [ ":chromium_src_config" ] sources = [ + "//chrome/browser/renderer_preferences_util.cc", + "//chrome/browser/renderer_preferences_util.h", "chrome/renderer/content_settings_observer.cc", "chrome/renderer/content_settings_observer.h", ] @@ -145,6 +146,7 @@ source_set("browser") { ":history", ":metrics", ":password_manager", + ":permissions", ":sessions", ":web_data", "chrome/browser/safe_browsing", @@ -153,6 +155,7 @@ source_set("browser") { "//chrome/common", "//chrome/common:service_process_mojom", "//chrome/utility", + "//components/certificate_reporting:cert_logger_proto", "//components/certificate_transparency", "//components/crash/content/app", "//components/crash/core/browser", @@ -165,7 +168,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", @@ -204,6 +206,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", @@ -263,7 +267,8 @@ source_set("browser") { "chrome/browser/ui/chrome_select_file_policy.cc", "//chrome/browser/ui/cocoa/ui_localizer.h", "//chrome/browser/ui/cocoa/ui_localizer.mm", - + "//chrome/browser/ui/pdf/adobe_reader_info_win.cc", + "//chrome/browser/ui/pdf/adobe_reader_info_win.h", "chrome/browser/ui/profile_error_dialog.cc", "//chrome/browser/ui/web_contents_sizer.cc", @@ -531,6 +536,8 @@ source_set("browser") { "//chrome/browser/extensions/extension_tab_util.h", "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc", "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h", + "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.cc", + "//chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h", "chrome/browser/extensions/api/messaging/incognito_connectability.cc", "//chrome/browser/extensions/api/messaging/incognito_connectability.h", "//chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc", @@ -622,6 +629,16 @@ source_set("browser") { } } +source_set("permissions") { + configs += [ "//electron/build:electron_config" ] + configs += [ ":chromium_src_config" ] + + sources = [ + "chrome/browser/permissions/permission_uma_util.cc", + "//chrome/browser/permissions/permission_uma_util.h", + ] +} + source_set("crashes_ui") { configs += [ "//electron/build:electron_config" ] configs += [ ":chromium_src_config" ] @@ -773,8 +790,10 @@ source_set("sync") { configs += [ ":chromium_src_config" ] sources = [ + "//chrome/browser/sync/user_event_service_factory.h", "chrome/browser/sync/glue/sync_start_util.cc", - "chrome/browser/sync/profile_sync_service_factory.cc" + "chrome/browser/sync/profile_sync_service_factory.cc", + "chrome/browser/sync/user_event_service_factory.cc", ] deps = [ @@ -884,8 +903,16 @@ source_set("downloads") { "//chrome/browser/background_fetch/background_fetch_delegate_impl.h", "//chrome/browser/background_fetch/background_fetch_download_client.cc", "//chrome/browser/background_fetch/background_fetch_download_client.h", + "chrome/browser/download/chrome_download_manager_delegate.cc", + "//chrome/browser/download/chrome_download_manager_delegate.h", + "chrome/browser/download/download_commands.cc", + "//chrome/browser/download/download_commands.h", "chrome/browser/download/download_core_service.cc", "//chrome/browser/download/download_core_service.h", + "chrome/browser/download/download_core_service_factory.cc", + "//chrome/browser/download/download_core_service_factory.h", + "chrome/browser/download/download_history.cc", + "//chrome/browser/download/download_history.h", "//chrome/browser/download/download_path_reservation_tracker.cc", "//chrome/browser/download/download_path_reservation_tracker.h", "chrome/browser/download/download_request_limiter.cc", @@ -894,6 +921,23 @@ source_set("downloads") { "//chrome/browser/download/download_service_factory.h", "//chrome/browser/download/download_task_scheduler_impl.cc", "//chrome/browser/download/download_task_scheduler_impl.h", + "//chrome/browser/download/download_completion_blocker.cc", + "//chrome/browser/download/download_completion_blocker.h", + "chrome/browser/download/download_crx_util.cc", + "//chrome/browser/download/download_crx_util.h", + "//chrome/browser/download/download_item_model.cc", + "//chrome/browser/download/download_item_model.h", + "//chrome/browser/download/download_prefs.cc", + "//chrome/browser/download/download_prefs.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", + "//chrome/browser/download/trusted_sources_manager.cc", + "//chrome/browser/download/trusted_sources_manager.h", + "//chrome/browser/download/trusted_sources_manager_win.cc", ] deps = [ @@ -1101,6 +1145,8 @@ source_set("tab_manager") { "//chrome/browser/memory_details_win.cc", "//chrome/browser/ui/browser_tab_strip_tracker.cc", "//chrome/browser/ui/browser_tab_strip_tracker.h", + "chrome/browser/ui/page_info/page_info_ui.cc", + "//chrome/browser/ui/page_info/page_info_ui.h", "chrome/browser/ui/tab_contents/core_tab_helper.cc", "//chrome/browser/ui/tab_contents/core_tab_helper.h", "//chrome/browser/ui/tabs/tab_strip_model.cc", diff --git a/chromium_src/chrome/browser/browser_process_impl.cc b/chromium_src/chrome/browser/browser_process_impl.cc index fb738d8a84..b690fb92ad 100644 --- a/chromium_src/chrome/browser/browser_process_impl.cc +++ b/chromium_src/chrome/browser/browser_process_impl.cc @@ -230,6 +230,9 @@ void BrowserProcessImpl::StartTearDown() { DCHECK(IsShuttingDown()); browser_shutdown::SetTryingToQuit(true); + + if (safe_browsing_service_.get()) + safe_browsing_service()->ShutDown(); for (content::RenderProcessHost::iterator i( content::RenderProcessHost::AllHostsIterator()); @@ -248,6 +251,31 @@ void BrowserProcessImpl::StartTearDown() { } } +safe_browsing::SafeBrowsingService* + BrowserProcessImpl::safe_browsing_service() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (!created_safe_browsing_service_) + CreateSafeBrowsingService(); + return safe_browsing_service_.get(); +} + +safe_browsing::ClientSideDetectionService* + BrowserProcessImpl::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 BrowserProcessImpl::CreateSafeBrowsingService() { + DCHECK(!safe_browsing_service_); + created_safe_browsing_service_ = true; + safe_browsing_service_ = + safe_browsing::SafeBrowsingService::CreateSafeBrowsingService(); + safe_browsing_service_->Initialize(); +} + + void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) { locale_ = locale; brave::BraveContentBrowserClient::SetApplicationLocale(locale); @@ -655,16 +683,6 @@ void BrowserProcessImpl::set_background_mode_manager_for_test( NOTIMPLEMENTED(); } -safe_browsing::SafeBrowsingService* -BrowserProcessImpl::safe_browsing_service() { - return nullptr; -} - -safe_browsing::ClientSideDetectionService* -BrowserProcessImpl::safe_browsing_detection_service() { - return nullptr; -} - subresource_filter::ContentRulesetService* BrowserProcessImpl::subresource_filter_ruleset_service() { NOTIMPLEMENTED(); diff --git a/chromium_src/chrome/browser/download/chrome_download_manager_delegate.cc b/chromium_src/chrome/browser/download/chrome_download_manager_delegate.cc new file mode 100644 index 0000000000..eead2104db --- /dev/null +++ b/chromium_src/chrome/browser/download/chrome_download_manager_delegate.cc @@ -0,0 +1,7 @@ +#include "chrome/browser/download/chrome_download_manager_delegate.h" +#include "content/public/browser/download_item.h" + +void ChromeDownloadManagerDelegate::OpenDownloadUsingPlatformHandler( + content::DownloadItem* download) { + return; +} diff --git a/chromium_src/chrome/browser/download/download_commands.cc b/chromium_src/chrome/browser/download/download_commands.cc new file mode 100644 index 0000000000..12d2bb1bda --- /dev/null +++ b/chromium_src/chrome/browser/download/download_commands.cc @@ -0,0 +1,11 @@ +#include "chrome/browser/download/download_commands.h" + +DownloadCommands::DownloadCommands(content::DownloadItem* download_item) + : download_item_(download_item) { +} + +DownloadCommands::~DownloadCommands() = default; + +void DownloadCommands::ExecuteCommand(Command command) { + return; +} diff --git a/chromium_src/chrome/browser/download/download_core_service_factory.cc b/chromium_src/chrome/browser/download/download_core_service_factory.cc new file mode 100644 index 0000000000..7c32f733f8 --- /dev/null +++ b/chromium_src/chrome/browser/download/download_core_service_factory.cc @@ -0,0 +1,7 @@ +#include "chrome/browser/download/download_core_service_factory.h" + +// static +DownloadCoreService* DownloadCoreServiceFactory::GetForBrowserContext( + content::BrowserContext* context) { + return NULL; +} diff --git a/chromium_src/chrome/browser/download/download_crx_util.cc b/chromium_src/chrome/browser/download/download_crx_util.cc new file mode 100644 index 0000000000..4edb243288 --- /dev/null +++ b/chromium_src/chrome/browser/download/download_crx_util.cc @@ -0,0 +1,19 @@ +// 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/download/download_crx_util.h" + +using content::DownloadItem; + +namespace download_crx_util { + +bool IsExtensionDownload(const DownloadItem& download_item) { + return false; +} + +bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { + return false; +} + +} // namespace crx_util diff --git a/chromium_src/chrome/browser/download/download_history.cc b/chromium_src/chrome/browser/download/download_history.cc new file mode 100644 index 0000000000..54a2c4d0cc --- /dev/null +++ b/chromium_src/chrome/browser/download/download_history.cc @@ -0,0 +1,8 @@ +#include "chrome/browser/download/download_history.h" + +#include "content/public/browser/download_item.h" + +bool DownloadHistory::WasRestoredFromHistory( + const content::DownloadItem* download) const { + return true; +} diff --git a/chromium_src/chrome/browser/download/download_item_model.cc b/chromium_src/chrome/browser/download/download_item_model.cc new file mode 100644 index 0000000000..0d5ebbacb9 --- /dev/null +++ b/chromium_src/chrome/browser/download/download_item_model.cc @@ -0,0 +1,5 @@ +#include "chrome/browser/download/download_item_model.h" + +void DownloadItemModel::OpenUsingPlatformHandler() { + return; +} diff --git a/chromium_src/chrome/browser/extensions/api/experience_sampling_private/experience_sampling.cc b/chromium_src/chrome/browser/extensions/api/experience_sampling_private/experience_sampling.cc new file mode 100644 index 0000000000..af4202c016 --- /dev/null +++ b/chromium_src/chrome/browser/extensions/api/experience_sampling_private/experience_sampling.cc @@ -0,0 +1,12 @@ +// Copyright 2014 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/extensions/api/experience_sampling_private/experience_sampling.h" + +namespace extensions { + +ExperienceSamplingEvent::~ExperienceSamplingEvent() { +} + +} // namespace extensions diff --git a/chromium_src/chrome/browser/interstitials/BUILD.gn b/chromium_src/chrome/browser/interstitials/BUILD.gn new file mode 100644 index 0000000000..9d0bfd74bd --- /dev/null +++ b/chromium_src/chrome/browser/interstitials/BUILD.gn @@ -0,0 +1,13 @@ +source_set("interstitials") { + configs += [ "//electron/build:electron_config" ] + configs += [ "//electron/chromium_src:chromium_src_config" ] + + sources = [ + "chrome_metrics_helper.cc", + "//chrome/browser/interstitials/chrome_metrics_helper.h", + ] + + deps = [ + "//content/public/browser" + ] +} diff --git a/chromium_src/chrome/browser/interstitials/chrome_metrics_helper.cc b/chromium_src/chrome/browser/interstitials/chrome_metrics_helper.cc new file mode 100644 index 0000000000..ca14de18a6 --- /dev/null +++ b/chromium_src/chrome/browser/interstitials/chrome_metrics_helper.cc @@ -0,0 +1,44 @@ +// Copyright 2015 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/interstitials/chrome_metrics_helper.h" + +#include "chrome/common/features.h" +#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 + +ChromeMetricsHelper::ChromeMetricsHelper( + content::WebContents* web_contents, + const GURL& request_url, + const security_interstitials::MetricsHelper::ReportDetails settings, + const std::string& sampling_event_name) + : security_interstitials::MetricsHelper( + request_url, + settings, + nullptr), +#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) || BUILDFLAG(ENABLE_EXTENSIONS) + web_contents_(web_contents), +#endif + request_url_(request_url), + sampling_event_name_(sampling_event_name) { + DCHECK(!sampling_event_name_.empty()); +} + +ChromeMetricsHelper::~ChromeMetricsHelper() {} + +void ChromeMetricsHelper::RecordExtraShutdownMetrics() {} + +void ChromeMetricsHelper::RecordExtraUserDecisionMetrics( + security_interstitials::MetricsHelper::Decision decision) {} + +void ChromeMetricsHelper::RecordExtraUserInteractionMetrics( + security_interstitials::MetricsHelper::Interaction interaction) {} diff --git a/chromium_src/chrome/browser/permissions/permission_uma_util.cc b/chromium_src/chrome/browser/permissions/permission_uma_util.cc new file mode 100644 index 0000000000..2983e2a591 --- /dev/null +++ b/chromium_src/chrome/browser/permissions/permission_uma_util.cc @@ -0,0 +1,4 @@ +#include "chrome/browser/permissions/permission_uma_util.h" + +PermissionReportInfo::PermissionReportInfo( + const PermissionReportInfo& other) = default; diff --git a/chromium_src/chrome/browser/prerender/BUILD.gn b/chromium_src/chrome/browser/prerender/BUILD.gn index c07abec8c8..b5e43e5b08 100644 --- a/chromium_src/chrome/browser/prerender/BUILD.gn +++ b/chromium_src/chrome/browser/prerender/BUILD.gn @@ -8,7 +8,9 @@ source_set("prerender") { ] deps = [ + "//chrome/browser:resource_prefetch_predictor_proto", "//electron/chromium_src:sessions", + "//content/public/browser", "//components/history/content/browser", "//components/history/core/browser", "//components/history/core/common", diff --git a/chromium_src/chrome/browser/prerender/prerender_contents.cc b/chromium_src/chrome/browser/prerender/prerender_contents.cc index 7e9d1a3829..8bcd1dcc6b 100644 --- a/chromium_src/chrome/browser/prerender/prerender_contents.cc +++ b/chromium_src/chrome/browser/prerender/prerender_contents.cc @@ -14,6 +14,8 @@ 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; diff --git a/chromium_src/chrome/browser/profiles/profile.h b/chromium_src/chrome/browser/profiles/profile.h index 233cc34f42..e8f73c2ccb 100644 --- a/chromium_src/chrome/browser/profiles/profile.h +++ b/chromium_src/chrome/browser/profiles/profile.h @@ -124,6 +124,8 @@ class Profile : public atom::AtomBrowserContext { // profile is not incognito. virtual Profile* GetOriginalProfile() = 0; + bool IsLegacySupervised() {return false;} + // Return the original "recording" profile. This method returns this if the // profile is not incognito. virtual const Profile* GetOriginalProfile() const = 0; diff --git a/chromium_src/chrome/browser/safe_browsing/BUILD.gn b/chromium_src/chrome/browser/safe_browsing/BUILD.gn index c073ea22b9..40267a1d5b 100644 --- a/chromium_src/chrome/browser/safe_browsing/BUILD.gn +++ b/chromium_src/chrome/browser/safe_browsing/BUILD.gn @@ -1,19 +1,67 @@ -source_set("safe_browsing") { +source_set("install_verification") { + configs += [ "//electron/build:electron_config" ] + configs += [ "//electron/chromium_src:chromium_src_config" ] + + sources = [ + "//chrome/browser/install_verification/win/install_verification.cc", + "//chrome/browser/install_verification/win/install_verification.h", + "//chrome/browser/install_verification/win/loaded_module_verification.cc", + "//chrome/browser/install_verification/win/loaded_module_verification.h", + "//chrome/browser/install_verification/win/module_ids.cc", + "//chrome/browser/install_verification/win/module_ids.h", + "//chrome/browser/install_verification/win/module_info.h", + "//chrome/browser/install_verification/win/module_list.cc", + "//chrome/browser/install_verification/win/module_list.h", + "//chrome/browser/install_verification/win/module_verification_common.cc", + "//chrome/browser/install_verification/win/module_verification_common.h", + ] +} + +source_set("ui_extensions") { configs += [ "//electron/build:electron_config" ] configs += [ "//electron/chromium_src:chromium_src_config" ] sources = [ - "safe_browsing_service.cc", + "//electron/chromium_src/chrome/browser/ui/browser_commands.cc", + "//chrome/browser/ui/browser_commands.h", + "//electron/chromium_src/chrome/browser/ui/extensions/hosted_app_browser_controller.cc", ] deps = [ - "//components/safe_browsing/common:interfaces", - "//third_party/protobuf:protobuf_lite", + "//chrome/common:mojo_bindings", + "//printing/features", ] +} - if (is_win) { - cflags = [ "/wd4172", ] - } else { - cflags = [ "-Wnoreturn-stack-address" ] - } +source_set("net") { + configs += [ "//electron/build:electron_config" ] + configs += [ "//electron/chromium_src:chromium_src_config" ] + + sources = [ + "//chrome/browser/net/service_providers_win.cc", + "//chrome/browser/net/service_providers_win.h", + ] +} + +source_set("safe_browsing") { + configs += [ "//electron/build:electron_config" ] + configs += [ "//electron/chromium_src:chromium_src_config" ] + + sources = [ + "password_reuse_modal_warning_dialog.cc", + ] + + public_deps = [ + "//chrome/browser/safe_browsing", + "//content/public/browser", + ] + + deps = [ + ":install_verification", + ":net", + ":ui_extensions", + "//electron/chromium_src/chrome/browser/interstitials", + "//electron/chromium_src/chrome/browser/prerender", + "//electron/chromium_src/chrome/browser/signin", + ] } diff --git a/chromium_src/chrome/browser/safe_browsing/password_reuse_modal_warning_dialog.cc b/chromium_src/chrome/browser/safe_browsing/password_reuse_modal_warning_dialog.cc new file mode 100644 index 0000000000..c692f17d1e --- /dev/null +++ b/chromium_src/chrome/browser/safe_browsing/password_reuse_modal_warning_dialog.cc @@ -0,0 +1,15 @@ +#include "build/build_config.h" +#include "chrome/browser/safe_browsing/chrome_password_protection_service.h" +#include "components/safe_browsing/password_protection/password_protection_service.h" +#include "content/public/browser/web_contents.h" + +namespace safe_browsing { + +void ShowPasswordReuseModalWarningDialog( + content::WebContents* web_contents, + ChromePasswordProtectionService* service, + OnWarningDone done_callback) { + std::move(done_callback).Run(PasswordProtectionService::IGNORE_WARNING); +} + +} // namespace safe_browsing 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 81d116de0b..0000000000 --- a/chromium_src/chrome/browser/safe_browsing/safe_browsing_service.cc +++ /dev/null @@ -1,21 +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 { - static scoped_refptr empty; - return empty; -} - -void SafeBrowsingService::DisableQuicOnIOThread() {} - -} // namespace safe_browsing diff --git a/chromium_src/chrome/browser/signin/BUILD.gn b/chromium_src/chrome/browser/signin/BUILD.gn new file mode 100644 index 0000000000..e4740919d9 --- /dev/null +++ b/chromium_src/chrome/browser/signin/BUILD.gn @@ -0,0 +1,14 @@ +source_set("signin") { + configs += [ "//electron/build:electron_config" ] + configs += [ "//electron/chromium_src:chromium_src_config" ] + + sources = [ + "//chrome/browser/signin/signin_manager_factory.h", + "signin_manager_factory.cc", + ] + + deps = [ + "//electron/chromium_src:sessions", + ] +} + diff --git a/chromium_src/chrome/browser/signin/signin_manager_factory.cc b/chromium_src/chrome/browser/signin/signin_manager_factory.cc new file mode 100644 index 0000000000..d648f3b197 --- /dev/null +++ b/chromium_src/chrome/browser/signin/signin_manager_factory.cc @@ -0,0 +1,13 @@ +// 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/signin/signin_manager_factory.h" + +#include "build/build_config.h" +#include "chrome/browser/profiles/profile.h" + +// static +SigninManager* SigninManagerFactory::GetForProfileIfExists(Profile* profile) { + return nullptr; +} diff --git a/chromium_src/chrome/browser/sync/user_event_service_factory.cc b/chromium_src/chrome/browser/sync/user_event_service_factory.cc new file mode 100644 index 0000000000..e094d8b495 --- /dev/null +++ b/chromium_src/chrome/browser/sync/user_event_service_factory.cc @@ -0,0 +1,15 @@ +// Copyright 2017 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/sync/user_event_service_factory.h" + +namespace browser_sync { + +// static +syncer::UserEventService* UserEventServiceFactory::GetForProfile( + Profile* profile) { + return nullptr; +} + +} // namespace browser_sync diff --git a/chromium_src/chrome/browser/ui/browser.h b/chromium_src/chrome/browser/ui/browser.h index 0f5cea1728..a48a422d16 100644 --- a/chromium_src/chrome/browser/ui/browser.h +++ b/chromium_src/chrome/browser/ui/browser.h @@ -101,6 +101,7 @@ class Browser : public content::WebContentsDelegate { explicit Browser(const CreateParams& params); ~Browser(); + content::WebContents* OpenURL(const content::OpenURLParams& params); // void WillDestroyNativeObject(); diff --git a/chromium_src/chrome/browser/ui/browser_commands.cc b/chromium_src/chrome/browser/ui/browser_commands.cc new file mode 100644 index 0000000000..287c48f33e --- /dev/null +++ b/chromium_src/chrome/browser/ui/browser_commands.cc @@ -0,0 +1,9 @@ +#include "chrome/browser/ui/browser_commands.h" + +namespace chrome { + +void OpenInChrome(Browser* browser) { + return; +} + +} diff --git a/chromium_src/chrome/browser/ui/extensions/hosted_app_browser_controller.cc b/chromium_src/chrome/browser/ui/extensions/hosted_app_browser_controller.cc new file mode 100644 index 0000000000..7c2a827762 --- /dev/null +++ b/chromium_src/chrome/browser/ui/extensions/hosted_app_browser_controller.cc @@ -0,0 +1,7 @@ +#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" + +// static +bool extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser( + const Browser* browser) { + return false; +} diff --git a/chromium_src/chrome/browser/ui/page_info/page_info_ui.cc b/chromium_src/chrome/browser/ui/page_info/page_info_ui.cc new file mode 100644 index 0000000000..e990714c44 --- /dev/null +++ b/chromium_src/chrome/browser/ui/page_info/page_info_ui.cc @@ -0,0 +1,6 @@ +#include "chrome/browser/ui/page_info/page_info_ui.h" + +// static +bool PageInfoUI::ContentSettingsTypeInPageInfo(ContentSettingsType type) { + return false; +} diff --git a/muon/browser/muon_browser_process_impl.cc b/muon/browser/muon_browser_process_impl.cc index 404803eb22..c44e44d6b3 100644 --- a/muon/browser/muon_browser_process_impl.cc +++ b/muon/browser/muon_browser_process_impl.cc @@ -11,6 +11,7 @@ #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 "components/component_updater/component_updater_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_dispatcher_host.h"