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_LocalStorage_h
8
#define mozilla_dom_LocalStorage_h
9
10
#include "Storage.h"
11
#include "nsWeakReference.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
class LocalStorageCache;
17
class LocalStorageManager;
18
class StorageEvent;
19
20
class LocalStorage final : public Storage, public nsSupportsWeakReference {
21
public:
22
NS_DECL_ISUPPORTS_INHERITED
23
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LocalStorage, Storage)
24
25
StorageType Type() const override { return eLocalStorage; }
26
27
LocalStorageManager* GetManager() const { return mManager; }
28
29
LocalStorageCache const* GetCache() const { return mCache; }
30
31
const nsString& DocumentURI() const { return mDocumentURI; }
32
33
LocalStorage(nsPIDOMWindowInner* aWindow, LocalStorageManager* aManager,
34
LocalStorageCache* aCache, const nsAString& aDocumentURI,
35
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal,
36
bool aIsPrivate);
37
38
bool IsForkOf(const Storage* aOther) const override;
39
40
// WebIDL
41
42
int64_t GetOriginQuotaUsage() const override;
43
44
uint32_t GetLength(nsIPrincipal& aSubjectPrincipal,
45
ErrorResult& aRv) override;
46
47
void Key(uint32_t aIndex, nsAString& aResult, nsIPrincipal& aSubjectPrincipal,
48
ErrorResult& aRv) override;
49
50
void GetItem(const nsAString& aKey, nsAString& aResult,
51
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) override;
52
53
void GetSupportedNames(nsTArray<nsString>& aKeys) override;
54
55
void SetItem(const nsAString& aKey, const nsAString& aValue,
56
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) override;
57
58
void RemoveItem(const nsAString& aKey, nsIPrincipal& aSubjectPrincipal,
59
ErrorResult& aRv) override;
60
61
void Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) override;
62
63
bool IsPrivate() const { return mIsPrivate; }
64
65
void ApplyEvent(StorageEvent* aStorageEvent);
66
67
private:
68
~LocalStorage();
69
70
friend class LocalStorageManager;
71
friend class LocalStorageCache;
72
73
RefPtr<LocalStorageManager> mManager;
74
RefPtr<LocalStorageCache> mCache;
75
nsString mDocumentURI;
76
77
// Whether this storage is running in private-browsing window.
78
bool mIsPrivate : 1;
79
80
void OnChange(const nsAString& aKey, const nsAString& aOldValue,
81
const nsAString& aNewValue);
82
};
83
84
} // namespace dom
85
} // namespace mozilla
86
87
#endif // mozilla_dom_LocalStorage_h