save_page_handler.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 ATOM_BROWSER_API_SAVE_PAGE_HANDLER_H_
  5. #define ATOM_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 "v8/include/v8.h"
  11. namespace base {
  12. class FilePath;
  13. }
  14. namespace content {
  15. class WebContents;
  16. }
  17. namespace atom {
  18. namespace api {
  19. // A self-destroyed class for handling save page request.
  20. class SavePageHandler : public content::DownloadManager::Observer,
  21. public download::DownloadItem::Observer {
  22. public:
  23. using SavePageCallback = base::Callback<void(v8::Local<v8::Value>)>;
  24. SavePageHandler(content::WebContents* web_contents,
  25. const SavePageCallback& callback);
  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. SavePageCallback callback_;
  38. };
  39. } // namespace api
  40. } // namespace atom
  41. #endif // ATOM_BROWSER_API_SAVE_PAGE_HANDLER_H_