From 4e580d5b3965f5968021d63f14eec5804dde48e7 Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Tue, 10 Apr 2018 17:29:26 +0200 Subject: [PATCH] Move download_item.h from content/public to components/download https://chromium-review.googlesource.com/907687 --- atom/browser/api/atom_api_download_item.cc | 25 ++++++++++--------- atom/browser/api/atom_api_download_item.h | 18 ++++++------- atom/browser/api/atom_api_session.cc | 13 ++++++---- atom/browser/api/atom_api_session.h | 2 +- atom/browser/api/atom_api_web_contents.cc | 2 +- atom/browser/api/save_page_handler.cc | 8 +++--- atom/browser/api/save_page_handler.h | 12 ++++----- .../browser/atom_download_manager_delegate.cc | 23 +++++++++-------- atom/browser/atom_download_manager_delegate.h | 6 ++--- 9 files changed, 58 insertions(+), 51 deletions(-) diff --git a/atom/browser/api/atom_api_download_item.cc b/atom/browser/api/atom_api_download_item.cc index 1b7bb819764..4fa4d5517b4 100644 --- a/atom/browser/api/atom_api_download_item.cc +++ b/atom/browser/api/atom_api_download_item.cc @@ -20,21 +20,22 @@ namespace mate { template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - content::DownloadItem::DownloadState state) { +struct Converter { + static v8::Local ToV8( + v8::Isolate* isolate, + download::DownloadItem::DownloadState state) { std::string download_state; switch (state) { - case content::DownloadItem::IN_PROGRESS: + case download::DownloadItem::IN_PROGRESS: download_state = "progressing"; break; - case content::DownloadItem::COMPLETE: + case download::DownloadItem::COMPLETE: download_state = "completed"; break; - case content::DownloadItem::CANCELLED: + case download::DownloadItem::CANCELLED: download_state = "cancelled"; break; - case content::DownloadItem::INTERRUPTED: + case download::DownloadItem::INTERRUPTED: download_state = "interrupted"; break; default: @@ -57,7 +58,7 @@ std::map> g_download_item_objects; } // namespace DownloadItem::DownloadItem(v8::Isolate* isolate, - content::DownloadItem* download_item) + download::DownloadItem* download_item) : download_item_(download_item) { download_item_->AddObserver(this); Init(isolate); @@ -75,7 +76,7 @@ DownloadItem::~DownloadItem() { g_download_item_objects.erase(weak_map_id()); } -void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) { +void DownloadItem::OnDownloadUpdated(download::DownloadItem* item) { if (download_item_->IsDone()) { Emit("done", item->GetState()); // Destroy the item once item is downloaded. @@ -86,7 +87,7 @@ void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) { } } -void DownloadItem::OnDownloadDestroyed(content::DownloadItem* download_item) { +void DownloadItem::OnDownloadDestroyed(download::DownloadItem* download_item) { download_item_ = nullptr; // Destroy the native class immediately when downloadItem is destroyed. delete this; @@ -148,7 +149,7 @@ const std::vector& DownloadItem::GetURLChain() const { return download_item_->GetUrlChain(); } -content::DownloadItem::DownloadState DownloadItem::GetState() const { +download::DownloadItem::DownloadState DownloadItem::GetState() const { return download_item_->GetState(); } @@ -206,7 +207,7 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate, // static mate::Handle DownloadItem::Create(v8::Isolate* isolate, - content::DownloadItem* item) { + download::DownloadItem* item) { auto* existing = TrackableObject::FromWrappedClass(isolate, item); if (existing) return mate::CreateHandle(isolate, static_cast(existing)); diff --git a/atom/browser/api/atom_api_download_item.h b/atom/browser/api/atom_api_download_item.h index 43a02805960..45ed54faf19 100644 --- a/atom/browser/api/atom_api_download_item.h +++ b/atom/browser/api/atom_api_download_item.h @@ -10,7 +10,7 @@ #include "atom/browser/api/trackable_object.h" #include "base/files/file_path.h" -#include "content/public/browser/download_item.h" +#include "components/download/public/common/download_item.h" #include "native_mate/handle.h" #include "url/gurl.h" @@ -19,10 +19,10 @@ namespace atom { namespace api { class DownloadItem : public mate::TrackableObject, - public content::DownloadItem::Observer { + public download::DownloadItem::Observer { public: static mate::Handle Create(v8::Isolate* isolate, - content::DownloadItem* item); + download::DownloadItem* item); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -40,7 +40,7 @@ class DownloadItem : public mate::TrackableObject, std::string GetContentDisposition() const; const GURL& GetURL() const; const std::vector& GetURLChain() const; - content::DownloadItem::DownloadState GetState() const; + download::DownloadItem::DownloadState GetState() const; bool IsDone() const; void SetSavePath(const base::FilePath& path); base::FilePath GetSavePath() const; @@ -49,16 +49,16 @@ class DownloadItem : public mate::TrackableObject, double GetStartTime() const; protected: - DownloadItem(v8::Isolate* isolate, content::DownloadItem* download_item); + DownloadItem(v8::Isolate* isolate, download::DownloadItem* download_item); ~DownloadItem() override; - // Override content::DownloadItem::Observer methods - void OnDownloadUpdated(content::DownloadItem* download) override; - void OnDownloadDestroyed(content::DownloadItem* download) override; + // Override download::DownloadItem::Observer methods + void OnDownloadUpdated(download::DownloadItem* download) override; + void OnDownloadDestroyed(download::DownloadItem* download) override; private: base::FilePath save_path_; - content::DownloadItem* download_item_; + download::DownloadItem* download_item_; DISALLOW_COPY_AND_ASSIGN(DownloadItem); }; diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index dc2cdb12d81..0d9fcdfeb03 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -35,6 +35,7 @@ #include "chrome/common/pref_names.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/download_item_utils.h" #include "content/public/browser/download_manager_delegate.h" #include "content/public/browser/storage_partition.h" #include "native_mate/dictionary.h" @@ -433,10 +434,10 @@ void DownloadIdCallback(content::DownloadManager* download_manager, base::GenerateGUID(), id, path, path, url_chain, GURL(), GURL(), GURL(), GURL(), mime_type, mime_type, start_time, base::Time(), etag, last_modified, offset, length, std::string(), - content::DownloadItem::INTERRUPTED, + download::DownloadItem::INTERRUPTED, content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false, base::Time(), - false, std::vector()); + false, std::vector()); } void SetDevToolsNetworkEmulationClientIdInIO( @@ -506,16 +507,18 @@ Session::~Session() { } void Session::OnDownloadCreated(content::DownloadManager* manager, - content::DownloadItem* item) { + download::DownloadItem* item) { if (item->IsSavePackageDownload()) return; v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); auto handle = DownloadItem::Create(isolate(), item); - if (item->GetState() == content::DownloadItem::INTERRUPTED) + if (item->GetState() == download::DownloadItem::INTERRUPTED) handle->SetSavePath(item->GetTargetFilePath()); - bool prevent_default = Emit("will-download", handle, item->GetWebContents()); + content::WebContents* web_contents = + content::DownloadItemUtils::GetWebContents(item); + bool prevent_default = Emit("will-download", handle, web_contents); if (prevent_default) { item->Cancel(true); item->Remove(); diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index 4e88743c6af..6c8247c5c4a 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -95,7 +95,7 @@ class Session : public mate::TrackableObject, // content::DownloadManager::Observer: void OnDownloadCreated(content::DownloadManager* manager, - content::DownloadItem* item) override; + download::DownloadItem* item) override; private: // Cached object. diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 96178cbfdc9..fd3f6047c58 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1214,7 +1214,7 @@ void WebContents::DownloadURL(const GURL& url) { content::BrowserContext::GetDownloadManager(browser_context); download_manager->DownloadUrl( - content::DownloadUrlParameters::CreateForWebContentsMainFrame( + download::DownloadUrlParameters::CreateForWebContentsMainFrame( web_contents(), url, NO_TRAFFIC_ANNOTATION_YET)); } diff --git a/atom/browser/api/save_page_handler.cc b/atom/browser/api/save_page_handler.cc index cce01876f1c..a0d8e283961 100644 --- a/atom/browser/api/save_page_handler.cc +++ b/atom/browser/api/save_page_handler.cc @@ -22,7 +22,7 @@ SavePageHandler::SavePageHandler(content::WebContents* web_contents, SavePageHandler::~SavePageHandler() {} void SavePageHandler::OnDownloadCreated(content::DownloadManager* manager, - content::DownloadItem* item) { + download::DownloadItem* item) { // OnDownloadCreated is invoked during WebContents::SavePage, so the |item| // here is the one stated by WebContents::SavePage. item->AddObserver(this); @@ -48,12 +48,12 @@ bool SavePageHandler::Handle(const base::FilePath& full_path, return result; } -void SavePageHandler::OnDownloadUpdated(content::DownloadItem* item) { +void SavePageHandler::OnDownloadUpdated(download::DownloadItem* item) { if (item->IsDone()) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::HandleScope handle_scope(isolate); - if (item->GetState() == content::DownloadItem::COMPLETE) { + if (item->GetState() == download::DownloadItem::COMPLETE) { callback_.Run(v8::Null(isolate)); } else { v8::Local error_message = @@ -64,7 +64,7 @@ void SavePageHandler::OnDownloadUpdated(content::DownloadItem* item) { } } -void SavePageHandler::Destroy(content::DownloadItem* item) { +void SavePageHandler::Destroy(download::DownloadItem* item) { item->RemoveObserver(this); delete this; } diff --git a/atom/browser/api/save_page_handler.h b/atom/browser/api/save_page_handler.h index ae34211936c..204d65bd6b1 100644 --- a/atom/browser/api/save_page_handler.h +++ b/atom/browser/api/save_page_handler.h @@ -7,7 +7,7 @@ #include -#include "content/public/browser/download_item.h" +#include "components/download/public/common/download_item.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/save_page_type.h" #include "v8/include/v8.h" @@ -26,7 +26,7 @@ namespace api { // A self-destroyed class for handling save page request. class SavePageHandler : public content::DownloadManager::Observer, - public content::DownloadItem::Observer { + public download::DownloadItem::Observer { public: using SavePageCallback = base::Callback)>; @@ -38,14 +38,14 @@ class SavePageHandler : public content::DownloadManager::Observer, const content::SavePageType& save_type); private: - void Destroy(content::DownloadItem* item); + void Destroy(download::DownloadItem* item); // content::DownloadManager::Observer: void OnDownloadCreated(content::DownloadManager* manager, - content::DownloadItem* item) override; + download::DownloadItem* item) override; - // content::DownloadItem::Observer: - void OnDownloadUpdated(content::DownloadItem* item) override; + // download::DownloadItem::Observer: + void OnDownloadUpdated(download::DownloadItem* item) override; content::WebContents* web_contents_; // weak SavePageCallback callback_; diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index a19da1f0ac6..ee0141ff3bc 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -19,6 +19,7 @@ #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_item_utils.h" #include "content/public/browser/download_manager.h" #include "net/base/filename_util.h" @@ -57,7 +58,7 @@ AtomDownloadManagerDelegate::~AtomDownloadManagerDelegate() { } } -void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item, +void AtomDownloadManagerDelegate::GetItemSavePath(download::DownloadItem* item, base::FilePath* path) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); @@ -79,7 +80,8 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( return; NativeWindow* window = nullptr; - content::WebContents* web_contents = item->GetWebContents(); + content::WebContents* web_contents = + content::DownloadItemUtils::GetWebContents(item); auto* relay = web_contents ? NativeWindowRelay::FromWebContents(web_contents) : nullptr; if (relay) @@ -116,7 +118,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( // Running the DownloadTargetCallback with an empty FilePath signals that the // download should be cancelled. // If user cancels the file save dialog, run the callback with empty FilePath. - callback.Run(path, content::DownloadItem::TARGET_DISPOSITION_PROMPT, + callback.Run(path, download::DownloadItem::TARGET_DISPOSITION_PROMPT, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path, path.empty() ? content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED : content::DOWNLOAD_INTERRUPT_REASON_NONE); @@ -128,13 +130,13 @@ void AtomDownloadManagerDelegate::Shutdown() { } bool AtomDownloadManagerDelegate::DetermineDownloadTarget( - content::DownloadItem* download, + download::DownloadItem* download, const content::DownloadTargetCallback& callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (!download->GetForcedFilePath().empty()) { callback.Run(download->GetForcedFilePath(), - content::DownloadItem::TARGET_DISPOSITION_OVERWRITE, + download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, download->GetForcedFilePath(), content::DOWNLOAD_INTERRUPT_REASON_NONE); @@ -145,9 +147,10 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget( base::FilePath save_path; GetItemSavePath(download, &save_path); if (!save_path.empty()) { - callback.Run(save_path, content::DownloadItem::TARGET_DISPOSITION_OVERWRITE, - content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, save_path, - content::DOWNLOAD_INTERRUPT_REASON_NONE); + callback.Run(save_path, + download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, + save_path, content::DOWNLOAD_INTERRUPT_REASON_NONE); return true; } @@ -171,14 +174,14 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget( } bool AtomDownloadManagerDelegate::ShouldOpenDownload( - content::DownloadItem* download, + 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 = download::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 ce0400f2b94..f1cc1190d4b 100644 --- a/atom/browser/atom_download_manager_delegate.h +++ b/atom/browser/atom_download_manager_delegate.h @@ -31,16 +31,16 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate { // content::DownloadManagerDelegate: void Shutdown() override; bool DetermineDownloadTarget( - content::DownloadItem* download, + download::DownloadItem* download, const content::DownloadTargetCallback& callback) override; bool ShouldOpenDownload( - content::DownloadItem* download, + download::DownloadItem* download, const content::DownloadOpenDelayedCallback& callback) override; void GetNextId(const content::DownloadIdCallback& callback) override; private: // Get the save path set on the associated api::DownloadItem object - void GetItemSavePath(content::DownloadItem* item, base::FilePath* path); + void GetItemSavePath(download::DownloadItem* item, base::FilePath* path); content::DownloadManager* download_manager_; base::WeakPtrFactory weak_ptr_factory_;