diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/presentation/ipc/PresentationBuilderParent.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/presentation/ipc/PresentationBuilderParent.cpp')
-rw-r--r-- | dom/presentation/ipc/PresentationBuilderParent.cpp | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/dom/presentation/ipc/PresentationBuilderParent.cpp b/dom/presentation/ipc/PresentationBuilderParent.cpp new file mode 100644 index 000000000..dc784b13c --- /dev/null +++ b/dom/presentation/ipc/PresentationBuilderParent.cpp @@ -0,0 +1,267 @@ +/* -*- 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/. */ + +#include "DCPresentationChannelDescription.h" +#include "PresentationBuilderParent.h" +#include "PresentationSessionInfo.h" + +namespace mozilla { +namespace dom { + +namespace { + +class PresentationSessionTransportIPC final : + public nsIPresentationSessionTransport +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPRESENTATIONSESSIONTRANSPORT + + PresentationSessionTransportIPC(PresentationParent* aParent, + const nsAString& aSessionId, + uint8_t aRole) + : mParent(aParent) + , mSessionId(aSessionId) + , mRole(aRole) + { + MOZ_ASSERT(mParent); + } + +private: + virtual ~PresentationSessionTransportIPC() = default; + + RefPtr<PresentationParent> mParent; + nsString mSessionId; + uint8_t mRole; +}; + +NS_IMPL_ISUPPORTS(PresentationSessionTransportIPC, + nsIPresentationSessionTransport) + +NS_IMETHODIMP +PresentationSessionTransportIPC::GetCallback( + nsIPresentationSessionTransportCallback** aCallback) +{ + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::SetCallback( + nsIPresentationSessionTransportCallback* aCallback) +{ + if (aCallback) { + aCallback->NotifyTransportReady(); + } + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::GetSelfAddress(nsINetAddr** aSelfAddress) +{ + MOZ_ASSERT(false, "Not expected."); + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::EnableDataNotification() +{ + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::Send(const nsAString& aData) +{ + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::SendBinaryMsg(const nsACString& aData) +{ + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::SendBlob(nsIDOMBlob* aBlob) +{ + return NS_OK; +} + +NS_IMETHODIMP +PresentationSessionTransportIPC::Close(nsresult aReason) +{ + if (NS_WARN_IF(!mParent->SendNotifyCloseSessionTransport(mSessionId, + mRole, + aReason))) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +} // anonymous namespace + +NS_IMPL_ISUPPORTS(PresentationBuilderParent, + nsIPresentationSessionTransportBuilder, + nsIPresentationDataChannelSessionTransportBuilder) + +PresentationBuilderParent::PresentationBuilderParent(PresentationParent* aParent) + : mParent(aParent) +{ + MOZ_COUNT_CTOR(PresentationBuilderParent); +} + +PresentationBuilderParent::~PresentationBuilderParent() +{ + MOZ_COUNT_DTOR(PresentationBuilderParent); + + if (mNeedDestroyActor) { + Unused << NS_WARN_IF(!Send__delete__(this)); + } +} + +NS_IMETHODIMP +PresentationBuilderParent::BuildDataChannelTransport( + uint8_t aRole, + mozIDOMWindow* aWindow, /* unused */ + nsIPresentationSessionTransportBuilderListener* aListener) +{ + mBuilderListener = aListener; + + RefPtr<PresentationSessionInfo> info = static_cast<PresentationSessionInfo*>(aListener); + nsAutoString sessionId(info->GetSessionId()); + if (NS_WARN_IF(!mParent->SendPPresentationBuilderConstructor(this, + sessionId, + aRole))) { + return NS_ERROR_FAILURE; + } + mIPCSessionTransport = new PresentationSessionTransportIPC(mParent, + sessionId, + aRole); + mNeedDestroyActor = true; + mParent = nullptr; + return NS_OK; +} + +NS_IMETHODIMP +PresentationBuilderParent::OnIceCandidate(const nsAString& aCandidate) +{ + if (NS_WARN_IF(!SendOnIceCandidate(nsString(aCandidate)))){ + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +PresentationBuilderParent::OnOffer(nsIPresentationChannelDescription* aDescription) +{ + nsAutoString SDP; + nsresult rv = aDescription->GetDataChannelSDP(SDP); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + if (NS_WARN_IF(!SendOnOffer(SDP))){ + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +PresentationBuilderParent::OnAnswer(nsIPresentationChannelDescription* aDescription) +{ + nsAutoString SDP; + nsresult rv = aDescription->GetDataChannelSDP(SDP); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + if (NS_WARN_IF(!SendOnAnswer(SDP))){ + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +PresentationBuilderParent::NotifyDisconnected(nsresult aReason) +{ + return NS_OK; +} + +void +PresentationBuilderParent::ActorDestroy(ActorDestroyReason aWhy) +{ + mNeedDestroyActor = false; + mParent = nullptr; + mBuilderListener = nullptr; +} + +bool +PresentationBuilderParent::RecvSendOffer(const nsString& aSDP) +{ + RefPtr<DCPresentationChannelDescription> description = + new DCPresentationChannelDescription(aSDP); + if (NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->SendOffer(description)))) { + return false; + } + return true; +} + +bool +PresentationBuilderParent::RecvSendAnswer(const nsString& aSDP) +{ + RefPtr<DCPresentationChannelDescription> description = + new DCPresentationChannelDescription(aSDP); + if (NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->SendAnswer(description)))) { + return false; + } + return true; +} + +bool +PresentationBuilderParent::RecvSendIceCandidate(const nsString& aCandidate) +{ + if (NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->SendIceCandidate(aCandidate)))) { + return false; + } + return true; +} + +bool +PresentationBuilderParent::RecvClose(const nsresult& aReason) +{ + if (NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->Close(aReason)))) { + return false; + } + return true; +} + +// Delegate to nsIPresentationSessionTransportBuilderListener +bool +PresentationBuilderParent::RecvOnSessionTransport() +{ + RefPtr<PresentationBuilderParent> kungFuDeathGrip = this; + Unused << + NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->OnSessionTransport(mIPCSessionTransport))); + return true; +} + +bool +PresentationBuilderParent::RecvOnSessionTransportError(const nsresult& aReason) +{ + if (NS_WARN_IF(!mBuilderListener || + NS_FAILED(mBuilderListener->OnError(aReason)))) { + return false; + } + return true; +} + +} // namespace dom +} // namespace mozilla |