diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 22357bbc41f9..159a12d38334 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -16,6 +16,7 @@ #include "nsAttrValueInlines.h" #include "nsAtom.h" #include "nsUnicharUtils.h" +#include "mozilla/CORSMode.h" #include "mozilla/MemoryReporting.h" #include "mozilla/ServoBindingTypes.h" #include "mozilla/ServoUtils.h" @@ -1692,7 +1693,9 @@ nsAttrValue::LoadImage(nsIDocument* aDocument) "How did we end up with an empty string for eURL"); mozilla::css::ImageValue* image = - mozilla::css::ImageValue::CreateFromURLValue(url, aDocument); + mozilla::css::ImageValue::CreateFromURLValue(url, + aDocument, + mozilla::CORSMode::CORS_NONE); NS_ADDREF(image); cont->mValue.mImage = image; diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index ed9cf2b680d8..85b099d35202 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -52,6 +52,7 @@ #include "nsTArray.h" #include "nsTransitionManager.h" +#include "mozilla/CORSMode.h" #include "mozilla/DeclarationBlockInlines.h" #include "mozilla/EffectCompositor.h" #include "mozilla/EffectSet.h" @@ -1507,8 +1508,11 @@ CreateStyleImageRequest(nsStyleImageRequest::Mode aModeFlags, mozilla::css::ImageValue* Gecko_ImageValue_Create(ServoBundledURI aURI, ServoRawOffsetArc aURIString) { + // Bug 1434963: Change this to accept a CORS mode from the caller. RefPtr value( - new css::ImageValue(aURIString, do_AddRef(aURI.mExtraData))); + new css::ImageValue(aURIString, + do_AddRef(aURI.mExtraData), + mozilla::CORSMode::CORS_NONE)); return value.forget().take(); } diff --git a/layout/style/nsCSSDataBlock.cpp b/layout/style/nsCSSDataBlock.cpp index aeff6a67a2b8..d1c09c603875 100644 --- a/layout/style/nsCSSDataBlock.cpp +++ b/layout/style/nsCSSDataBlock.cpp @@ -14,6 +14,7 @@ #include "CSSVariableImageTable.h" #include "mozilla/css/Declaration.h" #include "mozilla/css/ImageLoader.h" +#include "mozilla/CORSMode.h" #include "mozilla/MemoryReporting.h" #include "mozilla/WritingModes.h" #include "nsAutoPtr.h" @@ -94,7 +95,7 @@ TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument, } } - aValue.StartImageLoad(aDocument); + aValue.StartImageLoad(aDocument, CORSMode::CORS_NONE); if (aForTokenStream && aContext) { CSSVariableImageTable::Add(aContext, aProperty, aValue.GetImageStructValue()); diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index be2491fe1b3d..e3c893a2b737 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -894,11 +894,14 @@ nsCSSValue::GetCalcValue() const return result; } -void nsCSSValue::StartImageLoad(nsIDocument* aDocument) const +void nsCSSValue::StartImageLoad(nsIDocument* aDocument, + mozilla::CORSMode aCORSMode) const { MOZ_ASSERT(eCSSUnit_URL == mUnit, "Not a URL value!"); mozilla::css::ImageValue* image = - mozilla::css::ImageValue::CreateFromURLValue(mValue.mURL, aDocument); + mozilla::css::ImageValue::CreateFromURLValue(mValue.mURL, + aDocument, + aCORSMode); nsCSSValue* writable = const_cast(this); writable->SetImageValue(image); @@ -3111,44 +3114,59 @@ css::URLValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const css::ImageValue::ImageValue(nsIURI* aURI, const nsAString& aString, already_AddRefed aExtraData, - nsIDocument* aDocument) + nsIDocument* aDocument, + CORSMode aCORSMode) : URLValueData(do_AddRef(new PtrHolder("URLValueData::mURI", aURI)), aString, Move(aExtraData)) { + mCORSMode = aCORSMode; Initialize(aDocument); } css::ImageValue::ImageValue(nsIURI* aURI, ServoRawOffsetArc aString, already_AddRefed aExtraData, - nsIDocument* aDocument) + nsIDocument* aDocument, + CORSMode aCORSMode) : URLValueData(do_AddRef(new PtrHolder("URLValueData::mURI", aURI)), aString, Move(aExtraData)) { + mCORSMode = aCORSMode; Initialize(aDocument); } css::ImageValue::ImageValue(const nsAString& aString, - already_AddRefed aExtraData) + already_AddRefed aExtraData, + CORSMode aCORSMode) : URLValueData(aString, Move(aExtraData)) { + mCORSMode = aCORSMode; } css::ImageValue::ImageValue(ServoRawOffsetArc aString, - already_AddRefed aExtraData) + already_AddRefed aExtraData, + CORSMode aCORSMode) : URLValueData(aString, Move(aExtraData)) { + mCORSMode = aCORSMode; } /*static*/ css::ImageValue* -css::ImageValue::CreateFromURLValue(URLValue* aUrl, nsIDocument* aDocument) +css::ImageValue::CreateFromURLValue(URLValue* aUrl, + nsIDocument* aDocument, + CORSMode aCORSMode) { if (aUrl->mUsingRustString) { return new css::ImageValue(aUrl->GetURI(), Servo_CloneArcStringData(&aUrl->mStrings.mRustString), - do_AddRef(aUrl->mExtraData), aDocument); + do_AddRef(aUrl->mExtraData), + aDocument, + aCORSMode); } - return new css::ImageValue(aUrl->GetURI(), aUrl->mStrings.mString, - do_AddRef(aUrl->mExtraData), aDocument); + return new css::ImageValue(aUrl->GetURI(), + aUrl->mStrings.mString, + do_AddRef(aUrl->mExtraData), + aDocument, + aCORSMode); } void @@ -3169,9 +3187,9 @@ css::ImageValue::Initialize(nsIDocument* aDocument) mExtraData->GetPrincipal(), mExtraData->GetReferrer(), this, - CORSMode::CORS_NONE); + mCORSMode); - mLoadedImage = true; + mLoadedImage = true; } aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this); diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index ada6137e08a8..87952ae16f73 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -10,6 +10,7 @@ #define nsCSSValue_h___ #include "mozilla/Attributes.h" +#include "mozilla/CORSMode.h" #include "mozilla/MemoryReporting.h" #include "mozilla/ServoTypes.h" #include "mozilla/SheetType.h" @@ -204,11 +205,17 @@ protected: // confused by the non-standard-layout packing of the variable up into // URLValueData. bool mLoadedImage = false; + CORSMode mCORSMode = CORSMode::CORS_NONE; virtual ~URLValueData(); size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; +public: + void SetCORSMode(CORSMode aCORSMode) { + mCORSMode = aCORSMode; + } + private: URLValueData(const URLValueData& aOther) = delete; URLValueData& operator=(const URLValueData& aOther) = delete; @@ -237,7 +244,9 @@ struct URLValue final : public URLValueData struct ImageValue final : public URLValueData { - static ImageValue* CreateFromURLValue(URLValue* url, nsIDocument* aDocument); + static ImageValue* CreateFromURLValue(URLValue* url, + nsIDocument* aDocument, + CORSMode aCORSMode); // Not making the constructor and destructor inline because that would // force us to include imgIRequest.h, which leads to REQUIRES hell, since @@ -246,22 +255,26 @@ struct ImageValue final : public URLValueData // This constructor is only safe to call from the main thread. ImageValue(nsIURI* aURI, const nsAString& aString, already_AddRefed aExtraData, - nsIDocument* aDocument); + nsIDocument* aDocument, + CORSMode aCORSMode); // This constructor is only safe to call from the main thread. ImageValue(nsIURI* aURI, ServoRawOffsetArc aString, already_AddRefed aExtraData, - nsIDocument* aDocument); + nsIDocument* aDocument, + CORSMode aCORSMode); // This constructor is safe to call from any thread, but Initialize // must be called later for the object to be useful. ImageValue(const nsAString& aString, - already_AddRefed aExtraData); + already_AddRefed aExtraData, + CORSMode aCORSMode); // This constructor is safe to call from any thread, but Initialize // must be called later for the object to be useful. ImageValue(ServoRawOffsetArc aURIString, - already_AddRefed aExtraData); + already_AddRefed aExtraData, + CORSMode aCORSMode); ImageValue(const ImageValue&) = delete; ImageValue& operator=(const ImageValue&) = delete;