Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / storage / StorageNotifierService.h
blob9471962037ea7a1dce34df1e6e4059a55d7e4335
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/. */
7 #ifndef mozilla_dom_StorageNotifierService_h
8 #define mozilla_dom_StorageNotifierService_h
10 class nsPIDOMWindowInner;
12 namespace mozilla {
13 namespace dom {
15 class StorageEvent;
17 /**
18 * Enables the StorageNotifierService to check whether an observer is interested
19 * in receiving events for the given principal before calling the method, an
20 * optimization refactoring.
22 * Expected to only be implemented by nsGlobalWindowObserver or its succesor.
24 class StorageNotificationObserver {
25 public:
26 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
28 virtual void ObserveStorageNotification(StorageEvent* aEvent,
29 const char16_t* aStorageType,
30 bool aPrivateBrowsing) = 0;
32 virtual bool IsPrivateBrowsing() const = 0;
34 virtual nsIPrincipal* GetEffectiveStoragePrincipal() const = 0;
36 virtual nsIEventTarget* GetEventTarget() const = 0;
39 /**
40 * A specialized version of the observer service that uses the custom
41 * StorageNotificationObserver so that principal checks can happen in this class
42 * rather than in the nsIObserver::observe method where they used to happen.
44 * The only expected consumers are nsGlobalWindowInner instances via their
45 * nsGlobalWindowObserver helper that avoids being able to use the window as an
46 * nsIObserver.
48 class StorageNotifierService final {
49 public:
50 NS_INLINE_DECL_REFCOUNTING(StorageNotifierService)
52 static StorageNotifierService* GetOrCreate();
54 static void Broadcast(StorageEvent* aEvent, const char16_t* aStorageType,
55 bool aPrivateBrowsing, bool aImmediateDispatch);
57 void Register(StorageNotificationObserver* aObserver);
59 void Unregister(StorageNotificationObserver* aObserver);
61 private:
62 StorageNotifierService();
63 ~StorageNotifierService();
65 nsTObserverArray<RefPtr<StorageNotificationObserver>> mObservers;
68 } // namespace dom
69 } // namespace mozilla
71 #endif // mozilla_dom_StorageNotifierService_h