From 2fcfad024a164cedf6e0589075b333b140b58828 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Wed, 2 Apr 2003 21:44:39 +0000 Subject: [PATCH] Bug 169980, document.load should add its document to the parent document's loadgroup so that if we leave the current page the load will be aborted aotomatically, r=harishd, sr=darin. --- content/xml/document/src/nsXMLDocument.cpp | 38 ++++++++++++++++++++-- content/xml/document/src/nsXMLDocument.h | 2 ++ htmlparser/src/nsParser.cpp | 2 -- parser/htmlparser/src/nsParser.cpp | 2 -- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 01ff25648491..4ad8b4540ea8 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -62,6 +62,7 @@ #include "nsIDOMElement.h" #include "nsIDOMText.h" #include "nsIBaseWindow.h" +#include "nsIDOMWindow.h" #include "nsIDOMCDATASection.h" #include "nsIDOMProcessingInstruction.h" #include "nsIDOMDocumentType.h" @@ -376,6 +377,30 @@ nsXMLDocument::EvaluateXPointer(const nsAString& aExpression, return nsXPointer::Evaluate(this, aExpression, aResult); } +nsresult +nsXMLDocument::GetLoadGroup(nsILoadGroup **aLoadGroup) +{ + NS_ENSURE_ARG_POINTER(aLoadGroup); + *aLoadGroup = nsnull; + + if (mScriptContext) { + nsCOMPtr global; + mScriptContext->GetGlobalObject(getter_AddRefs(global)); + nsCOMPtr window = do_QueryInterface(global); + if (window) { + nsCOMPtr domdoc; + window->GetDocument(getter_AddRefs(domdoc)); + nsCOMPtr doc = do_QueryInterface(domdoc); + if (doc) { + doc->GetDocumentLoadGroup(aLoadGroup); + } + } + } + + return NS_OK; +} + + NS_IMETHODIMP nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) { @@ -440,7 +465,16 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) mCrossSiteAccessEnabled = crossSiteAccessEnabled; // Create a channel - rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, nsnull, this); + // When we are called from JS we can find the load group for the page, + // and add ourselves to it. This way any pending requests + // will be automatically aborted if the user leaves the page. + nsCOMPtr loadGroup; + GetLoadGroup(getter_AddRefs(loadGroup)); + + // nsIRequest::LOAD_BACKGROUND prevents throbber from becoming active, + // which in turn keeps STOP button from becoming active + rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, loadGroup, this, + nsIRequest::LOAD_BACKGROUND); if (NS_FAILED(rv)) return rv; // Set a principal for this document @@ -471,7 +505,7 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) // Prepare for loading the XML document "into oneself" nsCOMPtr listener; if (NS_FAILED(rv = StartDocumentLoad(kLoadAsData, channel, - nsnull, nsnull, + loadGroup, nsnull, getter_AddRefs(listener), PR_FALSE))) { NS_ERROR("nsXMLDocument::Load: Failed to start the document load."); diff --git a/content/xml/document/src/nsXMLDocument.h b/content/xml/document/src/nsXMLDocument.h index b159014fe1d7..72241eefc73e 100644 --- a/content/xml/document/src/nsXMLDocument.h +++ b/content/xml/document/src/nsXMLDocument.h @@ -147,6 +147,8 @@ protected: virtual PRInt32 InternalGetNumberOfStyleSheets(); nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult); + + virtual nsresult GetLoadGroup(nsILoadGroup **aLoadGroup); // For HTML elements in our content model // XXX This is not clean, but is there a better way? diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index beb7a5bdf53c..83393be9b8f3 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -1969,8 +1969,6 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) { { mParserContext->SetMimeType(contentType); } - else - NS_NOTREACHED("parser needs a content type to find a dtd"); #ifdef rickgdebug gOutFile= new fstream("c:/temp/out.file",ios::trunc); diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index beb7a5bdf53c..83393be9b8f3 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -1969,8 +1969,6 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) { { mParserContext->SetMimeType(contentType); } - else - NS_NOTREACHED("parser needs a content type to find a dtd"); #ifdef rickgdebug gOutFile= new fstream("c:/temp/out.file",ios::trunc);