save_page_handler.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
  5. #define SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_
  6. #include <string>
  7. #include "components/download/public/common/download_item.h"
  8. #include "content/public/browser/download_manager.h"
  9. #include "content/public/browser/save_page_type.h"
  10. #include "shell/common/promise_util.h"
  11. #include "v8/include/v8.h"
  12. namespace base {
  13. class FilePath;
  14. }
  15. namespace content {
  16. class WebContents;
  17. }
  18. namespace electron {
  19. namespace api {
  20. // A self-destroyed class for handling save page request.
  21. class SavePageHandler : public content::DownloadManager::Observer,
  22. public download::DownloadItem::Observer {
  23. public:
  24. SavePageHandler(content::WebContents* web_contents,
  25. electron::util::Promise promise);
  26. ~SavePageHandler() override;
  27. bool Handle(const base::FilePath& full_path,
  28. const content::SavePageType& save_type);
  29. private:
  30. void Destroy(download::DownloadItem* item);
  31. // content::DownloadManager::Observer:
  32. void OnDownloadCreated(content::DownloadManager* manager,
  33. download::DownloadItem* item) override;
  34. // download::DownloadItem::Observer:
  35. void OnDownloadUpdated(download::DownloadItem* item) override;
  36. content::WebContents* web_contents_; // weak
  37. electron::util::Promise promise_;
  38. };
  39. } // namespace api
  40. } // namespace electron
  41. #endif // SHELL_BROWSER_API_SAVE_PAGE_HANDLER_H_