for subscribe, root the tree in null, so that it goes blank when you switch servers.

start of fix for a bad news compatibility bug with Typhoon news servers.
(rest of fix coming soon.)

Fix it so if we don't have a msg window, we use the hidden window for the parent
of the username/password dialog.

general code cleanup.
This commit is contained in:
sspitzer%netscape.com 2000-04-30 00:27:23 +00:00
parent d4645e2135
commit 532dda5081
3 changed files with 87 additions and 71 deletions

View File

@ -62,6 +62,8 @@ function SetUpTree()
{
dump("SetUpTree()\n");
gSubscribeTree.setAttribute('ref',null);
var folder = GetMsgFolderFromUri(gServerURI);
var server = folder.server;

View File

@ -152,6 +152,7 @@ static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kCMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kPrefServiceCID,NS_PREF_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
typedef struct _cancelInfoEntry {
char *from;
@ -1195,6 +1196,9 @@ nsresult nsNNTPProtocol::ParseURL(nsIURI * aURL, PRBool * bValP, char ** aGroup,
PRInt32 nsNNTPProtocol::SendData(nsIURI * aURL, const char * dataBuffer)
{
NNTP_LOG_WRITE(dataBuffer);
#ifdef DEBUG_sspitzer
printf("SEND: %s\n",dataBuffer);
#endif
return nsMsgProtocol::SendData(aURL, dataBuffer); // base class actually transmits the data
}
@ -1207,6 +1211,7 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng
{
char * line = nsnull;
PRUint32 status = 0;
nsresult rv;
NS_PRECONDITION(nsnull != inputStream, "invalid input stream");
@ -1242,33 +1247,16 @@ PRInt32 nsNNTPProtocol::NewsResponse(nsIInputStream * inputStream, PRUint32 leng
m_previousResponseCode = m_responseCode;
PR_sscanf(line, "%d", &m_responseCode);
/* fix this, it is too agressive */
#if 1
PRInt32 major_opcode = MK_NNTP_RESPONSE_TYPE(m_responseCode);
if (((major_opcode == MK_NNTP_RESPONSE_TYPE_CANNOT) ||
(major_opcode == MK_NNTP_RESPONSE_TYPE_ERROR)) &&
((m_responseCode != MK_NNTP_RESPONSE_AUTHINFO_REQUIRE) &&
(m_responseCode != MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_REQUIRE))) {
nsresult rv;
nsCOMPtr <nsIPrompt> dialog = do_GetService(kCNetSupportDialogCID, &rv);
if (NS_SUCCEEDED(rv) || dialog) {
nsXPIDLString errorText;
GetNewsStringByName("errorFromServer", getter_Copies(errorText));
nsAutoString combinedMsg = NS_STATIC_CAST(const PRUnichar*, errorText);
combinedMsg.AppendWithConversion(m_responseText);
rv = dialog->Alert(combinedMsg.GetUnicode());
// XXX: todo, check rv?
}
if (m_responseCode == MK_NNTP_RESPONSE_AUTHINFO_DENIED) {
if (m_newsFolder) {
rv = m_newsFolder->ForgetGroupUsername();
rv = m_newsFolder->ForgetGroupPassword();
}
#ifdef DEBUG_sspitzer
printf("RECV: %s\n",line);
#endif
if (m_responseCode == MK_NNTP_RESPONSE_AUTHINFO_DENIED) {
if (m_newsFolder) {
rv = m_newsFolder->ForgetGroupUsername();
rv = m_newsFolder->ForgetGroupPassword();
}
}
#endif /* 1 */
/* authentication required can come at any time
*/
@ -2436,15 +2424,7 @@ PRInt32 nsNNTPProtocol::BeginAuthorization()
}
}
if (!m_msgWindow) {
NS_ASSERTION(m_msgWindow,"unable to get the msg window, so no password dialog");
NNTP_LOG_NOTE("unable to get the msg window");
rv = NS_ERROR_NULL_POINTER;
}
if (NS_SUCCEEDED(rv)) {
rv = m_newsFolder->GetGroupUsernameWithUI(usernamePromptText, nsnull, m_msgWindow, getter_Copies(username));
}
rv = m_newsFolder->GetGroupUsernameWithUI(usernamePromptText, nsnull, m_msgWindow, getter_Copies(username));
}
else {
#ifdef DEBUG_sspitzer
@ -2564,14 +2544,7 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
}
}
if (!m_msgWindow) {
rv = NS_ERROR_NULL_POINTER;
NNTP_LOG_NOTE("unable to get the msg window");
}
if (NS_SUCCEEDED(rv)) {
rv = m_newsFolder->GetGroupPasswordWithUI(passwordPromptText, passwordPromptTitleText, m_msgWindow, getter_Copies(password));
}
rv = m_newsFolder->GetGroupPasswordWithUI(passwordPromptText, passwordPromptTitleText, m_msgWindow, getter_Copies(password));
}
else {
NNTP_LOG_NOTE("we don't know the folder");
@ -2637,6 +2610,7 @@ PRInt32 nsNNTPProtocol::AuthorizationResponse()
PRInt32 nsNNTPProtocol::PasswordResponse()
{
nsresult rv;
if (MK_NNTP_RESPONSE_AUTHINFO_OK == m_responseCode ||
MK_NNTP_RESPONSE_AUTHINFO_SIMPLE_OK == m_responseCode)
@ -2683,8 +2657,6 @@ PRInt32 nsNNTPProtocol::PasswordResponse()
m_responseText ? m_responseText : ""));
if (m_newsFolder) {
nsresult rv;
rv = m_newsFolder->ForgetGroupUsername();
rv = m_newsFolder->ForgetGroupPassword();
}
@ -3305,9 +3277,6 @@ PRInt32 nsNNTPProtocol::ReadNewsgroupBody(nsIInputStream * inputStream, PRUint32
return !NS_SUCCEEDED(rv);
}
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define NEWS_MSGS_URL "chrome://messenger/locale/news.properties"
nsresult nsNNTPProtocol::GetNewsStringByName(const char *aName, PRUnichar **aString)
{

View File

@ -67,6 +67,10 @@
#include "nsINntpUrl.h"
#include "nsNewsSummarySpec.h"
#include "nsIAppShellService.h"
#include "nsIXULWindow.h"
#include "nsAppShellCIDs.h"
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
@ -78,6 +82,7 @@ static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID);
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
#define PREF_NEWS_ABBREVIATE_PRETTY_NAMES "news.abbreviate_pretty_name"
@ -1397,21 +1402,41 @@ nsMsgNewsFolder::GetGroupPasswordWithUI(const PRUnichar * aPromptMessage, const
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(aMsgWindow);
NS_ENSURE_ARG_POINTER(aGroupPassword);
if (!mGroupPassword) {
// prompt the user for the password
nsCOMPtr<nsIWebShell> webShell;
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
if (NS_FAILED(rv)) return rv;
// get top level window
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINetPrompt> dialog( do_QueryInterface( topLevelWindow, &rv ) );
if (NS_SUCCEEDED(rv))
{
// prompt the user for the password
nsCOMPtr<nsINetPrompt> dialog;
NS_ASSERTION(aMsgWindow,"no msg window, fix this, for now, use the hidden window");
if (aMsgWindow) {
nsCOMPtr<nsIWebShell> webShell;
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
if (NS_FAILED(rv)) return rv;
dialog = do_QueryInterface(topLevelWindow, &rv);
if (NS_FAILED(rv)) return rv;
}
else {
nsCOMPtr <nsIAppShellService> appshellservice = do_GetService(kAppShellServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
if (!appshellservice) return NS_ERROR_FAILURE;
nsCOMPtr<nsIXULWindow> xulWindow;
rv = appshellservice->GetHiddenWindow(getter_AddRefs(xulWindow));
if (NS_FAILED(rv)) return rv;
if (!xulWindow) return NS_ERROR_FAILURE;
dialog = do_QueryInterface(xulWindow, &rv);
if (NS_FAILED(rv)) return rv;
}
NS_ASSERTION(dialog,"we didn't get a net prompt");
if (dialog) {
nsXPIDLString uniGroupPassword;
PRBool okayValue = PR_TRUE;
@ -1449,21 +1474,41 @@ nsMsgNewsFolder::GetGroupUsernameWithUI(const PRUnichar * aPromptMessage, const
{
nsresult rv = NS_ERROR_FAILURE;;
NS_ENSURE_ARG_POINTER(aMsgWindow);
NS_ENSURE_ARG_POINTER(aGroupUsername);
if (!mGroupUsername) {
// prompt the user for the password
nsCOMPtr<nsIWebShell> webShell;
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
if (NS_FAILED(rv)) return rv;
// get top level window
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINetPrompt> dialog( do_QueryInterface( topLevelWindow, &rv ) );
if (NS_SUCCEEDED(rv))
{
// prompt the user for the username
nsCOMPtr<nsINetPrompt> dialog;
NS_ASSERTION(aMsgWindow,"no msg window, fix this, for now, use the hidden window");
if (aMsgWindow) {
nsCOMPtr<nsIWebShell> webShell;
rv = aMsgWindow->GetRootWebShell(getter_AddRefs(webShell));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
rv = webShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
if (NS_FAILED(rv)) return rv;
dialog = do_QueryInterface(topLevelWindow, &rv);
if (NS_FAILED(rv)) return rv;
}
else {
nsCOMPtr <nsIAppShellService> appshellservice = do_GetService(kAppShellServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
if (!appshellservice) return NS_ERROR_FAILURE;
nsCOMPtr<nsIXULWindow> xulWindow;
rv = appshellservice->GetHiddenWindow(getter_AddRefs(xulWindow));
if (NS_FAILED(rv)) return rv;
if (!xulWindow) return NS_ERROR_FAILURE;
dialog = do_QueryInterface(xulWindow, &rv);
if (NS_FAILED(rv)) return rv;
}
NS_ASSERTION(dialog,"we didn't get a net prompt");
if (dialog) {
nsXPIDLString uniGroupUsername;
PRBool okayValue = PR_TRUE;