Bug 1771337 [wpt PR 34217] - Convert `popup=popup` to `popup=auto` or just `popup...
[gecko.git] / dom / storage / StorageObserver.h
blobdf2b87b2e497afb4d0ac8eb7447c5f887154df4f
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_StorageObserver_h
8 #define mozilla_dom_StorageObserver_h
10 #include "mozilla/dom/quota/CheckedUnsafePtr.h"
11 #include "nsINamed.h"
12 #include "nsIObserver.h"
13 #include "nsITimer.h"
14 #include "nsWeakReference.h"
15 #include "nsTObserverArray.h"
16 #include "nsString.h"
18 namespace mozilla::dom {
20 class StorageObserver;
22 // Main-thread interface implemented by legacy LocalStorageManager and current
23 // SessionStorageManager for direct consumption. Also implemented by legacy
24 // StorageDBParent and current SessionStorageObserverParent for propagation to
25 // content processes.
26 class StorageObserverSink
27 : public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
28 public:
29 virtual ~StorageObserverSink() = default;
31 private:
32 friend class StorageObserver;
33 virtual nsresult Observe(const char* aTopic,
34 const nsAString& aOriginAttributesPattern,
35 const nsACString& aOriginScope) = 0;
38 // Statically (through layout statics) initialized observer receiving and
39 // processing chrome clearing notifications, such as cookie deletion etc.
40 class StorageObserver : public nsIObserver,
41 public nsINamed,
42 public nsSupportsWeakReference {
43 public:
44 NS_DECL_ISUPPORTS
45 NS_DECL_NSIOBSERVER
46 NS_DECL_NSINAMED
48 static nsresult Init();
49 static nsresult Shutdown();
50 static StorageObserver* Self() { return sSelf; }
52 void AddSink(StorageObserverSink* aObs);
53 void RemoveSink(StorageObserverSink* aObs);
54 void Notify(const char* aTopic,
55 const nsAString& aOriginAttributesPattern = u""_ns,
56 const nsACString& aOriginScope = ""_ns);
58 void NoteBackgroundThread(uint32_t aPrivateBrowsingId,
59 nsIEventTarget* aBackgroundThread);
61 private:
62 virtual ~StorageObserver() = default;
64 nsresult GetOriginScope(const char16_t* aData, nsACString& aOriginScope);
66 static void TestingPrefChanged(const char* aPrefName, void* aClosure);
68 static StorageObserver* sSelf;
70 nsCOMPtr<nsIEventTarget> mBackgroundThread[2];
72 // Weak references
73 nsTObserverArray<CheckedUnsafePtr<StorageObserverSink>> mSinks;
74 nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
77 } // namespace mozilla::dom
79 #endif // mozilla_dom_StorageObserver_h