From a9290ef91ec408fa7886b99cc59be40b413a0ce0 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 21 Jan 2020 20:00:48 -0500 Subject: Issue #1366 - Completely remove showModalDialog --- dom/html/test/file_iframe_sandbox_c_if4.html | 11 +-- dom/html/test/file_iframe_sandbox_j_if1.html | 30 ------ dom/html/test/file_iframe_sandbox_j_if2.html | 28 ------ dom/html/test/file_iframe_sandbox_j_if3.html | 27 ------ dom/html/test/mochitest.ini | 10 +- dom/html/test/test_bug391777.html | 25 ----- dom/html/test/test_iframe_sandbox_general.html | 2 +- dom/html/test/test_iframe_sandbox_modal.html | 122 ------------------------- 8 files changed, 3 insertions(+), 252 deletions(-) delete mode 100644 dom/html/test/file_iframe_sandbox_j_if1.html delete mode 100644 dom/html/test/file_iframe_sandbox_j_if2.html delete mode 100644 dom/html/test/file_iframe_sandbox_j_if3.html delete mode 100644 dom/html/test/test_bug391777.html delete mode 100644 dom/html/test/test_iframe_sandbox_modal.html (limited to 'dom/html') diff --git a/dom/html/test/file_iframe_sandbox_c_if4.html b/dom/html/test/file_iframe_sandbox_c_if4.html index 53bf49559..828592d63 100644 --- a/dom/html/test/file_iframe_sandbox_c_if4.html +++ b/dom/html/test/file_iframe_sandbox_c_if4.html @@ -12,7 +12,7 @@ } function doStuff() { - // try to open a new window via target="_blank", target="BC341604", window.open(), and showModalDialog() + // try to open a new window via target="_blank", target="BC341604", and window.open() // the window we try to open closes itself once it opens sendMouseEvent({type:'click'}, 'target_blank'); sendMouseEvent({type:'click'}, 'target_BC341604'); @@ -25,15 +25,6 @@ } ok(threw, "window.open threw a JS exception and was not allowed"); - - threw = false; - try { - window.showModalDialog("about:blank"); - } catch(error) { - threw = true; - } - - ok(threw, "window.showModalDialog threw a JS exception and was not allowed"); } diff --git a/dom/html/test/file_iframe_sandbox_j_if1.html b/dom/html/test/file_iframe_sandbox_j_if1.html deleted file mode 100644 index 6d4347dfc..000000000 --- a/dom/html/test/file_iframe_sandbox_j_if1.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - Test for Bug 766282 - - - - - - - I am sandboxed with "allow-scripts allow-popups allow-same-origin allow-forms allow-top-navigation". - - diff --git a/dom/html/test/file_iframe_sandbox_j_if2.html b/dom/html/test/file_iframe_sandbox_j_if2.html deleted file mode 100644 index 9552307ee..000000000 --- a/dom/html/test/file_iframe_sandbox_j_if2.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Test for Bug 766282 - - - - - - - I am sandboxed but with "allow-scripts allow-popups allow-same-origin". - After my initial load, "allow-same-origin" is removed and then I open file_iframe_sandbox_k_if9.html, - which attemps to call a function in my parent. - This should succeed since the new sandbox flags shouldn't have taken affect on me until I'm reloaded. - - diff --git a/dom/html/test/file_iframe_sandbox_j_if3.html b/dom/html/test/file_iframe_sandbox_j_if3.html deleted file mode 100644 index 07c5b66c1..000000000 --- a/dom/html/test/file_iframe_sandbox_j_if3.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Tests for Bug 766282 - - - - - - I am sandboxed but with "allow-popups allow-scripts allow-same-origin" - - diff --git a/dom/html/test/mochitest.ini b/dom/html/test/mochitest.ini index 024de1cd9..4a50a9c3f 100644 --- a/dom/html/test/mochitest.ini +++ b/dom/html/test/mochitest.ini @@ -154,9 +154,6 @@ support-files = file_iframe_sandbox_form_pass.html file_iframe_sandbox_g_if1.html file_iframe_sandbox_h_if1.html - file_iframe_sandbox_j_if1.html - file_iframe_sandbox_j_if2.html - file_iframe_sandbox_j_if3.html file_iframe_sandbox_k_if1.html file_iframe_sandbox_k_if2.html file_iframe_sandbox_k_if3.html @@ -471,9 +468,6 @@ skip-if = toolkit == 'android' # just copy the conditions from the test above tags = openwindow [test_iframe_sandbox_inheritance.html] tags = openwindow -[test_iframe_sandbox_modal.html] -tags = openwindow -skip-if = toolkit == 'android' || e10s #modal tests fail on android [test_iframe_sandbox_navigation.html] tags = openwindow [test_iframe_sandbox_navigation2.html] @@ -540,8 +534,6 @@ skip-if = toolkit == 'android' #bug 811644 [test_bug369370.html] skip-if = toolkit == "android" || toolkit == "windows" # disabled on Windows because of bug 1234520 [test_bug380383.html] -[test_bug391777.html] -skip-if = toolkit == 'android' || e10s [test_bug402680.html] [test_bug403868.html] [test_bug403868.xhtml] @@ -607,4 +599,4 @@ skip-if = os == "android" # up/down arrow keys not supported on android [test_script_module.html] support-files = file_script_module.html - file_script_nomodule.html \ No newline at end of file + file_script_nomodule.html diff --git a/dom/html/test/test_bug391777.html b/dom/html/test/test_bug391777.html deleted file mode 100644 index aa01a45de..000000000 --- a/dom/html/test/test_bug391777.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - Test for Bug 391777 - - - - -Mozilla Bug 391777 -

- - - diff --git a/dom/html/test/test_iframe_sandbox_general.html b/dom/html/test/test_iframe_sandbox_general.html index 6d3a190ee..83f0e9045 100644 --- a/dom/html/test/test_iframe_sandbox_general.html +++ b/dom/html/test/test_iframe_sandbox_general.html @@ -41,7 +41,7 @@ function ok_wrapper(result, desc) { passedTests++; } - if (completedTests == 33) { + if (completedTests == 32) { is(passedTests, completedTests, "There are " + completedTests + " general tests that should pass"); SimpleTest.finish(); } diff --git a/dom/html/test/test_iframe_sandbox_modal.html b/dom/html/test/test_iframe_sandbox_modal.html deleted file mode 100644 index 1307ea9a5..000000000 --- a/dom/html/test/test_iframe_sandbox_modal.html +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - Tests for Bug 766282 - - - - - - - -Mozilla Bug 766282 - implement allow-popups directive for iframe sandbox -

-
- - - -
-- cgit v1.2.3 From a2b56b295b8bd089b74c5d93148edafe7e6da912 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Wed, 1 Jan 2020 14:56:19 -0500 Subject: Bug 1276438 part 1. Move the implementation of the .body getter from nsHTMLDocument to nsIDocument. Tag UXP Issue #1344 Tag UXP Issue #252 --- dom/html/nsHTMLDocument.cpp | 20 -------------------- dom/html/nsHTMLDocument.h | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 0f2d90673..23c73298d 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1013,26 +1013,6 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv) rv = NodePrincipal()->SetDomain(newURI); } -nsGenericHTMLElement* -nsHTMLDocument::GetBody() -{ - Element* html = GetHtmlElement(); - if (!html) { - return nullptr; - } - - for (nsIContent* child = html->GetFirstChild(); - child; - child = child->GetNextSibling()) { - if (child->IsHTMLElement(nsGkAtoms::body) || - child->IsHTMLElement(nsGkAtoms::frameset)) { - return static_cast(child); - } - } - - return nullptr; -} - NS_IMETHODIMP nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody) { diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index 1fa81f6cd..02fc22d42 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -175,7 +175,7 @@ public: JS::MutableHandle aRetval, mozilla::ErrorResult& rv); void GetSupportedNames(nsTArray& aNames); - nsGenericHTMLElement *GetBody(); + using nsIDocument::GetBody; void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv); mozilla::dom::HTMLSharedElement *GetHead() { return static_cast(GetHeadElement()); -- cgit v1.2.3 From 32f3f8826f396fd17c1c77770d073d0abf15c904 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Wed, 1 Jan 2020 15:04:58 -0500 Subject: Bug 1276438 part 2. Move the implementation of the .body setter from nsHTMLDocument to nsIDocument. Tag UXP Issue #1344 Tag UXP Issue #252 --- dom/html/nsHTMLDocument.cpp | 25 ------------------------- dom/html/nsHTMLDocument.h | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 23c73298d..1eeef737a 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1034,31 +1034,6 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody) return rv.StealNSResult(); } -void -nsHTMLDocument::SetBody(nsGenericHTMLElement* newBody, ErrorResult& rv) -{ - nsCOMPtr root = GetRootElement(); - - // The body element must be either a body tag or a frameset tag. And we must - // have a html root tag, otherwise GetBody will not return the newly set - // body. - if (!newBody || - !newBody->IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset) || - !root || !root->IsHTMLElement() || - !root->IsHTMLElement(nsGkAtoms::html)) { - rv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR); - return; - } - - // Use DOM methods so that we pass through the appropriate security checks. - nsCOMPtr currentBody = GetBodyElement(); - if (currentBody) { - root->ReplaceChild(*newBody, *currentBody, rv); - } else { - root->AppendChild(*newBody, rv); - } -} - NS_IMETHODIMP nsHTMLDocument::GetHead(nsIDOMHTMLHeadElement** aHead) { diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index 02fc22d42..c9e46b3fa 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -176,7 +176,7 @@ public: mozilla::ErrorResult& rv); void GetSupportedNames(nsTArray& aNames); using nsIDocument::GetBody; - void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv); + using nsIDocument::SetBody; mozilla::dom::HTMLSharedElement *GetHead() { return static_cast(GetHeadElement()); } -- cgit v1.2.3 From bc8543bf793b5c203600c57565214b5e20f54592 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 20:27:27 -0500 Subject: Bug 1271549 - Remove details and summary preference. Tag UXP Issue #1344 --- dom/html/HTMLDetailsElement.cpp | 30 +----------------------------- dom/html/HTMLDetailsElement.h | 2 -- dom/html/HTMLSummaryElement.cpp | 12 +----------- 3 files changed, 2 insertions(+), 42 deletions(-) (limited to 'dom/html') diff --git a/dom/html/HTMLDetailsElement.cpp b/dom/html/HTMLDetailsElement.cpp index ed20b50ca..8619b1450 100644 --- a/dom/html/HTMLDetailsElement.cpp +++ b/dom/html/HTMLDetailsElement.cpp @@ -6,39 +6,11 @@ #include "mozilla/dom/HTMLDetailsElement.h" #include "mozilla/dom/HTMLDetailsElementBinding.h" -#include "mozilla/dom/HTMLUnknownElement.h" -#include "mozilla/Preferences.h" - -// Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Details) to add pref check. -nsGenericHTMLElement* -NS_NewHTMLDetailsElement(already_AddRefed&& aNodeInfo, - mozilla::dom::FromParser aFromParser) -{ - if (!mozilla::dom::HTMLDetailsElement::IsDetailsEnabled()) { - return new mozilla::dom::HTMLUnknownElement(aNodeInfo); - } - - return new mozilla::dom::HTMLDetailsElement(aNodeInfo); -} +NS_IMPL_NS_NEW_HTML_ELEMENT(Details) namespace mozilla { namespace dom { -/* static */ bool -HTMLDetailsElement::IsDetailsEnabled() -{ - static bool isDetailsEnabled = false; - static bool added = false; - - if (!added) { - Preferences::AddBoolVarCache(&isDetailsEnabled, - "dom.details_element.enabled"); - added = true; - } - - return isDetailsEnabled; -} - HTMLDetailsElement::~HTMLDetailsElement() { } diff --git a/dom/html/HTMLDetailsElement.h b/dom/html/HTMLDetailsElement.h index 5a3af27b4..6adf567bf 100644 --- a/dom/html/HTMLDetailsElement.h +++ b/dom/html/HTMLDetailsElement.h @@ -23,8 +23,6 @@ class HTMLDetailsElement final : public nsGenericHTMLElement public: using NodeInfo = mozilla::dom::NodeInfo; - static bool IsDetailsEnabled(); - explicit HTMLDetailsElement(already_AddRefed& aNodeInfo) : nsGenericHTMLElement(aNodeInfo) { diff --git a/dom/html/HTMLSummaryElement.cpp b/dom/html/HTMLSummaryElement.cpp index ee3c07b20..42ead6b87 100644 --- a/dom/html/HTMLSummaryElement.cpp +++ b/dom/html/HTMLSummaryElement.cpp @@ -14,17 +14,7 @@ #include "mozilla/TextEvents.h" #include "nsFocusManager.h" -// Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Summary) to add pref check. -nsGenericHTMLElement* -NS_NewHTMLSummaryElement(already_AddRefed&& aNodeInfo, - mozilla::dom::FromParser aFromParser) -{ - if (!mozilla::dom::HTMLDetailsElement::IsDetailsEnabled()) { - return new mozilla::dom::HTMLUnknownElement(aNodeInfo); - } - - return new mozilla::dom::HTMLSummaryElement(aNodeInfo); -} +NS_IMPL_NS_NEW_HTML_ELEMENT(Summary) namespace mozilla { namespace dom { -- cgit v1.2.3 From 244277a3fa428b70ba46cf611dbe1905733515eb Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 20:45:38 -0500 Subject: Bug 1274159 - Part 2-1: Include the name of relevant interface in nsHTMLTagList.h; Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 3e8e019b8..6e808f87e 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -96,14 +96,12 @@ NS_NewHTMLNOTUSEDElement(already_AddRefed&& aNodeInfo, return nullptr; } -#define HTML_TAG(_tag, _classname) NS_NewHTML##_classname##Element, -#define HTML_HTMLELEMENT_TAG(_tag) NS_NewHTMLElement, +#define HTML_TAG(_tag, _classname, _interfacename) NS_NewHTML##_classname##Element, #define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement, static const contentCreatorCallback sContentCreatorCallbacks[] = { NS_NewHTMLUnknownElement, #include "nsHTMLTagList.h" #undef HTML_TAG -#undef HTML_HTMLELEMENT_TAG #undef HTML_OTHER NS_NewHTMLUnknownElement }; -- cgit v1.2.3 From 88925e150bbcb64d1787b374c2115e6e28c3f6df Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 13:20:19 -0500 Subject: Bug 1357002 - Part 2: Don't call SetupCustomElement() if the custom element feature is pref-ed off; Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 6e808f87e..bba5d38ab 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -265,7 +265,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& return NS_ERROR_OUT_OF_MEMORY; } - if (isCustomElementName || aIs) { + if (CustomElementRegistry::IsCustomElementEnabled() && + (isCustomElementName || aIs)) { nsContentUtils::SetupCustomElement(*aResult, aIs); } -- cgit v1.2.3 From cc533eaee5b800a534b93484598779debcdf5591 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 19:48:30 -0500 Subject: Bug 1377993 - Make node slots less memory hungry in common cases. Tag UXP Issue #1344 --- dom/html/nsGenericHTMLElement.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 2f890325a..cbf97f1ea 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -497,7 +497,7 @@ nsGenericHTMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // We need to consider a labels element is moved to another subtree // with different root, it needs to update labels list and its root // as well. - nsDOMSlots* slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots && slots->mLabelsList) { slots->mLabelsList->MaybeResetRoot(SubtreeRoot()); } @@ -524,7 +524,7 @@ nsGenericHTMLElement::UnbindFromTree(bool aDeep, bool aNullParent) // We need to consider a labels element is removed from tree, // it needs to update labels list and its root as well. - nsDOMSlots* slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots && slots->mLabelsList) { slots->mLabelsList->MaybeResetRoot(SubtreeRoot()); } @@ -1730,7 +1730,7 @@ nsGenericHTMLElement::Labels() { MOZ_ASSERT(IsLabelable(), "Labels() only allow labelable elements to use it."); - nsDOMSlots* slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); if (!slots->mLabelsList) { slots->mLabelsList = new nsLabelsNodeList(SubtreeRoot(), MatchLabelsElement, -- cgit v1.2.3 From f50503df9c2eced785957626273ee07e5312d546 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 12:51:10 -0500 Subject: Bug 1301024 - Part 2: Implement create an element steps. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index bba5d38ab..ef160cf21 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -232,6 +232,26 @@ public: int32_t mStackPos; }; +static void +DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, + CustomElementConstructor* aConstructor, ErrorResult& aRv) +{ + RefPtr element = + aConstructor->Construct("Custom Element Create", aRv); + if (aRv.Failed() || !element->IsHTMLElement()) { + aRv.ThrowTypeError(NS_LITERAL_STRING("HTMLElement")); + return; + } + + if (aDoc != element->OwnerDoc() || element->GetParentNode() || + element->HasChildren() || element->GetAttrCount()) { + aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return; + } + + element.forget(aElement); +} + nsresult NS_NewHTMLElement(Element** aResult, already_AddRefed&& aNodeInfo, FromParser aFromParser, const nsAString* aIs) @@ -251,6 +271,81 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name); + // https://dom.spec.whatwg.org/#concept-create-element + // We only handle the "synchronous custom elements flag is set" now. + // For the unset case (e.g. cloning a node), see bug 1319342 for that. + // Step 4. + CustomElementDefinition* definition = nullptr; + if (CustomElementRegistry::IsCustomElementEnabled()) { + definition = + nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), + nodeInfo->LocalName(), + nodeInfo->NamespaceID(), + aIs); + } + + // It might be a problem that parser synchronously calls constructor, so filed + // bug 1378079 to figure out what we should do for parser case. + if (definition) { + /* + * Synchronous custom elements flag is determined by 3 places in spec, + * 1) create an element for a token, the flag is determined by + * "will execute script" which is not originally created + * for the HTML fragment parsing algorithm. + * 2) createElement and createElementNS, the flag is the same as + * NOT_FROM_PARSER. + * 3) clone a node, our implementation will not go into this function. + * For the unset case which is non-synchronous only applied for + * inner/outerHTML. + */ + bool synchronousCustomElements = aFromParser != dom::FROM_PARSER_FRAGMENT || + aFromParser == dom::NOT_FROM_PARSER; + // Per discussion in https://github.com/w3c/webcomponents/issues/635, + // use entry global in those places that are called from JS APIs. + nsIGlobalObject* global = GetEntryGlobal(); + MOZ_ASSERT(global); + AutoEntryScript aes(global, "create custom elements"); + JSContext* cx = aes.cx(); + ErrorResult rv; + + // Step 5. + if (definition->IsCustomBuiltIn()) { + // SetupCustomElement() should be called with an element that don't have + // CustomElementData setup, if not we will hit the assertion in + // SetCustomElementData(). + nsCOMPtr tagAtom = nodeInfo->NameAtom(); + nsCOMPtr typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom; + // Built-in element + *aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take(); + (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); + if (synchronousCustomElements) { + CustomElementRegistry::Upgrade(*aResult, definition, rv); + } else { + nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); + } + + if (rv.MaybeSetPendingException(cx)) { + aes.ReportException(); + } + return NS_OK; + } + + // Step 6.1. + if (synchronousCustomElements) { + DoCustomElementCreate(aResult, nodeInfo->GetDocument(), + definition->mConstructor, rv); + if (rv.MaybeSetPendingException(cx)) { + NS_IF_ADDREF(*aResult = NS_NewHTMLUnknownElement(nodeInfo.forget(), aFromParser)); + } + return NS_OK; + } + + // Step 6.2. + NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser)); + nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); + return NS_OK; + } + // Per the Custom Element specification, unknown tags that are valid custom // element names should be HTMLElement instead of HTMLUnknownElement. bool isCustomElementName = (tag == eHTMLTag_userdefined && -- cgit v1.2.3 From 4dda3f6039c4432a3545986ebc698a725c6c057c Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 18:38:55 -0500 Subject: Bug 1406297 - Fix Document.createElement must report an exception. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index ef160cf21..87ae2a4ac 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -233,18 +233,23 @@ public: }; static void -DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, +DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, nsIAtom* aLocalName, CustomElementConstructor* aConstructor, ErrorResult& aRv) { RefPtr element = aConstructor->Construct("Custom Element Create", aRv); - if (aRv.Failed() || !element->IsHTMLElement()) { + if (aRv.Failed()) { + return; + } + + if (!element || !element->IsHTMLElement()) { aRv.ThrowTypeError(NS_LITERAL_STRING("HTMLElement")); return; } if (aDoc != element->OwnerDoc() || element->GetParentNode() || - element->HasChildren() || element->GetAttrCount()) { + element->HasChildren() || element->GetAttrCount() || + element->NodeInfo()->NameAtom() != aLocalName) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return; } @@ -320,19 +325,20 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); if (synchronousCustomElements) { CustomElementRegistry::Upgrade(*aResult, definition, rv); + if (rv.MaybeSetPendingException(cx)) { + aes.ReportException(); + } } else { nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); } - if (rv.MaybeSetPendingException(cx)) { - aes.ReportException(); - } return NS_OK; } // Step 6.1. if (synchronousCustomElements) { DoCustomElementCreate(aResult, nodeInfo->GetDocument(), + nodeInfo->NameAtom(), definition->mConstructor, rv); if (rv.MaybeSetPendingException(cx)) { NS_IF_ADDREF(*aResult = NS_NewHTMLUnknownElement(nodeInfo.forget(), aFromParser)); -- cgit v1.2.3 From 0b6548613a4126193034d38242fb58a231e2c435 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 18 Jan 2020 20:26:28 -0500 Subject: Bug 1378079 - Part 2: Introduce throw-on-dynamic-markup-insertion counter. Per spec, document objects have a throw-on-dynamic-markup-insertion counter, which is used in conjunction with the create an element for the token algorithm to prevent custom element constructors from being able to use document.open(), document.close(), and document.write() when they are invoked by the parser. Tag UXP Issue #1344 --- dom/html/nsHTMLDocument.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'dom/html') diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 1eeef737a..f530d75e1 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1401,6 +1401,11 @@ nsHTMLDocument::Open(JSContext* cx, return nullptr; } + if (ShouldThrowOnDynamicMarkupInsertion()) { + aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } + // Set up the content type for insertion nsAutoCString contentType; contentType.AssignLiteral("text/html"); @@ -1608,6 +1613,11 @@ nsHTMLDocument::Close(ErrorResult& rv) return; } + if (ShouldThrowOnDynamicMarkupInsertion()) { + rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } + if (!mParser || !mParser->IsScriptCreated()) { return; } @@ -1683,6 +1693,10 @@ nsHTMLDocument::WriteCommon(JSContext *cx, return NS_ERROR_DOM_INVALID_STATE_ERR; } + if (ShouldThrowOnDynamicMarkupInsertion()) { + return NS_ERROR_DOM_INVALID_STATE_ERR; + } + if (mParserAborted) { // Hixie says aborting the parser doesn't undefine the insertion point. // However, since we null out mParser in that case, we track the -- cgit v1.2.3 From d163c367d9ee5f13769b8580b97bcc511fdd13cd Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 09:57:36 -0500 Subject: Bug 483155 - Put content creator function pointers onto nsHtml5ElementName. This is all the manual work for Bug 483155, minus the added functionality to disable SVG and MathML which can be done at any time and are out of scope. Tag UXP Issue #1344 --- dom/html/HTMLElement.cpp | 9 +++++++++ dom/html/nsGenericHTMLElement.h | 16 ++++++++++++++++ dom/html/nsHTMLContentSink.cpp | 8 ++------ 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'dom/html') diff --git a/dom/html/HTMLElement.cpp b/dom/html/HTMLElement.cpp index b2f23b931..d3901bdf3 100644 --- a/dom/html/HTMLElement.cpp +++ b/dom/html/HTMLElement.cpp @@ -52,3 +52,12 @@ NS_NewHTMLElement(already_AddRefed&& aNodeInfo, { return new mozilla::dom::HTMLElement(aNodeInfo); } + +// Distinct from the above in order to have function pointer that compared unequal +// to a function pointer to the above. +nsGenericHTMLElement* +NS_NewCustomElement(already_AddRefed&& aNodeInfo, + mozilla::dom::FromParser aFromParser) +{ + return new mozilla::dom::HTMLElement(aNodeInfo); +} diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 72039f266..edef2eeef 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -1590,6 +1590,15 @@ protected: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, \ mNodeInfo->Equals(nsGkAtoms::_tag)) +namespace mozilla { +namespace dom { + +typedef nsGenericHTMLElement* (*HTMLContentCreatorFunction)( + already_AddRefed&&, + mozilla::dom::FromParser aFromParser); + +} // namespace dom +} // namespace mozilla /** * A macro to declare the NS_NewHTMLXXXElement() functions. @@ -1638,6 +1647,13 @@ nsGenericHTMLElement* NS_NewHTMLElement(already_AddRefed&& aNodeInfo, mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); +// Distinct from the above in order to have function pointer that compared unequal +// to a function pointer to the above. +nsGenericHTMLElement* +NS_NewCustomElement( + already_AddRefed&& aNodeInfo, + mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); + NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared) NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList) NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedObject) diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 87ae2a4ac..2827f5ff6 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -84,10 +84,6 @@ using namespace mozilla::dom; //---------------------------------------------------------------------- -typedef nsGenericHTMLElement* - (*contentCreatorCallback)(already_AddRefed&&, - FromParser aFromParser); - nsGenericHTMLElement* NS_NewHTMLNOTUSEDElement(already_AddRefed&& aNodeInfo, FromParser aFromParser) @@ -98,7 +94,7 @@ NS_NewHTMLNOTUSEDElement(already_AddRefed&& aNodeInfo, #define HTML_TAG(_tag, _classname, _interfacename) NS_NewHTML##_classname##Element, #define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement, -static const contentCreatorCallback sContentCreatorCallbacks[] = { +static const HTMLContentCreatorFunction sHTMLContentCreatorFunctions[] = { NS_NewHTMLUnknownElement, #include "nsHTMLTagList.h" #undef HTML_TAG @@ -383,7 +379,7 @@ CreateHTMLElement(uint32_t aNodeType, aNodeType == eHTMLTag_userdefined, "aNodeType is out of bounds"); - contentCreatorCallback cb = sContentCreatorCallbacks[aNodeType]; + HTMLContentCreatorFunction cb = sHTMLContentCreatorFunctions[aNodeType]; NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement, "Don't know how to construct tag element!"); -- cgit v1.2.3 From a0014ac6e9e751f9f9bf68c1a345394bbcfd096f Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 21:22:39 -0500 Subject: Bug 1378079 - Part 3: Complete the steps related to custom elements in "create an element for a token". With fixup for missing header due to unified builds. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 2827f5ff6..518a3675e 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -255,7 +255,8 @@ DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, nsIAtom* aLocalName nsresult NS_NewHTMLElement(Element** aResult, already_AddRefed&& aNodeInfo, - FromParser aFromParser, const nsAString* aIs) + FromParser aFromParser, const nsAString* aIs, + mozilla::dom::CustomElementDefinition* aDefinition) { *aResult = nullptr; @@ -276,8 +277,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // We only handle the "synchronous custom elements flag is set" now. // For the unset case (e.g. cloning a node), see bug 1319342 for that. // Step 4. - CustomElementDefinition* definition = nullptr; - if (CustomElementRegistry::IsCustomElementEnabled()) { + CustomElementDefinition* definition = aDefinition; + if (!definition && CustomElementRegistry::IsCustomElementEnabled()) { definition = nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nodeInfo->LocalName(), @@ -302,9 +303,20 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& bool synchronousCustomElements = aFromParser != dom::FROM_PARSER_FRAGMENT || aFromParser == dom::NOT_FROM_PARSER; // Per discussion in https://github.com/w3c/webcomponents/issues/635, - // use entry global in those places that are called from JS APIs. - nsIGlobalObject* global = GetEntryGlobal(); - MOZ_ASSERT(global); + // use entry global in those places that are called from JS APIs and use the + // node document's global object if it is called from parser. + nsIGlobalObject* global; + if (aFromParser == dom::NOT_FROM_PARSER) { + global = GetEntryGlobal(); + } else { + global = nodeInfo->GetDocument()->GetScopeObject(); + } + if (!global) { + // In browser chrome code, one may have access to a document which doesn't + // have scope object anymore. + return NS_ERROR_FAILURE; + } + AutoEntryScript aes(global, "create custom elements"); JSContext* cx = aes.cx(); ErrorResult rv; @@ -344,6 +356,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // Step 6.2. NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser)); + (*aResult)->SetCustomElementData(new CustomElementData(definition->mType)); nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); return NS_OK; } -- cgit v1.2.3 From fb657f7a1e3ef326214e0c42a5a0dd6dc0109338 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 22:59:16 -0500 Subject: Bug 1406325 - Part 4: Use mType for LookupCustomElementDefinition and also removing parts of v0. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 518a3675e..7d60fffb5 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -267,6 +267,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& return NS_ERROR_OUT_OF_MEMORY; nsIAtom *name = nodeInfo->NameAtom(); + RefPtr tagAtom = nodeInfo->NameAtom(); + RefPtr typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom; NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML), "Trying to HTML elements that don't have the XHTML namespace"); @@ -283,7 +285,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nodeInfo->LocalName(), nodeInfo->NamespaceID(), - aIs); + typeAtom); } // It might be a problem that parser synchronously calls constructor, so filed @@ -326,8 +328,6 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // SetupCustomElement() should be called with an element that don't have // CustomElementData setup, if not we will hit the assertion in // SetCustomElementData(). - nsCOMPtr tagAtom = nodeInfo->NameAtom(); - nsCOMPtr typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom; // Built-in element *aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take(); (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); @@ -377,7 +377,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& if (CustomElementRegistry::IsCustomElementEnabled() && (isCustomElementName || aIs)) { - nsContentUtils::SetupCustomElement(*aResult, aIs); + (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); } return NS_OK; -- cgit v1.2.3 From 14d115cfe32ab72b7193a4fb74e13c06c6d4cc8f Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Mon, 20 Jan 2020 21:44:27 -0500 Subject: Bug 1419643 - Don't need to lookup custom element definition for a non-custom element Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 7d60fffb5..920ded728 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -275,12 +275,18 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name); + bool isCustomElementName = (tag == eHTMLTag_userdefined && + nsContentUtils::IsCustomElementName(name)); + bool isCustomElement = isCustomElementName || aIs; + MOZ_ASSERT_IF(aDefinition, isCustomElement); + // https://dom.spec.whatwg.org/#concept-create-element // We only handle the "synchronous custom elements flag is set" now. // For the unset case (e.g. cloning a node), see bug 1319342 for that. // Step 4. CustomElementDefinition* definition = aDefinition; - if (!definition && CustomElementRegistry::IsCustomElementEnabled()) { + if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement && + !definition) { definition = nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nodeInfo->LocalName(), @@ -363,8 +369,6 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // Per the Custom Element specification, unknown tags that are valid custom // element names should be HTMLElement instead of HTMLUnknownElement. - bool isCustomElementName = (tag == eHTMLTag_userdefined && - nsContentUtils::IsCustomElementName(name)); if (isCustomElementName) { NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser)); } else { @@ -375,8 +379,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& return NS_ERROR_OUT_OF_MEMORY; } - if (CustomElementRegistry::IsCustomElementEnabled() && - (isCustomElementName || aIs)) { + if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement) { (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); } -- cgit v1.2.3 From 3c70b297c7be12b7d7e120de04a38f40b600928b Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 25 Jan 2020 09:14:03 -0500 Subject: Bug 1430951 - Avoid element name atomizing to improve performance of LookupCustomElementDefinition Since we are dealing with the element (nodeInfo->LocalName() and NameAtom() are the same value), we could use nodeInfo->NameAtom() instead. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dom/html') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 920ded728..1fe5d2a86 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -287,9 +287,10 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& CustomElementDefinition* definition = aDefinition; if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement && !definition) { + MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName())); definition = nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), - nodeInfo->LocalName(), + nodeInfo->NameAtom(), nodeInfo->NamespaceID(), typeAtom); } -- cgit v1.2.3