atom_api_cookies.h 1.8 KB

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