| Index: third_party/WebKit/Source/core/dom/Document.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
|
| index 93a13ab219b2a1740691546634dd51c213453042..e3b138245dbd18a2d07896bd649e4b387e6a50d3 100644
|
| --- a/third_party/WebKit/Source/core/dom/Document.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/Document.cpp
|
| @@ -1287,18 +1287,29 @@ void Document::updateTitle(const String& title)
|
| void Document::setTitle(const String& title)
|
| {
|
| // Title set by JavaScript -- overrides any title elements.
|
| - if (!isHTMLDocument() && !isXHTMLDocument()) {
|
| - m_titleElement = nullptr;
|
| - } else if (!m_titleElement) {
|
| - HTMLElement* headElement = head();
|
| - if (!headElement)
|
| - return;
|
| - m_titleElement = HTMLTitleElement::create(*this);
|
| - headElement->appendChild(m_titleElement.get());
|
| + if (!m_titleElement) {
|
| + if (isHTMLDocument() || isXHTMLDocument()) {
|
| + HTMLElement* headElement = head();
|
| + if (!headElement)
|
| + return;
|
| + m_titleElement = HTMLTitleElement::create(*this);
|
| + headElement->appendChild(m_titleElement.get());
|
| + } else if (isSVGDocument()) {
|
| + Element* element = documentElement();
|
| + if (!isSVGSVGElement(element))
|
| + return;
|
| + m_titleElement = SVGTitleElement::create(*this);
|
| + element->insertBefore(m_titleElement.get(), element->firstChild());
|
| + }
|
| + } else {
|
| + if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument())
|
| + m_titleElement = nullptr;
|
| }
|
|
|
| if (isHTMLTitleElement(m_titleElement))
|
| toHTMLTitleElement(m_titleElement)->setText(title);
|
| + else if (isSVGTitleElement(m_titleElement))
|
| + toSVGTitleElement(m_titleElement)->setText(title);
|
| else
|
| updateTitle(title);
|
| }
|
| @@ -1316,6 +1327,31 @@ void Document::setTitleElement(Element* titleElement)
|
| m_titleElement = titleElement;
|
| }
|
|
|
| + if (isSVGDocument()) {
|
| + // If the root element that is <svg> element in the svg namespace is not the parent of <title> element,
|
| + // ignore <title> element.
|
| + Node* parent = m_titleElement->parentNode();
|
| + while (parent) {
|
| + if (isSVGSVGElement(parent) && toSVGElement(parent)->isOutermostSVGSVGElement()) {
|
| + if (documentElement() != parent || m_titleElement->parentNode() != parent) {
|
| + m_titleElement = nullptr;
|
| + return;
|
| + }
|
| + break;
|
| + }
|
| + parent = parent->parentNode();
|
| + }
|
| +
|
| + // If the root element is not <svg> element in the svg namespace and <title> element is in the svg namespace,
|
| + // or the root element is <svg> element in the svg namespace and <title> element is not in the svg namespace,
|
| + // ignore <title> element.
|
| + if ((!isSVGSVGElement(m_titleElement->parentNode()) && isSVGTitleElement(m_titleElement))
|
| + || (isSVGSVGElement(m_titleElement->parentNode()) && !isSVGTitleElement(m_titleElement))) {
|
| + m_titleElement = nullptr;
|
| + return;
|
| + }
|
| + }
|
| +
|
| if (isHTMLTitleElement(m_titleElement))
|
| updateTitle(toHTMLTitleElement(m_titleElement)->text());
|
| else if (isSVGTitleElement(m_titleElement))
|
|
|