From 9bb4033ec3f52fb5a17b9cd7a5b2f157b895d7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 16 Mar 2018 18:50:16 +0100 Subject: [PATCH] style: Allow @-moz-document url-prefix() on content. MozReview-Commit-ID: zaT41fpsDT Bug: 1446470 Reviewed-by: xidorn --- components/style/stylesheets/document_rule.rs | 47 +++++++++++++++++-- components/style/stylesheets/rule_parser.rs | 13 ----- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 089fa2c6799..596ea487510 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -15,7 +15,7 @@ use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::{CssWriter, ParseError, ToCss}; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use stylesheets::CssRules; use values::CssUrl; @@ -186,8 +186,17 @@ impl DocumentCondition { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - input.parse_comma_separated(|input| UrlMatchingFunction::parse(context, input)) - .map(DocumentCondition) + let conditions = input.parse_comma_separated(|input| { + UrlMatchingFunction::parse(context, input) + })?; + + let condition = DocumentCondition(conditions); + if !condition.allowed_in(context) { + return Err(input.new_custom_error( + StyleParseErrorKind::UnsupportedAtRule("-moz-document".into()) + )) + } + Ok(condition) } /// Evaluate a document condition. @@ -196,4 +205,36 @@ impl DocumentCondition { url_matching_function.evaluate(device) }) } + + #[cfg(feature = "servo")] + fn allowed_in(&self, _: &ParserContext) -> bool { + false + } + + #[cfg(feature = "gecko")] + fn allowed_in(&self, context: &ParserContext) -> bool { + use gecko_bindings::structs; + use stylesheets::Origin; + + if context.stylesheet_origin != Origin::Author { + return true; + } + + if unsafe { structs::StylePrefs_sMozDocumentEnabledInContent } { + return true; + } + + // Allow a single url-prefix() for compatibility. + // + // See bug 1446470 and dependencies. + if self.0.len() != 1 { + return false; + } + + // NOTE(emilio): This technically allows url-prefix("") too, but... + match self.0[0] { + UrlMatchingFunction::UrlPrefix(ref prefix) => prefix.is_empty(), + _ => false + } + } } diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 5bc3fb8f050..714a0730882 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -422,19 +422,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a )) } - #[cfg(feature = "gecko")] - { - use gecko_bindings::structs; - - if self.stylesheet_origin == Origin::Author && - unsafe { !structs::StylePrefs_sMozDocumentEnabledInContent } - { - return Err(input.new_custom_error( - StyleParseErrorKind::UnsupportedAtRule(name.clone()) - )) - } - } - let cond = DocumentCondition::parse(self.context, input)?; Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Document(cond, location))) },