1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_RegistryMessageUtils_h
7 #define mozilla_RegistryMessageUtils_h
9 #include "ipc/IPCMessageUtils.h"
12 struct SerializedURI
{
15 bool operator==(const SerializedURI
& rhs
) const {
16 return spec
.Equals(rhs
.spec
);
20 struct ChromePackage
{
22 SerializedURI contentBaseURI
;
23 SerializedURI localeBaseURI
;
24 SerializedURI skinBaseURI
;
27 bool operator==(const ChromePackage
& rhs
) const {
28 return package
.Equals(rhs
.package
) &&
29 contentBaseURI
== rhs
.contentBaseURI
&&
30 localeBaseURI
== rhs
.localeBaseURI
&&
31 skinBaseURI
== rhs
.skinBaseURI
&& flags
== rhs
.flags
;
35 struct SubstitutionMapping
{
38 SerializedURI resolvedURI
;
41 bool operator==(const SubstitutionMapping
& rhs
) const {
42 return scheme
.Equals(rhs
.scheme
) && path
.Equals(rhs
.path
) &&
43 resolvedURI
== rhs
.resolvedURI
&& flags
== rhs
.flags
;
47 struct OverrideMapping
{
48 SerializedURI originalURI
;
49 SerializedURI overrideURI
;
51 bool operator==(const OverrideMapping
& rhs
) const {
52 return originalURI
== rhs
.originalURI
&& overrideURI
== rhs
.overrideURI
;
59 struct ParamTraits
<SerializedURI
> {
60 typedef SerializedURI paramType
;
62 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
63 WriteParam(aWriter
, aParam
.spec
);
66 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
68 if (ReadParam(aReader
, &spec
)) {
77 struct ParamTraits
<ChromePackage
> {
78 typedef ChromePackage paramType
;
80 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
81 WriteParam(aWriter
, aParam
.package
);
82 WriteParam(aWriter
, aParam
.contentBaseURI
);
83 WriteParam(aWriter
, aParam
.localeBaseURI
);
84 WriteParam(aWriter
, aParam
.skinBaseURI
);
85 WriteParam(aWriter
, aParam
.flags
);
88 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
90 SerializedURI contentBaseURI
, localeBaseURI
, skinBaseURI
;
93 if (ReadParam(aReader
, &package
) && ReadParam(aReader
, &contentBaseURI
) &&
94 ReadParam(aReader
, &localeBaseURI
) &&
95 ReadParam(aReader
, &skinBaseURI
) && ReadParam(aReader
, &flags
)) {
96 aResult
->package
= package
;
97 aResult
->contentBaseURI
= contentBaseURI
;
98 aResult
->localeBaseURI
= localeBaseURI
;
99 aResult
->skinBaseURI
= skinBaseURI
;
100 aResult
->flags
= flags
;
106 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
107 aLog
->append(StringPrintf(L
"[%s, %s, %s, %s, %u]", aParam
.package
.get(),
108 aParam
.contentBaseURI
.spec
.get(),
109 aParam
.localeBaseURI
.spec
.get(),
110 aParam
.skinBaseURI
.spec
.get(), aParam
.flags
));
115 struct ParamTraits
<SubstitutionMapping
> {
116 typedef SubstitutionMapping paramType
;
118 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
119 WriteParam(aWriter
, aParam
.scheme
);
120 WriteParam(aWriter
, aParam
.path
);
121 WriteParam(aWriter
, aParam
.resolvedURI
);
122 WriteParam(aWriter
, aParam
.flags
);
125 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
126 nsCString scheme
, path
;
127 SerializedURI resolvedURI
;
130 if (ReadParam(aReader
, &scheme
) && ReadParam(aReader
, &path
) &&
131 ReadParam(aReader
, &resolvedURI
) && ReadParam(aReader
, &flags
)) {
132 aResult
->scheme
= scheme
;
133 aResult
->path
= path
;
134 aResult
->resolvedURI
= resolvedURI
;
135 aResult
->flags
= flags
;
141 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
142 aLog
->append(StringPrintf(L
"[%s://%s, %s, %u]", aParam
.scheme
.get(),
144 aParam
.resolvedURI
.spec
.get()));
149 struct ParamTraits
<OverrideMapping
> {
150 typedef OverrideMapping paramType
;
152 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
153 WriteParam(aWriter
, aParam
.originalURI
);
154 WriteParam(aWriter
, aParam
.overrideURI
);
157 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
158 SerializedURI originalURI
;
159 SerializedURI overrideURI
;
161 if (ReadParam(aReader
, &originalURI
) && ReadParam(aReader
, &overrideURI
)) {
162 aResult
->originalURI
= originalURI
;
163 aResult
->overrideURI
= overrideURI
;
169 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
170 aLog
->append(StringPrintf(L
"[%s, %s, %u]", aParam
.originalURI
.spec
.get(),
171 aParam
.overrideURI
.spec
.get()));
177 #endif // RegistryMessageUtils_h