Files
palemoon27/dom/presentation/PresentationCallbacks.cpp
roytam1 18ad48cb0e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1217835 - Rewrite some code in CanvasRenderingContext2D::GetImageDataArray to avoid build warnings; r=gw280 (cedba0b14a)
- Bug 1232864 - Cauterize and release WebGL 2 to Nightly. - r=jrmuizel (5a16387f1d)
- Bug 1229585 - Add helpful error text for fb incompleteness. - r=kamidphish (1a3d7505e2)
- Bug 1231303 - Moz2Dify nsFilterInstance. r=roc. (44ec4c5df6)
- Bug 1229235 - Make RedirectChannelRegistrar thread-safe. r=jduell (5acca6a770)
- Bug 1211090 - Use Buffered IO for PrefixSet load/store. r=froydnj (00720fe291)
- Bug 1211090 - Add fallocate support to nsIOutputFileStream and use it. r=froydnj (6a49aa4a5f)
- Bug 1211090 - Don't fail to open databases if we can't do buffered IO. r=froydnj (70ab38e03b)
- Bug 1223808 - part 3 - replace nsAutoArrayPtr<T> with UniquePtr<T[]> in netwerk/; r=mcmanus (4a1d880135)
- Bug 1223808 - part 1 - optimize creating a WebSocketFrame with a payload; r=mcmanus (9a046a6f0a)
- Bug 1223808 - part 2 - use UniquePtr<uint8_t[]> instead of nsAutoArrayPtr<SHA1Sum::Hash> in HandleHashKey; r=michal (c6a0f6d5d3)
- Bug 1167053 - Convert NetUtil.newChannel2 callsites to use new API - remove newChannel2,asyncFetch2 (r=sicking,paolo) (875b9c78f0)
- Bug 1185982 - Remove the unused NotifyNetworkActivity::mObs member; r=bagder (f09d2676f7)
- bits of Bug 1152597 - Icons are shown for some apps. (9a289ab9ec)
- Bug 1223231 - Use channel.asyncOpen2 in devtools/client/shared/AppCacheUtils.jsm (r=sicking) (5c635d797c)
- Bug 1208905 - Fix a condition in PresentationResponderLoadingCallback::Init; r=baku (ff84b8a595)
- Bug 1231677 - verify the return of mDiscoveryTimer->Init, if it faild exit function with error code. r=jst (04b8be172c)
- Bug 1199564 - start/stop mDNS on demand - v3. r=mcmanus (66d7ef06e6)
- Bug 1225726 - enable nsDNSServiceDiscovery on OS X. r=mcmanus. (01ea13e4a6)
- Bug 1172383 - Stop mDNS properly during destruction. r=mcmanus (c041817b7e)
- Bug 1198058 - Fix crashes inspecting loadGroups in browser toolbox. r=mcmanus (462b5aa8bd)
- Bug 1220607 - Expand on the nsILoadGroup interface's comment to indicate how it is used. r=bz IGNORE IDL (49a95cc217)
- use response for response (348055fc69)
- Remove some old clobber-workarounds. No bug. (db7e7c4773)
- Bug 280280 - Make "no proxy for" do domain comparison. r=bagder (4804e39fd6)
- backout f600f0cd7bb3 (Bug 1170646) because of Thunderbird regressions with OSX, r=michal (d43ba00896)
- Bug 1220215 - Add '#' between client id and suffix in appcache groud id, r=jduell (240fcec72a)
- Bug 1198792 - Clear Application Cache internal hashtables on Clear Recent History, r=jduell (1313393dc5)
- Bug 1222782 - TSan: data race netwerk/cache2/CacheIOThread.cpp:148 Target (race on mXPCOMThread), r=jseward (d56470a300)
- Bug 1190951 - TSan: data race netwerk/cache2/CacheIndex.cpp:1397 CacheIndex::IsUpToDate, r=valentin.gosu (24934e1885)
2023-07-18 14:31:13 +08:00

195 lines
6.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/dom/Promise.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPresentationService.h"
#include "nsIWebProgress.h"
#include "nsServiceManagerUtils.h"
#include "PresentationCallbacks.h"
#include "PresentationRequest.h"
#include "PresentationSession.h"
using namespace mozilla;
using namespace mozilla::dom;
/*
* Implementation of PresentationRequesterCallback
*/
NS_IMPL_ISUPPORTS(PresentationRequesterCallback, nsIPresentationServiceCallback)
PresentationRequesterCallback::PresentationRequesterCallback(PresentationRequest* aRequest,
const nsAString& aUrl,
const nsAString& aSessionId,
Promise* aPromise)
: mRequest(aRequest)
, mSessionId(aSessionId)
, mPromise(aPromise)
{
MOZ_ASSERT(mRequest);
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.
RefPtr<PresentationSession> session =
PresentationSession::Create(mRequest->GetOwner(), mSessionId,
PresentationSessionState::Connected);
if (NS_WARN_IF(!session)) {
mPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return NS_OK;
}
mPromise->MaybeResolve(session);
return mRequest->DispatchSessionConnectEvent(session);
}
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<nsPIDOMWindow> window = do_GetInterface(mProgress);
if (NS_WARN_IF(!window || !window->GetCurrentInnerWindow())) {
return NS_ERROR_NOT_AVAILABLE;
}
uint64_t windowId = window->GetCurrentInnerWindow()->WindowID();
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
return service->NotifyReceiverReady(mSessionId, windowId);
}
// 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;
}