Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_SessionStorageManager_h
8
#define mozilla_dom_SessionStorageManager_h
9
10
#include "nsIDOMStorageManager.h"
11
#include "nsClassHashtable.h"
12
#include "nsHashKeys.h"
13
#include "nsRefPtrHashtable.h"
14
#include "StorageObserver.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
class ContentParent;
20
class KeyValuePair;
21
class SessionStorageCache;
22
class SessionStorageObserver;
23
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.
32
//
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.
40
//
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);
47
48
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
49
NS_DECL_NSIDOMSTORAGEMANAGER
50
NS_DECL_NSIDOMSESSIONSTORAGEMANAGER
51
52
NS_DECL_CYCLE_COLLECTION_CLASS(SessionStorageManager)
53
54
RefPtr<BrowsingContext> GetBrowsingContext() const {
55
return mBrowsingContext;
56
}
57
58
void SendSessionStorageDataToParentProcess();
59
void SendSessionStorageDataToContentProcess(ContentParent* aActor,
60
nsIPrincipal* aPrincipal);
61
62
void LoadSessionStorageData(ContentParent* aSource,
63
const nsACString& aOriginAttrs,
64
const nsACString& aOriginKey,
65
const nsTArray<KeyValuePair>& aDefaultData,
66
const nsTArray<KeyValuePair>& aSessionData);
67
68
private:
69
~SessionStorageManager();
70
71
// StorageObserverSink, handler to various chrome clearing notification
72
nsresult Observe(const char* aTopic,
73
const nsAString& aOriginAttributesPattern,
74
const nsACString& aOriginScope) override;
75
76
enum ClearStorageType {
77
eAll,
78
eSessionOnly,
79
};
80
81
void ClearStorages(ClearStorageType aType,
82
const OriginAttributesPattern& aPattern,
83
const nsACString& aOriginScope);
84
85
nsresult GetSessionStorageCacheHelper(nsIPrincipal* aPrincipal,
86
bool aMakeIfNeeded,
87
SessionStorageCache* aCloneFrom,
88
RefPtr<SessionStorageCache>* aRetVal);
89
90
nsresult GetSessionStorageCacheHelper(const nsACString& aOriginAttrs,
91
const nsACString& aOriginKey,
92
bool aMakeIfNeeded,
93
SessionStorageCache* aCloneFrom,
94
RefPtr<SessionStorageCache>* aRetVal);
95
96
struct OriginRecord {
97
RefPtr<SessionStorageCache> mCache;
98
nsTHashtable<nsUint64HashKey> mKnownTo;
99
};
100
101
OriginRecord* GetOriginRecord(const nsACString& aOriginAttrs,
102
const nsACString& aOriginKey,
103
bool aMakeIfNeeded,
104
SessionStorageCache* aCloneFrom);
105
106
template <typename Actor>
107
void SendSessionStorageCache(Actor* aActor, const nsACString& aOriginAttrs,
108
const nsACString& aOriginKey,
109
SessionStorageCache* aCache);
110
111
using OriginKeyHashTable = nsClassHashtable<nsCStringHashKey, OriginRecord>;
112
nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
113
114
RefPtr<SessionStorageObserver> mObserver;
115
116
RefPtr<BrowsingContext> mBrowsingContext;
117
};
118
119
} // namespace dom
120
} // namespace mozilla
121
122
#endif // mozilla_dom_SessionStorageManager_h