save_page_handler.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
  5. #define ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
  6. #include "components/download/public/common/download_item.h"
  7. #include "content/public/browser/download_manager.h"
  8. #include "content/public/browser/save_page_type.h"
  9. #include "shell/common/gin_helper/promise.h"
  10. #include "v8/include/v8.h"
  11. namespace base {
  12. class FilePath;
  13. }
  14. namespace content {
  15. class WebContents;
  16. }
  17. namespace electron::api {
  18. // A self-destroyed class for handling save page request.
  19. class SavePageHandler : public content::DownloadManager::Observer,
  20. public download::DownloadItem::Observer {
  21. public:
  22. SavePageHandler(content::WebContents* web_contents,
  23. gin_helper::Promise<void> promise);
  24. ~SavePageHandler() override;
  25. bool Handle(const base::FilePath& full_path,
  26. const content::SavePageType& save_type);
  27. private:
  28. void Destroy(download::DownloadItem* item);
  29. // content::DownloadManager::Observer:
  30. void OnDownloadCreated(content::DownloadManager* manager,
  31. download::DownloadItem* item) override;
  32. // download::DownloadItem::Observer:
  33. void OnDownloadUpdated(download::DownloadItem* item) override;
  34. content::WebContents* web_contents_; // weak
  35. gin_helper::Promise<void> promise_;
  36. };
  37. } // namespace electron::api
  38. #endif // ELECTRON_SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_