LCOV - code coverage report
Current view: directory - dom/src/storage - StorageParent.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 58 0 0.0 %
Date: 2012-06-02 Functions: 12 0 0.0 %

       1                 : /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
       2                 : /* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla DOM Storage.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  *   The Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Josh Matthews <josh@joshmatthews.net> (original author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "StorageParent.h"
      41                 : #include "mozilla/dom/PContentParent.h"
      42                 : #include "mozilla/unused.h"
      43                 : #include "nsDOMString.h"
      44                 : 
      45                 : using mozilla::unused;
      46                 : 
      47                 : namespace mozilla {
      48                 : namespace dom {
      49                 : 
      50               0 : StorageParent::StorageParent(const StorageConstructData& aData)
      51                 : {
      52               0 :   if (aData.type() == StorageConstructData::Tnull_t) {
      53               0 :     mStorage = new DOMStorageImpl(nsnull);
      54                 :   } else {
      55               0 :     const StorageClone& clone = aData.get_StorageClone();
      56               0 :     StorageParent* other = static_cast<StorageParent*>(clone.actorParent());
      57               0 :     mStorage = new DOMStorageImpl(nsnull, *other->mStorage.get());
      58               0 :     mStorage->CloneFrom(clone.callerSecure(), other->mStorage);
      59                 :   }
      60               0 : }
      61                 : 
      62                 : bool
      63               0 : StorageParent::RecvInit(const bool& aUseDB,
      64                 :                         const bool& aCanUseChromePersist,
      65                 :                         const bool& aSessionOnly,
      66                 :                         const nsCString& aDomain,
      67                 :                         const nsCString& aScopeDBKey,
      68                 :                         const nsCString& aQuotaDomainDBKey,
      69                 :                         const nsCString& aQuotaETLDplus1DomainDBKey,
      70                 :                         const PRUint32& aStorageType)
      71                 : {
      72                 :   mStorage->InitFromChild(aUseDB, aCanUseChromePersist, aSessionOnly, aDomain,
      73                 :                           aScopeDBKey, aQuotaDomainDBKey, aQuotaETLDplus1DomainDBKey,
      74               0 :                           aStorageType);
      75               0 :   return true;
      76                 : }
      77                 : 
      78                 : bool
      79               0 : StorageParent::RecvGetKeys(const bool& aCallerSecure, InfallibleTArray<nsString>* aKeys)
      80                 : {
      81                 :   // Callers are responsible for deallocating the array returned by mStorage->GetKeys
      82               0 :   nsAutoPtr<nsTArray<nsString> > keys(mStorage->GetKeys(aCallerSecure));
      83               0 :   aKeys->SwapElements(*keys);
      84               0 :   return true;
      85                 : }
      86                 : 
      87                 : bool
      88               0 : StorageParent::RecvGetLength(const bool& aCallerSecure, const bool& aSessionOnly,
      89                 :                              PRUint32* aLength, nsresult* rv)
      90                 : {
      91               0 :   mStorage->SetSessionOnly(aSessionOnly);
      92               0 :   *rv = mStorage->GetLength(aCallerSecure, aLength);
      93               0 :   return true;
      94                 : }
      95                 : 
      96                 : bool
      97               0 : StorageParent::RecvGetKey(const bool& aCallerSecure, const bool& aSessionOnly,
      98                 :                           const PRUint32& aIndex, nsString* aKey, nsresult* rv)
      99                 : {
     100               0 :   mStorage->SetSessionOnly(aSessionOnly);
     101               0 :   *rv = mStorage->GetKey(aCallerSecure, aIndex, *aKey);
     102               0 :   return true;
     103                 : }
     104                 : 
     105                 : bool
     106               0 : StorageParent::RecvGetValue(const bool& aCallerSecure, const bool& aSessionOnly,
     107                 :                             const nsString& aKey, StorageItem* aItem,
     108                 :                             nsresult* rv)
     109                 : {
     110               0 :   mStorage->SetSessionOnly(aSessionOnly);
     111                 : 
     112                 :   // We need to ensure that a proper null representation is sent to the child
     113                 :   // if no item is found or an error occurs.
     114                 : 
     115               0 :   *rv = NS_OK;
     116               0 :   nsCOMPtr<nsIDOMStorageItem> item = mStorage->GetValue(aCallerSecure, aKey, rv);
     117               0 :   if (NS_FAILED(*rv) || !item) {
     118               0 :     *aItem = null_t();
     119               0 :     return true;
     120                 :   }
     121                 : 
     122               0 :   ItemData data(EmptyString(), false);
     123               0 :   nsDOMStorageItem* internalItem = static_cast<nsDOMStorageItem*>(item.get());
     124               0 :   data.value() = internalItem->GetValueInternal();
     125               0 :   if (aCallerSecure)
     126               0 :     data.secure() = internalItem->IsSecure();
     127               0 :   *aItem = data;
     128               0 :   return true;
     129                 : }
     130                 : 
     131                 : bool
     132               0 : StorageParent::RecvSetValue(const bool& aCallerSecure, const bool& aSessionOnly,
     133                 :                             const nsString& aKey, const nsString& aData,
     134                 :                             nsString* aOldValue, nsresult* rv)
     135                 : {
     136               0 :   mStorage->SetSessionOnly(aSessionOnly);
     137               0 :   *rv = mStorage->SetValue(aCallerSecure, aKey, aData, *aOldValue);
     138               0 :   return true;
     139                 : }
     140                 : 
     141                 : bool
     142               0 : StorageParent::RecvRemoveValue(const bool& aCallerSecure, const bool& aSessionOnly,
     143                 :                                const nsString& aKey, nsString* aOldValue,
     144                 :                                nsresult* rv)
     145                 : {
     146               0 :   mStorage->SetSessionOnly(aSessionOnly);
     147               0 :   *rv = mStorage->RemoveValue(aCallerSecure, aKey, *aOldValue);
     148               0 :   return true;
     149                 : }
     150                 : 
     151                 : bool
     152               0 : StorageParent::RecvClear(const bool& aCallerSecure, const bool& aSessionOnly,
     153                 :                          PRInt32* aOldCount, nsresult* rv)
     154                 : {
     155               0 :   mStorage->SetSessionOnly(aSessionOnly);
     156               0 :   *rv = mStorage->Clear(aCallerSecure, aOldCount);
     157               0 :   return true;
     158                 : }
     159                 : 
     160                 : bool
     161               0 : StorageParent::RecvGetDBValue(const nsString& aKey, nsString* aValue,
     162                 :                               bool* aSecure, nsresult* rv)
     163                 : {
     164               0 :   *rv = mStorage->GetDBValue(aKey, *aValue, aSecure);
     165               0 :   return true;
     166                 : }
     167                 : 
     168                 : bool
     169               0 : StorageParent::RecvSetDBValue(const nsString& aKey, const nsString& aValue,
     170                 :                               const bool& aSecure, nsresult* rv)
     171                 : {
     172               0 :   *rv = mStorage->SetDBValue(aKey, aValue, aSecure);
     173               0 :   return true;
     174                 : }
     175                 : 
     176                 : bool
     177               0 : StorageParent::RecvSetSecure(const nsString& aKey, const bool& aSecure,
     178                 :                              nsresult* rv)
     179                 : {
     180               0 :   *rv = mStorage->SetSecure(aKey, aSecure);
     181               0 :   return true;
     182                 : }
     183                 : 
     184                 : }
     185                 : }

Generated by: LCOV version 1.7