Bug 471131: NNTP: Incomplete loading of multiple inline images/content r/sr=bienvenu
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -558,16 +558,21 @@ NS_IMETHODIMP nsNNTPProtocol::GetIsBusy(
*aIsBusy = m_connectionBusy;
return NS_OK;
}
NS_IMETHODIMP nsNNTPProtocol::SetIsBusy(PRBool aIsBusy)
{
PR_LOG(NNTP,PR_LOG_ALWAYS,("(%p) setting busy to %d",this, aIsBusy));
m_connectionBusy = aIsBusy;
+
+ // Maybe we could load another URI.
+ if (!aIsBusy && m_nntpServer)
+ m_nntpServer->PrepareForNextUrl(this);
+
return NS_OK;
}
NS_IMETHODIMP nsNNTPProtocol::GetIsCachedConnection(PRBool *aIsCachedConnection)
{
NS_ENSURE_ARG_POINTER(aIsCachedConnection);
*aIsCachedConnection = m_fromCache;
return NS_OK;
@@ -853,16 +858,17 @@ PRBool nsNNTPProtocol::ReadFromLocalCach
rv = pump->AsyncRead(cacheListener, m_channelContext);
NS_RELEASE(cacheListener);
if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
{
m_ContentType.Truncate();
m_channelListener = nsnull;
+ NNTP_LOG_NOTE("Loading message from offline storage");
return PR_TRUE;
}
}
else
mailnewsUrl->SetMsgIsInLocalCache(PR_FALSE);
}
}
@@ -944,31 +950,43 @@ NS_IMETHODIMP nsNNTPProtocol::AsyncOpen(
rv = NS_CheckPortSafety(port, "news");
if (NS_FAILED(rv))
return rv;
m_channelContext = ctxt;
m_channelListener = listener;
m_runningURL->GetNewsAction(&m_newsAction);
- // first, check if this is a message load that should come from either
- // the memory cache or the local msg cache.
- if (mailnewsUrl && (m_newsAction == nsINntpUrl::ActionFetchArticle || m_newsAction == nsINntpUrl::ActionFetchPart
- || m_newsAction == nsINntpUrl::ActionSaveMessageToDisk))
+
+ // Before running through the connection, try to see if we can grab the data
+ // from the offline storage or the memory cache. Only actions retrieving
+ // messages can be cached.
+ if (mailnewsUrl && (m_newsAction == nsINntpUrl::ActionFetchArticle ||
+ m_newsAction == nsINntpUrl::ActionFetchPart ||
+ m_newsAction == nsINntpUrl::ActionSaveMessageToDisk))
{
-
SetupPartExtractorListener(m_channelListener);
+
+ // Attempt to get the message from the offline storage cache. If this
+ // succeeds, we don't need to use our connection, so tell the server that we
+ // are ready for the next URL.
if (ReadFromLocalCache())
- return NS_OK;
-
- rv = OpenCacheEntry();
- if (NS_SUCCEEDED(rv)) return NS_OK; // if this didn't return an error then jump out now...
-
+ {
+ if (m_nntpServer)
+ m_nntpServer->PrepareForNextUrl(this);
+ return NS_OK;
+ }
+
+ // If it wasn't offline, try to get the cache from memory. If this call
+ // succeeds, we probably won't need the connection, but the cache might fail
+ // later on. The code there will determine if we need to fallback and will
+ // handle informing the server of our readiness.
+ if (NS_SUCCEEDED(OpenCacheEntry()))
+ return NS_OK;
}
- nsCOMPtr<nsIRequest> parentRequest;
return nsMsgProtocol::AsyncOpen(listener, ctxt);
}
nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
{
NS_ENSURE_ARG_POINTER(aURL);
nsCString group;
@@ -5259,18 +5277,16 @@ nsresult nsNNTPProtocol::ProcessProtocol
*/
FinishMemCacheEntry(PR_FALSE); // cleanup mem cache entry
if (m_responseCode != MK_NNTP_RESPONSE_ARTICLE_NOTFOUND && m_responseCode != MK_NNTP_RESPONSE_ARTICLE_NONEXIST)
return CloseConnection();
case NEWS_FREE:
// Remember when we last used this connection
m_lastActiveTimeStamp = PR_Now();
CleanupAfterRunningUrl();
- if (m_nntpServer)
- m_nntpServer->PrepareForNextUrl(this);
case NEWS_FINISHED:
return NS_OK;
break;
default:
/* big error */
return NS_ERROR_FAILURE;
} // end switch
--- a/mailnews/news/src/nsNntpMockChannel.cpp
+++ b/mailnews/news/src/nsNntpMockChannel.cpp
@@ -270,16 +270,17 @@ NS_IMETHODIMP nsNntpMockChannel::AsyncOp
nsresult
nsNntpMockChannel::AttachNNTPConnection(nsNNTPProtocol &protocol)
{
// First things first. Were we canceled? If so, tell the protocol.
if (m_channelState == CHANNEL_CLOSED || m_channelState == CHANNEL_UNOPENED)
return NS_ERROR_FAILURE;
+
// We're going to active the protocol now. Note that if the user has
// interacted with us through the nsIChannel API, we need to pass it to the
// protocol instance. We also need to initialize it. For best results, we're
// going to initialize the code and then set the values.
nsresult rv = protocol.Initialize(m_url, m_msgWindow);
NS_ENSURE_SUCCESS(rv, rv);
// Variable fun