From 1e0da4f45efe75bcb36a2e9eab65d50e1476b30e Mon Sep 17 00:00:00 2001 From: Steve Workman Date: Wed, 3 Apr 2013 10:48:22 -0700 Subject: [PATCH] Bug 808402 - Make call to nsIPrompt::Alert from nsFtpState::StopProcessing async r=jduell --- .../protocol/ftp/nsFtpConnectionThread.cpp | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp index 5340ec6cdc0a..8b765eb80cb6 100644 --- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp @@ -1848,6 +1848,32 @@ nsFtpState::KillControlConnection() mControlConnection = nullptr; } +class nsFtpAsyncAlert : public nsRunnable +{ +public: + nsFtpAsyncAlert(nsIPrompt *aPrompter, nsACString& aResponseMsg) + : mPrompter(aPrompter) + , mResponseMsg(aResponseMsg) + { + MOZ_COUNT_CTOR(nsFtpAsyncAlert); + } + virtual ~nsFtpAsyncAlert() + { + MOZ_COUNT_DTOR(nsFtpAsyncAlert); + } + NS_IMETHOD Run() + { + if (mPrompter) { + mPrompter->Alert(nullptr, NS_ConvertASCIItoUTF16(mResponseMsg).get()); + } + return NS_OK; + } +private: + nsCOMPtr mPrompter; + nsCString mResponseMsg; +}; + + nsresult nsFtpState::StopProcessing() { @@ -1869,8 +1895,11 @@ nsFtpState::StopProcessing() // XXX(darin): this code should not be dictating UI like this! nsCOMPtr prompter; mChannel->GetCallback(prompter); - if (prompter) - prompter->Alert(nullptr, NS_ConvertASCIItoUTF16(mResponseMsg).get()); + if (prompter) { + nsCOMPtr alertEvent = + new nsFtpAsyncAlert(prompter, mResponseMsg); + NS_DispatchToMainThread(alertEvent, NS_DISPATCH_NORMAL); + } } nsresult broadcastErrorCode = mControlStatus;