|
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 { |
|
14 nsCString spec; |
|
15 nsCString charset; |
|
16 }; |
|
17 |
|
18 struct ChromePackage |
|
19 { |
|
20 nsCString package; |
|
21 SerializedURI contentBaseURI; |
|
22 SerializedURI localeBaseURI; |
|
23 SerializedURI skinBaseURI; |
|
24 uint32_t flags; |
|
25 }; |
|
26 |
|
27 struct ResourceMapping |
|
28 { |
|
29 nsCString resource; |
|
30 SerializedURI resolvedURI; |
|
31 }; |
|
32 |
|
33 struct OverrideMapping |
|
34 { |
|
35 SerializedURI originalURI; |
|
36 SerializedURI overrideURI; |
|
37 }; |
|
38 |
|
39 namespace IPC { |
|
40 |
|
41 template<> |
|
42 struct ParamTraits<SerializedURI> |
|
43 { |
|
44 typedef SerializedURI paramType; |
|
45 |
|
46 static void Write(Message* aMsg, const paramType& aParam) |
|
47 { |
|
48 WriteParam(aMsg, aParam.spec); |
|
49 WriteParam(aMsg, aParam.charset); |
|
50 } |
|
51 |
|
52 static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
|
53 { |
|
54 nsCString spec, charset; |
|
55 if (ReadParam(aMsg, aIter, &spec) && |
|
56 ReadParam(aMsg, aIter, &charset)) { |
|
57 aResult->spec = spec; |
|
58 aResult->charset = charset; |
|
59 return true; |
|
60 } |
|
61 return false; |
|
62 } |
|
63 }; |
|
64 |
|
65 template <> |
|
66 struct ParamTraits<ChromePackage> |
|
67 { |
|
68 typedef ChromePackage paramType; |
|
69 |
|
70 static void Write(Message* aMsg, const paramType& aParam) |
|
71 { |
|
72 WriteParam(aMsg, aParam.package); |
|
73 WriteParam(aMsg, aParam.contentBaseURI); |
|
74 WriteParam(aMsg, aParam.localeBaseURI); |
|
75 WriteParam(aMsg, aParam.skinBaseURI); |
|
76 WriteParam(aMsg, aParam.flags); |
|
77 } |
|
78 |
|
79 static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
|
80 { |
|
81 nsCString package; |
|
82 SerializedURI contentBaseURI, localeBaseURI, skinBaseURI; |
|
83 uint32_t flags; |
|
84 |
|
85 if (ReadParam(aMsg, aIter, &package) && |
|
86 ReadParam(aMsg, aIter, &contentBaseURI) && |
|
87 ReadParam(aMsg, aIter, &localeBaseURI) && |
|
88 ReadParam(aMsg, aIter, &skinBaseURI) && |
|
89 ReadParam(aMsg, aIter, &flags)) { |
|
90 aResult->package = package; |
|
91 aResult->contentBaseURI = contentBaseURI; |
|
92 aResult->localeBaseURI = localeBaseURI; |
|
93 aResult->skinBaseURI = skinBaseURI; |
|
94 aResult->flags = flags; |
|
95 return true; |
|
96 } |
|
97 return false; |
|
98 } |
|
99 |
|
100 static void Log(const paramType& aParam, std::wstring* aLog) |
|
101 { |
|
102 aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(), |
|
103 aParam.contentBaseURI.spec.get(), |
|
104 aParam.localeBaseURI.spec.get(), |
|
105 aParam.skinBaseURI.spec.get(), aParam.flags)); |
|
106 } |
|
107 }; |
|
108 |
|
109 template <> |
|
110 struct ParamTraits<ResourceMapping> |
|
111 { |
|
112 typedef ResourceMapping paramType; |
|
113 |
|
114 static void Write(Message* aMsg, const paramType& aParam) |
|
115 { |
|
116 WriteParam(aMsg, aParam.resource); |
|
117 WriteParam(aMsg, aParam.resolvedURI); |
|
118 } |
|
119 |
|
120 static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
|
121 { |
|
122 nsCString resource; |
|
123 SerializedURI resolvedURI; |
|
124 |
|
125 if (ReadParam(aMsg, aIter, &resource) && |
|
126 ReadParam(aMsg, aIter, &resolvedURI)) { |
|
127 aResult->resource = resource; |
|
128 aResult->resolvedURI = resolvedURI; |
|
129 return true; |
|
130 } |
|
131 return false; |
|
132 } |
|
133 |
|
134 static void Log(const paramType& aParam, std::wstring* aLog) |
|
135 { |
|
136 aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.resource.get(), |
|
137 aParam.resolvedURI.spec.get())); |
|
138 } |
|
139 }; |
|
140 |
|
141 template <> |
|
142 struct ParamTraits<OverrideMapping> |
|
143 { |
|
144 typedef OverrideMapping paramType; |
|
145 |
|
146 static void Write(Message* aMsg, const paramType& aParam) |
|
147 { |
|
148 WriteParam(aMsg, aParam.originalURI); |
|
149 WriteParam(aMsg, aParam.overrideURI); |
|
150 } |
|
151 |
|
152 static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
|
153 { |
|
154 SerializedURI originalURI; |
|
155 SerializedURI overrideURI; |
|
156 |
|
157 if (ReadParam(aMsg, aIter, &originalURI) && |
|
158 ReadParam(aMsg, aIter, &overrideURI)) { |
|
159 aResult->originalURI = originalURI; |
|
160 aResult->overrideURI = overrideURI; |
|
161 return true; |
|
162 } |
|
163 return false; |
|
164 } |
|
165 |
|
166 static void Log(const paramType& aParam, std::wstring* aLog) |
|
167 { |
|
168 aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(), |
|
169 aParam.overrideURI.spec.get())); |
|
170 } |
|
171 }; |
|
172 |
|
173 } |
|
174 |
|
175 #endif // RegistryMessageUtils_h |