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

     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/. */
     6 #ifndef nsDOMStorage_h___
     7 #define nsDOMStorage_h___
     9 #include "mozilla/Attributes.h"
    10 #include "nsIDOMStorage.h"
    11 #include "nsPIDOMStorage.h"
    12 #include "nsWeakReference.h"
    13 #include "nsAutoPtr.h"
    15 namespace mozilla {
    16 namespace dom {
    18 class DOMStorageManager;
    19 class DOMStorageCache;
    21 class DOMStorage MOZ_FINAL : public nsIDOMStorage
    22                            , public nsPIDOMStorage
    23                            , public nsSupportsWeakReference
    24 {
    25   NS_DECL_ISUPPORTS
    26   NS_DECL_NSIDOMSTORAGE
    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; }
    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; }
    39   DOMStorage(DOMStorageManager* aManager,
    40              DOMStorageCache* aCache,
    41              const nsAString& aDocumentURI,
    42              nsIPrincipal* aPrincipal,
    43              bool aIsPrivate);
    44   ~DOMStorage();
    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);
    55   bool IsPrivate() const { return mIsPrivate; }
    56   bool IsSessionOnly() const { return mIsSessionOnly; }
    58 private:
    59   friend class DOMStorageManager;
    60   friend class DOMStorageCache;
    62   nsRefPtr<DOMStorageManager> mManager;
    63   nsRefPtr<DOMStorageCache> mCache;
    64   nsString mDocumentURI;
    66   // Principal this DOMStorage (i.e. localStorage or sessionStorage) has
    67   // been created for
    68   nsCOMPtr<nsIPrincipal> mPrincipal;
    70   // Whether this storage is running in private-browsing window.
    71   bool mIsPrivate : 1;
    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;
    78   void BroadcastChangeNotification(const nsSubstring& aKey,
    79                                    const nsSubstring& aOldValue,
    80                                    const nsSubstring& aNewValue);
    81 };
    83 } // ::dom
    84 } // ::mozilla
    86 #endif /* nsDOMStorage_h___ */

mercurial