From b0706d5cf04f6a8704185e0f1825cc50cae2f998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 2 Oct 2017 19:40:18 +0200 Subject: [PATCH] stylo: Add a mechanism to restrict media-features to UA and chrome sheets. Reviewed-by: xidorn Bug: 1396066 MozReview-Commit-ID: 38jRV6mPbE3 --- components/style/gecko/media_queries.rs | 13 +++++++++++-- components/style/parser.rs | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index ca967a866c0..e0be4e7423f 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -32,6 +32,7 @@ use string_cache::Atom; use style_traits::{CSSPixel, DevicePixel}; use style_traits::{ToCss, ParseError, StyleParseError}; use style_traits::viewport::ViewportConstraints; +use stylesheets::Origin; use values::{CSSFloat, CustomIdent, serialize_dimension}; use values::computed::{self, ToComputedValue}; use values::specified::Length; @@ -584,8 +585,10 @@ impl Expression { /// ``` /// (media-feature: media-value) /// ``` - pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { + pub fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { input.expect_parenthesis_block().map_err(|err| match err { BasicParseError::UnexpectedToken(t) => StyleParseError::ExpectedIdentifier(t), @@ -606,6 +609,12 @@ impl Expression { )?; let mut flags = 0; + + if context.in_chrome_stylesheet() || + context.stylesheet_origin == Origin::UserAgent { + flags |= nsMediaFeature_RequirementFlags::eUserAgentAndChromeOnly as u8; + } + let result = { let mut feature_name = &**ident; diff --git a/components/style/parser.rs b/components/style/parser.rs index 20ea720f613..6e08d937b76 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -130,6 +130,11 @@ impl<'a> ParserContext<'a> { }; context.error_reporter.report_error(self.url_data, location, error) } + + /// Returns whether this is a chrome stylesheets. + pub fn in_chrome_stylesheet(&self) -> bool { + self.url_data.is_chrome() + } } // XXXManishearth Replace all specified value parse impls with impls of this