Bug 1610775 [wpt PR 21336] - Update urllib3 to 1.25.8, a=testonly
[gecko.git] / dom / storage / SessionStorageManager.h
blob76cd86f0941dffe14b657e07e082df7becb0ae91
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_SessionStorageManager_h
8 #define mozilla_dom_SessionStorageManager_h
10 #include "nsIDOMStorageManager.h"
11 #include "nsClassHashtable.h"
12 #include "nsHashKeys.h"
13 #include "nsRefPtrHashtable.h"
14 #include "StorageObserver.h"
16 namespace mozilla {
17 namespace dom {
19 class ContentParent;
20 class KeyValuePair;
21 class SessionStorageCache;
22 class SessionStorageObserver;
24 // sessionStorage is a data store that's unique to each tab (i.e. top-level
25 // browsing context) and origin. Before the advent of Fission all the data
26 // for a given tab could be stored in a single content process; now each
27 // site-specific process stores only its portion of the data. As content
28 // processes terminate, their sessionStorage data needs to be saved in the
29 // parent process, in case the same origin appears again in the tab (e.g.
30 // by navigating an iframe element). Therefore SessionStorageManager
31 // objects exist in both the parent and content processes.
33 // Whenever a content process terminates it sends its sessionStorage data
34 // to the parent process (see SessionStorageService); whenever a content
35 // process navigates to an origin for the first time in a given tab, the
36 // parent process sends it the saved data. To avoid sending the data
37 // multiple times, the parent process maintains a table of content
38 // processes that already received it; this table is empty in content
39 // processes.
41 // Note: the current implementation is expected to be replaced by a new
42 // implementation using LSNG.
43 class SessionStorageManager final : public nsIDOMSessionStorageManager,
44 public StorageObserverSink {
45 public:
46 explicit SessionStorageManager(RefPtr<BrowsingContext> aBrowsingContext);
48 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
49 NS_DECL_NSIDOMSTORAGEMANAGER
50 NS_DECL_NSIDOMSESSIONSTORAGEMANAGER
52 NS_DECL_CYCLE_COLLECTION_CLASS(SessionStorageManager)
54 RefPtr<BrowsingContext> GetBrowsingContext() const {
55 return mBrowsingContext;
58 void SendSessionStorageDataToParentProcess();
59 void SendSessionStorageDataToContentProcess(ContentParent* aActor,
60 nsIPrincipal* aPrincipal);
62 void LoadSessionStorageData(ContentParent* aSource,
63 const nsACString& aOriginAttrs,
64 const nsACString& aOriginKey,
65 const nsTArray<KeyValuePair>& aDefaultData,
66 const nsTArray<KeyValuePair>& aSessionData);
68 private:
69 ~SessionStorageManager();
71 // StorageObserverSink, handler to various chrome clearing notification
72 nsresult Observe(const char* aTopic,
73 const nsAString& aOriginAttributesPattern,
74 const nsACString& aOriginScope) override;
76 enum ClearStorageType {
77 eAll,
78 eSessionOnly,
81 void ClearStorages(ClearStorageType aType,
82 const OriginAttributesPattern& aPattern,
83 const nsACString& aOriginScope);
85 nsresult GetSessionStorageCacheHelper(nsIPrincipal* aPrincipal,
86 bool aMakeIfNeeded,
87 SessionStorageCache* aCloneFrom,
88 RefPtr<SessionStorageCache>* aRetVal);
90 nsresult GetSessionStorageCacheHelper(const nsACString& aOriginAttrs,
91 const nsACString& aOriginKey,
92 bool aMakeIfNeeded,
93 SessionStorageCache* aCloneFrom,
94 RefPtr<SessionStorageCache>* aRetVal);
96 struct OriginRecord {
97 RefPtr<SessionStorageCache> mCache;
98 nsTHashtable<nsUint64HashKey> mKnownTo;
101 OriginRecord* GetOriginRecord(const nsACString& aOriginAttrs,
102 const nsACString& aOriginKey,
103 bool aMakeIfNeeded,
104 SessionStorageCache* aCloneFrom);
106 template <typename Actor>
107 void SendSessionStorageCache(Actor* aActor, const nsACString& aOriginAttrs,
108 const nsACString& aOriginKey,
109 SessionStorageCache* aCache);
111 using OriginKeyHashTable = nsClassHashtable<nsCStringHashKey, OriginRecord>;
112 nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
114 RefPtr<SessionStorageObserver> mObserver;
116 RefPtr<BrowsingContext> mBrowsingContext;
119 } // namespace dom
120 } // namespace mozilla
122 #endif // mozilla_dom_SessionStorageManager_h