зеркало из https://github.com/electron/electron.git
Move download_item.h from content/public to components/download
https://chromium-review.googlesource.com/907687
This commit is contained in:
Родитель
a315d6330c
Коммит
4e580d5b39
|
@ -20,21 +20,22 @@
|
|||
namespace mate {
|
||||
|
||||
template <>
|
||||
struct Converter<content::DownloadItem::DownloadState> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
content::DownloadItem::DownloadState state) {
|
||||
struct Converter<download::DownloadItem::DownloadState> {
|
||||
static v8::Local<v8::Value> 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<uint32_t, v8::Global<v8::Object>> 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<GURL>& 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> 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<DownloadItem*>(existing));
|
||||
|
|
|
@ -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<DownloadItem>,
|
||||
public content::DownloadItem::Observer {
|
||||
public download::DownloadItem::Observer {
|
||||
public:
|
||||
static mate::Handle<DownloadItem> Create(v8::Isolate* isolate,
|
||||
content::DownloadItem* item);
|
||||
download::DownloadItem* item);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
@ -40,7 +40,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
|
|||
std::string GetContentDisposition() const;
|
||||
const GURL& GetURL() const;
|
||||
const std::vector<GURL>& 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<DownloadItem>,
|
|||
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);
|
||||
};
|
||||
|
|
|
@ -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<content::DownloadItem::ReceivedSlice>());
|
||||
false, std::vector<download::DownloadItem::ReceivedSlice>());
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -95,7 +95,7 @@ class Session : public mate::TrackableObject<Session>,
|
|||
|
||||
// content::DownloadManager::Observer:
|
||||
void OnDownloadCreated(content::DownloadManager* manager,
|
||||
content::DownloadItem* item) override;
|
||||
download::DownloadItem* item) override;
|
||||
|
||||
private:
|
||||
// Cached object.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<v8::String> 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;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#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<void(v8::Local<v8::Value>)>;
|
||||
|
||||
|
@ -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_;
|
||||
|
|
|
@ -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++);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AtomDownloadManagerDelegate> weak_ptr_factory_;
|
||||
|
|
Загрузка…
Ссылка в новой задаче