diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 6989cdba4996..6ec20566248e 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -535,6 +535,9 @@ public: } virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0; + /** + * Reset this document to aURI and aLoadGroup. aURI must not be null. + */ virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup) = 0; virtual void AddReference(void *aKey, nsISupports *aReference) = 0; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 2f3a514d06d7..9a76a396d750 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -683,6 +683,7 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) void nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) { + NS_PRECONDITION(aURI, "Null URI passed to ResetToURI"); mDocumentTitle.Truncate(); mPrincipal = nsnull; @@ -707,24 +708,9 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) } mChildren.Clear(); - // The stylesheets should forget us - PRInt32 indx = mStyleSheets.Count(); - while (--indx >= 0) { - nsIStyleSheet* sheet = mStyleSheets[indx]; - sheet->SetOwningDocument(nsnull); - - PRBool applicable; - sheet->GetApplicable(applicable); - if (applicable) { - RemoveStyleSheetFromStyleSets(sheet); - } - - // XXX Tell observers? - } - - // Release all the sheets - mStyleSheets.Clear(); - + // Reset our stylesheets + ResetStylesheetsToURI(aURI); + // Release the listener manager mListenerManager = nsnull; @@ -744,10 +730,60 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) mLastModified.Truncate(); mContentType.Truncate(); mContentLanguage.Truncate(); + mBaseTarget.Truncate(); mXMLDeclarationBits = 0; } +nsresult +nsDocument::ResetStylesheetsToURI(nsIURI* aURI) +{ + NS_PRECONDITION(aURI, "Null URI passed to ResetStylesheetsToURI"); + + // The stylesheets should forget us + PRInt32 indx = mStyleSheets.Count(); + while (--indx >= 0) { + nsIStyleSheet* sheet = mStyleSheets[indx]; + sheet->SetOwningDocument(nsnull); + + PRBool applicable; + sheet->GetApplicable(applicable); + if (applicable) { + RemoveStyleSheetFromStyleSets(sheet); + } + + // XXX Tell observers? + } + + // Release all the sheets + mStyleSheets.Clear(); + + // Now reset our inline style and attribute sheets. Note that we + // already set their owning document to null in the loop above, but + // we'll reset it when we call AddStyleSheet on them. + nsresult rv; + if (mAttrStyleSheet) { + rv = mAttrStyleSheet->Reset(aURI); + } else { + rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this); + } + NS_ENSURE_SUCCESS(rv, rv); + + AddStyleSheet(mAttrStyleSheet, 0); + + if (mStyleAttrStyleSheet) { + rv = mStyleAttrStyleSheet->Reset(aURI); + } else { + rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), aURI, + this); + } + NS_ENSURE_SUCCESS(rv, rv); + + AddStyleSheet(mStyleAttrStyleSheet, 0); + + return rv; +} + nsresult nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, @@ -870,12 +906,13 @@ nsDocument::SetBaseURI(nsIURI* aURI) void nsDocument::GetBaseTarget(nsAString &aBaseTarget) const { - aBaseTarget.Truncate(); + aBaseTarget.Assign(mBaseTarget); } void nsDocument::SetBaseTarget(const nsAString &aBaseTarget) { + mBaseTarget.Assign(aBaseTarget); } void diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 3aafe324d074..1bbd71aa7d6a 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -563,6 +563,8 @@ protected: nsCompatibility aCompatMode, nsIPresShell** aInstancePtrResult); + nsresult ResetStylesheetsToURI(nsIURI* aURI); + nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult); nsDocument(); @@ -614,6 +616,8 @@ protected: nsCOMPtr mScriptEventManager; + nsString mBaseTarget; + private: nsresult IsAllowedAsChild(PRUint16 aNodeType, nsIContent* aRefContent); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 7e81e1c457d4..ea94e3b94e94 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -380,13 +380,7 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) mLoadFlags = nsIRequest::LOAD_NORMAL; nsDocument::ResetToURI(aURI, aLoadGroup); - BaseResetToURI(aURI); -} - -void -nsHTMLDocument::BaseResetToURI(nsIURI *aURI) -{ nsresult rv = NS_OK; InvalidateHashTables(); @@ -403,38 +397,11 @@ nsHTMLDocument::BaseResetToURI(nsIURI *aURI) mImageMaps.Clear(); mForms = nsnull; - if (aURI) { - if (!mAttrStyleSheet) { - rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this); - } - else { - rv = mAttrStyleSheet->Reset(aURI); - } - if (NS_SUCCEEDED(rv)) { - // tell the world about our new style sheet - AddStyleSheet(mAttrStyleSheet, 0); - - if (!mStyleAttrStyleSheet) { - rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), - aURI, this); - } - else { - rv = mStyleAttrStyleSheet->Reset(aURI); - } - if (NS_SUCCEEDED(rv)) { - // tell the world about our new style sheet - AddStyleSheet(mStyleAttrStyleSheet, 0); - } - } - } - NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::Reset() - Wyciwyg Channel still exists!"); mWyciwygChannel = nsnull; - mBaseTarget.Truncate(); - // Make the content type default to "text/html", we are a HTML // document, after all. Once we start getting data, this may be // changed. @@ -1233,18 +1200,6 @@ nsHTMLDocument::InternalGetNumberOfStyleSheets() const return count; } -void -nsHTMLDocument::GetBaseTarget(nsAString& aTarget) const -{ - aTarget.Assign(mBaseTarget); -} - -void -nsHTMLDocument::SetBaseTarget(const nsAString& aTarget) -{ - mBaseTarget = aTarget; -} - NS_IMETHODIMP nsHTMLDocument::SetReferrer(const nsAString& aReferrer) { diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index a2c720b1db81..41bfaf601701 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -113,9 +113,6 @@ public: virtual nsICSSLoader* GetCSSLoader(); - virtual void GetBaseTarget(nsAString& aTarget) const; - virtual void SetBaseTarget(const nsAString& aTarget); - NS_IMETHOD SetReferrer(const nsAString& aReferrer); NS_IMETHOD GetCompatibilityMode(nsCompatibility& aMode); @@ -259,11 +256,8 @@ protected: nsresult CreateAndAddWyciwygChannel(void); nsresult RemoveWyciwygChannel(void); - void BaseResetToURI(nsIURI* aURI); - virtual void RetrieveRelevantHeaders(nsIChannel *aChannel); - nsString mBaseTarget; nsString mReferrer; nsCOMPtr mChannel; diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index cae09f74f5fc..adb854536876 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -226,16 +226,6 @@ void nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) { nsDocument::Reset(aChannel, aLoadGroup); - nsCOMPtr url; - if (aChannel) { - nsresult result = aChannel->GetURI(getter_AddRefs(url)); - if (NS_FAILED(result)) - return; - } - - SetDefaultStylesheets(url); - - mBaseTarget.Truncate(); mScriptContext = nsnull; } @@ -1027,48 +1017,6 @@ nsXMLDocument::GetElementById(const nsAString& aElementId, return CallQueryInterface(content, aReturn); } -nsresult -nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl) -{ - if (!aUrl) { - return NS_OK; - } - - // XXXbz this code is very similar to the HTMLDocument code; should merge! - if (mAttrStyleSheet) { - mAttrStyleSheet->SetOwningDocument(nsnull); - } - if (mStyleAttrStyleSheet) { - mStyleAttrStyleSheet->SetOwningDocument(nsnull); - } - - nsresult rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aUrl, - this); - NS_ENSURE_SUCCESS(rv, rv); - - rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), aUrl, - this); - NS_ENSURE_SUCCESS(rv, rv); - - // tell the world about our new style sheets - AddStyleSheet(mAttrStyleSheet, 0); - AddStyleSheet(mStyleAttrStyleSheet, 0); - - return rv; -} - -void -nsXMLDocument::SetBaseTarget(const nsAString &aBaseTarget) -{ - mBaseTarget.Assign(aBaseTarget); -} - -void -nsXMLDocument::GetBaseTarget(nsAString &aBaseTarget) const -{ - aBaseTarget.Assign(mBaseTarget); -} - nsICSSLoader* nsXMLDocument::GetCSSLoader() { diff --git a/content/xml/document/src/nsXMLDocument.h b/content/xml/document/src/nsXMLDocument.h index a2d598d112db..614783a86b89 100644 --- a/content/xml/document/src/nsXMLDocument.h +++ b/content/xml/document/src/nsXMLDocument.h @@ -78,9 +78,6 @@ public: virtual void EndLoad(); - virtual void GetBaseTarget(nsAString &aBaseTarget) const; - virtual void SetBaseTarget(const nsAString &aBaseTarget); - // nsIDOMNode interface NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); @@ -127,13 +124,10 @@ protected: virtual nsresult GetLoadGroup(nsILoadGroup **aLoadGroup); - nsresult SetDefaultStylesheets(nsIURI* aUrl); - // For additional catalog sheets (if any) needed to layout the XML vocabulary // of the document. Catalog sheets are kept at the beginning of our array of // style sheets and this counter is used as an offset to distinguish them PRInt32 mCatalogSheetCount; - nsString mBaseTarget; nsCOMPtr mEventQService; diff --git a/content/xul/document/public/nsIXULDocument.h b/content/xul/document/public/nsIXULDocument.h index 05a8233e39eb..6a3c3b959c45 100644 --- a/content/xul/document/public/nsIXULDocument.h +++ b/content/xul/document/public/nsIXULDocument.h @@ -123,11 +123,6 @@ public: */ NS_IMETHOD SetCurrentPrototype(nsIXULPrototypeDocument* aDocument) = 0; - /** - * Load inline and attribute style sheets - */ - NS_IMETHOD PrepareStyleSheets(nsIURI* aURI) = 0; - /** * Notify the XUL document that a subtree has been added */ diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index e84b78908989..b4b9a4853589 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -525,42 +525,6 @@ nsXULDocument::SetContentType(const nsAString& aContentType) // application/vnd.mozilla.xul+xml } -NS_IMETHODIMP -nsXULDocument::PrepareStyleSheets(nsIURI* anURL) -{ - nsresult rv; - - // XXXbz this is similar to code in nsHTMLDocument and - // nsXMLDocument; move up to nsDocument? - // Delete references to style sheets - this should be done in superclass... - PRInt32 i = mStyleSheets.Count(); - while (--i >= 0) { - mStyleSheets.ObjectAt(i)->SetOwningDocument(nsnull); - } - mStyleSheets.Clear(); - - // Create an HTML style sheet for the HTML content. - rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), anURL, this); - if (NS_FAILED(rv)) { - NS_ERROR("unable to add HTML style sheet"); - return rv; - } - - AddStyleSheet(mAttrStyleSheet, 0); - - // Create an inline style sheet for inline content that contains a style - // attribute. - rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet), anURL, this); - if (NS_FAILED(rv)) { - NS_ERROR("unable to add inline style sheet"); - return rv; - } - - AddStyleSheet(mStyleAttrStyleSheet, 0); - - return NS_OK; -} - nsresult nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, @@ -575,7 +539,7 @@ nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsresult rv = aChannel->GetOriginalURI(getter_AddRefs(mDocumentURI)); if (NS_FAILED(rv)) return rv; - rv = PrepareStyleSheets(mDocumentURI); + rv = ResetStylesheetsToURI(mDocumentURI); if (NS_FAILED(rv)) return rv; RetrieveRelevantHeaders(aChannel); diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 165820770291..458df62a4ae6 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -146,7 +146,6 @@ public: NS_IMETHOD SetMasterPrototype(nsIXULPrototypeDocument* aDocument); NS_IMETHOD GetMasterPrototype(nsIXULPrototypeDocument** aDocument); NS_IMETHOD SetCurrentPrototype(nsIXULPrototypeDocument* aDocument); - NS_IMETHOD PrepareStyleSheets(nsIURI* anURL); NS_IMETHOD AddSubtreeToDocument(nsIContent* aElement); NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aElement); NS_IMETHOD SetTemplateBuilderFor(nsIContent* aContent,