diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index d045f4b52df..ab5b643f9b9 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -22,7 +22,7 @@ use servo_url::{ImmutableOrigin, ServoUrl}; use style::media_queries::MediaList; use style::parser::ParserContext; use style::shared_lock::{Locked, SharedRwLock}; -use style::stylesheets::import_rule::{ImportLayer, ImportSheet}; +use style::stylesheets::import_rule::{ImportLayer, ImportSheet, ImportSupportsCondition}; use style::stylesheets::{ CssRules, ImportRule, Origin, Stylesheet, StylesheetContents, StylesheetLoader as StyleStylesheetLoader, @@ -361,8 +361,20 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> { context: &ParserContext, lock: &SharedRwLock, media: Arc>, + supports: Option, layer: Option, ) -> Arc> { + // Ensure the supports conditions for this @import are true, if not, refuse to load + if !supports.as_ref().map_or(true, |s| s.enabled) { + return Arc::new(lock.wrap(ImportRule { + url, + stylesheet: ImportSheet::new_refused(), + supports, + layer, + source_location, + })); + } + let sheet = Arc::new(Stylesheet { contents: StylesheetContents::from_data( CssRules::new(Vec::new(), lock), @@ -375,10 +387,11 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> { disabled: AtomicBool::new(false), }); - let stylesheet = ImportSheet(sheet.clone()); + let stylesheet = ImportSheet::new(sheet.clone()); let import = ImportRule { url, stylesheet, + supports, layer, source_location, }; diff --git a/components/style/stylesheets/import_rule.rs b/components/style/stylesheets/import_rule.rs index 03440e31927..76a202b1985 100644 --- a/components/style/stylesheets/import_rule.rs +++ b/components/style/stylesheets/import_rule.rs @@ -107,18 +107,45 @@ impl DeepCloneWithLock for ImportSheet { /// A sheet that is held from an import rule. #[cfg(feature = "servo")] #[derive(Debug)] -pub struct ImportSheet(pub ::servo_arc::Arc); +pub enum ImportSheet { + /// A bonafide stylesheet. + Sheet(::servo_arc::Arc), + + /// An @import created with a false , so will never be fetched. + Refused, +} #[cfg(feature = "servo")] impl ImportSheet { + /// Creates a new ImportSheet from a stylesheet. + pub fn new(sheet: ::servo_arc::Arc) -> Self { + ImportSheet::Sheet(sheet) + } + + /// Creates a refused ImportSheet for a load that will not happen. + pub fn new_refused() -> Self { + ImportSheet::Refused + } + + /// Returns a reference to the stylesheet in this ImportSheet, if it exists. + pub fn as_sheet(&self) -> Option<&::servo_arc::Arc> { + match *self { + ImportSheet::Sheet(ref s) => Some(s), + ImportSheet::Refused => None, + } + } + /// Returns the media list for this import rule. pub fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> { - self.0.media(guard) + self.as_sheet().and_then(|s| s.media(guard)) } /// Returns the rules for this import rule. pub fn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a [CssRule] { - self.0.rules(guard) + match self.as_sheet() { + Some(s) => s.rules(guard), + None => &[], + } } } @@ -130,9 +157,13 @@ impl DeepCloneWithLock for ImportSheet { _guard: &SharedRwLockReadGuard, _params: &DeepCloneParams, ) -> Self { - use servo_arc::Arc; - - ImportSheet(Arc::new((&*self.0).clone())) + match *self { + ImportSheet::Sheet(ref s) => { + use servo_arc::Arc; + ImportSheet::Sheet(Arc::new((&**s).clone())) + }, + ImportSheet::Refused => ImportSheet::Refused, + } } } diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 894861b3099..804d0d688e2 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -241,7 +241,12 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { let url_string = input.expect_url_or_string()?.as_ref().to_owned(); let url = CssUrl::parse_from_string(url_string, &self.context, CorsMode::None); - let supports = if !static_prefs::pref!("layout.css.import-supports.enabled") { + #[cfg(feature = "gecko")] + let supports_enabled = static_prefs::pref!("layout.css.import-supports.enabled"); + #[cfg(feature = "servo")] + let supports_enabled = false; + + let supports = if !supports_enabled { None } else { input.try_parse(SupportsCondition::parse_for_import).map(|condition| {