ported from UXP: Convert UI-dictating FTP errors to console errors. (e9a87c9c)

This commit is contained in:
2022-04-01 15:53:02 +08:00
parent 6e91b61ef6
commit 2f7e663e80
2 changed files with 4 additions and 114 deletions
+1 -38
View File
@@ -516,31 +516,6 @@ FTPChannelChild::RecvOnStopRequest(const nsresult& aChannelStatus,
return IPC_OK();
}
class nsFtpChildAsyncAlert : public Runnable
{
public:
nsFtpChildAsyncAlert(nsIPrompt *aPrompter, nsString aResponseMsg)
: mPrompter(aPrompter)
, mResponseMsg(aResponseMsg)
{
}
protected:
virtual ~nsFtpChildAsyncAlert()
{
}
public:
NS_IMETHOD Run() override
{
if (mPrompter) {
mPrompter->Alert(nullptr, mResponseMsg.get());
}
return NS_OK;
}
private:
nsCOMPtr<nsIPrompt> mPrompter;
nsString mResponseMsg;
};
class MaybeDivertOnStopFTPEvent : public ChannelEvent
{
public:
@@ -598,19 +573,7 @@ FTPChannelChild::DoOnStopRequest(const nsresult& aChannelStatus,
(void)mListener->OnStopRequest(this, mListenerContext, aChannelStatus);
if (NS_FAILED(aChannelStatus) && !aErrorMsg.IsEmpty()) {
nsCOMPtr<nsIPrompt> prompter;
GetCallback(prompter);
if (prompter) {
nsCOMPtr<nsIRunnable> alertEvent;
if (aUseUTF8) {
alertEvent = new nsFtpChildAsyncAlert(prompter,
NS_ConvertUTF8toUTF16(aErrorMsg));
} else {
alertEvent = new nsFtpChildAsyncAlert(prompter,
NS_ConvertASCIItoUTF16(aErrorMsg));
}
NS_DispatchToMainThread(alertEvent);
}
NS_ERROR("FTP error on stop request.");
}
mListener = nullptr;
+3 -76
View File
@@ -29,7 +29,6 @@
#include "nsIStreamListenerTee.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIStringBundle.h"
#include "nsAuthInformationHolder.h"
#include "nsIProtocolProxyService.h"
#include "nsICancelable.h"
@@ -931,38 +930,7 @@ nsFtpState::R_syst() {
mServerType = FTP_VMS_TYPE;
} else {
NS_ERROR("Server type list format unrecognized.");
// Guessing causes crashes.
// (Of course, the parsing code should be more robust...)
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if (!bundleService)
return FTP_ERROR;
nsCOMPtr<nsIStringBundle> bundle;
nsresult rv = bundleService->CreateBundle(NECKO_MSGS_URL,
getter_AddRefs(bundle));
if (NS_FAILED(rv))
return FTP_ERROR;
char16_t* ucs2Response = ToNewUnicode(mResponseMsg);
const char16_t *formatStrings[1] = { ucs2Response };
NS_NAMED_LITERAL_STRING(name, "UnsupportedFTPServer");
nsXPIDLString formattedString;
rv = bundle->FormatStringFromName(name.get(), formatStrings, 1,
getter_Copies(formattedString));
free(ucs2Response);
if (NS_FAILED(rv))
return FTP_ERROR;
// TODO(darin): this code should not be dictating UI like this!
nsCOMPtr<nsIPrompt> prompter;
mChannel->GetCallback(prompter);
if (prompter)
prompter->Alert(nullptr, formattedString.get());
// since we just alerted the user, clear mResponseMsg,
// which is displayed to the user.
// clear mResponseMsg, which is displayed to the user.
mResponseMsg = "";
return FTP_ERROR;
}
@@ -1791,32 +1759,6 @@ nsFtpState::KillControlConnection()
mControlConnection = nullptr;
}
class nsFtpAsyncAlert : public Runnable
{
public:
nsFtpAsyncAlert(nsIPrompt *aPrompter, nsString aResponseMsg)
: mPrompter(aPrompter)
, mResponseMsg(aResponseMsg)
{
}
protected:
virtual ~nsFtpAsyncAlert()
{
}
public:
NS_IMETHOD Run() override
{
if (mPrompter) {
mPrompter->Alert(nullptr, mResponseMsg.get());
}
return NS_OK;
}
private:
nsCOMPtr<nsIPrompt> mPrompter;
nsString mResponseMsg;
};
nsresult
nsFtpState::StopProcessing()
{
@@ -1828,23 +1770,8 @@ nsFtpState::StopProcessing()
LOG_INFO(("FTP:(%x) nsFtpState stopping", this));
if (NS_FAILED(mInternalError) && !mResponseMsg.IsEmpty()) {
// check to see if the control status is bad.
// web shell wont throw an alert. we better:
// XXX(darin): this code should not be dictating UI like this!
nsCOMPtr<nsIPrompt> prompter;
mChannel->GetCallback(prompter);
if (prompter) {
nsCOMPtr<nsIRunnable> alertEvent;
if (mUseUTF8) {
alertEvent = new nsFtpAsyncAlert(prompter,
NS_ConvertUTF8toUTF16(mResponseMsg));
} else {
alertEvent = new nsFtpAsyncAlert(prompter,
NS_ConvertASCIItoUTF16(mResponseMsg));
}
NS_DispatchToMainThread(alertEvent);
}
NS_ERROR("FTP: bad control status.");
// check to see if the control status is bad; forward the error message.
nsCOMPtr<nsIFTPChannelParentInternal> ftpChanP;
mChannel->GetCallback(ftpChanP);
if (ftpChanP) {