Bug 634734 - Fennec ASSERTION: mFUnitsConvFactor not valid: mFUnitsConvFactor > 0...
[mozilla-central.git] / chrome / src / RegistryMessageUtils.h
blob3e8fc8ed3c704320a2abed09e66cba8719b95aca
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Matthews <josh@joshmatthews.net> (Initial Developer)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef mozilla_RegistryMessageUtils_h
40 #define mozilla_RegistryMessageUtils_h
42 #include "IPC/IPCMessageUtils.h"
43 #include "nsStringGlue.h"
45 struct SerializedURI
47 nsCString spec;
48 nsCString charset;
51 struct ChromePackage
53 nsCString package;
54 SerializedURI contentBaseURI;
55 SerializedURI localeBaseURI;
56 SerializedURI skinBaseURI;
57 PRUint32 flags;
60 struct ResourceMapping
62 nsCString resource;
63 SerializedURI resolvedURI;
66 struct OverrideMapping
68 SerializedURI originalURI;
69 SerializedURI overrideURI;
72 namespace IPC {
74 template<>
75 struct ParamTraits<SerializedURI>
77 typedef SerializedURI paramType;
79 static void Write(Message* aMsg, const paramType& aParam)
81 WriteParam(aMsg, aParam.spec);
82 WriteParam(aMsg, aParam.charset);
85 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
87 nsCString spec, charset;
88 if (ReadParam(aMsg, aIter, &spec) &&
89 ReadParam(aMsg, aIter, &charset)) {
90 aResult->spec = spec;
91 aResult->charset = charset;
92 return true;
94 return false;
98 template <>
99 struct ParamTraits<ChromePackage>
101 typedef ChromePackage paramType;
103 static void Write(Message* aMsg, const paramType& aParam)
105 WriteParam(aMsg, aParam.package);
106 WriteParam(aMsg, aParam.contentBaseURI);
107 WriteParam(aMsg, aParam.localeBaseURI);
108 WriteParam(aMsg, aParam.skinBaseURI);
109 WriteParam(aMsg, aParam.flags);
112 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
114 nsCString package;
115 SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
116 PRUint32 flags;
118 if (ReadParam(aMsg, aIter, &package) &&
119 ReadParam(aMsg, aIter, &contentBaseURI) &&
120 ReadParam(aMsg, aIter, &localeBaseURI) &&
121 ReadParam(aMsg, aIter, &skinBaseURI) &&
122 ReadParam(aMsg, aIter, &flags)) {
123 aResult->package = package;
124 aResult->contentBaseURI = contentBaseURI;
125 aResult->localeBaseURI = localeBaseURI;
126 aResult->skinBaseURI = skinBaseURI;
127 aResult->flags = flags;
128 return true;
130 return false;
133 static void Log(const paramType& aParam, std::wstring* aLog)
135 aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
136 aParam.contentBaseURI.spec.get(),
137 aParam.localeBaseURI.spec.get(),
138 aParam.skinBaseURI.spec.get(), aParam.flags));
142 template <>
143 struct ParamTraits<ResourceMapping>
145 typedef ResourceMapping paramType;
147 static void Write(Message* aMsg, const paramType& aParam)
149 WriteParam(aMsg, aParam.resource);
150 WriteParam(aMsg, aParam.resolvedURI);
153 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
155 nsCString resource;
156 SerializedURI resolvedURI;
158 if (ReadParam(aMsg, aIter, &resource) &&
159 ReadParam(aMsg, aIter, &resolvedURI)) {
160 aResult->resource = resource;
161 aResult->resolvedURI = resolvedURI;
162 return true;
164 return false;
167 static void Log(const paramType& aParam, std::wstring* aLog)
169 aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.resource.get(),
170 aParam.resolvedURI.spec.get()));
174 template <>
175 struct ParamTraits<OverrideMapping>
177 typedef OverrideMapping paramType;
179 static void Write(Message* aMsg, const paramType& aParam)
181 WriteParam(aMsg, aParam.originalURI);
182 WriteParam(aMsg, aParam.overrideURI);
185 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
187 SerializedURI originalURI;
188 SerializedURI overrideURI;
190 if (ReadParam(aMsg, aIter, &originalURI) &&
191 ReadParam(aMsg, aIter, &overrideURI)) {
192 aResult->originalURI = originalURI;
193 aResult->overrideURI = overrideURI;
194 return true;
196 return false;
199 static void Log(const paramType& aParam, std::wstring* aLog)
201 aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
202 aParam.overrideURI.spec.get()));
208 #endif // RegistryMessageUtils_h