dom/src/storage/DOMStorage.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/src/storage/DOMStorage.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsDOMStorage_h___
    1.10 +#define nsDOMStorage_h___
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsIDOMStorage.h"
    1.14 +#include "nsPIDOMStorage.h"
    1.15 +#include "nsWeakReference.h"
    1.16 +#include "nsAutoPtr.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace dom {
    1.20 +
    1.21 +class DOMStorageManager;
    1.22 +class DOMStorageCache;
    1.23 +
    1.24 +class DOMStorage MOZ_FINAL : public nsIDOMStorage
    1.25 +                           , public nsPIDOMStorage
    1.26 +                           , public nsSupportsWeakReference
    1.27 +{
    1.28 +  NS_DECL_ISUPPORTS
    1.29 +  NS_DECL_NSIDOMSTORAGE
    1.30 +
    1.31 +  // nsPIDOMStorage
    1.32 +  virtual StorageType GetType() const MOZ_OVERRIDE;
    1.33 +  virtual DOMStorageManager* GetManager() const MOZ_OVERRIDE { return mManager; }
    1.34 +  virtual const DOMStorageCache* GetCache() const MOZ_OVERRIDE { return mCache; }
    1.35 +
    1.36 +  virtual nsTArray<nsString>* GetKeys() MOZ_OVERRIDE;
    1.37 +  virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE;
    1.38 +  virtual bool PrincipalEquals(nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
    1.39 +  virtual bool CanAccess(nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
    1.40 +  virtual bool IsPrivate() MOZ_OVERRIDE { return mIsPrivate; }
    1.41 +
    1.42 +  DOMStorage(DOMStorageManager* aManager,
    1.43 +             DOMStorageCache* aCache,
    1.44 +             const nsAString& aDocumentURI,
    1.45 +             nsIPrincipal* aPrincipal,
    1.46 +             bool aIsPrivate);
    1.47 +  ~DOMStorage();
    1.48 +
    1.49 +  // The method checks whether the caller can use a storage.
    1.50 +  // CanUseStorage is called before any DOM initiated operation
    1.51 +  // on a storage is about to happen and ensures that the storage's
    1.52 +  // session-only flag is properly set according the current settings.
    1.53 +  // It is an optimization since the privileges check and session only
    1.54 +  // state determination are complex and share the code (comes hand in
    1.55 +  // hand together).
    1.56 +  static bool CanUseStorage(DOMStorage* aStorage = nullptr);
    1.57 +
    1.58 +  bool IsPrivate() const { return mIsPrivate; }
    1.59 +  bool IsSessionOnly() const { return mIsSessionOnly; }
    1.60 +
    1.61 +private:
    1.62 +  friend class DOMStorageManager;
    1.63 +  friend class DOMStorageCache;
    1.64 +
    1.65 +  nsRefPtr<DOMStorageManager> mManager;
    1.66 +  nsRefPtr<DOMStorageCache> mCache;
    1.67 +  nsString mDocumentURI;
    1.68 +
    1.69 +  // Principal this DOMStorage (i.e. localStorage or sessionStorage) has
    1.70 +  // been created for
    1.71 +  nsCOMPtr<nsIPrincipal> mPrincipal;
    1.72 +
    1.73 +  // Whether this storage is running in private-browsing window.
    1.74 +  bool mIsPrivate : 1;
    1.75 +
    1.76 +  // Whether storage is set to persist data only per session, may change
    1.77 +  // dynamically and is set by CanUseStorage function that is called
    1.78 +  // before any operation on the storage.
    1.79 +  bool mIsSessionOnly : 1;
    1.80 +
    1.81 +  void BroadcastChangeNotification(const nsSubstring& aKey,
    1.82 +                                   const nsSubstring& aOldValue,
    1.83 +                                   const nsSubstring& aNewValue);
    1.84 +};
    1.85 +
    1.86 +} // ::dom
    1.87 +} // ::mozilla
    1.88 +
    1.89 +#endif /* nsDOMStorage_h___ */

mercurial