commit e5997cb83e2b7bd7a197a97c557ea8ad36bfeeea
parent 19e3473912a0e6d9816eff46ea12f95231670751
Author: Narcis Beleuzu <nbeleuzu@mozilla.com>
Date: Sun, 12 Oct 2025 04:51:00 +0300
Revert "Bug 1993821 - Refactor imported stylesheets for Servo. r=firefox-style-system-reviewers,emilio" for causing bustages on loader.rs
This reverts commit 19e3473912a0e6d9816eff46ea12f95231670751.
Diffstat:
5 files changed, 97 insertions(+), 21 deletions(-)
diff --git a/servo/components/style/servo/encoding_support.rs b/servo/components/style/servo/encoding_support.rs
@@ -7,7 +7,7 @@
use crate::context::QuirksMode;
use crate::error_reporting::ParseErrorReporter;
use crate::media_queries::MediaList;
-use crate::shared_lock::{Locked, SharedRwLock};
+use crate::shared_lock::SharedRwLock;
use crate::stylesheets::{AllowImportRules, Origin, Stylesheet, StylesheetLoader, UrlExtraData};
use cssparser::{stylesheet_encoding, EncodingSupport};
use servo_arc::Arc;
@@ -59,7 +59,7 @@ impl Stylesheet {
protocol_encoding_label: Option<&str>,
environment_encoding: Option<&'static encoding_rs::Encoding>,
origin: Origin,
- media: Arc<Locked<MediaList>>,
+ media: MediaList,
shared_lock: SharedRwLock,
stylesheet_loader: Option<&dyn StylesheetLoader>,
error_reporter: Option<&dyn ParseErrorReporter>,
@@ -70,7 +70,7 @@ impl Stylesheet {
&string,
url_data,
origin,
- media,
+ Arc::new(shared_lock.wrap(media)),
shared_lock,
stylesheet_loader,
error_reporter,
@@ -78,4 +78,26 @@ impl Stylesheet {
AllowImportRules::Yes,
)
}
+
+ /// Updates an empty stylesheet with a set of bytes that reached over the
+ /// network.
+ pub fn update_from_bytes(
+ existing: &Stylesheet,
+ bytes: &[u8],
+ protocol_encoding_label: Option<&str>,
+ environment_encoding: Option<&'static encoding_rs::Encoding>,
+ url_data: UrlExtraData,
+ stylesheet_loader: Option<&dyn StylesheetLoader>,
+ error_reporter: Option<&dyn ParseErrorReporter>,
+ ) {
+ let string = decode_stylesheet_bytes(bytes, protocol_encoding_label, environment_encoding);
+ Self::update_from_str(
+ existing,
+ &string,
+ url_data,
+ stylesheet_loader,
+ error_reporter,
+ AllowImportRules::Yes,
+ )
+ }
}
diff --git a/servo/components/style/stylesheets/import_rule.rs b/servo/components/style/stylesheets/import_rule.rs
@@ -19,16 +19,12 @@ use std::fmt::{self, Write};
use style_traits::{CssStringWriter, CssWriter, ToCss};
use to_shmem::{SharedMemoryBuilder, ToShmem};
-#[cfg(feature = "gecko")]
-type StyleSheet = crate::gecko::data::GeckoStyleSheet;
-#[cfg(feature = "servo")]
-type StyleSheet = ::servo_arc::Arc<crate::stylesheets::Stylesheet>;
-
/// A sheet that is held from an import rule.
+#[cfg(feature = "gecko")]
#[derive(Debug)]
pub enum ImportSheet {
/// A bonafide stylesheet.
- Sheet(StyleSheet),
+ Sheet(crate::gecko::data::GeckoStyleSheet),
/// An @import created while parsing off-main-thread, whose Gecko sheet has
/// yet to be created and attached.
@@ -38,9 +34,10 @@ pub enum ImportSheet {
Refused,
}
+#[cfg(feature = "gecko")]
impl ImportSheet {
- /// Creates a new ImportSheet from a stylesheet.
- pub fn new(sheet: StyleSheet) -> Self {
+ /// Creates a new ImportSheet from a GeckoStyleSheet.
+ pub fn new(sheet: crate::gecko::data::GeckoStyleSheet) -> Self {
ImportSheet::Sheet(sheet)
}
@@ -54,10 +51,10 @@ impl ImportSheet {
ImportSheet::Refused
}
- /// Returns a reference to the stylesheet in this ImportSheet, if it exists.
- pub fn as_sheet(&self) -> Option<&StyleSheet> {
+ /// Returns a reference to the GeckoStyleSheet in this ImportSheet, if it
+ /// exists.
+ pub fn as_sheet(&self) -> Option<&crate::gecko::data::GeckoStyleSheet> {
match *self {
- #[cfg(feature = "gecko")]
ImportSheet::Sheet(ref s) => {
debug_assert!(!s.hack_is_null());
if s.hack_is_null() {
@@ -65,8 +62,6 @@ impl ImportSheet {
}
Some(s)
},
- #[cfg(feature = "servo")]
- ImportSheet::Sheet(ref s) => Some(s),
ImportSheet::Refused | ImportSheet::Pending => None,
}
}
@@ -85,21 +80,75 @@ impl ImportSheet {
}
}
+#[cfg(feature = "gecko")]
impl DeepCloneWithLock for ImportSheet {
fn deep_clone_with_lock(&self, _lock: &SharedRwLock, _guard: &SharedRwLockReadGuard) -> Self {
+ use crate::gecko::data::GeckoStyleSheet;
+ use crate::gecko_bindings::bindings;
match *self {
- #[cfg(feature = "gecko")]
ImportSheet::Sheet(ref s) => {
- use crate::gecko_bindings::bindings;
let clone = unsafe { bindings::Gecko_StyleSheet_Clone(s.raw() as *const _) };
- ImportSheet::Sheet(unsafe { StyleSheet::from_addrefed(clone) })
+ ImportSheet::Sheet(unsafe { GeckoStyleSheet::from_addrefed(clone) })
},
- #[cfg(feature = "servo")]
+ ImportSheet::Pending => ImportSheet::Pending,
+ ImportSheet::Refused => ImportSheet::Refused,
+ }
+ }
+}
+
+/// A sheet that is held from an import rule.
+#[cfg(feature = "servo")]
+#[derive(Debug)]
+pub enum ImportSheet {
+ /// A bonafide stylesheet.
+ Sheet(::servo_arc::Arc<crate::stylesheets::Stylesheet>),
+
+ /// An @import created with a false <supports-condition>, 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<crate::stylesheets::Stylesheet>) -> 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<crate::stylesheets::Stylesheet>> {
+ 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.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] {
+ match self.as_sheet() {
+ Some(s) => s.rules(guard),
+ None => &[],
+ }
+ }
+}
+
+#[cfg(feature = "servo")]
+impl DeepCloneWithLock for ImportSheet {
+ fn deep_clone_with_lock(&self, _lock: &SharedRwLock, _guard: &SharedRwLockReadGuard) -> Self {
+ match *self {
ImportSheet::Sheet(ref s) => {
use servo_arc::Arc;
ImportSheet::Sheet(Arc::new((&**s).clone()))
},
- ImportSheet::Pending => ImportSheet::Pending,
ImportSheet::Refused => ImportSheet::Refused,
}
}
diff --git a/servo/components/style/stylesheets/loader.rs b/servo/components/style/stylesheets/loader.rs
@@ -6,6 +6,7 @@
//! for `@import` rules.
use crate::media_queries::MediaList;
+use crate::parser::ParserContext;
use crate::shared_lock::{Locked, SharedRwLock};
use crate::stylesheets::import_rule::{ImportLayer, ImportRule, ImportSupportsCondition};
use crate::values::CssUrl;
@@ -21,6 +22,7 @@ pub trait StylesheetLoader {
&self,
url: CssUrl,
location: SourceLocation,
+ context: &ParserContext,
lock: &SharedRwLock,
media: Arc<Locked<MediaList>>,
supports: Option<ImportSupportsCondition>,
diff --git a/servo/components/style/stylesheets/rule_parser.rs b/servo/components/style/stylesheets/rule_parser.rs
@@ -424,6 +424,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a, 'i> {
let import_rule = loader.request_stylesheet(
url,
start.source_location(),
+ &self.context,
&self.shared_lock,
media,
supports,
diff --git a/servo/ports/geckolib/stylesheet_loader.rs b/servo/ports/geckolib/stylesheet_loader.rs
@@ -47,6 +47,7 @@ impl StyleStylesheetLoader for StylesheetLoader {
&self,
url: CssUrl,
source_location: SourceLocation,
+ _context: &ParserContext,
lock: &SharedRwLock,
media: Arc<Locked<MediaList>>,
supports: Option<ImportSupportsCondition>,
@@ -144,6 +145,7 @@ impl StyleStylesheetLoader for AsyncStylesheetParser {
&self,
url: CssUrl,
source_location: SourceLocation,
+ _context: &ParserContext,
lock: &SharedRwLock,
media: Arc<Locked<MediaList>>,
supports: Option<ImportSupportsCondition>,