michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_RegistryMessageUtils_h michael@0: #define mozilla_RegistryMessageUtils_h michael@0: michael@0: #include "ipc/IPCMessageUtils.h" michael@0: #include "nsString.h" michael@0: michael@0: struct SerializedURI michael@0: { michael@0: nsCString spec; michael@0: nsCString charset; michael@0: }; michael@0: michael@0: struct ChromePackage michael@0: { michael@0: nsCString package; michael@0: SerializedURI contentBaseURI; michael@0: SerializedURI localeBaseURI; michael@0: SerializedURI skinBaseURI; michael@0: uint32_t flags; michael@0: }; michael@0: michael@0: struct ResourceMapping michael@0: { michael@0: nsCString resource; michael@0: SerializedURI resolvedURI; michael@0: }; michael@0: michael@0: struct OverrideMapping michael@0: { michael@0: SerializedURI originalURI; michael@0: SerializedURI overrideURI; michael@0: }; michael@0: michael@0: namespace IPC { michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef SerializedURI paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.spec); michael@0: WriteParam(aMsg, aParam.charset); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: nsCString spec, charset; michael@0: if (ReadParam(aMsg, aIter, &spec) && michael@0: ReadParam(aMsg, aIter, &charset)) { michael@0: aResult->spec = spec; michael@0: aResult->charset = charset; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef ChromePackage paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.package); michael@0: WriteParam(aMsg, aParam.contentBaseURI); michael@0: WriteParam(aMsg, aParam.localeBaseURI); michael@0: WriteParam(aMsg, aParam.skinBaseURI); michael@0: WriteParam(aMsg, aParam.flags); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: nsCString package; michael@0: SerializedURI contentBaseURI, localeBaseURI, skinBaseURI; michael@0: uint32_t flags; michael@0: michael@0: if (ReadParam(aMsg, aIter, &package) && michael@0: ReadParam(aMsg, aIter, &contentBaseURI) && michael@0: ReadParam(aMsg, aIter, &localeBaseURI) && michael@0: ReadParam(aMsg, aIter, &skinBaseURI) && michael@0: ReadParam(aMsg, aIter, &flags)) { michael@0: aResult->package = package; michael@0: aResult->contentBaseURI = contentBaseURI; michael@0: aResult->localeBaseURI = localeBaseURI; michael@0: aResult->skinBaseURI = skinBaseURI; michael@0: aResult->flags = flags; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(), michael@0: aParam.contentBaseURI.spec.get(), michael@0: aParam.localeBaseURI.spec.get(), michael@0: aParam.skinBaseURI.spec.get(), aParam.flags)); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef ResourceMapping paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.resource); michael@0: WriteParam(aMsg, aParam.resolvedURI); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: nsCString resource; michael@0: SerializedURI resolvedURI; michael@0: michael@0: if (ReadParam(aMsg, aIter, &resource) && michael@0: ReadParam(aMsg, aIter, &resolvedURI)) { michael@0: aResult->resource = resource; michael@0: aResult->resolvedURI = resolvedURI; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.resource.get(), michael@0: aParam.resolvedURI.spec.get())); michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: { michael@0: typedef OverrideMapping paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.originalURI); michael@0: WriteParam(aMsg, aParam.overrideURI); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: SerializedURI originalURI; michael@0: SerializedURI overrideURI; michael@0: michael@0: if (ReadParam(aMsg, aIter, &originalURI) && michael@0: ReadParam(aMsg, aIter, &overrideURI)) { michael@0: aResult->originalURI = originalURI; michael@0: aResult->overrideURI = overrideURI; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(), michael@0: aParam.overrideURI.spec.get())); michael@0: } michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif // RegistryMessageUtils_h