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(Message
* aMsg
, const paramType
& aParam
) {
63 WriteParam(aMsg
, aParam
.spec
);
66 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
69 if (ReadParam(aMsg
, aIter
, &spec
)) {
78 struct ParamTraits
<ChromePackage
> {
79 typedef ChromePackage paramType
;
81 static void Write(Message
* aMsg
, const paramType
& aParam
) {
82 WriteParam(aMsg
, aParam
.package
);
83 WriteParam(aMsg
, aParam
.contentBaseURI
);
84 WriteParam(aMsg
, aParam
.localeBaseURI
);
85 WriteParam(aMsg
, aParam
.skinBaseURI
);
86 WriteParam(aMsg
, aParam
.flags
);
89 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
92 SerializedURI contentBaseURI
, localeBaseURI
, skinBaseURI
;
95 if (ReadParam(aMsg
, aIter
, &package
) &&
96 ReadParam(aMsg
, aIter
, &contentBaseURI
) &&
97 ReadParam(aMsg
, aIter
, &localeBaseURI
) &&
98 ReadParam(aMsg
, aIter
, &skinBaseURI
) &&
99 ReadParam(aMsg
, aIter
, &flags
)) {
100 aResult
->package
= package
;
101 aResult
->contentBaseURI
= contentBaseURI
;
102 aResult
->localeBaseURI
= localeBaseURI
;
103 aResult
->skinBaseURI
= skinBaseURI
;
104 aResult
->flags
= flags
;
110 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
111 aLog
->append(StringPrintf(L
"[%s, %s, %s, %s, %u]", aParam
.package
.get(),
112 aParam
.contentBaseURI
.spec
.get(),
113 aParam
.localeBaseURI
.spec
.get(),
114 aParam
.skinBaseURI
.spec
.get(), aParam
.flags
));
119 struct ParamTraits
<SubstitutionMapping
> {
120 typedef SubstitutionMapping paramType
;
122 static void Write(Message
* aMsg
, const paramType
& aParam
) {
123 WriteParam(aMsg
, aParam
.scheme
);
124 WriteParam(aMsg
, aParam
.path
);
125 WriteParam(aMsg
, aParam
.resolvedURI
);
126 WriteParam(aMsg
, aParam
.flags
);
129 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
130 paramType
* aResult
) {
131 nsCString scheme
, path
;
132 SerializedURI resolvedURI
;
135 if (ReadParam(aMsg
, aIter
, &scheme
) && ReadParam(aMsg
, aIter
, &path
) &&
136 ReadParam(aMsg
, aIter
, &resolvedURI
) &&
137 ReadParam(aMsg
, aIter
, &flags
)) {
138 aResult
->scheme
= scheme
;
139 aResult
->path
= path
;
140 aResult
->resolvedURI
= resolvedURI
;
141 aResult
->flags
= flags
;
147 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
148 aLog
->append(StringPrintf(L
"[%s://%s, %s, %u]", aParam
.scheme
.get(),
150 aParam
.resolvedURI
.spec
.get()));
155 struct ParamTraits
<OverrideMapping
> {
156 typedef OverrideMapping paramType
;
158 static void Write(Message
* aMsg
, const paramType
& aParam
) {
159 WriteParam(aMsg
, aParam
.originalURI
);
160 WriteParam(aMsg
, aParam
.overrideURI
);
163 static bool Read(const Message
* aMsg
, PickleIterator
* aIter
,
164 paramType
* aResult
) {
165 SerializedURI originalURI
;
166 SerializedURI overrideURI
;
168 if (ReadParam(aMsg
, aIter
, &originalURI
) &&
169 ReadParam(aMsg
, aIter
, &overrideURI
)) {
170 aResult
->originalURI
= originalURI
;
171 aResult
->overrideURI
= overrideURI
;
177 static void Log(const paramType
& aParam
, std::wstring
* aLog
) {
178 aLog
->append(StringPrintf(L
"[%s, %s, %u]", aParam
.originalURI
.spec
.get(),
179 aParam
.overrideURI
.spec
.get()));
185 #endif // RegistryMessageUtils_h