Commit 79671540 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Add Document::CreateRawElement(), and use it in some functions.

The purpose of this function is to reduce the number of callsites for
FooElementFactory::createFooElement(), which don't support prefixes
correctly and contain unnecessary custom element processing.

The implementation of CreateRawElement() is equivalent to
Document::createElement(qname, flags) without custom-element processing.

* Document::createElement(local_name, options, exception_state):
  Replace createElement(local_name, exception_state) with
  CreateRawElement(). createElement(local_name, exception_state)
  contains V0 custom-element processing, but it isn't necessary here
  because it's already done before calling createElement().

* Document::createElementNS(ns, qname, exception_state):
  Replace createElement(qname, flag) call with V0 custom-element
  processing and CreateRawElement().
  createElement(qname, flag) does V0 custom-element processing in this
  path. This CL adds the custom-element processing here, and use
  CreateRawElement().

* Document::createElementNS(ns, qname, options, exception_state):
  Replace createElement(qname, flag) call with CreateRawElement().
  createElement(qname, flag) contains V0 custom-element processing,
  but it isn't necessary here because it's already done before
  calling createElement().

Bug: 806641
Change-Id: Ib3d0f3e8cc05b17c69945594b307d76988a840ea
Reviewed-on: https://chromium-review.googlesource.com/890958Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532366}
parent 6f157120
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
#include "core/html/HTMLScriptElement.h" #include "core/html/HTMLScriptElement.h"
#include "core/html/HTMLTemplateElement.h" #include "core/html/HTMLTemplateElement.h"
#include "core/html/HTMLTitleElement.h" #include "core/html/HTMLTitleElement.h"
#include "core/html/HTMLUnknownElement.h"
#include "core/html/PluginDocument.h" #include "core/html/PluginDocument.h"
#include "core/html/WindowNameCollection.h" #include "core/html/WindowNameCollection.h"
#include "core/html/canvas/CanvasContextCreationAttributes.h" #include "core/html/canvas/CanvasContextCreationAttributes.h"
...@@ -211,6 +212,7 @@ ...@@ -211,6 +212,7 @@
#include "core/svg/SVGDocumentExtensions.h" #include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGScriptElement.h" #include "core/svg/SVGScriptElement.h"
#include "core/svg/SVGTitleElement.h" #include "core/svg/SVGTitleElement.h"
#include "core/svg/SVGUnknownElement.h"
#include "core/svg/SVGUseElement.h" #include "core/svg/SVGUseElement.h"
#include "core/svg_element_factory.h" #include "core/svg_element_factory.h"
#include "core/svg_names.h" #include "core/svg_names.h"
...@@ -853,6 +855,38 @@ AtomicString Document::ConvertLocalName(const AtomicString& name) { ...@@ -853,6 +855,38 @@ AtomicString Document::ConvertLocalName(const AtomicString& name) {
return IsHTMLDocument() ? name.LowerASCII() : name; return IsHTMLDocument() ? name.LowerASCII() : name;
} }
// Just creates an element with specified qualified name without any
// custom element processing.
// This is a common code for step 5.2 and 7.2 of "create an element"
// <https://dom.spec.whatwg.org/#concept-create-element>
// Functions other than this one should not use HTMLElementFactory and
// SVGElementFactory because they don't support prefixes correctly.
Element* Document::CreateRawElement(const QualifiedName& qname,
CreateElementFlags flags) {
Element* element = nullptr;
if (qname.NamespaceURI() == HTMLNames::xhtmlNamespaceURI) {
element = HTMLElementFactory::CreateRawHTMLElement(qname.LocalName(), *this,
flags);
if (!element)
element = HTMLUnknownElement::Create(qname, *this);
saw_elements_in_known_namespaces_ = true;
} else if (qname.NamespaceURI() == SVGNames::svgNamespaceURI) {
element =
SVGElementFactory::CreateRawSVGElement(qname.LocalName(), *this, flags);
if (!element)
element = SVGUnknownElement::Create(qname, *this);
saw_elements_in_known_namespaces_ = true;
} else {
element = Element::Create(qname, this);
}
if (element->prefix() != qname.Prefix())
element->SetTagNameForCreateElementNS(qname);
DCHECK(qname == element->TagQName());
return element;
}
// https://dom.spec.whatwg.org/#dom-document-createelement // https://dom.spec.whatwg.org/#dom-document-createelement
Element* Document::createElement(const AtomicString& name, Element* Document::createElement(const AtomicString& name,
ExceptionState& exception_state) { ExceptionState& exception_state) {
...@@ -966,9 +1000,12 @@ Element* Document::createElement(const AtomicString& local_name, ...@@ -966,9 +1000,12 @@ Element* Document::createElement(const AtomicString& local_name,
*this, *this,
QualifiedName(g_null_atom, converted_local_name, xhtmlNamespaceURI)); QualifiedName(g_null_atom, converted_local_name, xhtmlNamespaceURI));
} else { } else {
element = createElement(local_name, exception_state); element =
if (exception_state.HadException()) CreateRawElement(QualifiedName(g_null_atom, converted_local_name,
return nullptr; IsXHTMLDocument() || IsHTMLDocument()
? HTMLNames::xhtmlNamespaceURI
: g_null_atom),
kCreatedByCreateElement);
} }
// 8. If 'is' is non-null, set 'is' attribute // 8. If 'is' is non-null, set 'is' attribute
...@@ -1016,7 +1053,10 @@ Element* Document::createElementNS(const AtomicString& namespace_uri, ...@@ -1016,7 +1053,10 @@ Element* Document::createElementNS(const AtomicString& namespace_uri,
if (CustomElement::ShouldCreateCustomElement(q_name)) if (CustomElement::ShouldCreateCustomElement(q_name))
return CustomElement::CreateCustomElementSync(*this, q_name); return CustomElement::CreateCustomElementSync(*this, q_name);
return createElement(q_name, kCreatedByCreateElement); else if (RegistrationContext() &&
V0CustomElement::IsValidName(q_name.LocalName()))
return RegistrationContext()->CreateCustomTagElement(*this, q_name);
return CreateRawElement(q_name, kCreatedByCreateElement);
} }
// https://dom.spec.whatwg.org/#internal-createelementns-steps // https://dom.spec.whatwg.org/#internal-createelementns-steps
...@@ -1076,7 +1116,7 @@ Element* Document::createElementNS(const AtomicString& namespace_uri, ...@@ -1076,7 +1116,7 @@ Element* Document::createElementNS(const AtomicString& namespace_uri,
RegistrationContext()) { RegistrationContext()) {
element = RegistrationContext()->CreateCustomTagElement(*this, q_name); element = RegistrationContext()->CreateCustomTagElement(*this, q_name);
} else { } else {
element = createElement(q_name, kCreatedByCreateElement); element = CreateRawElement(q_name, kCreatedByCreateElement);
} }
// 6. If 'is' is non-null, set 'is' attribute // 6. If 'is' is non-null, set 'is' attribute
......
...@@ -1537,6 +1537,8 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -1537,6 +1537,8 @@ class CORE_EXPORT Document : public ContainerNode,
// the LocalFrameClient. // the LocalFrameClient.
void ApplyFeaturePolicy(const ParsedFeaturePolicy& declared_policy); void ApplyFeaturePolicy(const ParsedFeaturePolicy& declared_policy);
Element* CreateRawElement(const QualifiedName&, CreateElementFlags);
DocumentLifecycle lifecycle_; DocumentLifecycle lifecycle_;
bool has_nodes_with_placeholder_style_; bool has_nodes_with_placeholder_style_;
......
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