зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1704658: Implement ParamTraits for RefPtr<nsAtom> r=nika
Serialization for both nsStaticAtoms and nsDynamicAtoms. Differential Revision: https://phabricator.services.mozilla.com/D112433
This commit is contained in:
Родитель
08e5481d99
Коммит
c99bc3e206
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "IPCMessageUtilsSpecializations.h"
|
||||
#include "nsGkAtoms.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
static const uint16_t kDynamicAtomToken = 0xffff;
|
||||
static const uint16_t kAtomsCount =
|
||||
static_cast<uint16_t>(mozilla::detail::GkAtoms::Atoms::AtomsCount);
|
||||
|
||||
static_assert(static_cast<size_t>(
|
||||
mozilla::detail::GkAtoms::Atoms::AtomsCount) == kAtomsCount,
|
||||
"Number of static atoms must fit in a uint16_t");
|
||||
|
||||
static_assert(kDynamicAtomToken >= kAtomsCount,
|
||||
"Exceeded supported number of static atoms");
|
||||
|
||||
/* static */
|
||||
void ParamTraits<nsAtom*>::Write(Message* aMsg, const nsAtom* aParam) {
|
||||
MOZ_ASSERT(aParam);
|
||||
|
||||
if (aParam->IsStatic()) {
|
||||
const nsStaticAtom* atom = aParam->AsStatic();
|
||||
uint16_t index = static_cast<uint16_t>(nsGkAtoms::IndexOf(atom));
|
||||
MOZ_ASSERT(index < kAtomsCount);
|
||||
WriteParam(aMsg, index);
|
||||
return;
|
||||
}
|
||||
WriteParam(aMsg, kDynamicAtomToken);
|
||||
nsDependentAtomString atomStr(aParam);
|
||||
// nsDependentAtomString is serialized as its base, nsString, but we
|
||||
// can be explicit about it.
|
||||
nsString& str = atomStr;
|
||||
WriteParam(aMsg, str);
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool ParamTraits<nsAtom*>::Read(const Message* aMsg, PickleIterator* aIter,
|
||||
RefPtr<nsAtom>* aResult) {
|
||||
uint16_t token;
|
||||
if (!ReadParam(aMsg, aIter, &token)) {
|
||||
return false;
|
||||
}
|
||||
if (token != kDynamicAtomToken) {
|
||||
if (token >= kAtomsCount) {
|
||||
return false;
|
||||
}
|
||||
*aResult = nsGkAtoms::GetAtomByIndex(token);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsAutoString str;
|
||||
if (!ReadParam(aMsg, aIter, static_cast<nsString*>(&str))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*aResult = NS_Atomize(str);
|
||||
MOZ_ASSERT(*aResult);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace IPC
|
|
@ -68,6 +68,8 @@ template <typename T>
|
|||
class Optional;
|
||||
}
|
||||
|
||||
class nsAtom;
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template <>
|
||||
|
@ -887,6 +889,15 @@ struct ParamTraits<mozilla::dom::Optional<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<nsAtom*> {
|
||||
typedef nsAtom paramType;
|
||||
|
||||
static void Write(Message* aMsg, const paramType* aParam);
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter,
|
||||
RefPtr<paramType>* aResult);
|
||||
};
|
||||
|
||||
struct CrossOriginOpenerPolicyValidator {
|
||||
using IntegralType =
|
||||
std::underlying_type_t<nsILoadInfo::CrossOriginOpenerPolicy>;
|
||||
|
|
|
@ -160,6 +160,7 @@ UNIFIED_SOURCES += [
|
|||
"IdleSchedulerParent.cpp",
|
||||
"InputStreamUtils.cpp",
|
||||
"IPCMessageUtils.cpp",
|
||||
"IPCMessageUtilsSpecializations.cpp",
|
||||
"IPCStreamChild.cpp",
|
||||
"IPCStreamDestination.cpp",
|
||||
"IPCStreamParent.cpp",
|
||||
|
|
|
@ -149,6 +149,13 @@ class nsGkAtoms {
|
|||
return const_cast<nsStaticAtom*>(&sAtoms[aIndex]);
|
||||
}
|
||||
|
||||
static size_t IndexOf(const nsStaticAtom* atom) {
|
||||
nsStaticAtom* firstAtom = GetAtomByIndex(0);
|
||||
size_t ret = atom - firstAtom;
|
||||
MOZ_ASSERT(ret < sAtomsLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// The definition of the pointer to each static atom.
|
||||
//
|
||||
// These types are not `static constexpr <type>* const` -- even though these
|
||||
|
|
Загрузка…
Ссылка в новой задаче