From 958490b3c11c19207558d2e14d9f95eaea4d83af Mon Sep 17 00:00:00 2001 From: Razvan Maries Date: Wed, 20 May 2020 19:36:00 +0300 Subject: [PATCH] Backed out 4 changesets (bug 1639392) for build bustages on nsCOMPtr.h. CLOSED TREE Backed out changeset 379e2c6c0491 (bug 1639392) Backed out changeset ce2500faad38 (bug 1639392) Backed out changeset cee5116fbef3 (bug 1639392) Backed out changeset 7c5823c53db8 (bug 1639392) --- dom/base/nsIStyleSheetLinkingElement.h | 24 +++++++++++++++++++ dom/base/nsStyleLinkElement.cpp | 18 ++++++++++++-- dom/base/nsStyleLinkElement.h | 24 ++++++++++--------- .../PrototypeDocumentContentSink.cpp | 22 ++++++++--------- dom/prototype/PrototypeDocumentContentSink.h | 3 +-- .../XMLStylesheetProcessingInstruction.cpp | 1 + dom/xml/XMLStylesheetProcessingInstruction.h | 10 ++------ dom/xml/nsXMLContentSink.cpp | 2 ++ dom/xslt/xslt/txMozillaXMLOutput.cpp | 2 ++ parser/html/nsHtml5TreeOperation.cpp | 3 +++ 10 files changed, 75 insertions(+), 34 deletions(-) diff --git a/dom/base/nsIStyleSheetLinkingElement.h b/dom/base/nsIStyleSheetLinkingElement.h index 2c2e620b1f36..a65d9750bb7a 100644 --- a/dom/base/nsIStyleSheetLinkingElement.h +++ b/dom/base/nsIStyleSheetLinkingElement.h @@ -127,6 +127,21 @@ class nsIStyleSheetLinkingElement : public nsISupports { */ virtual void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) = 0; + /** + * Used to obtain the style sheet linked in by this element. + * + * @return the style sheet associated with this element. + */ + virtual mozilla::StyleSheet* GetStyleSheet() = 0; + + /** + * Initialize the stylesheet linking element. If aDontLoadStyle is + * true the element will ignore the first modification to the + * element that would cause a stylesheet to be loaded. Subsequent + * modifications to the element will not be ignored. + */ + virtual void InitStyleLinkElement(bool aDontLoadStyle) = 0; + /** * Tells this element to update the stylesheet. * @@ -153,6 +168,15 @@ class nsIStyleSheetLinkingElement : public nsISupports { */ virtual void GetCharset(nsAString& aCharset) = 0; + /** + * Tells this element to use a different base URI. This is used for + * proper loading of xml-stylesheet processing instructions in XUL overlays + * and is only currently used by nsXMLStylesheetPI. + * + * @param aNewBaseURI the new base URI, nullptr to use the default base URI. + */ + virtual void OverrideBaseURI(nsIURI* aNewBaseURI) = 0; + // This doesn't entirely belong here since they only make sense for // some types of linking elements, but it's a better place than // anywhere else. diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index 815d2510b587..1b5062fa6cf3 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -65,7 +65,8 @@ nsStyleLinkElement::SheetInfo::SheetInfo( nsStyleLinkElement::SheetInfo::~SheetInfo() = default; nsStyleLinkElement::nsStyleLinkElement() - : mUpdatesEnabled(true), + : mDontLoadStyle(false), + mUpdatesEnabled(true), mLineNumber(1), mColumnNumber(1) {} @@ -130,6 +131,12 @@ void nsStyleLinkElement::SetStyleSheet(StyleSheet* aStyleSheet) { } } +StyleSheet* nsStyleLinkElement::GetStyleSheet() { return mStyleSheet; } + +void nsStyleLinkElement::InitStyleLinkElement(bool aDontLoadStyle) { + mDontLoadStyle = aDontLoadStyle; +} + void nsStyleLinkElement::SetEnableUpdates(bool aEnableUpdates) { mUpdatesEnabled = aEnableUpdates; } @@ -138,6 +145,13 @@ void nsStyleLinkElement::GetCharset(nsAString& aCharset) { aCharset.Truncate(); } +/* virtual */ +void nsStyleLinkElement::OverrideBaseURI(nsIURI* aNewBaseURI) { + MOZ_ASSERT_UNREACHABLE( + "Base URI can't be overriden in this implementation " + "of nsIStyleSheetLinkingElement."); +} + /* virtual */ void nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber) { mLineNumber = aLineNumber; @@ -262,7 +276,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument, } // When static documents are created, stylesheets are cloned manually. - if (!mUpdatesEnabled || doc->IsStaticDocument()) { + if (mDontLoadStyle || !mUpdatesEnabled || doc->IsStaticDocument()) { return Update{}; } diff --git a/dom/base/nsStyleLinkElement.h b/dom/base/nsStyleLinkElement.h index 470924910738..233f026c7a2d 100644 --- a/dom/base/nsStyleLinkElement.h +++ b/dom/base/nsStyleLinkElement.h @@ -32,9 +32,6 @@ class ShadowRoot; } // namespace mozilla class nsStyleLinkElement : public nsIStyleSheetLinkingElement { - template - using Result = mozilla::Result; - public: nsStyleLinkElement(); virtual ~nsStyleLinkElement(); @@ -44,17 +41,21 @@ class nsStyleLinkElement : public nsIStyleSheetLinkingElement { mozilla::StyleSheet* GetSheet() const { return mStyleSheet; } // nsIStyleSheetLinkingElement - void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) final; + void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override; + mozilla::StyleSheet* GetStyleSheet() override; + void InitStyleLinkElement(bool aDontLoadStyle) override; - Result UpdateStyleSheet(nsICSSLoaderObserver*) final; + mozilla::Result UpdateStyleSheet( + nsICSSLoaderObserver*) override; - void SetEnableUpdates(bool aEnableUpdates) final; + void SetEnableUpdates(bool aEnableUpdates) override; void GetCharset(nsAString& aCharset) override; - void SetLineNumber(uint32_t aLineNumber) final; - uint32_t GetLineNumber() final; - void SetColumnNumber(uint32_t aColumnNumber) final; - uint32_t GetColumnNumber() final; + void OverrideBaseURI(nsIURI* aNewBaseURI) override; + void SetLineNumber(uint32_t aLineNumber) override; + uint32_t GetLineNumber() override; + void SetColumnNumber(uint32_t aColumnNumber) override; + uint32_t GetColumnNumber() override; enum RelValue { ePREFETCH = 0x00000001, @@ -87,7 +88,7 @@ class nsStyleLinkElement : public nsIStyleSheetLinkingElement { * * TODO(emilio): Should probably pass a single DocumentOrShadowRoot. */ - Result UpdateStyleSheetInternal( + mozilla::Result UpdateStyleSheetInternal( mozilla::dom::Document* aOldDocument, mozilla::dom::ShadowRoot* aOldShadowRoot, ForceUpdate = ForceUpdate::No); @@ -132,6 +133,7 @@ class nsStyleLinkElement : public nsIStyleSheetLinkingElement { protected: nsCOMPtr mTriggeringPrincipal; + bool mDontLoadStyle; bool mUpdatesEnabled; uint32_t mLineNumber; uint32_t mColumnNumber; diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index c346d9ef7882..e5ee83b3f673 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -46,7 +46,6 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLTemplateElement.h" #include "mozilla/dom/ProcessingInstruction.h" -#include "mozilla/dom/XMLStylesheetProcessingInstruction.h" #include "mozilla/dom/ScriptLoader.h" #include "mozilla/LoadInfo.h" #include "mozilla/PresShell.h" @@ -344,11 +343,7 @@ nsresult PrototypeDocumentContentSink::CreateAndInsertPI( nsresult rv; if (aProtoPI->mTarget.EqualsLiteral("xml-stylesheet")) { - MOZ_ASSERT( - nsCOMPtr(do_QueryInterface(node)), - "XML Stylesheet node does not implement nsIStyleSheetLinkingElement!"); - auto* pi = static_cast(node.get()); - rv = InsertXMLStylesheetPI(aProtoPI, aParent, aBeforeThis, pi); + rv = InsertXMLStylesheetPI(aProtoPI, aParent, aBeforeThis, node); } else { // No special processing, just add the PI to the document. rv = aParent->InsertChildBefore( @@ -361,25 +356,30 @@ nsresult PrototypeDocumentContentSink::CreateAndInsertPI( nsresult PrototypeDocumentContentSink::InsertXMLStylesheetPI( const nsXULPrototypePI* aProtoPI, nsINode* aParent, nsINode* aBeforeThis, - XMLStylesheetProcessingInstruction* aPINode) { + nsIContent* aPINode) { + nsCOMPtr ssle(do_QueryInterface(aPINode)); + NS_ASSERTION(ssle, + "passed XML Stylesheet node does not " + "implement nsIStyleSheetLinkingElement!"); nsresult rv; + ssle->InitStyleLinkElement(false); // We want to be notified when the style sheet finishes loading, so // disable style sheet loading for now. - aPINode->SetEnableUpdates(false); - aPINode->OverrideBaseURI(mCurrentPrototype->GetURI()); + ssle->SetEnableUpdates(false); + ssle->OverrideBaseURI(mCurrentPrototype->GetURI()); rv = aParent->InsertChildBefore( aPINode->AsContent(), aBeforeThis ? aBeforeThis->AsContent() : nullptr, false); if (NS_FAILED(rv)) return rv; - aPINode->SetEnableUpdates(true); + ssle->SetEnableUpdates(true); // load the stylesheet if necessary, passing ourselves as // nsICSSObserver - auto result = aPINode->UpdateStyleSheet(this); + auto result = ssle->UpdateStyleSheet(this); if (result.isErr()) { // Ignore errors from UpdateStyleSheet; we don't want failure to // do that to break the XUL document load. But do propagate out diff --git a/dom/prototype/PrototypeDocumentContentSink.h b/dom/prototype/PrototypeDocumentContentSink.h index 221605735ba6..ff789f75e566 100644 --- a/dom/prototype/PrototypeDocumentContentSink.h +++ b/dom/prototype/PrototypeDocumentContentSink.h @@ -36,7 +36,6 @@ namespace dom { class Element; class ScriptLoader; class Document; -class XMLStylesheetProcessingInstruction; } // namespace dom } // namespace mozilla @@ -238,7 +237,7 @@ class PrototypeDocumentContentSink final : public nsIStreamLoaderObserver, */ nsresult InsertXMLStylesheetPI(const nsXULPrototypePI* aProtoPI, nsINode* aParent, nsINode* aBeforeThis, - XMLStylesheetProcessingInstruction* aPINode); + nsIContent* aPINode); void CloseElement(Element* aElement); }; diff --git a/dom/xml/XMLStylesheetProcessingInstruction.cpp b/dom/xml/XMLStylesheetProcessingInstruction.cpp index 2f213f8be254..b4242bc2f0a4 100644 --- a/dom/xml/XMLStylesheetProcessingInstruction.cpp +++ b/dom/xml/XMLStylesheetProcessingInstruction.cpp @@ -72,6 +72,7 @@ void XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset) { } } +/* virtual */ void XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI) { mOverriddenBaseURI = aNewBaseURI; } diff --git a/dom/xml/XMLStylesheetProcessingInstruction.h b/dom/xml/XMLStylesheetProcessingInstruction.h index 79fefb274712..c9985ffcd7a4 100644 --- a/dom/xml/XMLStylesheetProcessingInstruction.h +++ b/dom/xml/XMLStylesheetProcessingInstruction.h @@ -47,14 +47,8 @@ class XMLStylesheetProcessingInstruction final : public ProcessingInstruction { virtual nsresult BindToTree(BindContext&, nsINode& aParent) override; virtual void UnbindFromTree(bool aNullParent = true) override; - /** - * Tells this processing instruction to use a different base URI. This is used - * for proper loading of xml-stylesheet processing instructions in XUL - * overlays and is only currently used by nsXMLStylesheetPI. - * - * @param aNewBaseURI the new base URI, nullptr to use the default base URI. - */ - void OverrideBaseURI(nsIURI* aNewBaseURI); + // nsIStyleSheetLinkingElement + virtual void OverrideBaseURI(nsIURI* aNewBaseURI) override; // nsStyleLinkElement void GetCharset(nsAString& aCharset) override; diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index 398f2c4fe37d..a65c9ad418b0 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -501,6 +501,7 @@ nsresult nsXMLContentSink::CreateElement( aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) { nsCOMPtr ssle(do_QueryInterface(content)); if (ssle) { + ssle->InitStyleLinkElement(false); if (aFromParser) { ssle->SetEnableUpdates(false); } @@ -1167,6 +1168,7 @@ nsXMLContentSink::HandleProcessingInstruction(const char16_t* aTarget, nsCOMPtr ssle = do_QueryInterface(ToSupports(node)); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); mPrettyPrintXML = false; } diff --git a/dom/xslt/xslt/txMozillaXMLOutput.cpp b/dom/xslt/xslt/txMozillaXMLOutput.cpp index 7d26429d5409..b1f7e2620874 100644 --- a/dom/xslt/xslt/txMozillaXMLOutput.cpp +++ b/dom/xslt/xslt/txMozillaXMLOutput.cpp @@ -356,6 +356,7 @@ nsresult txMozillaXMLOutput::processingInstruction(const nsString& aTarget, if (mCreatingNewDocument) { ssle = do_QueryInterface(pi); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); } } @@ -500,6 +501,7 @@ nsresult txMozillaXMLOutput::startElementInternal(nsAtom* aPrefix, nsCOMPtr ssle = do_QueryInterface(mOpenedElement); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); } } diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index 224e8b6beace..5d5147ba2435 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -458,6 +458,7 @@ nsIContent* nsHtml5TreeOperation::CreateHTMLElement( if (MOZ_UNLIKELY(aName == nsGkAtoms::style || aName == nsGkAtoms::link)) { nsCOMPtr ssle(do_QueryInterface(newContent)); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); } } @@ -485,6 +486,7 @@ nsIContent* nsHtml5TreeOperation::CreateHTMLElement( if (MOZ_UNLIKELY(aName == nsGkAtoms::style || aName == nsGkAtoms::link)) { nsCOMPtr ssle(do_QueryInterface(newContent)); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); } } @@ -533,6 +535,7 @@ nsIContent* nsHtml5TreeOperation::CreateSVGElement( if (MOZ_UNLIKELY(aName == nsGkAtoms::style)) { nsCOMPtr ssle(do_QueryInterface(newContent)); if (ssle) { + ssle->InitStyleLinkElement(false); ssle->SetEnableUpdates(false); } }