Bug 1492908 [wpt PR 13122] - Update wpt metadata, a=testonly
[gecko.git] / chrome / RegistryMessageUtils.h
blobd8cfa616852a3860c8d38a5cf197bb4544c658b0
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"
10 #include "nsString.h"
12 struct SerializedURI
14 nsCString spec;
16 bool operator ==(const SerializedURI& rhs) const
18 return spec.Equals(rhs.spec);
22 struct ChromePackage
24 nsCString package;
25 SerializedURI contentBaseURI;
26 SerializedURI localeBaseURI;
27 SerializedURI skinBaseURI;
28 uint32_t flags;
30 bool operator ==(const ChromePackage& rhs) const
32 return package.Equals(rhs.package) &&
33 contentBaseURI == rhs.contentBaseURI &&
34 localeBaseURI == rhs.localeBaseURI &&
35 skinBaseURI == rhs.skinBaseURI &&
36 flags == rhs.flags;
40 struct SubstitutionMapping
42 nsCString scheme;
43 nsCString path;
44 SerializedURI resolvedURI;
45 uint32_t flags;
47 bool operator ==(const SubstitutionMapping& rhs) const
49 return scheme.Equals(rhs.scheme) &&
50 path.Equals(rhs.path) &&
51 resolvedURI == rhs.resolvedURI &&
52 flags == rhs.flags;
56 struct OverrideMapping
58 SerializedURI originalURI;
59 SerializedURI overrideURI;
61 bool operator==(const OverrideMapping& rhs) const
63 return originalURI == rhs.originalURI &&
64 overrideURI == rhs.overrideURI;
68 namespace IPC {
70 template<>
71 struct ParamTraits<SerializedURI>
73 typedef SerializedURI paramType;
75 static void Write(Message* aMsg, const paramType& aParam)
77 WriteParam(aMsg, aParam.spec);
80 static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
82 nsCString spec;
83 if (ReadParam(aMsg, aIter, &spec)) {
84 aResult->spec = spec;
85 return true;
87 return false;
91 template <>
92 struct ParamTraits<ChromePackage>
94 typedef ChromePackage paramType;
96 static void Write(Message* aMsg, const paramType& aParam)
98 WriteParam(aMsg, aParam.package);
99 WriteParam(aMsg, aParam.contentBaseURI);
100 WriteParam(aMsg, aParam.localeBaseURI);
101 WriteParam(aMsg, aParam.skinBaseURI);
102 WriteParam(aMsg, aParam.flags);
105 static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
107 nsCString package;
108 SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
109 uint32_t flags;
111 if (ReadParam(aMsg, aIter, &package) &&
112 ReadParam(aMsg, aIter, &contentBaseURI) &&
113 ReadParam(aMsg, aIter, &localeBaseURI) &&
114 ReadParam(aMsg, aIter, &skinBaseURI) &&
115 ReadParam(aMsg, aIter, &flags)) {
116 aResult->package = package;
117 aResult->contentBaseURI = contentBaseURI;
118 aResult->localeBaseURI = localeBaseURI;
119 aResult->skinBaseURI = skinBaseURI;
120 aResult->flags = flags;
121 return true;
123 return false;
126 static void Log(const paramType& aParam, std::wstring* aLog)
128 aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
129 aParam.contentBaseURI.spec.get(),
130 aParam.localeBaseURI.spec.get(),
131 aParam.skinBaseURI.spec.get(), aParam.flags));
135 template <>
136 struct ParamTraits<SubstitutionMapping>
138 typedef SubstitutionMapping paramType;
140 static void Write(Message* aMsg, const paramType& aParam)
142 WriteParam(aMsg, aParam.scheme);
143 WriteParam(aMsg, aParam.path);
144 WriteParam(aMsg, aParam.resolvedURI);
145 WriteParam(aMsg, aParam.flags);
148 static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
150 nsCString scheme, path;
151 SerializedURI resolvedURI;
152 uint32_t flags;
154 if (ReadParam(aMsg, aIter, &scheme) &&
155 ReadParam(aMsg, aIter, &path) &&
156 ReadParam(aMsg, aIter, &resolvedURI) &&
157 ReadParam(aMsg, aIter, &flags)) {
158 aResult->scheme = scheme;
159 aResult->path = path;
160 aResult->resolvedURI = resolvedURI;
161 aResult->flags = flags;
162 return true;
164 return false;
167 static void Log(const paramType& aParam, std::wstring* aLog)
169 aLog->append(StringPrintf(L"[%s://%s, %s, %u]",
170 aParam.scheme.get(),
171 aParam.path.get(),
172 aParam.resolvedURI.spec.get()));
176 template <>
177 struct ParamTraits<OverrideMapping>
179 typedef OverrideMapping paramType;
181 static void Write(Message* aMsg, const paramType& aParam)
183 WriteParam(aMsg, aParam.originalURI);
184 WriteParam(aMsg, aParam.overrideURI);
187 static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
189 SerializedURI originalURI;
190 SerializedURI overrideURI;
192 if (ReadParam(aMsg, aIter, &originalURI) &&
193 ReadParam(aMsg, aIter, &overrideURI)) {
194 aResult->originalURI = originalURI;
195 aResult->overrideURI = overrideURI;
196 return true;
198 return false;
201 static void Log(const paramType& aParam, std::wstring* aLog)
203 aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
204 aParam.overrideURI.spec.get()));
208 } // namespace IPC
210 #endif // RegistryMessageUtils_h