Bug 484200. src attribute on <style> makes styles not apply. r=bzbarsky
authorDavid Zbarsky <dzbarsky@gmail.com>
Tue, 28 Jul 2009 12:07:31 -0400
changeset 30794 a8d700960e41dfae8b34e513316bef50b2c0166b
parent 30793 5e7bdee4ca0ed5df91ed43ab790564946f821b4d
child 30795 dcda49ff1a2640d376a54a8aed9b5e66f9f9178c
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs484200
milestone1.9.2a1pre
Bug 484200. src attribute on <style> makes styles not apply. r=bzbarsky
content/base/src/nsStyleLinkElement.cpp
content/base/src/nsStyleLinkElement.h
content/html/content/reftests/484200-1-ref.html
content/html/content/reftests/484200-1.html
content/html/content/reftests/reftest.list
content/html/content/src/nsHTMLLinkElement.cpp
content/html/content/src/nsHTMLStyleElement.cpp
content/svg/content/src/nsSVGStyleElement.cpp
content/xml/content/src/nsXMLStylesheetPI.cpp
--- a/content/base/src/nsStyleLinkElement.cpp
+++ b/content/base/src/nsStyleLinkElement.cpp
@@ -245,19 +245,19 @@ nsStyleLinkElement::DoUpdateStyleSheet(n
   }
 
   PRBool enabled = PR_FALSE;
   doc->CSSLoader()->GetEnabled(&enabled);
   if (!enabled) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIURI> uri;
   PRBool isInline;
-  GetStyleSheetURL(&isInline, getter_AddRefs(uri));
+  
+  nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
 
   if (!aForceUpdate && mStyleSheet && !isInline && uri) {
     nsCOMPtr<nsIURI> oldURI;
 
     mStyleSheet->GetSheetURI(getter_AddRefs(oldURI));
     if (oldURI) {
       PRBool equal;
       nsresult rv = oldURI->Equals(uri, &equal);
--- a/content/base/src/nsStyleLinkElement.h
+++ b/content/base/src/nsStyleLinkElement.h
@@ -90,18 +90,17 @@ protected:
    * @param aForceUpdate PR_TRUE will force the update even if the URI has not
    *                     changed.  This should be used in cases when something
    *                     about the content that affects the resulting sheet
    *                     changed but the URI may not have changed.
    */
   nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
                                     PRBool aForceUpdate = PR_FALSE);
 
-  virtual void GetStyleSheetURL(PRBool* aIsInline,
-                                nsIURI** aURI) = 0;
+  virtual already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline) = 0;
   virtual void GetStyleSheetInfo(nsAString& aTitle,
                                  nsAString& aType,
                                  nsAString& aMedia,
                                  PRBool* aIsAlternate) = 0;
 
   nsIStyleSheet* GetStyleSheet() { return mStyleSheet; }
 
 private:
new file mode 100644
--- /dev/null
+++ b/content/html/content/reftests/484200-1-ref.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<title>Test for Bug 484200</title>
+<style>
+p { background:lime }
+</style>
+</head>
+<body>
+<p>xxxxx</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/html/content/reftests/484200-1.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<title>Test for Bug 484200</title>
+<style src=style>
+p { background:lime }
+</style>
+</head>
+<body>
+<p>xxxxx</p>
+</body>
+</html>
--- a/content/html/content/reftests/reftest.list
+++ b/content/html/content/reftests/reftest.list
@@ -1,6 +1,7 @@
 != 468263-1a.html about:blank
 != 468263-1b.html about:blank
 != 468263-1c.html about:blank
 != 468263-1d.html about:blank
 == 468263-2.html 468263-2-ref.html
 == 468263-2.html 468263-2-alternate-ref.html
+== 484200-1.html 484200-1-ref.html
--- a/content/html/content/src/nsHTMLLinkElement.cpp
+++ b/content/html/content/src/nsHTMLLinkElement.cpp
@@ -111,18 +111,17 @@ public:
   virtual void GetLinkTarget(nsAString& aTarget);
   virtual nsLinkState GetLinkState() const;
   virtual void SetLinkState(nsLinkState aState);
   virtual already_AddRefed<nsIURI> GetHrefURI() const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
 protected:
-  virtual void GetStyleSheetURL(PRBool* aIsInline,
-                                nsIURI** aURI);
+  virtual already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline);
   virtual void GetStyleSheetInfo(nsAString& aTitle,
                                  nsAString& aType,
                                  nsAString& aMedia,
                                  PRBool* aIsAlternate);
  
   // The cached visited state
   nsLinkState mLinkState;
 };
@@ -390,23 +389,21 @@ nsHTMLLinkElement::SetLinkState(nsLinkSt
 }
 
 already_AddRefed<nsIURI>
 nsHTMLLinkElement::GetHrefURI() const
 {
   return GetHrefURIForAnchors();
 }
 
-void
-nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline,
-                                    nsIURI** aURI)
+already_AddRefed<nsIURI>
+nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline)
 {
   *aIsInline = PR_FALSE;
-  *aURI = GetHrefURIForAnchors().get();
-  return;
+  return GetHrefURIForAnchors();
 }
 
 void
 nsHTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
                                      nsAString& aType,
                                      nsAString& aMedia,
                                      PRBool* aIsAlternate)
 {
--- a/content/html/content/src/nsHTMLStyleElement.cpp
+++ b/content/html/content/src/nsHTMLStyleElement.cpp
@@ -98,18 +98,17 @@ public:
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
 protected:
-  void GetStyleSheetURL(PRBool* aIsInline,
-                        nsIURI** aURI);
+  already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline);
   void GetStyleSheetInfo(nsAString& aTitle,
                          nsAString& aType,
                          nsAString& aMedia,
                          PRBool* aIsAlternate);
   /**
    * Common method to call from the various mutation observer methods.
    * aContent is a content node that's either the one that changed or its
    * parent; we should only respond to the change if aContent is non-anonymous.
@@ -307,34 +306,21 @@ nsHTMLStyleElement::SetInnerHTML(const n
   nsresult rv = nsContentUtils::SetNodeTextContent(this, aInnerHTML, PR_TRUE);
   
   SetEnableUpdates(PR_TRUE);
   
   UpdateStyleSheetInternal(nsnull);
   return rv;
 }
 
-void
-nsHTMLStyleElement::GetStyleSheetURL(PRBool* aIsInline,
-                                     nsIURI** aURI)
+already_AddRefed<nsIURI>
+nsHTMLStyleElement::GetStyleSheetURL(PRBool* aIsInline)
 {
-  *aURI = nsnull;
-  *aIsInline = !HasAttr(kNameSpaceID_None, nsGkAtoms::src);
-  if (*aIsInline) {
-    return;
-  }
-  if (!IsInHTMLDocument()) {
-    // We stopped supporting <style src="..."> for XHTML as it is
-    // non-standard.
-    *aIsInline = PR_TRUE;
-    return;
-  }
-
-  *aURI = GetHrefURIForAnchors().get();
-  return;
+  *aIsInline = PR_TRUE;
+  return nsnull;
 }
 
 void
 nsHTMLStyleElement::GetStyleSheetInfo(nsAString& aTitle,
                                       nsAString& aType,
                                       nsAString& aMedia,
                                       PRBool* aIsAlternate)
 {
--- a/content/svg/content/src/nsSVGStyleElement.cpp
+++ b/content/svg/content/src/nsSVGStyleElement.cpp
@@ -94,18 +94,18 @@ protected:
   // NS_IMPL_ELEMENT_CLONE_WITH_INIT usable with this class. This should be
   // completely optimized away.
   inline nsresult Init()
   {
     return NS_OK;
   }
 
   // nsStyleLinkElement overrides
-  void GetStyleSheetURL(PRBool* aIsInline,
-                        nsIURI** aURI);
+  already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline);
+
   void GetStyleSheetInfo(nsAString& aTitle,
                          nsAString& aType,
                          nsAString& aMedia,
                          PRBool* aIsAlternate);
   /**
    * Common method to call from the various mutation observer methods.
    * aContent is a content node that's either the one that changed or its
    * parent; we should only respond to the change if aContent is non-anonymous.
@@ -306,24 +306,21 @@ NS_IMETHODIMP nsSVGStyleElement::GetTitl
 NS_IMETHODIMP nsSVGStyleElement::SetTitle(const nsAString & aTitle)
 {
   return SetAttr(kNameSpaceID_XML, nsGkAtoms::title, aTitle, PR_TRUE);
 }
 
 //----------------------------------------------------------------------
 // nsStyleLinkElement methods
 
-void
-nsSVGStyleElement::GetStyleSheetURL(PRBool* aIsInline,
-                                    nsIURI** aURI)
+already_AddRefed<nsIURI>
+nsSVGStyleElement::GetStyleSheetURL(PRBool* aIsInline)
 {
-  *aURI = nsnull;
   *aIsInline = PR_TRUE;
-
-  return;
+  return nsnull;
 }
 
 void
 nsSVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
                                      nsAString& aType,
                                      nsAString& aMedia,
                                      PRBool* aIsAlternate)
 {
--- a/content/xml/content/src/nsXMLStylesheetPI.cpp
+++ b/content/xml/content/src/nsXMLStylesheetPI.cpp
@@ -73,18 +73,17 @@ public:
   virtual void OverrideBaseURI(nsIURI* aNewBaseURI);
 
   // nsStyleLinkElement
   NS_IMETHOD GetCharset(nsAString& aCharset);
 
 protected:
   nsCOMPtr<nsIURI> mOverriddenBaseURI;
 
-  void GetStyleSheetURL(PRBool* aIsInline,
-                        nsIURI** aURI);
+  already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline);
   void GetStyleSheetInfo(nsAString& aTitle,
                          nsAString& aType,
                          nsAString& aMedia,
                          PRBool* aIsAlternate);
   virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo,
                                               PRBool aCloneText) const;
 };
 
@@ -161,39 +160,39 @@ nsXMLStylesheetPI::GetCharset(nsAString&
 }
 
 /* virtual */ void
 nsXMLStylesheetPI::OverrideBaseURI(nsIURI* aNewBaseURI)
 {
   mOverriddenBaseURI = aNewBaseURI;
 }
 
-void
-nsXMLStylesheetPI::GetStyleSheetURL(PRBool* aIsInline,
-                                    nsIURI** aURI)
+already_AddRefed<nsIURI>
+nsXMLStylesheetPI::GetStyleSheetURL(PRBool* aIsInline)
 {
   *aIsInline = PR_FALSE;
-  *aURI = nsnull;
 
   nsAutoString href;
   if (!GetAttrValue(nsGkAtoms::href, href)) {
-    return;
+    return nsnull;
   }
 
   nsIURI *baseURL;
   nsCAutoString charset;
   nsIDocument *document = GetOwnerDoc();
   if (document) {
     baseURL = mOverriddenBaseURI ? mOverriddenBaseURI.get() : document->GetBaseURI();
     charset = document->GetDocumentCharacterSet();
   } else {
     baseURL = mOverriddenBaseURI;
   }
 
-  NS_NewURI(aURI, href, charset.get(), baseURL);
+  nsCOMPtr<nsIURI> aURI;
+  NS_NewURI(getter_AddRefs(aURI), href, charset.get(), baseURL);
+  return aURI.forget();
 }
 
 void
 nsXMLStylesheetPI::GetStyleSheetInfo(nsAString& aTitle,
                                      nsAString& aType,
                                      nsAString& aMedia,
                                      PRBool* aIsAlternate)
 {