Bug 1772603 [wpt PR 34303] - Add WPT test writing and reading back a 0.5 alpha fillSt...
[gecko.git] / chrome / RegistryMessageUtils.h
blobc022a8071425e473c2911e541ca0906e93a936a4
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 {
13 nsCString spec;
15 bool operator==(const SerializedURI& rhs) const {
16 return spec.Equals(rhs.spec);
20 struct ChromePackage {
21 nsCString package;
22 SerializedURI contentBaseURI;
23 SerializedURI localeBaseURI;
24 SerializedURI skinBaseURI;
25 uint32_t flags;
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 {
36 nsCString scheme;
37 nsCString path;
38 SerializedURI resolvedURI;
39 uint32_t flags;
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;
56 namespace IPC {
58 template <>
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) {
67 nsCString spec;
68 if (ReadParam(aReader, &spec)) {
69 aResult->spec = spec;
70 return true;
72 return false;
76 template <>
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) {
89 nsCString package;
90 SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
91 uint32_t flags;
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;
101 return true;
103 return false;
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));
114 template <>
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;
128 uint32_t flags;
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;
136 return true;
138 return false;
141 static void Log(const paramType& aParam, std::wstring* aLog) {
142 aLog->append(StringPrintf(L"[%s://%s, %s, %u]", aParam.scheme.get(),
143 aParam.path.get(),
144 aParam.resolvedURI.spec.get()));
148 template <>
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;
164 return true;
166 return false;
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()));
175 } // namespace IPC
177 #endif // RegistryMessageUtils_h