2009-09-22 06:02:15 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2009-06-29 22:38:29 +04:00
|
|
|
|
|
|
|
#ifndef __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
#define __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
|
2013-01-18 00:06:36 +04:00
|
|
|
#include "base/process_util.h"
|
2009-06-29 22:38:29 +04:00
|
|
|
#include "chrome/common/ipc_message_utils.h"
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-07-31 21:28:20 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-02-12 01:56:58 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/TimeStamp_windows.h"
|
|
|
|
#endif
|
2014-01-10 23:06:12 +04:00
|
|
|
#include "mozilla/TypedEnum.h"
|
2014-04-14 18:17:40 +04:00
|
|
|
#include "mozilla/IntegerTypeTraits.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2011-06-24 18:19:56 +04:00
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsMemory.h"
|
2013-09-23 21:25:00 +04:00
|
|
|
#include "nsString.h"
|
2009-06-29 22:38:29 +04:00
|
|
|
#include "nsTArray.h"
|
2013-08-20 10:43:47 +04:00
|
|
|
#include "js/StructuredClone.h"
|
2012-08-20 17:35:41 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2009-06-29 22:38:29 +04:00
|
|
|
|
2010-01-22 18:06:13 +03:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning( disable : 4800 )
|
|
|
|
#endif
|
|
|
|
|
2010-11-09 05:48:59 +03:00
|
|
|
#if !defined(OS_POSIX)
|
|
|
|
// This condition must be kept in sync with the one in
|
|
|
|
// ipc_message_utils.h, but this dummy definition of
|
|
|
|
// base::FileDescriptor acts as a static assert that we only get one
|
|
|
|
// def or the other (or neither, in which case code using
|
|
|
|
// FileDescriptor fails to build)
|
2012-01-18 06:01:51 +04:00
|
|
|
namespace base { struct FileDescriptor { }; }
|
2010-11-09 05:48:59 +03:00
|
|
|
#endif
|
2010-05-22 23:35:40 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2011-07-22 04:49:35 +04:00
|
|
|
// This is a cross-platform approximation to HANDLE, which we expect
|
|
|
|
// to be typedef'd to void* or thereabouts.
|
|
|
|
typedef uintptr_t WindowsHandle;
|
|
|
|
|
2010-05-22 23:35:40 +04:00
|
|
|
// XXX there are out of place and might be generally useful. Could
|
|
|
|
// move to nscore.h or something.
|
2010-05-22 23:35:42 +04:00
|
|
|
struct void_t {
|
|
|
|
bool operator==(const void_t&) const { return true; }
|
|
|
|
};
|
|
|
|
struct null_t {
|
|
|
|
bool operator==(const null_t&) const { return true; }
|
|
|
|
};
|
2010-05-22 23:35:40 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
struct SerializedStructuredCloneBuffer
|
|
|
|
{
|
|
|
|
SerializedStructuredCloneBuffer()
|
|
|
|
: data(nullptr), dataLength(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
SerializedStructuredCloneBuffer(const JSAutoStructuredCloneBuffer& aOther)
|
|
|
|
{
|
|
|
|
*this = aOther;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const SerializedStructuredCloneBuffer& aOther) const
|
|
|
|
{
|
|
|
|
return this->data == aOther.data &&
|
|
|
|
this->dataLength == aOther.dataLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
SerializedStructuredCloneBuffer&
|
|
|
|
operator=(const JSAutoStructuredCloneBuffer& aOther)
|
|
|
|
{
|
|
|
|
data = aOther.data();
|
|
|
|
dataLength = aOther.nbytes();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t* data;
|
|
|
|
size_t dataLength;
|
|
|
|
};
|
|
|
|
|
2010-05-22 23:35:40 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-06-29 22:38:29 +04:00
|
|
|
namespace IPC {
|
|
|
|
|
2011-11-24 15:45:55 +04:00
|
|
|
/**
|
|
|
|
* Generic enum serializer.
|
2012-02-05 23:51:06 +04:00
|
|
|
*
|
2014-04-14 18:17:40 +04:00
|
|
|
* Consider using the specializations below, such as ContiguousEnumSerializer.
|
|
|
|
*
|
2012-02-05 23:51:06 +04:00
|
|
|
* This is a generic serializer for any enum type used in IPDL.
|
|
|
|
* Programmers can define ParamTraits<E> for enum type E by deriving
|
2014-04-14 18:17:40 +04:00
|
|
|
* EnumSerializer<E, MyEnumValidator> where MyEnumValidator is a struct
|
|
|
|
* that has to define a static IsLegalValue function returning whether
|
|
|
|
* a given value is a legal value of the enum type at hand.
|
2012-02-05 23:51:06 +04:00
|
|
|
*
|
|
|
|
* \sa https://developer.mozilla.org/en/IPDL/Type_Serialization
|
2011-11-24 15:45:55 +04:00
|
|
|
*/
|
2014-04-14 18:17:40 +04:00
|
|
|
template <typename E, typename EnumValidator>
|
2011-11-24 15:45:55 +04:00
|
|
|
struct EnumSerializer {
|
|
|
|
typedef E paramType;
|
2014-04-14 18:17:40 +04:00
|
|
|
typedef typename mozilla::UnsignedStdintTypeForSize<sizeof(paramType)>::Type
|
|
|
|
uintParamType;
|
2011-11-24 15:45:55 +04:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aValue) {
|
2014-04-14 18:17:40 +04:00
|
|
|
MOZ_ASSERT(EnumValidator::IsLegalValue(aValue));
|
|
|
|
WriteParam(aMsg, uintParamType(aValue));
|
2011-11-24 15:45:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
|
2014-04-14 18:17:40 +04:00
|
|
|
uintParamType value;
|
2011-11-24 15:45:55 +04:00
|
|
|
if(!ReadParam(aMsg, aIter, &value) ||
|
2014-04-14 18:17:40 +04:00
|
|
|
!EnumValidator::IsLegalValue(paramType(value))) {
|
2011-11-24 15:45:55 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*aResult = paramType(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-10 23:06:12 +04:00
|
|
|
template <typename E,
|
2014-04-14 18:17:40 +04:00
|
|
|
E MinLegal,
|
|
|
|
E HighBound>
|
|
|
|
struct ContiguousEnumValidator
|
|
|
|
{
|
|
|
|
static bool IsLegalValue(E e)
|
|
|
|
{
|
|
|
|
return MinLegal <= e && e < HighBound;
|
2014-01-10 23:06:12 +04:00
|
|
|
}
|
2014-04-14 18:17:40 +04:00
|
|
|
};
|
2014-01-10 23:06:12 +04:00
|
|
|
|
2014-04-14 18:17:40 +04:00
|
|
|
template <typename E,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) MinLegal,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) HighBound>
|
|
|
|
class ContiguousTypedEnumValidator
|
|
|
|
{
|
|
|
|
// Silence overzealous -Wtype-limits bug in GCC fixed in GCC 4.8:
|
|
|
|
// "comparison of unsigned expression >= 0 is always true"
|
|
|
|
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
|
|
|
|
template <typename T>
|
|
|
|
static bool IsLessThanOrEqual(T a, T b) { return a <= b; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool IsLegalValue(E e)
|
|
|
|
{
|
|
|
|
typedef MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) ActualEnumType;
|
|
|
|
return IsLessThanOrEqual(MinLegal, ActualEnumType(e)) &&
|
|
|
|
ActualEnumType(e) < HighBound;
|
2014-01-10 23:06:12 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-26 06:34:04 +04:00
|
|
|
template <typename E,
|
|
|
|
E AllBits>
|
|
|
|
struct BitFlagsEnumValidator
|
|
|
|
{
|
|
|
|
static bool IsLegalValue(E e)
|
|
|
|
{
|
|
|
|
return (e & AllBits) == e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename E,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) AllBits>
|
|
|
|
struct BitFlagsTypedEnumValidator
|
|
|
|
{
|
|
|
|
static bool IsLegalValue(E e)
|
|
|
|
{
|
|
|
|
return (e & AllBits) == e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-14 18:17:40 +04:00
|
|
|
/**
|
|
|
|
* Specialization of EnumSerializer for enums with contiguous enum values.
|
|
|
|
*
|
|
|
|
* Provide two values: MinLegal, HighBound. An enum value x will be
|
|
|
|
* considered legal if MinLegal <= x < HighBound.
|
|
|
|
*
|
|
|
|
* For example, following is definition of serializer for enum type FOO.
|
|
|
|
* \code
|
|
|
|
* enum FOO { FOO_FIRST, FOO_SECOND, FOO_LAST, NUM_FOO };
|
|
|
|
*
|
|
|
|
* template <>
|
|
|
|
* struct ParamTraits<FOO>:
|
|
|
|
* public ContiguousEnumSerializer<FOO, FOO_FIRST, NUM_FOO> {};
|
|
|
|
* \endcode
|
|
|
|
* FOO_FIRST, FOO_SECOND, and FOO_LAST are valid value.
|
|
|
|
*/
|
|
|
|
template <typename E,
|
|
|
|
E MinLegal,
|
|
|
|
E HighBound>
|
|
|
|
struct ContiguousEnumSerializer
|
|
|
|
: EnumSerializer<E,
|
|
|
|
ContiguousEnumValidator<E, MinLegal, HighBound>>
|
|
|
|
{};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to ContiguousEnumSerializer, but for MFBT typed enums
|
|
|
|
* as constructed by MOZ_BEGIN_ENUM_CLASS. This can go away when
|
|
|
|
* we drop MOZ_BEGIN_ENUM_CLASS and use C++11 enum classes directly.
|
|
|
|
*/
|
|
|
|
template <typename E,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) MinLegal,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) HighBound>
|
|
|
|
struct ContiguousTypedEnumSerializer
|
|
|
|
: EnumSerializer<E,
|
|
|
|
ContiguousTypedEnumValidator<E, MinLegal, HighBound>>
|
|
|
|
{};
|
|
|
|
|
2014-04-26 06:34:04 +04:00
|
|
|
/**
|
|
|
|
* Specialization of EnumSerializer for enums representing bit flags.
|
|
|
|
*
|
|
|
|
* Provide one value: AllBits. An enum value x will be
|
|
|
|
* considered legal if (x & AllBits) == x;
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* \code
|
|
|
|
* enum FOO {
|
|
|
|
* FOO_FIRST = 1 << 0,
|
|
|
|
* FOO_SECOND = 1 << 1,
|
|
|
|
* FOO_LAST = 1 << 2,
|
|
|
|
* ALL_BITS = (1 << 3) - 1
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* template <>
|
|
|
|
* struct ParamTraits<FOO>:
|
|
|
|
* public BitFlagsEnumSerializer<FOO, FOO::ALL_BITS> {};
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
template <typename E,
|
|
|
|
E AllBits>
|
|
|
|
struct BitFlagsEnumSerializer
|
|
|
|
: EnumSerializer<E,
|
|
|
|
BitFlagsEnumValidator<E, AllBits>>
|
|
|
|
{};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to BitFlagsEnumSerializer, but for MFBT typed enums
|
|
|
|
* as constructed by MOZ_BEGIN_ENUM_CLASS. This can go away when
|
|
|
|
* we drop MOZ_BEGIN_ENUM_CLASS and use C++11 enum classes directly.
|
|
|
|
*/
|
|
|
|
template <typename E,
|
|
|
|
MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(E) AllBits>
|
|
|
|
struct BitFlagsTypedEnumSerializer
|
|
|
|
: EnumSerializer<E,
|
|
|
|
BitFlagsTypedEnumValidator<E, AllBits>>
|
|
|
|
{};
|
|
|
|
|
2013-01-18 00:06:36 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<base::ChildPrivileges>
|
2014-04-14 18:17:40 +04:00
|
|
|
: public ContiguousEnumSerializer<base::ChildPrivileges,
|
|
|
|
base::PRIVILEGES_DEFAULT,
|
|
|
|
base::PRIVILEGES_LAST>
|
2013-01-18 00:06:36 +04:00
|
|
|
{ };
|
|
|
|
|
2010-01-26 01:47:39 +03:00
|
|
|
template<>
|
2012-08-22 19:56:38 +04:00
|
|
|
struct ParamTraits<int8_t>
|
2010-01-26 01:47:39 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef int8_t paramType;
|
2010-01-26 01:47:39 +03:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
const char* outp;
|
|
|
|
if (!aMsg->ReadBytes(aIter, &outp, sizeof(*aResult)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*aResult = *reinterpret_cast<const paramType*>(outp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2012-08-22 19:56:38 +04:00
|
|
|
struct ParamTraits<uint8_t>
|
2010-01-26 01:47:39 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
typedef uint8_t paramType;
|
2010-01-26 01:47:39 +03:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
const char* outp;
|
|
|
|
if (!aMsg->ReadBytes(aIter, &outp, sizeof(*aResult)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*aResult = *reinterpret_cast<const paramType*>(outp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-09 05:48:59 +03:00
|
|
|
#if !defined(OS_POSIX)
|
|
|
|
// See above re: keeping definitions in sync
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<base::FileDescriptor>
|
|
|
|
{
|
|
|
|
typedef base::FileDescriptor paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) {
|
|
|
|
NS_RUNTIMEABORT("FileDescriptor isn't meaningful on this platform");
|
|
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
|
|
|
|
NS_RUNTIMEABORT("FileDescriptor isn't meaningful on this platform");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // !defined(OS_POSIX)
|
|
|
|
|
2009-06-29 22:38:29 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsACString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
2013-08-23 23:51:58 +04:00
|
|
|
// represents a nullptr pointer
|
2009-09-22 06:02:15 +04:00
|
|
|
return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 22:38:29 +04:00
|
|
|
WriteParam(aMsg, length);
|
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length);
|
|
|
|
}
|
|
|
|
|
2009-07-30 01:12:15 +04:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 22:38:29 +04:00
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aResult->SetIsVoid(true);
|
2009-09-22 06:02:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2009-06-29 22:38:29 +04:00
|
|
|
if (ReadParam(aMsg, aIter, &length)) {
|
|
|
|
const char* buf;
|
|
|
|
if (aMsg->ReadBytes(aIter, &buf, length)) {
|
2009-07-30 01:12:15 +04:00
|
|
|
aResult->Assign(buf, length);
|
2009-06-29 22:38:29 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else
|
|
|
|
aLog->append(UTF8ToWide(aParam.BeginReading()));
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsAString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
2013-08-23 23:51:58 +04:00
|
|
|
// represents a nullptr pointer
|
2009-09-22 06:02:15 +04:00
|
|
|
return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 22:38:29 +04:00
|
|
|
WriteParam(aMsg, length);
|
2014-01-04 19:02:17 +04:00
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length * sizeof(char16_t));
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
|
2009-07-30 01:12:15 +04:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 22:38:29 +04:00
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aResult->SetIsVoid(true);
|
2009-09-22 06:02:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2009-06-29 22:38:29 +04:00
|
|
|
if (ReadParam(aMsg, aIter, &length)) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* buf;
|
2009-06-29 22:38:29 +04:00
|
|
|
if (aMsg->ReadBytes(aIter, reinterpret_cast<const char**>(&buf),
|
2014-01-04 19:02:17 +04:00
|
|
|
length * sizeof(char16_t))) {
|
2009-07-30 01:12:15 +04:00
|
|
|
aResult->Assign(buf, length);
|
2009-06-29 22:38:29 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-22 06:02:15 +04:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else {
|
2009-06-29 22:38:29 +04:00
|
|
|
#ifdef WCHAR_T_IS_UTF16
|
2009-09-22 06:02:15 +04:00
|
|
|
aLog->append(reinterpret_cast<const wchar_t*>(aParam.BeginReading()));
|
2009-06-29 22:38:29 +04:00
|
|
|
#else
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aParam.Length();
|
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2009-09-22 06:02:15 +04:00
|
|
|
aLog->push_back(std::wstring::value_type(aParam[index]));
|
|
|
|
}
|
2009-06-29 22:38:29 +04:00
|
|
|
#endif
|
2009-09-22 06:02:15 +04:00
|
|
|
}
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-30 01:12:15 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsCString> : ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsCString paramType;
|
|
|
|
};
|
|
|
|
|
2014-01-09 00:51:38 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsLiteralCString> : ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsLiteralCString paramType;
|
|
|
|
};
|
|
|
|
|
2010-03-23 18:14:36 +03:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
|
|
|
|
template<>
|
2012-09-02 06:35:17 +04:00
|
|
|
struct ParamTraits<nsAutoCString> : ParamTraits<nsCString>
|
2010-03-23 18:14:36 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
typedef nsAutoCString paramType;
|
2010-03-23 18:14:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOZILLA_INTERNAL_API
|
|
|
|
|
2009-07-30 01:12:15 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsString> : ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsString paramType;
|
|
|
|
};
|
|
|
|
|
2014-01-09 00:51:38 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsLiteralString> : ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsLiteralString paramType;
|
|
|
|
};
|
|
|
|
|
2012-12-19 05:16:06 +04:00
|
|
|
template <typename E>
|
|
|
|
struct ParamTraits<FallibleTArray<E> >
|
2009-06-29 22:38:29 +04:00
|
|
|
{
|
2012-12-19 05:16:06 +04:00
|
|
|
typedef FallibleTArray<E> paramType;
|
2009-06-29 22:38:29 +04:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 22:38:29 +04:00
|
|
|
WriteParam(aMsg, length);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2009-06-29 22:38:29 +04:00
|
|
|
WriteParam(aMsg, aParam[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-30 01:12:15 +04:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
2009-06-29 22:38:29 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2009-06-29 22:38:29 +04:00
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-22 00:35:48 +04:00
|
|
|
aResult->SetCapacity(length);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2009-10-20 01:06:13 +04:00
|
|
|
E* element = aResult->AppendElement();
|
|
|
|
if (!(element && ReadParam(aMsg, aIter, element))) {
|
2009-08-06 02:36:33 +04:00
|
|
|
return false;
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < aParam.Length(); index++) {
|
2009-06-29 22:38:29 +04:00
|
|
|
if (index) {
|
|
|
|
aLog->append(L" ");
|
|
|
|
}
|
|
|
|
LogParam(aParam[index], aLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-09 05:49:00 +03:00
|
|
|
template<typename E>
|
2012-12-19 05:16:06 +04:00
|
|
|
struct ParamTraits<InfallibleTArray<E> >
|
2010-11-09 05:49:00 +03:00
|
|
|
{
|
|
|
|
typedef InfallibleTArray<E> paramType;
|
|
|
|
|
2012-12-19 05:16:06 +04:00
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, static_cast<const FallibleTArray<E>&>(aParam));
|
|
|
|
}
|
2010-11-09 05:49:00 +03:00
|
|
|
|
|
|
|
// deserialize the array fallibly, but return an InfallibleTArray
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
2012-12-19 05:16:06 +04:00
|
|
|
FallibleTArray<E> temp;
|
2010-11-09 05:49:00 +03:00
|
|
|
if (!ReadParam(aMsg, aIter, &temp))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aResult->SwapElements(temp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-19 05:16:06 +04:00
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
LogParam(static_cast<const FallibleTArray<E>&>(aParam), aLog);
|
|
|
|
}
|
2010-11-09 05:49:00 +03:00
|
|
|
};
|
|
|
|
|
2009-11-06 23:24:35 +03:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<float>
|
|
|
|
{
|
|
|
|
typedef float paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(paramType));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
const char* outFloat;
|
|
|
|
if (!aMsg->ReadBytes(aIter, &outFloat, sizeof(float)))
|
|
|
|
return false;
|
|
|
|
*aResult = *reinterpret_cast<const float*>(outFloat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"%g", aParam));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-20 17:35:41 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsCSSProperty>
|
2014-04-14 18:17:40 +04:00
|
|
|
: public ContiguousEnumSerializer<nsCSSProperty,
|
|
|
|
eCSSProperty_UNKNOWN,
|
|
|
|
eCSSProperty_COUNT>
|
2012-08-20 17:35:41 +04:00
|
|
|
{};
|
|
|
|
|
2010-05-22 23:35:40 +04:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::void_t>
|
|
|
|
{
|
|
|
|
typedef mozilla::void_t paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) { }
|
|
|
|
static bool
|
|
|
|
Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
*aResult = paramType();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::null_t>
|
|
|
|
{
|
|
|
|
typedef mozilla::null_t paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) { }
|
|
|
|
static bool
|
|
|
|
Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
*aResult = paramType();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-24 18:19:56 +04:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<nsID>
|
|
|
|
{
|
|
|
|
typedef nsID paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.m0);
|
|
|
|
WriteParam(aMsg, aParam.m1);
|
|
|
|
WriteParam(aMsg, aParam.m2);
|
2011-10-11 09:50:08 +04:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++) {
|
2011-06-24 18:19:56 +04:00
|
|
|
WriteParam(aMsg, aParam.m3[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
if(!ReadParam(aMsg, aIter, &(aResult->m0)) ||
|
|
|
|
!ReadParam(aMsg, aIter, &(aResult->m1)) ||
|
|
|
|
!ReadParam(aMsg, aIter, &(aResult->m2)))
|
|
|
|
return false;
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aResult->m3); i++)
|
2011-06-24 18:19:56 +04:00
|
|
|
if (!ReadParam(aMsg, aIter, &(aResult->m3[i])))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(L"{");
|
|
|
|
aLog->append(StringPrintf(L"%8.8X-%4.4X-%4.4X-",
|
|
|
|
aParam.m0,
|
|
|
|
aParam.m1,
|
|
|
|
aParam.m2));
|
2011-10-11 09:50:08 +04:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++)
|
2011-06-24 18:19:56 +04:00
|
|
|
aLog->append(StringPrintf(L"%2.2X", aParam.m3[i]));
|
|
|
|
aLog->append(L"}");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-31 21:28:20 +04:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::TimeDuration>
|
|
|
|
{
|
|
|
|
typedef mozilla::TimeDuration paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.mValue);
|
|
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->mValue);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::TimeStamp>
|
|
|
|
{
|
|
|
|
typedef mozilla::TimeStamp paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.mValue);
|
|
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->mValue);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-02-12 01:56:58 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::TimeStampValue>
|
|
|
|
{
|
|
|
|
typedef mozilla::TimeStampValue paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.mGTC);
|
|
|
|
WriteParam(aMsg, aParam.mQPC);
|
|
|
|
WriteParam(aMsg, aParam.mHasQPC);
|
|
|
|
WriteParam(aMsg, aParam.mIsNull);
|
|
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
return (ReadParam(aMsg, aIter, &aResult->mGTC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mQPC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mHasQPC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mIsNull));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::SerializedStructuredCloneBuffer>
|
|
|
|
{
|
|
|
|
typedef mozilla::SerializedStructuredCloneBuffer paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.dataLength);
|
|
|
|
if (aParam.dataLength) {
|
|
|
|
// Structured clone data must be 64-bit aligned.
|
|
|
|
aMsg->WriteBytes(aParam.data, aParam.dataLength, sizeof(uint64_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
if (!ReadParam(aMsg, aIter, &aResult->dataLength)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult->dataLength) {
|
|
|
|
const char** buffer =
|
|
|
|
const_cast<const char**>(reinterpret_cast<char**>(&aResult->data));
|
|
|
|
// Structured clone data must be 64-bit aligned.
|
|
|
|
if (!aMsg->ReadBytes(aIter, buffer, aResult->dataLength,
|
|
|
|
sizeof(uint64_t))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-23 23:51:58 +04:00
|
|
|
aResult->data = nullptr;
|
2012-08-02 10:02:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
LogParam(aParam.dataLength, aLog);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-29 22:38:29 +04:00
|
|
|
} /* namespace IPC */
|
|
|
|
|
|
|
|
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
|