From 41ac1056bf41b35e87ba09c5ee0ee051c4874044 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 28 Aug 2012 13:10:07 -0400 Subject: [PATCH] Bug 732209 part 2. Communicate the CORS state of style link loads to the CSS loader. r=sicking --- content/base/src/nsContentSink.cpp | 6 ++++ content/base/src/nsStyleLinkElement.cpp | 4 +-- content/base/src/nsStyleLinkElement.h | 7 +++++ .../html/content/src/nsHTMLLinkElement.cpp | 29 ++++++++++++++++++ content/svg/content/src/nsSVGStyleElement.cpp | 30 +++++++++++++++++++ layout/style/Loader.cpp | 1 + layout/style/Loader.h | 3 ++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 06c6c8f0db4..8e836236397 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -737,9 +737,15 @@ nsContentSink::ProcessStyleLink(nsIContent* aElement, return NS_OK; } + NS_ASSERTION(!aElement || + aElement->NodeType() == nsIDOMNode::PROCESSING_INSTRUCTION_NODE, + "We only expect processing instructions here"); + // If this is a fragment parser, we don't want to observe. + // We don't support CORS for processing instructions bool isAlternate; rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, aAlternate, + CORS_NONE, mRunsToCompletion ? nullptr : this, &isAlternate); NS_ENSURE_SUCCESS(rv, rv); diff --git a/content/base/src/nsStyleLinkElement.cpp b/content/base/src/nsStyleLinkElement.cpp index 4575ccf9113..33996ce62c6 100644 --- a/content/base/src/nsStyleLinkElement.cpp +++ b/content/base/src/nsStyleLinkElement.cpp @@ -276,8 +276,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument *aOldDocument, uri->Clone(getter_AddRefs(clonedURI)); NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY); rv = doc->CSSLoader()-> - LoadStyleLink(thisContent, clonedURI, title, media, isAlternate, aObserver, - &isAlternate); + LoadStyleLink(thisContent, clonedURI, title, media, isAlternate, + GetCORSMode(), aObserver, &isAlternate); if (NS_FAILED(rv)) { // Don't propagate LoadStyleLink() errors further than this, since some // consumers (e.g. nsXMLContentSink) will completely abort on innocuous diff --git a/content/base/src/nsStyleLinkElement.h b/content/base/src/nsStyleLinkElement.h index c70fff828c5..7f7918dd756 100644 --- a/content/base/src/nsStyleLinkElement.h +++ b/content/base/src/nsStyleLinkElement.h @@ -19,6 +19,7 @@ #include "nsIStyleSheet.h" #include "nsIURI.h" #include "nsTArray.h" +#include "mozilla/CORSMode.h" #define PREFETCH 0x00000001 #define DNS_PREFETCH 0x00000002 @@ -76,6 +77,12 @@ protected: nsIStyleSheet* GetStyleSheet() { return mStyleSheet; } + virtual mozilla::CORSMode GetCORSMode() const + { + // Default to no CORS + return mozilla::CORS_NONE; + } + private: /** * @param aOldDocument should be non-null only if we're updating because we diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 41b7380bd4d..f67a99cd4fb 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -24,6 +24,8 @@ #include "nsAsyncDOMEvent.h" #include "Link.h" + +using namespace mozilla; using namespace mozilla::dom; class nsHTMLLinkElement : public nsGenericHTMLElement, @@ -63,6 +65,10 @@ public: bool aCompileEventHandlers); virtual void UnbindFromTree(bool aDeep = true, bool aNullParent = true); + virtual bool ParseAttribute(int32_t aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult); void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName); nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, const nsAString& aValue, bool aNotify) @@ -94,6 +100,7 @@ protected: nsAString& aType, nsAString& aMedia, bool* aIsAlternate); + virtual CORSMode GetCORSMode() const; protected: virtual void GetItemValueText(nsAString& text); virtual void SetItemValueText(const nsAString& text); @@ -242,6 +249,22 @@ nsHTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent) UpdateStyleSheetInternal(oldDoc); } +bool +nsHTMLLinkElement::ParseAttribute(int32_t aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult) +{ + if (aNamespaceID == kNameSpaceID_None && + aAttribute == nsGkAtoms::crossorigin) { + ParseCORSValue(aValue, aResult); + return true; + } + + return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, + aResult); +} + void nsHTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName) @@ -443,6 +466,12 @@ nsHTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle, return; } +CORSMode +nsHTMLLinkElement::GetCORSMode() const +{ + return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)); +} + nsEventStates nsHTMLLinkElement::IntrinsicState() const { diff --git a/content/svg/content/src/nsSVGStyleElement.cpp b/content/svg/content/src/nsSVGStyleElement.cpp index cc8bbae1693..aa41a800a84 100644 --- a/content/svg/content/src/nsSVGStyleElement.cpp +++ b/content/svg/content/src/nsSVGStyleElement.cpp @@ -11,6 +11,8 @@ #include "nsStyleLinkElement.h" #include "nsContentUtils.h" +using namespace mozilla; + typedef nsSVGElement nsSVGStyleElementBase; class nsSVGStyleElement : public nsSVGStyleElementBase, @@ -48,6 +50,10 @@ public: bool aNotify); virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, bool aNotify); + virtual bool ParseAttribute(int32_t aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult); virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; @@ -76,6 +82,8 @@ protected: nsAString& aType, nsAString& aMedia, bool* aIsAlternate); + virtual CORSMode GetCORSMode() const; + /** * Common method to call from the various mutation observer methods. * aContent is a content node that's either the one that changed or its @@ -184,6 +192,22 @@ nsSVGStyleElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, return rv; } +bool +nsSVGStyleElement::ParseAttribute(int32_t aNamespaceID, + nsIAtom* aAttribute, + const nsAString& aValue, + nsAttrValue& aResult) +{ + if (aNamespaceID == kNameSpaceID_None && + aAttribute == nsGkAtoms::crossorigin) { + ParseCORSValue(aValue, aResult); + return true; + } + + return nsSVGStyleElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue, + aResult); +} + //---------------------------------------------------------------------- // nsIMutationObserver methods @@ -317,3 +341,9 @@ nsSVGStyleElement::GetStyleSheetInfo(nsAString& aTitle, return; } + +CORSMode +nsSVGStyleElement::GetCORSMode() const +{ + return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)); +} diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 55636e7808a..e7a5858d427 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1846,6 +1846,7 @@ Loader::LoadStyleLink(nsIContent* aElement, const nsAString& aTitle, const nsAString& aMedia, bool aHasAlternateRel, + CORSMode aCORSMode, nsICSSLoaderObserver* aObserver, bool* aIsAlternate) { diff --git a/layout/style/Loader.h b/layout/style/Loader.h index c821b3081c1..c8ff7c6c08c 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -19,6 +19,7 @@ #include "nsTObserverArray.h" #include "nsURIHashKey.h" #include "mozilla/Attributes.h" +#include "mozilla/CORSMode.h" class nsIAtom; class nsICSSLoaderObserver; @@ -168,6 +169,7 @@ public: * @param aMedia the media string for the sheet. * @param aHasAlternateRel whether the rel for this link included * "alternate". + * @param aCORSMode the CORS mode for this load. * @param aObserver the observer to notify when the load completes. * May be null. * @param [out] aIsAlternate whether the stylesheet actually ended up beinga @@ -179,6 +181,7 @@ public: const nsAString& aTitle, const nsAString& aMedia, bool aHasAlternateRel, + mozilla::CORSMode aCORSMode, nsICSSLoaderObserver* aObserver, bool* aIsAlternate);