1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "IPCMessageUtilsSpecializations.h"
12 static const uint16_t kDynamicAtomToken
= 0xffff;
13 static const uint16_t kAtomsCount
=
14 static_cast<uint16_t>(mozilla::detail::GkAtoms::Atoms::AtomsCount
);
16 static_assert(static_cast<size_t>(
17 mozilla::detail::GkAtoms::Atoms::AtomsCount
) == kAtomsCount
,
18 "Number of static atoms must fit in a uint16_t");
20 static_assert(kDynamicAtomToken
>= kAtomsCount
,
21 "Exceeded supported number of static atoms");
24 void ParamTraits
<nsAtom
*>::Write(MessageWriter
* aWriter
, const nsAtom
* aParam
) {
27 if (aParam
->IsStatic()) {
28 const nsStaticAtom
* atom
= aParam
->AsStatic();
29 uint16_t index
= static_cast<uint16_t>(nsGkAtoms::IndexOf(atom
));
30 MOZ_ASSERT(index
< kAtomsCount
);
31 WriteParam(aWriter
, index
);
34 WriteParam(aWriter
, kDynamicAtomToken
);
35 nsDependentAtomString
atomStr(aParam
);
36 // nsDependentAtomString is serialized as its base, nsString, but we
37 // can be explicit about it.
38 nsString
& str
= atomStr
;
39 WriteParam(aWriter
, str
);
43 bool ParamTraits
<nsAtom
*>::Read(MessageReader
* aReader
,
44 RefPtr
<nsAtom
>* aResult
) {
46 if (!ReadParam(aReader
, &token
)) {
49 if (token
!= kDynamicAtomToken
) {
50 if (token
>= kAtomsCount
) {
53 *aResult
= nsGkAtoms::GetAtomByIndex(token
);
58 if (!ReadParam(aReader
, static_cast<nsString
*>(&str
))) {
62 *aResult
= NS_Atomize(str
);