Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Unified Diff: Source/core/html/HTMLTitleElement.cpp

Issue 139313009: Remove children of title element before setting new title (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLTitleElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLTitleElement.cpp
diff --git a/Source/core/html/HTMLTitleElement.cpp b/Source/core/html/HTMLTitleElement.cpp
index 872ca280e1356f5134c9bc1c04d0ee49e34acffe..ff62d1c92a0824c76b4ba392ea626248a62fec5d 100644
--- a/Source/core/html/HTMLTitleElement.cpp
+++ b/Source/core/html/HTMLTitleElement.cpp
@@ -25,6 +25,7 @@
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
+#include "core/dom/ChildListMutationScope.h"
#include "core/dom/Document.h"
#include "core/dom/Text.h"
#include "core/rendering/style/RenderStyle.h"
@@ -37,6 +38,7 @@ using namespace HTMLNames;
inline HTMLTitleElement::HTMLTitleElement(Document& document)
: HTMLElement(titleTag, document)
+ , m_ignoreTitleUpdatesWhenChildrenChange(false)
{
setHasCustomStyleCallbacks();
ScriptWrappable::init(this);
@@ -65,7 +67,7 @@ void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint)
void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
- if (inDocument() && !isInShadowTree())
+ if (inDocument() && !isInShadowTree() && !m_ignoreTitleUpdatesWhenChildrenChange)
document().setTitleElement(text(), this);
}
@@ -84,23 +86,14 @@ String HTMLTitleElement::text() const
void HTMLTitleElement::setText(const String &value)
{
RefPtr<Node> protectFromMutationEvents(this);
+ ChildListMutationScope mutation(*this);
- int numChildren = childNodeCount();
-
- if (numChildren == 1 && firstChild()->isTextNode()) {
- toText(firstChild())->setData(value);
- document().setTitleElement(text(), this);
- } else {
- // We make a copy here because entity of "value" argument can be Document::m_title,
- // which goes empty during removeChildren() invocation below,
- // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle().
- String valueCopy(value);
+ // Avoid calling Document::setTitleElement() during intermediate steps.
+ m_ignoreTitleUpdatesWhenChildrenChange = true;
+ removeChildren();
+ m_ignoreTitleUpdatesWhenChildrenChange = false;
- if (numChildren > 0)
- removeChildren();
-
- appendChild(document().createTextNode(valueCopy.impl()), IGNORE_EXCEPTION);
- }
+ appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);
}
}
« no previous file with comments | « Source/core/html/HTMLTitleElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698