CookieStore.h (2695B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_CookieStore_h 8 #define mozilla_dom_CookieStore_h 9 10 #include "mozilla/DOMEventTargetHelper.h" 11 #include "mozilla/dom/CookieStoreBinding.h" 12 13 class nsIGlobalObject; 14 15 namespace mozilla::net { 16 class CookieStruct; 17 } 18 19 namespace mozilla::dom { 20 21 class CookieStoreChild; 22 class CookieStoreNotificationWatcherWrapper; 23 class CookieStoreNotifier; 24 class Promise; 25 26 class CookieStore final : public DOMEventTargetHelper { 27 friend class CookieStoreChild; 28 29 public: 30 NS_DECL_ISUPPORTS_INHERITED 31 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CookieStore, DOMEventTargetHelper) 32 33 static already_AddRefed<CookieStore> Create(nsIGlobalObject* aGlobalObject); 34 35 JSObject* WrapObject(JSContext* aCx, 36 JS::Handle<JSObject*> aGivenProto) override; 37 38 void FireDelayedDOMEvents(); 39 40 already_AddRefed<Promise> Get(const nsAString& aName, ErrorResult& aRv); 41 42 already_AddRefed<Promise> Get(const CookieStoreGetOptions& aOptions, 43 ErrorResult& aRv); 44 45 already_AddRefed<Promise> GetAll(const nsAString& aName, ErrorResult& aRv); 46 47 already_AddRefed<Promise> GetAll(const CookieStoreGetOptions& aOptions, 48 ErrorResult& aRv); 49 50 already_AddRefed<Promise> Set(const nsAString& aName, const nsAString& aValue, 51 ErrorResult& aRv); 52 53 already_AddRefed<Promise> Set(const CookieInit& aOptions, ErrorResult& aRv); 54 55 already_AddRefed<Promise> Delete(const nsAString& aName, ErrorResult& aRv); 56 57 already_AddRefed<Promise> Delete(const CookieStoreDeleteOptions& aOptions, 58 ErrorResult& aRv); 59 60 IMPL_EVENT_HANDLER(change); 61 62 static void CookieStructToItem(const net::CookieStruct& aData, 63 CookieListItem* aItem); 64 65 private: 66 explicit CookieStore(nsIGlobalObject* aGlobal); 67 ~CookieStore(); 68 69 void Shutdown(); 70 71 Document* MaybeGetDocument() const; 72 73 already_AddRefed<Promise> GetInternal(const CookieStoreGetOptions& aOptions, 74 bool aOnlyTheFirstMatch, 75 ErrorResult& aRv); 76 77 bool MaybeCreateActor(); 78 79 RefPtr<CookieStoreChild> mActor; 80 RefPtr<CookieStoreNotifier> mNotifier; 81 RefPtr<CookieStoreNotificationWatcherWrapper> mNotificationWatcher; 82 }; 83 84 } // namespace mozilla::dom 85 86 #endif /* mozilla_dom_CookieStore_h */