2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-03-26 06:16:21 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
#include "DCPresentationChannelDescription.h"
|
2016-08-31 15:56:17 +03:00
|
|
|
#include "mozilla/dom/ContentProcessManager.h"
|
2017-03-28 12:05:12 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2015-03-26 06:16:21 +03:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
2016-09-05 02:17:00 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-03-26 06:16:21 +03:00
|
|
|
#include "nsIPresentationDeviceManager.h"
|
2016-09-16 15:59:00 +03:00
|
|
|
#include "nsIPresentationSessionTransport.h"
|
|
|
|
#include "nsIPresentationSessionTransportBuilder.h"
|
2015-03-26 06:16:21 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2016-06-03 06:03:27 +03:00
|
|
|
#include "PresentationBuilderParent.h"
|
2015-03-26 06:16:21 +03:00
|
|
|
#include "PresentationParent.h"
|
|
|
|
#include "PresentationService.h"
|
2016-06-03 06:03:27 +03:00
|
|
|
#include "PresentationSessionInfo.h"
|
2015-03-26 06:16:21 +03:00
|
|
|
|
2016-09-16 15:59:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PresentationTransportBuilderConstructorIPC final
|
|
|
|
: public nsIPresentationTransportBuilderConstructor {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPRESENTATIONTRANSPORTBUILDERCONSTRUCTOR
|
|
|
|
|
|
|
|
explicit PresentationTransportBuilderConstructorIPC(
|
|
|
|
PresentationParent* aParent)
|
|
|
|
: mParent(aParent) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~PresentationTransportBuilderConstructorIPC() = default;
|
|
|
|
|
|
|
|
RefPtr<PresentationParent> mParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(PresentationTransportBuilderConstructorIPC,
|
|
|
|
nsIPresentationTransportBuilderConstructor)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationTransportBuilderConstructorIPC::CreateTransportBuilder(
|
|
|
|
uint8_t aType, nsIPresentationSessionTransportBuilder** aRetval) {
|
|
|
|
if (NS_WARN_IF(!aRetval)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aRetval = nullptr;
|
|
|
|
|
|
|
|
if (NS_WARN_IF(aType != nsIPresentationChannelDescription::TYPE_TCP &&
|
|
|
|
aType !=
|
|
|
|
nsIPresentationChannelDescription::TYPE_DATACHANNEL)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"CreateTransportBuilder can only be invoked in parent process.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationSessionTransportBuilder> builder;
|
|
|
|
if (aType == nsIPresentationChannelDescription::TYPE_TCP) {
|
|
|
|
builder = do_CreateInstance(PRESENTATION_TCP_SESSION_TRANSPORT_CONTRACTID);
|
|
|
|
} else {
|
|
|
|
builder = new PresentationBuilderParent(mParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!builder)) {
|
|
|
|
return NS_ERROR_DOM_OPERATION_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.forget(aRetval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2015-03-26 06:16:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of PresentationParent
|
|
|
|
*/
|
|
|
|
|
2015-09-10 11:29:08 +03:00
|
|
|
NS_IMPL_ISUPPORTS(PresentationParent, nsIPresentationAvailabilityListener,
|
|
|
|
nsIPresentationSessionListener,
|
|
|
|
nsIPresentationRespondingListener)
|
2015-03-26 06:16:21 +03:00
|
|
|
|
|
|
|
PresentationParent::PresentationParent() {}
|
|
|
|
|
|
|
|
/* virtual */ PresentationParent::~PresentationParent() {}
|
|
|
|
|
2016-08-31 15:56:17 +03:00
|
|
|
bool PresentationParent::Init(ContentParentId aContentParentId) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(!mService);
|
|
|
|
mService = do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
2016-08-31 15:56:17 +03:00
|
|
|
mChildId = aContentParentId;
|
2015-03-26 06:16:21 +03:00
|
|
|
return NS_WARN_IF(!mService) ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresentationParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
mActorDestroyed = true;
|
2015-04-22 11:01:38 +03:00
|
|
|
|
2016-04-18 03:19:00 +03:00
|
|
|
for (uint32_t i = 0; i < mSessionIdsAtController.Length(); i++) {
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->UnregisterSessionListener(
|
|
|
|
mSessionIdsAtController[i], nsIPresentationService::ROLE_CONTROLLER)));
|
2015-04-22 11:01:38 +03:00
|
|
|
}
|
2016-04-18 03:19:00 +03:00
|
|
|
mSessionIdsAtController.Clear();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mSessionIdsAtReceiver.Length(); i++) {
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->UnregisterSessionListener(
|
2016-04-18 03:19:00 +03:00
|
|
|
mSessionIdsAtReceiver[i], nsIPresentationService::ROLE_RECEIVER)));
|
|
|
|
}
|
|
|
|
mSessionIdsAtReceiver.Clear();
|
2015-04-22 11:01:38 +03:00
|
|
|
|
2015-09-22 13:36:47 +03:00
|
|
|
for (uint32_t i = 0; i < mWindowIds.Length(); i++) {
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->UnregisterRespondingListener(mWindowIds[i])));
|
2015-09-22 13:36:47 +03:00
|
|
|
}
|
|
|
|
mWindowIds.Clear();
|
|
|
|
|
2016-11-08 06:13:00 +03:00
|
|
|
if (!mContentAvailabilityUrls.IsEmpty()) {
|
|
|
|
mService->UnregisterAvailabilityListener(mContentAvailabilityUrls, this);
|
|
|
|
}
|
2015-03-26 06:16:21 +03:00
|
|
|
mService = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult PresentationParent::RecvPPresentationRequestConstructor(
|
|
|
|
PPresentationRequestParent* aActor,
|
2015-09-14 05:39:57 +03:00
|
|
|
const PresentationIPCRequest& aRequest) {
|
2015-03-26 06:16:21 +03:00
|
|
|
PresentationRequestParent* actor =
|
|
|
|
static_cast<PresentationRequestParent*>(aActor);
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
switch (aRequest.type()) {
|
2015-09-14 05:39:57 +03:00
|
|
|
case PresentationIPCRequest::TStartSessionRequest:
|
2015-03-26 06:16:21 +03:00
|
|
|
rv = actor->DoRequest(aRequest.get_StartSessionRequest());
|
|
|
|
break;
|
2015-09-14 05:39:57 +03:00
|
|
|
case PresentationIPCRequest::TSendSessionMessageRequest:
|
2015-03-26 06:16:21 +03:00
|
|
|
rv = actor->DoRequest(aRequest.get_SendSessionMessageRequest());
|
|
|
|
break;
|
2015-10-08 13:11:10 +03:00
|
|
|
case PresentationIPCRequest::TCloseSessionRequest:
|
|
|
|
rv = actor->DoRequest(aRequest.get_CloseSessionRequest());
|
|
|
|
break;
|
|
|
|
case PresentationIPCRequest::TTerminateSessionRequest:
|
|
|
|
rv = actor->DoRequest(aRequest.get_TerminateSessionRequest());
|
2015-03-26 06:16:21 +03:00
|
|
|
break;
|
2016-08-02 20:11:00 +03:00
|
|
|
case PresentationIPCRequest::TReconnectSessionRequest:
|
|
|
|
rv = actor->DoRequest(aRequest.get_ReconnectSessionRequest());
|
|
|
|
break;
|
|
|
|
case PresentationIPCRequest::TBuildTransportRequest:
|
|
|
|
rv = actor->DoRequest(aRequest.get_BuildTransportRequest());
|
|
|
|
break;
|
2015-03-26 06:16:21 +03:00
|
|
|
default:
|
2015-09-14 05:39:57 +03:00
|
|
|
MOZ_CRASH("Unknown PresentationIPCRequest type");
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PPresentationRequestParent* PresentationParent::AllocPPresentationRequestParent(
|
2015-09-14 05:39:57 +03:00
|
|
|
const PresentationIPCRequest& aRequest) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2016-08-31 15:56:17 +03:00
|
|
|
RefPtr<PresentationRequestParent> actor =
|
|
|
|
new PresentationRequestParent(mService, mChildId);
|
2015-03-26 06:16:21 +03:00
|
|
|
return actor.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PresentationParent::DeallocPPresentationRequestParent(
|
|
|
|
PPresentationRequestParent* aActor) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PresentationRequestParent> actor =
|
2015-03-26 06:16:21 +03:00
|
|
|
dont_AddRef(static_cast<PresentationRequestParent*>(aActor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
PPresentationBuilderParent* PresentationParent::AllocPPresentationBuilderParent(
|
|
|
|
const nsString& aSessionId, const uint8_t& aRole) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"We should never be manually allocating "
|
|
|
|
"AllocPPresentationBuilderParent actors");
|
2016-06-03 06:03:27 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PresentationParent::DeallocPPresentationBuilderParent(
|
|
|
|
PPresentationBuilderParent* aActor) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
mozilla::ipc::IPCResult PresentationParent::Recv__delete__() {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 06:13:00 +03:00
|
|
|
mozilla::ipc::IPCResult PresentationParent::RecvRegisterAvailabilityHandler(
|
|
|
|
nsTArray<nsString>&& aAvailabilityUrls) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2016-11-08 06:13:00 +03:00
|
|
|
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(
|
|
|
|
mService->RegisterAvailabilityListener(aAvailabilityUrls, this)));
|
|
|
|
mContentAvailabilityUrls.AppendElements(aAvailabilityUrls);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-08 06:13:00 +03:00
|
|
|
mozilla::ipc::IPCResult PresentationParent::RecvUnregisterAvailabilityHandler(
|
|
|
|
nsTArray<nsString>&& aAvailabilityUrls) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2016-11-08 06:13:00 +03:00
|
|
|
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(
|
|
|
|
mService->UnregisterAvailabilityListener(aAvailabilityUrls, this)));
|
|
|
|
for (const auto& url : aAvailabilityUrls) {
|
|
|
|
mContentAvailabilityUrls.RemoveElement(url);
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
/* virtual */ mozilla::ipc::IPCResult
|
2016-04-18 03:19:00 +03:00
|
|
|
PresentationParent::RecvRegisterSessionHandler(const nsString& aSessionId,
|
|
|
|
const uint8_t& aRole) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2015-08-31 08:24:35 +03:00
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
2016-04-18 03:19:00 +03:00
|
|
|
->IsSessionAccessible(aSessionId, aRole, OtherPid()))) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-08-31 08:24:35 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 03:19:00 +03:00
|
|
|
if (nsIPresentationService::ROLE_CONTROLLER == aRole) {
|
|
|
|
mSessionIdsAtController.AppendElement(aSessionId);
|
|
|
|
} else {
|
|
|
|
mSessionIdsAtReceiver.AppendElement(aSessionId);
|
|
|
|
}
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->RegisterSessionListener(aSessionId, aRole, this)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
/* virtual */ mozilla::ipc::IPCResult
|
2016-04-18 03:19:00 +03:00
|
|
|
PresentationParent::RecvUnregisterSessionHandler(const nsString& aSessionId,
|
|
|
|
const uint8_t& aRole) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2016-04-18 03:19:00 +03:00
|
|
|
if (nsIPresentationService::ROLE_CONTROLLER == aRole) {
|
|
|
|
mSessionIdsAtController.RemoveElement(aSessionId);
|
|
|
|
} else {
|
|
|
|
mSessionIdsAtReceiver.RemoveElement(aSessionId);
|
|
|
|
}
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->UnregisterSessionListener(aSessionId, aRole)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
/* virtual */ mozilla::ipc::IPCResult
|
2015-09-10 11:29:08 +03:00
|
|
|
PresentationParent::RecvRegisterRespondingHandler(const uint64_t& aWindowId) {
|
|
|
|
MOZ_ASSERT(mService);
|
2015-09-22 13:36:47 +03:00
|
|
|
|
|
|
|
mWindowIds.AppendElement(aWindowId);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->RegisterRespondingListener(aWindowId, this)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-09-10 11:29:08 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
/* virtual */ mozilla::ipc::IPCResult
|
2015-09-10 11:29:08 +03:00
|
|
|
PresentationParent::RecvUnregisterRespondingHandler(const uint64_t& aWindowId) {
|
|
|
|
MOZ_ASSERT(mService);
|
2015-09-22 13:36:47 +03:00
|
|
|
mWindowIds.RemoveElement(aWindowId);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->UnregisterRespondingListener(aWindowId)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-09-10 11:29:08 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
NS_IMETHODIMP
|
2016-11-08 06:13:00 +03:00
|
|
|
PresentationParent::NotifyAvailableChange(
|
|
|
|
const nsTArray<nsString>& aAvailabilityUrls, bool aAvailable) {
|
|
|
|
if (NS_WARN_IF(mActorDestroyed ||
|
|
|
|
!SendNotifyAvailableChange(aAvailabilityUrls, aAvailable))) {
|
2015-03-26 06:16:21 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifyStateChange(const nsAString& aSessionId,
|
2016-05-30 09:48:00 +03:00
|
|
|
uint16_t aState, nsresult aReason) {
|
2015-03-26 06:16:21 +03:00
|
|
|
if (NS_WARN_IF(mActorDestroyed ||
|
2016-05-30 09:48:00 +03:00
|
|
|
!SendNotifySessionStateChange(nsString(aSessionId), aState,
|
|
|
|
aReason))) {
|
2015-03-26 06:16:21 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifyMessage(const nsAString& aSessionId,
|
2016-09-18 02:42:00 +03:00
|
|
|
const nsACString& aData, bool aIsBinary) {
|
2015-03-26 06:16:21 +03:00
|
|
|
if (NS_WARN_IF(mActorDestroyed ||
|
2016-09-18 02:42:00 +03:00
|
|
|
!SendNotifyMessage(nsString(aSessionId), nsCString(aData),
|
|
|
|
aIsBinary))) {
|
2015-03-26 06:16:21 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-10 11:29:08 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifySessionConnect(uint64_t aWindowId,
|
|
|
|
const nsAString& aSessionId) {
|
|
|
|
if (NS_WARN_IF(mActorDestroyed ||
|
2016-04-11 06:20:55 +03:00
|
|
|
!SendNotifySessionConnect(aWindowId, nsString(aSessionId)))) {
|
2015-09-10 11:29:08 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-25 03:20:00 +03:00
|
|
|
mozilla::ipc::IPCResult PresentationParent::RecvNotifyReceiverReady(
|
2016-08-04 04:46:14 +03:00
|
|
|
const nsString& aSessionId, const uint64_t& aWindowId,
|
|
|
|
const bool& aIsLoading) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2016-04-11 06:20:55 +03:00
|
|
|
|
2016-09-16 15:59:00 +03:00
|
|
|
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
|
|
|
|
new PresentationTransportBuilderConstructorIPC(this);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->NotifyReceiverReady(
|
2016-09-16 15:59:00 +03:00
|
|
|
aSessionId, aWindowId, aIsLoading, constructor)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
mozilla::ipc::IPCResult PresentationParent::RecvNotifyTransportClosed(
|
|
|
|
const nsString& aSessionId, const uint8_t& aRole, const nsresult& aReason) {
|
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(mService->NotifyTransportClosed(aSessionId, aRole, aReason)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-06-03 06:03:27 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
/*
|
|
|
|
* Implementation of PresentationRequestParent
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(PresentationRequestParent, nsIPresentationServiceCallback)
|
|
|
|
|
2016-08-31 15:56:17 +03:00
|
|
|
PresentationRequestParent::PresentationRequestParent(
|
|
|
|
nsIPresentationService* aService, ContentParentId aContentParentId)
|
|
|
|
: mService(aService), mChildId(aContentParentId) {}
|
2015-03-26 06:16:21 +03:00
|
|
|
|
|
|
|
PresentationRequestParent::~PresentationRequestParent() {}
|
|
|
|
|
|
|
|
void PresentationRequestParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
mActorDestroyed = true;
|
|
|
|
mService = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const StartSessionRequest& aRequest) {
|
|
|
|
MOZ_ASSERT(mService);
|
2016-09-16 15:59:00 +03:00
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
mSessionId = aRequest.sessionId();
|
2016-08-31 15:56:17 +03:00
|
|
|
|
2018-04-20 07:49:30 +03:00
|
|
|
RefPtr<EventTarget> eventTarget;
|
2016-08-31 15:56:17 +03:00
|
|
|
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
2019-04-10 00:38:15 +03:00
|
|
|
RefPtr<BrowserParent> tp = cpm->GetTopLevelBrowserParentByProcessAndTabId(
|
|
|
|
mChildId, aRequest.tabId());
|
2016-08-31 15:56:17 +03:00
|
|
|
if (tp) {
|
2018-04-20 07:49:30 +03:00
|
|
|
eventTarget = tp->GetOwnerElement();
|
2016-08-31 15:56:17 +03:00
|
|
|
}
|
2016-09-16 15:59:00 +03:00
|
|
|
|
|
|
|
RefPtr<PresentationParent> parent =
|
|
|
|
static_cast<PresentationParent*>(Manager());
|
|
|
|
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
|
|
|
|
new PresentationTransportBuilderConstructorIPC(parent);
|
2016-09-05 02:17:00 +03:00
|
|
|
return mService->StartSession(aRequest.urls(), aRequest.sessionId(),
|
2016-05-25 03:20:00 +03:00
|
|
|
aRequest.origin(), aRequest.deviceId(),
|
2016-10-04 09:27:05 +03:00
|
|
|
aRequest.windowId(), eventTarget,
|
|
|
|
aRequest.principal(), this, constructor);
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const SendSessionMessageRequest& aRequest) {
|
|
|
|
MOZ_ASSERT(mService);
|
2015-08-31 08:24:35 +03:00
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
2016-04-18 03:19:00 +03:00
|
|
|
->IsSessionAccessible(aRequest.sessionId(),
|
|
|
|
aRequest.role(), OtherPid()))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_ERROR_DOM_SECURITY_ERR);
|
2015-08-31 08:24:35 +03:00
|
|
|
}
|
|
|
|
|
2016-04-11 06:20:55 +03:00
|
|
|
nsresult rv = mService->SendSessionMessage(aRequest.sessionId(),
|
|
|
|
aRequest.role(), aRequest.data());
|
2015-03-26 06:16:21 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(rv);
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_OK);
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2015-10-08 13:11:10 +03:00
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const CloseSessionRequest& aRequest) {
|
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
2016-04-18 03:19:00 +03:00
|
|
|
->IsSessionAccessible(aRequest.sessionId(),
|
|
|
|
aRequest.role(), OtherPid()))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_ERROR_DOM_SECURITY_ERR);
|
2015-10-08 13:11:10 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:48:00 +03:00
|
|
|
nsresult rv = mService->CloseSession(aRequest.sessionId(), aRequest.role(),
|
|
|
|
aRequest.closedReason());
|
2015-10-08 13:11:10 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(rv);
|
2015-10-08 13:11:10 +03:00
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_OK);
|
2015-10-08 13:11:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const TerminateSessionRequest& aRequest) {
|
2015-03-26 06:16:21 +03:00
|
|
|
MOZ_ASSERT(mService);
|
2015-08-31 08:24:35 +03:00
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
2016-04-18 03:19:00 +03:00
|
|
|
->IsSessionAccessible(aRequest.sessionId(),
|
|
|
|
aRequest.role(), OtherPid()))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_ERROR_DOM_SECURITY_ERR);
|
2015-08-31 08:24:35 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 03:19:00 +03:00
|
|
|
nsresult rv =
|
|
|
|
mService->TerminateSession(aRequest.sessionId(), aRequest.role());
|
2015-03-26 06:16:21 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(rv);
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_OK);
|
2015-03-26 06:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-08-02 20:11:00 +03:00
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const ReconnectSessionRequest& aRequest) {
|
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
|
|
|
->IsSessionAccessible(aRequest.sessionId(),
|
|
|
|
aRequest.role(), OtherPid()))) {
|
|
|
|
// NOTE: Return NS_ERROR_DOM_NOT_FOUND_ERR here to match the spec.
|
|
|
|
// https://w3c.github.io/presentation-api/#reconnecting-to-a-presentation
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_ERROR_DOM_NOT_FOUND_ERR);
|
2016-08-02 20:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mSessionId = aRequest.sessionId();
|
2016-09-05 02:17:00 +03:00
|
|
|
return mService->ReconnectSession(aRequest.urls(), aRequest.sessionId(),
|
2016-08-02 20:11:00 +03:00
|
|
|
aRequest.role(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresentationRequestParent::DoRequest(
|
|
|
|
const BuildTransportRequest& aRequest) {
|
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
|
|
|
// Validate the accessibility (primarily for receiver side) so that a
|
|
|
|
// compromised child process can't fake the ID.
|
|
|
|
if (NS_WARN_IF(!static_cast<PresentationService*>(mService.get())
|
|
|
|
->IsSessionAccessible(aRequest.sessionId(),
|
|
|
|
aRequest.role(), OtherPid()))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_ERROR_DOM_SECURITY_ERR);
|
2016-08-02 20:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mService->BuildTransport(aRequest.sessionId(), aRequest.role());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(rv);
|
2016-08-02 20:11:00 +03:00
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
return SendResponse(NS_OK);
|
2016-08-02 20:11:00 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
NS_IMETHODIMP
|
2016-09-05 02:17:00 +03:00
|
|
|
PresentationRequestParent::NotifySuccess(const nsAString& aUrl) {
|
|
|
|
Unused << SendNotifyRequestUrlSelected(nsString(aUrl));
|
2015-03-26 06:16:21 +03:00
|
|
|
return SendResponse(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationRequestParent::NotifyError(nsresult aError) {
|
|
|
|
return SendResponse(aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PresentationRequestParent::SendResponse(nsresult aResult) {
|
|
|
|
if (NS_WARN_IF(mActorDestroyed || !Send__delete__(this, aResult))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-09-16 15:59:00 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|