2015-10-14 04:41:31 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
|
2015-10-14 04:41:31 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2018-04-10 15:29:26 +00:00
|
|
|
#include "components/download/public/common/download_item.h"
|
2015-10-14 04:41:31 +00:00
|
|
|
#include "content/public/browser/download_manager.h"
|
|
|
|
#include "content/public/browser/save_page_type.h"
|
2019-11-01 06:10:32 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2015-10-14 04:41:31 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class WebContents;
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2015-10-14 04:41:31 +00:00
|
|
|
|
|
|
|
// A self-destroyed class for handling save page request.
|
|
|
|
class SavePageHandler : public content::DownloadManager::Observer,
|
2018-04-10 15:29:26 +00:00
|
|
|
public download::DownloadItem::Observer {
|
2015-10-14 04:41:31 +00:00
|
|
|
public:
|
|
|
|
SavePageHandler(content::WebContents* web_contents,
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise);
|
2018-04-17 23:03:51 +00:00
|
|
|
~SavePageHandler() override;
|
2015-10-14 04:41:31 +00:00
|
|
|
|
|
|
|
bool Handle(const base::FilePath& full_path,
|
|
|
|
const content::SavePageType& save_type);
|
|
|
|
|
|
|
|
private:
|
2018-04-10 15:29:26 +00:00
|
|
|
void Destroy(download::DownloadItem* item);
|
2015-10-14 04:41:31 +00:00
|
|
|
|
|
|
|
// content::DownloadManager::Observer:
|
|
|
|
void OnDownloadCreated(content::DownloadManager* manager,
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem* item) override;
|
2015-10-14 04:41:31 +00:00
|
|
|
|
2018-04-10 15:29:26 +00:00
|
|
|
// download::DownloadItem::Observer:
|
|
|
|
void OnDownloadUpdated(download::DownloadItem* item) override;
|
2015-10-14 04:41:31 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<content::WebContents> web_contents_; // weak
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise_;
|
2015-10-14 04:41:31 +00:00
|
|
|
};
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2015-10-14 04:41:31 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
|