commit 86bb6dbee83d2386ae66bc869cf92be98f52b146
parent e6af034b6d639658a57d8f31cdeae6c0f168308b
Author: smayya <smayya@mozilla.com>
Date: Mon, 20 Oct 2025 10:53:14 +0000
Bug 1967266 - Pass clientinfo when we create a loadinfo for websocket. r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D269009
Diffstat:
4 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp
@@ -273,6 +273,7 @@ class WebSocketImpl final : public nsIInterfaceRequestor,
RefPtr<WebSocketEventService> mService;
nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
+ Maybe<ClientInfo> mClientInfo;
RefPtr<WebSocketImplProxy> mImplProxy;
@@ -1669,6 +1670,7 @@ nsresult WebSocketImpl::Init(nsIGlobalObject* aWindowGlobal, JSContext* aCx,
}
mIsServerSide = aIsServerSide;
+ mClientInfo = aClientInfo;
// If we don't have aCx, we are window-less, so we don't have a
// inner-windowID. This can happen in sharedWorkers and ServiceWorkers or in
@@ -1934,7 +1936,7 @@ nsresult WebSocketImpl::InitializeConnection(
doc, doc ? doc->NodePrincipal() : aPrincipal, aPrincipal,
aCookieJarSettings,
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
- nsIContentPolicy::TYPE_WEBSOCKET, 0);
+ nsIContentPolicy::TYPE_WEBSOCKET, mClientInfo, 0);
MOZ_ASSERT(NS_SUCCEEDED(rv));
if (!mRequestedProtocolList.IsEmpty()) {
diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp
@@ -221,10 +221,13 @@ BaseWebSocketChannel::InitLoadInfoNative(
nsINode* aLoadingNode, nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal,
nsICookieJarSettings* aCookieJarSettings, uint32_t aSecurityFlags,
- nsContentPolicyType aContentPolicyType, uint32_t aSandboxFlags) {
+ nsContentPolicyType aContentPolicyType,
+ const Maybe<mozilla::dom::ClientInfo>& aClientInfo,
+ uint32_t aSandboxFlags) {
+ MOZ_ASSERT(NS_IsMainThread());
mLoadInfo = MOZ_TRY(LoadInfo::Create(
aLoadingPrincipal, aTriggeringPrincipal, aLoadingNode, aSecurityFlags,
- aContentPolicyType, Maybe<mozilla::dom::ClientInfo>(),
+ aContentPolicyType, aClientInfo,
Maybe<mozilla::dom::ServiceWorkerDescriptor>(), aSandboxFlags));
if (aCookieJarSettings) {
mLoadInfo->SetCookieJarSettings(aCookieJarSettings);
@@ -249,9 +252,9 @@ BaseWebSocketChannel::InitLoadInfo(nsINode* aLoadingNode,
nsIPrincipal* aTriggeringPrincipal,
uint32_t aSecurityFlags,
nsContentPolicyType aContentPolicyType) {
- return InitLoadInfoNative(aLoadingNode, aLoadingPrincipal,
- aTriggeringPrincipal, nullptr, aSecurityFlags,
- aContentPolicyType, 0);
+ return InitLoadInfoNative(
+ aLoadingNode, aLoadingPrincipal, aTriggeringPrincipal, nullptr,
+ aSecurityFlags, aContentPolicyType, Maybe<mozilla::dom::ClientInfo>(), 0);
}
NS_IMETHODIMP
diff --git a/netwerk/protocol/websocket/BaseWebSocketChannel.h b/netwerk/protocol/websocket/BaseWebSocketChannel.h
@@ -54,13 +54,13 @@ class BaseWebSocketChannel : public nsIWebSocketChannel,
NS_IMETHOD SetPingInterval(uint32_t aSeconds) override;
NS_IMETHOD GetPingTimeout(uint32_t* aSeconds) override;
NS_IMETHOD SetPingTimeout(uint32_t aSeconds) override;
- NS_IMETHOD InitLoadInfoNative(nsINode* aLoadingNode,
- nsIPrincipal* aLoadingPrincipal,
- nsIPrincipal* aTriggeringPrincipal,
- nsICookieJarSettings* aCookieJarSettings,
- uint32_t aSecurityFlags,
- nsContentPolicyType aContentPolicyType,
- uint32_t aSandboxFlags) override;
+ NS_IMETHOD InitLoadInfoNative(
+ nsINode* aLoadingNode, nsIPrincipal* aLoadingPrincipal,
+ nsIPrincipal* aTriggeringPrincipal,
+ nsICookieJarSettings* aCookieJarSettings, uint32_t aSecurityFlags,
+ nsContentPolicyType aContentPolicyType,
+ const Maybe<mozilla::dom::ClientInfo>& aClientInfo,
+ uint32_t aSandboxFlags) override;
NS_IMETHOD InitLoadInfo(nsINode* aLoadingNode,
nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal,
diff --git a/netwerk/protocol/websocket/nsIWebSocketChannel.idl b/netwerk/protocol/websocket/nsIWebSocketChannel.idl
@@ -20,9 +20,18 @@ webidl Node;
#include "nsISupports.idl"
#include "nsIContentPolicy.idl"
+%{C++
+#include "mozilla/Maybe.h"
+
+namespace mozilla::dom {
+class ClientInfo;
+}
+using mozilla::Maybe;
+%}
[ref] native OriginAttributes(const mozilla::OriginAttributes);
+[ref] native MaybeClientInfo(const Maybe<mozilla::dom::ClientInfo>);
/**
* Low-level websocket API: handles network protocol.
@@ -92,6 +101,7 @@ interface nsIWebSocketChannel : nsISupports
* @param aCookieJarSettings
* @param aSecurityFlags
* @param aContentPolicyType
+ * @param aClientInfo
* These will be used as values for the nsILoadInfo object on the
* created channel. For details, see nsILoadInfo in nsILoadInfo.idl
* @return reference to the new nsIChannel object
@@ -109,6 +119,7 @@ interface nsIWebSocketChannel : nsISupports
in nsICookieJarSettings aCookieJarSettings,
in unsigned long aSecurityFlags,
in nsContentPolicyType aContentPolicyType,
+ in MaybeClientInfo aClientInfo,
in unsigned long aSandboxFlags);
/**