/src/mozilla-central/dom/presentation/ipc/PresentationChild.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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "DCPresentationChannelDescription.h" |
8 | | #include "mozilla/StaticPtr.h" |
9 | | #include "PresentationBuilderChild.h" |
10 | | #include "PresentationChild.h" |
11 | | #include "PresentationIPCService.h" |
12 | | #include "nsThreadUtils.h" |
13 | | |
14 | | using namespace mozilla; |
15 | | using namespace mozilla::dom; |
16 | | |
17 | | /* |
18 | | * Implementation of PresentationChild |
19 | | */ |
20 | | |
21 | | PresentationChild::PresentationChild(PresentationIPCService* aService) |
22 | | : mActorDestroyed(false) |
23 | | , mService(aService) |
24 | 0 | { |
25 | 0 | MOZ_ASSERT(mService); |
26 | 0 |
|
27 | 0 | MOZ_COUNT_CTOR(PresentationChild); |
28 | 0 | } |
29 | | |
30 | | PresentationChild::~PresentationChild() |
31 | 0 | { |
32 | 0 | MOZ_COUNT_DTOR(PresentationChild); |
33 | 0 |
|
34 | 0 | if (!mActorDestroyed) { |
35 | 0 | Send__delete__(this); |
36 | 0 | } |
37 | 0 | mService = nullptr; |
38 | 0 | } |
39 | | |
40 | | void |
41 | | PresentationChild::ActorDestroy(ActorDestroyReason aWhy) |
42 | 0 | { |
43 | 0 | mActorDestroyed = true; |
44 | 0 | mService->NotifyPresentationChildDestroyed(); |
45 | 0 | mService = nullptr; |
46 | 0 | } |
47 | | |
48 | | PPresentationRequestChild* |
49 | | PresentationChild::AllocPPresentationRequestChild(const PresentationIPCRequest& aRequest) |
50 | 0 | { |
51 | 0 | MOZ_ASSERT_UNREACHABLE("We should never be manually allocating " |
52 | 0 | "PPresentationRequestChild actors"); |
53 | 0 | return nullptr; |
54 | 0 | } |
55 | | |
56 | | bool |
57 | | PresentationChild::DeallocPPresentationRequestChild(PPresentationRequestChild* aActor) |
58 | 0 | { |
59 | 0 | delete aActor; |
60 | 0 | return true; |
61 | 0 | } |
62 | | |
63 | | mozilla::ipc::IPCResult |
64 | | PresentationChild::RecvPPresentationBuilderConstructor( |
65 | | PPresentationBuilderChild* aActor, |
66 | | const nsString& aSessionId, |
67 | | const uint8_t& aRole) |
68 | 0 | { |
69 | 0 | // Child will build the session transport |
70 | 0 | PresentationBuilderChild* actor = static_cast<PresentationBuilderChild*>(aActor); |
71 | 0 | if (NS_WARN_IF(NS_FAILED(actor->Init()))) { |
72 | 0 | return IPC_FAIL_NO_REASON(this); |
73 | 0 | } |
74 | 0 | return IPC_OK(); |
75 | 0 | } |
76 | | |
77 | | PPresentationBuilderChild* |
78 | | PresentationChild::AllocPPresentationBuilderChild(const nsString& aSessionId, |
79 | | const uint8_t& aRole) |
80 | 0 | { |
81 | 0 | RefPtr<PresentationBuilderChild> actor |
82 | 0 | = new PresentationBuilderChild(aSessionId, aRole); |
83 | 0 |
|
84 | 0 | return actor.forget().take(); |
85 | 0 | } |
86 | | |
87 | | bool |
88 | | PresentationChild::DeallocPPresentationBuilderChild(PPresentationBuilderChild* aActor) |
89 | 0 | { |
90 | 0 | RefPtr<PresentationBuilderChild> actor = |
91 | 0 | dont_AddRef(static_cast<PresentationBuilderChild*>(aActor)); |
92 | 0 | return true; |
93 | 0 | } |
94 | | |
95 | | |
96 | | mozilla::ipc::IPCResult |
97 | | PresentationChild::RecvNotifyAvailableChange( |
98 | | nsTArray<nsString>&& aAvailabilityUrls, |
99 | | const bool& aAvailable) |
100 | 0 | { |
101 | 0 | if (mService) { |
102 | 0 | Unused << |
103 | 0 | NS_WARN_IF(NS_FAILED(mService->NotifyAvailableChange(aAvailabilityUrls, |
104 | 0 | aAvailable))); |
105 | 0 | } |
106 | 0 | return IPC_OK(); |
107 | 0 | } |
108 | | |
109 | | mozilla::ipc::IPCResult |
110 | | PresentationChild::RecvNotifySessionStateChange(const nsString& aSessionId, |
111 | | const uint16_t& aState, |
112 | | const nsresult& aReason) |
113 | 0 | { |
114 | 0 | if (mService) { |
115 | 0 | Unused << NS_WARN_IF(NS_FAILED(mService->NotifySessionStateChange(aSessionId, |
116 | 0 | aState, |
117 | 0 | aReason))); |
118 | 0 | } |
119 | 0 | return IPC_OK(); |
120 | 0 | } |
121 | | |
122 | | mozilla::ipc::IPCResult |
123 | | PresentationChild::RecvNotifyMessage(const nsString& aSessionId, |
124 | | const nsCString& aData, |
125 | | const bool& aIsBinary) |
126 | 0 | { |
127 | 0 | if (mService) { |
128 | 0 | Unused << NS_WARN_IF(NS_FAILED(mService->NotifyMessage(aSessionId, |
129 | 0 | aData, |
130 | 0 | aIsBinary))); |
131 | 0 | } |
132 | 0 | return IPC_OK(); |
133 | 0 | } |
134 | | |
135 | | mozilla::ipc::IPCResult |
136 | | PresentationChild::RecvNotifySessionConnect(const uint64_t& aWindowId, |
137 | | const nsString& aSessionId) |
138 | 0 | { |
139 | 0 | if (mService) { |
140 | 0 | Unused << NS_WARN_IF(NS_FAILED(mService->NotifySessionConnect(aWindowId, aSessionId))); |
141 | 0 | } |
142 | 0 | return IPC_OK(); |
143 | 0 | } |
144 | | |
145 | | mozilla::ipc::IPCResult |
146 | | PresentationChild::RecvNotifyCloseSessionTransport(const nsString& aSessionId, |
147 | | const uint8_t& aRole, |
148 | | const nsresult& aReason) |
149 | 0 | { |
150 | 0 | if (mService) { |
151 | 0 | Unused << NS_WARN_IF(NS_FAILED( |
152 | 0 | mService->CloseContentSessionTransport(aSessionId, aRole, aReason))); |
153 | 0 | } |
154 | 0 | return IPC_OK(); |
155 | 0 | } |
156 | | |
157 | | /* |
158 | | * Implementation of PresentationRequestChild |
159 | | */ |
160 | | |
161 | | PresentationRequestChild::PresentationRequestChild(nsIPresentationServiceCallback* aCallback) |
162 | | : mActorDestroyed(false) |
163 | | , mCallback(aCallback) |
164 | 0 | { |
165 | 0 | MOZ_COUNT_CTOR(PresentationRequestChild); |
166 | 0 | } |
167 | | |
168 | | PresentationRequestChild::~PresentationRequestChild() |
169 | 0 | { |
170 | 0 | MOZ_COUNT_DTOR(PresentationRequestChild); |
171 | 0 |
|
172 | 0 | mCallback = nullptr; |
173 | 0 | } |
174 | | |
175 | | void |
176 | | PresentationRequestChild::ActorDestroy(ActorDestroyReason aWhy) |
177 | 0 | { |
178 | 0 | mActorDestroyed = true; |
179 | 0 | mCallback = nullptr; |
180 | 0 | } |
181 | | |
182 | | mozilla::ipc::IPCResult |
183 | | PresentationRequestChild::Recv__delete__(const nsresult& aResult) |
184 | 0 | { |
185 | 0 | if (mActorDestroyed) { |
186 | 0 | return IPC_OK(); |
187 | 0 | } |
188 | 0 |
|
189 | 0 | if (mCallback) { |
190 | 0 | if (NS_FAILED(aResult)) { |
191 | 0 | Unused << NS_WARN_IF(NS_FAILED(mCallback->NotifyError(aResult))); |
192 | 0 | } |
193 | 0 | } |
194 | 0 |
|
195 | 0 | return IPC_OK(); |
196 | 0 | } |
197 | | |
198 | | mozilla::ipc::IPCResult |
199 | | PresentationRequestChild::RecvNotifyRequestUrlSelected(const nsString& aUrl) |
200 | 0 | { |
201 | 0 | Unused << NS_WARN_IF(NS_FAILED(mCallback->NotifySuccess(aUrl))); |
202 | 0 | return IPC_OK(); |
203 | 0 | } |