|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsDOMStorage_h___ |
|
7 #define nsDOMStorage_h___ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsIDOMStorage.h" |
|
11 #include "nsPIDOMStorage.h" |
|
12 #include "nsWeakReference.h" |
|
13 #include "nsAutoPtr.h" |
|
14 |
|
15 namespace mozilla { |
|
16 namespace dom { |
|
17 |
|
18 class DOMStorageManager; |
|
19 class DOMStorageCache; |
|
20 |
|
21 class DOMStorage MOZ_FINAL : public nsIDOMStorage |
|
22 , public nsPIDOMStorage |
|
23 , public nsSupportsWeakReference |
|
24 { |
|
25 NS_DECL_ISUPPORTS |
|
26 NS_DECL_NSIDOMSTORAGE |
|
27 |
|
28 // nsPIDOMStorage |
|
29 virtual StorageType GetType() const MOZ_OVERRIDE; |
|
30 virtual DOMStorageManager* GetManager() const MOZ_OVERRIDE { return mManager; } |
|
31 virtual const DOMStorageCache* GetCache() const MOZ_OVERRIDE { return mCache; } |
|
32 |
|
33 virtual nsTArray<nsString>* GetKeys() MOZ_OVERRIDE; |
|
34 virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE; |
|
35 virtual bool PrincipalEquals(nsIPrincipal* aPrincipal) MOZ_OVERRIDE; |
|
36 virtual bool CanAccess(nsIPrincipal* aPrincipal) MOZ_OVERRIDE; |
|
37 virtual bool IsPrivate() MOZ_OVERRIDE { return mIsPrivate; } |
|
38 |
|
39 DOMStorage(DOMStorageManager* aManager, |
|
40 DOMStorageCache* aCache, |
|
41 const nsAString& aDocumentURI, |
|
42 nsIPrincipal* aPrincipal, |
|
43 bool aIsPrivate); |
|
44 ~DOMStorage(); |
|
45 |
|
46 // The method checks whether the caller can use a storage. |
|
47 // CanUseStorage is called before any DOM initiated operation |
|
48 // on a storage is about to happen and ensures that the storage's |
|
49 // session-only flag is properly set according the current settings. |
|
50 // It is an optimization since the privileges check and session only |
|
51 // state determination are complex and share the code (comes hand in |
|
52 // hand together). |
|
53 static bool CanUseStorage(DOMStorage* aStorage = nullptr); |
|
54 |
|
55 bool IsPrivate() const { return mIsPrivate; } |
|
56 bool IsSessionOnly() const { return mIsSessionOnly; } |
|
57 |
|
58 private: |
|
59 friend class DOMStorageManager; |
|
60 friend class DOMStorageCache; |
|
61 |
|
62 nsRefPtr<DOMStorageManager> mManager; |
|
63 nsRefPtr<DOMStorageCache> mCache; |
|
64 nsString mDocumentURI; |
|
65 |
|
66 // Principal this DOMStorage (i.e. localStorage or sessionStorage) has |
|
67 // been created for |
|
68 nsCOMPtr<nsIPrincipal> mPrincipal; |
|
69 |
|
70 // Whether this storage is running in private-browsing window. |
|
71 bool mIsPrivate : 1; |
|
72 |
|
73 // Whether storage is set to persist data only per session, may change |
|
74 // dynamically and is set by CanUseStorage function that is called |
|
75 // before any operation on the storage. |
|
76 bool mIsSessionOnly : 1; |
|
77 |
|
78 void BroadcastChangeNotification(const nsSubstring& aKey, |
|
79 const nsSubstring& aOldValue, |
|
80 const nsSubstring& aNewValue); |
|
81 }; |
|
82 |
|
83 } // ::dom |
|
84 } // ::mozilla |
|
85 |
|
86 #endif /* nsDOMStorage_h___ */ |