/src/mozilla-central/ipc/glue/IPCMessageUtils.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef __IPC_GLUE_IPCMESSAGEUTILS_H__ |
8 | | #define __IPC_GLUE_IPCMESSAGEUTILS_H__ |
9 | | |
10 | | #include "base/process_util.h" |
11 | | #include "chrome/common/ipc_message_utils.h" |
12 | | |
13 | | #include "mozilla/ArrayUtils.h" |
14 | | #include "mozilla/Attributes.h" |
15 | | #include "mozilla/DebugOnly.h" |
16 | | #include "mozilla/dom/ipc/StructuredCloneData.h" |
17 | | #include "mozilla/EnumSet.h" |
18 | | #include "mozilla/EnumTypeTraits.h" |
19 | | #include "mozilla/Maybe.h" |
20 | | #include "mozilla/net/WebSocketFrame.h" |
21 | | #include "mozilla/TimeStamp.h" |
22 | | #ifdef XP_WIN |
23 | | #include "mozilla/TimeStamp_windows.h" |
24 | | #endif |
25 | | #include "mozilla/TypeTraits.h" |
26 | | #include "mozilla/IntegerTypeTraits.h" |
27 | | |
28 | | #include <limits> |
29 | | #include <stdint.h> |
30 | | #include <type_traits> |
31 | | |
32 | | #include "nsExceptionHandler.h" |
33 | | #include "nsID.h" |
34 | | #include "nsIWidget.h" |
35 | | #include "nsMemory.h" |
36 | | #include "nsString.h" |
37 | | #include "nsTArray.h" |
38 | | #include "js/StructuredClone.h" |
39 | | #include "nsCSSPropertyID.h" |
40 | | |
41 | | #ifdef _MSC_VER |
42 | | #pragma warning( disable : 4800 ) |
43 | | #endif |
44 | | |
45 | | #if !defined(OS_POSIX) |
46 | | // This condition must be kept in sync with the one in |
47 | | // ipc_message_utils.h, but this dummy definition of |
48 | | // base::FileDescriptor acts as a static assert that we only get one |
49 | | // def or the other (or neither, in which case code using |
50 | | // FileDescriptor fails to build) |
51 | | namespace base { struct FileDescriptor { }; } |
52 | | #endif |
53 | | |
54 | | namespace mozilla { |
55 | | |
56 | | // This is a cross-platform approximation to HANDLE, which we expect |
57 | | // to be typedef'd to void* or thereabouts. |
58 | | typedef uintptr_t WindowsHandle; |
59 | | |
60 | | // XXX there are out of place and might be generally useful. Could |
61 | | // move to nscore.h or something. |
62 | | struct void_t { |
63 | 0 | bool operator==(const void_t&) const { return true; } |
64 | | }; |
65 | | struct null_t { |
66 | 0 | bool operator==(const null_t&) const { return true; } |
67 | | }; |
68 | | |
69 | | struct SerializedStructuredCloneBuffer final |
70 | | { |
71 | | SerializedStructuredCloneBuffer() |
72 | | : data(JS::StructuredCloneScope::Unassigned) |
73 | 0 | { |
74 | 0 | } |
75 | | |
76 | | SerializedStructuredCloneBuffer(const SerializedStructuredCloneBuffer& aOther) |
77 | | : SerializedStructuredCloneBuffer() |
78 | 0 | { |
79 | 0 | *this = aOther; |
80 | 0 | } |
81 | | |
82 | | SerializedStructuredCloneBuffer& |
83 | | operator=(const SerializedStructuredCloneBuffer& aOther) |
84 | 0 | { |
85 | 0 | data.Clear(); |
86 | 0 | data.initScope(aOther.data.scope()); |
87 | 0 | data.Append(aOther.data); |
88 | 0 | return *this; |
89 | 0 | } |
90 | | |
91 | | bool |
92 | | operator==(const SerializedStructuredCloneBuffer& aOther) const |
93 | 0 | { |
94 | 0 | // The copy assignment operator and the equality operator are |
95 | 0 | // needed by the IPDL generated code. We relied on the copy |
96 | 0 | // assignment operator at some places but we never use the |
97 | 0 | // equality operator. |
98 | 0 | return false; |
99 | 0 | } |
100 | | |
101 | | JSStructuredCloneData data; |
102 | | }; |
103 | | |
104 | | } // namespace mozilla |
105 | | |
106 | | namespace IPC { |
107 | | |
108 | | /** |
109 | | * Maximum size, in bytes, of a single IPC message. |
110 | | */ |
111 | | static const uint32_t MAX_MESSAGE_SIZE = 65536; |
112 | | |
113 | | /** |
114 | | * Generic enum serializer. |
115 | | * |
116 | | * Consider using the specializations below, such as ContiguousEnumSerializer. |
117 | | * |
118 | | * This is a generic serializer for any enum type used in IPDL. |
119 | | * Programmers can define ParamTraits<E> for enum type E by deriving |
120 | | * EnumSerializer<E, MyEnumValidator> where MyEnumValidator is a struct |
121 | | * that has to define a static IsLegalValue function returning whether |
122 | | * a given value is a legal value of the enum type at hand. |
123 | | * |
124 | | * \sa https://developer.mozilla.org/en/IPDL/Type_Serialization |
125 | | */ |
126 | | template <typename E, typename EnumValidator> |
127 | | struct EnumSerializer { |
128 | | typedef E paramType; |
129 | | typedef typename mozilla::UnsignedStdintTypeForSize<sizeof(paramType)>::Type |
130 | | uintParamType; |
131 | | |
132 | 0 | static void Write(Message* aMsg, const paramType& aValue) { |
133 | 0 | MOZ_RELEASE_ASSERT(EnumValidator::IsLegalValue(aValue)); |
134 | 0 | WriteParam(aMsg, uintParamType(aValue)); |
135 | 0 | } Unexecuted instantiation: IPC::EnumSerializer<mozilla::layers::LayersBackend, IPC::ContiguousEnumValidator<mozilla::layers::LayersBackend, (mozilla::layers::LayersBackend)0, (mozilla::layers::LayersBackend)6> >::Write(IPC::Message*, mozilla::layers::LayersBackend const&) Unexecuted instantiation: IPC::EnumSerializer<GeckoProcessType, IPC::ContiguousEnumValidator<GeckoProcessType, (GeckoProcessType)0, (GeckoProcessType)8> >::Write(IPC::Message*, GeckoProcessType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadCapabilityFlags, IPC::BitFlagsEnumValidator<mozilla::dom::GamepadCapabilityFlags, (mozilla::dom::GamepadCapabilityFlags)31> >::Write(IPC::Message*, mozilla::dom::GamepadCapabilityFlags const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::HeadersGuardEnum, IPC::ContiguousEnumValidator<mozilla::dom::HeadersGuardEnum, (mozilla::dom::HeadersGuardEnum)0, (mozilla::dom::HeadersGuardEnum)5> >::Write(IPC::Message*, mozilla::dom::HeadersGuardEnum const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ReferrerPolicy, IPC::ContiguousEnumValidator<mozilla::dom::ReferrerPolicy, (mozilla::dom::ReferrerPolicy)0, (mozilla::dom::ReferrerPolicy)9> >::Write(IPC::Message*, mozilla::dom::ReferrerPolicy const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestMode, IPC::ContiguousEnumValidator<mozilla::dom::RequestMode, (mozilla::dom::RequestMode)0, (mozilla::dom::RequestMode)4> >::Write(IPC::Message*, mozilla::dom::RequestMode const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestCredentials, IPC::ContiguousEnumValidator<mozilla::dom::RequestCredentials, (mozilla::dom::RequestCredentials)0, (mozilla::dom::RequestCredentials)3> >::Write(IPC::Message*, mozilla::dom::RequestCredentials const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestCache, IPC::ContiguousEnumValidator<mozilla::dom::RequestCache, (mozilla::dom::RequestCache)0, (mozilla::dom::RequestCache)6> >::Write(IPC::Message*, mozilla::dom::RequestCache const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestRedirect, IPC::ContiguousEnumValidator<mozilla::dom::RequestRedirect, (mozilla::dom::RequestRedirect)0, (mozilla::dom::RequestRedirect)3> >::Write(IPC::Message*, mozilla::dom::RequestRedirect const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ResponseType, IPC::ContiguousEnumValidator<mozilla::dom::ResponseType, (mozilla::dom::ResponseType)0, (mozilla::dom::ResponseType)6> >::Write(IPC::Message*, mozilla::dom::ResponseType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::cache::OpenMode, IPC::ContiguousEnumValidator<mozilla::dom::cache::OpenMode, (mozilla::dom::cache::OpenMode)0, (mozilla::dom::cache::OpenMode)2> >::Write(IPC::Message*, mozilla::dom::cache::OpenMode const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::cache::Namespace, IPC::ContiguousEnumValidator<mozilla::dom::cache::Namespace, (mozilla::dom::cache::Namespace)0, (mozilla::dom::cache::Namespace)2> >::Write(IPC::Message*, mozilla::dom::cache::Namespace const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ClientType, IPC::ContiguousEnumValidator<mozilla::dom::ClientType, (mozilla::dom::ClientType)0, (mozilla::dom::ClientType)5> >::Write(IPC::Message*, mozilla::dom::ClientType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::FrameType, IPC::ContiguousEnumValidator<mozilla::dom::FrameType, (mozilla::dom::FrameType)0, (mozilla::dom::FrameType)4> >::Write(IPC::Message*, mozilla::dom::FrameType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::VisibilityState, IPC::ContiguousEnumValidator<mozilla::dom::VisibilityState, (mozilla::dom::VisibilityState)0, (mozilla::dom::VisibilityState)2> >::Write(IPC::Message*, mozilla::dom::VisibilityState const&) Unexecuted instantiation: IPC::EnumSerializer<nsContentUtils::StorageAccess, IPC::ContiguousEnumValidator<nsContentUtils::StorageAccess, (nsContentUtils::StorageAccess)0, (nsContentUtils::StorageAccess)4> >::Write(IPC::Message*, nsContentUtils::StorageAccess const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::SurfaceFormat, IPC::ContiguousEnumValidator<mozilla::gfx::SurfaceFormat, (mozilla::gfx::SurfaceFormat)0, (mozilla::gfx::SurfaceFormat)18> >::Write(IPC::Message*, mozilla::gfx::SurfaceFormat const&) Unexecuted instantiation: IPC::EnumSerializer<GMPBufferType, IPC::ContiguousEnumValidator<GMPBufferType, (GMPBufferType)0, (GMPBufferType)5> >::Write(IPC::Message*, GMPBufferType const&) Unexecuted instantiation: IPC::EnumSerializer<GMPEncryptionScheme, IPC::ContiguousEnumValidator<GMPEncryptionScheme, (GMPEncryptionScheme)0, (GMPEncryptionScheme)3> >::Write(IPC::Message*, GMPEncryptionScheme const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadMappingType, IPC::ContiguousEnumValidator<mozilla::dom::GamepadMappingType, (mozilla::dom::GamepadMappingType)0, (mozilla::dom::GamepadMappingType)2> >::Write(IPC::Message*, mozilla::dom::GamepadMappingType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadHand, IPC::ContiguousEnumValidator<mozilla::dom::GamepadHand, (mozilla::dom::GamepadHand)0, (mozilla::dom::GamepadHand)3> >::Write(IPC::Message*, mozilla::dom::GamepadHand const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadServiceType, IPC::ContiguousEnumValidator<mozilla::dom::GamepadServiceType, (mozilla::dom::GamepadServiceType)0, (mozilla::dom::GamepadServiceType)2> >::Write(IPC::Message*, mozilla::dom::GamepadServiceType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::FeatureStatus, IPC::ContiguousEnumValidator<mozilla::gfx::FeatureStatus, (mozilla::gfx::FeatureStatus)0, (mozilla::gfx::FeatureStatus)12> >::Write(IPC::Message*, mozilla::gfx::FeatureStatus const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::BackendType, IPC::ContiguousEnumValidator<mozilla::gfx::BackendType, (mozilla::gfx::BackendType)0, (mozilla::gfx::BackendType)7> >::Write(IPC::Message*, mozilla::gfx::BackendType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ServiceWorkerState, IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerState, (mozilla::dom::ServiceWorkerState)0, (mozilla::dom::ServiceWorkerState)6> >::Write(IPC::Message*, mozilla::dom::ServiceWorkerState const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ServiceWorkerUpdateViaCache, IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerUpdateViaCache, (mozilla::dom::ServiceWorkerUpdateViaCache)0, (mozilla::dom::ServiceWorkerUpdateViaCache)3> >::Write(IPC::Message*, mozilla::dom::ServiceWorkerUpdateViaCache const&) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoCodecType, IPC::ContiguousEnumValidator<GMPVideoCodecType, (GMPVideoCodecType)0, (GMPVideoCodecType)3> >::Write(IPC::Message*, GMPVideoCodecType const&) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoCodecMode, IPC::ContiguousEnumValidator<GMPVideoCodecMode, (GMPVideoCodecMode)0, (GMPVideoCodecMode)3> >::Write(IPC::Message*, GMPVideoCodecMode const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::plugins::FunctionHookId, IPC::ContiguousEnumValidator<mozilla::plugins::FunctionHookId, (mozilla::plugins::FunctionHookId)0, (mozilla::plugins::FunctionHookId)0> >::Write(IPC::Message*, mozilla::plugins::FunctionHookId const&) Unexecuted instantiation: IPC::EnumSerializer<GMPErr, IPC::ContiguousEnumValidator<GMPErr, (GMPErr)0, (GMPErr)15> >::Write(IPC::Message*, GMPErr const&) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoFrameType, IPC::ContiguousEnumValidator<GMPVideoFrameType, (GMPVideoFrameType)0, (GMPVideoFrameType)5> >::Write(IPC::Message*, GMPVideoFrameType const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::Feature, IPC::ContiguousEnumValidator<mozilla::gfx::Feature, (mozilla::gfx::Feature)0, (mozilla::gfx::Feature)11> >::Write(IPC::Message*, mozilla::gfx::Feature const&) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::Fallback, IPC::ContiguousEnumValidator<mozilla::gfx::Fallback, (mozilla::gfx::Fallback)0, (mozilla::gfx::Fallback)1> >::Write(IPC::Message*, mozilla::gfx::Fallback const&) |
136 | | |
137 | 0 | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { |
138 | 0 | uintParamType value; |
139 | 0 | if (!ReadParam(aMsg, aIter, &value)) { |
140 | 0 | CrashReporter::AnnotateCrashReport( |
141 | 0 | CrashReporter::Annotation::IPCReadErrorReason, |
142 | 0 | NS_LITERAL_CSTRING("Bad iter")); |
143 | 0 | return false; |
144 | 0 | } else if (!EnumValidator::IsLegalValue(paramType(value))) { |
145 | 0 | CrashReporter::AnnotateCrashReport( |
146 | 0 | CrashReporter::Annotation::IPCReadErrorReason, |
147 | 0 | NS_LITERAL_CSTRING("Illegal value")); |
148 | 0 | return false; |
149 | 0 | } |
150 | 0 | *aResult = paramType(value); |
151 | 0 | return true; |
152 | 0 | } Unexecuted instantiation: IPC::EnumSerializer<mozilla::layers::LayersBackend, IPC::ContiguousEnumValidator<mozilla::layers::LayersBackend, (mozilla::layers::LayersBackend)0, (mozilla::layers::LayersBackend)6> >::Read(IPC::Message const*, PickleIterator*, mozilla::layers::LayersBackend*) Unexecuted instantiation: IPC::EnumSerializer<GeckoProcessType, IPC::ContiguousEnumValidator<GeckoProcessType, (GeckoProcessType)0, (GeckoProcessType)8> >::Read(IPC::Message const*, PickleIterator*, GeckoProcessType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadCapabilityFlags, IPC::BitFlagsEnumValidator<mozilla::dom::GamepadCapabilityFlags, (mozilla::dom::GamepadCapabilityFlags)31> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::GamepadCapabilityFlags*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::HeadersGuardEnum, IPC::ContiguousEnumValidator<mozilla::dom::HeadersGuardEnum, (mozilla::dom::HeadersGuardEnum)0, (mozilla::dom::HeadersGuardEnum)5> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::HeadersGuardEnum*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ReferrerPolicy, IPC::ContiguousEnumValidator<mozilla::dom::ReferrerPolicy, (mozilla::dom::ReferrerPolicy)0, (mozilla::dom::ReferrerPolicy)9> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::ReferrerPolicy*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestMode, IPC::ContiguousEnumValidator<mozilla::dom::RequestMode, (mozilla::dom::RequestMode)0, (mozilla::dom::RequestMode)4> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::RequestMode*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestCredentials, IPC::ContiguousEnumValidator<mozilla::dom::RequestCredentials, (mozilla::dom::RequestCredentials)0, (mozilla::dom::RequestCredentials)3> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::RequestCredentials*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestCache, IPC::ContiguousEnumValidator<mozilla::dom::RequestCache, (mozilla::dom::RequestCache)0, (mozilla::dom::RequestCache)6> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::RequestCache*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::RequestRedirect, IPC::ContiguousEnumValidator<mozilla::dom::RequestRedirect, (mozilla::dom::RequestRedirect)0, (mozilla::dom::RequestRedirect)3> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::RequestRedirect*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ResponseType, IPC::ContiguousEnumValidator<mozilla::dom::ResponseType, (mozilla::dom::ResponseType)0, (mozilla::dom::ResponseType)6> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::ResponseType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::cache::OpenMode, IPC::ContiguousEnumValidator<mozilla::dom::cache::OpenMode, (mozilla::dom::cache::OpenMode)0, (mozilla::dom::cache::OpenMode)2> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::cache::OpenMode*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::cache::Namespace, IPC::ContiguousEnumValidator<mozilla::dom::cache::Namespace, (mozilla::dom::cache::Namespace)0, (mozilla::dom::cache::Namespace)2> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::cache::Namespace*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ClientType, IPC::ContiguousEnumValidator<mozilla::dom::ClientType, (mozilla::dom::ClientType)0, (mozilla::dom::ClientType)5> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::ClientType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::FrameType, IPC::ContiguousEnumValidator<mozilla::dom::FrameType, (mozilla::dom::FrameType)0, (mozilla::dom::FrameType)4> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::FrameType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::VisibilityState, IPC::ContiguousEnumValidator<mozilla::dom::VisibilityState, (mozilla::dom::VisibilityState)0, (mozilla::dom::VisibilityState)2> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::VisibilityState*) Unexecuted instantiation: IPC::EnumSerializer<nsContentUtils::StorageAccess, IPC::ContiguousEnumValidator<nsContentUtils::StorageAccess, (nsContentUtils::StorageAccess)0, (nsContentUtils::StorageAccess)4> >::Read(IPC::Message const*, PickleIterator*, nsContentUtils::StorageAccess*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::SurfaceFormat, IPC::ContiguousEnumValidator<mozilla::gfx::SurfaceFormat, (mozilla::gfx::SurfaceFormat)0, (mozilla::gfx::SurfaceFormat)18> >::Read(IPC::Message const*, PickleIterator*, mozilla::gfx::SurfaceFormat*) Unexecuted instantiation: IPC::EnumSerializer<GMPBufferType, IPC::ContiguousEnumValidator<GMPBufferType, (GMPBufferType)0, (GMPBufferType)5> >::Read(IPC::Message const*, PickleIterator*, GMPBufferType*) Unexecuted instantiation: IPC::EnumSerializer<GMPEncryptionScheme, IPC::ContiguousEnumValidator<GMPEncryptionScheme, (GMPEncryptionScheme)0, (GMPEncryptionScheme)3> >::Read(IPC::Message const*, PickleIterator*, GMPEncryptionScheme*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadMappingType, IPC::ContiguousEnumValidator<mozilla::dom::GamepadMappingType, (mozilla::dom::GamepadMappingType)0, (mozilla::dom::GamepadMappingType)2> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::GamepadMappingType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadHand, IPC::ContiguousEnumValidator<mozilla::dom::GamepadHand, (mozilla::dom::GamepadHand)0, (mozilla::dom::GamepadHand)3> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::GamepadHand*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::GamepadServiceType, IPC::ContiguousEnumValidator<mozilla::dom::GamepadServiceType, (mozilla::dom::GamepadServiceType)0, (mozilla::dom::GamepadServiceType)2> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::GamepadServiceType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::FeatureStatus, IPC::ContiguousEnumValidator<mozilla::gfx::FeatureStatus, (mozilla::gfx::FeatureStatus)0, (mozilla::gfx::FeatureStatus)12> >::Read(IPC::Message const*, PickleIterator*, mozilla::gfx::FeatureStatus*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::BackendType, IPC::ContiguousEnumValidator<mozilla::gfx::BackendType, (mozilla::gfx::BackendType)0, (mozilla::gfx::BackendType)7> >::Read(IPC::Message const*, PickleIterator*, mozilla::gfx::BackendType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ServiceWorkerState, IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerState, (mozilla::dom::ServiceWorkerState)0, (mozilla::dom::ServiceWorkerState)6> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::ServiceWorkerState*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::dom::ServiceWorkerUpdateViaCache, IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerUpdateViaCache, (mozilla::dom::ServiceWorkerUpdateViaCache)0, (mozilla::dom::ServiceWorkerUpdateViaCache)3> >::Read(IPC::Message const*, PickleIterator*, mozilla::dom::ServiceWorkerUpdateViaCache*) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoCodecType, IPC::ContiguousEnumValidator<GMPVideoCodecType, (GMPVideoCodecType)0, (GMPVideoCodecType)3> >::Read(IPC::Message const*, PickleIterator*, GMPVideoCodecType*) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoCodecMode, IPC::ContiguousEnumValidator<GMPVideoCodecMode, (GMPVideoCodecMode)0, (GMPVideoCodecMode)3> >::Read(IPC::Message const*, PickleIterator*, GMPVideoCodecMode*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::plugins::FunctionHookId, IPC::ContiguousEnumValidator<mozilla::plugins::FunctionHookId, (mozilla::plugins::FunctionHookId)0, (mozilla::plugins::FunctionHookId)0> >::Read(IPC::Message const*, PickleIterator*, mozilla::plugins::FunctionHookId*) Unexecuted instantiation: IPC::EnumSerializer<GMPErr, IPC::ContiguousEnumValidator<GMPErr, (GMPErr)0, (GMPErr)15> >::Read(IPC::Message const*, PickleIterator*, GMPErr*) Unexecuted instantiation: IPC::EnumSerializer<GMPVideoFrameType, IPC::ContiguousEnumValidator<GMPVideoFrameType, (GMPVideoFrameType)0, (GMPVideoFrameType)5> >::Read(IPC::Message const*, PickleIterator*, GMPVideoFrameType*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::Feature, IPC::ContiguousEnumValidator<mozilla::gfx::Feature, (mozilla::gfx::Feature)0, (mozilla::gfx::Feature)11> >::Read(IPC::Message const*, PickleIterator*, mozilla::gfx::Feature*) Unexecuted instantiation: IPC::EnumSerializer<mozilla::gfx::Fallback, IPC::ContiguousEnumValidator<mozilla::gfx::Fallback, (mozilla::gfx::Fallback)0, (mozilla::gfx::Fallback)1> >::Read(IPC::Message const*, PickleIterator*, mozilla::gfx::Fallback*) |
153 | | }; |
154 | | |
155 | | template <typename E, |
156 | | E MinLegal, |
157 | | E HighBound> |
158 | | class ContiguousEnumValidator |
159 | | { |
160 | | // Silence overzealous -Wtype-limits bug in GCC fixed in GCC 4.8: |
161 | | // "comparison of unsigned expression >= 0 is always true" |
162 | | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856 |
163 | | template <typename T> |
164 | 0 | static bool IsLessThanOrEqual(T a, T b) { return a <= b; } Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::layers::LayersBackend, (mozilla::layers::LayersBackend)0, (mozilla::layers::LayersBackend)6>::IsLessThanOrEqual<mozilla::layers::LayersBackend>(mozilla::layers::LayersBackend, mozilla::layers::LayersBackend) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GeckoProcessType, (GeckoProcessType)0, (GeckoProcessType)8>::IsLessThanOrEqual<GeckoProcessType>(GeckoProcessType, GeckoProcessType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::HeadersGuardEnum, (mozilla::dom::HeadersGuardEnum)0, (mozilla::dom::HeadersGuardEnum)5>::IsLessThanOrEqual<mozilla::dom::HeadersGuardEnum>(mozilla::dom::HeadersGuardEnum, mozilla::dom::HeadersGuardEnum) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::ReferrerPolicy, (mozilla::dom::ReferrerPolicy)0, (mozilla::dom::ReferrerPolicy)9>::IsLessThanOrEqual<mozilla::dom::ReferrerPolicy>(mozilla::dom::ReferrerPolicy, mozilla::dom::ReferrerPolicy) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::RequestMode, (mozilla::dom::RequestMode)0, (mozilla::dom::RequestMode)4>::IsLessThanOrEqual<mozilla::dom::RequestMode>(mozilla::dom::RequestMode, mozilla::dom::RequestMode) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::RequestCredentials, (mozilla::dom::RequestCredentials)0, (mozilla::dom::RequestCredentials)3>::IsLessThanOrEqual<mozilla::dom::RequestCredentials>(mozilla::dom::RequestCredentials, mozilla::dom::RequestCredentials) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::RequestCache, (mozilla::dom::RequestCache)0, (mozilla::dom::RequestCache)6>::IsLessThanOrEqual<mozilla::dom::RequestCache>(mozilla::dom::RequestCache, mozilla::dom::RequestCache) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::RequestRedirect, (mozilla::dom::RequestRedirect)0, (mozilla::dom::RequestRedirect)3>::IsLessThanOrEqual<mozilla::dom::RequestRedirect>(mozilla::dom::RequestRedirect, mozilla::dom::RequestRedirect) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::ResponseType, (mozilla::dom::ResponseType)0, (mozilla::dom::ResponseType)6>::IsLessThanOrEqual<mozilla::dom::ResponseType>(mozilla::dom::ResponseType, mozilla::dom::ResponseType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::cache::OpenMode, (mozilla::dom::cache::OpenMode)0, (mozilla::dom::cache::OpenMode)2>::IsLessThanOrEqual<mozilla::dom::cache::OpenMode>(mozilla::dom::cache::OpenMode, mozilla::dom::cache::OpenMode) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::cache::Namespace, (mozilla::dom::cache::Namespace)0, (mozilla::dom::cache::Namespace)2>::IsLessThanOrEqual<mozilla::dom::cache::Namespace>(mozilla::dom::cache::Namespace, mozilla::dom::cache::Namespace) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::ClientType, (mozilla::dom::ClientType)0, (mozilla::dom::ClientType)5>::IsLessThanOrEqual<mozilla::dom::ClientType>(mozilla::dom::ClientType, mozilla::dom::ClientType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::FrameType, (mozilla::dom::FrameType)0, (mozilla::dom::FrameType)4>::IsLessThanOrEqual<mozilla::dom::FrameType>(mozilla::dom::FrameType, mozilla::dom::FrameType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::VisibilityState, (mozilla::dom::VisibilityState)0, (mozilla::dom::VisibilityState)2>::IsLessThanOrEqual<mozilla::dom::VisibilityState>(mozilla::dom::VisibilityState, mozilla::dom::VisibilityState) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<nsContentUtils::StorageAccess, (nsContentUtils::StorageAccess)0, (nsContentUtils::StorageAccess)4>::IsLessThanOrEqual<nsContentUtils::StorageAccess>(nsContentUtils::StorageAccess, nsContentUtils::StorageAccess) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::gfx::SurfaceFormat, (mozilla::gfx::SurfaceFormat)0, (mozilla::gfx::SurfaceFormat)18>::IsLessThanOrEqual<mozilla::gfx::SurfaceFormat>(mozilla::gfx::SurfaceFormat, mozilla::gfx::SurfaceFormat) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPBufferType, (GMPBufferType)0, (GMPBufferType)5>::IsLessThanOrEqual<GMPBufferType>(GMPBufferType, GMPBufferType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPEncryptionScheme, (GMPEncryptionScheme)0, (GMPEncryptionScheme)3>::IsLessThanOrEqual<GMPEncryptionScheme>(GMPEncryptionScheme, GMPEncryptionScheme) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::GamepadMappingType, (mozilla::dom::GamepadMappingType)0, (mozilla::dom::GamepadMappingType)2>::IsLessThanOrEqual<mozilla::dom::GamepadMappingType>(mozilla::dom::GamepadMappingType, mozilla::dom::GamepadMappingType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::GamepadHand, (mozilla::dom::GamepadHand)0, (mozilla::dom::GamepadHand)3>::IsLessThanOrEqual<mozilla::dom::GamepadHand>(mozilla::dom::GamepadHand, mozilla::dom::GamepadHand) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::GamepadServiceType, (mozilla::dom::GamepadServiceType)0, (mozilla::dom::GamepadServiceType)2>::IsLessThanOrEqual<mozilla::dom::GamepadServiceType>(mozilla::dom::GamepadServiceType, mozilla::dom::GamepadServiceType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::gfx::FeatureStatus, (mozilla::gfx::FeatureStatus)0, (mozilla::gfx::FeatureStatus)12>::IsLessThanOrEqual<mozilla::gfx::FeatureStatus>(mozilla::gfx::FeatureStatus, mozilla::gfx::FeatureStatus) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::gfx::BackendType, (mozilla::gfx::BackendType)0, (mozilla::gfx::BackendType)7>::IsLessThanOrEqual<mozilla::gfx::BackendType>(mozilla::gfx::BackendType, mozilla::gfx::BackendType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerState, (mozilla::dom::ServiceWorkerState)0, (mozilla::dom::ServiceWorkerState)6>::IsLessThanOrEqual<mozilla::dom::ServiceWorkerState>(mozilla::dom::ServiceWorkerState, mozilla::dom::ServiceWorkerState) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerUpdateViaCache, (mozilla::dom::ServiceWorkerUpdateViaCache)0, (mozilla::dom::ServiceWorkerUpdateViaCache)3>::IsLessThanOrEqual<mozilla::dom::ServiceWorkerUpdateViaCache>(mozilla::dom::ServiceWorkerUpdateViaCache, mozilla::dom::ServiceWorkerUpdateViaCache) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPVideoCodecType, (GMPVideoCodecType)0, (GMPVideoCodecType)3>::IsLessThanOrEqual<GMPVideoCodecType>(GMPVideoCodecType, GMPVideoCodecType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPVideoCodecMode, (GMPVideoCodecMode)0, (GMPVideoCodecMode)3>::IsLessThanOrEqual<GMPVideoCodecMode>(GMPVideoCodecMode, GMPVideoCodecMode) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::plugins::FunctionHookId, (mozilla::plugins::FunctionHookId)0, (mozilla::plugins::FunctionHookId)0>::IsLessThanOrEqual<mozilla::plugins::FunctionHookId>(mozilla::plugins::FunctionHookId, mozilla::plugins::FunctionHookId) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPErr, (GMPErr)0, (GMPErr)15>::IsLessThanOrEqual<GMPErr>(GMPErr, GMPErr) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<GMPVideoFrameType, (GMPVideoFrameType)0, (GMPVideoFrameType)5>::IsLessThanOrEqual<GMPVideoFrameType>(GMPVideoFrameType, GMPVideoFrameType) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::gfx::Feature, (mozilla::gfx::Feature)0, (mozilla::gfx::Feature)11>::IsLessThanOrEqual<mozilla::gfx::Feature>(mozilla::gfx::Feature, mozilla::gfx::Feature) Unexecuted instantiation: bool IPC::ContiguousEnumValidator<mozilla::gfx::Fallback, (mozilla::gfx::Fallback)0, (mozilla::gfx::Fallback)1>::IsLessThanOrEqual<mozilla::gfx::Fallback>(mozilla::gfx::Fallback, mozilla::gfx::Fallback) |
165 | | |
166 | | public: |
167 | | static bool IsLegalValue(E e) |
168 | 0 | { |
169 | 0 | return IsLessThanOrEqual(MinLegal, e) && e < HighBound; |
170 | 0 | } Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::layers::LayersBackend, (mozilla::layers::LayersBackend)0, (mozilla::layers::LayersBackend)6>::IsLegalValue(mozilla::layers::LayersBackend) Unexecuted instantiation: IPC::ContiguousEnumValidator<GeckoProcessType, (GeckoProcessType)0, (GeckoProcessType)8>::IsLegalValue(GeckoProcessType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::HeadersGuardEnum, (mozilla::dom::HeadersGuardEnum)0, (mozilla::dom::HeadersGuardEnum)5>::IsLegalValue(mozilla::dom::HeadersGuardEnum) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::ReferrerPolicy, (mozilla::dom::ReferrerPolicy)0, (mozilla::dom::ReferrerPolicy)9>::IsLegalValue(mozilla::dom::ReferrerPolicy) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::RequestMode, (mozilla::dom::RequestMode)0, (mozilla::dom::RequestMode)4>::IsLegalValue(mozilla::dom::RequestMode) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::RequestCredentials, (mozilla::dom::RequestCredentials)0, (mozilla::dom::RequestCredentials)3>::IsLegalValue(mozilla::dom::RequestCredentials) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::RequestCache, (mozilla::dom::RequestCache)0, (mozilla::dom::RequestCache)6>::IsLegalValue(mozilla::dom::RequestCache) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::RequestRedirect, (mozilla::dom::RequestRedirect)0, (mozilla::dom::RequestRedirect)3>::IsLegalValue(mozilla::dom::RequestRedirect) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::ResponseType, (mozilla::dom::ResponseType)0, (mozilla::dom::ResponseType)6>::IsLegalValue(mozilla::dom::ResponseType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::cache::OpenMode, (mozilla::dom::cache::OpenMode)0, (mozilla::dom::cache::OpenMode)2>::IsLegalValue(mozilla::dom::cache::OpenMode) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::cache::Namespace, (mozilla::dom::cache::Namespace)0, (mozilla::dom::cache::Namespace)2>::IsLegalValue(mozilla::dom::cache::Namespace) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::ClientType, (mozilla::dom::ClientType)0, (mozilla::dom::ClientType)5>::IsLegalValue(mozilla::dom::ClientType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::FrameType, (mozilla::dom::FrameType)0, (mozilla::dom::FrameType)4>::IsLegalValue(mozilla::dom::FrameType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::VisibilityState, (mozilla::dom::VisibilityState)0, (mozilla::dom::VisibilityState)2>::IsLegalValue(mozilla::dom::VisibilityState) Unexecuted instantiation: IPC::ContiguousEnumValidator<nsContentUtils::StorageAccess, (nsContentUtils::StorageAccess)0, (nsContentUtils::StorageAccess)4>::IsLegalValue(nsContentUtils::StorageAccess) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::gfx::SurfaceFormat, (mozilla::gfx::SurfaceFormat)0, (mozilla::gfx::SurfaceFormat)18>::IsLegalValue(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPBufferType, (GMPBufferType)0, (GMPBufferType)5>::IsLegalValue(GMPBufferType) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPEncryptionScheme, (GMPEncryptionScheme)0, (GMPEncryptionScheme)3>::IsLegalValue(GMPEncryptionScheme) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::GamepadMappingType, (mozilla::dom::GamepadMappingType)0, (mozilla::dom::GamepadMappingType)2>::IsLegalValue(mozilla::dom::GamepadMappingType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::GamepadHand, (mozilla::dom::GamepadHand)0, (mozilla::dom::GamepadHand)3>::IsLegalValue(mozilla::dom::GamepadHand) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::GamepadServiceType, (mozilla::dom::GamepadServiceType)0, (mozilla::dom::GamepadServiceType)2>::IsLegalValue(mozilla::dom::GamepadServiceType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::gfx::FeatureStatus, (mozilla::gfx::FeatureStatus)0, (mozilla::gfx::FeatureStatus)12>::IsLegalValue(mozilla::gfx::FeatureStatus) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::gfx::BackendType, (mozilla::gfx::BackendType)0, (mozilla::gfx::BackendType)7>::IsLegalValue(mozilla::gfx::BackendType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerState, (mozilla::dom::ServiceWorkerState)0, (mozilla::dom::ServiceWorkerState)6>::IsLegalValue(mozilla::dom::ServiceWorkerState) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::dom::ServiceWorkerUpdateViaCache, (mozilla::dom::ServiceWorkerUpdateViaCache)0, (mozilla::dom::ServiceWorkerUpdateViaCache)3>::IsLegalValue(mozilla::dom::ServiceWorkerUpdateViaCache) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPVideoCodecType, (GMPVideoCodecType)0, (GMPVideoCodecType)3>::IsLegalValue(GMPVideoCodecType) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPVideoCodecMode, (GMPVideoCodecMode)0, (GMPVideoCodecMode)3>::IsLegalValue(GMPVideoCodecMode) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::plugins::FunctionHookId, (mozilla::plugins::FunctionHookId)0, (mozilla::plugins::FunctionHookId)0>::IsLegalValue(mozilla::plugins::FunctionHookId) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPErr, (GMPErr)0, (GMPErr)15>::IsLegalValue(GMPErr) Unexecuted instantiation: IPC::ContiguousEnumValidator<GMPVideoFrameType, (GMPVideoFrameType)0, (GMPVideoFrameType)5>::IsLegalValue(GMPVideoFrameType) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::gfx::Feature, (mozilla::gfx::Feature)0, (mozilla::gfx::Feature)11>::IsLegalValue(mozilla::gfx::Feature) Unexecuted instantiation: IPC::ContiguousEnumValidator<mozilla::gfx::Fallback, (mozilla::gfx::Fallback)0, (mozilla::gfx::Fallback)1>::IsLegalValue(mozilla::gfx::Fallback) |
171 | | }; |
172 | | |
173 | | template <typename E, |
174 | | E MinLegal, |
175 | | E MaxLegal> |
176 | | class ContiguousEnumValidatorInclusive |
177 | | { |
178 | | // Silence overzealous -Wtype-limits bug in GCC fixed in GCC 4.8: |
179 | | // "comparison of unsigned expression >= 0 is always true" |
180 | | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856 |
181 | | template <typename T> |
182 | | static bool IsLessThanOrEqual(T a, T b) { return a <= b; } |
183 | | |
184 | | public: |
185 | | static bool IsLegalValue(E e) |
186 | | { |
187 | | return IsLessThanOrEqual(MinLegal, e) && e <= MaxLegal; |
188 | | } |
189 | | }; |
190 | | |
191 | | template <typename E, |
192 | | E AllBits> |
193 | | struct BitFlagsEnumValidator |
194 | | { |
195 | | static bool IsLegalValue(E e) |
196 | 0 | { |
197 | 0 | return (e & AllBits) == e; |
198 | 0 | } |
199 | | }; |
200 | | |
201 | | /** |
202 | | * Specialization of EnumSerializer for enums with contiguous enum values. |
203 | | * |
204 | | * Provide two values: MinLegal, HighBound. An enum value x will be |
205 | | * considered legal if MinLegal <= x < HighBound. |
206 | | * |
207 | | * For example, following is definition of serializer for enum type FOO. |
208 | | * \code |
209 | | * enum FOO { FOO_FIRST, FOO_SECOND, FOO_LAST, NUM_FOO }; |
210 | | * |
211 | | * template <> |
212 | | * struct ParamTraits<FOO>: |
213 | | * public ContiguousEnumSerializer<FOO, FOO_FIRST, NUM_FOO> {}; |
214 | | * \endcode |
215 | | * FOO_FIRST, FOO_SECOND, and FOO_LAST are valid value. |
216 | | */ |
217 | | template <typename E, |
218 | | E MinLegal, |
219 | | E HighBound> |
220 | | struct ContiguousEnumSerializer |
221 | | : EnumSerializer<E, |
222 | | ContiguousEnumValidator<E, MinLegal, HighBound>> |
223 | | {}; |
224 | | |
225 | | /** |
226 | | * This is similar to ContiguousEnumSerializer, but the last template |
227 | | * parameter is expected to be the highest legal value, rather than a |
228 | | * sentinel value. This is intended to support enumerations that don't |
229 | | * have sentinel values. |
230 | | */ |
231 | | template <typename E, |
232 | | E MinLegal, |
233 | | E MaxLegal> |
234 | | struct ContiguousEnumSerializerInclusive |
235 | | : EnumSerializer<E, |
236 | | ContiguousEnumValidatorInclusive<E, MinLegal, MaxLegal>> |
237 | | {}; |
238 | | |
239 | | /** |
240 | | * Specialization of EnumSerializer for enums representing bit flags. |
241 | | * |
242 | | * Provide one value: AllBits. An enum value x will be |
243 | | * considered legal if (x & AllBits) == x; |
244 | | * |
245 | | * Example: |
246 | | * \code |
247 | | * enum FOO { |
248 | | * FOO_FIRST = 1 << 0, |
249 | | * FOO_SECOND = 1 << 1, |
250 | | * FOO_LAST = 1 << 2, |
251 | | * ALL_BITS = (1 << 3) - 1 |
252 | | * }; |
253 | | * |
254 | | * template <> |
255 | | * struct ParamTraits<FOO>: |
256 | | * public BitFlagsEnumSerializer<FOO, FOO::ALL_BITS> {}; |
257 | | * \endcode |
258 | | */ |
259 | | template <typename E, |
260 | | E AllBits> |
261 | | struct BitFlagsEnumSerializer |
262 | | : EnumSerializer<E, |
263 | | BitFlagsEnumValidator<E, AllBits>> |
264 | | {}; |
265 | | |
266 | | /** |
267 | | * A helper class for serializing plain-old data (POD) structures. |
268 | | * The memory representation of the structure is written to and read from |
269 | | * the serialized stream directly, without individual processing of the |
270 | | * structure's members. |
271 | | * |
272 | | * Derive ParamTraits<T> from PlainOldDataSerializer<T> if T is POD. |
273 | | * |
274 | | * Note: For POD structures with enumeration fields, this will not do |
275 | | * validation of the enum values the way serializing the fields |
276 | | * individually would. Prefer serializing the fields individually |
277 | | * in such cases. |
278 | | */ |
279 | | template <typename T> |
280 | | struct PlainOldDataSerializer |
281 | | { |
282 | | // TODO: Once the mozilla::IsPod trait is in good enough shape (bug 900042), |
283 | | // static_assert that mozilla::IsPod<T>::value is true. |
284 | | typedef T paramType; |
285 | | |
286 | 0 | static void Write(Message* aMsg, const paramType& aParam) { |
287 | 0 | aMsg->WriteBytes(&aParam, sizeof(aParam)); |
288 | 0 | } |
289 | | |
290 | 0 | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { |
291 | 0 | return aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType)); |
292 | 0 | } |
293 | | }; |
294 | | |
295 | | /** |
296 | | * A helper class for serializing empty structs. Since the struct is empty there |
297 | | * is nothing to write, and a priori we know the result of the read. |
298 | | */ |
299 | | template <typename T> |
300 | | struct EmptyStructSerializer |
301 | | { |
302 | | typedef T paramType; |
303 | | |
304 | | static void Write(Message* aMsg, const paramType& aParam) {} |
305 | | |
306 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { |
307 | | *aResult = {}; |
308 | | return true; |
309 | | } |
310 | | }; |
311 | | |
312 | | template<> |
313 | | struct ParamTraits<int8_t> |
314 | | { |
315 | | typedef int8_t paramType; |
316 | | |
317 | | static void Write(Message* aMsg, const paramType& aParam) |
318 | | { |
319 | | aMsg->WriteBytes(&aParam, sizeof(aParam)); |
320 | | } |
321 | | |
322 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
323 | | { |
324 | | return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult)); |
325 | | } |
326 | | |
327 | | static void Log(const paramType& aParam, std::wstring* aLog) |
328 | | { |
329 | | // Use 0xff to avoid sign extension. |
330 | | aLog->append(StringPrintf(L"0x%02x", aParam & 0xff)); |
331 | | } |
332 | | }; |
333 | | |
334 | | template<> |
335 | | struct ParamTraits<uint8_t> |
336 | | { |
337 | | typedef uint8_t paramType; |
338 | | |
339 | | static void Write(Message* aMsg, const paramType& aParam) |
340 | | { |
341 | | aMsg->WriteBytes(&aParam, sizeof(aParam)); |
342 | | } |
343 | | |
344 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
345 | | { |
346 | | return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult)); |
347 | | } |
348 | | |
349 | | static void Log(const paramType& aParam, std::wstring* aLog) |
350 | | { |
351 | | aLog->append(StringPrintf(L"0x%02x", aParam)); |
352 | | } |
353 | | }; |
354 | | |
355 | | #if !defined(OS_POSIX) |
356 | | // See above re: keeping definitions in sync |
357 | | template<> |
358 | | struct ParamTraits<base::FileDescriptor> |
359 | | { |
360 | | typedef base::FileDescriptor paramType; |
361 | | static void Write(Message* aMsg, const paramType& aParam) { |
362 | | MOZ_CRASH("FileDescriptor isn't meaningful on this platform"); |
363 | | } |
364 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { |
365 | | MOZ_CRASH("FileDescriptor isn't meaningful on this platform"); |
366 | | return false; |
367 | | } |
368 | | }; |
369 | | #endif // !defined(OS_POSIX) |
370 | | |
371 | | template <> |
372 | | struct ParamTraits<nsACString> |
373 | | { |
374 | | typedef nsACString paramType; |
375 | | |
376 | | static void Write(Message* aMsg, const paramType& aParam) |
377 | | { |
378 | | bool isVoid = aParam.IsVoid(); |
379 | | aMsg->WriteBool(isVoid); |
380 | | |
381 | | if (isVoid) |
382 | | // represents a nullptr pointer |
383 | | return; |
384 | | |
385 | | uint32_t length = aParam.Length(); |
386 | | WriteParam(aMsg, length); |
387 | | aMsg->WriteBytes(aParam.BeginReading(), length); |
388 | | } |
389 | | |
390 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
391 | | { |
392 | | bool isVoid; |
393 | | if (!aMsg->ReadBool(aIter, &isVoid)) |
394 | | return false; |
395 | | |
396 | | if (isVoid) { |
397 | | aResult->SetIsVoid(true); |
398 | | return true; |
399 | | } |
400 | | |
401 | | uint32_t length; |
402 | | if (!ReadParam(aMsg, aIter, &length)) { |
403 | | return false; |
404 | | } |
405 | | if (!aMsg->HasBytesAvailable(aIter, length)) { |
406 | | return false; |
407 | | } |
408 | | aResult->SetLength(length); |
409 | | |
410 | | return aMsg->ReadBytesInto(aIter, aResult->BeginWriting(), length); |
411 | | } |
412 | | |
413 | | static void Log(const paramType& aParam, std::wstring* aLog) |
414 | | { |
415 | | if (aParam.IsVoid()) |
416 | | aLog->append(L"(NULL)"); |
417 | | else |
418 | | aLog->append(UTF8ToWide(aParam.BeginReading())); |
419 | | } |
420 | | }; |
421 | | |
422 | | template <> |
423 | | struct ParamTraits<nsAString> |
424 | | { |
425 | | typedef nsAString paramType; |
426 | | |
427 | | static void Write(Message* aMsg, const paramType& aParam) |
428 | 0 | { |
429 | 0 | bool isVoid = aParam.IsVoid(); |
430 | 0 | aMsg->WriteBool(isVoid); |
431 | 0 |
|
432 | 0 | if (isVoid) |
433 | 0 | // represents a nullptr pointer |
434 | 0 | return; |
435 | 0 | |
436 | 0 | uint32_t length = aParam.Length(); |
437 | 0 | WriteParam(aMsg, length); |
438 | 0 | aMsg->WriteBytes(aParam.BeginReading(), length * sizeof(char16_t)); |
439 | 0 | } |
440 | | |
441 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
442 | 0 | { |
443 | 0 | bool isVoid; |
444 | 0 | if (!aMsg->ReadBool(aIter, &isVoid)) |
445 | 0 | return false; |
446 | 0 | |
447 | 0 | if (isVoid) { |
448 | 0 | aResult->SetIsVoid(true); |
449 | 0 | return true; |
450 | 0 | } |
451 | 0 | |
452 | 0 | uint32_t length; |
453 | 0 | if (!ReadParam(aMsg, aIter, &length)) { |
454 | 0 | return false; |
455 | 0 | } |
456 | 0 | |
457 | 0 | mozilla::CheckedInt<uint32_t> byteLength = mozilla::CheckedInt<uint32_t>(length) * sizeof(char16_t); |
458 | 0 | if (!byteLength.isValid() || !aMsg->HasBytesAvailable(aIter, byteLength.value())) { |
459 | 0 | return false; |
460 | 0 | } |
461 | 0 | |
462 | 0 | aResult->SetLength(length); |
463 | 0 |
|
464 | 0 | return aMsg->ReadBytesInto(aIter, aResult->BeginWriting(), byteLength.value()); |
465 | 0 | } |
466 | | |
467 | | static void Log(const paramType& aParam, std::wstring* aLog) |
468 | | { |
469 | | if (aParam.IsVoid()) |
470 | | aLog->append(L"(NULL)"); |
471 | | else { |
472 | | #ifdef WCHAR_T_IS_UTF16 |
473 | | aLog->append(reinterpret_cast<const wchar_t*>(aParam.BeginReading())); |
474 | | #else |
475 | | uint32_t length = aParam.Length(); |
476 | | for (uint32_t index = 0; index < length; index++) { |
477 | | aLog->push_back(std::wstring::value_type(aParam[index])); |
478 | | } |
479 | | #endif |
480 | | } |
481 | | } |
482 | | }; |
483 | | |
484 | | template <> |
485 | | struct ParamTraits<nsCString> : ParamTraits<nsACString> |
486 | | { |
487 | | typedef nsCString paramType; |
488 | | }; |
489 | | |
490 | | template <> |
491 | | struct ParamTraits<nsLiteralCString> : ParamTraits<nsACString> |
492 | | { |
493 | | typedef nsLiteralCString paramType; |
494 | | }; |
495 | | |
496 | | #ifdef MOZILLA_INTERNAL_API |
497 | | |
498 | | template<> |
499 | | struct ParamTraits<nsAutoCString> : ParamTraits<nsCString> |
500 | | { |
501 | | typedef nsAutoCString paramType; |
502 | | }; |
503 | | |
504 | | #endif // MOZILLA_INTERNAL_API |
505 | | |
506 | | template <> |
507 | | struct ParamTraits<nsString> : ParamTraits<nsAString> |
508 | | { |
509 | | typedef nsString paramType; |
510 | | }; |
511 | | |
512 | | template <> |
513 | | struct ParamTraits<nsLiteralString> : ParamTraits<nsAString> |
514 | | { |
515 | | typedef nsLiteralString paramType; |
516 | | }; |
517 | | |
518 | | template <> |
519 | | struct ParamTraits<nsDependentSubstring> : ParamTraits<nsAString> |
520 | | { |
521 | | typedef nsDependentSubstring paramType; |
522 | | }; |
523 | | |
524 | | template <> |
525 | | struct ParamTraits<nsDependentCSubstring> : ParamTraits<nsACString> |
526 | | { |
527 | | typedef nsDependentCSubstring paramType; |
528 | | }; |
529 | | |
530 | | #ifdef MOZILLA_INTERNAL_API |
531 | | |
532 | | template<> |
533 | | struct ParamTraits<nsAutoString> : ParamTraits<nsString> |
534 | | { |
535 | | typedef nsAutoString paramType; |
536 | | }; |
537 | | |
538 | | #endif // MOZILLA_INTERNAL_API |
539 | | |
540 | | // Pickle::ReadBytes and ::WriteBytes take the length in ints, so we must |
541 | | // ensure there is no overflow. This returns |false| if it would overflow. |
542 | | // Otherwise, it returns |true| and places the byte length in |aByteLength|. |
543 | | bool ByteLengthIsValid(uint32_t aNumElements, size_t aElementSize, int* aByteLength); |
544 | | |
545 | | // Note: IPDL will sometimes codegen specialized implementations of |
546 | | // nsTArray serialization and deserialization code in |
547 | | // implementSpecialArrayPickling(). This is needed when ParamTraits<E> |
548 | | // is not defined. |
549 | | template <typename E> |
550 | | struct ParamTraits<nsTArray<E>> |
551 | | { |
552 | | typedef nsTArray<E> paramType; |
553 | | |
554 | | // We write arrays of integer or floating-point data using a single pickling |
555 | | // call, rather than writing each element individually. We deliberately do |
556 | | // not use mozilla::IsPod here because it is perfectly reasonable to have |
557 | | // a data structure T for which IsPod<T>::value is true, yet also have a |
558 | | // ParamTraits<T> specialization. |
559 | | static const bool sUseWriteBytes = (mozilla::IsIntegral<E>::value || |
560 | | mozilla::IsFloatingPoint<E>::value); |
561 | | |
562 | | static void Write(Message* aMsg, const paramType& aParam) |
563 | 0 | { |
564 | 0 | uint32_t length = aParam.Length(); |
565 | 0 | WriteParam(aMsg, length); |
566 | 0 |
|
567 | 0 | if (sUseWriteBytes) { |
568 | 0 | int pickledLength = 0; |
569 | 0 | MOZ_RELEASE_ASSERT(ByteLengthIsValid(length, sizeof(E), &pickledLength)); |
570 | 0 | aMsg->WriteBytes(aParam.Elements(), pickledLength); |
571 | 0 | } else { |
572 | 0 | const E* elems = aParam.Elements(); |
573 | 0 | for (uint32_t index = 0; index < length; index++) { |
574 | 0 | WriteParam(aMsg, elems[index]); |
575 | 0 | } |
576 | 0 | } |
577 | 0 | } |
578 | | |
579 | | // This method uses infallible allocation so that an OOM failure will |
580 | | // show up as an OOM crash rather than an IPC FatalError. |
581 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
582 | 0 | { |
583 | 0 | uint32_t length; |
584 | 0 | if (!ReadParam(aMsg, aIter, &length)) { |
585 | 0 | return false; |
586 | 0 | } |
587 | 0 | |
588 | 0 | if (sUseWriteBytes) { |
589 | 0 | int pickledLength = 0; |
590 | 0 | if (!ByteLengthIsValid(length, sizeof(E), &pickledLength)) { |
591 | 0 | return false; |
592 | 0 | } |
593 | 0 | |
594 | 0 | E* elements = aResult->AppendElements(length); |
595 | 0 | return aMsg->ReadBytesInto(aIter, elements, pickledLength); |
596 | 0 | } else { |
597 | 0 |
|
598 | 0 | // Each ReadParam<E> may read more than 1 byte each; this is an attempt |
599 | 0 | // to minimally validate that the length isn't much larger than what's |
600 | 0 | // actually available in aMsg. |
601 | 0 | if (!aMsg->HasBytesAvailable(aIter, length)) { |
602 | 0 | return false; |
603 | 0 | } |
604 | 0 | |
605 | 0 | aResult->SetCapacity(length); |
606 | 0 |
|
607 | 0 | for (uint32_t index = 0; index < length; index++) { |
608 | 0 | E* element = aResult->AppendElement(); |
609 | 0 | if (!ReadParam(aMsg, aIter, element)) { |
610 | 0 | return false; |
611 | 0 | } |
612 | 0 | } |
613 | 0 | return true; |
614 | 0 | } |
615 | 0 | } |
616 | | |
617 | | static void Log(const paramType& aParam, std::wstring* aLog) |
618 | 0 | { |
619 | 0 | for (uint32_t index = 0; index < aParam.Length(); index++) { |
620 | 0 | if (index) { |
621 | 0 | aLog->append(L" "); |
622 | 0 | } |
623 | 0 | LogParam(aParam[index], aLog); |
624 | 0 | } |
625 | 0 | } |
626 | | }; |
627 | | |
628 | | template<typename E> |
629 | | struct ParamTraits<FallibleTArray<E>> |
630 | | { |
631 | | typedef FallibleTArray<E> paramType; |
632 | | |
633 | | static void Write(Message* aMsg, const paramType& aParam) |
634 | | { |
635 | | WriteParam(aMsg, static_cast<const nsTArray<E>&>(aParam)); |
636 | | } |
637 | | |
638 | | // Deserialize the array infallibly, but return a FallibleTArray. |
639 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
640 | | { |
641 | | nsTArray<E> temp; |
642 | | if (!ReadParam(aMsg, aIter, &temp)) |
643 | | return false; |
644 | | |
645 | | aResult->SwapElements(temp); |
646 | | return true; |
647 | | } |
648 | | |
649 | | static void Log(const paramType& aParam, std::wstring* aLog) |
650 | | { |
651 | | LogParam(static_cast<const nsTArray<E>&>(aParam), aLog); |
652 | | } |
653 | | }; |
654 | | |
655 | | template<typename E, size_t N> |
656 | | struct ParamTraits<AutoTArray<E, N>> : ParamTraits<nsTArray<E>> |
657 | | { |
658 | | typedef AutoTArray<E, N> paramType; |
659 | | }; |
660 | | |
661 | | template<> |
662 | | struct ParamTraits<float> |
663 | | { |
664 | | typedef float paramType; |
665 | | |
666 | | static void Write(Message* aMsg, const paramType& aParam) |
667 | 0 | { |
668 | 0 | aMsg->WriteBytes(&aParam, sizeof(paramType)); |
669 | 0 | } |
670 | | |
671 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
672 | 0 | { |
673 | 0 | return aMsg->ReadBytesInto(aIter, aResult, sizeof(*aResult)); |
674 | 0 | } |
675 | | |
676 | | static void Log(const paramType& aParam, std::wstring* aLog) |
677 | | { |
678 | | aLog->append(StringPrintf(L"%g", aParam)); |
679 | | } |
680 | | }; |
681 | | |
682 | | template <> |
683 | | struct ParamTraits<nsCSSPropertyID> |
684 | | : public ContiguousEnumSerializer<nsCSSPropertyID, |
685 | | eCSSProperty_UNKNOWN, |
686 | | eCSSProperty_COUNT> |
687 | | {}; |
688 | | |
689 | | template<> |
690 | | struct ParamTraits<mozilla::void_t> |
691 | | { |
692 | | typedef mozilla::void_t paramType; |
693 | 0 | static void Write(Message* aMsg, const paramType& aParam) { } |
694 | | static bool |
695 | | Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
696 | 0 | { |
697 | 0 | *aResult = paramType(); |
698 | 0 | return true; |
699 | 0 | } |
700 | | }; |
701 | | |
702 | | template<> |
703 | | struct ParamTraits<mozilla::null_t> |
704 | | { |
705 | | typedef mozilla::null_t paramType; |
706 | 0 | static void Write(Message* aMsg, const paramType& aParam) { } |
707 | | static bool |
708 | | Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
709 | 0 | { |
710 | 0 | *aResult = paramType(); |
711 | 0 | return true; |
712 | 0 | } |
713 | | }; |
714 | | |
715 | | template<> |
716 | | struct ParamTraits<nsID> |
717 | | { |
718 | | typedef nsID paramType; |
719 | | |
720 | | static void Write(Message* aMsg, const paramType& aParam) |
721 | 0 | { |
722 | 0 | WriteParam(aMsg, aParam.m0); |
723 | 0 | WriteParam(aMsg, aParam.m1); |
724 | 0 | WriteParam(aMsg, aParam.m2); |
725 | 0 | for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++) { |
726 | 0 | WriteParam(aMsg, aParam.m3[i]); |
727 | 0 | } |
728 | 0 | } |
729 | | |
730 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
731 | 0 | { |
732 | 0 | if(!ReadParam(aMsg, aIter, &(aResult->m0)) || |
733 | 0 | !ReadParam(aMsg, aIter, &(aResult->m1)) || |
734 | 0 | !ReadParam(aMsg, aIter, &(aResult->m2))) |
735 | 0 | return false; |
736 | 0 | |
737 | 0 | for (unsigned int i = 0; i < mozilla::ArrayLength(aResult->m3); i++) |
738 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->m3[i]))) |
739 | 0 | return false; |
740 | 0 |
|
741 | 0 | return true; |
742 | 0 | } |
743 | | |
744 | | static void Log(const paramType& aParam, std::wstring* aLog) |
745 | | { |
746 | | aLog->append(L"{"); |
747 | | aLog->append(StringPrintf(L"%8.8X-%4.4X-%4.4X-", |
748 | | aParam.m0, |
749 | | aParam.m1, |
750 | | aParam.m2)); |
751 | | for (unsigned int i = 0; i < mozilla::ArrayLength(aParam.m3); i++) |
752 | | aLog->append(StringPrintf(L"%2.2X", aParam.m3[i])); |
753 | | aLog->append(L"}"); |
754 | | } |
755 | | }; |
756 | | |
757 | | template<> |
758 | | struct ParamTraits<mozilla::TimeDuration> |
759 | | { |
760 | | typedef mozilla::TimeDuration paramType; |
761 | | static void Write(Message* aMsg, const paramType& aParam) |
762 | 0 | { |
763 | 0 | WriteParam(aMsg, aParam.mValue); |
764 | 0 | } |
765 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
766 | 0 | { |
767 | 0 | return ReadParam(aMsg, aIter, &aResult->mValue); |
768 | 0 | }; |
769 | | }; |
770 | | |
771 | | template<> |
772 | | struct ParamTraits<mozilla::TimeStamp> |
773 | | { |
774 | | typedef mozilla::TimeStamp paramType; |
775 | | static void Write(Message* aMsg, const paramType& aParam) |
776 | 0 | { |
777 | 0 | WriteParam(aMsg, aParam.mValue); |
778 | 0 | } |
779 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
780 | 0 | { |
781 | 0 | return ReadParam(aMsg, aIter, &aResult->mValue); |
782 | 0 | }; |
783 | | }; |
784 | | |
785 | | #ifdef XP_WIN |
786 | | |
787 | | template<> |
788 | | struct ParamTraits<mozilla::TimeStampValue> |
789 | | { |
790 | | typedef mozilla::TimeStampValue paramType; |
791 | | static void Write(Message* aMsg, const paramType& aParam) |
792 | | { |
793 | | WriteParam(aMsg, aParam.mGTC); |
794 | | WriteParam(aMsg, aParam.mQPC); |
795 | | WriteParam(aMsg, aParam.mHasQPC); |
796 | | WriteParam(aMsg, aParam.mIsNull); |
797 | | } |
798 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
799 | | { |
800 | | return (ReadParam(aMsg, aIter, &aResult->mGTC) && |
801 | | ReadParam(aMsg, aIter, &aResult->mQPC) && |
802 | | ReadParam(aMsg, aIter, &aResult->mHasQPC) && |
803 | | ReadParam(aMsg, aIter, &aResult->mIsNull)); |
804 | | } |
805 | | }; |
806 | | |
807 | | #endif |
808 | | |
809 | | template <> |
810 | | struct ParamTraits<mozilla::dom::ipc::StructuredCloneData> |
811 | | { |
812 | | typedef mozilla::dom::ipc::StructuredCloneData paramType; |
813 | | |
814 | | static void Write(Message* aMsg, const paramType& aParam) |
815 | | { |
816 | | aParam.WriteIPCParams(aMsg); |
817 | | } |
818 | | |
819 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
820 | | { |
821 | | return aResult->ReadIPCParams(aMsg, aIter); |
822 | | } |
823 | | |
824 | | static void Log(const paramType& aParam, std::wstring* aLog) |
825 | | { |
826 | | LogParam(aParam.DataLength(), aLog); |
827 | | } |
828 | | }; |
829 | | |
830 | | template <> |
831 | | struct ParamTraits<mozilla::net::WebSocketFrameData> |
832 | | { |
833 | | typedef mozilla::net::WebSocketFrameData paramType; |
834 | | |
835 | | static void Write(Message* aMsg, const paramType& aParam) |
836 | | { |
837 | | aParam.WriteIPCParams(aMsg); |
838 | | } |
839 | | |
840 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
841 | | { |
842 | | return aResult->ReadIPCParams(aMsg, aIter); |
843 | | } |
844 | | }; |
845 | | |
846 | | template <> |
847 | | struct ParamTraits<JSStructuredCloneData> |
848 | | { |
849 | | typedef JSStructuredCloneData paramType; |
850 | | |
851 | | static void Write(Message* aMsg, const paramType& aParam) |
852 | 0 | { |
853 | 0 | MOZ_ASSERT(!(aParam.Size() % sizeof(uint64_t))); |
854 | 0 | WriteParam(aMsg, aParam.Size()); |
855 | 0 | aParam.ForEachDataChunk([&](const char* aData, size_t aSize) { |
856 | 0 | return aMsg->WriteBytes(aData, aSize, sizeof(uint64_t)); |
857 | 0 | }); |
858 | 0 | } |
859 | | |
860 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
861 | 0 | { |
862 | 0 | size_t length = 0; |
863 | 0 | if (!ReadParam(aMsg, aIter, &length)) { |
864 | 0 | return false; |
865 | 0 | } |
866 | 0 | MOZ_ASSERT(!(length % sizeof(uint64_t))); |
867 | 0 |
|
868 | 0 | mozilla::BufferList<InfallibleAllocPolicy> buffers(0, 0, 4096); |
869 | 0 |
|
870 | 0 | // Borrowing is not suitable to use for IPC to hand out data |
871 | 0 | // because we often want to store the data somewhere for |
872 | 0 | // processing after IPC has released the underlying buffers. One |
873 | 0 | // case is PContentChild::SendGetXPCOMProcessAttributes. We can't |
874 | 0 | // return a borrowed buffer because the out param outlives the |
875 | 0 | // IPDL callback. |
876 | 0 | if (length && !aMsg->ExtractBuffers(aIter, length, &buffers, sizeof(uint64_t))) { |
877 | 0 | return false; |
878 | 0 | } |
879 | 0 | |
880 | 0 | bool success; |
881 | 0 | mozilla::BufferList<js::SystemAllocPolicy> out = |
882 | 0 | buffers.MoveFallible<js::SystemAllocPolicy>(&success); |
883 | 0 | if (!success) { |
884 | 0 | return false; |
885 | 0 | } |
886 | 0 | |
887 | 0 | *aResult = JSStructuredCloneData(std::move(out), JS::StructuredCloneScope::DifferentProcess); |
888 | 0 |
|
889 | 0 | return true; |
890 | 0 | } |
891 | | }; |
892 | | |
893 | | template <> |
894 | | struct ParamTraits<mozilla::SerializedStructuredCloneBuffer> |
895 | | { |
896 | | typedef mozilla::SerializedStructuredCloneBuffer paramType; |
897 | | |
898 | | static void Write(Message* aMsg, const paramType& aParam) |
899 | 0 | { |
900 | 0 | WriteParam(aMsg, aParam.data); |
901 | 0 | } |
902 | | |
903 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
904 | 0 | { |
905 | 0 | return ReadParam(aMsg, aIter, &aResult->data); |
906 | 0 | } |
907 | | |
908 | | static void Log(const paramType& aParam, std::wstring* aLog) |
909 | | { |
910 | | LogParam(aParam.data.Size(), aLog); |
911 | | } |
912 | | }; |
913 | | |
914 | | template <> |
915 | | struct ParamTraits<nsIWidget::TouchPointerState> |
916 | | : public BitFlagsEnumSerializer<nsIWidget::TouchPointerState, |
917 | | nsIWidget::TouchPointerState::ALL_BITS> |
918 | | { |
919 | | }; |
920 | | |
921 | | template<class T> |
922 | | struct ParamTraits<mozilla::Maybe<T>> |
923 | | { |
924 | | typedef mozilla::Maybe<T> paramType; |
925 | | |
926 | | static void Write(Message* msg, const paramType& param) |
927 | | { |
928 | | if (param.isSome()) { |
929 | | WriteParam(msg, true); |
930 | | WriteParam(msg, param.value()); |
931 | | } else { |
932 | | WriteParam(msg, false); |
933 | | } |
934 | | } |
935 | | |
936 | | static bool Read(const Message* msg, PickleIterator* iter, paramType* result) |
937 | | { |
938 | | bool isSome; |
939 | | if (!ReadParam(msg, iter, &isSome)) { |
940 | | return false; |
941 | | } |
942 | | if (isSome) { |
943 | | T tmp; |
944 | | if (!ReadParam(msg, iter, &tmp)) { |
945 | | return false; |
946 | | } |
947 | | *result = mozilla::Some(std::move(tmp)); |
948 | | } else { |
949 | | *result = mozilla::Nothing(); |
950 | | } |
951 | | return true; |
952 | | } |
953 | | }; |
954 | | |
955 | | template<typename T, typename U> |
956 | | struct ParamTraits<mozilla::EnumSet<T, U>> |
957 | | { |
958 | | typedef mozilla::EnumSet<T, U> paramType; |
959 | | typedef U serializedType; |
960 | | |
961 | | static void Write(Message* msg, const paramType& param) |
962 | | { |
963 | | MOZ_RELEASE_ASSERT(IsLegalValue(param.serialize())); |
964 | | WriteParam(msg, param.serialize()); |
965 | | } |
966 | | |
967 | | static bool Read(const Message* msg, PickleIterator* iter, paramType* result) |
968 | | { |
969 | | serializedType tmp; |
970 | | |
971 | | if (ReadParam(msg, iter, &tmp)) { |
972 | | if (IsLegalValue(tmp)) { |
973 | | result->deserialize(tmp); |
974 | | return true; |
975 | | } |
976 | | } |
977 | | |
978 | | return false; |
979 | | } |
980 | | |
981 | | static constexpr serializedType AllEnumBits() |
982 | | { |
983 | | return ~serializedType(0) >> |
984 | | (std::numeric_limits<serializedType>::digits - (mozilla::MaxEnumValue<T>::value + 1)); |
985 | | } |
986 | | |
987 | | static constexpr bool IsLegalValue(const serializedType value) |
988 | | { |
989 | | static_assert(mozilla::MaxEnumValue<T>::value < std::numeric_limits<serializedType>::digits, |
990 | | "Enum max value is not in the range!"); |
991 | | static_assert(std::is_unsigned<decltype(mozilla::MaxEnumValue<T>::value)>::value, |
992 | | "Type of MaxEnumValue<T>::value specialization should be unsigned!"); |
993 | | |
994 | | return (value & AllEnumBits()) == value; |
995 | | } |
996 | | }; |
997 | | |
998 | | template<class... Ts> |
999 | | struct ParamTraits<mozilla::Variant<Ts...>> |
1000 | | { |
1001 | | typedef mozilla::Variant<Ts...> paramType; |
1002 | | using Tag = typename mozilla::detail::VariantTag<Ts...>::Type; |
1003 | | |
1004 | | struct VariantWriter |
1005 | | { |
1006 | | Message* msg; |
1007 | | |
1008 | | template<class T> |
1009 | 0 | void match(const T& t) { |
1010 | 0 | WriteParam(msg, t); |
1011 | 0 | } Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<mozilla::plugins::IpdlTuple::InvalidType>(mozilla::plugins::IpdlTuple::InvalidType const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<signed char>(signed char const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<unsigned char>(unsigned char const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<short>(short const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<unsigned short>(unsigned short const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<int>(int const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<unsigned int>(unsigned int const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<long>(long const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<unsigned long>(unsigned long const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<nsTString<char> >(nsTString<char> const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantWriter::match<bool>(bool const&) |
1012 | | }; |
1013 | | |
1014 | | static void Write(Message* msg, const paramType& param) |
1015 | 0 | { |
1016 | 0 | WriteParam(msg, param.tag); |
1017 | 0 | param.match(VariantWriter{msg}); |
1018 | 0 | } |
1019 | | |
1020 | | // Because VariantReader is a nested struct, we need the dummy template |
1021 | | // parameter to avoid making VariantReader<0> an explicit specialization, |
1022 | | // which is not allowed for a nested class template |
1023 | | template<size_t N, typename dummy = void> |
1024 | | struct VariantReader |
1025 | | { |
1026 | | using Next = VariantReader<N-1>; |
1027 | | |
1028 | | static bool Read(const Message* msg, PickleIterator* iter, |
1029 | | Tag tag, paramType* result) |
1030 | 0 | { |
1031 | 0 | // Since the VariantReader specializations start at N , we need to |
1032 | 0 | // subtract one to look at N - 1, the first valid tag. This means our |
1033 | 0 | // comparisons are off by 1. If we get to N = 0 then we have failed to |
1034 | 0 | // find a match to the tag. |
1035 | 0 | if (tag == N - 1) { |
1036 | 0 | // Recall, even though the template parameter is N, we are |
1037 | 0 | // actually interested in the N - 1 tag. |
1038 | 0 | typename mozilla::detail::Nth<N - 1, Ts...>::Type val; |
1039 | 0 | if (ReadParam(msg, iter, &val)) { |
1040 | 0 | *result = mozilla::AsVariant(val); |
1041 | 0 | return true; |
1042 | 0 | } |
1043 | 0 | return false; |
1044 | 0 | } else { |
1045 | 0 | return Next::Read(msg, iter, tag, result); |
1046 | 0 | } |
1047 | 0 | } Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<11ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<10ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<9ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<8ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<7ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<6ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<5ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<4ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<3ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<2ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) Unexecuted instantiation: IPC::ParamTraits<mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::VariantReader<1ul, void>::Read(IPC::Message const*, PickleIterator*, unsigned char, mozilla::Variant<mozilla::plugins::IpdlTuple::InvalidType, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool>*) |
1048 | | |
1049 | | }; // VariantReader<N> |
1050 | | |
1051 | | // Since we are conditioning on tag = N - 1 in the preceding specialization, |
1052 | | // if we get to `VariantReader<0, dummy>` we have failed to find |
1053 | | // a matching tag. |
1054 | | template<typename dummy> |
1055 | | struct VariantReader<0, dummy> |
1056 | | { |
1057 | | static bool Read(const Message* msg, PickleIterator* iter, |
1058 | | Tag tag, paramType* result) |
1059 | 0 | { |
1060 | 0 | return false; |
1061 | 0 | } |
1062 | | }; |
1063 | | |
1064 | | static bool Read(const Message* msg, PickleIterator* iter, paramType* result) |
1065 | 0 | { |
1066 | 0 | Tag tag; |
1067 | 0 | if (ReadParam(msg, iter, &tag)) { |
1068 | 0 | return VariantReader<sizeof...(Ts)>::Read(msg, iter, tag, result); |
1069 | 0 | } |
1070 | 0 | return false; |
1071 | 0 | } |
1072 | | }; |
1073 | | |
1074 | | template<typename T> |
1075 | | struct ParamTraits<mozilla::dom::Optional<T>> |
1076 | | { |
1077 | | typedef mozilla::dom::Optional<T> paramType; |
1078 | | |
1079 | | static void Write(Message* aMsg, const paramType& aParam) |
1080 | | { |
1081 | | if (aParam.WasPassed()) { |
1082 | | WriteParam(aMsg, true); |
1083 | | WriteParam(aMsg, aParam.Value()); |
1084 | | return; |
1085 | | } |
1086 | | |
1087 | | WriteParam(aMsg, false); |
1088 | | } |
1089 | | |
1090 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
1091 | | { |
1092 | | bool wasPassed = false; |
1093 | | |
1094 | | if (!ReadParam(aMsg, aIter, &wasPassed)) { |
1095 | | return false; |
1096 | | } |
1097 | | |
1098 | | aResult->Reset(); |
1099 | | |
1100 | | if (wasPassed) { |
1101 | | if (!ReadParam(aMsg, aIter, &aResult->Construct())) { |
1102 | | return false; |
1103 | | } |
1104 | | } |
1105 | | |
1106 | | return true; |
1107 | | } |
1108 | | }; |
1109 | | |
1110 | | } /* namespace IPC */ |
1111 | | |
1112 | | #endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */ |