Issue #2135 - Bug 1410578: Make <link rel="stylesheet"> work in shadow trees

This commit is contained in:
FranklinDM 2023-03-04 00:53:46 +08:00 committed by roytam1
commit 588c2154a5
4 changed files with 21 additions and 49 deletions

View file

@ -162,7 +162,8 @@ HTMLLinkElement::HasDeferredDNSPrefetchRequest()
}
nsresult
HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
HTMLLinkElement::BindToTree(nsIDocument* aDocument,
nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
@ -173,12 +174,8 @@ HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
// Link must be inert in ShadowRoot.
if (aDocument && !GetContainingShadow()) {
aDocument->RegisterPendingLinkUpdate(this);
}
if (IsInComposedDoc()) {
if (nsIDocument* doc = GetComposedDoc()) {
doc->RegisterPendingLinkUpdate(this);
TryDNSPrefetchPreconnectOrPrefetch();
}
@ -222,11 +219,7 @@ HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent)
// If this is reinserted back into the document it will not be
// from the parser.
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
// Check for a ShadowRoot because link elements are inert in a
// ShadowRoot.
ShadowRoot* oldShadowRoot = GetBindingParent() ?
GetBindingParent()->GetShadowRoot() : nullptr;
ShadowRoot* oldShadowRoot = GetContainingShadow();
OwnerDoc()->UnregisterPendingLinkUpdate(this);