2009-09-22 02:02:15 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2016-05-27 21:54:31 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 18:38:29 +00:00
|
|
|
|
|
|
|
#ifndef __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
#define __IPC_GLUE_IPCMESSAGEUTILS_H__
|
|
|
|
|
2013-01-17 20:06:36 +00:00
|
|
|
#include "base/process_util.h"
|
2009-06-29 18:38:29 +00:00
|
|
|
#include "chrome/common/ipc_message_utils.h"
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2016-01-28 07:43:46 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-11-04 13:57:25 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-09-10 20:50:58 +00:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
2015-05-26 19:40:24 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-10-26 15:31:00 +00:00
|
|
|
#include "mozilla/net/WebSocketFrame.h"
|
2012-07-31 17:28:20 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-02-11 21:56:58 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/TimeStamp_windows.h"
|
|
|
|
#endif
|
2014-11-04 13:57:25 +00:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2014-04-14 14:17:40 +00:00
|
|
|
#include "mozilla/IntegerTypeTraits.h"
|
2013-07-30 14:25:31 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2016-03-30 04:32:26 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
2011-06-24 14:19:56 +00:00
|
|
|
#include "nsID.h"
|
2015-04-14 15:36:36 +00:00
|
|
|
#include "nsIWidget.h"
|
2011-06-24 14:19:56 +00:00
|
|
|
#include "nsMemory.h"
|
2013-09-23 17:25:00 +00:00
|
|
|
#include "nsString.h"
|
2009-06-29 18:38:29 +00:00
|
|
|
#include "nsTArray.h"
|
2013-08-20 06:43:47 +00:00
|
|
|
#include "js/StructuredClone.h"
|
2016-08-09 23:28:19 +00:00
|
|
|
#include "nsCSSPropertyID.h"
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2010-01-22 15:06:13 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning( disable : 4800 )
|
|
|
|
#endif
|
|
|
|
|
2010-11-09 02:48:59 +00: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 02:01:51 +00:00
|
|
|
namespace base { struct FileDescriptor { }; }
|
2010-11-09 02:48:59 +00:00
|
|
|
#endif
|
2010-05-22 19:35:40 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2011-07-22 00:49:35 +00: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 19:35:40 +00:00
|
|
|
// XXX there are out of place and might be generally useful. Could
|
|
|
|
// move to nscore.h or something.
|
2010-05-22 19:35:42 +00: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 19:35:40 +00:00
|
|
|
|
2016-04-22 10:04:20 +00:00
|
|
|
struct SerializedStructuredCloneBuffer final
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
SerializedStructuredCloneBuffer&
|
|
|
|
operator=(const SerializedStructuredCloneBuffer& aOther)
|
|
|
|
{
|
|
|
|
data.Clear();
|
|
|
|
auto iter = aOther.data.Iter();
|
|
|
|
while (!iter.Done()) {
|
|
|
|
data.WriteBytes(iter.Data(), iter.RemainingInSegment());
|
|
|
|
iter.Advance(aOther.data, iter.RemainingInSegment());
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const SerializedStructuredCloneBuffer& aOther) const
|
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
// The copy assignment operator and the equality operator are
|
|
|
|
// needed by the IPDL generated code. We relied on the copy
|
|
|
|
// assignment operator at some places but we never use the
|
|
|
|
// equality operator.
|
|
|
|
return false;
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 10:04:20 +00:00
|
|
|
JSStructuredCloneData data;
|
2012-08-02 06:02:29 +00:00
|
|
|
};
|
|
|
|
|
2010-05-22 19:35:40 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
namespace IPC {
|
|
|
|
|
2015-08-06 21:36:54 +00:00
|
|
|
/**
|
|
|
|
* Maximum size, in bytes, of a single IPC message.
|
|
|
|
*/
|
|
|
|
static const uint32_t MAX_MESSAGE_SIZE = 65536;
|
|
|
|
|
2011-11-24 11:45:55 +00:00
|
|
|
/**
|
|
|
|
* Generic enum serializer.
|
2012-02-05 19:51:06 +00:00
|
|
|
*
|
2014-04-14 14:17:40 +00:00
|
|
|
* Consider using the specializations below, such as ContiguousEnumSerializer.
|
|
|
|
*
|
2012-02-05 19:51:06 +00: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 14:17:40 +00: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 19:51:06 +00:00
|
|
|
*
|
|
|
|
* \sa https://developer.mozilla.org/en/IPDL/Type_Serialization
|
2011-11-24 11:45:55 +00:00
|
|
|
*/
|
2014-04-14 14:17:40 +00:00
|
|
|
template <typename E, typename EnumValidator>
|
2011-11-24 11:45:55 +00:00
|
|
|
struct EnumSerializer {
|
|
|
|
typedef E paramType;
|
2014-04-14 14:17:40 +00:00
|
|
|
typedef typename mozilla::UnsignedStdintTypeForSize<sizeof(paramType)>::Type
|
|
|
|
uintParamType;
|
2011-11-24 11:45:55 +00:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aValue) {
|
2014-04-14 14:17:40 +00:00
|
|
|
MOZ_ASSERT(EnumValidator::IsLegalValue(aValue));
|
|
|
|
WriteParam(aMsg, uintParamType(aValue));
|
2011-11-24 11:45:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
|
2014-04-14 14:17:40 +00:00
|
|
|
uintParamType value;
|
2016-03-30 04:32:26 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &value)) {
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCReadErrorReason"),
|
|
|
|
NS_LITERAL_CSTRING("Bad iter"));
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
} else if (!EnumValidator::IsLegalValue(paramType(value))) {
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCReadErrorReason"),
|
|
|
|
NS_LITERAL_CSTRING("Illegal value"));
|
|
|
|
#endif
|
2011-11-24 11:45:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*aResult = paramType(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-10 19:06:12 +00:00
|
|
|
template <typename E,
|
2014-04-14 14:17:40 +00:00
|
|
|
E MinLegal,
|
|
|
|
E HighBound>
|
2015-01-25 22:22:08 +00:00
|
|
|
class ContiguousEnumValidator
|
2014-04-14 14:17:40 +00:00
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2015-01-25 22:22:08 +00:00
|
|
|
return IsLessThanOrEqual(MinLegal, e) && e < HighBound;
|
2014-01-10 19:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-26 02:34:04 +00:00
|
|
|
template <typename E,
|
|
|
|
E AllBits>
|
|
|
|
struct BitFlagsEnumValidator
|
|
|
|
{
|
|
|
|
static bool IsLegalValue(E e)
|
|
|
|
{
|
|
|
|
return (e & AllBits) == e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-14 14:17:40 +00: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>>
|
|
|
|
{};
|
|
|
|
|
2014-04-26 02:34:04 +00: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>>
|
|
|
|
{};
|
|
|
|
|
2013-01-17 20:06:36 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<base::ChildPrivileges>
|
2014-04-14 14:17:40 +00:00
|
|
|
: public ContiguousEnumSerializer<base::ChildPrivileges,
|
|
|
|
base::PRIVILEGES_DEFAULT,
|
|
|
|
base::PRIVILEGES_LAST>
|
2013-01-17 20:06:36 +00:00
|
|
|
{ };
|
|
|
|
|
2010-01-25 22:47:39 +00:00
|
|
|
template<>
|
2012-08-22 15:56:38 +00:00
|
|
|
struct ParamTraits<int8_t>
|
2010-01-25 22:47:39 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
typedef int8_t paramType;
|
2010-01-25 22:47:39 +00:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(aParam));
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2010-01-25 22:47:39 +00:00
|
|
|
{
|
2016-05-16 21:32:37 +00:00
|
|
|
return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult));
|
2010-01-25 22:47:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2012-08-22 15:56:38 +00:00
|
|
|
struct ParamTraits<uint8_t>
|
2010-01-25 22:47:39 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
typedef uint8_t paramType;
|
2010-01-25 22:47:39 +00:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(aParam));
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2010-01-25 22:47:39 +00:00
|
|
|
{
|
2016-05-16 21:32:37 +00:00
|
|
|
return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult));
|
2010-01-25 22:47:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-09 02:48:59 +00: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");
|
|
|
|
}
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
|
2010-11-09 02:48:59 +00:00
|
|
|
NS_RUNTIMEABORT("FileDescriptor isn't meaningful on this platform");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // !defined(OS_POSIX)
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsACString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
2013-08-23 19:51:58 +00:00
|
|
|
// represents a nullptr pointer
|
2009-09-22 02:02:15 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 18:38:29 +00:00
|
|
|
WriteParam(aMsg, length);
|
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length);
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2009-06-29 18:38:29 +00:00
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aResult->SetIsVoid(true);
|
2009-09-22 02:02:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length;
|
2016-05-16 21:32:37 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
2016-05-16 21:32:37 +00:00
|
|
|
aResult->SetLength(length);
|
|
|
|
|
|
|
|
return aMsg->ReadBytesInto(aIter, aResult->BeginWriting(), length);
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else
|
|
|
|
aLog->append(UTF8ToWide(aParam.BeginReading()));
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsAString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
bool isVoid = aParam.IsVoid();
|
|
|
|
aMsg->WriteBool(isVoid);
|
|
|
|
|
|
|
|
if (isVoid)
|
2013-08-23 19:51:58 +00:00
|
|
|
// represents a nullptr pointer
|
2009-09-22 02:02:15 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 18:38:29 +00:00
|
|
|
WriteParam(aMsg, length);
|
2014-01-04 15:02:17 +00:00
|
|
|
aMsg->WriteBytes(aParam.BeginReading(), length * sizeof(char16_t));
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2009-06-29 18:38:29 +00:00
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
bool isVoid;
|
|
|
|
if (!aMsg->ReadBool(aIter, &isVoid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isVoid) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aResult->SetIsVoid(true);
|
2009-09-22 02:02:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length;
|
2016-05-16 21:32:37 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
2016-05-16 21:32:37 +00:00
|
|
|
aResult->SetLength(length);
|
|
|
|
|
|
|
|
return aMsg->ReadBytesInto(aIter, aResult->BeginWriting(), length * sizeof(char16_t));
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2009-09-22 02:02:15 +00:00
|
|
|
if (aParam.IsVoid())
|
|
|
|
aLog->append(L"(NULL)");
|
|
|
|
else {
|
2009-06-29 18:38:29 +00:00
|
|
|
#ifdef WCHAR_T_IS_UTF16
|
2009-09-22 02:02:15 +00:00
|
|
|
aLog->append(reinterpret_cast<const wchar_t*>(aParam.BeginReading()));
|
2009-06-29 18:38:29 +00:00
|
|
|
#else
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = aParam.Length();
|
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2009-09-22 02:02:15 +00:00
|
|
|
aLog->push_back(std::wstring::value_type(aParam[index]));
|
|
|
|
}
|
2009-06-29 18:38:29 +00:00
|
|
|
#endif
|
2009-09-22 02:02:15 +00:00
|
|
|
}
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-29 21:12:15 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsCString> : ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsCString paramType;
|
|
|
|
};
|
|
|
|
|
2014-01-08 20:51:38 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsLiteralCString> : ParamTraits<nsACString>
|
|
|
|
{
|
|
|
|
typedef nsLiteralCString paramType;
|
|
|
|
};
|
|
|
|
|
2010-03-23 15:14:36 +00:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
|
|
|
|
template<>
|
2012-09-02 02:35:17 +00:00
|
|
|
struct ParamTraits<nsAutoCString> : ParamTraits<nsCString>
|
2010-03-23 15:14:36 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
typedef nsAutoCString paramType;
|
2010-03-23 15:14:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOZILLA_INTERNAL_API
|
|
|
|
|
2009-07-29 21:12:15 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsString> : ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsString paramType;
|
|
|
|
};
|
|
|
|
|
2014-01-08 20:51:38 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsLiteralString> : ParamTraits<nsAString>
|
|
|
|
{
|
|
|
|
typedef nsLiteralString paramType;
|
|
|
|
};
|
|
|
|
|
2016-04-28 17:00:46 +00:00
|
|
|
// Pickle::ReadBytes and ::WriteBytes take the length in ints, so we must
|
|
|
|
// ensure there is no overflow. This returns |false| if it would overflow.
|
|
|
|
// Otherwise, it returns |true| and places the byte length in |aByteLength|.
|
|
|
|
bool ByteLengthIsValid(uint32_t aNumElements, size_t aElementSize, int* aByteLength);
|
|
|
|
|
2016-05-03 16:29:39 +00:00
|
|
|
// Note: IPDL will sometimes codegen specialized implementations of
|
|
|
|
// nsTArray serialization and deserialization code in
|
|
|
|
// implementSpecialArrayPickling(). This is needed when ParamTraits<E>
|
|
|
|
// is not defined.
|
2012-12-19 01:16:06 +00:00
|
|
|
template <typename E>
|
2016-05-03 16:29:39 +00:00
|
|
|
struct ParamTraits<nsTArray<E>>
|
2009-06-29 18:38:29 +00:00
|
|
|
{
|
2016-05-03 16:29:39 +00:00
|
|
|
typedef nsTArray<E> paramType;
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2014-11-04 13:57:25 +00:00
|
|
|
// We write arrays of integer or floating-point data using a single pickling
|
|
|
|
// call, rather than writing each element individually. We deliberately do
|
|
|
|
// not use mozilla::IsPod here because it is perfectly reasonable to have
|
|
|
|
// a data structure T for which IsPod<T>::value is true, yet also have a
|
|
|
|
// ParamTraits<T> specialization.
|
|
|
|
static const bool sUseWriteBytes = (mozilla::IsIntegral<E>::value ||
|
|
|
|
mozilla::IsFloatingPoint<E>::value);
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = aParam.Length();
|
2009-06-29 18:38:29 +00:00
|
|
|
WriteParam(aMsg, length);
|
2014-11-04 13:57:25 +00:00
|
|
|
|
|
|
|
if (sUseWriteBytes) {
|
|
|
|
int pickledLength = 0;
|
2016-04-28 17:00:46 +00:00
|
|
|
MOZ_RELEASE_ASSERT(ByteLengthIsValid(length, sizeof(E), &pickledLength));
|
2014-11-04 13:57:25 +00:00
|
|
|
aMsg->WriteBytes(aParam.Elements(), pickledLength);
|
|
|
|
} else {
|
2016-09-02 20:14:28 +00:00
|
|
|
const E* elems = aParam.Elements();
|
2014-11-04 13:57:25 +00:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2016-09-02 20:14:28 +00:00
|
|
|
WriteParam(aMsg, elems[index]);
|
2014-11-04 13:57:25 +00:00
|
|
|
}
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 16:29:39 +00:00
|
|
|
// This method uses infallible allocation so that an OOM failure will
|
|
|
|
// show up as an OOM crash rather than an IPC FatalError.
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2009-06-29 18:38:29 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length;
|
2009-06-29 18:38:29 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-04 13:57:25 +00:00
|
|
|
if (sUseWriteBytes) {
|
|
|
|
int pickledLength = 0;
|
2016-04-28 17:00:46 +00:00
|
|
|
if (!ByteLengthIsValid(length, sizeof(E), &pickledLength)) {
|
2009-08-05 22:36:33 +00:00
|
|
|
return false;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
2014-11-04 13:57:25 +00:00
|
|
|
|
2016-05-03 16:29:39 +00:00
|
|
|
E* elements = aResult->AppendElements(length);
|
2016-05-16 21:32:37 +00:00
|
|
|
return aMsg->ReadBytesInto(aIter, elements, pickledLength);
|
2014-11-04 13:57:25 +00:00
|
|
|
} else {
|
2016-05-03 16:29:39 +00:00
|
|
|
aResult->SetCapacity(length);
|
2014-11-04 13:57:25 +00:00
|
|
|
|
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2016-05-03 16:29:39 +00:00
|
|
|
E* element = aResult->AppendElement();
|
2014-11-04 13:57:25 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 21:32:37 +00:00
|
|
|
return true;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t index = 0; index < aParam.Length(); index++) {
|
2009-06-29 18:38:29 +00:00
|
|
|
if (index) {
|
|
|
|
aLog->append(L" ");
|
|
|
|
}
|
|
|
|
LogParam(aParam[index], aLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-09 02:49:00 +00:00
|
|
|
template<typename E>
|
2016-05-03 16:29:39 +00:00
|
|
|
struct ParamTraits<FallibleTArray<E>>
|
2010-11-09 02:49:00 +00:00
|
|
|
{
|
2016-05-03 16:29:39 +00:00
|
|
|
typedef FallibleTArray<E> paramType;
|
2010-11-09 02:49:00 +00:00
|
|
|
|
2012-12-19 01:16:06 +00:00
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2016-05-03 16:29:39 +00:00
|
|
|
WriteParam(aMsg, static_cast<const nsTArray<E>&>(aParam));
|
2012-12-19 01:16:06 +00:00
|
|
|
}
|
2010-11-09 02:49:00 +00:00
|
|
|
|
2016-05-03 16:29:39 +00:00
|
|
|
// Deserialize the array infallibly, but return a FallibleTArray.
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2010-11-09 02:49:00 +00:00
|
|
|
{
|
2016-05-03 16:29:39 +00:00
|
|
|
nsTArray<E> temp;
|
2010-11-09 02:49:00 +00:00
|
|
|
if (!ReadParam(aMsg, aIter, &temp))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aResult->SwapElements(temp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-19 01:16:06 +00:00
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2016-05-03 16:29:39 +00:00
|
|
|
LogParam(static_cast<const nsTArray<E>&>(aParam), aLog);
|
2012-12-19 01:16:06 +00:00
|
|
|
}
|
2010-11-09 02:49:00 +00:00
|
|
|
};
|
|
|
|
|
2015-01-31 07:17:12 +00:00
|
|
|
template<typename E, size_t N>
|
2016-02-02 15:36:30 +00:00
|
|
|
struct ParamTraits<AutoTArray<E, N>> : ParamTraits<nsTArray<E>>
|
2015-01-31 07:17:12 +00:00
|
|
|
{
|
2016-02-02 15:36:30 +00:00
|
|
|
typedef AutoTArray<E, N> paramType;
|
2015-01-31 07:17:12 +00:00
|
|
|
};
|
|
|
|
|
2009-11-06 20:24:35 +00:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<float>
|
|
|
|
{
|
|
|
|
typedef float paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteBytes(&aParam, sizeof(paramType));
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2009-11-06 20:24:35 +00:00
|
|
|
{
|
2016-05-16 21:32:37 +00:00
|
|
|
return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult));
|
2009-11-06 20:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"%g", aParam));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-20 13:35:41 +00:00
|
|
|
template <>
|
2016-08-09 23:28:19 +00:00
|
|
|
struct ParamTraits<nsCSSPropertyID>
|
|
|
|
: public ContiguousEnumSerializer<nsCSSPropertyID,
|
2014-04-14 14:17:40 +00:00
|
|
|
eCSSProperty_UNKNOWN,
|
|
|
|
eCSSProperty_COUNT>
|
2012-08-20 13:35:41 +00:00
|
|
|
{};
|
|
|
|
|
2010-05-22 19:35:40 +00:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::void_t>
|
|
|
|
{
|
|
|
|
typedef mozilla::void_t paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) { }
|
|
|
|
static bool
|
2016-04-21 04:09:15 +00:00
|
|
|
Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2010-05-22 19:35:40 +00:00
|
|
|
{
|
|
|
|
*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
|
2016-04-21 04:09:15 +00:00
|
|
|
Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2010-05-22 19:35:40 +00:00
|
|
|
{
|
|
|
|
*aResult = paramType();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-24 14:19:56 +00: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 05:50:08 +00:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++) {
|
2011-06-24 14:19:56 +00:00
|
|
|
WriteParam(aMsg, aParam.m3[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2011-06-24 14:19:56 +00:00
|
|
|
{
|
|
|
|
if(!ReadParam(aMsg, aIter, &(aResult->m0)) ||
|
|
|
|
!ReadParam(aMsg, aIter, &(aResult->m1)) ||
|
|
|
|
!ReadParam(aMsg, aIter, &(aResult->m2)))
|
|
|
|
return false;
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aResult->m3); i++)
|
2011-06-24 14:19:56 +00: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 05:50:08 +00:00
|
|
|
for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++)
|
2011-06-24 14:19:56 +00:00
|
|
|
aLog->append(StringPrintf(L"%2.2X", aParam.m3[i]));
|
|
|
|
aLog->append(L"}");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-31 17:28:20 +00:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::TimeDuration>
|
|
|
|
{
|
|
|
|
typedef mozilla::TimeDuration paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.mValue);
|
|
|
|
}
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2012-07-31 17:28:20 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2012-07-31 17:28:20 +00:00
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->mValue);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-02-11 21:56:58 +00: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);
|
|
|
|
}
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2013-02-11 21:56:58 +00:00
|
|
|
{
|
|
|
|
return (ReadParam(aMsg, aIter, &aResult->mGTC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mQPC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mHasQPC) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->mIsNull));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-09-09 07:10:32 +00:00
|
|
|
template <>
|
2015-09-10 20:50:58 +00:00
|
|
|
struct ParamTraits<mozilla::dom::ipc::StructuredCloneData>
|
2015-09-09 07:10:32 +00:00
|
|
|
{
|
2015-09-10 20:50:58 +00:00
|
|
|
typedef mozilla::dom::ipc::StructuredCloneData paramType;
|
2015-09-09 07:10:32 +00:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aParam.WriteIPCParams(aMsg);
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2015-09-09 07:10:32 +00:00
|
|
|
{
|
|
|
|
return aResult->ReadIPCParams(aMsg, aIter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
LogParam(aParam.DataLength(), aLog);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-26 15:31:00 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::net::WebSocketFrameData>
|
|
|
|
{
|
|
|
|
typedef mozilla::net::WebSocketFrameData paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aParam.WriteIPCParams(aMsg);
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2015-10-26 15:31:00 +00:00
|
|
|
{
|
|
|
|
return aResult->ReadIPCParams(aMsg, aIter);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-02 06:02:29 +00:00
|
|
|
template <>
|
2016-04-22 10:04:20 +00:00
|
|
|
struct ParamTraits<JSStructuredCloneData>
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
typedef JSStructuredCloneData paramType;
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
MOZ_ASSERT(!(aParam.Size() % sizeof(uint64_t)));
|
|
|
|
WriteParam(aMsg, aParam.Size());
|
|
|
|
auto iter = aParam.Iter();
|
|
|
|
while (!iter.Done()) {
|
|
|
|
aMsg->WriteBytes(iter.Data(), iter.RemainingInSegment(), sizeof(uint64_t));
|
|
|
|
iter.Advance(aParam, iter.RemainingInSegment());
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
size_t length = 0;
|
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
2012-08-02 06:02:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-22 10:04:20 +00:00
|
|
|
MOZ_ASSERT(!(length % sizeof(uint64_t)));
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2016-04-22 10:04:20 +00:00
|
|
|
mozilla::BufferList<InfallibleAllocPolicy> buffers(0, 0, 4096);
|
|
|
|
|
|
|
|
// Borrowing is not suitable to use for IPC to hand out data
|
|
|
|
// because we often want to store the data somewhere for
|
|
|
|
// processing after IPC has released the underlying buffers. One
|
|
|
|
// case is PContentChild::SendGetXPCOMProcessAttributes. We can't
|
|
|
|
// return a borrowed buffer because the out param outlives the
|
|
|
|
// IPDL callback.
|
|
|
|
if (length && !aMsg->ExtractBuffers(aIter, length, &buffers, sizeof(uint64_t))) {
|
|
|
|
return false;
|
2016-05-16 21:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 10:04:20 +00:00
|
|
|
bool success;
|
|
|
|
mozilla::BufferList<js::SystemAllocPolicy> out =
|
|
|
|
buffers.MoveFallible<js::SystemAllocPolicy>(&success);
|
|
|
|
if (!success) {
|
2016-05-16 21:32:37 +00:00
|
|
|
return false;
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-22 10:04:20 +00:00
|
|
|
*aResult = JSStructuredCloneData(Move(out));
|
|
|
|
|
2012-08-02 06:02:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-22 10:04:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::SerializedStructuredCloneBuffer>
|
|
|
|
{
|
|
|
|
typedef mozilla::SerializedStructuredCloneBuffer paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->data);
|
|
|
|
}
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
2016-04-22 10:04:20 +00:00
|
|
|
LogParam(aParam.data.Size(), aLog);
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-14 15:36:36 +00:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<nsIWidget::TouchPointerState>
|
|
|
|
: public BitFlagsEnumSerializer<nsIWidget::TouchPointerState,
|
|
|
|
nsIWidget::TouchPointerState::ALL_BITS>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2015-05-26 19:40:24 +00:00
|
|
|
template<class T>
|
2016-05-03 16:29:39 +00:00
|
|
|
struct ParamTraits<mozilla::Maybe<T>>
|
2015-05-26 19:40:24 +00:00
|
|
|
{
|
|
|
|
typedef mozilla::Maybe<T> paramType;
|
|
|
|
|
|
|
|
static void Write(Message* msg, const paramType& param)
|
|
|
|
{
|
|
|
|
if (param.isSome()) {
|
|
|
|
WriteParam(msg, true);
|
|
|
|
WriteParam(msg, param.value());
|
|
|
|
} else {
|
|
|
|
WriteParam(msg, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
static bool Read(const Message* msg, PickleIterator* iter, paramType* result)
|
2015-05-26 19:40:24 +00:00
|
|
|
{
|
|
|
|
bool isSome;
|
|
|
|
if (!ReadParam(msg, iter, &isSome)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isSome) {
|
|
|
|
T tmp;
|
|
|
|
if (!ReadParam(msg, iter, &tmp)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*result = mozilla::Some(mozilla::Move(tmp));
|
|
|
|
} else {
|
|
|
|
*result = mozilla::Nothing();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
} /* namespace IPC */
|
|
|
|
|
|
|
|
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
|