no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / ipc / SharedMessageBody.h
blob2c824736786a09794acf10d1963b66d6a8183136
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/. */
7 #ifndef mozilla_dom_SharedMessageBody_h
8 #define mozilla_dom_SharedMessageBody_h
10 #include "mozilla/dom/ipc/StructuredCloneData.h"
11 #include "mozilla/Maybe.h"
13 namespace mozilla {
15 namespace ipc {
16 class PBackgroundChild;
19 namespace dom {
21 class MessagePort;
22 class RefMessageBody;
23 class RefMessageBodyService;
25 class SharedMessageBody final {
26 public:
27 NS_INLINE_DECL_REFCOUNTING(SharedMessageBody)
29 SharedMessageBody(
30 StructuredCloneHolder::TransferringSupport aSupportsTransferring,
31 const Maybe<nsID>& aAgentClusterId);
33 // Note that the populated MessageData borrows the underlying
34 // JSStructuredCloneData from the SharedMessageBody, so the caller is
35 // required to ensure that the MessageData instances are destroyed prior to
36 // the SharedMessageBody instances.
37 static void FromSharedToMessageChild(
38 mozilla::ipc::PBackgroundChild* aBackgroundManager,
39 SharedMessageBody* aData, MessageData& aMessage);
40 static void FromSharedToMessagesChild(
41 mozilla::ipc::PBackgroundChild* aBackgroundManager,
42 const nsTArray<RefPtr<SharedMessageBody>>& aData,
43 nsTArray<MessageData>& aArray);
45 // Const MessageData.
46 static already_AddRefed<SharedMessageBody> FromMessageToSharedChild(
47 MessageData& aMessage,
48 StructuredCloneHolder::TransferringSupport aSupportsTransferring =
49 StructuredCloneHolder::TransferringSupported);
50 // Non-const MessageData.
51 static already_AddRefed<SharedMessageBody> FromMessageToSharedChild(
52 const MessageData& aMessage,
53 StructuredCloneHolder::TransferringSupport aSupportsTransferring =
54 StructuredCloneHolder::TransferringSupported);
55 // Array of MessageData objects
56 static bool FromMessagesToSharedChild(
57 nsTArray<MessageData>& aArray,
58 FallibleTArray<RefPtr<SharedMessageBody>>& aData,
59 StructuredCloneHolder::TransferringSupport aSupportsTransferring =
60 StructuredCloneHolder::TransferringSupported);
62 // Note that the populated MessageData borrows the underlying
63 // JSStructuredCloneData from the SharedMessageBody, so the caller is
64 // required to ensure that the MessageData instances are destroyed prior to
65 // the SharedMessageBody instances.
66 static bool FromSharedToMessagesParent(
67 mozilla::ipc::PBackgroundParent* aManager,
68 const nsTArray<RefPtr<SharedMessageBody>>& aData,
69 nsTArray<MessageData>& aArray);
71 static already_AddRefed<SharedMessageBody> FromMessageToSharedParent(
72 MessageData& aMessage,
73 StructuredCloneHolder::TransferringSupport aSupportsTransferring =
74 StructuredCloneHolder::TransferringSupported);
75 static bool FromMessagesToSharedParent(
76 nsTArray<MessageData>& aArray,
77 FallibleTArray<RefPtr<SharedMessageBody>>& aData,
78 StructuredCloneHolder::TransferringSupport aSupportsTransferring =
79 StructuredCloneHolder::TransferringSupported);
81 enum ReadMethod {
82 StealRefMessageBody,
83 KeepRefMessageBody,
86 void Read(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
87 RefMessageBodyService* aRefMessageBodyService,
88 ReadMethod aReadMethod, ErrorResult& aRv);
90 void Write(JSContext* aCx, JS::Handle<JS::Value> aValue,
91 JS::Handle<JS::Value> aTransfers, nsID& aPortID,
92 RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv);
94 bool TakeTransferredPortsAsSequence(
95 Sequence<OwningNonNull<mozilla::dom::MessagePort>>& aPorts);
97 private:
98 ~SharedMessageBody() = default;
100 UniquePtr<ipc::StructuredCloneData> mCloneData;
102 RefPtr<RefMessageBody> mRefData;
103 Maybe<nsID> mRefDataId;
105 const StructuredCloneHolder::TransferringSupport mSupportsTransferring;
106 const Maybe<nsID> mAgentClusterId;
109 } // namespace dom
110 } // namespace mozilla
112 #endif // mozilla_dom_SharedMessageBody_h