2015-03-26 06:16:21 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=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/. */
|
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
#include "DCPresentationChannelDescription.h"
|
2016-08-31 15:56:17 +03:00
|
|
|
#include "mozilla/dom/ContentProcessManager.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"
|
|
|
|
#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 05:31:32 +03:00
|
|
|
using namespace mozilla::dom;
|
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()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(PresentationParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ PresentationParent::~PresentationParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(PresentationParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-08-31 15:56:17 +03:00
|
|
|
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->
|
2016-04-18 03:19:00 +03:00
|
|
|
UnregisterSessionListener(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();
|
|
|
|
|
2015-09-10 11:29:08 +03:00
|
|
|
mService->UnregisterAvailabilityListener(this);
|
2015-03-26 06:16:21 +03:00
|
|
|
mService = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return NS_WARN_IF(NS_FAILED(rv)) ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("We should never be manually allocating AllocPPresentationBuilderParent actors");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PresentationParent::DeallocPPresentationBuilderParent(
|
|
|
|
PPresentationBuilderParent* aActor)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
bool
|
|
|
|
PresentationParent::Recv__delete__()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-09-10 11:29:08 +03:00
|
|
|
PresentationParent::RecvRegisterAvailabilityHandler()
|
2015-03-26 06:16:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mService);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->RegisterAvailabilityListener(this)));
|
2015-03-26 06:16:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-09-10 11:29:08 +03:00
|
|
|
PresentationParent::RecvUnregisterAvailabilityHandler()
|
2015-03-26 06:16:21 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mService);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->UnregisterAvailabilityListener(this)));
|
2015-03-26 06:16:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ bool
|
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()))) {
|
2015-08-31 08:24:35 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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)));
|
2015-03-26 06:16:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ bool
|
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)));
|
2015-03-26 06:16:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 11:29:08 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
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)));
|
2015-09-10 11:29:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
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)));
|
2015-09-10 11:29:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-16 05:31:32 +03:00
|
|
|
bool
|
|
|
|
PresentationParent::RegisterTransportBuilder(const nsString& aSessionId,
|
|
|
|
const uint8_t& aRole)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mService);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationSessionTransportBuilder> builder =
|
|
|
|
new PresentationBuilderParent(this);
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(static_cast<PresentationService*>(mService.get())->
|
|
|
|
RegisterTransportBuilder(aSessionId, aRole, builder)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifyAvailableChange(bool aAvailable)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(mActorDestroyed || !SendNotifyAvailableChange(aAvailable))) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:11:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifyReplaced()
|
|
|
|
{
|
|
|
|
// Do nothing here, since |PresentationIPCService::RegisterSessionListener|
|
|
|
|
// already dealt with this in content process.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PresentationParent::NotifyMessage(const nsAString& aSessionId,
|
|
|
|
const nsACString& aData)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(mActorDestroyed ||
|
2016-04-11 06:20:55 +03:00
|
|
|
!SendNotifyMessage(nsString(aSessionId), nsCString(aData)))) {
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-26 06:16:21 +03:00
|
|
|
bool
|
2016-05-25 03:20:00 +03:00
|
|
|
PresentationParent::RecvNotifyReceiverReady(const nsString& aSessionId,
|
2016-08-04 04:46:14 +03:00
|
|
|
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 05:31:32 +03:00
|
|
|
RegisterTransportBuilder(aSessionId, nsIPresentationService::ROLE_RECEIVER);
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(mService->NotifyReceiverReady(aSessionId,
|
|
|
|
aWindowId,
|
2016-09-16 05:31:32 +03:00
|
|
|
aIsLoading)));
|
2015-03-26 06:16:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-03 06:03:27 +03:00
|
|
|
bool
|
|
|
|
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-06-03 06:03:27 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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)
|
2016-06-03 06:03:27 +03:00
|
|
|
: mService(aService)
|
2016-08-31 15:56:17 +03:00
|
|
|
, mChildId(aContentParentId)
|
2015-03-26 06:16:21 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(PresentationRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
PresentationRequestParent::~PresentationRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(PresentationRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PresentationRequestParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
mActorDestroyed = true;
|
|
|
|
mService = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PresentationRequestParent::DoRequest(const StartSessionRequest& aRequest)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mService);
|
2016-09-16 05:31:32 +03:00
|
|
|
mNeedRegisterBuilder = true;
|
2016-06-03 06:03:27 +03:00
|
|
|
mSessionId = aRequest.sessionId();
|
2016-08-31 15:56:17 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> eventTarget;
|
|
|
|
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
|
|
|
RefPtr<TabParent> tp =
|
|
|
|
cpm->GetTopLevelTabParentByProcessAndTabId(mChildId, aRequest.tabId());
|
|
|
|
if (tp) {
|
|
|
|
eventTarget = do_QueryInterface(tp->GetOwnerElement());
|
|
|
|
}
|
2016-09-16 05:31:32 +03:00
|
|
|
|
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-09-16 05:31:32 +03:00
|
|
|
aRequest.windowId(), eventTarget, this);
|
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(),
|
2016-04-18 03:19:00 +03:00
|
|
|
aRequest.role(),
|
2016-04-11 06:20:55 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-10-08 13:11:10 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-16 05:31:32 +03:00
|
|
|
mNeedRegisterBuilder = true;
|
2016-08-02 20:11:00 +03:00
|
|
|
mSessionId = aRequest.sessionId();
|
2016-09-05 02:17:00 +03:00
|
|
|
return mService->ReconnectSession(aRequest.urls(),
|
2016-08-02 20:11:00 +03:00
|
|
|
aRequest.sessionId(),
|
|
|
|
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)
|
2015-03-26 06:16:21 +03:00
|
|
|
{
|
2016-09-16 05:31:32 +03:00
|
|
|
if (mNeedRegisterBuilder) {
|
|
|
|
RefPtr<PresentationParent> parent = static_cast<PresentationParent*>(Manager());
|
|
|
|
Unused << NS_WARN_IF(!parent->RegisterTransportBuilder(
|
|
|
|
mSessionId,
|
|
|
|
nsIPresentationService::ROLE_CONTROLLER));
|
|
|
|
}
|
|
|
|
|
2016-09-05 02:17:00 +03:00
|
|
|
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;
|
|
|
|
}
|