commit 4ff46835ea256761575b1b760dc45a423ed02125
parent ddcbf623f75cfd0867c6125e3cdd09c51b8df3a7
Author: Nika Layzell <nika@thelayzells.com>
Date: Thu, 20 Nov 2025 23:12:06 +0000
Bug 2000994 - Part 3: Use nsBaseParentChannel for nsDataChannel, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D273126
Diffstat:
14 files changed, 33 insertions(+), 312 deletions(-)
diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp
@@ -12,7 +12,6 @@
#include "mozilla/net/HttpChannelChild.h"
#include "mozilla/net/ChildDNSService.h"
#include "mozilla/net/CookieServiceChild.h"
-#include "mozilla/net/DataChannelChild.h"
#ifdef MOZ_WIDGET_GTK
# include "mozilla/net/GIOChannelChild.h"
#endif
diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp
@@ -18,7 +18,6 @@
#include "mozilla/net/CookieServiceParent.h"
#include "mozilla/net/WebSocketChannelParent.h"
#include "mozilla/net/WebSocketEventListenerParent.h"
-#include "mozilla/net/DataChannelParent.h"
#ifdef MOZ_WIDGET_GTK
# include "mozilla/net/GIOChannelParent.h"
#endif
@@ -328,20 +327,6 @@ mozilla::ipc::IPCResult NeckoParent::RecvConnectBaseChannel(
return IPC_OK();
}
-already_AddRefed<PDataChannelParent> NeckoParent::AllocPDataChannelParent(
- const uint32_t& channelId) {
- RefPtr<DataChannelParent> p = new DataChannelParent();
- return p.forget();
-}
-
-mozilla::ipc::IPCResult NeckoParent::RecvPDataChannelConstructor(
- PDataChannelParent* actor, const uint32_t& channelId) {
- DataChannelParent* p = static_cast<DataChannelParent*>(actor);
- DebugOnly<bool> rv = p->Init(channelId);
- MOZ_ASSERT(rv);
- return IPC_OK();
-}
-
#ifdef MOZ_WIDGET_GTK
static already_AddRefed<nsIPrincipal> GetRequestingPrincipal(
const GIOChannelCreationArgs& aArgs) {
diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h
@@ -139,11 +139,6 @@ class NeckoParent : public PNeckoParent {
mozilla::ipc::IPCResult RecvConnectBaseChannel(const uint32_t& channelId);
- already_AddRefed<PDataChannelParent> AllocPDataChannelParent(
- const uint32_t& channelId);
-
- virtual mozilla::ipc::IPCResult RecvPDataChannelConstructor(
- PDataChannelParent* aActor, const uint32_t& channelId) override;
# ifdef MOZ_WIDGET_GTK
PGIOChannelParent* AllocPGIOChannelParent(
PBrowserParent* aBrowser, const SerializedLoadContext& aSerialized,
diff --git a/netwerk/ipc/PDataChannel.ipdl b/netwerk/ipc/PDataChannel.ipdl
@@ -1,25 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
-
-/* 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 protocol PNecko;
-
-namespace mozilla {
-namespace net {
-
-[ChildImpl=virtual]
-async protocol PDataChannel
-{
- manager PNecko;
-
-parent:
- // Note: channels are opened during construction, so no open method here:
- // see PNecko.ipdl
- async __delete__();
-};
-
-} // namespace net
-} // namespace mozilla
diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl
@@ -21,7 +21,6 @@ include protocol PTCPSocket;
include protocol PTCPServerSocket;
include protocol PUDPSocket;
include protocol PDNSRequest;
-include protocol PDataChannel;
include protocol PTransportProvider;
include protocol PStunAddrsRequest;
include protocol PFileChannel;
@@ -59,7 +58,6 @@ namespace net {
manages PTCPServerSocket;
manages PUDPSocket;
manages PDNSRequest;
- manages PDataChannel;
#ifdef MOZ_WIDGET_GTK
manages PGIOChannel;
#endif
@@ -120,11 +118,6 @@ parent:
*/
async ConnectBaseChannel(uint32_t channelId);
- /**
- * channelId is used to establish a connection between redirect channels in
- * the parent and the child when we're redirecting to a data: URI.
- */
- async PDataChannel(uint32_t channelId);
#ifdef MOZ_WIDGET_GTK
async PGIOChannel(nullable PBrowser browser, SerializedLoadContext loadContext, GIOChannelCreationArgs args);
#endif
diff --git a/netwerk/ipc/moz.build b/netwerk/ipc/moz.build
@@ -75,7 +75,6 @@ PREPROCESSED_IPDL_SOURCES += [
IPDL_SOURCES = [
"NeckoChannelParams.ipdlh",
- "PDataChannel.ipdl",
"PDocumentChannel.ipdl",
"PFileChannel.ipdl",
"PInputChannelThrottleQueue.ipdl",
diff --git a/netwerk/protocol/data/DataChannelChild.cpp b/netwerk/protocol/data/DataChannelChild.cpp
@@ -1,57 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=4 sw=2 sts=2 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 "DataChannelChild.h"
-
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/net/NeckoChild.h"
-
-namespace mozilla {
-namespace net {
-
-NS_IMPL_ISUPPORTS_INHERITED(DataChannelChild, nsDataChannel, nsIChildChannel)
-
-DataChannelChild::DataChannelChild(nsIURI* aURI)
- : nsDataChannel(aURI), mIPCOpen(false) {}
-
-NS_IMETHODIMP
-DataChannelChild::ConnectParent(uint32_t aId) {
- mozilla::dom::ContentChild* cc =
- static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager());
- if (cc->IsShuttingDown()) {
- return NS_ERROR_FAILURE;
- }
-
- if (!gNeckoChild->SendPDataChannelConstructor(this, aId)) {
- return NS_ERROR_FAILURE;
- }
-
- // IPC now has a ref to us.
- mIPCOpen = true;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelChild::CompleteRedirectSetup(nsIStreamListener* aListener) {
- nsresult rv;
- rv = AsyncOpen(aListener);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
- }
-
- if (mIPCOpen) {
- (void)Send__delete__(this);
- }
- return NS_OK;
-}
-
-void DataChannelChild::ActorDestroy(ActorDestroyReason why) {
- MOZ_ASSERT(mIPCOpen);
- mIPCOpen = false;
-}
-
-} // namespace net
-} // namespace mozilla
diff --git a/netwerk/protocol/data/DataChannelChild.h b/netwerk/protocol/data/DataChannelChild.h
@@ -1,40 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=4 sw=2 sts=2 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/. */
-
-#ifndef NS_DATACHANNELCHILD_H
-#define NS_DATACHANNELCHILD_H
-
-#include "nsDataChannel.h"
-#include "nsIChildChannel.h"
-#include "nsISupportsImpl.h"
-
-#include "mozilla/net/PDataChannelChild.h"
-
-namespace mozilla {
-namespace net {
-
-class DataChannelChild : public nsDataChannel,
- public nsIChildChannel,
- public PDataChannelChild {
- public:
- explicit DataChannelChild(nsIURI* uri);
-
- NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_NSICHILDCHANNEL
-
- protected:
- virtual void ActorDestroy(ActorDestroyReason why) override;
-
- private:
- ~DataChannelChild() = default;
-
- bool mIPCOpen;
-};
-
-} // namespace net
-} // namespace mozilla
-
-#endif /* NS_DATACHANNELCHILD_H */
diff --git a/netwerk/protocol/data/DataChannelParent.cpp b/netwerk/protocol/data/DataChannelParent.cpp
@@ -1,105 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=4 sw=2 sts=2 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 "DataChannelParent.h"
-#include "mozilla/Assertions.h"
-#include "mozilla/dom/ContentParent.h"
-#include "mozilla/net/NeckoParent.h"
-#include "nsNetUtil.h"
-#include "nsIChannel.h"
-
-#ifdef FUZZING_SNAPSHOT
-# define MOZ_ALWAYS_SUCCEEDS_FUZZING(...) (void)__VA_ARGS__
-#else
-# define MOZ_ALWAYS_SUCCEEDS_FUZZING(...) MOZ_ALWAYS_SUCCEEDS(__VA_ARGS__)
-#endif
-
-namespace mozilla {
-namespace net {
-
-NS_IMPL_ISUPPORTS(DataChannelParent, nsIParentChannel, nsIStreamListener)
-
-bool DataChannelParent::Init(const uint64_t& aChannelId) {
- nsCOMPtr<nsIChannel> channel;
-
- MOZ_ALWAYS_SUCCEEDS_FUZZING(
- NS_LinkRedirectChannels(aChannelId, this, getter_AddRefs(channel)));
-
- return true;
-}
-
-NS_IMETHODIMP
-DataChannelParent::SetParentListener(ParentChannelListener* aListener) {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags,
- bool aIsThirdParty) {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::SetClassifierMatchedInfo(const nsACString& aList,
- const nsACString& aProvider,
- const nsACString& aFullHash) {
- // nothing to do
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::SetClassifierMatchedTrackingInfo(
- const nsACString& aLists, const nsACString& aFullHashes) {
- // nothing to do
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::Delete() {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::GetRemoteType(nsACString& aRemoteType) {
- if (!CanSend()) {
- return NS_ERROR_UNEXPECTED;
- }
-
- dom::PContentParent* pcp = Manager()->Manager();
- aRemoteType = static_cast<dom::ContentParent*>(pcp)->GetRemoteType();
- return NS_OK;
-}
-
-void DataChannelParent::ActorDestroy(ActorDestroyReason why) {}
-
-NS_IMETHODIMP
-DataChannelParent::OnStartRequest(nsIRequest* aRequest) {
- // We don't have a way to prevent nsBaseChannel from calling AsyncOpen on
- // the created nsDataChannel. We don't have anywhere to send the data in the
- // parent, so abort the binding.
- return NS_BINDING_ABORTED;
-}
-
-NS_IMETHODIMP
-DataChannelParent::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
- // See above.
- MOZ_ASSERT(NS_FAILED(aStatusCode));
- return NS_OK;
-}
-
-NS_IMETHODIMP
-DataChannelParent::OnDataAvailable(nsIRequest* aRequest,
- nsIInputStream* aInputStream,
- uint64_t aOffset, uint32_t aCount) {
- // See above.
- MOZ_CRASH("Should never be called");
-}
-
-} // namespace net
-} // namespace mozilla
diff --git a/netwerk/protocol/data/DataChannelParent.h b/netwerk/protocol/data/DataChannelParent.h
@@ -1,39 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=4 sw=2 sts=2 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/. */
-
-#ifndef NS_DATACHANNELPARENT_H
-#define NS_DATACHANNELPARENT_H
-
-#include "nsIParentChannel.h"
-#include "nsISupportsImpl.h"
-
-#include "mozilla/net/PDataChannelParent.h"
-
-namespace mozilla {
-namespace net {
-
-// In order to support HTTP redirects to data:, we need to implement the HTTP
-// redirection API, which requires a class that implements nsIParentChannel
-// and which calls NS_LinkRedirectChannels.
-class DataChannelParent : public nsIParentChannel, public PDataChannelParent {
- public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIPARENTCHANNEL
- NS_DECL_NSIREQUESTOBSERVER
- NS_DECL_NSISTREAMLISTENER
-
- [[nodiscard]] bool Init(const uint64_t& aChannelId);
-
- private:
- ~DataChannelParent() = default;
-
- virtual void ActorDestroy(ActorDestroyReason why) override;
-};
-
-} // namespace net
-} // namespace mozilla
-
-#endif /* NS_DATACHANNELPARENT_H */
diff --git a/netwerk/protocol/data/moz.build b/netwerk/protocol/data/moz.build
@@ -4,11 +4,6 @@
# 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/.
-EXPORTS.mozilla.net += [
- "DataChannelChild.h",
- "DataChannelParent.h",
-]
-
XPIDL_SOURCES += [
"nsIDataChannel.idl",
]
@@ -21,8 +16,6 @@ EXPORTS += [
]
UNIFIED_SOURCES += [
- "DataChannelChild.cpp",
- "DataChannelParent.cpp",
"nsDataChannel.cpp",
"nsDataHandler.cpp",
]
diff --git a/netwerk/protocol/data/nsDataChannel.cpp b/netwerk/protocol/data/nsDataChannel.cpp
@@ -9,20 +9,22 @@
#include "mozilla/Base64.h"
#include "mozilla/dom/MimeType.h"
+#include "mozilla/net/NeckoChild.h"
+#include "mozilla/net/NeckoCommon.h"
#include "nsDataHandler.h"
#include "nsIInputStream.h"
#include "nsEscape.h"
#include "nsISupports.h"
#include "nsStringStream.h"
#include "nsIObserverService.h"
-#include "mozilla/dom/ContentParent.h"
+#include "mozilla/dom/ContentChild.h"
#include "../protocol/http/nsHttpHandler.h"
using namespace mozilla;
using namespace mozilla::net;
NS_IMPL_ISUPPORTS_INHERITED(nsDataChannel, nsBaseChannel, nsIDataChannel,
- nsIIdentChannel)
+ nsIIdentChannel, nsIChildChannel)
/**
* Helper for performing a fallible unescape.
@@ -176,3 +178,27 @@ nsDataChannel::SetChannelId(uint64_t aChannelId) {
mChannelId = aChannelId;
return NS_OK;
}
+
+//-----------------------------------------------------------------------------
+// nsDataChannel::nsIChildChannel
+
+NS_IMETHODIMP
+nsDataChannel::ConnectParent(uint32_t aId) {
+ if (!IsNeckoChild()) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+ }
+
+ mozilla::dom::ContentChild* cc =
+ static_cast<mozilla::dom::ContentChild*>(gNeckoChild->Manager());
+ if (cc->IsShuttingDown()) {
+ return NS_ERROR_FAILURE;
+ }
+
+ gNeckoChild->SendConnectBaseChannel(aId);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDataChannel::CompleteRedirectSetup(nsIStreamListener* aListener) {
+ return AsyncOpen(aListener);
+}
diff --git a/netwerk/protocol/data/nsDataChannel.h b/netwerk/protocol/data/nsDataChannel.h
@@ -9,19 +9,22 @@
#define nsDataChannel_h___
#include "nsBaseChannel.h"
+#include "nsIChildChannel.h"
#include "nsIDataChannel.h"
class nsIInputStream;
class nsDataChannel : public nsBaseChannel,
public nsIDataChannel,
- public nsIIdentChannel {
+ public nsIIdentChannel,
+ public nsIChildChannel {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDATACHANNEL
NS_FORWARD_NSIREQUEST(nsBaseChannel::)
NS_FORWARD_NSICHANNEL(nsBaseChannel::)
NS_DECL_NSIIDENTCHANNEL
+ NS_DECL_NSICHILDCHANNEL
explicit nsDataChannel(nsIURI* uri) { SetURI(uri); }
diff --git a/netwerk/protocol/data/nsDataHandler.cpp b/netwerk/protocol/data/nsDataHandler.cpp
@@ -8,7 +8,6 @@
#include "nsNetCID.h"
#include "nsError.h"
#include "nsIOService.h"
-#include "DataChannelChild.h"
#include "nsNetUtil.h"
#include "nsSimpleURI.h"
#include "nsUnicharUtils.h"
@@ -86,12 +85,7 @@ NS_IMETHODIMP
nsDataHandler::NewChannel(nsIURI* uri, nsILoadInfo* aLoadInfo,
nsIChannel** result) {
NS_ENSURE_ARG_POINTER(uri);
- RefPtr<nsDataChannel> channel;
- if (XRE_IsParentProcess()) {
- channel = new nsDataChannel(uri);
- } else {
- channel = new mozilla::net::DataChannelChild(uri);
- }
+ RefPtr<nsDataChannel> channel = new nsDataChannel(uri);
// set the loadInfo on the new channel
nsresult rv = channel->SetLoadInfo(aLoadInfo);