/* 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/. */ #ifndef mozilla_dom_SharedMessageBody_h #define mozilla_dom_SharedMessageBody_h #include "mozilla/Maybe.h" #include "mozilla/dom/ipc/StructuredCloneData.h" namespace mozilla { namespace ipc { class PBackgroundChild; } namespace dom { class MessagePort; class RefMessageBody; class RefMessageBodyService; class SharedMessageBody final { public: NS_INLINE_DECL_REFCOUNTING(SharedMessageBody) SharedMessageBody( StructuredCloneHolder::TransferringSupport aSupportsTransferring, const Maybe& aAgentClusterId); enum ReadMethod { StealRefMessageBody, KeepRefMessageBody, }; void Read(JSContext* aCx, JS::MutableHandle aValue, RefMessageBodyService* aRefMessageBodyService, ReadMethod aReadMethod, ErrorResult& aRv); void Write(JSContext* aCx, JS::Handle aValue, JS::Handle aTransfers, nsID& aPortID, RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv); bool TakeTransferredPortsAsSequence( Sequence>& aPorts); const Maybe& GetRefDataId() const { return mRefDataId; } private: friend struct IPC::ParamTraits; ~SharedMessageBody(); RefPtr mCloneData; RefPtr mRefData; Maybe mRefDataId; const StructuredCloneHolder::TransferringSupport mSupportsTransferring; const Maybe mAgentClusterId; }; } // namespace dom } // namespace mozilla namespace IPC { template <> struct ParamTraits { using paramType = mozilla::dom::SharedMessageBody; static void Write(MessageWriter* aWriter, paramType* aParam); static bool Read(MessageReader* aReader, RefPtr* aResult); }; } // namespace IPC #endif // mozilla_dom_SharedMessageBody_h