Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 if (m_name == name) | 71 if (m_name == name) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 m_name = name; | 74 m_name = name; |
| 75 | 75 |
| 76 // https://crbug.com/607205: Make sure m_uniqueName doesn't change after | 76 // https://crbug.com/607205: Make sure m_uniqueName doesn't change after |
| 77 // initial navigation - session history depends on this. | 77 // initial navigation - session history depends on this. |
| 78 if (toLocalFrame(m_thisFrame)->loader().stateMachine()->committedFirstRealDo cumentLoad()) | 78 if (toLocalFrame(m_thisFrame)->loader().stateMachine()->committedFirstRealDo cumentLoad()) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 // Remove our old frame name so it's not considered in calculateUniqueNameFo rChildFrame | 81 // Leave main frame's unique name set to a null string. |
| 82 // and appendUniqueSuffix calls below. | 82 if (!parent()) |
| 83 return; | |
| 84 | |
| 85 // Remove our old frame name so it's not considered in | |
| 86 // calculateUniqueNameForChildFrame call below. | |
| 83 m_uniqueName = AtomicString(); | 87 m_uniqueName = AtomicString(); |
| 84 | 88 |
| 85 // Calculate a new unique name based on inputs. | 89 // Calculate a new unique name based on inputs. |
| 86 if (parent()) { | 90 setUniqueName( |
| 87 setUniqueName( | 91 parent()->tree().calculateUniqueNameForChildFrame(m_thisFrame, name, nul lAtom)); |
| 88 parent()->tree().calculateUniqueNameForChildFrame(m_thisFrame, name, nullAtom)); | |
| 89 } else if (name.isEmpty() || !uniqueNameExists(name)) { | |
| 90 // Only main frame can have an empty unique name, so for main frames | |
| 91 // emptiness guarantees uniquness. | |
| 92 setUniqueName(name); | |
| 93 } else { | |
| 94 setUniqueName(appendUniqueSuffix(name, "<!--framePosition")); | |
| 95 } | |
| 96 } | 92 } |
| 97 | 93 |
| 98 void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicStrin g& uniqueName) | 94 void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicStrin g& uniqueName) |
| 99 { | 95 { |
| 100 m_name = name; | 96 m_name = name; |
| 101 | 97 |
| 102 // Non-main frames should have a non-empty unique name. | 98 if (parent()) { |
| 103 DCHECK(!parent() || !uniqueName.isEmpty()); | 99 // Non-main frames should have a non-empty unique name. |
| 100 DCHECK(!uniqueName.isEmpty()); | |
| 101 } else { | |
| 102 // Unique name of main frames should always stay empty. | |
| 103 DCHECK(uniqueName.isEmpty()); | |
| 104 } | |
| 104 | 105 |
| 105 // TODO(lukasza): We would like to assert uniqueness below (i.e. by calling | 106 // TODO(lukasza): We would like to assert uniqueness below (i.e. by calling |
| 106 // setUniqueName), but | 107 // setUniqueName), but |
| 107 // 1) uniqueness is currently violated by provisional/old frame pairs. | 108 // 1) uniqueness is currently violated by provisional/old frame pairs. |
| 108 // 2) there is an unresolved race between 2 OOPIFs, that can result in a | 109 // 2) there is an unresolved race between 2 OOPIFs, that can result in a |
| 109 // non-unique |uniqueName| - see https://crbug.com/558680#c14. | 110 // non-unique |uniqueName| - see https://crbug.com/558680#c14. |
| 110 m_uniqueName = uniqueName; | 111 m_uniqueName = uniqueName; |
| 111 } | 112 } |
| 112 | 113 |
| 113 Frame* FrameTree::parent() const | 114 Frame* FrameTree::parent() const |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 307 |
| 307 // Description of the current unique name format | 308 // Description of the current unique name format |
| 308 // --------------------------------------------- | 309 // --------------------------------------------- |
| 309 // | 310 // |
| 310 // Changing the format of unique name is undesirable, because it breaks | 311 // Changing the format of unique name is undesirable, because it breaks |
| 311 // backcompatibility of session history (which stores unique names | 312 // backcompatibility of session history (which stores unique names |
| 312 // generated in the past on user's disk). This incremental, | 313 // generated in the past on user's disk). This incremental, |
| 313 // backcompatibility-aware approach has resulted so far in the following | 314 // backcompatibility-aware approach has resulted so far in the following |
| 314 // rather baroque format... : | 315 // rather baroque format... : |
| 315 // | 316 // |
| 316 // uniqueName ::= <assignedName> | <generatedName> | 317 // uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName> |
| 317 // (generatedName is used if assignedName is | 318 // (generatedName is used if assignedName is |
| 318 // 1) non-unique / conflicts with other frame's unique name or | 319 // non-unique / conflicts with other frame's unique name. |
| 319 // 2) assignedName is empty for a non-main frame) | |
| 320 // | 320 // |
| 321 // assignedName ::= value of iframe's name attribute | 321 // assignedName ::= value of iframe's name attribute |
| 322 // or value assigned to window.name (*before* the first | 322 // or value assigned to window.name (*before* the first |
| 323 // real commit - afterwards unique name stays immutable). | 323 // real commit - afterwards unique name stays immutable). |
| 324 // | 324 // |
| 325 // generatedName ::= oldGeneratedName newUniqueSuffix? | 325 // generatedName ::= oldGeneratedName newUniqueSuffix? |
| 326 // (newUniqueSuffix is only present if oldGeneratedName was | 326 // (newUniqueSuffix is only present if oldGeneratedName was |
| 327 // not unique after all) | 327 // not unique after all) |
| 328 // | 328 // |
| 329 // oldGeneratedName ::= "<!--framePath //" ancestorChain "/<!--frame" chil dCount "-->-->" | 329 // oldGeneratedName ::= "<!--framePath //" ancestorChain "/<!--frame" chil dCount "-->-->" |
| 330 // (main frame is special - oldGeneratedName for main frame | 330 // (oldGeneratedName is generated by generateUniqueNameCand idate method). |
| 331 // is always the frame's assignedName; oldGeneratedName is | |
| 332 // generated by generateUniqueNameCandidate method). | |
| 333 // | 331 // |
| 334 // childCount ::= current number of siblings | 332 // childCount ::= current number of siblings |
| 335 // | 333 // |
| 336 // ancestorChain ::= concatenated unique names of ancestor chain, | 334 // ancestorChain ::= concatenated unique names of ancestor chain, |
| 337 // terminated on the first ancestor (if any) starting wi th "<!--framePath" | 335 // terminated on the first ancestor (if any) starting wi th "<!--framePath" |
| 338 // each ancestor's unique name is separated by "/" chara cter | 336 // each ancestor's unique name is separated by "/" chara cter |
| 339 // ancestorChain example1: "grandparent/parent" | 337 // ancestorChain example1: "grandparent/parent" |
| 340 // (ancestor's unique names : #1--^ | #2-^ ) | 338 // (ancestor's unique names : #1--^ | #2-^ ) |
| 341 // ancestorChain example2: "<!--framePath //foo/bar/<!--frame42-->-->/blah /foobar" | 339 // ancestorChain example2: "<!--framePath //foo/bar/<!--frame42-->-->/blah /foobar" |
| 342 // (ancestor's unique names : ^--#1--^ | #2 | #3-^ ) | 340 // (ancestor's unique names : ^--#1--^ | #2 | #3-^ ) |
| 343 // | 341 // |
| 344 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber " -->" | 342 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber " -->" |
| 345 // | 343 // |
| 346 // framePosition ::= "-" numberOfSiblingsBeforeChild [ framePosition-forPa rent? ] | 344 // framePosition ::= "-" numberOfSiblingsBeforeChild [ framePosition-forPa rent? ] |
| 347 // | <empty string for main frame> | |
| 348 // | 345 // |
| 349 // retryNumber ::= smallest non-negative integer resulting in unique name | 346 // retryNumber ::= smallest non-negative integer resulting in unique name |
| 350 } | 347 } |
| 351 | 348 |
| 352 void FrameTree::setUniqueName(const AtomicString& uniqueName) | 349 void FrameTree::setUniqueName(const AtomicString& uniqueName) |
| 353 { | 350 { |
| 354 // Main frame is the only frame that can have an empty unique name. | 351 DCHECK(parent()); // Only subframes can have a custom-tailored unique name. |
|
dcheng
2016/09/15 06:33:23
custom-tailored => non-empty
Łukasz Anforowicz
2016/09/15 15:55:18
Done + expanded the comment a bit more.
| |
| 355 if (parent()) { | 352 DCHECK(!uniqueName.isEmpty() && !uniqueNameExists(uniqueName)); |
| 356 DCHECK(!uniqueName.isEmpty() && !uniqueNameExists(uniqueName)); | |
| 357 } else { | |
| 358 DCHECK(uniqueName.isEmpty() || !uniqueNameExists(uniqueName)); | |
| 359 } | |
| 360 | |
| 361 m_uniqueName = uniqueName; | 353 m_uniqueName = uniqueName; |
| 362 } | 354 } |
| 363 | 355 |
| 364 Frame* FrameTree::scopedChild(unsigned index) const | 356 Frame* FrameTree::scopedChild(unsigned index) const |
| 365 { | 357 { |
| 366 unsigned scopedIndex = 0; | 358 unsigned scopedIndex = 0; |
| 367 for (Frame* child = firstChild(); child; child = child->tree().nextSibling() ) { | 359 for (Frame* child = firstChild(); child; child = child->tree().nextSibling() ) { |
| 368 if (child->client()->inShadowTree()) | 360 if (child->client()->inShadowTree()) |
| 369 continue; | 361 continue; |
| 370 if (scopedIndex == index) | 362 if (scopedIndex == index) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 { | 589 { |
| 598 if (!frame) { | 590 if (!frame) { |
| 599 printf("Null input frame\n"); | 591 printf("Null input frame\n"); |
| 600 return; | 592 return; |
| 601 } | 593 } |
| 602 | 594 |
| 603 printFrames(frame->tree().top(), frame, 0); | 595 printFrames(frame->tree().top(), frame, 0); |
| 604 } | 596 } |
| 605 | 597 |
| 606 #endif | 598 #endif |
| OLD | NEW |