summaryrefslogtreecommitdiffstats
path: root/dom/storage/StorageNotifierService.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/storage/StorageNotifierService.h
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/storage/StorageNotifierService.h')
-rw-r--r--dom/storage/StorageNotifierService.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/dom/storage/StorageNotifierService.h b/dom/storage/StorageNotifierService.h
new file mode 100644
index 0000000000..9568f4b259
--- /dev/null
+++ b/dom/storage/StorageNotifierService.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_StorageNotifierService_h
+#define mozilla_dom_StorageNotifierService_h
+
+#include "nsISupportsImpl.h"
+#include "nsTObserverArray.h"
+
+class nsIEventTarget;
+class nsIPrincipal;
+class nsPIDOMWindowInner;
+
+namespace mozilla::dom {
+
+class StorageEvent;
+
+/**
+ * Enables the StorageNotifierService to check whether an observer is interested
+ * in receiving events for the given principal before calling the method, an
+ * optimization refactoring.
+ *
+ * Expected to only be implemented by nsGlobalWindowObserver or its succesor.
+ */
+class StorageNotificationObserver {
+ public:
+ NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
+
+ virtual void ObserveStorageNotification(StorageEvent* aEvent,
+ const char16_t* aStorageType,
+ bool aPrivateBrowsing) = 0;
+
+ virtual bool IsPrivateBrowsing() const = 0;
+
+ virtual nsIPrincipal* GetEffectiveCookiePrincipal() const = 0;
+
+ virtual nsIPrincipal* GetEffectiveStoragePrincipal() const = 0;
+
+ virtual nsIEventTarget* GetEventTarget() const = 0;
+};
+
+/**
+ * A specialized version of the observer service that uses the custom
+ * StorageNotificationObserver so that principal checks can happen in this class
+ * rather than in the nsIObserver::observe method where they used to happen.
+ *
+ * The only expected consumers are nsGlobalWindowInner instances via their
+ * nsGlobalWindowObserver helper that avoids being able to use the window as an
+ * nsIObserver.
+ */
+class StorageNotifierService final {
+ public:
+ NS_INLINE_DECL_REFCOUNTING(StorageNotifierService)
+
+ static StorageNotifierService* GetOrCreate();
+
+ static void Broadcast(StorageEvent* aEvent, const char16_t* aStorageType,
+ bool aPrivateBrowsing, bool aImmediateDispatch);
+
+ void Register(StorageNotificationObserver* aObserver);
+
+ void Unregister(StorageNotificationObserver* aObserver);
+
+ private:
+ StorageNotifierService();
+ ~StorageNotifierService();
+
+ nsTObserverArray<RefPtr<StorageNotificationObserver>> mObservers;
+};
+
+} // namespace mozilla::dom
+
+#endif // mozilla_dom_StorageNotifierService_h