diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 045e797b9333..7ed30e4aa40f 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -90,8 +90,8 @@ class nsILayoutHistoryState; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ -{ 0x660e9925, 0x30e0, 0x4016, \ - { 0x8b, 0x7f, 0x0d, 0x70, 0x6e, 0xba, 0xc9, 0x8e } } +{ 0x97e4f20e, 0x73de, 0x41fd, \ + { 0x85, 0x20, 0x41, 0x45, 0xc8, 0x74, 0xf5, 0x85 } } // The base value for the content ID counter. // This counter is used by the document to @@ -441,6 +441,13 @@ public: return mCSSLoader; } + /** + * Get the channel that was passed to StartDocumentLoad for this + * document. Note that this may be null in some cases (eg if + * StartDocumentLoad was never called) + */ + virtual nsIChannel* GetChannel() const = 0; + /** * Get this document's attribute stylesheet. May return null if * there isn't one. diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index c6b802ffbf50..464805922cd3 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -1030,6 +1030,8 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, RetrieveRelevantHeaders(aChannel); + mChannel = aChannel; + return NS_OK; } diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index a1f7bdc104ef..80f927cad432 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -343,12 +343,15 @@ public: virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet); virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI); + virtual nsIChannel* GetChannel() const { + return mChannel; + } /** * Get this document's attribute stylesheet. May return null if * there isn't one. */ - nsHTMLStyleSheet* GetAttributeStyleSheet() const { + virtual nsHTMLStyleSheet* GetAttributeStyleSheet() const { return mAttrStyleSheet; } @@ -356,7 +359,7 @@ public: * Get this document's inline style sheet. May return null if there * isn't one */ - nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const { + virtual nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const { return mStyleAttrStyleSheet; } @@ -631,6 +634,8 @@ protected: nsSupportsHashtable* mBoxObjectTable; + // The channel that got passed to StartDocumentLoad(), if any + nsCOMPtr mChannel; nsRefPtr mAttrStyleSheet; nsCOMPtr mStyleAttrStyleSheet; nsRefPtr mXMLEventsManager; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index c7e21201d27f..a28af48e2d7c 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -708,9 +708,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, // Store the security info for future use with wyciwyg channels. aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); - // Stash away a pointer to our channel (we need this for cookies) - mChannel = aChannel; - nsCOMPtr uri; rv = aChannel->GetURI(getter_AddRefs(uri)); if (NS_FAILED(rv)) { diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 46530ef1ae6e..fc8574832a83 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -251,8 +251,6 @@ protected: return mDefaultNamespaceID; }; - nsCOMPtr mChannel; - nsCompatibility mCompatMode; nsCOMArray mImageMaps; diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 5d0818f52da8..a1e55d3ba8b4 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -225,10 +225,10 @@ nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) void nsXMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) { - if (mPendingChannel) { + if (mChannelIsPending) { StopDocumentLoad(); - mPendingChannel->Cancel(NS_BINDING_ABORTED); - mPendingChannel = nsnull; + mChannel->Cancel(NS_BINDING_ABORTED); + mChannelIsPending = nsnull; } nsDocument::ResetToURI(aURI, aLoadGroup); @@ -506,12 +506,12 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) } // After this point, if we error out of this method we should clear - // mPendingChannel. + // mChannelIsPending. // Start an asynchronous read of the XML document rv = channel->AsyncOpen(listener, nsnull); if (NS_FAILED(rv)) { - mPendingChannel = nsnull; + mChannelIsPending = PR_FALSE; if (modalEventQueue) { mEventQService->PopThreadEventQueue(modalEventQueue); } @@ -614,8 +614,9 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, rv = CallQueryInterface(mParser, aDocListener); NS_ENSURE_SUCCESS(rv, rv); - mPendingChannel = aChannel; - + NS_ASSERTION(mChannel, "How can we not have a channel here?"); + mChannelIsPending = PR_TRUE; + SetDocumentCharacterSet(charset); mParser->SetDocumentCharset(charset, charsetSource); mParser->SetCommand(aCommand); @@ -628,7 +629,7 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, void nsXMLDocument::EndLoad() { - mPendingChannel = nsnull; + mChannelIsPending = PR_FALSE; mLoopingForSyncLoad = PR_FALSE; if (mLoadedAsData || mLoadedAsInteractiveData) { diff --git a/content/xml/document/src/nsXMLDocument.h b/content/xml/document/src/nsXMLDocument.h index 4ecc3b43848d..1bbdb80f19ed 100644 --- a/content/xml/document/src/nsXMLDocument.h +++ b/content/xml/document/src/nsXMLDocument.h @@ -102,12 +102,13 @@ protected: nsCOMPtr mScriptContext; - // mPendingChannel is the channel that we're currently asynchronously loading - // (via document.load() or normal load). It's set when we first find out - // about the channel (at the end of StartDocumentLoad) and cleared in EndLoad - // or if ResetToURI() is called. In the latter case it's also cancelled. - nsCOMPtr mPendingChannel; - + // mChannelIsPending indicates whether we're currently asynchronously loading + // data from mChannel (via document.load() or normal load). It's set to true + // when we first find out about the channel (StartDocumentLoad) and set to + // false in EndLoad or if ResetToURI() is called. In the latter case our + // mChannel is also cancelled. Note that if this member is true, mChannel + // cannot be null. + PRPackedBool mChannelIsPending; PRPackedBool mCrossSiteAccessEnabled; PRPackedBool mLoadedAsData; PRPackedBool mLoadedAsInteractiveData; diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 597a90d003bf..1b8a8103e5f7 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -532,6 +532,8 @@ nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, mDocumentTitle.SetIsVoid(PR_TRUE); + mChannel = aChannel; + nsresult rv = aChannel->GetOriginalURI(getter_AddRefs(mDocumentURI)); NS_ENSURE_SUCCESS(rv, rv);