Skip to content

Commit 89dbbf6

Browse files
committed
Further changes required by Servo
1 parent 92a7705 commit 89dbbf6

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

components/script/stylesheet_loader.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use servo_url::{ImmutableOrigin, ServoUrl};
2222
use style::media_queries::MediaList;
2323
use style::parser::ParserContext;
2424
use style::shared_lock::{Locked, SharedRwLock};
25-
use style::stylesheets::import_rule::{ImportLayer, ImportSheet};
25+
use style::stylesheets::import_rule::{ImportLayer, ImportSheet, ImportSupportsCondition};
2626
use style::stylesheets::{
2727
CssRules, ImportRule, Origin, Stylesheet, StylesheetContents,
2828
StylesheetLoader as StyleStylesheetLoader,
@@ -361,8 +361,20 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
361361
context: &ParserContext,
362362
lock: &SharedRwLock,
363363
media: Arc<Locked<MediaList>>,
364+
supports: Option<ImportSupportsCondition>,
364365
layer: Option<ImportLayer>,
365366
) -> Arc<Locked<ImportRule>> {
367+
// Ensure the supports conditions for this @import are true, if not, refuse to load
368+
if !supports.as_ref().map_or(true, |s| s.enabled) {
369+
return Arc::new(lock.wrap(ImportRule {
370+
url,
371+
stylesheet: ImportSheet::new_refused(),
372+
supports,
373+
layer,
374+
source_location,
375+
}));
376+
}
377+
366378
let sheet = Arc::new(Stylesheet {
367379
contents: StylesheetContents::from_data(
368380
CssRules::new(Vec::new(), lock),
@@ -375,10 +387,11 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
375387
disabled: AtomicBool::new(false),
376388
});
377389

378-
let stylesheet = ImportSheet(sheet.clone());
390+
let stylesheet = ImportSheet::new(sheet.clone());
379391
let import = ImportRule {
380392
url,
381393
stylesheet,
394+
supports,
382395
layer,
383396
source_location,
384397
};

components/style/stylesheets/import_rule.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,45 @@ impl DeepCloneWithLock for ImportSheet {
107107
/// A sheet that is held from an import rule.
108108
#[cfg(feature = "servo")]
109109
#[derive(Debug)]
110-
pub struct ImportSheet(pub ::servo_arc::Arc<crate::stylesheets::Stylesheet>);
110+
pub enum ImportSheet {
111+
/// A bonafide stylesheet.
112+
Sheet(::servo_arc::Arc<crate::stylesheets::Stylesheet>),
113+
114+
/// An @import created with a false <supports-condition>, so will never be fetched.
115+
Refused,
116+
}
111117

112118
#[cfg(feature = "servo")]
113119
impl ImportSheet {
120+
/// Creates a new ImportSheet from a stylesheet.
121+
pub fn new(sheet: ::servo_arc::Arc<crate::stylesheets::Stylesheet>) -> Self {
122+
ImportSheet::Sheet(sheet)
123+
}
124+
125+
/// Creates a refused ImportSheet for a load that will not happen.
126+
pub fn new_refused() -> Self {
127+
ImportSheet::Refused
128+
}
129+
130+
/// Returns a reference to the stylesheet in this ImportSheet, if it exists.
131+
pub fn as_sheet(&self) -> Option<&::servo_arc::Arc<crate::stylesheets::Stylesheet>> {
132+
match *self {
133+
ImportSheet::Sheet(ref s) => Some(s),
134+
ImportSheet::Refused => None,
135+
}
136+
}
137+
114138
/// Returns the media list for this import rule.
115139
pub fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> {
116-
self.0.media(guard)
140+
self.as_sheet().and_then(|s| s.media(guard))
117141
}
118142

119143
/// Returns the rules for this import rule.
120144
pub fn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a [CssRule] {
121-
self.0.rules(guard)
145+
match self.as_sheet() {
146+
Some(s) => s.rules(guard),
147+
None => &[],
148+
}
122149
}
123150
}
124151

@@ -130,9 +157,13 @@ impl DeepCloneWithLock for ImportSheet {
130157
_guard: &SharedRwLockReadGuard,
131158
_params: &DeepCloneParams,
132159
) -> Self {
133-
use servo_arc::Arc;
134-
135-
ImportSheet(Arc::new((&*self.0).clone()))
160+
match *self {
161+
ImportSheet::Sheet(ref s) => {
162+
use servo_arc::Arc;
163+
ImportSheet::Sheet(Arc::new((&**s).clone()))
164+
},
165+
ImportSheet::Refused => ImportSheet::Refused,
166+
}
136167
}
137168
}
138169

components/style/stylesheets/rule_parser.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
241241
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
242242
let url = CssUrl::parse_from_string(url_string, &self.context, CorsMode::None);
243243

244-
let supports = if !static_prefs::pref!("layout.css.import-supports.enabled") {
244+
#[cfg(feature = "gecko")]
245+
let supports_enabled = static_prefs::pref!("layout.css.import-supports.enabled");
246+
#[cfg(feature = "servo")]
247+
let supports_enabled = false;
248+
249+
let supports = if !supports_enabled {
245250
None
246251
} else {
247252
input.try_parse(SupportsCondition::parse_for_import).map(|condition| {

0 commit comments

Comments
 (0)