Files
palemoon27/dom/presentation/PresentationCallbacks.cpp
T
roytam1 8cb2d1cd9e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1069230 - Presentation API implementation. Part 1 - WebIDL Bindings. r=smaug (180d2e23a)
- Bug 1142770 - part 1 - Use telephony service creator for telephony IPC service. r=hsinyi (447da4e64)
- Bug 1142770 - part 2 - disable telephonyservice and voicemailservice. r=fabrice (5e0592769)
- Bug 1069230 - Presentation API implementation. Part 2 - Presentation service and listeners. r=smaug (4be1d0628)
- Bug 1069230 - Presentation API implementation. Part 3 - IPC. r=smaug (10db1c229)
- Bug 1069230 - Presentation API implementation. Part 4 - Establish session (sender) & available changes. r=smaug (d7b358f74)
- Bug 1069230 - Presentation API implementation. Part 5 - Establish session (receiver). r=smaug (e60709725)
- Bug 1020179 - ContentPermissionPrompt change in b2g. r=fabrice (7aab4449e)
- Bug 1020179 - Test case for visibilitychange. r=fabrice (d404f25e6)
- Bug 1069230 - Presentation API implementation. Part 6 - mozChromeEvent for app launch. r=fabrice r=smaug (17081096c)
- Bug 1069230 - Presentation API implementation. Part 7 - Presentation session. r=smaug (29227f2cf)
- Bug 1069230 - Presentation API implementation. Part 8 - Data transport channel. r=jdm (2eb3a49ca)
- Bug 1069230 - Presentation API implementation. Part 9 - Tests. r=kikuo (3cb72b71e)
- Bug 1162700 - Split the AppInfo into initial setting of the values and the further initialization. r=smaug (d0b8d1470)
2021-06-08 15:21:25 +08:00

186 lines
5.7 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/dom/Promise.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPresentationService.h"
#include "nsIWebProgress.h"
#include "nsServiceManagerUtils.h"
#include "PresentationCallbacks.h"
#include "PresentationSession.h"
using namespace mozilla;
using namespace mozilla::dom;
/*
* Implementation of PresentationRequesterCallback
*/
NS_IMPL_ISUPPORTS(PresentationRequesterCallback, nsIPresentationServiceCallback)
PresentationRequesterCallback::PresentationRequesterCallback(nsPIDOMWindow* aWindow,
const nsAString& aUrl,
const nsAString& aSessionId,
Promise* aPromise)
: mWindow(aWindow)
, mSessionId(aSessionId)
, mPromise(aPromise)
{
MOZ_ASSERT(mWindow);
MOZ_ASSERT(mPromise);
MOZ_ASSERT(!mSessionId.IsEmpty());
}
PresentationRequesterCallback::~PresentationRequesterCallback()
{
}
// nsIPresentationServiceCallback
NS_IMETHODIMP
PresentationRequesterCallback::NotifySuccess()
{
MOZ_ASSERT(NS_IsMainThread());
// At the sender side, this function must get called after the transport
// channel is ready. So we simply set the session state as connected.
nsRefPtr<PresentationSession> session =
PresentationSession::Create(mWindow, mSessionId, PresentationSessionState::Connected);
if (!session) {
mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
return NS_OK;
}
mPromise->MaybeResolve(session);
return NS_OK;
}
NS_IMETHODIMP
PresentationRequesterCallback::NotifyError(nsresult aError)
{
MOZ_ASSERT(NS_IsMainThread());
mPromise->MaybeReject(aError);
return NS_OK;
}
/*
* Implementation of PresentationRequesterCallback
*/
NS_IMPL_ISUPPORTS(PresentationResponderLoadingCallback,
nsIWebProgressListener,
nsISupportsWeakReference)
PresentationResponderLoadingCallback::PresentationResponderLoadingCallback(const nsAString& aSessionId)
: mSessionId(aSessionId)
{
}
PresentationResponderLoadingCallback::~PresentationResponderLoadingCallback()
{
if (mProgress) {
mProgress->RemoveProgressListener(this);
mProgress = nullptr;
}
}
nsresult
PresentationResponderLoadingCallback::Init(nsIDocShell* aDocShell)
{
mProgress = do_GetInterface(aDocShell);
if (NS_WARN_IF(!mProgress)) {
return NS_ERROR_NOT_AVAILABLE;
}
uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
nsresult rv = aDocShell->GetBusyFlags(&busyFlags);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if ((busyFlags & nsIDocShell::BUSY_FLAGS_NONE) ||
(busyFlags & nsIDocShell::BUSY_FLAGS_PAGE_LOADING)) {
// The docshell has finished loading or is receiving data (|STATE_TRANSFERRING|
// has already been fired), so the page is ready for presentation use.
return NotifyReceiverReady();
}
// Start to listen to document state change event |STATE_TRANSFERRING|.
return mProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
}
nsresult
PresentationResponderLoadingCallback::NotifyReceiverReady()
{
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
return service->NotifyReceiverReady(mSessionId);
}
// nsIWebProgressListener
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnStateChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aStateFlags,
nsresult aStatus)
{
MOZ_ASSERT(NS_IsMainThread());
if (aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING) {
mProgress->RemoveProgressListener(this);
return NotifyReceiverReady();
}
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnProgressChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
int32_t aCurSelfProgress,
int32_t aMaxSelfProgress,
int32_t aCurTotalProgress,
int32_t aMaxTotalProgress)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI* aURI,
uint32_t aFlags)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const char16_t* aMessage)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t state)
{
// Do nothing.
return NS_OK;
}