tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 10ffdc9d9c5559351a0380ed414301917130286d
parent 7e15fae492598a4b8d7df3c945ce4787db9f5743
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date:   Mon, 22 Dec 2025 04:06:27 +0000

Bug 2006181 - Set the browsing context id for the webtransport channel r=necko-reviewers,kershaw,jesup

Adding the browsing context id to the channel for devtools visibility of the request.

Differential Revision: https://phabricator.services.mozilla.com/D276447

Diffstat:
Mdom/webtransport/api/WebTransport.cpp | 11++++++++---
Mdom/webtransport/api/WebTransport.h | 1+
Mdom/webtransport/parent/WebTransportParent.cpp | 8+++++---
Mdom/webtransport/parent/WebTransportParent.h | 1+
Mipc/glue/BackgroundParentImpl.cpp | 8+++++---
Mipc/glue/BackgroundParentImpl.h | 1+
Mipc/glue/PBackground.ipdl | 1+
Mnetwerk/base/LoadInfo.h | 7+++++--
Mnetwerk/protocol/webtransport/WebTransportSessionProxy.cpp | 20+++++++++++++++++---
Mnetwerk/protocol/webtransport/nsIWebTransport.idl | 1+
10 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/dom/webtransport/api/WebTransport.cpp b/dom/webtransport/api/WebTransport.cpp @@ -294,6 +294,11 @@ void WebTransport::Init(const GlobalObject& aGlobal, const nsAString& aURL, if (mGlobal->GetClientInfo().isSome()) { ipcClientInfo = mozilla::Some(mGlobal->GetClientInfo().ref().ToIPC()); } + + nsPIDOMWindowInner* window = mGlobal->GetAsInnerWindow(); + if (window) { + mBrowsingContextID = window->GetBrowsingContext()->Id(); + } // Create a new IPC connection Endpoint<PWebTransportParent> parentEndpoint; Endpoint<PWebTransportChild> childEndpoint; @@ -372,9 +377,9 @@ void WebTransport::Init(const GlobalObject& aGlobal, const nsAString& aURL, mChild = child; backgroundChild ->SendCreateWebTransportParent( - aURL, principal, ipcClientInfo, dedicated, requireUnreliable, - (uint32_t)congestionControl, std::move(aServerCertHashes), - std::move(parentEndpoint)) + aURL, principal, mBrowsingContextID, ipcClientInfo, dedicated, + requireUnreliable, (uint32_t)congestionControl, + std::move(aServerCertHashes), std::move(parentEndpoint)) ->Then(GetCurrentSerialEventTarget(), __func__, [self = RefPtr{this}]( PBackgroundChild::CreateWebTransportParentPromise:: diff --git a/dom/webtransport/api/WebTransport.h b/dom/webtransport/api/WebTransport.h @@ -152,6 +152,7 @@ class WebTransport final : public nsISupports, public nsWrapperCache { RefPtr<Promise> mReady; uint64_t mInnerWindowID = 0; uint64_t mHttpChannelID = 0; + uint64_t mBrowsingContextID = 0; RefPtr<mozilla::net::WebTransportEventService> mService; // XXX may not need to be a RefPtr, since we own it through the Streams RefPtr<WebTransportIncomingStreamsAlgorithms> mIncomingBidirectionalAlgorithm; diff --git a/dom/webtransport/parent/WebTransportParent.cpp b/dom/webtransport/parent/WebTransportParent.cpp @@ -35,6 +35,7 @@ WebTransportParent::~WebTransportParent() { void WebTransportParent::Create( const nsAString& aURL, nsIPrincipal* aPrincipal, + const uint64_t& aBrowsingContextID, const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated, const bool& aRequireUnreliable, const uint32_t& aCongestionControl, nsTArray<WebTransportHash>&& aServerCertHashes, @@ -92,13 +93,14 @@ void WebTransportParent::Create( [self = RefPtr{this}, uri = std::move(uri), dedicated = true /* aDedicated, see BUG 1915735.*/, nsServerCertHashes = std::move(nsServerCertHashes), - principal = RefPtr{aPrincipal}, + principal = RefPtr{aPrincipal}, browsingContextID = aBrowsingContextID, flags = nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, clientInfo = aClientInfo] { LOG(("WebTransport %p AsyncConnect", self.get())); if (NS_FAILED(self->mWebTransport->AsyncConnectWithClient( - uri, dedicated, std::move(nsServerCertHashes), principal, flags, - self, clientInfo, nsIWebTransport::HTTPVersion::h3))) { + uri, dedicated, std::move(nsServerCertHashes), principal, + browsingContextID, flags, self, clientInfo, + nsIWebTransport::HTTPVersion::h3))) { LOG(("AsyncConnect failure; we should get OnSessionClosed")); } }); diff --git a/dom/webtransport/parent/WebTransportParent.h b/dom/webtransport/parent/WebTransportParent.h @@ -34,6 +34,7 @@ class WebTransportParent : public PWebTransportParent, NS_DECL_WEBTRANSPORTSESSIONEVENTLISTENER void Create(const nsAString& aURL, nsIPrincipal* aPrincipal, + const uint64_t& aBrowsingContextID, const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated, const bool& aRequireUnreliable, const uint32_t& aCongestionControl, diff --git a/ipc/glue/BackgroundParentImpl.cpp b/ipc/glue/BackgroundParentImpl.cpp @@ -465,6 +465,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateFileSystemManagerParent( mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent( const nsAString& aURL, nsIPrincipal* aPrincipal, + const uint64_t& aBrowsingContextID, const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated, const bool& aRequireUnreliable, const uint32_t& aCongestionControl, nsTArray<WebTransportHash>&& aServerCertHashes, @@ -475,9 +476,10 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent( RefPtr<mozilla::dom::WebTransportParent> webt = new mozilla::dom::WebTransportParent(); - webt->Create(aURL, aPrincipal, aClientInfo, aDedicated, aRequireUnreliable, - aCongestionControl, std::move(aServerCertHashes), - std::move(aParentEndpoint), std::move(aResolver)); + webt->Create(aURL, aPrincipal, aBrowsingContextID, aClientInfo, aDedicated, + aRequireUnreliable, aCongestionControl, + std::move(aServerCertHashes), std::move(aParentEndpoint), + std::move(aResolver)); return IPC_OK(); } diff --git a/ipc/glue/BackgroundParentImpl.h b/ipc/glue/BackgroundParentImpl.h @@ -123,6 +123,7 @@ class BackgroundParentImpl : public PBackgroundParent { mozilla::ipc::IPCResult RecvCreateWebTransportParent( const nsAString& aURL, nsIPrincipal* aPrincipal, + const uint64_t& aBrowsingContextID, const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated, const bool& aRequireUnreliable, const uint32_t& aCongestionControl, nsTArray<WebTransportHash>&& aServerCertHashes, diff --git a/ipc/glue/PBackground.ipdl b/ipc/glue/PBackground.ipdl @@ -179,6 +179,7 @@ parent: async CreateWebTransportParent( nsString aURL, nullable nsIPrincipal aPrincipal, + uint64_t aBrowsingContextID, IPCClientInfo? aClientInfo, bool aDedicated, bool aRequireUnreliable, diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h @@ -42,6 +42,7 @@ namespace net { class EarlyHintPreloader; class LoadInfoArgs; class LoadInfo; +class WebTransportSessionProxy; } // namespace net namespace ipc { @@ -457,10 +458,12 @@ class LoadInfo final : public nsILoadInfo { void SetIncludeCookiesSecFlag(); friend class mozilla::dom::XMLHttpRequestMainThread; - // nsDocShell::OpenInitializedChannel and EarlyHintPreloader::OpenChannel - // needs to update the loadInfo with the correct browsingContext. + // nsDocShell::OpenInitializedChannel, EarlyHintPreloader::OpenChannel and + // WebTransportSessionProxy::AsyncConnectWithClient need to update the + // loadInfo with the correct browsingContext. friend class ::nsDocShell; friend class mozilla::net::EarlyHintPreloader; + friend class mozilla::net::WebTransportSessionProxy; void UpdateBrowsingContextID(uint64_t aBrowsingContextID) { mBrowsingContextID = aBrowsingContextID; } diff --git a/netwerk/protocol/webtransport/WebTransportSessionProxy.cpp b/netwerk/protocol/webtransport/WebTransportSessionProxy.cpp @@ -18,10 +18,12 @@ #include "nsIX509Cert.h" #include "nsNetUtil.h" #include "nsProxyRelease.h" +#include "nsILoadInfo.h" #include "nsSocketTransportService2.h" #include "mozilla/Logging.h" #include "mozilla/ScopeExit.h" #include "mozilla/StaticPrefs_network.h" +#include "mozilla/LoadInfo.h" namespace mozilla::net { @@ -72,15 +74,15 @@ nsresult WebTransportSessionProxy::AsyncConnect( WebTransportSessionEventListener* aListener, nsIWebTransport::HTTPVersion aVersion) { return AsyncConnectWithClient(aURI, aDedicated, std::move(aServerCertHashes), - aPrincipal, aSecurityFlags, aListener, + aPrincipal, 0, aSecurityFlags, aListener, Maybe<dom::ClientInfo>(), aVersion); } nsresult WebTransportSessionProxy::AsyncConnectWithClient( nsIURI* aURI, bool aDedicated, const nsTArray<RefPtr<nsIWebTransportHash>>& aServerCertHashes, - nsIPrincipal* aPrincipal, uint32_t aSecurityFlags, - WebTransportSessionEventListener* aListener, + nsIPrincipal* aPrincipal, uint64_t aBrowsingContextID, + uint32_t aSecurityFlags, WebTransportSessionEventListener* aListener, const Maybe<dom::ClientInfo>& aClientInfo, nsIWebTransport::HTTPVersion aVersion) { MOZ_ASSERT(NS_IsMainThread()); @@ -185,6 +187,18 @@ nsresult WebTransportSessionProxy::AsyncConnectWithClient( mHttpChannelID = httpChannel->ChannelId(); + // Setting the BrowsingContextID here to let WebTransport requests show up in + // devtools. Normally that would automatically happen if we would pass the + // nsILoadGroup in ns_NewChannel above, but the nsILoadGroup is inaccessible + // here in the ParentProcess. The nsILoadGroup only exists in ContentProcess + // as part of the document and nsDocShell. It is also not yet determined which + // ContentProcess this load belongs to. + if (aBrowsingContextID != 0) { + nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo(); + static_cast<LoadInfo*>(loadInfo.get()) + ->UpdateBrowsingContextID(aBrowsingContextID); + } + return rv; } diff --git a/netwerk/protocol/webtransport/nsIWebTransport.idl b/netwerk/protocol/webtransport/nsIWebTransport.idl @@ -55,6 +55,7 @@ interface nsIWebTransport : nsISupports { in boolean aDedicated, in Array<nsIWebTransportHash> aServerCertHashes, in nsIPrincipal aLoadingPrincipal, + in uint64_t aBrowsingContextID, in unsigned long aSecurityFlags, in WebTransportSessionEventListener aListener, in const_MaybeClientInfoRef aClientInfo,