michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef TABMESSAGE_UTILS_H michael@0: #define TABMESSAGE_UTILS_H michael@0: michael@0: #include "AudioChannelCommon.h" michael@0: #include "ipc/IPCMessageUtils.h" michael@0: #include "mozilla/dom/AudioChannelBinding.h" michael@0: #include "nsIDOMEvent.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: #ifdef MOZ_CRASHREPORTER michael@0: #include "nsExceptionHandler.h" michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: struct RemoteDOMEvent michael@0: { michael@0: // Make sure to set the owner after deserializing. michael@0: nsCOMPtr mEvent; michael@0: }; michael@0: michael@0: bool ReadRemoteEvent(const IPC::Message* aMsg, void** aIter, michael@0: mozilla::dom::RemoteDOMEvent* aResult); michael@0: michael@0: #ifdef MOZ_CRASHREPORTER michael@0: typedef CrashReporter::ThreadId NativeThreadId; michael@0: #else michael@0: // unused in this case michael@0: typedef int32_t NativeThreadId; michael@0: #endif michael@0: michael@0: } michael@0: } michael@0: michael@0: namespace IPC { michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::RemoteDOMEvent paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: aParam.mEvent->Serialize(aMsg, true); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: return mozilla::dom::ReadRemoteEvent(aMsg, aIter, aResult); michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::dom::AudioChannel paramType; michael@0: michael@0: static bool IsLegalValue(const paramType &aValue) { michael@0: return aValue <= mozilla::dom::AudioChannel::Publicnotification; michael@0: } michael@0: michael@0: static void Write(Message* aMsg, const paramType& aValue) { michael@0: MOZ_ASSERT(IsLegalValue(aValue)); michael@0: WriteParam(aMsg, (uint32_t)aValue); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { michael@0: uint32_t value; michael@0: if(!ReadParam(aMsg, aIter, &value) || michael@0: !IsLegalValue(paramType(value))) { michael@0: return false; michael@0: } michael@0: *aResult = paramType(value); michael@0: return true; michael@0: } michael@0: michael@0: static void Log(const paramType& aParam, std::wstring* aLog) michael@0: { michael@0: } michael@0: }; michael@0: michael@0: template <> michael@0: struct ParamTraits michael@0: : public ContiguousEnumSerializer michael@0: { }; michael@0: michael@0: } michael@0: michael@0: michael@0: #endif