atom_api_download_item.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_ATOM_API_DOWNLOAD_ITEM_H_
  5. #define ATOM_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_
  6. #include <string>
  7. #include <vector>
  8. #include "atom/browser/api/trackable_object.h"
  9. #include "base/files/file_path.h"
  10. #include "content/public/browser/download_item.h"
  11. #include "native_mate/handle.h"
  12. #include "url/gurl.h"
  13. namespace atom {
  14. namespace api {
  15. class DownloadItem : public mate::TrackableObject<DownloadItem>,
  16. public content::DownloadItem::Observer {
  17. public:
  18. static mate::Handle<DownloadItem> Create(v8::Isolate* isolate,
  19. content::DownloadItem* item);
  20. static void BuildPrototype(v8::Isolate* isolate,
  21. v8::Local<v8::FunctionTemplate> prototype);
  22. void Pause();
  23. bool IsPaused() const;
  24. void Resume();
  25. bool CanResume() const;
  26. void Cancel();
  27. int64_t GetReceivedBytes() const;
  28. int64_t GetTotalBytes() const;
  29. std::string GetMimeType() const;
  30. bool HasUserGesture() const;
  31. std::string GetFilename() const;
  32. std::string GetContentDisposition() const;
  33. const GURL& GetURL() const;
  34. const std::vector<GURL>& GetURLChain() const;
  35. content::DownloadItem::DownloadState GetState() const;
  36. bool IsDone() const;
  37. void SetSavePath(const base::FilePath& path);
  38. base::FilePath GetSavePath() const;
  39. std::string GetLastModifiedTime() const;
  40. std::string GetETag() const;
  41. double GetStartTime() const;
  42. protected:
  43. DownloadItem(v8::Isolate* isolate, content::DownloadItem* download_item);
  44. ~DownloadItem() override;
  45. // Override content::DownloadItem::Observer methods
  46. void OnDownloadUpdated(content::DownloadItem* download) override;
  47. void OnDownloadDestroyed(content::DownloadItem* download) override;
  48. private:
  49. base::FilePath save_path_;
  50. content::DownloadItem* download_item_;
  51. DISALLOW_COPY_AND_ASSIGN(DownloadItem);
  52. };
  53. } // namespace api
  54. } // namespace atom
  55. #endif // ATOM_BROWSER_API_ATOM_API_DOWNLOAD_ITEM_H_