atom_api_cookies.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_COOKIES_H_
  5. #define ATOM_BROWSER_API_ATOM_API_COOKIES_H_
  6. #include <memory>
  7. #include <string>
  8. #include "atom/browser/api/trackable_object.h"
  9. #include "atom/browser/net/cookie_details.h"
  10. #include "atom/common/promise_util.h"
  11. #include "base/callback_list.h"
  12. #include "native_mate/handle.h"
  13. #include "net/cookies/canonical_cookie.h"
  14. namespace base {
  15. class DictionaryValue;
  16. }
  17. namespace net {
  18. class URLRequestContextGetter;
  19. }
  20. namespace atom {
  21. class AtomBrowserContext;
  22. namespace api {
  23. class Cookies : public mate::TrackableObject<Cookies> {
  24. public:
  25. enum Error {
  26. SUCCESS,
  27. FAILED,
  28. };
  29. static mate::Handle<Cookies> Create(v8::Isolate* isolate,
  30. AtomBrowserContext* browser_context);
  31. // mate::TrackableObject:
  32. static void BuildPrototype(v8::Isolate* isolate,
  33. v8::Local<v8::FunctionTemplate> prototype);
  34. protected:
  35. Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
  36. ~Cookies() override;
  37. v8::Local<v8::Promise> Get(const base::DictionaryValue& filter);
  38. v8::Local<v8::Promise> Set(const base::DictionaryValue& details);
  39. v8::Local<v8::Promise> Remove(const GURL& url, const std::string& name);
  40. v8::Local<v8::Promise> FlushStore();
  41. // CookieChangeNotifier subscription:
  42. void OnCookieChanged(const CookieDetails*);
  43. private:
  44. std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
  45. cookie_change_subscription_;
  46. scoped_refptr<AtomBrowserContext> browser_context_;
  47. DISALLOW_COPY_AND_ASSIGN(Cookies);
  48. };
  49. } // namespace api
  50. } // namespace atom
  51. #endif // ATOM_BROWSER_API_ATOM_API_COOKIES_H_