summaryrefslogtreecommitdiffstats
path: root/dom/base/nsContentUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/nsContentUtils.cpp')
-rw-r--r--dom/base/nsContentUtils.cpp172
1 files changed, 94 insertions, 78 deletions
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 800f40fa1..b6cbbbace 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -227,6 +227,7 @@ extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
int ns_aware, const char** colon);
class imgLoader;
+class nsIAtom;
using namespace mozilla::dom;
using namespace mozilla::ipc;
@@ -258,7 +259,6 @@ nsIWordBreaker *nsContentUtils::sWordBreaker;
nsIBidiKeyboard *nsContentUtils::sBidiKeyboard = nullptr;
uint32_t nsContentUtils::sScriptBlockerCount = 0;
uint32_t nsContentUtils::sDOMNodeRemovedSuppressCount = 0;
-uint32_t nsContentUtils::sMicroTaskLevel = 0;
AutoTArray<nsCOMPtr<nsIRunnable>, 8>* nsContentUtils::sBlockedScriptRunners = nullptr;
uint32_t nsContentUtils::sRunnersCountAtFirstBlocker = 0;
nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nullptr;
@@ -284,6 +284,8 @@ bool nsContentUtils::sIsResourceTimingEnabled = false;
bool nsContentUtils::sIsPerformanceNavigationTimingEnabled = false;
bool nsContentUtils::sIsUserTimingLoggingEnabled = false;
bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false;
+bool nsContentUtils::sIsWebComponentsEnabled = false;
+bool nsContentUtils::sIsCustomElementsEnabled = false;
bool nsContentUtils::sEncodeDecodeURLHash = false;
bool nsContentUtils::sGettersDecodeURLHash = false;
bool nsContentUtils::sPrivacyResistFingerprinting = false;
@@ -584,6 +586,12 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sIsExperimentalAutocompleteEnabled,
"dom.forms.autocomplete.experimental", false);
+ Preferences::AddBoolVarCache(&sIsWebComponentsEnabled,
+ "dom.webcomponents.enabled", false);
+
+ Preferences::AddBoolVarCache(&sIsCustomElementsEnabled,
+ "dom.webcomponents.customelements.enabled", false);
+
Preferences::AddBoolVarCache(&sEncodeDecodeURLHash,
"dom.url.encode_decode_hash", false);
@@ -5293,51 +5301,6 @@ nsContentUtils::RunInMetastableState(already_AddRefed<nsIRunnable> aRunnable)
CycleCollectedJSContext::Get()->RunInMetastableState(Move(aRunnable));
}
-void
-nsContentUtils::EnterMicroTask()
-{
- MOZ_ASSERT(NS_IsMainThread());
- ++sMicroTaskLevel;
-}
-
-void
-nsContentUtils::LeaveMicroTask()
-{
- MOZ_ASSERT(NS_IsMainThread());
- if (--sMicroTaskLevel == 0) {
- PerformMainThreadMicroTaskCheckpoint();
- }
-}
-
-bool
-nsContentUtils::IsInMicroTask()
-{
- MOZ_ASSERT(NS_IsMainThread());
- return sMicroTaskLevel != 0;
-}
-
-uint32_t
-nsContentUtils::MicroTaskLevel()
-{
- MOZ_ASSERT(NS_IsMainThread());
- return sMicroTaskLevel;
-}
-
-void
-nsContentUtils::SetMicroTaskLevel(uint32_t aLevel)
-{
- MOZ_ASSERT(NS_IsMainThread());
- sMicroTaskLevel = aLevel;
-}
-
-void
-nsContentUtils::PerformMainThreadMicroTaskCheckpoint()
-{
- MOZ_ASSERT(NS_IsMainThread());
-
- nsDOMMutationObserver::HandleMutations();
-}
-
/*
* Helper function for nsContentUtils::ProcessViewportInfo.
*
@@ -9567,11 +9530,34 @@ nsContentUtils::HttpsStateIsModern(nsIDocument* aDocument)
return false;
}
+/* static */ void
+nsContentUtils::TryToUpgradeElement(Element* aElement)
+{
+ NodeInfo* nodeInfo = aElement->NodeInfo();
+ RefPtr<nsIAtom> typeAtom =
+ aElement->GetCustomElementData()->GetCustomElementType();
+
+ MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
+ CustomElementDefinition* definition =
+ nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
+ nodeInfo->NameAtom(),
+ nodeInfo->NamespaceID(),
+ typeAtom);
+ if (definition) {
+ nsContentUtils::EnqueueUpgradeReaction(aElement, definition);
+ } else {
+ // Add an unresolved custom element that is a candidate for
+ // upgrade when a custom element is connected to the document.
+ // We will make sure it's shadow-including tree order in bug 1326028.
+ nsContentUtils::RegisterUnresolvedElement(aElement, typeAtom);
+ }
+}
+
/* static */ CustomElementDefinition*
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
- const nsAString& aLocalName,
+ nsIAtom* aNameAtom,
uint32_t aNameSpaceID,
- const nsAString* aIs)
+ nsIAtom* aTypeAtom)
{
MOZ_ASSERT(aDoc);
@@ -9593,30 +9579,37 @@ nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
return nullptr;
}
- return registry->LookupCustomElementDefinition(aLocalName, aIs);
+ return registry->LookupCustomElementDefinition(aNameAtom, aTypeAtom);
}
/* static */ void
-nsContentUtils::SetupCustomElement(Element* aElement,
- const nsAString* aTypeExtension)
+nsContentUtils::RegisterUnresolvedElement(Element* aElement, nsIAtom* aTypeName)
{
MOZ_ASSERT(aElement);
- nsCOMPtr<nsIDocument> doc = aElement->OwnerDoc();
-
- if (!doc) {
+ nsIDocument* doc = aElement->OwnerDoc();
+ nsPIDOMWindowInner* window(doc->GetInnerWindow());
+ if (!window) {
return;
}
- // To support imported document.
- doc = doc->MasterDocument();
-
- if (aElement->GetNameSpaceID() != kNameSpaceID_XHTML ||
- !doc->GetDocShell()) {
+ RefPtr<CustomElementRegistry> registry(window->CustomElements());
+ if (!registry) {
return;
}
- nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
+ registry->RegisterUnresolvedElement(aElement, aTypeName);
+}
+
+/* static */ void
+nsContentUtils::UnregisterUnresolvedElement(Element* aElement)
+{
+ MOZ_ASSERT(aElement);
+
+ RefPtr<nsIAtom> typeAtom =
+ aElement->GetCustomElementData()->GetCustomElementType();
+ nsIDocument* doc = aElement->OwnerDoc();
+ nsPIDOMWindowInner* window(doc->GetInnerWindow());
if (!window) {
return;
}
@@ -9626,36 +9619,59 @@ nsContentUtils::SetupCustomElement(Element* aElement,
return;
}
- return registry->SetupCustomElement(aElement, aTypeExtension);
+ registry->UnregisterUnresolvedElement(aElement, typeAtom);
+}
+
+/* static */ CustomElementDefinition*
+nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement,
+ nsIAtom* aExtensionType,
+ nsIAtom* aAttrName)
+{
+ CustomElementDefinition* definition =
+ aCustomElement->GetCustomElementDefinition();
+
+ // Custom element not defined yet or attribute is not in the observed
+ // attribute list.
+ if (!definition || !definition->IsInObservedAttributeList(aAttrName)) {
+ return nullptr;
+ }
+
+ return definition;
}
/* static */ void
-nsContentUtils::EnqueueLifecycleCallback(nsIDocument* aDoc,
- nsIDocument::ElementCallbackType aType,
- Element* aCustomElement,
- LifecycleCallbackArgs* aArgs,
- CustomElementDefinition* aDefinition)
+nsContentUtils::EnqueueUpgradeReaction(Element* aElement,
+ CustomElementDefinition* aDefinition)
{
- MOZ_ASSERT(aDoc);
+ MOZ_ASSERT(aElement);
- // To support imported document.
- nsCOMPtr<nsIDocument> doc = aDoc->MasterDocument();
+ nsIDocument* doc = aElement->OwnerDoc();
- if (!doc->GetDocShell()) {
+ // No DocGroup means no custom element reactions stack.
+ if (!doc->GetDocGroup()) {
return;
}
- nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
- if (!window) {
- return;
- }
+ CustomElementReactionsStack* stack =
+ doc->GetDocGroup()->CustomElementReactionsStack();
+ stack->EnqueueUpgradeReaction(aElement, aDefinition);
+}
- RefPtr<CustomElementRegistry> registry(window->CustomElements());
- if (!registry) {
+/* static */ void
+nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
+ Element* aCustomElement,
+ LifecycleCallbackArgs* aArgs,
+ LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
+ CustomElementDefinition* aDefinition)
+{
+ // No DocGroup means no custom element reactions stack.
+ if (!aCustomElement->OwnerDoc()->GetDocGroup()) {
return;
}
- registry->EnqueueLifecycleCallback(aType, aCustomElement, aArgs, aDefinition);
+ CustomElementRegistry::EnqueueLifecycleCallback(aType, aCustomElement, aArgs,
+ aAdoptedCallbackArgs,
+ aDefinition);
}
/* static */ void
@@ -9834,4 +9850,4 @@ nsContentUtils::IsLocalRefURL(const nsString& aString)
}
return false;
-} \ No newline at end of file
+}