Bug 1891340 - Part 1: Add parameters to customize the before and after icon tints...
[gecko.git] / ipc / glue / IPCMessageUtilsSpecializations.cpp
blob410b1e730ff87c52cd2dc3264c4fd77cf4bf44fc
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"
8 #include "nsGkAtoms.h"
10 namespace IPC {
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");
23 /* static */
24 void ParamTraits<nsAtom*>::Write(MessageWriter* aWriter, const nsAtom* aParam) {
25 MOZ_ASSERT(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);
32 return;
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);
42 /* static */
43 bool ParamTraits<nsAtom*>::Read(MessageReader* aReader,
44 RefPtr<nsAtom>* aResult) {
45 uint16_t token;
46 if (!ReadParam(aReader, &token)) {
47 return false;
49 if (token != kDynamicAtomToken) {
50 if (token >= kAtomsCount) {
51 return false;
53 *aResult = nsGkAtoms::GetAtomByIndex(token);
54 return true;
57 nsAutoString str;
58 if (!ReadParam(aReader, static_cast<nsString*>(&str))) {
59 return false;
62 *aResult = NS_Atomize(str);
63 MOZ_ASSERT(*aResult);
64 return true;
67 } // namespace IPC