mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
d6926a176f
- Bug 1214179 - Provide device Id for non-discoverable controller. r=xeonchen (0c83743144)
- Bug 1194606 - Add gtest for demuxed-only scenario in MediaFormatReader. r=jya (67a5e19042)
- Bug 1154513 - [EME] GMP crash crashes browser in Nightly - Remember if actor is destroyed, so that no messages are sent from subsequent Shutdown() - r=cpearce (36109a68e8)
- Bug 1171499 - Defer processing GMP EncodingComplete() calls until intr shmem allocs are finished. r=jesup (bac114c170)
- Bug 1162358 - Defer processing GMP DecodingComplete() calls until intr shmem allocs are finished. r=jesup (4b91da11f0)
- Bug 1155178 - Part 1: Convert GMPUnique into a template alias; r=cpearce (3f8ba45b9f)
- Bug 1155178 - Part 2: Rename GMPUnique to GMPUniquePtr; r=cpearce (fa1fd17384)
- Bug 1160908 - [EME] Delete GMPRecords that are 0 bytes in size. r=cpearce (3cc4ad2772)
- Bug 1188235 - Make GMPStorage immune to record name hash collisions. r=gerald (ae6c32363b)
- Bug 1187163 - Ensure we send Reset/Drain complete notifications no matter what happens in GMP{Audio,Video}Decoder. r=gerald (5654321861)
- Bug 1194576 - Add more NSPR logging around GMP*Parent actors. r=gerald (7572f82456)
- Bug 1169129 - Change GMP*Parent::ParentId() to a more consistent GMP*Parent::GetPluginId(). r=edwin (ce2dd08740)
- Bug 1208289 - Log outstanding frames in GMP DrainComplete() and detect dropped ResetComplete. r=jwwang (6e29c332a7)
- Bug 1208289 - Add SimpleTimer to make setting timeouts in C++ easy. r=jwwang (b4c179dc5b)
- Bug 1131908 - no IPC calls after GMPDecryptorChild::RecvDecryptingComplete(). r=edwin. (cb3d2df998)
- Bug 1215508: Fix the race in accessing the unopened IPC channels in TabChild::PreloadSlowThings(). r=khuey (c43fcb1530)
- bits of 1216401 (bb15f26885)
- Bug 1205219 - [Presentation WebAPI] Support terminate semantics. Part 1 - WebIDL & implementation changes. r=smaug (8e485cdec8)
- Bug 1205219 - [Presentation WebAPI] Support terminate semantics. Part 2 - Tests. r=smaug (e16de5d102)
- Bug 1178858 - Video would not playback after seek seekbar first if media.autoplay.enabled = false. r=cpearce (68bae0db50)
- Bug 1072150 - Introduce a transitional legacy API that works like things used to. r=bz Bug 1072150 - Use the opt-out for various sloppy consumers. r=bz (703304f396)
301 lines
8.0 KiB
C++
301 lines
8.0 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
/* 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 "mozilla/AsyncEventDispatcher.h"
|
|
#include "mozilla/dom/MessageEvent.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsIPresentationService.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "nsStringStream.h"
|
|
#include "PresentationSession.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(PresentationSession)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PresentationSession, DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PresentationSession, DOMEventTargetHelper)
|
|
tmp->Shutdown();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_ADDREF_INHERITED(PresentationSession, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(PresentationSession, DOMEventTargetHelper)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PresentationSession)
|
|
NS_INTERFACE_MAP_ENTRY(nsIPresentationSessionListener)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
PresentationSession::PresentationSession(nsPIDOMWindow* aWindow,
|
|
const nsAString& aId,
|
|
PresentationSessionState aState)
|
|
: DOMEventTargetHelper(aWindow)
|
|
, mId(aId)
|
|
, mState(aState)
|
|
{
|
|
}
|
|
|
|
/* virtual */ PresentationSession::~PresentationSession()
|
|
{
|
|
}
|
|
|
|
/* static */ already_AddRefed<PresentationSession>
|
|
PresentationSession::Create(nsPIDOMWindow* aWindow,
|
|
const nsAString& aId,
|
|
PresentationSessionState aState)
|
|
{
|
|
RefPtr<PresentationSession> session =
|
|
new PresentationSession(aWindow, aId, aState);
|
|
return NS_WARN_IF(!session->Init()) ? nullptr : session.forget();
|
|
}
|
|
|
|
bool
|
|
PresentationSession::Init()
|
|
{
|
|
if (NS_WARN_IF(mId.IsEmpty())) {
|
|
return false;
|
|
}
|
|
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if(NS_WARN_IF(!service)) {
|
|
return false;
|
|
}
|
|
|
|
nsresult rv = service->RegisterSessionListener(mId, this);
|
|
if(NS_WARN_IF(NS_FAILED(rv))) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void
|
|
PresentationSession::Shutdown()
|
|
{
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if (NS_WARN_IF(!service)) {
|
|
return;
|
|
}
|
|
|
|
nsresult rv = service->UnregisterSessionListener(mId);
|
|
NS_WARN_IF(NS_FAILED(rv));
|
|
}
|
|
|
|
/* virtual */ void
|
|
PresentationSession::DisconnectFromOwner()
|
|
{
|
|
Shutdown();
|
|
DOMEventTargetHelper::DisconnectFromOwner();
|
|
}
|
|
|
|
/* virtual */ JSObject*
|
|
PresentationSession::WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return PresentationSessionBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
void
|
|
PresentationSession::GetId(nsAString& aId) const
|
|
{
|
|
aId = mId;
|
|
}
|
|
|
|
PresentationSessionState
|
|
PresentationSession::State() const
|
|
{
|
|
return mState;
|
|
}
|
|
|
|
void
|
|
PresentationSession::Send(const nsAString& aData,
|
|
ErrorResult& aRv)
|
|
{
|
|
// Sending is not allowed if the session is not connected.
|
|
if (NS_WARN_IF(mState != PresentationSessionState::Connected)) {
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
return;
|
|
}
|
|
|
|
nsresult rv;
|
|
nsCOMPtr<nsIStringInputStream> stream =
|
|
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
|
|
if(NS_WARN_IF(NS_FAILED(rv))) {
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
return;
|
|
}
|
|
|
|
NS_ConvertUTF16toUTF8 msgString(aData);
|
|
rv = stream->SetData(msgString.BeginReading(), msgString.Length());
|
|
if(NS_WARN_IF(NS_FAILED(rv))) {
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
return;
|
|
}
|
|
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if(NS_WARN_IF(!service)) {
|
|
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
|
|
return;
|
|
}
|
|
|
|
rv = service->SendSessionMessage(mId, stream);
|
|
if(NS_WARN_IF(NS_FAILED(rv))) {
|
|
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
|
|
}
|
|
}
|
|
|
|
void
|
|
PresentationSession::Close(ErrorResult& aRv)
|
|
{
|
|
// It only works when the state is CONNECTED.
|
|
if (NS_WARN_IF(mState != PresentationSessionState::Connected)) {
|
|
return;
|
|
}
|
|
|
|
// TODO Bug 1210340 - Support close semantics.
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
}
|
|
|
|
void
|
|
PresentationSession::Terminate(ErrorResult& aRv)
|
|
{
|
|
// It only works when the state is CONNECTED.
|
|
if (NS_WARN_IF(mState != PresentationSessionState::Connected)) {
|
|
return;
|
|
}
|
|
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if(NS_WARN_IF(!service)) {
|
|
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
|
|
return;
|
|
}
|
|
|
|
NS_WARN_IF(NS_FAILED(service->TerminateSession(mId)));
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
PresentationSession::NotifyStateChange(const nsAString& aSessionId,
|
|
uint16_t aState)
|
|
{
|
|
if (!aSessionId.Equals(mId)) {
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
PresentationSessionState state;
|
|
switch (aState) {
|
|
case nsIPresentationSessionListener::STATE_CONNECTED:
|
|
state = PresentationSessionState::Connected;
|
|
break;
|
|
case nsIPresentationSessionListener::STATE_CLOSED:
|
|
state = PresentationSessionState::Closed;
|
|
break;
|
|
case nsIPresentationSessionListener::STATE_TERMINATED:
|
|
state = PresentationSessionState::Terminated;
|
|
break;
|
|
default:
|
|
NS_WARNING("Unknown presentation session state.");
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
if (mState == state) {
|
|
return NS_OK;
|
|
}
|
|
|
|
mState = state;
|
|
|
|
// Unregister session listener if the session is no longer connected.
|
|
if (mState == PresentationSessionState::Terminated) {
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if (NS_WARN_IF(!service)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
nsresult rv = service->UnregisterSessionListener(mId);
|
|
if(NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
}
|
|
|
|
return DispatchStateChangeEvent();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
PresentationSession::NotifyMessage(const nsAString& aSessionId,
|
|
const nsACString& aData)
|
|
{
|
|
if (!aSessionId.Equals(mId)) {
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
// No message should be expected when the session is not connected.
|
|
if (NS_WARN_IF(mState != PresentationSessionState::Connected)) {
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
}
|
|
|
|
// Transform the data.
|
|
AutoJSAPI jsapi;
|
|
if (!jsapi.Init(GetOwner())) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
JSContext* cx = jsapi.cx();
|
|
JS::Rooted<JS::Value> jsData(cx);
|
|
NS_ConvertUTF8toUTF16 utf16Data(aData);
|
|
if(NS_WARN_IF(!ToJSValue(cx, utf16Data, &jsData))) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return DispatchMessageEvent(jsData);
|
|
}
|
|
|
|
nsresult
|
|
PresentationSession::DispatchStateChangeEvent()
|
|
{
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
new AsyncEventDispatcher(this, NS_LITERAL_STRING("statechange"), false);
|
|
return asyncDispatcher->PostDOMEvent();
|
|
}
|
|
|
|
nsresult
|
|
PresentationSession::DispatchMessageEvent(JS::Handle<JS::Value> aData)
|
|
{
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
if (NS_WARN_IF(!global)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
// Get the origin.
|
|
nsAutoString origin;
|
|
nsresult rv = nsContentUtils::GetUTFOrigin(global->PrincipalOrNull(), origin);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
RefPtr<MessageEvent> messageEvent =
|
|
NS_NewDOMMessageEvent(this, nullptr, nullptr);
|
|
|
|
rv = messageEvent->InitMessageEvent(NS_LITERAL_STRING("message"),
|
|
false, false,
|
|
aData,
|
|
origin,
|
|
EmptyString(), nullptr);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return rv;
|
|
}
|
|
|
|
messageEvent->SetTrusted(true);
|
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
new AsyncEventDispatcher(this, static_cast<Event*>(messageEvent));
|
|
return asyncDispatcher->PostDOMEvent();
|
|
}
|