commit ddcbf623f75cfd0867c6125e3cdd09c51b8df3a7
parent d50f9cb3f3b18966d66f90f271d96bd9ae10cbf1
Author: Nika Layzell <nika@thelayzells.com>
Date: Thu, 20 Nov 2025 23:12:06 +0000
Bug 2000994 - Part 2: Use nsBaseParentChannel for SimpleChannel, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D273125
Diffstat:
12 files changed, 15 insertions(+), 257 deletions(-)
diff --git a/netwerk/base/SimpleChannel.cpp b/netwerk/base/SimpleChannel.cpp
@@ -17,11 +17,12 @@
#include "mozilla/Try.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/net/NeckoChild.h"
-#include "mozilla/net/PSimpleChannelChild.h"
namespace mozilla {
namespace net {
+NS_IMPL_ISUPPORTS_INHERITED(SimpleChannel, nsBaseChannel, nsIChildChannel)
+
SimpleChannel::SimpleChannel(UniquePtr<SimpleChannelCallbacks>&& aCallbacks)
: mCallbacks(std::move(aCallbacks)) {
EnableSynthesizedProgressEvents(true);
@@ -73,57 +74,31 @@ nsresult SimpleChannel::BeginAsyncRead(nsIStreamListener* listener,
return NS_OK;
}
-NS_IMPL_ISUPPORTS_INHERITED(SimpleChannelChild, SimpleChannel, nsIChildChannel)
-
-SimpleChannelChild::SimpleChannelChild(
- UniquePtr<SimpleChannelCallbacks>&& aCallbacks)
- : SimpleChannel(std::move(aCallbacks)) {}
-
NS_IMETHODIMP
-SimpleChannelChild::ConnectParent(uint32_t aId) {
- MOZ_ASSERT(NS_IsMainThread());
+SimpleChannel::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;
}
- // Reference freed in DeallocPSimpleChannelChild.
- if (!gNeckoChild->SendPSimpleChannelConstructor(do_AddRef(this).take(),
- aId)) {
- return NS_ERROR_FAILURE;
- }
-
+ gNeckoChild->SendConnectBaseChannel(aId);
return NS_OK;
}
NS_IMETHODIMP
-SimpleChannelChild::CompleteRedirectSetup(nsIStreamListener* aListener) {
- if (CanSend()) {
- MOZ_ASSERT(NS_IsMainThread());
- }
-
- nsresult rv;
- rv = AsyncOpen(aListener);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
- }
-
- if (CanSend()) {
- (void)Send__delete__(this);
- }
- return NS_OK;
+SimpleChannel::CompleteRedirectSetup(nsIStreamListener* aListener) {
+ return AsyncOpen(aListener);
}
already_AddRefed<nsIChannel> NS_NewSimpleChannelInternal(
nsIURI* aURI, nsILoadInfo* aLoadInfo,
UniquePtr<SimpleChannelCallbacks>&& aCallbacks) {
- RefPtr<SimpleChannel> chan;
- if (IsNeckoChild()) {
- chan = new SimpleChannelChild(std::move(aCallbacks));
- } else {
- chan = new SimpleChannel(std::move(aCallbacks));
- }
+ RefPtr<SimpleChannel> chan = new SimpleChannel(std::move(aCallbacks));
chan->SetURI(aURI);
diff --git a/netwerk/base/SimpleChannel.h b/netwerk/base/SimpleChannel.h
@@ -10,7 +10,6 @@
#include "mozilla/UniquePtr.h"
#include "nsBaseChannel.h"
#include "nsIChildChannel.h"
-#include "mozilla/net/PSimpleChannelChild.h"
#include "nsCOMPtr.h"
class nsIChannel;
@@ -70,8 +69,11 @@ class SimpleChannelCallbacksImpl final : public SimpleChannelCallbacks {
RefPtr<T> mContext;
};
-class SimpleChannel : public nsBaseChannel {
+class SimpleChannel : public nsBaseChannel, public nsIChildChannel {
public:
+ NS_DECL_ISUPPORTS_INHERITED
+ NS_DECL_NSICHILDCHANNEL
+
explicit SimpleChannel(UniquePtr<SimpleChannelCallbacks>&& aCallbacks);
protected:
@@ -88,19 +90,6 @@ class SimpleChannel : public nsBaseChannel {
UniquePtr<SimpleChannelCallbacks> mCallbacks;
};
-class SimpleChannelChild final : public SimpleChannel,
- public nsIChildChannel,
- public PSimpleChannelChild {
- public:
- explicit SimpleChannelChild(UniquePtr<SimpleChannelCallbacks>&& aCallbacks);
-
- NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_NSICHILDCHANNEL
-
- private:
- virtual ~SimpleChannelChild() = default;
-};
-
already_AddRefed<nsIChannel> NS_NewSimpleChannelInternal(
nsIURI* aURI, nsILoadInfo* aLoadInfo,
UniquePtr<SimpleChannelCallbacks>&& aCallbacks);
diff --git a/netwerk/base/SimpleChannelParent.cpp b/netwerk/base/SimpleChannelParent.cpp
@@ -1,97 +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 "SimpleChannelParent.h"
-#include "mozilla/Assertions.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(SimpleChannelParent, nsIParentChannel, nsIStreamListener)
-
-bool SimpleChannelParent::Init(const uint64_t& aChannelId) {
- nsCOMPtr<nsIChannel> channel;
-
- MOZ_ALWAYS_SUCCEEDS_FUZZING(
- NS_LinkRedirectChannels(aChannelId, this, getter_AddRefs(channel)));
-
- return true;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::SetParentListener(ParentChannelListener* aListener) {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags,
- bool aIsThirdParty) {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::SetClassifierMatchedInfo(const nsACString& aList,
- const nsACString& aProvider,
- const nsACString& aPrefix) {
- // nothing to do
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::SetClassifierMatchedTrackingInfo(
- const nsACString& aLists, const nsACString& aFullHashes) {
- // nothing to do
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::Delete() {
- // Nothing to do.
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::GetRemoteType(nsACString& aRemoteType) {
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-void SimpleChannelParent::ActorDestroy(ActorDestroyReason aWhy) {}
-
-NS_IMETHODIMP
-SimpleChannelParent::OnStartRequest(nsIRequest* aRequest) {
- // We don't have a way to prevent nsBaseChannel from calling AsyncOpen on
- // the created nsSimpleChannel. We don't have anywhere to send the data in the
- // parent, so abort the binding.
- return NS_BINDING_ABORTED;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
- // See above.
- MOZ_ASSERT(NS_FAILED(aStatusCode));
- return NS_OK;
-}
-
-NS_IMETHODIMP
-SimpleChannelParent::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/base/SimpleChannelParent.h b/netwerk/base/SimpleChannelParent.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_SIMPLECHANNELPARENT_H
-#define NS_SIMPLECHANNELPARENT_H
-
-#include "nsIParentChannel.h"
-#include "nsISupportsImpl.h"
-
-#include "mozilla/net/PSimpleChannelParent.h"
-
-namespace mozilla {
-namespace net {
-
-// In order to support HTTP redirects, we need to implement the HTTP
-// redirection API, which requires a class that implements nsIParentChannel
-// and which calls NS_LinkRedirectChannels.
-class SimpleChannelParent : public nsIParentChannel,
- public PSimpleChannelParent {
- public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIPARENTCHANNEL
- NS_DECL_NSIREQUESTOBSERVER
- NS_DECL_NSISTREAMLISTENER; // semicolon for clang-format bug 1629756
-
- [[nodiscard]] bool Init(const uint64_t& aChannelId);
-
- private:
- ~SimpleChannelParent() = default;
-
- virtual void ActorDestroy(ActorDestroyReason why) override;
-};
-
-} // namespace net
-} // namespace mozilla
-
-#endif /* NS_SIMPLECHANNELPARENT_H */
diff --git a/netwerk/base/moz.build b/netwerk/base/moz.build
@@ -174,7 +174,6 @@ EXPORTS.mozilla.net += [
"ProtocolHandlerInfo.h",
"RedirectChannelRegistrar.h",
"RequestContextService.h",
- "SimpleChannelParent.h",
"SimpleURIUnknownSchemes.h",
"SSLTokensCache.h",
"ThrottleQueue.h",
@@ -249,7 +248,6 @@ UNIFIED_SOURCES += [
"RequestContextService.cpp",
"SimpleBuffer.cpp",
"SimpleChannel.cpp",
- "SimpleChannelParent.cpp",
"SimpleURIUnknownSchemes.cpp",
"SSLTokensCache.cpp",
"SuspendableChannelWrapper.cpp",
diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp
@@ -190,17 +190,6 @@ bool NeckoChild::DeallocPWebSocketEventListenerChild(
return true;
}
-PSimpleChannelChild* NeckoChild::AllocPSimpleChannelChild(
- const uint32_t& channelId) {
- MOZ_ASSERT_UNREACHABLE("Should never get here");
- return nullptr;
-}
-
-bool NeckoChild::DeallocPSimpleChannelChild(PSimpleChannelChild* child) {
- static_cast<SimpleChannelChild*>(child)->Release();
- return true;
-}
-
PTCPSocketChild* NeckoChild::AllocPTCPSocketChild(const nsAString& host,
const uint16_t& port) {
TCPSocketChild* p = new TCPSocketChild(host, port, nullptr);
diff --git a/netwerk/ipc/NeckoChild.h b/netwerk/ipc/NeckoChild.h
@@ -61,8 +61,6 @@ class NeckoChild : public PNeckoChild {
PUDPSocketChild* AllocPUDPSocketChild(nsIPrincipal* aPrincipal,
const nsACString& aFilter);
bool DeallocPUDPSocketChild(PUDPSocketChild*);
- PSimpleChannelChild* AllocPSimpleChannelChild(const uint32_t& channelId);
- bool DeallocPSimpleChannelChild(PSimpleChannelChild* child);
PTransportProviderChild* AllocPTransportProviderChild();
bool DeallocPTransportProviderChild(PTransportProviderChild* aActor);
PWebSocketEventListenerChild* AllocPWebSocketEventListenerChild(
diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp
@@ -26,7 +26,6 @@
# include "mozilla/net/GeckoViewContentChannelParent.h"
#endif
#include "mozilla/net/DocumentChannelParent.h"
-#include "mozilla/net/SimpleChannelParent.h"
#include "mozilla/net/AltDataOutputStreamParent.h"
#include "mozilla/net/FileChannelParent.h"
#include "mozilla/net/DNSRequestParent.h"
@@ -428,25 +427,6 @@ mozilla::ipc::IPCResult NeckoParent::RecvPGeckoViewContentChannelConstructor(
}
#endif
-PSimpleChannelParent* NeckoParent::AllocPSimpleChannelParent(
- const uint32_t& channelId) {
- RefPtr<SimpleChannelParent> p = new SimpleChannelParent();
- return p.forget().take();
-}
-
-bool NeckoParent::DeallocPSimpleChannelParent(PSimpleChannelParent* actor) {
- RefPtr<SimpleChannelParent> p =
- dont_AddRef(actor).downcast<SimpleChannelParent>();
- return true;
-}
-
-mozilla::ipc::IPCResult NeckoParent::RecvPSimpleChannelConstructor(
- PSimpleChannelParent* actor, const uint32_t& channelId) {
- SimpleChannelParent* p = static_cast<SimpleChannelParent*>(actor);
- MOZ_ALWAYS_TRUE(p->Init(channelId));
- return IPC_OK();
-}
-
already_AddRefed<PFileChannelParent> NeckoParent::AllocPFileChannelParent() {
RefPtr<FileChannelParent> p = new FileChannelParent();
return p.forget();
diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h
@@ -166,11 +166,6 @@ class NeckoParent : public PNeckoParent {
const SerializedLoadContext& aSerialized,
const GeckoViewContentChannelArgs& args) override;
# endif
- PSimpleChannelParent* AllocPSimpleChannelParent(const uint32_t& channelId);
- bool DeallocPSimpleChannelParent(PSimpleChannelParent* actor);
-
- virtual mozilla::ipc::IPCResult RecvPSimpleChannelConstructor(
- PSimpleChannelParent* aActor, const uint32_t& channelId) override;
already_AddRefed<PFileChannelParent> AllocPFileChannelParent();
diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl
@@ -22,7 +22,6 @@ include protocol PTCPServerSocket;
include protocol PUDPSocket;
include protocol PDNSRequest;
include protocol PDataChannel;
-include protocol PSimpleChannel;
include protocol PTransportProvider;
include protocol PStunAddrsRequest;
include protocol PFileChannel;
@@ -67,7 +66,6 @@ namespace net {
#ifdef MOZ_WIDGET_ANDROID
manages PGeckoViewContentChannel;
#endif
- manages PSimpleChannel;
manages PFileChannel;
manages PTransportProvider;
manages PAltDataOutputStream;
@@ -130,7 +128,6 @@ parent:
#ifdef MOZ_WIDGET_GTK
async PGIOChannel(nullable PBrowser browser, SerializedLoadContext loadContext, GIOChannelCreationArgs args);
#endif
- async PSimpleChannel(uint32_t channelId);
async PFileChannel();
#ifdef MOZ_WIDGET_ANDROID
diff --git a/netwerk/ipc/PSimpleChannel.ipdl b/netwerk/ipc/PSimpleChannel.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 {
-
-[ManualDealloc, ChildImpl=virtual]
-async protocol PSimpleChannel
-{
- 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/moz.build b/netwerk/ipc/moz.build
@@ -81,7 +81,6 @@ IPDL_SOURCES = [
"PInputChannelThrottleQueue.ipdl",
"PProxyAutoConfig.ipdl",
"PProxyConfigLookup.ipdl",
- "PSimpleChannel.ipdl",
"PSocketProcessBackground.ipdl",
]