tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StorageEvent.cpp (3075B)


      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 #include "mozilla/dom/StorageEvent.h"
      8 
      9 #include "mozilla/dom/Storage.h"
     10 #include "mozilla/dom/StorageEventBinding.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 NS_IMPL_CYCLE_COLLECTION_CLASS(StorageEvent)
     15 
     16 NS_IMPL_ADDREF_INHERITED(StorageEvent, Event)
     17 NS_IMPL_RELEASE_INHERITED(StorageEvent, Event)
     18 
     19 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StorageEvent, Event)
     20  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStorageArea)
     21 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     22 
     23 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(StorageEvent, Event)
     24 NS_IMPL_CYCLE_COLLECTION_TRACE_END
     25 
     26 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StorageEvent, Event)
     27  NS_IMPL_CYCLE_COLLECTION_UNLINK(mStorageArea)
     28 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     29 
     30 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StorageEvent)
     31 NS_INTERFACE_MAP_END_INHERITING(Event)
     32 
     33 StorageEvent::StorageEvent(EventTarget* aOwner)
     34    : Event(aOwner, nullptr, nullptr) {}
     35 
     36 StorageEvent::~StorageEvent() = default;
     37 
     38 StorageEvent* StorageEvent::AsStorageEvent() { return this; }
     39 
     40 JSObject* StorageEvent::WrapObjectInternal(JSContext* aCx,
     41                                           JS::Handle<JSObject*> aGivenProto) {
     42  return StorageEvent_Binding::Wrap(aCx, this, aGivenProto);
     43 }
     44 
     45 already_AddRefed<StorageEvent> StorageEvent::Constructor(
     46    EventTarget* aOwner, const nsAString& aType,
     47    const StorageEventInit& aEventInitDict) {
     48  RefPtr<StorageEvent> e = new StorageEvent(aOwner);
     49 
     50  bool trusted = e->Init(aOwner);
     51  e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
     52  e->mKey = aEventInitDict.mKey;
     53  e->mOldValue = aEventInitDict.mOldValue;
     54  e->mNewValue = aEventInitDict.mNewValue;
     55  e->mUrl = aEventInitDict.mUrl;
     56  e->mStorageArea = aEventInitDict.mStorageArea;
     57  e->SetTrusted(trusted);
     58  e->SetComposed(aEventInitDict.mComposed);
     59  return e.forget();
     60 }
     61 
     62 already_AddRefed<StorageEvent> StorageEvent::Constructor(
     63    const GlobalObject& aGlobal, const nsAString& aType,
     64    const StorageEventInit& aEventInitDict) {
     65  nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
     66  return Constructor(owner, aType, aEventInitDict);
     67 }
     68 
     69 void StorageEvent::InitStorageEvent(const nsAString& aType, bool aCanBubble,
     70                                    bool aCancelable, const nsAString& aKey,
     71                                    const nsAString& aOldValue,
     72                                    const nsAString& aNewValue,
     73                                    const nsAString& aURL,
     74                                    Storage* aStorageArea) {
     75  NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
     76 
     77  InitEvent(aType, aCanBubble, aCancelable);
     78  mKey = aKey;
     79  mOldValue = aOldValue;
     80  mNewValue = aNewValue;
     81  mUrl = aURL;
     82  mStorageArea = aStorageArea;
     83 }
     84 
     85 }  // namespace mozilla::dom