Bug 1418930 Part 4: Define a CSS property flag to accompany the image preload flag -- to also use anonymous CORS. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 25 Jan 2018 14:56:39 -0800
changeset 751873 ddc15fa984ec306168493bbdcc6ff36c6bb3366e
parent 751872 ba36db3c79d16e202efa509c21a48d9873e46ad7
child 751874 8a74c1b92c03ff74e2c876e68174fd2f1dcbcff0
push id98080
push userbwerth@mozilla.com
push dateWed, 07 Feb 2018 01:10:26 +0000
bugs1418930
milestone60.0a1
Bug 1418930 Part 4: Define a CSS property flag to accompany the image preload flag -- to also use anonymous CORS. MozReview-Commit-ID: 9iQgT3g1m9J
layout/style/nsCSSDataBlock.cpp
layout/style/nsCSSPropList.h
layout/style/nsCSSProps.h
layout/style/nsCSSValue.h
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -90,17 +90,21 @@ TryToStartImageLoadOnValue(const nsCSSVa
         bool isEqualExceptRef = false;
         nsresult  rv = imageURI->EqualsExceptRef(docURI, &isEqualExceptRef);
         if (NS_SUCCEEDED(rv) && isEqualExceptRef) {
           return;
         }
       }
     }
 
-    aValue.StartImageLoad(aDocument, CORSMode::CORS_NONE);
+    CORSMode mode =
+      nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_LOAD_USE_CORS) ?
+      CORSMode::CORS_ANONYMOUS :
+      CORSMode::CORS_NONE;
+    aValue.StartImageLoad(aDocument, mode);
     if (aForTokenStream && aContext) {
       CSSVariableImageTable::Add(aContext, aProperty,
                                  aValue.GetImageStructValue());
     }
   }
   else if (aValue.GetUnit() == eCSSUnit_Image) {
     // If we already have a request, see if this document needs to clone it.
     imgIRequest* request = aValue.GetImageValue(nullptr);
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -3748,16 +3748,17 @@ CSS_PROP_DISPLAY(
 CSS_PROP_DISPLAY(
     shape-outside,
     shape_outside,
     ShapeOutside,
     CSS_PROPERTY_PARSE_VALUE |
         CSS_PROPERTY_VALUE_PARSER_FUNCTION |
         CSS_PROPERTY_APPLIES_TO_FIRST_LETTER |
         CSS_PROPERTY_START_IMAGE_LOADS |
+        CSS_PROPERTY_LOAD_USE_CORS |
         CSS_PROPERTY_STORES_CALC,
     "layout.css.shape-outside.enabled",
     0,
     nullptr,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_Custom)
 CSS_PROP_SVG(
     shape-rendering,
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -279,16 +279,21 @@ static_assert((CSS_PROPERTY_PARSE_PROPER
 // absolutely positioned elements.
 // This should be set for any properties that can cause an element to be
 // such a containing block, as implemented in
 // nsStyleDisplay::IsAbsPosContainingBlock.
 // It does not need to be set for properties that also have
 // CSS_PROPERTY_FIXPOS_CB set.
 #define CSS_PROPERTY_ABSPOS_CB                    (1<<30)
 
+// This property should add Cross Origin Request headers to any loads
+// that it triggers. Currently this is only used for properties that
+// also use CSS_PROPERTY_START_IMAGE_LOADS.
+#define CSS_PROPERTY_LOAD_USE_CORS                (1U<<31)
+
 /**
  * Types of animatable values.
  */
 enum nsStyleAnimType {
   // requires a custom implementation in
   // StyleAnimationValue::ExtractComputedValue
   eStyleAnimType_Custom,
 
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -979,17 +979,18 @@ public:
   nsCSSRect& SetRectValue();
   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) const;  // Only pretend const
+  void StartImageLoad(nsIDocument* aDocument,
+                      mozilla::CORSMode aCORSMode) 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.)