Bug 1635673 [wpt PR 23412] - [ResourceTiming] Dispatch entry for 404 scripts, a=testonly
[gecko.git] / chrome / RegistryMessageUtils.h
blobcc682676dc261757f0c3938a32c24104bafc5803
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(Message* aMsg, const paramType& aParam) {
63 WriteParam(aMsg, aParam.spec);
66 static bool Read(const Message* aMsg, PickleIterator* aIter,
67 paramType* aResult) {
68 nsCString spec;
69 if (ReadParam(aMsg, aIter, &spec)) {
70 aResult->spec = spec;
71 return true;
73 return false;
77 template <>
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,
90 paramType* aResult) {
91 nsCString package;
92 SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
93 uint32_t flags;
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;
105 return true;
107 return false;
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));
118 template <>
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;
133 uint32_t flags;
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;
142 return true;
144 return false;
147 static void Log(const paramType& aParam, std::wstring* aLog) {
148 aLog->append(StringPrintf(L"[%s://%s, %s, %u]", aParam.scheme.get(),
149 aParam.path.get(),
150 aParam.resolvedURI.spec.get()));
154 template <>
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;
172 return true;
174 return false;
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()));
183 } // namespace IPC
185 #endif // RegistryMessageUtils_h