michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDOMStorage_h___ michael@0: #define nsDOMStorage_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIDOMStorage.h" michael@0: #include "nsPIDOMStorage.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class DOMStorageManager; michael@0: class DOMStorageCache; michael@0: michael@0: class DOMStorage MOZ_FINAL : public nsIDOMStorage michael@0: , public nsPIDOMStorage michael@0: , public nsSupportsWeakReference michael@0: { michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDOMSTORAGE michael@0: michael@0: // nsPIDOMStorage michael@0: virtual StorageType GetType() const MOZ_OVERRIDE; michael@0: virtual DOMStorageManager* GetManager() const MOZ_OVERRIDE { return mManager; } michael@0: virtual const DOMStorageCache* GetCache() const MOZ_OVERRIDE { return mCache; } michael@0: michael@0: virtual nsTArray* GetKeys() MOZ_OVERRIDE; michael@0: virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE; michael@0: virtual bool PrincipalEquals(nsIPrincipal* aPrincipal) MOZ_OVERRIDE; michael@0: virtual bool CanAccess(nsIPrincipal* aPrincipal) MOZ_OVERRIDE; michael@0: virtual bool IsPrivate() MOZ_OVERRIDE { return mIsPrivate; } michael@0: michael@0: DOMStorage(DOMStorageManager* aManager, michael@0: DOMStorageCache* aCache, michael@0: const nsAString& aDocumentURI, michael@0: nsIPrincipal* aPrincipal, michael@0: bool aIsPrivate); michael@0: ~DOMStorage(); michael@0: michael@0: // The method checks whether the caller can use a storage. michael@0: // CanUseStorage is called before any DOM initiated operation michael@0: // on a storage is about to happen and ensures that the storage's michael@0: // session-only flag is properly set according the current settings. michael@0: // It is an optimization since the privileges check and session only michael@0: // state determination are complex and share the code (comes hand in michael@0: // hand together). michael@0: static bool CanUseStorage(DOMStorage* aStorage = nullptr); michael@0: michael@0: bool IsPrivate() const { return mIsPrivate; } michael@0: bool IsSessionOnly() const { return mIsSessionOnly; } michael@0: michael@0: private: michael@0: friend class DOMStorageManager; michael@0: friend class DOMStorageCache; michael@0: michael@0: nsRefPtr mManager; michael@0: nsRefPtr mCache; michael@0: nsString mDocumentURI; michael@0: michael@0: // Principal this DOMStorage (i.e. localStorage or sessionStorage) has michael@0: // been created for michael@0: nsCOMPtr mPrincipal; michael@0: michael@0: // Whether this storage is running in private-browsing window. michael@0: bool mIsPrivate : 1; michael@0: michael@0: // Whether storage is set to persist data only per session, may change michael@0: // dynamically and is set by CanUseStorage function that is called michael@0: // before any operation on the storage. michael@0: bool mIsSessionOnly : 1; michael@0: michael@0: void BroadcastChangeNotification(const nsSubstring& aKey, michael@0: const nsSubstring& aOldValue, michael@0: const nsSubstring& aNewValue); michael@0: }; michael@0: michael@0: } // ::dom michael@0: } // ::mozilla michael@0: michael@0: #endif /* nsDOMStorage_h___ */