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_StorageEvent_h 8 #define mozilla_dom_StorageEvent_h 9 10 #include "js/RootingAPI.h" 11 #include "mozilla/AlreadyAddRefed.h" 12 #include "mozilla/Assertions.h" 13 #include "mozilla/RefPtr.h" 14 #include "mozilla/dom/Event.h" 15 #include "nsCOMPtr.h" 16 #include "nsCycleCollectionParticipant.h" 17 #include "nsIPrincipal.h" 18 #include "nsISupports.h" 19 #include "nsStringFwd.h" 20 21 class nsIPrincipal; 22 23 namespace mozilla { 24 namespace dom { 25 26 class Storage; 27 struct StorageEventInit; 28 29 class StorageEvent : public Event { 30 public: 31 NS_DECL_ISUPPORTS_INHERITED 32 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StorageEvent, Event) 33 34 explicit StorageEvent(EventTarget* aOwner); 35 36 protected: 37 virtual ~StorageEvent(); 38 39 nsString mKey; 40 nsString mOldValue; 41 nsString mNewValue; 42 nsString mUrl; 43 RefPtr<Storage> mStorageArea; 44 nsCOMPtr<nsIPrincipal> mPrincipal; 45 46 public: 47 virtual StorageEvent* AsStorageEvent(); 48 49 virtual JSObject* WrapObjectInternal( 50 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 51 52 static already_AddRefed<StorageEvent> Constructor( 53 EventTarget* aOwner, const nsAString& aType, 54 const StorageEventInit& aEventInitDict); 55 56 static already_AddRefed<StorageEvent> Constructor( 57 const GlobalObject& aGlobal, const nsAString& aType, 58 const StorageEventInit& aEventInitDict); 59 60 void InitStorageEvent(const nsAString& aType, bool aCanBubble, 61 bool aCancelable, const nsAString& aKey, 62 const nsAString& aOldValue, const nsAString& aNewValue, 63 const nsAString& aURL, Storage* aStorageArea); 64 GetKey(nsString & aRetVal)65 void GetKey(nsString& aRetVal) const { aRetVal = mKey; } 66 GetOldValue(nsString & aRetVal)67 void GetOldValue(nsString& aRetVal) const { aRetVal = mOldValue; } 68 GetNewValue(nsString & aRetVal)69 void GetNewValue(nsString& aRetVal) const { aRetVal = mNewValue; } 70 GetUrl(nsString & aRetVal)71 void GetUrl(nsString& aRetVal) const { aRetVal = mUrl; } 72 GetStorageArea()73 Storage* GetStorageArea() const { return mStorageArea; } 74 75 // Non WebIDL methods SetPrincipal(nsIPrincipal * aPrincipal)76 void SetPrincipal(nsIPrincipal* aPrincipal) { 77 MOZ_ASSERT(!mPrincipal); 78 mPrincipal = aPrincipal; 79 } 80 GetPrincipal()81 nsIPrincipal* GetPrincipal() const { return mPrincipal; } 82 }; 83 84 } // namespace dom 85 } // namespace mozilla 86 87 #endif // mozilla_dom_StorageEvent_h 88