Line data Source code
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/. */
5 :
6 : #ifndef mozilla_RegistryMessageUtils_h
7 : #define mozilla_RegistryMessageUtils_h
8 :
9 : #include "ipc/IPCMessageUtils.h"
10 : #include "nsString.h"
11 :
12 4518 : struct SerializedURI
13 : {
14 : nsCString spec;
15 : nsCString charset;
16 :
17 0 : bool operator ==(const SerializedURI& rhs) const
18 : {
19 0 : return spec.Equals(rhs.spec) &&
20 0 : charset.Equals(rhs.charset);
21 : }
22 : };
23 :
24 788 : struct ChromePackage
25 : {
26 : nsCString package;
27 : SerializedURI contentBaseURI;
28 : SerializedURI localeBaseURI;
29 : SerializedURI skinBaseURI;
30 : uint32_t flags;
31 :
32 0 : bool operator ==(const ChromePackage& rhs) const
33 : {
34 0 : return package.Equals(rhs.package) &&
35 0 : contentBaseURI == rhs.contentBaseURI &&
36 0 : localeBaseURI == rhs.localeBaseURI &&
37 0 : skinBaseURI == rhs.skinBaseURI &&
38 0 : flags == rhs.flags;
39 : }
40 : };
41 :
42 110 : struct SubstitutionMapping
43 : {
44 : nsCString scheme;
45 : nsCString path;
46 : SerializedURI resolvedURI;
47 :
48 0 : bool operator ==(const SubstitutionMapping& rhs) const
49 : {
50 0 : return scheme.Equals(rhs.scheme) &&
51 0 : path.Equals(rhs.path) &&
52 0 : resolvedURI == rhs.resolvedURI;
53 : }
54 : };
55 :
56 260 : struct OverrideMapping
57 : {
58 : SerializedURI originalURI;
59 : SerializedURI overrideURI;
60 :
61 0 : bool operator==(const OverrideMapping& rhs) const
62 : {
63 0 : return originalURI == rhs.originalURI &&
64 0 : overrideURI == rhs.overrideURI;
65 : }
66 : };
67 :
68 : namespace IPC {
69 :
70 : template<>
71 : struct ParamTraits<SerializedURI>
72 : {
73 : typedef SerializedURI paramType;
74 :
75 366 : static void Write(Message* aMsg, const paramType& aParam)
76 : {
77 366 : WriteParam(aMsg, aParam.spec);
78 366 : WriteParam(aMsg, aParam.charset);
79 366 : }
80 :
81 366 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
82 : {
83 732 : nsCString spec, charset;
84 732 : if (ReadParam(aMsg, aIter, &spec) &&
85 366 : ReadParam(aMsg, aIter, &charset)) {
86 366 : aResult->spec = spec;
87 366 : aResult->charset = charset;
88 366 : return true;
89 : }
90 0 : return false;
91 : }
92 : };
93 :
94 : template <>
95 : struct ParamTraits<ChromePackage>
96 : {
97 : typedef ChromePackage paramType;
98 :
99 88 : static void Write(Message* aMsg, const paramType& aParam)
100 : {
101 88 : WriteParam(aMsg, aParam.package);
102 88 : WriteParam(aMsg, aParam.contentBaseURI);
103 88 : WriteParam(aMsg, aParam.localeBaseURI);
104 88 : WriteParam(aMsg, aParam.skinBaseURI);
105 88 : WriteParam(aMsg, aParam.flags);
106 88 : }
107 :
108 88 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
109 : {
110 176 : nsCString package;
111 176 : SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
112 : uint32_t flags;
113 :
114 264 : if (ReadParam(aMsg, aIter, &package) &&
115 176 : ReadParam(aMsg, aIter, &contentBaseURI) &&
116 176 : ReadParam(aMsg, aIter, &localeBaseURI) &&
117 264 : ReadParam(aMsg, aIter, &skinBaseURI) &&
118 88 : ReadParam(aMsg, aIter, &flags)) {
119 88 : aResult->package = package;
120 88 : aResult->contentBaseURI = contentBaseURI;
121 88 : aResult->localeBaseURI = localeBaseURI;
122 88 : aResult->skinBaseURI = skinBaseURI;
123 88 : aResult->flags = flags;
124 88 : return true;
125 : }
126 0 : return false;
127 : }
128 :
129 : static void Log(const paramType& aParam, std::wstring* aLog)
130 : {
131 : aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
132 : aParam.contentBaseURI.spec.get(),
133 : aParam.localeBaseURI.spec.get(),
134 : aParam.skinBaseURI.spec.get(), aParam.flags));
135 : }
136 : };
137 :
138 : template <>
139 : struct ParamTraits<SubstitutionMapping>
140 : {
141 : typedef SubstitutionMapping paramType;
142 :
143 22 : static void Write(Message* aMsg, const paramType& aParam)
144 : {
145 22 : WriteParam(aMsg, aParam.scheme);
146 22 : WriteParam(aMsg, aParam.path);
147 22 : WriteParam(aMsg, aParam.resolvedURI);
148 22 : }
149 :
150 22 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
151 : {
152 44 : nsCString scheme, path;
153 44 : SerializedURI resolvedURI;
154 :
155 66 : if (ReadParam(aMsg, aIter, &scheme) &&
156 44 : ReadParam(aMsg, aIter, &path) &&
157 22 : ReadParam(aMsg, aIter, &resolvedURI)) {
158 22 : aResult->scheme = scheme;
159 22 : aResult->path = path;
160 22 : aResult->resolvedURI = resolvedURI;
161 22 : return true;
162 : }
163 0 : return false;
164 : }
165 :
166 : static void Log(const paramType& aParam, std::wstring* aLog)
167 : {
168 : aLog->append(StringPrintf(L"[%s://%s, %s, %u]",
169 : aParam.scheme.get(),
170 : aParam.path.get(),
171 : aParam.resolvedURI.spec.get()));
172 : }
173 : };
174 :
175 : template <>
176 : struct ParamTraits<OverrideMapping>
177 : {
178 : typedef OverrideMapping paramType;
179 :
180 40 : static void Write(Message* aMsg, const paramType& aParam)
181 : {
182 40 : WriteParam(aMsg, aParam.originalURI);
183 40 : WriteParam(aMsg, aParam.overrideURI);
184 40 : }
185 :
186 40 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
187 : {
188 80 : SerializedURI originalURI;
189 80 : SerializedURI overrideURI;
190 :
191 80 : if (ReadParam(aMsg, aIter, &originalURI) &&
192 40 : ReadParam(aMsg, aIter, &overrideURI)) {
193 40 : aResult->originalURI = originalURI;
194 40 : aResult->overrideURI = overrideURI;
195 40 : return true;
196 : }
197 0 : return false;
198 : }
199 :
200 : static void Log(const paramType& aParam, std::wstring* aLog)
201 : {
202 : aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
203 : aParam.overrideURI.spec.get()));
204 : }
205 : };
206 :
207 : } // namespace IPC
208 :
209 : #endif // RegistryMessageUtils_h
|