/src/mozilla-central/dom/storage/LocalStorage.h
Line | Count | Source (jump to first uncovered line) |
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 |
21 | | , public nsSupportsWeakReference |
22 | | { |
23 | | public: |
24 | | NS_DECL_ISUPPORTS_INHERITED |
25 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LocalStorage, Storage) |
26 | | |
27 | 0 | StorageType Type() const override { return eLocalStorage; } |
28 | | |
29 | | LocalStorageManager* GetManager() const |
30 | | { |
31 | | return mManager; |
32 | | } |
33 | | |
34 | | LocalStorageCache const* GetCache() const |
35 | 0 | { |
36 | 0 | return mCache; |
37 | 0 | } |
38 | | |
39 | | const nsString& |
40 | | DocumentURI() const |
41 | 0 | { |
42 | 0 | return mDocumentURI; |
43 | 0 | } |
44 | | |
45 | | bool PrincipalEquals(nsIPrincipal* aPrincipal); |
46 | | |
47 | | LocalStorage(nsPIDOMWindowInner* aWindow, |
48 | | LocalStorageManager* aManager, |
49 | | LocalStorageCache* aCache, |
50 | | const nsAString& aDocumentURI, |
51 | | nsIPrincipal* aPrincipal, |
52 | | bool aIsPrivate); |
53 | | |
54 | | bool IsForkOf(const Storage* aOther) const override; |
55 | | |
56 | | // WebIDL |
57 | | |
58 | | int64_t GetOriginQuotaUsage() const override; |
59 | | |
60 | | uint32_t GetLength(nsIPrincipal& aSubjectPrincipal, |
61 | | ErrorResult& aRv) override; |
62 | | |
63 | | void Key(uint32_t aIndex, nsAString& aResult, |
64 | | nsIPrincipal& aSubjectPrincipal, |
65 | | ErrorResult& aRv) override; |
66 | | |
67 | | void GetItem(const nsAString& aKey, nsAString& aResult, |
68 | | nsIPrincipal& aSubjectPrincipal, |
69 | | ErrorResult& aRv) override; |
70 | | |
71 | | void GetSupportedNames(nsTArray<nsString>& aKeys) override; |
72 | | |
73 | | void SetItem(const nsAString& aKey, const nsAString& aValue, |
74 | | nsIPrincipal& aSubjectPrincipal, |
75 | | ErrorResult& aRv) override; |
76 | | |
77 | | void RemoveItem(const nsAString& aKey, |
78 | | nsIPrincipal& aSubjectPrincipal, |
79 | | ErrorResult& aRv) override; |
80 | | |
81 | | void Clear(nsIPrincipal& aSubjectPrincipal, |
82 | | ErrorResult& aRv) override; |
83 | | |
84 | 0 | bool IsPrivate() const { return mIsPrivate; } |
85 | | |
86 | | void |
87 | | ApplyEvent(StorageEvent* aStorageEvent); |
88 | | |
89 | | private: |
90 | | ~LocalStorage(); |
91 | | |
92 | | friend class LocalStorageManager; |
93 | | friend class LocalStorageCache; |
94 | | |
95 | | RefPtr<LocalStorageManager> mManager; |
96 | | RefPtr<LocalStorageCache> mCache; |
97 | | nsString mDocumentURI; |
98 | | |
99 | | // Principal this Storage (i.e. localStorage or sessionStorage) has |
100 | | // been created for |
101 | | nsCOMPtr<nsIPrincipal> mPrincipal; |
102 | | |
103 | | // Whether this storage is running in private-browsing window. |
104 | | bool mIsPrivate : 1; |
105 | | |
106 | | void OnChange(const nsAString& aKey, |
107 | | const nsAString& aOldValue, |
108 | | const nsAString& aNewValue); |
109 | | }; |
110 | | |
111 | | } // namespace dom |
112 | | } // namespace mozilla |
113 | | |
114 | | #endif // mozilla_dom_LocalStorage_h |