diff options
Diffstat (limited to 'components/script/stylesheet_loader.rs')
-rw-r--r-- | components/script/stylesheet_loader.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index 61c89b35f80..69975c7803b 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -13,8 +13,9 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::htmlelement::HTMLElement; use crate::dom::htmllinkelement::{HTMLLinkElement, RequestGenerationId}; -use crate::dom::node::{document_from_node, window_from_node}; +use crate::dom::node::{containing_shadow_root, document_from_node, window_from_node}; use crate::dom::performanceresourcetiming::InitiatorType; +use crate::dom::shadowroot::ShadowRoot; use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener}; use cssparser::SourceLocation; use encoding_rs::UTF_8; @@ -81,6 +82,7 @@ pub struct StylesheetContext { data: Vec<u8>, /// The node document for elem when the load was initiated. document: Trusted<Document>, + shadow_root: Option<Trusted<ShadowRoot>>, origin_clean: bool, /// A token which must match the generation id of the `HTMLLinkElement` for it to load the stylesheet. /// This is ignored for `HTMLStyleElement` and imports. @@ -187,7 +189,11 @@ impl FetchResponseListener for StylesheetContext { }, } - document.invalidate_stylesheets(); + if let Some(ref shadow_root) = self.shadow_root { + shadow_root.root().invalidate_stylesheets(); + } else { + document.invalidate_stylesheets(); + } // FIXME: Revisit once consensus is reached at: // https://github.com/whatwg/html/issues/1142 @@ -264,6 +270,7 @@ impl<'a> StylesheetLoader<'a> { integrity_metadata: String, ) { let document = document_from_node(self.elem); + let shadow_root = containing_shadow_root(self.elem).map(|sr| Trusted::new(&*sr)); let gen = self .elem .downcast::<HTMLLinkElement>() @@ -275,6 +282,7 @@ impl<'a> StylesheetLoader<'a> { metadata: None, data: vec![], document: Trusted::new(&*document), + shadow_root, origin_clean: true, request_generation_id: gen, resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource), |