Bug 1639392 - Move nsIStyleSheetLinkingElement::OverrideBaseURI to its only implementation. r=jwatt
☠☠ backed out by a0d10a7e5c3f ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 20 May 2020 10:32:14 +0000
changeset 531268 379e2c6c049115d64977587961d08b42a09ad3c9
parent 531267 ce2500faad3817560e106e9ff0588cca6fcfee27
child 531269 250ab0b9289e05387740e2ee517f8ad4eec92e03
push id37436
push userncsoregi@mozilla.com
push dateWed, 20 May 2020 21:30:50 +0000
treeherdermozilla-central@6c10970490f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1639392
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639392 - Move nsIStyleSheetLinkingElement::OverrideBaseURI to its only implementation. r=jwatt It's a PI thing, so keep it there. Depends on D76069 Differential Revision: https://phabricator.services.mozilla.com/D76070
dom/base/nsIStyleSheetLinkingElement.h
dom/base/nsStyleLinkElement.cpp
dom/base/nsStyleLinkElement.h
dom/prototype/PrototypeDocumentContentSink.cpp
dom/prototype/PrototypeDocumentContentSink.h
dom/xml/XMLStylesheetProcessingInstruction.cpp
dom/xml/XMLStylesheetProcessingInstruction.h
--- a/dom/base/nsIStyleSheetLinkingElement.h
+++ b/dom/base/nsIStyleSheetLinkingElement.h
@@ -148,25 +148,16 @@ class nsIStyleSheetLinkingElement : publ
    * Gets the charset that the element claims the style sheet is in.
    * Can return empty string to indicate that we have no charset
    * information.
    *
    * @param aCharset the charset
    */
   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.
   virtual void SetLineNumber(uint32_t aLineNumber) = 0;
 
   /**
    * Get the line number, as previously set by SetLineNumber.
    *
--- a/dom/base/nsStyleLinkElement.cpp
+++ b/dom/base/nsStyleLinkElement.cpp
@@ -134,23 +134,16 @@ void nsStyleLinkElement::SetEnableUpdate
   mUpdatesEnabled = aEnableUpdates;
 }
 
 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;
 }
 
 /* virtual */
 uint32_t nsStyleLinkElement::GetLineNumber() { return mLineNumber; }
 
 /* virtual */
--- a/dom/base/nsStyleLinkElement.h
+++ b/dom/base/nsStyleLinkElement.h
@@ -46,17 +46,16 @@ class nsStyleLinkElement : public nsISty
   // nsIStyleSheetLinkingElement
   void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) final;
 
   Result<Update, nsresult> UpdateStyleSheet(nsICSSLoaderObserver*) final;
 
   void SetEnableUpdates(bool aEnableUpdates) final;
   void GetCharset(nsAString& aCharset) override;
 
-  void OverrideBaseURI(nsIURI* aNewBaseURI) override;
   void SetLineNumber(uint32_t aLineNumber) final;
   uint32_t GetLineNumber() final;
   void SetColumnNumber(uint32_t aColumnNumber) final;
   uint32_t GetColumnNumber() final;
 
   enum RelValue {
     ePREFETCH = 0x00000001,
     eDNS_PREFETCH = 0x00000002,
--- a/dom/prototype/PrototypeDocumentContentSink.cpp
+++ b/dom/prototype/PrototypeDocumentContentSink.cpp
@@ -41,16 +41,17 @@
 #include "nsHtml5SVGLoadDispatcher.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/CDATASection.h"
 #include "mozilla/dom/Comment.h"
 #include "mozilla/dom/DocumentType.h"
 #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"
 
 #include "nsXULPrototypeCache.h"
 #include "nsXULElement.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "js/CompilationAndEvaluation.h"
@@ -338,52 +339,52 @@ nsresult PrototypeDocumentContentSink::C
   MOZ_ASSERT(aParent, "null ptr");
 
   RefPtr<ProcessingInstruction> node =
       NS_NewXMLProcessingInstruction(aParent->OwnerDoc()->NodeInfoManager(),
                                      aProtoPI->mTarget, aProtoPI->mData);
 
   nsresult rv;
   if (aProtoPI->mTarget.EqualsLiteral("xml-stylesheet")) {
-    rv = InsertXMLStylesheetPI(aProtoPI, aParent, aBeforeThis, node);
+    MOZ_ASSERT(
+        nsCOMPtr<nsIStyleSheetLinkingElement>(do_QueryInterface(node)),
+        "XML Stylesheet node does not implement nsIStyleSheetLinkingElement!");
+    auto* pi = static_cast<XMLStylesheetProcessingInstruction*>(node.get());
+    rv = InsertXMLStylesheetPI(aProtoPI, aParent, aBeforeThis, pi);
   } else {
     // No special processing, just add the PI to the document.
     rv = aParent->InsertChildBefore(
         node->AsContent(), aBeforeThis ? aBeforeThis->AsContent() : nullptr,
         false);
   }
 
   return rv;
 }
 
 nsresult PrototypeDocumentContentSink::InsertXMLStylesheetPI(
     const nsXULPrototypePI* aProtoPI, nsINode* aParent, nsINode* aBeforeThis,
-    nsIContent* aPINode) {
-  nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aPINode));
-  NS_ASSERTION(ssle,
-               "passed XML Stylesheet node does not "
-               "implement nsIStyleSheetLinkingElement!");
+    XMLStylesheetProcessingInstruction* aPINode) {
 
   nsresult rv;
 
   // We want to be notified when the style sheet finishes loading, so
   // disable style sheet loading for now.
-  ssle->SetEnableUpdates(false);
-  ssle->OverrideBaseURI(mCurrentPrototype->GetURI());
+  aPINode->SetEnableUpdates(false);
+  aPINode->OverrideBaseURI(mCurrentPrototype->GetURI());
 
   rv = aParent->InsertChildBefore(
       aPINode->AsContent(), aBeforeThis ? aBeforeThis->AsContent() : nullptr,
       false);
   if (NS_FAILED(rv)) return rv;
 
-  ssle->SetEnableUpdates(true);
+  aPINode->SetEnableUpdates(true);
 
   // load the stylesheet if necessary, passing ourselves as
   // nsICSSObserver
-  auto result = ssle->UpdateStyleSheet(this);
+  auto result = aPINode->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
     // NS_ERROR_OUT_OF_MEMORY.
     if (result.unwrapErr() == NS_ERROR_OUT_OF_MEMORY) {
       return result.unwrapErr();
     }
     return NS_OK;
--- a/dom/prototype/PrototypeDocumentContentSink.h
+++ b/dom/prototype/PrototypeDocumentContentSink.h
@@ -31,16 +31,17 @@ class nsXULPrototypeElement;
 class nsXULPrototypePI;
 class nsXULPrototypeScript;
 
 namespace mozilla {
 namespace dom {
 class Element;
 class ScriptLoader;
 class Document;
+class XMLStylesheetProcessingInstruction;
 }  // namespace dom
 }  // namespace mozilla
 
 nsresult NS_NewPrototypeDocumentContentSink(nsIContentSink** aResult,
                                             mozilla::dom::Document* aDoc,
                                             nsIURI* aURI,
                                             nsISupports* aContainer,
                                             nsIChannel* aChannel);
@@ -232,16 +233,16 @@ class PrototypeDocumentContentSink final
    * asynchronously.
    * The prototype document walk can happen before the stylesheets
    * are loaded, but the final steps in the load process (see
    * DoneWalking()) are not run before all the stylesheets are done
    * loading.
    */
   nsresult InsertXMLStylesheetPI(const nsXULPrototypePI* aProtoPI,
                                  nsINode* aParent, nsINode* aBeforeThis,
-                                 nsIContent* aPINode);
+                                 XMLStylesheetProcessingInstruction* aPINode);
   void CloseElement(Element* aElement);
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_PrototypeDocumentContentSink_h__
--- a/dom/xml/XMLStylesheetProcessingInstruction.cpp
+++ b/dom/xml/XMLStylesheetProcessingInstruction.cpp
@@ -67,17 +67,16 @@ void XMLStylesheetProcessingInstruction:
 // nsStyleLinkElement
 
 void XMLStylesheetProcessingInstruction::GetCharset(nsAString& aCharset) {
   if (!GetAttrValue(nsGkAtoms::charset, aCharset)) {
     aCharset.Truncate();
   }
 }
 
-/* virtual */
 void XMLStylesheetProcessingInstruction::OverrideBaseURI(nsIURI* aNewBaseURI) {
   mOverriddenBaseURI = aNewBaseURI;
 }
 
 Maybe<nsStyleLinkElement::SheetInfo>
 XMLStylesheetProcessingInstruction::GetStyleSheetInfo() {
   // xml-stylesheet PI is special only in prolog
   if (!nsContentUtils::InProlog(this)) {
--- a/dom/xml/XMLStylesheetProcessingInstruction.h
+++ b/dom/xml/XMLStylesheetProcessingInstruction.h
@@ -42,18 +42,24 @@ class XMLStylesheetProcessingInstruction
   // nsINode
   virtual void SetNodeValueInternal(const nsAString& aNodeValue,
                                     mozilla::ErrorResult& aError) override;
 
   // nsIContent
   virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
   virtual void UnbindFromTree(bool aNullParent = true) override;
 
-  // nsIStyleSheetLinkingElement
-  virtual void OverrideBaseURI(nsIURI* aNewBaseURI) 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);
 
   // nsStyleLinkElement
   void GetCharset(nsAString& aCharset) override;
 
   virtual void SetData(const nsAString& aData,
                        mozilla::ErrorResult& rv) override {
     CharacterData::SetData(aData, rv);
     if (rv.Failed()) {