diff --git a/netwerk/protocol/ftp/FTPChannelChild.cpp b/netwerk/protocol/ftp/FTPChannelChild.cpp index 9cb64945633e..a4bbb3b35727 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.cpp +++ b/netwerk/protocol/ftp/FTPChannelChild.cpp @@ -5,11 +5,14 @@ * 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 "mozilla/SystemGroup.h" #include "mozilla/net/NeckoChild.h" #include "mozilla/net/ChannelDiverterChild.h" #include "mozilla/net/FTPChannelChild.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/DocGroup.h" #include "mozilla/dom/TabChild.h" +#include "nsContentUtils.h" #include "nsFtpProtocolHandler.h" #include "nsITabChild.h" #include "nsStringStream.h" @@ -198,6 +201,9 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext) rv = mozilla::ipc::LoadInfoToLoadInfoArgs(loadInfo, &openArgs.loadInfo()); NS_ENSURE_SUCCESS(rv, rv); + // This must happen before the constructor message is sent. + EnsureDispatcher(); + gNeckoChild-> SendPFTPChannelConstructor(this, tabChild, IPC::SerializedLoadContext(this), openArgs); @@ -608,7 +614,17 @@ FTPChannelChild::DoOnStopRequest(const nsresult& aChannelStatus, alertEvent = new nsFtpChildAsyncAlert(prompter, NS_ConvertASCIItoUTF16(aErrorMsg)); } - NS_DispatchToMainThread(alertEvent); + + if (mDispatcher) { + mDispatcher->Dispatch("FTPAlertEvent", + TaskCategory::Other, + alertEvent.forget()); + } else { + // In case |mDispatcher| is null, dispatch by SystemGroup. + SystemGroup::Dispatch("FTPAlertEvent", + TaskCategory::Other, + alertEvent.forget()); + } } } @@ -820,6 +836,9 @@ FTPChannelChild::ConnectParent(uint32_t id) tabChild = static_cast(iTabChild.get()); } + // This must happen before the constructor message is sent. + EnsureDispatcher(); + // The socket transport in the chrome process now holds a logical ref to us // until OnStopRequest, or we do a redirect, or we hit an IPDL error. AddIPDLReference(); @@ -924,6 +943,27 @@ FTPChannelChild::GetDivertingToParent(bool* aDiverting) return NS_OK; } +void +FTPChannelChild::EnsureDispatcher() +{ + if (mDispatcher) { + return; + } + + nsCOMPtr loadInfo; + GetLoadInfo(getter_AddRefs(loadInfo)); + + mDispatcher = nsContentUtils::GetDispatcherByLoadInfo(loadInfo); + if (!mDispatcher) { + return; + } + + nsCOMPtr target = + mDispatcher->EventTargetFor(TaskCategory::Network); + gNeckoChild->SetEventTargetForActor(this, target); + mEventQ->RetargetDeliveryTo(target); +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/ftp/FTPChannelChild.h b/netwerk/protocol/ftp/FTPChannelChild.h index 7739dd34272b..555cfcafd144 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.h +++ b/netwerk/protocol/ftp/FTPChannelChild.h @@ -23,6 +23,9 @@ #include "PrivateBrowsingChannel.h" namespace mozilla { + +class Dispatcher; + namespace net { // This class inherits logic from nsBaseChannel that is not needed for an @@ -150,6 +153,10 @@ private: // Set if SendSuspend is called. Determines if SendResume is needed when // diverting callbacks to parent. bool mSuspendSent; + + RefPtr mDispatcher; + + void EnsureDispatcher(); }; inline bool