summaryrefslogtreecommitdiffstats
path: root/dom/storage/StorageNotifierService.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/storage/StorageNotifierService.h
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
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..e36bb08b0d
--- /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 {
+namespace 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* 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 dom
+} // namespace mozilla
+
+#endif // mozilla_dom_StorageNotifierService_h