1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ipc/SerializationHelpers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,309 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_dom_indexeddb_serializationhelpers_h__ 1.9 +#define mozilla_dom_indexeddb_serializationhelpers_h__ 1.10 + 1.11 +#include "ipc/IPCMessageUtils.h" 1.12 + 1.13 +#include "mozilla/dom/indexedDB/DatabaseInfo.h" 1.14 +#include "mozilla/dom/indexedDB/Key.h" 1.15 +#include "mozilla/dom/indexedDB/KeyPath.h" 1.16 +#include "mozilla/dom/indexedDB/IDBCursor.h" 1.17 +#include "mozilla/dom/indexedDB/IDBTransaction.h" 1.18 + 1.19 +namespace IPC { 1.20 + 1.21 +template <> 1.22 +struct ParamTraits<mozilla::dom::quota::PersistenceType> : 1.23 + public ContiguousEnumSerializer< 1.24 + mozilla::dom::quota::PersistenceType, 1.25 + mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT, 1.26 + mozilla::dom::quota::PERSISTENCE_TYPE_INVALID> 1.27 +{ }; 1.28 + 1.29 +template <> 1.30 +struct ParamTraits<mozilla::dom::indexedDB::Key> 1.31 +{ 1.32 + typedef mozilla::dom::indexedDB::Key paramType; 1.33 + 1.34 + static void Write(Message* aMsg, const paramType& aParam) 1.35 + { 1.36 + WriteParam(aMsg, aParam.mBuffer); 1.37 + } 1.38 + 1.39 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.40 + { 1.41 + return ReadParam(aMsg, aIter, &aResult->mBuffer); 1.42 + } 1.43 + 1.44 + static void Log(const paramType& aParam, std::wstring* aLog) 1.45 + { 1.46 + LogParam(aParam.mBuffer, aLog); 1.47 + } 1.48 +}; 1.49 + 1.50 +template <> 1.51 +struct ParamTraits<mozilla::dom::indexedDB::KeyPath::KeyPathType> : 1.52 + public ContiguousEnumSerializer< 1.53 + mozilla::dom::indexedDB::KeyPath::KeyPathType, 1.54 + mozilla::dom::indexedDB::KeyPath::NONEXISTENT, 1.55 + mozilla::dom::indexedDB::KeyPath::ENDGUARD> 1.56 +{ }; 1.57 + 1.58 +template <> 1.59 +struct ParamTraits<mozilla::dom::indexedDB::KeyPath> 1.60 +{ 1.61 + typedef mozilla::dom::indexedDB::KeyPath paramType; 1.62 + 1.63 + static void Write(Message* aMsg, const paramType& aParam) 1.64 + { 1.65 + WriteParam(aMsg, aParam.mType); 1.66 + WriteParam(aMsg, aParam.mStrings); 1.67 + } 1.68 + 1.69 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.70 + { 1.71 + return ReadParam(aMsg, aIter, &aResult->mType) && 1.72 + ReadParam(aMsg, aIter, &aResult->mStrings); 1.73 + } 1.74 + 1.75 + static void Log(const paramType& aParam, std::wstring* aLog) 1.76 + { 1.77 + LogParam(aParam.mStrings, aLog); 1.78 + } 1.79 +}; 1.80 + 1.81 +template <> 1.82 +struct ParamTraits<mozilla::dom::indexedDB::IDBCursor::Direction> : 1.83 + public ContiguousEnumSerializer< 1.84 + mozilla::dom::indexedDB::IDBCursor::Direction, 1.85 + mozilla::dom::indexedDB::IDBCursor::NEXT, 1.86 + mozilla::dom::indexedDB::IDBCursor::DIRECTION_INVALID> 1.87 +{ }; 1.88 + 1.89 +template <> 1.90 +struct ParamTraits<mozilla::dom::indexedDB::IDBTransaction::Mode> : 1.91 + public ContiguousEnumSerializer< 1.92 + mozilla::dom::indexedDB::IDBTransaction::Mode, 1.93 + mozilla::dom::indexedDB::IDBTransaction::READ_ONLY, 1.94 + mozilla::dom::indexedDB::IDBTransaction::MODE_INVALID> 1.95 +{ }; 1.96 + 1.97 +template <> 1.98 +struct ParamTraits<mozilla::dom::indexedDB::IndexInfo> 1.99 +{ 1.100 + typedef mozilla::dom::indexedDB::IndexInfo paramType; 1.101 + 1.102 + static void Write(Message* aMsg, const paramType& aParam) 1.103 + { 1.104 + WriteParam(aMsg, aParam.name); 1.105 + WriteParam(aMsg, aParam.id); 1.106 + WriteParam(aMsg, aParam.keyPath); 1.107 + WriteParam(aMsg, aParam.unique); 1.108 + WriteParam(aMsg, aParam.multiEntry); 1.109 + } 1.110 + 1.111 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.112 + { 1.113 + return ReadParam(aMsg, aIter, &aResult->name) && 1.114 + ReadParam(aMsg, aIter, &aResult->id) && 1.115 + ReadParam(aMsg, aIter, &aResult->keyPath) && 1.116 + ReadParam(aMsg, aIter, &aResult->unique) && 1.117 + ReadParam(aMsg, aIter, &aResult->multiEntry); 1.118 + } 1.119 + 1.120 + static void Log(const paramType& aParam, std::wstring* aLog) 1.121 + { 1.122 + LogParam(aParam.name, aLog); 1.123 + LogParam(aParam.id, aLog); 1.124 + LogParam(aParam.keyPath, aLog); 1.125 + LogParam(aParam.unique, aLog); 1.126 + LogParam(aParam.multiEntry, aLog); 1.127 + } 1.128 +}; 1.129 + 1.130 +template <> 1.131 +struct ParamTraits<mozilla::dom::indexedDB::ObjectStoreInfoGuts> 1.132 +{ 1.133 + typedef mozilla::dom::indexedDB::ObjectStoreInfoGuts paramType; 1.134 + 1.135 + static void Write(Message* aMsg, const paramType& aParam) 1.136 + { 1.137 + WriteParam(aMsg, aParam.name); 1.138 + WriteParam(aMsg, aParam.id); 1.139 + WriteParam(aMsg, aParam.keyPath); 1.140 + WriteParam(aMsg, aParam.autoIncrement); 1.141 + WriteParam(aMsg, aParam.indexes); 1.142 + } 1.143 + 1.144 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.145 + { 1.146 + return ReadParam(aMsg, aIter, &aResult->name) && 1.147 + ReadParam(aMsg, aIter, &aResult->id) && 1.148 + ReadParam(aMsg, aIter, &aResult->keyPath) && 1.149 + ReadParam(aMsg, aIter, &aResult->autoIncrement) && 1.150 + ReadParam(aMsg, aIter, &aResult->indexes); 1.151 + } 1.152 + 1.153 + static void Log(const paramType& aParam, std::wstring* aLog) 1.154 + { 1.155 + LogParam(aParam.name, aLog); 1.156 + LogParam(aParam.id, aLog); 1.157 + LogParam(aParam.keyPath, aLog); 1.158 + LogParam(aParam.autoIncrement, aLog); 1.159 + LogParam(aParam.indexes, aLog); 1.160 + } 1.161 +}; 1.162 + 1.163 +template <> 1.164 +struct ParamTraits<mozilla::dom::indexedDB::DatabaseInfoGuts> 1.165 +{ 1.166 + typedef mozilla::dom::indexedDB::DatabaseInfoGuts paramType; 1.167 + 1.168 + static void Write(Message* aMsg, const paramType& aParam) 1.169 + { 1.170 + WriteParam(aMsg, aParam.name); 1.171 + WriteParam(aMsg, aParam.group); 1.172 + WriteParam(aMsg, aParam.origin); 1.173 + WriteParam(aMsg, aParam.version); 1.174 + WriteParam(aMsg, aParam.persistenceType); 1.175 + WriteParam(aMsg, aParam.nextObjectStoreId); 1.176 + WriteParam(aMsg, aParam.nextIndexId); 1.177 + } 1.178 + 1.179 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.180 + { 1.181 + return ReadParam(aMsg, aIter, &aResult->name) && 1.182 + ReadParam(aMsg, aIter, &aResult->group) && 1.183 + ReadParam(aMsg, aIter, &aResult->origin) && 1.184 + ReadParam(aMsg, aIter, &aResult->version) && 1.185 + ReadParam(aMsg, aIter, &aResult->persistenceType) && 1.186 + ReadParam(aMsg, aIter, &aResult->nextObjectStoreId) && 1.187 + ReadParam(aMsg, aIter, &aResult->nextIndexId); 1.188 + } 1.189 + 1.190 + static void Log(const paramType& aParam, std::wstring* aLog) 1.191 + { 1.192 + LogParam(aParam.name, aLog); 1.193 + LogParam(aParam.group, aLog); 1.194 + LogParam(aParam.origin, aLog); 1.195 + LogParam(aParam.version, aLog); 1.196 + LogParam(aParam.nextObjectStoreId, aLog); 1.197 + LogParam(aParam.nextIndexId, aLog); 1.198 + } 1.199 +}; 1.200 + 1.201 +template <> 1.202 +struct ParamTraits<mozilla::dom::indexedDB::IndexUpdateInfo> 1.203 +{ 1.204 + typedef mozilla::dom::indexedDB::IndexUpdateInfo paramType; 1.205 + 1.206 + static void Write(Message* aMsg, const paramType& aParam) 1.207 + { 1.208 + WriteParam(aMsg, aParam.indexId); 1.209 + WriteParam(aMsg, aParam.indexUnique); 1.210 + WriteParam(aMsg, aParam.value); 1.211 + } 1.212 + 1.213 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.214 + { 1.215 + return ReadParam(aMsg, aIter, &aResult->indexId) && 1.216 + ReadParam(aMsg, aIter, &aResult->indexUnique) && 1.217 + ReadParam(aMsg, aIter, &aResult->value); 1.218 + } 1.219 + 1.220 + static void Log(const paramType& aParam, std::wstring* aLog) 1.221 + { 1.222 + LogParam(aParam.indexId, aLog); 1.223 + LogParam(aParam.indexUnique, aLog); 1.224 + LogParam(aParam.value, aLog); 1.225 + } 1.226 +}; 1.227 + 1.228 +template <> 1.229 +struct ParamTraits<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> 1.230 +{ 1.231 + typedef mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo paramType; 1.232 + 1.233 + static void Write(Message* aMsg, const paramType& aParam) 1.234 + { 1.235 + WriteParam(aMsg, aParam.dataLength); 1.236 + if (aParam.dataLength) { 1.237 + aMsg->WriteBytes(aParam.data, aParam.dataLength); 1.238 + } 1.239 + } 1.240 + 1.241 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.242 + { 1.243 + if (!ReadParam(aMsg, aIter, &aResult->dataLength)) { 1.244 + return false; 1.245 + } 1.246 + 1.247 + if (aResult->dataLength) { 1.248 + const char** buffer = 1.249 + const_cast<const char**>(reinterpret_cast<char**>(&aResult->data)); 1.250 + if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) { 1.251 + return false; 1.252 + } 1.253 + } else { 1.254 + aResult->data = nullptr; 1.255 + } 1.256 + 1.257 + return true; 1.258 + } 1.259 + 1.260 + static void Log(const paramType& aParam, std::wstring* aLog) 1.261 + { 1.262 + LogParam(aParam.dataLength, aLog); 1.263 + } 1.264 +}; 1.265 + 1.266 +template <> 1.267 +struct ParamTraits<mozilla::dom::indexedDB::SerializedStructuredCloneWriteInfo> 1.268 +{ 1.269 + typedef mozilla::dom::indexedDB::SerializedStructuredCloneWriteInfo paramType; 1.270 + 1.271 + static void Write(Message* aMsg, const paramType& aParam) 1.272 + { 1.273 + WriteParam(aMsg, aParam.dataLength); 1.274 + if (aParam.dataLength) { 1.275 + aMsg->WriteBytes(aParam.data, aParam.dataLength); 1.276 + } 1.277 + WriteParam(aMsg, aParam.offsetToKeyProp); 1.278 + } 1.279 + 1.280 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.281 + { 1.282 + if (!ReadParam(aMsg, aIter, &aResult->dataLength)) { 1.283 + return false; 1.284 + } 1.285 + 1.286 + if (aResult->dataLength) { 1.287 + const char** buffer = 1.288 + const_cast<const char**>(reinterpret_cast<char**>(&aResult->data)); 1.289 + if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) { 1.290 + return false; 1.291 + } 1.292 + } else { 1.293 + aResult->data = nullptr; 1.294 + } 1.295 + 1.296 + if (!ReadParam(aMsg, aIter, &aResult->offsetToKeyProp)) { 1.297 + return false; 1.298 + } 1.299 + 1.300 + return true; 1.301 + } 1.302 + 1.303 + static void Log(const paramType& aParam, std::wstring* aLog) 1.304 + { 1.305 + LogParam(aParam.dataLength, aLog); 1.306 + LogParam(aParam.offsetToKeyProp, aLog); 1.307 + } 1.308 +}; 1.309 + 1.310 +} // namespace IPC 1.311 + 1.312 +#endif // mozilla_dom_indexeddb_serializationhelpers_h__