Bug 1334043 - Part 2: Make nsContentUtils::EnqueueLifecycleCallback static.

We make nsContentUtils::EnqueueLifecycleCallback static so that it can be called without a window object. To achive this, we also make CustomElementReaction not taking a CustomElementRegistry in the constructor, as it can call Upgrade statically.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-05 15:59:26 -05:00 committed by Roy Tam
commit befa1027e3
5 changed files with 41 additions and 75 deletions

View file

@ -9661,48 +9661,30 @@ nsContentUtils::EnqueueUpgradeReaction(Element* aElement,
MOZ_ASSERT(aElement);
nsIDocument* doc = aElement->OwnerDoc();
nsPIDOMWindowInner* window(doc->GetInnerWindow());
if (!window) {
return;
}
RefPtr<CustomElementRegistry> registry(window->CustomElements());
if (!registry) {
// No DocGroup means no custom element reactions stack.
if (!doc->GetDocGroup()) {
return;
}
CustomElementReactionsStack* stack =
doc->GetDocGroup()->CustomElementReactionsStack();
stack->EnqueueUpgradeReaction(registry, aElement, aDefinition);
stack->EnqueueUpgradeReaction(aElement, aDefinition);
}
/* static */ void
nsContentUtils::EnqueueLifecycleCallback(nsIDocument* aDoc,
nsIDocument::ElementCallbackType aType,
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
Element* aCustomElement,
LifecycleCallbackArgs* aArgs,
CustomElementDefinition* aDefinition)
{
MOZ_ASSERT(aDoc);
// To support imported document.
nsCOMPtr<nsIDocument> doc = aDoc->MasterDocument();
if (!doc->GetDocShell()) {
// No DocGroup means no custom element reactions stack.
if (!aCustomElement->OwnerDoc()->GetDocGroup()) {
return;
}
nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
if (!window) {
return;
}
RefPtr<CustomElementRegistry> registry(window->CustomElements());
if (!registry) {
return;
}
registry->EnqueueLifecycleCallback(aType, aCustomElement, aArgs, aDefinition);
CustomElementRegistry::EnqueueLifecycleCallback(aType, aCustomElement, aArgs,
aDefinition);
}
/* static */ void