Source code

Revision control

Other Tools

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
struct SerializedURI {
13
nsCString spec;
14
15
bool operator==(const SerializedURI& rhs) const {
16
return spec.Equals(rhs.spec);
17
}
18
};
19
20
struct ChromePackage {
21
nsCString package;
22
SerializedURI contentBaseURI;
23
SerializedURI localeBaseURI;
24
SerializedURI skinBaseURI;
25
uint32_t flags;
26
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;
32
}
33
};
34
35
struct SubstitutionMapping {
36
nsCString scheme;
37
nsCString path;
38
SerializedURI resolvedURI;
39
uint32_t flags;
40
41
bool operator==(const SubstitutionMapping& rhs) const {
42
return scheme.Equals(rhs.scheme) && path.Equals(rhs.path) &&
43
resolvedURI == rhs.resolvedURI && flags == rhs.flags;
44
}
45
};
46
47
struct OverrideMapping {
48
SerializedURI originalURI;
49
SerializedURI overrideURI;
50
51
bool operator==(const OverrideMapping& rhs) const {
52
return originalURI == rhs.originalURI && overrideURI == rhs.overrideURI;
53
}
54
};
55
56
namespace IPC {
57
58
template <>
59
struct ParamTraits<SerializedURI> {
60
typedef SerializedURI paramType;
61
62
static void Write(Message* aMsg, const paramType& aParam) {
63
WriteParam(aMsg, aParam.spec);
64
}
65
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;
72
}
73
return false;
74
}
75
};
76
77
template <>
78
struct ParamTraits<ChromePackage> {
79
typedef ChromePackage paramType;
80
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);
87
}
88
89
static bool Read(const Message* aMsg, PickleIterator* aIter,
90
paramType* aResult) {
91
nsCString package;
92
SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
93
uint32_t flags;
94
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;
106
}
107
return false;
108
}
109
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));
115
}
116
};
117
118
template <>
119
struct ParamTraits<SubstitutionMapping> {
120
typedef SubstitutionMapping paramType;
121
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);
127
}
128
129
static bool Read(const Message* aMsg, PickleIterator* aIter,
130
paramType* aResult) {
131
nsCString scheme, path;
132
SerializedURI resolvedURI;
133
uint32_t flags;
134
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;
143
}
144
return false;
145
}
146
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()));
151
}
152
};
153
154
template <>
155
struct ParamTraits<OverrideMapping> {
156
typedef OverrideMapping paramType;
157
158
static void Write(Message* aMsg, const paramType& aParam) {
159
WriteParam(aMsg, aParam.originalURI);
160
WriteParam(aMsg, aParam.overrideURI);
161
}
162
163
static bool Read(const Message* aMsg, PickleIterator* aIter,
164
paramType* aResult) {
165
SerializedURI originalURI;
166
SerializedURI overrideURI;
167
168
if (ReadParam(aMsg, aIter, &originalURI) &&
169
ReadParam(aMsg, aIter, &overrideURI)) {
170
aResult->originalURI = originalURI;
171
aResult->overrideURI = overrideURI;
172
return true;
173
}
174
return false;
175
}
176
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()));
180
}
181
};
182
183
} // namespace IPC
184
185
#endif // RegistryMessageUtils_h