LCOV - code coverage report
Current view: directory - dom/src/storage - nsDOMStorage.h (source / functions) Found Hit Coverage
Test: app.info Lines: 56 32 57.1 %
Date: 2012-07-07 Functions: 71 31 43.7 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Neil Deakin <enndeakin@sympatico.ca>
      24                 :  *   Johnny Stenback <jst@mozilla.com>
      25                 :  *   Ehsan Akhgari <ehsan.akhgari@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef nsDOMStorage_h___
      42                 : #define nsDOMStorage_h___
      43                 : 
      44                 : #include "nscore.h"
      45                 : #include "nsAutoPtr.h"
      46                 : #include "nsIDOMStorageObsolete.h"
      47                 : #include "nsIDOMStorage.h"
      48                 : #include "nsIDOMStorageList.h"
      49                 : #include "nsIDOMStorageItem.h"
      50                 : #include "nsIPermissionManager.h"
      51                 : #include "nsInterfaceHashtable.h"
      52                 : #include "nsVoidArray.h"
      53                 : #include "nsTArray.h"
      54                 : #include "nsPIDOMStorage.h"
      55                 : #include "nsIDOMToString.h"
      56                 : #include "nsDOMEvent.h"
      57                 : #include "nsIDOMStorageEvent.h"
      58                 : #include "nsIDOMStorageEventObsolete.h"
      59                 : #include "nsIDOMStorageManager.h"
      60                 : #include "nsCycleCollectionParticipant.h"
      61                 : #include "nsIObserver.h"
      62                 : #include "nsITimer.h"
      63                 : #include "nsWeakReference.h"
      64                 : 
      65                 : #include "nsDOMStorageDBWrapper.h"
      66                 : 
      67                 : #define IS_PERMISSION_ALLOWED(perm) \
      68                 :       ((perm) != nsIPermissionManager::UNKNOWN_ACTION && \
      69                 :       (perm) != nsIPermissionManager::DENY_ACTION)
      70                 : 
      71                 : class nsDOMStorage;
      72                 : class nsIDOMStorage;
      73                 : class nsDOMStorageItem;
      74                 : class nsDOMStoragePersistentDB;
      75                 : 
      76                 : namespace mozilla {
      77                 : namespace dom {
      78                 : class StorageParent;
      79                 : }
      80                 : }
      81                 : using mozilla::dom::StorageParent;
      82                 : 
      83                 : class DOMStorageImpl;
      84                 : 
      85                 : class nsDOMStorageEntry : public nsVoidPtrHashKey
      86                 : {
      87                 : public:
      88                 :   nsDOMStorageEntry(KeyTypePointer aStr);
      89                 :   nsDOMStorageEntry(const nsDOMStorageEntry& aToCopy);
      90                 :   ~nsDOMStorageEntry();
      91                 : 
      92                 :   // weak reference so that it can be deleted when no longer used
      93                 :   DOMStorageImpl* mStorage;
      94                 : };
      95                 : 
      96                 : class nsSessionStorageEntry : public nsStringHashKey
      97                 : {
      98                 : public:
      99                 :   nsSessionStorageEntry(KeyTypePointer aStr);
     100                 :   nsSessionStorageEntry(const nsSessionStorageEntry& aToCopy);
     101                 :   ~nsSessionStorageEntry();
     102                 : 
     103                 :   nsRefPtr<nsDOMStorageItem> mItem;
     104                 : };
     105                 : 
     106                 : class nsDOMStorageManager : public nsIDOMStorageManager
     107                 :                           , public nsIObserver
     108                 :                           , public nsSupportsWeakReference
     109            1403 : {
     110                 : public:
     111                 :   // nsISupports
     112                 :   NS_DECL_ISUPPORTS
     113                 : 
     114                 :   // nsIDOMStorageManager
     115                 :   NS_DECL_NSIDOMSTORAGEMANAGER
     116                 : 
     117                 :   // nsIObserver
     118                 :   NS_DECL_NSIOBSERVER
     119                 : 
     120                 :   nsDOMStorageManager();
     121                 : 
     122                 :   void AddToStoragesHash(DOMStorageImpl* aStorage);
     123                 :   void RemoveFromStoragesHash(DOMStorageImpl* aStorage);
     124                 : 
     125                 :   nsresult ClearAllStorages();
     126                 : 
     127             153 :   bool InPrivateBrowsingMode() { return mInPrivateBrowsing; }
     128                 : 
     129                 :   static nsresult Initialize();
     130                 :   static nsDOMStorageManager* GetInstance();
     131                 :   static void Shutdown();
     132                 :   static void ShutdownDB();
     133                 : 
     134                 :   /**
     135                 :    * Checks whether there is any data waiting to be flushed from a temp table.
     136                 :    */
     137                 :   bool UnflushedDataExists();
     138                 : 
     139                 :   static nsDOMStorageManager* gStorageManager;
     140                 : 
     141                 : protected:
     142                 : 
     143                 :   nsTHashtable<nsDOMStorageEntry> mStorages;
     144                 :   bool mInPrivateBrowsing;
     145                 : };
     146                 : 
     147                 : class DOMStorageBase : public nsISupports
     148              20 : {
     149                 : public:
     150                 :   DOMStorageBase();
     151                 :   DOMStorageBase(DOMStorageBase&);
     152                 : 
     153                 :   virtual void InitAsSessionStorage(nsIURI* aDomainURI);
     154                 :   virtual void InitAsLocalStorage(nsIURI* aDomainURI, bool aCanUseChromePersist);
     155                 :   virtual void InitAsGlobalStorage(const nsACString& aDomainDemanded);
     156                 : 
     157                 :   virtual nsTArray<nsString>* GetKeys(bool aCallerSecure) = 0;
     158                 :   virtual nsresult GetLength(bool aCallerSecure, PRUint32* aLength) = 0;
     159                 :   virtual nsresult GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey) = 0;
     160                 :   virtual nsIDOMStorageItem* GetValue(bool aCallerSecure, const nsAString& aKey,
     161                 :                                       nsresult* rv) = 0;
     162                 :   virtual nsresult SetValue(bool aCallerSecure, const nsAString& aKey,
     163                 :                             const nsAString& aData, nsAString& aOldValue) = 0;
     164                 :   virtual nsresult RemoveValue(bool aCallerSecure, const nsAString& aKey,
     165                 :                                nsAString& aOldValue) = 0;
     166                 :   virtual nsresult Clear(bool aCallerSecure, PRInt32* aOldCount) = 0;
     167                 :   
     168                 :   // If true, the contents of the storage should be stored in the
     169                 :   // database, otherwise this storage should act like a session
     170                 :   // storage.
     171                 :   // This call relies on mSessionOnly, and should only be used
     172                 :   // after a CacheStoragePermissions() call.  See the comments
     173                 :   // for mSessionOnly below.
     174             216 :   bool UseDB() {
     175             216 :     return mUseDB;
     176                 :   }
     177                 : 
     178                 :   // retrieve the value and secure state corresponding to a key out of storage.
     179                 :   virtual nsresult
     180                 :   GetDBValue(const nsAString& aKey,
     181                 :              nsAString& aValue,
     182                 :              bool* aSecure) = 0;
     183                 : 
     184                 :   // set the value corresponding to a key in the storage. If
     185                 :   // aSecure is false, then attempts to modify a secure value
     186                 :   // throw NS_ERROR_DOM_INVALID_ACCESS_ERR
     187                 :   virtual nsresult
     188                 :   SetDBValue(const nsAString& aKey,
     189                 :              const nsAString& aValue,
     190                 :              bool aSecure) = 0;
     191                 : 
     192                 :   // set the value corresponding to a key as secure.
     193                 :   virtual nsresult
     194                 :   SetSecure(const nsAString& aKey, bool aSecure) = 0;
     195                 : 
     196                 :   virtual nsresult
     197                 :   CloneFrom(bool aCallerSecure, DOMStorageBase* aThat) = 0;
     198                 : 
     199                 :   // e.g. "moc.rab.oof.:" or "moc.rab.oof.:http:80" depending
     200                 :   // on association with a domain (globalStorage) or
     201                 :   // an origin (localStorage).
     202             428 :   nsCString& GetScopeDBKey() {return mScopeDBKey;}
     203                 : 
     204                 :   // e.g. "moc.rab.%" - reversed eTLD+1 subpart of the domain or
     205                 :   // reversed offline application allowed domain.
     206              48 :   nsCString& GetQuotaDomainDBKey(bool aOfflineAllowed)
     207                 :   {
     208              48 :     return aOfflineAllowed ? mQuotaDomainDBKey : mQuotaETLDplus1DomainDBKey;
     209                 :   }
     210                 : 
     211                 :   virtual bool CacheStoragePermissions() = 0;
     212                 : 
     213                 : protected:
     214                 :   friend class nsDOMStorageManager;
     215                 :   friend class nsDOMStorage;
     216                 : 
     217                 :   nsPIDOMStorage::nsDOMStorageType mStorageType;
     218                 :   
     219                 :   // true if the storage database should be used for values
     220                 :   bool mUseDB;
     221                 : 
     222                 :   // true if the preferences indicates that this storage should be
     223                 :   // session only. This member is updated by
     224                 :   // CacheStoragePermissions(), using the current principal.
     225                 :   // CacheStoragePermissions() must be called at each entry point to
     226                 :   // make sure this stays up to date.
     227                 :   bool mSessionOnly;
     228                 : 
     229                 :   // domain this store is associated with
     230                 :   nsCString mDomain;
     231                 : 
     232                 :   // keys are used for database queries.
     233                 :   // see comments of the getters bellow.
     234                 :   nsCString mScopeDBKey;
     235                 :   nsCString mQuotaETLDplus1DomainDBKey;
     236                 :   nsCString mQuotaDomainDBKey;
     237                 : 
     238                 :   bool mCanUseChromePersist;
     239                 : };
     240                 : 
     241                 : class DOMStorageImpl : public DOMStorageBase
     242                 : 
     243                 : {
     244                 : public:
     245            1608 :   NS_DECL_CYCLE_COLLECTION_CLASS(DOMStorageImpl)
     246               4 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     247                 : 
     248                 :   DOMStorageImpl(nsDOMStorage*);
     249                 :   DOMStorageImpl(nsDOMStorage*, DOMStorageImpl&);
     250                 :   ~DOMStorageImpl();
     251                 : 
     252                 :   virtual void InitAsSessionStorage(nsIURI* aDomainURI);
     253                 :   virtual void InitAsLocalStorage(nsIURI* aDomainURI, bool aCanUseChromePersist);
     254                 :   virtual void InitAsGlobalStorage(const nsACString& aDomainDemanded);
     255                 : 
     256              92 :   bool SessionOnly() {
     257              92 :     return mSessionOnly;
     258                 :   }
     259                 : 
     260                 :   virtual nsTArray<nsString>* GetKeys(bool aCallerSecure);
     261                 :   virtual nsresult GetLength(bool aCallerSecure, PRUint32* aLength);
     262                 :   virtual nsresult GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey);
     263                 :   virtual nsIDOMStorageItem* GetValue(bool aCallerSecure, const nsAString& aKey,
     264                 :                                       nsresult* rv);
     265                 :   virtual nsresult SetValue(bool aCallerSecure, const nsAString& aKey,
     266                 :                             const nsAString& aData, nsAString& aOldValue);
     267                 :   virtual nsresult RemoveValue(bool aCallerSecure, const nsAString& aKey,
     268                 :                                nsAString& aOldValue);
     269                 :   virtual nsresult Clear(bool aCallerSecure, PRInt32* aOldCount);
     270                 : 
     271                 :   // cache the keys from the database for faster lookup
     272                 :   nsresult CacheKeysFromDB();
     273                 : 
     274             156 :   PRUint64 CachedVersion() { return mItemsCachedVersion; }
     275              98 :   void SetCachedVersion(PRUint64 version) { mItemsCachedVersion = version; }
     276                 :   
     277                 :   // Some privileged internal pages can use a persistent storage even in
     278                 :   // session-only or private-browsing modes.
     279                 :   bool CanUseChromePersist();
     280                 : 
     281                 :   // retrieve the value and secure state corresponding to a key out of storage
     282                 :   // that has been cached in mItems hash table.
     283                 :   nsresult
     284                 :   GetCachedValue(const nsAString& aKey,
     285                 :                  nsAString& aValue,
     286                 :                  bool* aSecure);
     287                 : 
     288                 :   // retrieve the value and secure state corresponding to a key out of storage.
     289                 :   virtual nsresult
     290                 :   GetDBValue(const nsAString& aKey,
     291                 :              nsAString& aValue,
     292                 :              bool* aSecure);
     293                 : 
     294                 :   // set the value corresponding to a key in the storage. If
     295                 :   // aSecure is false, then attempts to modify a secure value
     296                 :   // throw NS_ERROR_DOM_INVALID_ACCESS_ERR
     297                 :   virtual nsresult
     298                 :   SetDBValue(const nsAString& aKey,
     299                 :              const nsAString& aValue,
     300                 :              bool aSecure);
     301                 : 
     302                 :   // set the value corresponding to a key as secure.
     303                 :   virtual nsresult
     304                 :   SetSecure(const nsAString& aKey, bool aSecure);
     305                 : 
     306                 :   // clear all values from the store
     307                 :   void ClearAll();
     308                 : 
     309                 :   virtual nsresult
     310                 :   CloneFrom(bool aCallerSecure, DOMStorageBase* aThat);
     311                 : 
     312                 :   virtual bool CacheStoragePermissions();
     313                 : 
     314                 : private:
     315                 :   static nsDOMStorageDBWrapper* gStorageDB;
     316                 :   friend class nsDOMStorageManager;
     317                 :   friend class nsDOMStoragePersistentDB;
     318                 :   friend class StorageParent;
     319                 : 
     320                 :   void Init(nsDOMStorage*);
     321                 : 
     322                 :   // Cross-process storage implementations never have InitAs(Session|Local|Global)Storage
     323                 :   // called, so the appropriate initialization needs to happen from the child.
     324                 :   void InitFromChild(bool aUseDB, bool aCanUseChromePersist, bool aSessionOnly,
     325                 :                      const nsACString& aDomain,
     326                 :                      const nsACString& aScopeDBKey,
     327                 :                      const nsACString& aQuotaDomainDBKey,
     328                 :                      const nsACString& aQuotaETLDplus1DomainDBKey,
     329                 :                      PRUint32 aStorageType);
     330                 :   void SetSessionOnly(bool aSessionOnly);
     331                 : 
     332                 :   static nsresult InitDB();
     333                 : 
     334                 :   // 0 initially or a positive data version number assigned by gStorageDB
     335                 :   // after keys have been cached from the database
     336                 :   PRUint64 mItemsCachedVersion;
     337                 : 
     338                 :   // the key->value item pairs
     339                 :   nsTHashtable<nsSessionStorageEntry> mItems;
     340                 : 
     341                 :   // Weak reference to the owning storage instance
     342                 :   nsDOMStorage* mOwner;
     343                 : };
     344                 : 
     345                 : class nsDOMStorage : public nsIDOMStorageObsolete,
     346                 :                      public nsPIDOMStorage
     347                 : {
     348                 : public:
     349                 :   nsDOMStorage();
     350                 :   nsDOMStorage(nsDOMStorage& aThat);
     351                 :   virtual ~nsDOMStorage();
     352                 : 
     353               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     354            1504 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorage, nsIDOMStorageObsolete)
     355                 : 
     356                 :   NS_DECL_NSIDOMSTORAGEOBSOLETE
     357                 : 
     358                 :   // Helpers for implementing nsIDOMStorage
     359                 :   nsresult GetItem(const nsAString& key, nsAString& aData);
     360                 :   nsresult Clear();
     361                 : 
     362                 :   // nsPIDOMStorage
     363                 :   virtual nsresult InitAsSessionStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     364                 :   virtual nsresult InitAsLocalStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     365                 :   virtual nsresult InitAsGlobalStorage(const nsACString &aDomainDemanded);
     366                 :   virtual already_AddRefed<nsIDOMStorage> Clone();
     367                 :   virtual already_AddRefed<nsIDOMStorage> Fork(const nsSubstring &aDocumentURI);
     368                 :   virtual bool IsForkOf(nsIDOMStorage* aThat);
     369                 :   virtual nsTArray<nsString> *GetKeys();
     370                 :   virtual nsIPrincipal* Principal();
     371                 :   virtual bool CanAccess(nsIPrincipal *aPrincipal);
     372                 :   virtual nsDOMStorageType StorageType();
     373                 :   virtual void BroadcastChangeNotification(const nsSubstring &aKey,
     374                 :                                            const nsSubstring &aOldValue,
     375                 :                                            const nsSubstring &aNewValue);
     376                 : 
     377                 :   // Check whether storage may be used by the caller, and whether it
     378                 :   // is session only.  Returns true if storage may be used.
     379                 :   static bool
     380                 :   CanUseStorage(bool* aSessionOnly);
     381                 : 
     382                 :   // Check whether this URI can use chrome persist storage.  This kind of
     383                 :   // storage can bypass cookies limits, private browsing and uses the offline
     384                 :   // apps quota.
     385                 :   static bool
     386                 :   URICanUseChromePersist(nsIURI* aURI);
     387                 :   
     388                 :   // Check whether storage may be used.  Updates mSessionOnly based on
     389                 :   // the result of CanUseStorage.
     390                 :   bool
     391                 :   CacheStoragePermissions();
     392                 : 
     393                 :   nsIDOMStorageItem* GetNamedItem(const nsAString& aKey, nsresult* aResult);
     394                 : 
     395               0 :   static nsDOMStorage* FromSupports(nsISupports* aSupports)
     396                 :   {
     397               0 :     return static_cast<nsDOMStorage*>(static_cast<nsIDOMStorageObsolete*>(aSupports));
     398                 :   }
     399                 : 
     400                 :   nsresult SetSecure(const nsAString& aKey, bool aSecure)
     401                 :   {
     402                 :     return mStorageImpl->SetSecure(aKey, aSecure);
     403                 :   }
     404                 : 
     405                 :   nsresult CloneFrom(nsDOMStorage* aThat);
     406                 : 
     407                 :  protected:
     408                 :   friend class nsDOMStorage2;
     409                 :   friend class nsDOMStoragePersistentDB;
     410                 : 
     411                 :   nsRefPtr<DOMStorageBase> mStorageImpl;
     412                 : 
     413                 :   bool CanAccessSystem(nsIPrincipal *aPrincipal);
     414                 : 
     415                 :   // document URI of the document this storage is bound to
     416                 :   nsString mDocumentURI;
     417                 : 
     418                 :   // true if this storage was initialized as a localStorage object.  localStorage
     419                 :   // objects are scoped to scheme/host/port in the database, while globalStorage
     420                 :   // objects are scoped just to host.  this flag also tells the manager to map
     421                 :   // this storage also in mLocalStorages hash table.
     422                 :   nsDOMStorageType mStorageType;
     423                 : 
     424                 :   friend class nsIDOMStorage2;
     425                 :   nsCOMPtr<nsIPrincipal> mPrincipal;
     426                 :   nsPIDOMStorage* mEventBroadcaster;
     427                 : };
     428                 : 
     429                 : class nsDOMStorage2 : public nsIDOMStorage,
     430                 :                       public nsPIDOMStorage
     431              20 : {
     432                 : public:
     433                 :   // nsISupports
     434               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     435            1988 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorage2, nsIDOMStorage)
     436                 : 
     437                 :   nsDOMStorage2(nsDOMStorage2& aThat);
     438                 :   nsDOMStorage2();
     439                 : 
     440                 :   NS_DECL_NSIDOMSTORAGE
     441                 : 
     442                 :   // nsPIDOMStorage
     443                 :   virtual nsresult InitAsSessionStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     444                 :   virtual nsresult InitAsLocalStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     445                 :   virtual nsresult InitAsGlobalStorage(const nsACString &aDomainDemanded);
     446                 :   virtual already_AddRefed<nsIDOMStorage> Clone();
     447                 :   virtual already_AddRefed<nsIDOMStorage> Fork(const nsSubstring &aDocumentURI);
     448                 :   virtual bool IsForkOf(nsIDOMStorage* aThat);
     449                 :   virtual nsTArray<nsString> *GetKeys();
     450                 :   virtual nsIPrincipal* Principal();
     451                 :   virtual bool CanAccess(nsIPrincipal *aPrincipal);
     452                 :   virtual nsDOMStorageType StorageType();
     453                 :   virtual void BroadcastChangeNotification(const nsSubstring &aKey,
     454                 :                                            const nsSubstring &aOldValue,
     455                 :                                            const nsSubstring &aNewValue);
     456                 : 
     457                 :   nsresult InitAsSessionStorageFork(nsIPrincipal *aPrincipal,
     458                 :                                     const nsSubstring &aDocumentURI,
     459                 :                                     nsIDOMStorageObsolete* aStorage);
     460                 : 
     461                 : private:
     462                 :   // storages bound to an origin hold the principal to
     463                 :   // make security checks against it
     464                 :   nsCOMPtr<nsIPrincipal> mPrincipal;
     465                 : 
     466                 :   // Needed for the storage event, this is address of the document this storage
     467                 :   // is bound to
     468                 :   nsString mDocumentURI;
     469                 :   nsRefPtr<nsDOMStorage> mStorage;
     470                 : };
     471                 : 
     472                 : class nsDOMStorageList : public nsIDOMStorageList
     473                 : {
     474                 : public:
     475               0 :   nsDOMStorageList()
     476               0 :   {
     477               0 :     mStorages.Init();
     478               0 :   }
     479                 : 
     480               0 :   virtual ~nsDOMStorageList() {}
     481                 : 
     482                 :   // nsISupports
     483                 :   NS_DECL_ISUPPORTS
     484                 : 
     485                 :   // nsIDOMStorageList
     486                 :   NS_DECL_NSIDOMSTORAGELIST
     487                 : 
     488                 :   nsIDOMStorageObsolete* GetNamedItem(const nsAString& aDomain, nsresult* aResult);
     489                 : 
     490                 :   /**
     491                 :    * Check whether aCurrentDomain has access to aRequestedDomain
     492                 :    */
     493                 :   static bool
     494                 :   CanAccessDomain(const nsACString& aRequestedDomain,
     495                 :                   const nsACString& aCurrentDomain);
     496                 : 
     497                 : protected:
     498                 : 
     499                 :   /**
     500                 :    * Return the global nsIDOMStorageObsolete for a particular domain.
     501                 :    * aNoCurrentDomainCheck may be true to skip the domain comparison;
     502                 :    * this is used for chrome code so that it may retrieve data from
     503                 :    * any domain.
     504                 :    *
     505                 :    * @param aRequestedDomain domain to return
     506                 :    * @param aCurrentDomain domain of current caller
     507                 :    * @param aNoCurrentDomainCheck true to skip domain comparison
     508                 :    */
     509                 :   nsIDOMStorageObsolete*
     510                 :   GetStorageForDomain(const nsACString& aRequestedDomain,
     511                 :                       const nsACString& aCurrentDomain,
     512                 :                       bool aNoCurrentDomainCheck,
     513                 :                       nsresult* aResult);
     514                 : 
     515                 :   /**
     516                 :    * Convert the domain into an array of its component parts.
     517                 :    */
     518                 :   static bool
     519                 :   ConvertDomainToArray(const nsACString& aDomain,
     520                 :                        nsTArray<nsCString>* aArray);
     521                 : 
     522                 :   nsInterfaceHashtable<nsCStringHashKey, nsIDOMStorageObsolete> mStorages;
     523                 : };
     524                 : 
     525                 : class nsDOMStorageItem : public nsIDOMStorageItem,
     526                 :                          public nsIDOMToString
     527                 : {
     528                 : public:
     529                 :   nsDOMStorageItem(DOMStorageBase* aStorage,
     530                 :                    const nsAString& aKey,
     531                 :                    const nsAString& aValue,
     532                 :                    bool aSecure);
     533                 :   virtual ~nsDOMStorageItem();
     534                 : 
     535                 :   // nsISupports
     536               2 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     537            1722 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorageItem, nsIDOMStorageItem)
     538                 : 
     539                 :   // nsIDOMStorageObsolete
     540                 :   NS_DECL_NSIDOMSTORAGEITEM
     541                 : 
     542                 :   // nsIDOMToString
     543                 :   NS_DECL_NSIDOMTOSTRING
     544                 : 
     545              92 :   bool IsSecure()
     546                 :   {
     547              92 :     return mSecure;
     548                 :   }
     549                 : 
     550               0 :   void SetSecureInternal(bool aSecure)
     551                 :   {
     552               0 :     mSecure = aSecure;
     553               0 :   }
     554                 : 
     555               0 :   const nsAString& GetValueInternal()
     556                 :   {
     557               0 :     return mValue;
     558                 :   }
     559                 : 
     560               9 :   const void SetValueInternal(const nsAString& aValue)
     561                 :   {
     562               9 :     mValue = aValue;
     563               9 :   }
     564                 : 
     565               0 :   void ClearValue()
     566                 :   {
     567               0 :     mValue.Truncate();
     568               0 :   }
     569                 : 
     570                 : protected:
     571                 : 
     572                 :   // true if this value is for secure sites only
     573                 :   bool mSecure;
     574                 : 
     575                 :   // key for the item
     576                 :   nsString mKey;
     577                 : 
     578                 :   // value of the item
     579                 :   nsString mValue;
     580                 : 
     581                 :   // If this item came from the db, mStorage points to the storage
     582                 :   // object where this item came from.
     583                 :   nsRefPtr<DOMStorageBase> mStorage;
     584                 : };
     585                 : 
     586                 : class nsDOMStorageEvent : public nsDOMEvent,
     587                 :                           public nsIDOMStorageEvent
     588                 : {
     589                 : public:
     590              30 :   nsDOMStorageEvent()
     591              30 :     : nsDOMEvent(nsnull, nsnull)
     592                 :   {
     593              30 :   }
     594                 : 
     595              60 :   virtual ~nsDOMStorageEvent()
     596              30 :   {
     597             120 :   }
     598                 : 
     599                 :   nsresult Init();
     600                 : 
     601                 :   NS_DECL_ISUPPORTS_INHERITED
     602            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMStorageEvent, nsDOMEvent)
     603                 : 
     604                 :   NS_DECL_NSIDOMSTORAGEEVENT
     605              30 :   NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
     606                 : 
     607                 :   virtual nsresult InitFromCtor(const nsAString& aType,
     608                 :                                 JSContext* aCx, jsval* aVal);
     609                 : protected:
     610                 :   nsString mKey;
     611                 :   nsString mOldValue;
     612                 :   nsString mNewValue;
     613                 :   nsString mUrl;
     614                 :   nsCOMPtr<nsIDOMStorage> mStorageArea;
     615                 : };
     616                 : 
     617                 : class nsDOMStorageEventObsolete : public nsDOMEvent,
     618                 :                           public nsIDOMStorageEventObsolete
     619                 : {
     620                 : public:
     621               0 :   nsDOMStorageEventObsolete()
     622               0 :     : nsDOMEvent(nsnull, nsnull)
     623                 :   {
     624               0 :   }
     625                 : 
     626               0 :   virtual ~nsDOMStorageEventObsolete()
     627               0 :   {
     628               0 :   }
     629                 : 
     630                 :   NS_DECL_ISUPPORTS
     631                 :   NS_DECL_NSIDOMSTORAGEEVENTOBSOLETE
     632               0 :   NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
     633                 : 
     634                 : protected:
     635                 :   nsString mDomain;
     636                 : };
     637                 : 
     638                 : nsresult
     639                 : NS_NewDOMStorage(nsISupports* aOuter, REFNSIID aIID, void** aResult);
     640                 : 
     641                 : nsresult
     642                 : NS_NewDOMStorage2(nsISupports* aOuter, REFNSIID aIID, void** aResult);
     643                 : 
     644                 : nsresult
     645                 : NS_NewDOMStorageList(nsIDOMStorageList** aResult);
     646                 : 
     647                 : PRUint32
     648                 : GetOfflinePermission(const nsACString &aDomain);
     649                 : 
     650                 : bool
     651                 : IsOfflineAllowed(const nsACString &aDomain);
     652                 : 
     653                 : #endif /* nsDOMStorage_h___ */

Generated by: LCOV version 1.7