Bug 1835684 [wpt PR 40289] - Update wpt metadata, a=testonly
[gecko.git] / chrome / RegistryMessageUtils.h
blob53ef7defc2538ce227c0714570087573f33a29c9
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 "mozilla/ipc/IPDLParamTraits.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;
107 template <>
108 struct ParamTraits<SubstitutionMapping> {
109 typedef SubstitutionMapping paramType;
111 static void Write(MessageWriter* aWriter, const paramType& aParam) {
112 WriteParam(aWriter, aParam.scheme);
113 WriteParam(aWriter, aParam.path);
114 WriteParam(aWriter, aParam.resolvedURI);
115 WriteParam(aWriter, aParam.flags);
118 static bool Read(MessageReader* aReader, paramType* aResult) {
119 nsCString scheme, path;
120 SerializedURI resolvedURI;
121 uint32_t flags;
123 if (ReadParam(aReader, &scheme) && ReadParam(aReader, &path) &&
124 ReadParam(aReader, &resolvedURI) && ReadParam(aReader, &flags)) {
125 aResult->scheme = scheme;
126 aResult->path = path;
127 aResult->resolvedURI = resolvedURI;
128 aResult->flags = flags;
129 return true;
131 return false;
135 template <>
136 struct ParamTraits<OverrideMapping> {
137 typedef OverrideMapping paramType;
139 static void Write(MessageWriter* aWriter, const paramType& aParam) {
140 WriteParam(aWriter, aParam.originalURI);
141 WriteParam(aWriter, aParam.overrideURI);
144 static bool Read(MessageReader* aReader, paramType* aResult) {
145 SerializedURI originalURI;
146 SerializedURI overrideURI;
148 if (ReadParam(aReader, &originalURI) && ReadParam(aReader, &overrideURI)) {
149 aResult->originalURI = originalURI;
150 aResult->overrideURI = overrideURI;
151 return true;
153 return false;
157 } // namespace IPC
159 #endif // RegistryMessageUtils_h