Commit 91707a70 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

custom-elements: document.createElement in SVG documents should not create custom elements.

createElement() should assume the namespace is XHTML only if the
document is HTML-like.

New behavior matches to the standard and Firefox.

Bug: 807514
Change-Id: I1164612b6512c94de96bdefbf053e8f132f8b9f7
Reviewed-on: https://chromium-review.googlesource.com/894749
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarDominic Cooney <dominicc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533221}
parent 0b4607ae
<?xml version="1.0" encoding="utf-8"?>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/1999/xhtml"
width="100%" height="100%" viewBox="0 0 800 600">
<svg:title>document.createElement in SVG for custom elements</svg:title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script><![CDATA[
test(() => {
class MyElement1 extends HTMLElement {}
customElements.define('my-element', MyElement1);
let element = document.createElement('my-element', {});
assert_false(element instanceof MyElement1, 'Autonomous custom element should not be created.');
}, 'document.createElement() in SVG documents should not create autonomous custom elements.')
test(() => {
class MyElement2 extends HTMLDivElement {}
customElements.define('my-div', MyElement2, { extends: 'div' });
let element = document.createElement('div', { is: 'my-div' });
assert_false(element instanceof MyElement2, 'Custom built-in element should not be created.');
}, 'document.createElement() in SVG documents should not create custom built-in elements.')
]]></script>
</svg:svg>
......@@ -953,7 +953,13 @@ Element* Document::createElement(const AtomicString& local_name,
// 2. localName converted to ASCII lowercase
const AtomicString& converted_local_name = ConvertLocalName(local_name);
QualifiedName q_name(g_null_atom, converted_local_name,
IsXHTMLDocument() || IsHTMLDocument()
? HTMLNames::xhtmlNamespaceURI
: g_null_atom);
// TODO(tkent): Share the code with createElementNS(namespace_uri,
// qualified_name, string_or_options, exception_state).
bool is_v1 = string_or_options.IsDictionary() || !RegistrationContext();
bool create_v1_builtin =
string_or_options.IsDictionary() &&
......@@ -968,7 +974,7 @@ Element* Document::createElement(const AtomicString& local_name,
// 4. Let definition be result of lookup up custom element definition
CustomElementDefinition* definition = nullptr;
if (is_v1) {
if (is_v1 && q_name.NamespaceURI() == HTMLNames::xhtmlNamespaceURI) {
// Is the runtime flag enabled for customized builtin elements?
const CustomElementDescriptor desc =
RuntimeEnabledFeatures::CustomElementsBuiltinEnabled()
......@@ -992,20 +998,12 @@ Element* Document::createElement(const AtomicString& local_name,
Element* element;
if (definition) {
element = CustomElement::CreateCustomElementSync(
*this, converted_local_name, definition);
element = CustomElement::CreateCustomElementSync(*this, q_name, definition);
} else if (V0CustomElement::IsValidName(local_name) &&
RegistrationContext()) {
element = RegistrationContext()->CreateCustomTagElement(
*this,
QualifiedName(g_null_atom, converted_local_name, xhtmlNamespaceURI));
element = RegistrationContext()->CreateCustomTagElement(*this, q_name);
} else {
element =
CreateRawElement(QualifiedName(g_null_atom, converted_local_name,
IsXHTMLDocument() || IsHTMLDocument()
? HTMLNames::xhtmlNamespaceURI
: g_null_atom),
kCreatedByCreateElement);
element = CreateRawElement(q_name, kCreatedByCreateElement);
}
// 8. If 'is' is non-null, set 'is' attribute
......
......@@ -103,16 +103,6 @@ HTMLElement* CustomElement::CreateCustomElementSync(
return CreateCustomElementSync(document, tag_name, definition);
}
HTMLElement* CustomElement::CreateCustomElementSync(
Document& document,
const AtomicString& local_name,
CustomElementDefinition* definition) {
return CreateCustomElementSync(
document,
QualifiedName(g_null_atom, local_name, HTMLNames::xhtmlNamespaceURI),
definition);
}
// https://dom.spec.whatwg.org/#concept-create-element
HTMLElement* CustomElement::CreateCustomElementSync(
Document& document,
......
......@@ -69,9 +69,6 @@ class CORE_EXPORT CustomElement {
static bool ShouldCreateCustomizedBuiltinElement(const QualifiedName&);
static HTMLElement* CreateCustomElementSync(Document&, const QualifiedName&);
static HTMLElement* CreateCustomElementSync(Document&,
const AtomicString& local_name,
CustomElementDefinition*);
static HTMLElement* CreateCustomElementSync(Document&,
const QualifiedName&,
CustomElementDefinition*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment