Bug 1404222 Part 4: Change creators of ImageValues to specify load flags directly, instead of just the CORS mode. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 16 Feb 2018 16:44:23 -0800
changeset 762584 53e60d7b78a64370ecaa8ccc436543c436e8e692
parent 762583 86caca9827e81cd3edc79d789582eb449201d0f3
child 762585 3809307f73101bc2e60355a5a3684c555f33e163
push id101211
push userbwerth@mozilla.com
push dateFri, 02 Mar 2018 18:20:33 +0000
bugs1404222
milestone60.0a1
Bug 1404222 Part 4: Change creators of ImageValues to specify load flags directly, instead of just the CORS mode. MozReview-Commit-ID: JRMeGHEePzR
dom/base/nsAttrValue.cpp
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
layout/style/ImageLoader.cpp
layout/style/ImageLoader.h
layout/style/ServoBindings.cpp
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
--- a/dom/base/nsAttrValue.cpp
+++ b/dom/base/nsAttrValue.cpp
@@ -11,17 +11,16 @@
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/HashFunctions.h"
 
 #include "nsAttrValue.h"
 #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"
 #include "mozilla/DeclarationBlockInlines.h"
 #include "nsContentUtils.h"
 #include "nsReadableUtils.h"
 #include "nsHTMLCSSStyleSheet.h"
 #include "nsCSSParser.h"
@@ -1690,17 +1689,17 @@ nsAttrValue::LoadImage(nsIDocument* aDoc
   mozilla::css::URLValue* url = cont->mValue.mURL;
 
   NS_ASSERTION(!url->IsStringEmpty(),
                "How did we end up with an empty string for eURL");
 
   mozilla::css::ImageValue* image =
       mozilla::css::ImageValue::CreateFromURLValue(url,
                                                    aDocument,
-                                                   mozilla::CORSMode::CORS_NONE);
+                                                   nsIRequest::LOAD_NORMAL);
 
   NS_ADDREF(image);
   cont->mValue.mImage = image;
   NS_RELEASE(url);
   cont->mType = eImage;
 }
 
 bool
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3800,17 +3800,18 @@ nsContentUtils::CORSModeToLoadImageFlags
 // static
 nsresult
 nsContentUtils::LoadImage(nsIURI* aURI, nsINode* aContext,
                           nsIDocument* aLoadingDocument,
                           nsIPrincipal* aLoadingPrincipal,
                           uint64_t aRequestContextID,
                           nsIURI* aReferrer,
                           net::ReferrerPolicy aReferrerPolicy,
-                          imgINotificationObserver* aObserver, int32_t aLoadFlags,
+                          imgINotificationObserver* aObserver,
+                          nsLoadFlags aLoadFlags,
                           const nsAString& initiatorType,
                           imgRequestProxy** aRequest,
                           uint32_t aContentPolicyType,
                           bool aUseUrgentStartForChannel)
 {
   NS_PRECONDITION(aURI, "Must have a URI");
   NS_PRECONDITION(aContext, "Must have a context");
   NS_PRECONDITION(aLoadingDocument, "Must have a document");
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -874,17 +874,17 @@ public:
   static nsresult LoadImage(nsIURI* aURI,
                             nsINode* aContext,
                             nsIDocument* aLoadingDocument,
                             nsIPrincipal* aLoadingPrincipal,
                             uint64_t aRequestContextID,
                             nsIURI* aReferrer,
                             mozilla::net::ReferrerPolicy aReferrerPolicy,
                             imgINotificationObserver* aObserver,
-                            int32_t aLoadFlags,
+                            nsLoadFlags aLoadFlags,
                             const nsAString& initiatorType,
                             imgRequestProxy** aRequest,
                             uint32_t aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE,
                             bool aUseUrgentStartForChannel = false);
 
   /**
    * Obtain an image loader that respects the given document/channel's privacy status.
    * Null document/channel arguments return the public image loader.
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -241,34 +241,31 @@ ImageLoader::ClearFrames(nsPresContext* 
 
   mRequestToFrameMap.Clear();
   mFrameToRequestMap.Clear();
 }
 
 void
 ImageLoader::LoadImage(nsIURI* aURI, nsIPrincipal* aOriginPrincipal,
                        nsIURI* aReferrer, ImageLoader::Image* aImage,
-                       CORSMode aCorsMode)
+                       nsLoadFlags aLoadFlags)
 {
   NS_ASSERTION(aImage->mRequests.Count() == 0, "Huh?");
 
   aImage->mRequests.Put(nullptr, nullptr);
 
   if (!aURI) {
     return;
   }
 
-  int32_t loadFlags = nsIRequest::LOAD_NORMAL |
-                      nsContentUtils::CORSModeToLoadImageFlags(aCorsMode);
-
   RefPtr<imgRequestProxy> request;
   nsresult rv = nsContentUtils::LoadImage(aURI, mDocument, mDocument,
                                           aOriginPrincipal, 0, aReferrer,
                                           mDocument->GetReferrerPolicy(),
-                                          nullptr, loadFlags,
+                                          nullptr, aLoadFlags,
                                           NS_LITERAL_STRING("css"),
                                           getter_AddRefs(request));
 
   if (NS_FAILED(rv) || !request) {
     return;
   }
 
   RefPtr<imgRequestProxy> clonedRequest;
--- a/layout/style/ImageLoader.h
+++ b/layout/style/ImageLoader.h
@@ -61,17 +61,17 @@ public:
   void SetAnimationMode(uint16_t aMode);
 
   // The prescontext for this ImageLoader's document. We need it to be passed
   // in because this can be called during presentation destruction after the
   // presshell pointer on the document has been cleared.
   void ClearFrames(nsPresContext* aPresContext);
 
   void LoadImage(nsIURI* aURI, nsIPrincipal* aPrincipal, nsIURI* aReferrer,
-                 Image* aCSSValue, CORSMode aCorsMode);
+                 Image* aCSSValue, nsLoadFlags aLoadFlags);
 
   void DestroyRequest(imgIRequest* aRequest);
 
   void FlushUseCounters();
 
 private:
   ~ImageLoader() {}
 
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -47,17 +47,16 @@
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsStyleStruct.h"
 #include "nsStyleUtil.h"
 #include "nsSVGElement.h"
 #include "nsTArray.h"
 #include "nsTransitionManager.h"
 
-#include "mozilla/CORSMode.h"
 #include "mozilla/DeclarationBlockInlines.h"
 #include "mozilla/EffectCompositor.h"
 #include "mozilla/EffectSet.h"
 #include "mozilla/EventStates.h"
 #ifdef MOZ_OLD_STYLE
 #include "mozilla/GeckoStyleContext.h"
 #endif
 #include "mozilla/Keyframe.h"
@@ -1500,17 +1499,17 @@ CreateStyleImageRequest(nsStyleImageRequ
 
 mozilla::css::ImageValue*
 Gecko_ImageValue_Create(ServoBundledURI aURI, ServoRawOffsetArc<RustString> aURIString)
 {
   // Bug 1434963: Change this to accept a CORS mode from the caller.
   RefPtr<css::ImageValue> value(
     new css::ImageValue(aURIString,
                         do_AddRef(aURI.mExtraData),
-                        mozilla::CORSMode::CORS_NONE));
+                        nsIRequest::LOAD_NORMAL));
   return value.forget().take();
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(GeckoImageValueMallocSizeOf)
 
 size_t
 Gecko_ImageValue_SizeOfIncludingThis(mozilla::css::ImageValue* aImageValue)
 {
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* representation of simple property values within CSS declarations */
 
 #include "nsCSSValue.h"
 
-#include "mozilla/CORSMode.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/ServoTypes.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/css/ImageLoader.h"
 #include "CSSCalc.h"
@@ -891,23 +890,23 @@ nsCSSValue::GetCalcValue() const
     result.mPercent = percent.GetPercentValue();
     result.mHasPercent = true;
   }
 
   return result;
 }
 
 void nsCSSValue::StartImageLoad(nsIDocument* aDocument,
-                                mozilla::CORSMode aCORSMode) const
+                                nsLoadFlags aLoadFlags) const
 {
   MOZ_ASSERT(eCSSUnit_URL == mUnit, "Not a URL value!");
   mozilla::css::ImageValue* image =
       mozilla::css::ImageValue::CreateFromURLValue(mValue.mURL,
                                                    aDocument,
-                                                   aCORSMode);
+                                                   aLoadFlags);
 
   nsCSSValue* writable = const_cast<nsCSSValue*>(this);
   writable->SetImageValue(image);
 }
 
 nscolor nsCSSValue::GetColorValue() const
 {
   MOZ_ASSERT(IsNumericColorUnit(), "not a color value");
@@ -3116,68 +3115,68 @@ css::URLValue::SizeOfIncludingThis(mozil
     n += URLValueData::SizeOfExcludingThis(aMallocSizeOf);
   }
   return n;
 }
 
 css::ImageValue::ImageValue(nsIURI* aURI, const nsAString& aString,
                             already_AddRefed<URLExtraData> aExtraData,
                             nsIDocument* aDocument,
-                            CORSMode aCORSMode)
+                            nsLoadFlags aLoadFlags)
   : URLValueData(do_AddRef(new PtrHolder<nsIURI>("URLValueData::mURI", aURI)),
                  aString, Move(aExtraData))
 {
-  mCORSMode = aCORSMode;
+  mLoadFlags = aLoadFlags;
   Initialize(aDocument);
 }
 
 css::ImageValue::ImageValue(nsIURI* aURI, ServoRawOffsetArc<RustString> aString,
                             already_AddRefed<URLExtraData> aExtraData,
                             nsIDocument* aDocument,
-                            CORSMode aCORSMode)
+                            nsLoadFlags aLoadFlags)
   : URLValueData(do_AddRef(new PtrHolder<nsIURI>("URLValueData::mURI", aURI)),
                  aString, Move(aExtraData))
 {
-  mCORSMode = aCORSMode;
+  mLoadFlags = aLoadFlags;
   Initialize(aDocument);
 }
 
 css::ImageValue::ImageValue(const nsAString& aString,
                             already_AddRefed<URLExtraData> aExtraData,
-                            CORSMode aCORSMode)
+                            nsLoadFlags aLoadFlags)
   : URLValueData(aString, Move(aExtraData))
 {
-  mCORSMode = aCORSMode;
+  mLoadFlags = aLoadFlags;
 }
 
 css::ImageValue::ImageValue(ServoRawOffsetArc<RustString> aString,
                             already_AddRefed<URLExtraData> aExtraData,
-                            CORSMode aCORSMode)
+                            nsLoadFlags aLoadFlags)
   : URLValueData(aString, Move(aExtraData))
 {
-  mCORSMode = aCORSMode;
+  mLoadFlags = aLoadFlags;
 }
 
 /*static*/ css::ImageValue*
 css::ImageValue::CreateFromURLValue(URLValue* aUrl,
                                     nsIDocument* aDocument,
-                                    CORSMode aCORSMode)
+                                    nsLoadFlags aLoadFlags)
 {
   if (aUrl->mUsingRustString) {
     return new css::ImageValue(aUrl->GetURI(),
                                Servo_CloneArcStringData(&aUrl->mStrings.mRustString),
                                do_AddRef(aUrl->mExtraData),
                                aDocument,
-                               aCORSMode);
+                               aLoadFlags);
   }
   return new css::ImageValue(aUrl->GetURI(),
                              aUrl->mStrings.mString,
                              do_AddRef(aUrl->mExtraData),
                              aDocument,
-                             aCORSMode);
+                             aLoadFlags);
 }
 
 void
 css::ImageValue::Initialize(nsIDocument* aDocument)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // NB: If aDocument is not the original document, we may not be able to load
@@ -3188,17 +3187,17 @@ css::ImageValue::Initialize(nsIDocument*
     loadingDoc = aDocument;
   }
 
   if (!mLoadedImage) {
     loadingDoc->StyleImageLoader()->LoadImage(GetURI(),
                                               mExtraData->GetPrincipal(),
                                               mExtraData->GetReferrer(),
                                               this,
-                                              mCORSMode);
+                                              mLoadFlags);
 
     mLoadedImage = true;
   }
 
   aDocument->StyleImageLoader()->MaybeRegisterCSSImage(this);
 }
 
 css::ImageValue::~ImageValue()
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -5,24 +5,24 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* representation of simple property values within CSS declarations */
 
 #ifndef nsCSSValue_h___
 #define nsCSSValue_h___
 
 #include "mozilla/Attributes.h"
-#include "mozilla/CORSMode.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/ServoTypes.h"
 #include "mozilla/SheetType.h"
 #include "mozilla/StyleComplexColor.h"
 #include "mozilla/URLExtraData.h"
 #include "mozilla/UniquePtr.h"
 
+#include "nsIRequest.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSPropertyID.h"
 #include "nsCSSProps.h"
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsProxyRelease.h"
 #include "nsRefPtrHashtable.h"
 #include "nsString.h"
@@ -200,25 +200,26 @@ private:
   } mStrings;
   mutable bool mUsingRustString;
 
 protected:
   // Only used by ImageValue.  Declared up here because otherwise bindgen gets
   // confused by the non-standard-layout packing of the variable up into
   // URLValueData.
   bool mLoadedImage = false;
-  CORSMode mCORSMode = CORSMode::CORS_NONE;
+  nsLoadFlags mLoadFlags = 0;
 
   virtual ~URLValueData();
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 public:
-  void SetCORSMode(CORSMode aCORSMode) {
-    mCORSMode = aCORSMode;
+  nsLoadFlags GetLoadFlags() { return mLoadFlags; }
+  void SetLoadFlags(nsLoadFlags aLoadFlags) {
+    mLoadFlags = aLoadFlags;
   }
 
 private:
   URLValueData(const URLValueData& aOther) = delete;
   URLValueData& operator=(const URLValueData& aOther) = delete;
 
   friend struct ImageValue;
 };
@@ -241,45 +242,45 @@ struct URLValue final : public URLValueD
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 };
 
 struct ImageValue final : public URLValueData
 {
   static ImageValue* CreateFromURLValue(URLValue* url,
                                         nsIDocument* aDocument,
-                                        CORSMode aCORSMode);
+                                        nsLoadFlags aLoadFlags);
 
   // Not making the constructor and destructor inline because that would
   // force us to include imgIRequest.h, which leads to REQUIRES hell, since
   // this header is included all over.
   //
   // This constructor is only safe to call from the main thread.
   ImageValue(nsIURI* aURI, const nsAString& aString,
              already_AddRefed<URLExtraData> aExtraData,
              nsIDocument* aDocument,
-             CORSMode aCORSMode);
+             nsLoadFlags aLoadFlags);
 
   // This constructor is only safe to call from the main thread.
   ImageValue(nsIURI* aURI, ServoRawOffsetArc<RustString> aString,
              already_AddRefed<URLExtraData> aExtraData,
              nsIDocument* aDocument,
-             CORSMode aCORSMode);
+             nsLoadFlags aLoadFlags);
 
   // 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<URLExtraData> aExtraData,
-             CORSMode aCORSMode);
+             nsLoadFlags aLoadFlags);
 
   // This constructor is safe to call from any thread, but Initialize
   // must be called later for the object to be useful.
   ImageValue(ServoRawOffsetArc<RustString> aURIString,
              already_AddRefed<URLExtraData> aExtraData,
-             CORSMode aCORSMode);
+             nsLoadFlags aLoadFlags);
 
   ImageValue(const ImageValue&) = delete;
   ImageValue& operator=(const ImageValue&) = delete;
 
   void Initialize(nsIDocument* aDocument);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
@@ -980,17 +981,17 @@ public:
   nsCSSValueList* SetListValue();
   nsCSSValuePairList* SetPairListValue();
 
   // These take ownership of the passed-in resource.
   void AdoptListValue(mozilla::UniquePtr<nsCSSValueList> aValue);
   void AdoptPairListValue(mozilla::UniquePtr<nsCSSValuePairList> aValue);
 
   void StartImageLoad(nsIDocument* aDocument,
-                      mozilla::CORSMode aCORSMode) const;  // Only pretend const
+                      nsLoadFlags aLoadFlags) const;  // Only pretend const
 
   // Initializes as a function value with the specified function id.
   Array* InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs);
   // Checks if this is a function value with the specified function id.
   bool EqualsFunction(nsCSSKeyword aFunctionId) const;
 
   // Returns an already addrefed buffer.  Guaranteed to return non-null.
   // (Will abort on allocation failure.)
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -58,16 +58,17 @@
 #include "CSSVariableResolver.h"
 #include "nsCSSParser.h"
 #include "CounterStyleManager.h"
 #include "nsCSSPropertyIDSet.h"
 #include "mozilla/RuleNodeCacheConditions.h"
 #include "nsDeviceContext.h"
 #include "nsQueryObject.h"
 #include "nsUnicodeProperties.h"
+#include "imgILoader.h"
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
 #include <malloc.h>
 #ifdef _MSC_VER
 #define alloca _alloca
 #endif
 #endif
 #ifdef SOLARIS
@@ -6448,18 +6449,19 @@ nsRuleNode::ComputeDisplayData(void* aSt
       break;
     case eCSSUnit_Image:
     case eCSSUnit_Function:
     case eCSSUnit_Gradient:
     case eCSSUnit_Element: {
       auto shapeImage = MakeUnique<nsStyleImage>();
       SetStyleImage(aContext, *shapeOutsideValue, *shapeImage, conditions);
       if (shapeImage->GetType() == eStyleImageType_Image) {
-        shapeImage->GetImageRequest()->GetImageValue()->SetCORSMode(
-          CORSMode::CORS_ANONYMOUS);
+        shapeImage->GetImageRequest()->GetImageValue()->SetLoadFlags(
+          imgILoader::LOAD_CORS_ANONYMOUS |
+          imgILoader::DELAY_LOAD_EVENT_UNTIL_DECODE);
       }
       display->mShapeOutside = StyleShapeSource();
       display->mShapeOutside.SetShapeImage(Move(shapeImage));
       break;
     }
     case eCSSUnit_Array: {
       display->mShapeOutside = StyleShapeSource();
       SetStyleShapeSourceToCSSValue(&display->mShapeOutside, shapeOutsideValue,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -36,17 +36,17 @@
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/ImageTracker.h"
 #include "mozilla/CORSMode.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Likely.h"
 #include "nsIURI.h"
 #include "nsIDocument.h"
 #include <algorithm>
-#include "ImageLoader.h"
+#include "imgILoader.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static_assert((((1 << nsStyleStructID_Length) - 1) &
                ~(NS_STYLE_INHERIT_MASK)) == 0,
               "Not enough bits in NS_STYLE_INHERIT_MASK");
 
@@ -3769,18 +3769,19 @@ nsStyleDisplay::FinishStyle(
 
   if (mShapeOutside.GetType() == StyleShapeSourceType::Image) {
     const UniquePtr<nsStyleImage>& shapeImage = mShapeOutside.GetShapeImage();
     if (shapeImage) {
       // Bug 1434963: The CORS mode should instead be set when the
       // ImageValue is created, in both Gecko and Stylo. That will
       // avoid doing a mutation here.
       if (shapeImage->GetType() == eStyleImageType_Image) {
-        shapeImage->GetImageRequest()->GetImageValue()->SetCORSMode(
-          CORSMode::CORS_ANONYMOUS);
+        shapeImage->GetImageRequest()->GetImageValue()->SetLoadFlags(
+          imgILoader::LOAD_CORS_ANONYMOUS |
+          imgILoader::DELAY_LOAD_EVENT_UNTIL_DECODE);
       }
       const nsStyleImage* oldShapeImage =
         (aOldStyle &&
          aOldStyle->mShapeOutside.GetType() == StyleShapeSourceType::Image)
           ?  &*aOldStyle->mShapeOutside.GetShapeImage() : nullptr;
       shapeImage->ResolveImage(aPresContext, oldShapeImage);
     }
   }