dom/indexedDB/ipc/SerializationHelpers.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_dom_indexeddb_serializationhelpers_h__
     6 #define mozilla_dom_indexeddb_serializationhelpers_h__
     8 #include "ipc/IPCMessageUtils.h"
    10 #include "mozilla/dom/indexedDB/DatabaseInfo.h"
    11 #include "mozilla/dom/indexedDB/Key.h"
    12 #include "mozilla/dom/indexedDB/KeyPath.h"
    13 #include "mozilla/dom/indexedDB/IDBCursor.h"
    14 #include "mozilla/dom/indexedDB/IDBTransaction.h"
    16 namespace IPC {
    18 template <>
    19 struct ParamTraits<mozilla::dom::quota::PersistenceType> :
    20   public ContiguousEnumSerializer<
    21            mozilla::dom::quota::PersistenceType,
    22            mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT,
    23            mozilla::dom::quota::PERSISTENCE_TYPE_INVALID>
    24 { };
    26 template <>
    27 struct ParamTraits<mozilla::dom::indexedDB::Key>
    28 {
    29   typedef mozilla::dom::indexedDB::Key paramType;
    31   static void Write(Message* aMsg, const paramType& aParam)
    32   {
    33     WriteParam(aMsg, aParam.mBuffer);
    34   }
    36   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    37   {
    38     return ReadParam(aMsg, aIter, &aResult->mBuffer);
    39   }
    41   static void Log(const paramType& aParam, std::wstring* aLog)
    42   {
    43     LogParam(aParam.mBuffer, aLog);
    44   }
    45 };
    47 template <>
    48 struct ParamTraits<mozilla::dom::indexedDB::KeyPath::KeyPathType> :
    49   public ContiguousEnumSerializer<
    50            mozilla::dom::indexedDB::KeyPath::KeyPathType,
    51            mozilla::dom::indexedDB::KeyPath::NONEXISTENT,
    52            mozilla::dom::indexedDB::KeyPath::ENDGUARD>
    53 { };
    55 template <>
    56 struct ParamTraits<mozilla::dom::indexedDB::KeyPath>
    57 {
    58   typedef mozilla::dom::indexedDB::KeyPath paramType;
    60   static void Write(Message* aMsg, const paramType& aParam)
    61   {
    62     WriteParam(aMsg, aParam.mType);
    63     WriteParam(aMsg, aParam.mStrings);
    64   }
    66   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    67   {
    68     return ReadParam(aMsg, aIter, &aResult->mType) &&
    69            ReadParam(aMsg, aIter, &aResult->mStrings);
    70   }
    72   static void Log(const paramType& aParam, std::wstring* aLog)
    73   {
    74     LogParam(aParam.mStrings, aLog);
    75   }
    76 };
    78 template <>
    79 struct ParamTraits<mozilla::dom::indexedDB::IDBCursor::Direction> :
    80   public ContiguousEnumSerializer<
    81            mozilla::dom::indexedDB::IDBCursor::Direction,
    82            mozilla::dom::indexedDB::IDBCursor::NEXT,
    83            mozilla::dom::indexedDB::IDBCursor::DIRECTION_INVALID>
    84 { };
    86 template <>
    87 struct ParamTraits<mozilla::dom::indexedDB::IDBTransaction::Mode> :
    88   public ContiguousEnumSerializer<
    89            mozilla::dom::indexedDB::IDBTransaction::Mode,
    90            mozilla::dom::indexedDB::IDBTransaction::READ_ONLY,
    91            mozilla::dom::indexedDB::IDBTransaction::MODE_INVALID>
    92 { };
    94 template <>
    95 struct ParamTraits<mozilla::dom::indexedDB::IndexInfo>
    96 {
    97   typedef mozilla::dom::indexedDB::IndexInfo paramType;
    99   static void Write(Message* aMsg, const paramType& aParam)
   100   {
   101     WriteParam(aMsg, aParam.name);
   102     WriteParam(aMsg, aParam.id);
   103     WriteParam(aMsg, aParam.keyPath);
   104     WriteParam(aMsg, aParam.unique);
   105     WriteParam(aMsg, aParam.multiEntry);
   106   }
   108   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   109   {
   110     return ReadParam(aMsg, aIter, &aResult->name) &&
   111            ReadParam(aMsg, aIter, &aResult->id) &&
   112            ReadParam(aMsg, aIter, &aResult->keyPath) &&
   113            ReadParam(aMsg, aIter, &aResult->unique) &&
   114            ReadParam(aMsg, aIter, &aResult->multiEntry);
   115   }
   117   static void Log(const paramType& aParam, std::wstring* aLog)
   118   {
   119     LogParam(aParam.name, aLog);
   120     LogParam(aParam.id, aLog);
   121     LogParam(aParam.keyPath, aLog);
   122     LogParam(aParam.unique, aLog);
   123     LogParam(aParam.multiEntry, aLog);
   124   }
   125 };
   127 template <>
   128 struct ParamTraits<mozilla::dom::indexedDB::ObjectStoreInfoGuts>
   129 {
   130   typedef mozilla::dom::indexedDB::ObjectStoreInfoGuts paramType;
   132   static void Write(Message* aMsg, const paramType& aParam)
   133   {
   134     WriteParam(aMsg, aParam.name);
   135     WriteParam(aMsg, aParam.id);
   136     WriteParam(aMsg, aParam.keyPath);
   137     WriteParam(aMsg, aParam.autoIncrement);
   138     WriteParam(aMsg, aParam.indexes);
   139   }
   141   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   142   {
   143     return ReadParam(aMsg, aIter, &aResult->name) &&
   144            ReadParam(aMsg, aIter, &aResult->id) &&
   145            ReadParam(aMsg, aIter, &aResult->keyPath) &&
   146            ReadParam(aMsg, aIter, &aResult->autoIncrement) &&
   147            ReadParam(aMsg, aIter, &aResult->indexes);
   148   }
   150   static void Log(const paramType& aParam, std::wstring* aLog)
   151   {
   152     LogParam(aParam.name, aLog);
   153     LogParam(aParam.id, aLog);
   154     LogParam(aParam.keyPath, aLog);
   155     LogParam(aParam.autoIncrement, aLog);
   156     LogParam(aParam.indexes, aLog);
   157   }
   158 };
   160 template <>
   161 struct ParamTraits<mozilla::dom::indexedDB::DatabaseInfoGuts>
   162 {
   163   typedef mozilla::dom::indexedDB::DatabaseInfoGuts paramType;
   165   static void Write(Message* aMsg, const paramType& aParam)
   166   {
   167     WriteParam(aMsg, aParam.name);
   168     WriteParam(aMsg, aParam.group);
   169     WriteParam(aMsg, aParam.origin);
   170     WriteParam(aMsg, aParam.version);
   171     WriteParam(aMsg, aParam.persistenceType);
   172     WriteParam(aMsg, aParam.nextObjectStoreId);
   173     WriteParam(aMsg, aParam.nextIndexId);
   174   }
   176   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   177   {
   178     return ReadParam(aMsg, aIter, &aResult->name) &&
   179            ReadParam(aMsg, aIter, &aResult->group) &&
   180            ReadParam(aMsg, aIter, &aResult->origin) &&
   181            ReadParam(aMsg, aIter, &aResult->version) &&
   182            ReadParam(aMsg, aIter, &aResult->persistenceType) &&
   183            ReadParam(aMsg, aIter, &aResult->nextObjectStoreId) &&
   184            ReadParam(aMsg, aIter, &aResult->nextIndexId);
   185   }
   187   static void Log(const paramType& aParam, std::wstring* aLog)
   188   {
   189     LogParam(aParam.name, aLog);
   190     LogParam(aParam.group, aLog);
   191     LogParam(aParam.origin, aLog);
   192     LogParam(aParam.version, aLog);
   193     LogParam(aParam.nextObjectStoreId, aLog);
   194     LogParam(aParam.nextIndexId, aLog);
   195   }
   196 };
   198 template <>
   199 struct ParamTraits<mozilla::dom::indexedDB::IndexUpdateInfo>
   200 {
   201   typedef mozilla::dom::indexedDB::IndexUpdateInfo paramType;
   203   static void Write(Message* aMsg, const paramType& aParam)
   204   {
   205     WriteParam(aMsg, aParam.indexId);
   206     WriteParam(aMsg, aParam.indexUnique);
   207     WriteParam(aMsg, aParam.value);
   208   }
   210   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   211   {
   212     return ReadParam(aMsg, aIter, &aResult->indexId) &&
   213            ReadParam(aMsg, aIter, &aResult->indexUnique) &&
   214            ReadParam(aMsg, aIter, &aResult->value);
   215   }
   217   static void Log(const paramType& aParam, std::wstring* aLog)
   218   {
   219     LogParam(aParam.indexId, aLog);
   220     LogParam(aParam.indexUnique, aLog);
   221     LogParam(aParam.value, aLog);
   222   }
   223 };
   225 template <>
   226 struct ParamTraits<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo>
   227 {
   228   typedef mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo paramType;
   230   static void Write(Message* aMsg, const paramType& aParam)
   231   {
   232     WriteParam(aMsg, aParam.dataLength);
   233     if (aParam.dataLength) {
   234       aMsg->WriteBytes(aParam.data, aParam.dataLength);
   235     }
   236   }
   238   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   239   {
   240     if (!ReadParam(aMsg, aIter, &aResult->dataLength)) {
   241       return false;
   242     }
   244     if (aResult->dataLength) {
   245       const char** buffer =
   246         const_cast<const char**>(reinterpret_cast<char**>(&aResult->data));
   247       if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) {
   248         return false;
   249       }
   250     } else {
   251       aResult->data = nullptr;
   252     }
   254     return true;
   255   }
   257   static void Log(const paramType& aParam, std::wstring* aLog)
   258   {
   259     LogParam(aParam.dataLength, aLog);
   260   }
   261 };
   263 template <>
   264 struct ParamTraits<mozilla::dom::indexedDB::SerializedStructuredCloneWriteInfo>
   265 {
   266   typedef mozilla::dom::indexedDB::SerializedStructuredCloneWriteInfo paramType;
   268   static void Write(Message* aMsg, const paramType& aParam)
   269   {
   270     WriteParam(aMsg, aParam.dataLength);
   271     if (aParam.dataLength) {
   272       aMsg->WriteBytes(aParam.data, aParam.dataLength);
   273     }
   274     WriteParam(aMsg, aParam.offsetToKeyProp);
   275   }
   277   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   278   {
   279     if (!ReadParam(aMsg, aIter, &aResult->dataLength)) {
   280       return false;
   281     }
   283     if (aResult->dataLength) {
   284       const char** buffer =
   285         const_cast<const char**>(reinterpret_cast<char**>(&aResult->data));
   286       if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) {
   287         return false;
   288       }
   289     } else {
   290       aResult->data = nullptr;
   291     }
   293     if (!ReadParam(aMsg, aIter, &aResult->offsetToKeyProp)) {
   294       return false;
   295     }
   297     return true;
   298   }
   300   static void Log(const paramType& aParam, std::wstring* aLog)
   301   {
   302     LogParam(aParam.dataLength, aLog);
   303     LogParam(aParam.offsetToKeyProp, aLog);
   304   }
   305 };
   307 } // namespace IPC
   309 #endif // mozilla_dom_indexeddb_serializationhelpers_h__

mercurial