/src/mozilla-central/dom/messagechannel/SharedMessagePortMessage.cpp
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 | | #include "SharedMessagePortMessage.h" |
8 | | #include "MessagePort.h" |
9 | | #include "MessagePortChild.h" |
10 | | #include "MessagePortParent.h" |
11 | | #include "mozilla/dom/File.h" |
12 | | #include "mozilla/dom/PMessagePort.h" |
13 | | #include "mozilla/ipc/BackgroundChild.h" |
14 | | #include "mozilla/ipc/BackgroundParent.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | using namespace ipc; |
19 | | |
20 | | namespace dom { |
21 | | |
22 | | /* static */ void |
23 | | SharedMessagePortMessage::FromSharedToMessagesChild( |
24 | | MessagePortChild* aActor, |
25 | | const nsTArray<RefPtr<SharedMessagePortMessage>>& aData, |
26 | | nsTArray<ClonedMessageData>& aArray) |
27 | 0 | { |
28 | 0 | MOZ_ASSERT(aActor); |
29 | 0 | MOZ_ASSERT(aArray.IsEmpty()); |
30 | 0 | aArray.SetCapacity(aData.Length()); |
31 | 0 |
|
32 | 0 | PBackgroundChild* backgroundManager = aActor->Manager(); |
33 | 0 | MOZ_ASSERT(backgroundManager); |
34 | 0 |
|
35 | 0 | for (auto& data : aData) { |
36 | 0 | ClonedMessageData* message = aArray.AppendElement(); |
37 | 0 | data->BuildClonedMessageDataForBackgroundChild(backgroundManager, *message); |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | /* static */ bool |
42 | | SharedMessagePortMessage::FromMessagesToSharedChild( |
43 | | nsTArray<ClonedMessageData>& aArray, |
44 | | FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData) |
45 | 0 | { |
46 | 0 | MOZ_ASSERT(aData.IsEmpty()); |
47 | 0 |
|
48 | 0 | if (NS_WARN_IF(!aData.SetCapacity(aArray.Length(), mozilla::fallible))) { |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | |
52 | 0 | for (auto& message : aArray) { |
53 | 0 | RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage(); |
54 | 0 | data->StealFromClonedMessageDataForBackgroundChild(message); |
55 | 0 |
|
56 | 0 | if (!aData.AppendElement(data, mozilla::fallible)) { |
57 | 0 | return false; |
58 | 0 | } |
59 | 0 | } |
60 | 0 |
|
61 | 0 | return true; |
62 | 0 | } |
63 | | |
64 | | /* static */ bool |
65 | | SharedMessagePortMessage::FromSharedToMessagesParent( |
66 | | MessagePortParent* aActor, |
67 | | const nsTArray<RefPtr<SharedMessagePortMessage>>& aData, |
68 | | FallibleTArray<ClonedMessageData>& aArray) |
69 | 0 | { |
70 | 0 | MOZ_ASSERT(aArray.IsEmpty()); |
71 | 0 |
|
72 | 0 | if (NS_WARN_IF(!aArray.SetCapacity(aData.Length(), mozilla::fallible))) { |
73 | 0 | return false; |
74 | 0 | } |
75 | 0 | |
76 | 0 | PBackgroundParent* backgroundManager = aActor->Manager(); |
77 | 0 | MOZ_ASSERT(backgroundManager); |
78 | 0 |
|
79 | 0 | for (auto& data : aData) { |
80 | 0 | ClonedMessageData* message = aArray.AppendElement(mozilla::fallible); |
81 | 0 | data->BuildClonedMessageDataForBackgroundParent(backgroundManager, |
82 | 0 | *message); |
83 | 0 | } |
84 | 0 |
|
85 | 0 | return true; |
86 | 0 | } |
87 | | |
88 | | /* static */ bool |
89 | | SharedMessagePortMessage::FromMessagesToSharedParent( |
90 | | nsTArray<ClonedMessageData>& aArray, |
91 | | FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData) |
92 | 0 | { |
93 | 0 | MOZ_ASSERT(aData.IsEmpty()); |
94 | 0 |
|
95 | 0 | if (NS_WARN_IF(!aData.SetCapacity(aArray.Length(), mozilla::fallible))) { |
96 | 0 | return false; |
97 | 0 | } |
98 | 0 | |
99 | 0 | for (auto& message : aArray) { |
100 | 0 | RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage(); |
101 | 0 | data->StealFromClonedMessageDataForBackgroundParent(message); |
102 | 0 |
|
103 | 0 | if (!aData.AppendElement(data, mozilla::fallible)) { |
104 | 0 | return false; |
105 | 0 | } |
106 | 0 | } |
107 | 0 |
|
108 | 0 | return true; |
109 | 0 | } |
110 | | |
111 | | } // namespace dom |
112 | | } // namespace mozilla |