Bug 1418470 - Part 1: Provide a specialized parse_method for mask-image to use CORS. r=emilio, a=pascalc
authorBrad Werth <bwerth@mozilla.com>
Wed, 12 Sep 2018 15:54:24 -0700
changeset 490074 f6d84997277d20addda3c185adbb58acb48c41d9
parent 490073 1c22f27d31ec04d8ad7a46d584115665854bfc46
child 490075 3886ffc45b71c381bef499937a387a7e28fa4515
push id9897
push userryanvm@gmail.com
push dateWed, 26 Sep 2018 16:54:24 +0000
treeherdermozilla-beta@3886ffc45b71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, pascalc
bugs1418470
milestone63.0
Bug 1418470 - Part 1: Provide a specialized parse_method for mask-image to use CORS. r=emilio, a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D5714
servo/components/style/properties/longhands/svg.mako.rs
servo/components/style/values/specified/image.rs
--- a/servo/components/style/properties/longhands/svg.mako.rs
+++ b/servo/components/style/properties/longhands/svg.mako.rs
@@ -178,15 +178,16 @@
     spec="https://drafts.fxtf.org/css-masking/#propdef-mask-composite",
 )}
 
 ${helpers.predefined_type(
     "mask-image",
     "ImageLayer",
     "Either::First(None_)",
     initial_specified_value="Either::First(None_)",
+    parse_method="parse_with_cors_anonymous",
     spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image",
     vector=True,
     products="gecko",
     extra_prefixes="webkit",
     animation_value_type="discrete",
     flags="CREATES_STACKING_CONTEXT",
 )}
--- a/servo/components/style/values/specified/image.rs
+++ b/servo/components/style/values/specified/image.rs
@@ -28,16 +28,30 @@ use values::generics::position::Position
 use values::specified::{Angle, Color, Length, LengthOrPercentage};
 use values::specified::{Number, NumberOrPercentage, Percentage};
 use values::specified::position::{LegacyPosition, Position, PositionComponent, Side, X, Y};
 use values::specified::url::SpecifiedImageUrl;
 
 /// A specified image layer.
 pub type ImageLayer = Either<None_, Image>;
 
+impl ImageLayer {
+    /// This is a specialization of Either with an alternative parse
+    /// method to provide anonymous CORS headers for the Image url fetch.
+    pub fn parse_with_cors_anonymous<'i, 't>(
+        context: &ParserContext,
+        input: &mut Parser<'i, 't>,
+    ) -> Result<Self, ParseError<'i>> {
+        if let Ok(v) = input.try(|i| None_::parse(context, i)) {
+            return Ok(Either::First(v));
+        }
+        Image::parse_with_cors_anonymous(context, input).map(Either::Second)
+    }
+}
+
 /// Specified values for an image according to CSS-IMAGES.
 /// <https://drafts.csswg.org/css-images/#image-values>
 pub type Image = generic::Image<Gradient, MozImageRect, SpecifiedImageUrl>;
 
 /// Specified values for a CSS gradient.
 /// <https://drafts.csswg.org/css-images/#gradients>
 #[cfg(not(feature = "gecko"))]
 pub type Gradient =