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