dom/src/storage/DOMStorage.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial