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