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)
221 lines
6.1 KiB
C++
221 lines
6.1 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/PresentationBinding.h"
|
|
#include "mozilla/dom/Promise.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsIPresentationDeviceManager.h"
|
|
#include "nsIPresentationService.h"
|
|
#include "nsIUUIDGenerator.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "Presentation.h"
|
|
#include "PresentationCallbacks.h"
|
|
#include "PresentationSession.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Presentation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Presentation, DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDefaultRequest)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSessions)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingGetSessionPromises)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Presentation, DOMEventTargetHelper)
|
|
tmp->Shutdown();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDefaultRequest)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSessions)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingGetSessionPromises)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Presentation, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(Presentation, DOMEventTargetHelper)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Presentation)
|
|
NS_INTERFACE_MAP_ENTRY(nsIPresentationRespondingListener)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
/* static */ already_AddRefed<Presentation>
|
|
Presentation::Create(nsPIDOMWindow* aWindow)
|
|
{
|
|
RefPtr<Presentation> presentation = new Presentation(aWindow);
|
|
return NS_WARN_IF(!presentation->Init()) ? nullptr : presentation.forget();
|
|
}
|
|
|
|
Presentation::Presentation(nsPIDOMWindow* aWindow)
|
|
: DOMEventTargetHelper(aWindow)
|
|
{
|
|
}
|
|
|
|
Presentation::~Presentation()
|
|
{
|
|
Shutdown();
|
|
}
|
|
|
|
bool
|
|
Presentation::Init()
|
|
{
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if (NS_WARN_IF(!service)) {
|
|
return false;
|
|
}
|
|
|
|
if (NS_WARN_IF(!GetOwner())) {
|
|
return false;
|
|
}
|
|
mWindowId = GetOwner()->WindowID();
|
|
|
|
// Check if a session instance is required now. A session may already be
|
|
// connecting before the web content gets loaded in a presenting browsing
|
|
// context (receiver).
|
|
nsAutoString sessionId;
|
|
nsresult rv = service->GetExistentSessionIdAtLaunch(mWindowId, sessionId);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return false;
|
|
}
|
|
if (!sessionId.IsEmpty()) {
|
|
rv = NotifySessionConnect(mWindowId, sessionId);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Register listener for incoming sessions.
|
|
rv = service->RegisterRespondingListener(mWindowId, this);
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void Presentation::Shutdown()
|
|
{
|
|
mDefaultRequest = nullptr;
|
|
mSessions.Clear();
|
|
mPendingGetSessionPromises.Clear();
|
|
|
|
// Unregister listener for incoming sessions.
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
if (NS_WARN_IF(!service)) {
|
|
return;
|
|
}
|
|
|
|
nsresult rv = service->UnregisterRespondingListener(mWindowId);
|
|
NS_WARN_IF(NS_FAILED(rv));
|
|
}
|
|
|
|
/* virtual */ void
|
|
Presentation::DisconnectFromOwner()
|
|
{
|
|
Shutdown();
|
|
DOMEventTargetHelper::DisconnectFromOwner();
|
|
}
|
|
|
|
/* virtual */ JSObject*
|
|
Presentation::WrapObject(JSContext* aCx,
|
|
JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return PresentationBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
void
|
|
Presentation::SetDefaultRequest(PresentationRequest* aRequest)
|
|
{
|
|
mDefaultRequest = aRequest;
|
|
}
|
|
|
|
already_AddRefed<PresentationRequest>
|
|
Presentation::GetDefaultRequest() const
|
|
{
|
|
RefPtr<PresentationRequest> request = mDefaultRequest;
|
|
return request.forget();
|
|
}
|
|
|
|
already_AddRefed<Promise>
|
|
Presentation::GetSession(ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
if (NS_WARN_IF(!global)) {
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return nullptr;
|
|
}
|
|
|
|
// If there's no existing session, leave the promise pending until a
|
|
// connecting request arrives from the controlling browsing context (sender).
|
|
// http://w3c.github.io/presentation-api/#dom-presentation-getsession
|
|
if (!mSessions.IsEmpty()) {
|
|
promise->MaybeResolve(mSessions[0]);
|
|
} else {
|
|
mPendingGetSessionPromises.AppendElement(promise);
|
|
}
|
|
|
|
return promise.forget();
|
|
}
|
|
|
|
already_AddRefed<Promise>
|
|
Presentation::GetSessions(ErrorResult& aRv) const
|
|
{
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
if (NS_WARN_IF(!global)) {
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return nullptr;
|
|
}
|
|
|
|
promise->MaybeResolve(mSessions);
|
|
return promise.forget();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
Presentation::NotifySessionConnect(uint64_t aWindowId,
|
|
const nsAString& aSessionId)
|
|
{
|
|
if (NS_WARN_IF(aWindowId != GetOwner()->WindowID())) {
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
|
|
RefPtr<PresentationSession> session =
|
|
PresentationSession::Create(GetOwner(), aSessionId,
|
|
PresentationSessionState::Closed);
|
|
if (NS_WARN_IF(!session)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
mSessions.AppendElement(session);
|
|
|
|
// Resolve pending |GetSession| promises if any.
|
|
if (!mPendingGetSessionPromises.IsEmpty()) {
|
|
for(uint32_t i = 0; i < mPendingGetSessionPromises.Length(); i++) {
|
|
mPendingGetSessionPromises[i]->MaybeResolve(session);
|
|
}
|
|
mPendingGetSessionPromises.Clear();
|
|
}
|
|
|
|
return DispatchSessionAvailableEvent();
|
|
}
|
|
|
|
nsresult
|
|
Presentation::DispatchSessionAvailableEvent()
|
|
{
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
|
new AsyncEventDispatcher(this, NS_LITERAL_STRING("sessionavailable"), false);
|
|
return asyncDispatcher->PostDOMEvent();
|
|
}
|