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

Unified Diff: third_party/WebKit/Source/core/page/FrameTree.cpp

Issue 2329523003: Main frame's unique name can always be null. (Closed)
Patch Set: Addressed CR feedback from dcheng@. Created 4 years, 3 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
Index: third_party/WebKit/Source/core/page/FrameTree.cpp
diff --git a/third_party/WebKit/Source/core/page/FrameTree.cpp b/third_party/WebKit/Source/core/page/FrameTree.cpp
index e5b70f736e45c19dd7c395c724e3aa29e60fc621..5539d1d900a10f7ed910443dba9c091217872fee 100644
--- a/third_party/WebKit/Source/core/page/FrameTree.cpp
+++ b/third_party/WebKit/Source/core/page/FrameTree.cpp
@@ -78,29 +78,30 @@ void FrameTree::setName(const AtomicString& name)
if (toLocalFrame(m_thisFrame)->loader().stateMachine()->committedFirstRealDocumentLoad())
return;
- // Remove our old frame name so it's not considered in calculateUniqueNameForChildFrame
- // and appendUniqueSuffix calls below.
+ // Leave main frame's unique name set to a null string.
+ if (!parent())
+ return;
+
+ // Remove our old frame name so it's not considered in
+ // calculateUniqueNameForChildFrame call below.
m_uniqueName = AtomicString();
// Calculate a new unique name based on inputs.
- if (parent()) {
- setUniqueName(
- parent()->tree().calculateUniqueNameForChildFrame(m_thisFrame, name, nullAtom));
- } else if (name.isEmpty() || !uniqueNameExists(name)) {
- // Only main frame can have an empty unique name, so for main frames
- // emptiness guarantees uniquness.
- setUniqueName(name);
- } else {
- setUniqueName(appendUniqueSuffix(name, "<!--framePosition"));
- }
+ setUniqueName(
+ parent()->tree().calculateUniqueNameForChildFrame(m_thisFrame, name, nullAtom));
}
void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicString& uniqueName)
{
m_name = name;
- // Non-main frames should have a non-empty unique name.
- DCHECK(!parent() || !uniqueName.isEmpty());
+ if (parent()) {
+ // Non-main frames should have a non-empty unique name.
+ DCHECK(!uniqueName.isEmpty());
+ } else {
+ // Unique name of main frames should always stay empty.
+ DCHECK(uniqueName.isEmpty());
+ }
// TODO(lukasza): We would like to assert uniqueness below (i.e. by calling
// setUniqueName), but
@@ -313,10 +314,9 @@ AtomicString FrameTree::calculateUniqueNameForChildFrame(
// backcompatibility-aware approach has resulted so far in the following
// rather baroque format... :
//
- // uniqueName ::= <assignedName> | <generatedName>
+ // uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName>
// (generatedName is used if assignedName is
- // 1) non-unique / conflicts with other frame's unique name or
- // 2) assignedName is empty for a non-main frame)
+ // non-unique / conflicts with other frame's unique name.
//
// assignedName ::= value of iframe's name attribute
// or value assigned to window.name (*before* the first
@@ -327,9 +327,7 @@ AtomicString FrameTree::calculateUniqueNameForChildFrame(
// not unique after all)
//
// oldGeneratedName ::= "<!--framePath //" ancestorChain "/<!--frame" childCount "-->-->"
- // (main frame is special - oldGeneratedName for main frame
- // is always the frame's assignedName; oldGeneratedName is
- // generated by generateUniqueNameCandidate method).
+ // (oldGeneratedName is generated by generateUniqueNameCandidate method).
//
// childCount ::= current number of siblings
//
@@ -344,20 +342,17 @@ AtomicString FrameTree::calculateUniqueNameForChildFrame(
// newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber "-->"
//
// framePosition ::= "-" numberOfSiblingsBeforeChild [ framePosition-forParent? ]
- // | <empty string for main frame>
//
// retryNumber ::= smallest non-negative integer resulting in unique name
}
void FrameTree::setUniqueName(const AtomicString& uniqueName)
{
- // Main frame is the only frame that can have an empty unique name.
- if (parent()) {
- DCHECK(!uniqueName.isEmpty() && !uniqueNameExists(uniqueName));
- } else {
- DCHECK(uniqueName.isEmpty() || !uniqueNameExists(uniqueName));
- }
+ // Only subframes can have a non-null unique name - setUniqueName should
+ // only be called for subframes and never for a main frame.
+ DCHECK(parent());
+ DCHECK(!uniqueName.isEmpty() && !uniqueNameExists(uniqueName));
m_uniqueName = uniqueName;
}

Powered by Google App Engine
This is Rietveld 408576698