michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_serializationhelpers_h__ michael@0: #define mozilla_dom_indexeddb_serializationhelpers_h__ michael@0: michael@0: #include "ipc/IPCMessageUtils.h" michael@0: michael@0: #include "mozilla/dom/indexedDB/DatabaseInfo.h" michael@0: #include "mozilla/dom/indexedDB/Key.h" michael@0: #include "mozilla/dom/indexedDB/KeyPath.h" michael@0: #include "mozilla/dom/indexedDB/IDBCursor.h" michael@0: #include "mozilla/dom/indexedDB/IDBTransaction.h" michael@0: michael@0: namespace IPC { michael@0: michael@0: template <> michael@0: struct ParamTraits : michael@0: public ContiguousEnumSerializer< michael@0: mozilla::dom::quota::PersistenceType, michael@0: mozilla::dom::quota::PERSISTENCE_TYPE_PERSISTENT, michael@0: mozilla::dom::quota::PERSISTENCE_TYPE_INVALID> michael@0: { }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::Key paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mBuffer); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->mBuffer); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.mBuffer, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits : michael@0: public ContiguousEnumSerializer< michael@0: mozilla::dom::indexedDB::KeyPath::KeyPathType, michael@0: mozilla::dom::indexedDB::KeyPath::NONEXISTENT, michael@0: mozilla::dom::indexedDB::KeyPath::ENDGUARD> michael@0: { }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::KeyPath paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mType); michael@0: WriteParam(aMsg, aParam.mStrings); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->mType) && michael@0: ReadParam(aMsg, aIter, &aResult->mStrings); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.mStrings, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits : michael@0: public ContiguousEnumSerializer< michael@0: mozilla::dom::indexedDB::IDBCursor::Direction, michael@0: mozilla::dom::indexedDB::IDBCursor::NEXT, michael@0: mozilla::dom::indexedDB::IDBCursor::DIRECTION_INVALID> michael@0: { }; michael@0: michael@0: template <> michael@0: struct ParamTraits : michael@0: public ContiguousEnumSerializer< michael@0: mozilla::dom::indexedDB::IDBTransaction::Mode, michael@0: mozilla::dom::indexedDB::IDBTransaction::READ_ONLY, michael@0: mozilla::dom::indexedDB::IDBTransaction::MODE_INVALID> michael@0: { }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::IndexInfo paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.name); michael@0: WriteParam(aMsg, aParam.id); michael@0: WriteParam(aMsg, aParam.keyPath); michael@0: WriteParam(aMsg, aParam.unique); michael@0: WriteParam(aMsg, aParam.multiEntry); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->name) && michael@0: ReadParam(aMsg, aIter, &aResult->id) && michael@0: ReadParam(aMsg, aIter, &aResult->keyPath) && michael@0: ReadParam(aMsg, aIter, &aResult->unique) && michael@0: ReadParam(aMsg, aIter, &aResult->multiEntry); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.name, aLog); michael@0: LogParam(aParam.id, aLog); michael@0: LogParam(aParam.keyPath, aLog); michael@0: LogParam(aParam.unique, aLog); michael@0: LogParam(aParam.multiEntry, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::ObjectStoreInfoGuts paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.name); michael@0: WriteParam(aMsg, aParam.id); michael@0: WriteParam(aMsg, aParam.keyPath); michael@0: WriteParam(aMsg, aParam.autoIncrement); michael@0: WriteParam(aMsg, aParam.indexes); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->name) && michael@0: ReadParam(aMsg, aIter, &aResult->id) && michael@0: ReadParam(aMsg, aIter, &aResult->keyPath) && michael@0: ReadParam(aMsg, aIter, &aResult->autoIncrement) && michael@0: ReadParam(aMsg, aIter, &aResult->indexes); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.name, aLog); michael@0: LogParam(aParam.id, aLog); michael@0: LogParam(aParam.keyPath, aLog); michael@0: LogParam(aParam.autoIncrement, aLog); michael@0: LogParam(aParam.indexes, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::DatabaseInfoGuts paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.name); michael@0: WriteParam(aMsg, aParam.group); michael@0: WriteParam(aMsg, aParam.origin); michael@0: WriteParam(aMsg, aParam.version); michael@0: WriteParam(aMsg, aParam.persistenceType); michael@0: WriteParam(aMsg, aParam.nextObjectStoreId); michael@0: WriteParam(aMsg, aParam.nextIndexId); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->name) && michael@0: ReadParam(aMsg, aIter, &aResult->group) && michael@0: ReadParam(aMsg, aIter, &aResult->origin) && michael@0: ReadParam(aMsg, aIter, &aResult->version) && michael@0: ReadParam(aMsg, aIter, &aResult->persistenceType) && michael@0: ReadParam(aMsg, aIter, &aResult->nextObjectStoreId) && michael@0: ReadParam(aMsg, aIter, &aResult->nextIndexId); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.name, aLog); michael@0: LogParam(aParam.group, aLog); michael@0: LogParam(aParam.origin, aLog); michael@0: LogParam(aParam.version, aLog); michael@0: LogParam(aParam.nextObjectStoreId, aLog); michael@0: LogParam(aParam.nextIndexId, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::IndexUpdateInfo paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.indexId); michael@0: WriteParam(aMsg, aParam.indexUnique); michael@0: WriteParam(aMsg, aParam.value); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return ReadParam(aMsg, aIter, &aResult->indexId) && michael@0: ReadParam(aMsg, aIter, &aResult->indexUnique) && michael@0: ReadParam(aMsg, aIter, &aResult->value); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.indexId, aLog); michael@0: LogParam(aParam.indexUnique, aLog); michael@0: LogParam(aParam.value, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.dataLength); michael@0: if (aParam.dataLength) { michael@0: aMsg->WriteBytes(aParam.data, aParam.dataLength); michael@0: } michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->dataLength)) { michael@0: return false; michael@0: } michael@0: michael@0: if (aResult->dataLength) { michael@0: const char** buffer = michael@0: const_cast(reinterpret_cast(&aResult->data)); michael@0: if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) { michael@0: return false; michael@0: } michael@0: } else { michael@0: aResult->data = nullptr; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.dataLength, aLog); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::indexedDB::SerializedStructuredCloneWriteInfo paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.dataLength); michael@0: if (aParam.dataLength) { michael@0: aMsg->WriteBytes(aParam.data, aParam.dataLength); michael@0: } michael@0: WriteParam(aMsg, aParam.offsetToKeyProp); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->dataLength)) { michael@0: return false; michael@0: } michael@0: michael@0: if (aResult->dataLength) { michael@0: const char** buffer = michael@0: const_cast(reinterpret_cast(&aResult->data)); michael@0: if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength)) { michael@0: return false; michael@0: } michael@0: } else { michael@0: aResult->data = nullptr; michael@0: } michael@0: michael@0: if (!ReadParam(aMsg, aIter, &aResult->offsetToKeyProp)) { michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: LogParam(aParam.dataLength, aLog); michael@0: LogParam(aParam.offsetToKeyProp, aLog); michael@0: } michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // mozilla_dom_indexeddb_serializationhelpers_h__