Bug 635977. Make sure to always send OnStartRequest to our listener from nsIndexedToHTML. r=jduell, a=bsmedberg

This commit is contained in:
Boris Zbarsky 2011-02-24 13:42:15 -05:00
parent e191f7a6a9
commit 22613609cd
2 changed files with 28 additions and 13 deletions

View File

@ -151,6 +151,29 @@ nsIndexedToHTML::AsyncConvertData(const char *aFromType,
NS_IMETHODIMP
nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) {
nsString buffer;
nsresult rv = DoOnStartRequest(request, aContext, buffer);
if (NS_FAILED(rv)) {
request->Cancel(rv);
}
rv = mListener->OnStartRequest(request, aContext);
if (NS_FAILED(rv)) return rv;
// The request may have been canceled, and if that happens, we want to
// suppress calls to OnDataAvailable.
request->GetStatus(&rv);
if (NS_FAILED(rv)) return rv;
// Push our buffer to the listener.
rv = FormatInputStream(request, aContext, buffer);
return rv;
}
nsresult
nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext,
nsString& aBuffer) {
nsresult rv;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
@ -670,18 +693,7 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) {
" </thead>\n");
buffer.AppendLiteral(" <tbody>\n");
// Push buffer to the listener now, so the initial HTML will not
// be parsed in OnDataAvailable().
rv = mListener->OnStartRequest(request, aContext);
if (NS_FAILED(rv)) return rv;
// The request may have been canceled, and if that happens, we want to
// suppress calls to OnDataAvailable.
request->GetStatus(&rv);
if (NS_FAILED(rv)) return rv;
rv = FormatInputStream(request, aContext, buffer);
aBuffer = buffer;
return rv;
}

View File

@ -75,7 +75,10 @@ public:
protected:
void FormatSizeString(PRInt64 inSize, nsString& outSizeString);
nsresult FormatInputStream(nsIRequest* aRequest, nsISupports *aContext, const nsAString &aBuffer);
nsresult FormatInputStream(nsIRequest* aRequest, nsISupports *aContext, const nsAString &aBuffer);
// Helper to properly implement OnStartRequest
nsresult DoOnStartRequest(nsIRequest* request, nsISupports *aContext,
nsString& aBuffer);
protected:
nsCOMPtr<nsIDirIndexParser> mParser;