Files
roytam1 c2bcdec5c9 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1261009 - Remove the Data Store API, r=fabrice (b22e580107)
- Bug 1268393 - Some compilation issues in ServiceWorker code, r=ehsan (d9c2f2554b)
- Bug 1209095 - Accept opaqueredirection fetch results if the request redirection type is manual. r=bkelly (6fe92d1368)
- Bug 1267733 P2 Pass ServiceWorkerRegistrationInfo down to CancelChannelRunnable. r=jdm (0ec51f09ef)
- Bug 1267733 P3 Trigger service worker update after failed interception. r=jdm (f89a7998d4)
- Bug 1267733 P4 Add a wpt test that verifies a service worker update can recover from a broken navigation interception. r=jdm (9dc0ce97bd)
- Bug 1267691: Assert on failed attempts to shutdown a thread from itself r=froyd (0cbd1e458c)
- Bug 1180533 - Disable BackgroundHangMonitor on gonk (a2d666e741)
- Bug 1121216 - disable BackgroundHangMonitor for TSan builds; r=jchen (ef15d1016f)
- Bug 1265621 - Use StaticRefPtr in Omnijar.cpp; r=froydnj (81bc32836e)
- Bug 1265621 - Expose outer zip readers in Omnijar::GetReader; r=froydnj (ce3f82929e)
- Bug 1267021 - Use fallible allocation and move semantics for Push events. r=wchen (3a1ae23d8d)
- Bug 1222899 - Handle geolocation-device-events callback. r=kchen (a33bcf4297)
- Bug 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst (d389eedf47)
- Bug 1245033 - Build break in dom/system/gonk/GonkGPSGeolocationProvider.cpp:541:126: error: format '%d' expects argument of type 'int', but argument 5 has type 'nsresult'. r=fabrice (ecde789edf)
- Bug 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd (9bad7792bf)
- Bug 1267577 - Move nsRunnable to mozilla::Runnable. r=gsvelto (f58e2161f2)
- Bug 1210370 - Close wpa_supplicant before we shutdown nsIWifiProxyService. r=mrbkap (5cd4dce58f)
- Bug 1218629 - Save audio volume for each device to setting db r=alwu (2f1847dd6f)
- Bug 1249437 - Remove workaround of volume control r=alwu (13cd144a89)
- Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice (bcc768e9cb)
- Bug 1226483 - Add ASSERT check to AudioManager::SelectDeviceFromDevices() r=alwu (446e8f634e)
- Bug 1229234 - Enable audio_is_output_device() on ICS r=alwu (84aae07f23)
- Bug 1267369 - Only generate typelib data for scriptable interfaces; r=khuey (e49b44c9ce)
- Bug 1155969 - Make runtests.py flake8 compliant. r=ted (1de456b206)
- Bug 1266569 - Avoid including the ChromeUtils binding in Base64.h. r=froydnj (7ba39a7687)
2024-08-29 00:00:08 +08:00

296 lines
8.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et 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 "nsContentSecurityManager.h"
#include "nsContentUtils.h"
#include "RtspChannelChild.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsServiceManagerUtils.h"
using namespace mozilla::ipc;
namespace mozilla {
namespace net {
//-----------------------------------------------------------------------------
// RtspChannelChild
//-----------------------------------------------------------------------------
RtspChannelChild::RtspChannelChild(nsIURI *aUri)
: mIPCOpen(false)
, mCanceled(false)
{
nsBaseChannel::SetURI(aUri);
DisallowThreadRetargeting();
}
RtspChannelChild::~RtspChannelChild()
{
}
nsIStreamingProtocolController*
RtspChannelChild::GetController()
{
return mMediaStreamController;
}
void
RtspChannelChild::ReleaseController()
{
if (mMediaStreamController) {
mMediaStreamController = nullptr;
}
}
//-----------------------------------------------------------------------------
// IPDL
//-----------------------------------------------------------------------------
void
RtspChannelChild::AddIPDLReference()
{
MOZ_ASSERT(!mIPCOpen,
"Attempt to retain more than one IPDL reference");
mIPCOpen = true;
AddRef();
}
void
RtspChannelChild::ReleaseIPDLReference()
{
MOZ_ASSERT(mIPCOpen, "Attempt to release nonexistent IPDL reference");
mIPCOpen = false;
Release();
}
//-----------------------------------------------------------------------------
// nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS_INHERITED(RtspChannelChild,
nsBaseChannel,
nsIChannel,
nsIChildChannel)
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIChannel
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RtspChannelChild::GetContentType(nsACString& aContentType)
{
aContentType.AssignLiteral("RTSP");
return NS_OK;
}
class CallListenerOnStartRequestEvent : public Runnable
{
public:
CallListenerOnStartRequestEvent(nsIStreamListener *aListener,
nsIRequest *aRequest, nsISupports *aContext)
: mListener(aListener)
, mRequest(aRequest)
, mContext(aContext)
{
MOZ_RELEASE_ASSERT(aListener);
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
mListener->OnStartRequest(mRequest, mContext);
return NS_OK;
}
private:
RefPtr<nsIStreamListener> mListener;
RefPtr<nsIRequest> mRequest;
RefPtr<nsISupports> mContext;
};
NS_IMETHODIMP
RtspChannelChild::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
{
MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
"security flags in loadInfo but asyncOpen2() not called");
// Precondition checks.
MOZ_ASSERT(aListener);
nsCOMPtr<nsIURI> uri = nsBaseChannel::URI();
NS_ENSURE_TRUE(uri, NS_ERROR_ILLEGAL_VALUE);
// Create RtspController.
nsCOMPtr<nsIStreamingProtocolControllerService> mediaControllerService =
do_GetService(MEDIASTREAMCONTROLLERSERVICE_CONTRACTID);
MOZ_RELEASE_ASSERT(mediaControllerService,
"Cannot proceed if media controller service is unavailable!");
mediaControllerService->Create(this, getter_AddRefs(mMediaStreamController));
MOZ_ASSERT(mMediaStreamController);
// Add ourselves to the load group.
if (mLoadGroup) {
mLoadGroup->AddRequest(this, nullptr);
}
// Dispatch mListener's OnStartRequest directly. mListener is expected to
// create an RtspMediaResource and use the RtspController we just created to
// manage the control and data streams to and from the network.
mListener = aListener;
mListenerContext = aContext;
NS_DispatchToMainThread(
new CallListenerOnStartRequestEvent(mListener, this, mListenerContext));
return NS_OK;
}
NS_IMETHODIMP
RtspChannelChild::AsyncOpen2(nsIStreamListener *aListener)
{
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
return AsyncOpen(listener, nullptr);
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIStreamListener::nsIRequestObserver
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RtspChannelChild::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
{
MOZ_CRASH("Should never be called");
}
NS_IMETHODIMP
RtspChannelChild::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
nsresult aStatusCode)
{
MOZ_CRASH("Should never be called");
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIStreamListener
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RtspChannelChild::OnDataAvailable(nsIRequest *aRequest,
nsISupports *aContext,
nsIInputStream *aInputStream,
uint64_t aOffset,
uint32_t aCount)
{
MOZ_CRASH("Should never be called");
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIChannel::nsIRequest
//-----------------------------------------------------------------------------
class CallListenerOnStopRequestEvent : public Runnable
{
public:
CallListenerOnStopRequestEvent(nsIStreamListener *aListener,
nsIRequest *aRequest,
nsISupports *aContext, nsresult aStatus)
: mListener(aListener)
, mRequest(aRequest)
, mContext(aContext)
, mStatus(aStatus)
{
MOZ_RELEASE_ASSERT(aListener);
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
mListener->OnStopRequest(mRequest, mContext, mStatus);
return NS_OK;
}
private:
RefPtr<nsIStreamListener> mListener;
RefPtr<nsIRequest> mRequest;
RefPtr<nsISupports> mContext;
nsresult mStatus;
};
NS_IMETHODIMP
RtspChannelChild::Cancel(nsresult status)
{
if (mCanceled) {
return NS_OK;
}
mCanceled = true;
// Stop RtspController.
if (mMediaStreamController) {
mMediaStreamController->Stop();
}
// Call mListener's OnStopRequest to do clean up.
NS_DispatchToMainThread(
new CallListenerOnStopRequestEvent(mListener, this,
mListenerContext, status));
mListener = nullptr;
mListenerContext = nullptr;
// Remove ourselves from the load group.
if (mLoadGroup) {
mLoadGroup->RemoveRequest(this, nullptr, status);
}
return NS_OK;
}
NS_IMETHODIMP
RtspChannelChild::Suspend()
{
MOZ_CRASH("Should never be called");
}
NS_IMETHODIMP
RtspChannelChild::Resume()
{
MOZ_CRASH("Should never be called");
}
//-----------------------------------------------------------------------------
// nsBaseChannel
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RtspChannelChild::OpenContentStream(bool aAsync,
nsIInputStream **aStream,
nsIChannel **aChannel)
{
MOZ_CRASH("Should never be called");
}
//-----------------------------------------------------------------------------
// nsIChildChannel
//-----------------------------------------------------------------------------
NS_IMETHODIMP
RtspChannelChild::ConnectParent(uint32_t id)
{
// Create RtspChannelParent for redirection.
AddIPDLReference();
RtspChannelConnectArgs connectArgs;
SerializeURI(nsBaseChannel::URI(), connectArgs.uri());
connectArgs.channelId() = id;
if (!gNeckoChild->SendPRtspChannelConstructor(this, connectArgs)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
RtspChannelChild::CompleteRedirectSetup(nsIStreamListener *aListener,
nsISupports *aContext)
{
if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) {
MOZ_ASSERT(!aContext, "aContext should be null!");
return AsyncOpen2(aListener);
}
return AsyncOpen(aListener, aContext);
}
} // namespace net
} // namespace mozilla