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-06-02 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                 : 
     156                 :   virtual nsTArray<nsString>* GetKeys(bool aCallerSecure) = 0;
     157                 :   virtual nsresult GetLength(bool aCallerSecure, PRUint32* aLength) = 0;
     158                 :   virtual nsresult GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey) = 0;
     159                 :   virtual nsIDOMStorageItem* GetValue(bool aCallerSecure, const nsAString& aKey,
     160                 :                                       nsresult* rv) = 0;
     161                 :   virtual nsresult SetValue(bool aCallerSecure, const nsAString& aKey,
     162                 :                             const nsAString& aData, nsAString& aOldValue) = 0;
     163                 :   virtual nsresult RemoveValue(bool aCallerSecure, const nsAString& aKey,
     164                 :                                nsAString& aOldValue) = 0;
     165                 :   virtual nsresult Clear(bool aCallerSecure, PRInt32* aOldCount) = 0;
     166                 :   
     167                 :   // If true, the contents of the storage should be stored in the
     168                 :   // database, otherwise this storage should act like a session
     169                 :   // storage.
     170                 :   // This call relies on mSessionOnly, and should only be used
     171                 :   // after a CacheStoragePermissions() call.  See the comments
     172                 :   // for mSessionOnly below.
     173             216 :   bool UseDB() {
     174             216 :     return mUseDB;
     175                 :   }
     176                 : 
     177                 :   // retrieve the value and secure state corresponding to a key out of storage.
     178                 :   virtual nsresult
     179                 :   GetDBValue(const nsAString& aKey,
     180                 :              nsAString& aValue,
     181                 :              bool* aSecure) = 0;
     182                 : 
     183                 :   // set the value corresponding to a key in the storage. If
     184                 :   // aSecure is false, then attempts to modify a secure value
     185                 :   // throw NS_ERROR_DOM_INVALID_ACCESS_ERR
     186                 :   virtual nsresult
     187                 :   SetDBValue(const nsAString& aKey,
     188                 :              const nsAString& aValue,
     189                 :              bool aSecure) = 0;
     190                 : 
     191                 :   // set the value corresponding to a key as secure.
     192                 :   virtual nsresult
     193                 :   SetSecure(const nsAString& aKey, bool aSecure) = 0;
     194                 : 
     195                 :   virtual nsresult
     196                 :   CloneFrom(bool aCallerSecure, DOMStorageBase* aThat) = 0;
     197                 : 
     198                 :   // e.g. "moc.rab.oof.:" or "moc.rab.oof.:http:80" depending
     199                 :   // on association with a domain (globalStorage) or
     200                 :   // an origin (localStorage).
     201             428 :   nsCString& GetScopeDBKey() {return mScopeDBKey;}
     202                 : 
     203                 :   // e.g. "moc.rab.%" - reversed eTLD+1 subpart of the domain or
     204                 :   // reversed offline application allowed domain.
     205              48 :   nsCString& GetQuotaDomainDBKey(bool aOfflineAllowed)
     206                 :   {
     207              48 :     return aOfflineAllowed ? mQuotaDomainDBKey : mQuotaETLDplus1DomainDBKey;
     208                 :   }
     209                 : 
     210                 :   virtual bool CacheStoragePermissions() = 0;
     211                 : 
     212                 : protected:
     213                 :   friend class nsDOMStorageManager;
     214                 :   friend class nsDOMStorage;
     215                 : 
     216                 :   nsPIDOMStorage::nsDOMStorageType mStorageType;
     217                 :   
     218                 :   // true if the storage database should be used for values
     219                 :   bool mUseDB;
     220                 : 
     221                 :   // true if the preferences indicates that this storage should be
     222                 :   // session only. This member is updated by
     223                 :   // CacheStoragePermissions(), using the current principal.
     224                 :   // CacheStoragePermissions() must be called at each entry point to
     225                 :   // make sure this stays up to date.
     226                 :   bool mSessionOnly;
     227                 : 
     228                 :   // domain this store is associated with
     229                 :   nsCString mDomain;
     230                 : 
     231                 :   // keys are used for database queries.
     232                 :   // see comments of the getters bellow.
     233                 :   nsCString mScopeDBKey;
     234                 :   nsCString mQuotaETLDplus1DomainDBKey;
     235                 :   nsCString mQuotaDomainDBKey;
     236                 : 
     237                 :   bool mCanUseChromePersist;
     238                 : };
     239                 : 
     240                 : class DOMStorageImpl : public DOMStorageBase
     241                 : 
     242                 : {
     243                 : public:
     244            1608 :   NS_DECL_CYCLE_COLLECTION_CLASS(DOMStorageImpl)
     245               4 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     246                 : 
     247                 :   DOMStorageImpl(nsDOMStorage*);
     248                 :   DOMStorageImpl(nsDOMStorage*, DOMStorageImpl&);
     249                 :   ~DOMStorageImpl();
     250                 : 
     251                 :   virtual void InitAsSessionStorage(nsIURI* aDomainURI);
     252                 :   virtual void InitAsLocalStorage(nsIURI* aDomainURI, bool aCanUseChromePersist);
     253                 : 
     254              92 :   bool SessionOnly() {
     255              92 :     return mSessionOnly;
     256                 :   }
     257                 : 
     258                 :   virtual nsTArray<nsString>* GetKeys(bool aCallerSecure);
     259                 :   virtual nsresult GetLength(bool aCallerSecure, PRUint32* aLength);
     260                 :   virtual nsresult GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey);
     261                 :   virtual nsIDOMStorageItem* GetValue(bool aCallerSecure, const nsAString& aKey,
     262                 :                                       nsresult* rv);
     263                 :   virtual nsresult SetValue(bool aCallerSecure, const nsAString& aKey,
     264                 :                             const nsAString& aData, nsAString& aOldValue);
     265                 :   virtual nsresult RemoveValue(bool aCallerSecure, const nsAString& aKey,
     266                 :                                nsAString& aOldValue);
     267                 :   virtual nsresult Clear(bool aCallerSecure, PRInt32* aOldCount);
     268                 : 
     269                 :   // cache the keys from the database for faster lookup
     270                 :   nsresult CacheKeysFromDB();
     271                 : 
     272             156 :   PRUint64 CachedVersion() { return mItemsCachedVersion; }
     273              98 :   void SetCachedVersion(PRUint64 version) { mItemsCachedVersion = version; }
     274                 :   
     275                 :   // Some privileged internal pages can use a persistent storage even in
     276                 :   // session-only or private-browsing modes.
     277                 :   bool CanUseChromePersist();
     278                 : 
     279                 :   // retrieve the value and secure state corresponding to a key out of storage
     280                 :   // that has been cached in mItems hash table.
     281                 :   nsresult
     282                 :   GetCachedValue(const nsAString& aKey,
     283                 :                  nsAString& aValue,
     284                 :                  bool* aSecure);
     285                 : 
     286                 :   // retrieve the value and secure state corresponding to a key out of storage.
     287                 :   virtual nsresult
     288                 :   GetDBValue(const nsAString& aKey,
     289                 :              nsAString& aValue,
     290                 :              bool* aSecure);
     291                 : 
     292                 :   // set the value corresponding to a key in the storage. If
     293                 :   // aSecure is false, then attempts to modify a secure value
     294                 :   // throw NS_ERROR_DOM_INVALID_ACCESS_ERR
     295                 :   virtual nsresult
     296                 :   SetDBValue(const nsAString& aKey,
     297                 :              const nsAString& aValue,
     298                 :              bool aSecure);
     299                 : 
     300                 :   // set the value corresponding to a key as secure.
     301                 :   virtual nsresult
     302                 :   SetSecure(const nsAString& aKey, bool aSecure);
     303                 : 
     304                 :   // clear all values from the store
     305                 :   void ClearAll();
     306                 : 
     307                 :   virtual nsresult
     308                 :   CloneFrom(bool aCallerSecure, DOMStorageBase* aThat);
     309                 : 
     310                 :   virtual bool CacheStoragePermissions();
     311                 : 
     312                 : private:
     313                 :   static nsDOMStorageDBWrapper* gStorageDB;
     314                 :   friend class nsDOMStorageManager;
     315                 :   friend class nsDOMStoragePersistentDB;
     316                 :   friend class StorageParent;
     317                 : 
     318                 :   void Init(nsDOMStorage*);
     319                 : 
     320                 :   // Cross-process storage implementations never have InitAs(Session|Local|Global)Storage
     321                 :   // called, so the appropriate initialization needs to happen from the child.
     322                 :   void InitFromChild(bool aUseDB, bool aCanUseChromePersist, bool aSessionOnly,
     323                 :                      const nsACString& aDomain,
     324                 :                      const nsACString& aScopeDBKey,
     325                 :                      const nsACString& aQuotaDomainDBKey,
     326                 :                      const nsACString& aQuotaETLDplus1DomainDBKey,
     327                 :                      PRUint32 aStorageType);
     328                 :   void SetSessionOnly(bool aSessionOnly);
     329                 : 
     330                 :   static nsresult InitDB();
     331                 : 
     332                 :   // 0 initially or a positive data version number assigned by gStorageDB
     333                 :   // after keys have been cached from the database
     334                 :   PRUint64 mItemsCachedVersion;
     335                 : 
     336                 :   // the key->value item pairs
     337                 :   nsTHashtable<nsSessionStorageEntry> mItems;
     338                 : 
     339                 :   // Weak reference to the owning storage instance
     340                 :   nsDOMStorage* mOwner;
     341                 : };
     342                 : 
     343                 : class nsDOMStorage : public nsIDOMStorageObsolete,
     344                 :                      public nsPIDOMStorage
     345                 : {
     346                 : public:
     347                 :   nsDOMStorage();
     348                 :   nsDOMStorage(nsDOMStorage& aThat);
     349                 :   virtual ~nsDOMStorage();
     350                 : 
     351               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     352            1504 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorage, nsIDOMStorageObsolete)
     353                 : 
     354                 :   NS_DECL_NSIDOMSTORAGEOBSOLETE
     355                 : 
     356                 :   // Helpers for implementing nsIDOMStorage
     357                 :   nsresult GetItem(const nsAString& key, nsAString& aData);
     358                 :   nsresult Clear();
     359                 : 
     360                 :   // nsPIDOMStorage
     361                 :   virtual nsresult InitAsSessionStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     362                 :   virtual nsresult InitAsLocalStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     363                 :   virtual already_AddRefed<nsIDOMStorage> Clone();
     364                 :   virtual already_AddRefed<nsIDOMStorage> Fork(const nsSubstring &aDocumentURI);
     365                 :   virtual bool IsForkOf(nsIDOMStorage* aThat);
     366                 :   virtual nsTArray<nsString> *GetKeys();
     367                 :   virtual nsIPrincipal* Principal();
     368                 :   virtual bool CanAccess(nsIPrincipal *aPrincipal);
     369                 :   virtual nsDOMStorageType StorageType();
     370                 :   virtual void BroadcastChangeNotification(const nsSubstring &aKey,
     371                 :                                            const nsSubstring &aOldValue,
     372                 :                                            const nsSubstring &aNewValue);
     373                 : 
     374                 :   // Check whether storage may be used by the caller, and whether it
     375                 :   // is session only.  Returns true if storage may be used.
     376                 :   static bool
     377                 :   CanUseStorage(bool* aSessionOnly);
     378                 : 
     379                 :   // Check whether this URI can use chrome persist storage.  This kind of
     380                 :   // storage can bypass cookies limits, private browsing and uses the offline
     381                 :   // apps quota.
     382                 :   static bool
     383                 :   URICanUseChromePersist(nsIURI* aURI);
     384                 :   
     385                 :   // Check whether storage may be used.  Updates mSessionOnly based on
     386                 :   // the result of CanUseStorage.
     387                 :   bool
     388                 :   CacheStoragePermissions();
     389                 : 
     390                 :   nsIDOMStorageItem* GetNamedItem(const nsAString& aKey, nsresult* aResult);
     391                 : 
     392               0 :   static nsDOMStorage* FromSupports(nsISupports* aSupports)
     393                 :   {
     394               0 :     return static_cast<nsDOMStorage*>(static_cast<nsIDOMStorageObsolete*>(aSupports));
     395                 :   }
     396                 : 
     397                 :   nsresult SetSecure(const nsAString& aKey, bool aSecure)
     398                 :   {
     399                 :     return mStorageImpl->SetSecure(aKey, aSecure);
     400                 :   }
     401                 : 
     402                 :   nsresult CloneFrom(nsDOMStorage* aThat);
     403                 : 
     404                 :  protected:
     405                 :   friend class nsDOMStorage2;
     406                 :   friend class nsDOMStoragePersistentDB;
     407                 : 
     408                 :   nsRefPtr<DOMStorageBase> mStorageImpl;
     409                 : 
     410                 :   bool CanAccessSystem(nsIPrincipal *aPrincipal);
     411                 : 
     412                 :   // document URI of the document this storage is bound to
     413                 :   nsString mDocumentURI;
     414                 : 
     415                 :   // true if this storage was initialized as a localStorage object.  localStorage
     416                 :   // objects are scoped to scheme/host/port in the database, while globalStorage
     417                 :   // objects are scoped just to host.  this flag also tells the manager to map
     418                 :   // this storage also in mLocalStorages hash table.
     419                 :   nsDOMStorageType mStorageType;
     420                 : 
     421                 :   friend class nsIDOMStorage2;
     422                 :   nsCOMPtr<nsIPrincipal> mPrincipal;
     423                 :   nsPIDOMStorage* mEventBroadcaster;
     424                 : };
     425                 : 
     426                 : class nsDOMStorage2 : public nsIDOMStorage,
     427                 :                       public nsPIDOMStorage
     428              20 : {
     429                 : public:
     430                 :   // nsISupports
     431               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     432            1988 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorage2, nsIDOMStorage)
     433                 : 
     434                 :   nsDOMStorage2(nsDOMStorage2& aThat);
     435                 :   nsDOMStorage2();
     436                 : 
     437                 :   NS_DECL_NSIDOMSTORAGE
     438                 : 
     439                 :   // nsPIDOMStorage
     440                 :   virtual nsresult InitAsSessionStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     441                 :   virtual nsresult InitAsLocalStorage(nsIPrincipal *aPrincipal, const nsSubstring &aDocumentURI);
     442                 :   virtual already_AddRefed<nsIDOMStorage> Clone();
     443                 :   virtual already_AddRefed<nsIDOMStorage> Fork(const nsSubstring &aDocumentURI);
     444                 :   virtual bool IsForkOf(nsIDOMStorage* aThat);
     445                 :   virtual nsTArray<nsString> *GetKeys();
     446                 :   virtual nsIPrincipal* Principal();
     447                 :   virtual bool CanAccess(nsIPrincipal *aPrincipal);
     448                 :   virtual nsDOMStorageType StorageType();
     449                 :   virtual void BroadcastChangeNotification(const nsSubstring &aKey,
     450                 :                                            const nsSubstring &aOldValue,
     451                 :                                            const nsSubstring &aNewValue);
     452                 : 
     453                 :   nsresult InitAsSessionStorageFork(nsIPrincipal *aPrincipal,
     454                 :                                     const nsSubstring &aDocumentURI,
     455                 :                                     nsIDOMStorageObsolete* aStorage);
     456                 : 
     457                 : private:
     458                 :   // storages bound to an origin hold the principal to
     459                 :   // make security checks against it
     460                 :   nsCOMPtr<nsIPrincipal> mPrincipal;
     461                 : 
     462                 :   // Needed for the storage event, this is address of the document this storage
     463                 :   // is bound to
     464                 :   nsString mDocumentURI;
     465                 :   nsRefPtr<nsDOMStorage> mStorage;
     466                 : };
     467                 : 
     468                 : class nsDOMStorageList : public nsIDOMStorageList
     469                 : {
     470                 : public:
     471               0 :   nsDOMStorageList()
     472               0 :   {
     473               0 :     mStorages.Init();
     474               0 :   }
     475                 : 
     476               0 :   virtual ~nsDOMStorageList() {}
     477                 : 
     478                 :   // nsISupports
     479                 :   NS_DECL_ISUPPORTS
     480                 : 
     481                 :   // nsIDOMStorageList
     482                 :   NS_DECL_NSIDOMSTORAGELIST
     483                 : 
     484                 :   nsIDOMStorageObsolete* GetNamedItem(const nsAString& aDomain, nsresult* aResult);
     485                 : 
     486                 :   /**
     487                 :    * Check whether aCurrentDomain has access to aRequestedDomain
     488                 :    */
     489                 :   static bool
     490                 :   CanAccessDomain(const nsACString& aRequestedDomain,
     491                 :                   const nsACString& aCurrentDomain);
     492                 : 
     493                 : protected:
     494                 : 
     495                 :   /**
     496                 :    * Return the global nsIDOMStorageObsolete for a particular domain.
     497                 :    * aNoCurrentDomainCheck may be true to skip the domain comparison;
     498                 :    * this is used for chrome code so that it may retrieve data from
     499                 :    * any domain.
     500                 :    *
     501                 :    * @param aRequestedDomain domain to return
     502                 :    * @param aCurrentDomain domain of current caller
     503                 :    * @param aNoCurrentDomainCheck true to skip domain comparison
     504                 :    */
     505                 :   nsIDOMStorageObsolete*
     506                 :   GetStorageForDomain(const nsACString& aRequestedDomain,
     507                 :                       const nsACString& aCurrentDomain,
     508                 :                       bool aNoCurrentDomainCheck,
     509                 :                       nsresult* aResult);
     510                 : 
     511                 :   /**
     512                 :    * Convert the domain into an array of its component parts.
     513                 :    */
     514                 :   static bool
     515                 :   ConvertDomainToArray(const nsACString& aDomain,
     516                 :                        nsTArray<nsCString>* aArray);
     517                 : 
     518                 :   nsInterfaceHashtable<nsCStringHashKey, nsIDOMStorageObsolete> mStorages;
     519                 : };
     520                 : 
     521                 : class nsDOMStorageItem : public nsIDOMStorageItem,
     522                 :                          public nsIDOMToString
     523                 : {
     524                 : public:
     525                 :   nsDOMStorageItem(DOMStorageBase* aStorage,
     526                 :                    const nsAString& aKey,
     527                 :                    const nsAString& aValue,
     528                 :                    bool aSecure);
     529                 :   virtual ~nsDOMStorageItem();
     530                 : 
     531                 :   // nsISupports
     532               2 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     533            1722 :   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMStorageItem, nsIDOMStorageItem)
     534                 : 
     535                 :   // nsIDOMStorageObsolete
     536                 :   NS_DECL_NSIDOMSTORAGEITEM
     537                 : 
     538                 :   // nsIDOMToString
     539                 :   NS_DECL_NSIDOMTOSTRING
     540                 : 
     541              92 :   bool IsSecure()
     542                 :   {
     543              92 :     return mSecure;
     544                 :   }
     545                 : 
     546               0 :   void SetSecureInternal(bool aSecure)
     547                 :   {
     548               0 :     mSecure = aSecure;
     549               0 :   }
     550                 : 
     551               0 :   const nsAString& GetValueInternal()
     552                 :   {
     553               0 :     return mValue;
     554                 :   }
     555                 : 
     556               9 :   const void SetValueInternal(const nsAString& aValue)
     557                 :   {
     558               9 :     mValue = aValue;
     559               9 :   }
     560                 : 
     561               0 :   void ClearValue()
     562                 :   {
     563               0 :     mValue.Truncate();
     564               0 :   }
     565                 : 
     566                 : protected:
     567                 : 
     568                 :   // true if this value is for secure sites only
     569                 :   bool mSecure;
     570                 : 
     571                 :   // key for the item
     572                 :   nsString mKey;
     573                 : 
     574                 :   // value of the item
     575                 :   nsString mValue;
     576                 : 
     577                 :   // If this item came from the db, mStorage points to the storage
     578                 :   // object where this item came from.
     579                 :   nsRefPtr<DOMStorageBase> mStorage;
     580                 : };
     581                 : 
     582                 : class nsDOMStorageEvent : public nsDOMEvent,
     583                 :                           public nsIDOMStorageEvent
     584                 : {
     585                 : public:
     586              30 :   nsDOMStorageEvent()
     587              30 :     : nsDOMEvent(nsnull, nsnull)
     588                 :   {
     589              30 :   }
     590                 : 
     591              60 :   virtual ~nsDOMStorageEvent()
     592              30 :   {
     593             120 :   }
     594                 : 
     595                 :   nsresult Init();
     596                 : 
     597                 :   NS_DECL_ISUPPORTS_INHERITED
     598            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMStorageEvent, nsDOMEvent)
     599                 : 
     600                 :   NS_DECL_NSIDOMSTORAGEEVENT
     601              30 :   NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
     602                 : 
     603                 :   virtual nsresult InitFromCtor(const nsAString& aType,
     604                 :                                 JSContext* aCx, jsval* aVal);
     605                 : protected:
     606                 :   nsString mKey;
     607                 :   nsString mOldValue;
     608                 :   nsString mNewValue;
     609                 :   nsString mUrl;
     610                 :   nsCOMPtr<nsIDOMStorage> mStorageArea;
     611                 : };
     612                 : 
     613                 : class nsDOMStorageEventObsolete : public nsDOMEvent,
     614                 :                           public nsIDOMStorageEventObsolete
     615                 : {
     616                 : public:
     617               0 :   nsDOMStorageEventObsolete()
     618               0 :     : nsDOMEvent(nsnull, nsnull)
     619                 :   {
     620               0 :   }
     621                 : 
     622               0 :   virtual ~nsDOMStorageEventObsolete()
     623               0 :   {
     624               0 :   }
     625                 : 
     626                 :   NS_DECL_ISUPPORTS
     627                 :   NS_DECL_NSIDOMSTORAGEEVENTOBSOLETE
     628               0 :   NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
     629                 : 
     630                 : protected:
     631                 :   nsString mDomain;
     632                 : };
     633                 : 
     634                 : nsresult
     635                 : NS_NewDOMStorage(nsISupports* aOuter, REFNSIID aIID, void** aResult);
     636                 : 
     637                 : nsresult
     638                 : NS_NewDOMStorage2(nsISupports* aOuter, REFNSIID aIID, void** aResult);
     639                 : 
     640                 : nsresult
     641                 : NS_NewDOMStorageList(nsIDOMStorageList** aResult);
     642                 : 
     643                 : PRUint32
     644                 : GetOfflinePermission(const nsACString &aDomain);
     645                 : 
     646                 : bool
     647                 : IsOfflineAllowed(const nsACString &aDomain);
     648                 : 
     649                 : #endif /* nsDOMStorage_h___ */

Generated by: LCOV version 1.7