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

Side by Side Diff: third_party/WebKit/Source/core/page/FrameTree.cpp

Issue 1968213002: Try harder to make sure that blink::FrameTree::m_uniqueName is truly unique. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/page/FrameTree.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "core/page/FrameTree.h" 21 #include "core/page/FrameTree.h"
22 22
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/frame/FrameClient.h" 24 #include "core/frame/FrameClient.h"
25 #include "core/frame/FrameView.h" 25 #include "core/frame/FrameView.h"
26 #include "core/frame/LocalFrame.h" 26 #include "core/frame/LocalFrame.h"
27 #include "core/frame/RemoteFrame.h" 27 #include "core/frame/RemoteFrame.h"
28 #include "core/frame/RemoteFrameView.h" 28 #include "core/frame/RemoteFrameView.h"
29 #include "core/page/Page.h" 29 #include "core/page/Page.h"
30 #include "wtf/Assertions.h"
31 #include "wtf/CryptographicallyRandomNumber.h"
30 #include "wtf/Vector.h" 32 #include "wtf/Vector.h"
31 #include "wtf/text/CString.h" 33 #include "wtf/text/CString.h"
32 #include "wtf/text/StringBuilder.h" 34 #include "wtf/text/StringBuilder.h"
33 35
34 using std::swap; 36 using std::swap;
35 37
36 namespace blink { 38 namespace blink {
37 39
38 namespace { 40 namespace {
39 41
40 const unsigned invalidChildCount = ~0U; 42 const unsigned invalidChildCount = ~0U;
41 43
42 } // namespace 44 } // namespace
43 45
44 FrameTree::FrameTree(Frame* thisFrame) 46 FrameTree::FrameTree(Frame* thisFrame)
45 : m_thisFrame(thisFrame) 47 : m_thisFrame(thisFrame)
46 , m_scopedChildCount(invalidChildCount) 48 , m_scopedChildCount(invalidChildCount)
47 { 49 {
48 } 50 }
49 51
50 FrameTree::~FrameTree() 52 FrameTree::~FrameTree()
51 { 53 {
52 } 54 }
53 55
54 void FrameTree::setName(const AtomicString& name, const AtomicString& fallbackNa me) 56 void FrameTree::setName(const AtomicString& name, const AtomicString& fallbackNa me)
55 { 57 {
56 m_name = name; 58 m_name = name;
57 if (!parent()) {
58 m_uniqueName = name;
59 return;
60 }
61 59
62 // Remove our old frame name so it's not considered in calculateUniqueNameFo rChildFrame. 60 // Remove our old frame name so it's not considered in calculateUniqueNameFo rChildFrame
61 // and ensureUniquenessOfUniqueName calls below.
63 m_uniqueName = AtomicString(); 62 m_uniqueName = AtomicString();
64 63
65 m_uniqueName = parent()->tree().calculateUniqueNameForChildFrame(true, name, fallbackName); 64 // Calculate a new unique name based on inputs.
65 if (parent()) {
66 setUniqueName(
67 parent()->tree().calculateUniqueNameForChildFrame(true, name, fallba ckName));
68 } else if (name.isEmpty()) {
69 // Only main frame can have an empty unique name, so for main frames
70 // emptiness guarantees uniquness.
71 setUniqueName(name);
72 } else {
73 setUniqueName(ensureUniquenessOfUniqueName(name));
74 }
66 } 75 }
67 76
68 void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicStrin g& uniqueName) 77 void FrameTree::setPrecalculatedName(const AtomicString& name, const AtomicStrin g& uniqueName)
69 { 78 {
70 if (!parent()) { 79 if (!parent()) {
71 ASSERT(uniqueName == name); 80 ASSERT(uniqueName == name);
72 } else { 81 } else {
73 ASSERT(!uniqueName.isEmpty()); 82 ASSERT(!uniqueName.isEmpty());
74 } 83 }
75 84
76 m_name = name; 85 m_name = name;
86
87 // TODO(lukasza): We would like to assert uniqueness below (i.e. by calling
88 // setUniqueName), but
89 // 1) uniqueness is currently violated by provisional/old frame pairs.
90 // 2) there is an unresolved race between 2 OOPIFs, that can result in a
91 // non-unique |uniqueName| - see https://crbug.com/558680#c14.
77 m_uniqueName = uniqueName; 92 m_uniqueName = uniqueName;
78 } 93 }
79 94
80 Frame* FrameTree::parent() const 95 Frame* FrameTree::parent() const
81 { 96 {
82 if (!m_thisFrame->client()) 97 if (!m_thisFrame->client())
83 return nullptr; 98 return nullptr;
84 return m_thisFrame->client()->parent(); 99 return m_thisFrame->client()->parent();
85 } 100 }
86 101
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 133
119 Frame* FrameTree::lastChild() const 134 Frame* FrameTree::lastChild() const
120 { 135 {
121 if (!m_thisFrame->client()) 136 if (!m_thisFrame->client())
122 return nullptr; 137 return nullptr;
123 return m_thisFrame->client()->lastChild(); 138 return m_thisFrame->client()->lastChild();
124 } 139 }
125 140
126 bool FrameTree::uniqueNameExists(const AtomicString& name) const 141 bool FrameTree::uniqueNameExists(const AtomicString& name) const
127 { 142 {
143 // Before recalculating or checking unique name, we set m_uniqueName
144 // to an empty string (so the soon-to-be-removed name does not count
145 // as a collision). This means that uniqueNameExists would return
146 // false positives when called with an empty |name|.
147 ASSERT(!name.isEmpty());
148
128 for (Frame* frame = top(); frame; frame = frame->tree().traverseNext()) { 149 for (Frame* frame = top(); frame; frame = frame->tree().traverseNext()) {
129 if (frame->tree().uniqueName() == name) 150 if (frame->tree().uniqueName() == name)
130 return true; 151 return true;
131 } 152 }
132 return false; 153 return false;
133 } 154 }
134 155
135 AtomicString FrameTree::calculateUniqueNameForNewChildFrame( 156 AtomicString FrameTree::calculateUniqueNameForNewChildFrame(
136 const AtomicString& name, 157 const AtomicString& name,
137 const AtomicString& fallbackName) const 158 const AtomicString& fallbackName) const
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 for (int i = chain.size() - 1; i >= 0; --i) { 197 for (int i = chain.size() - 1; i >= 0; --i) {
177 frame = chain[i]; 198 frame = chain[i];
178 uniqueName.append('/'); 199 uniqueName.append('/');
179 uniqueName.append(frame->tree().uniqueName()); 200 uniqueName.append(frame->tree().uniqueName());
180 } 201 }
181 202
182 uniqueName.appendLiteral("/<!--frame"); 203 uniqueName.appendLiteral("/<!--frame");
183 uniqueName.appendNumber(childCount() - (existingChildFrame ? 1 : 0)); 204 uniqueName.appendNumber(childCount() - (existingChildFrame ? 1 : 0));
184 uniqueName.appendLiteral("-->-->"); 205 uniqueName.appendLiteral("-->-->");
185 206
186 return uniqueName.toAtomicString(); 207 return ensureUniquenessOfUniqueName(uniqueName.toAtomicString());
208 }
209
210 AtomicString FrameTree::ensureUniquenessOfUniqueName(const AtomicString& potenti allyUniqueName) const
211 {
212 if (!uniqueNameExists(potentiallyUniqueName))
213 return potentiallyUniqueName;
214
215 StringBuilder uniqueNameBuilder;
216 uniqueNameBuilder.append(potentiallyUniqueName);
217 do {
218 uniqueNameBuilder.append('-');
219 uniqueNameBuilder.appendNumber(cryptographicallyRandomNumber());
220 } while (uniqueNameExists(uniqueNameBuilder.toAtomicString()));
dcheng 2016/05/12 05:31:18 So according to the spec, a valid name cannot star
221 return uniqueNameBuilder.toAtomicString();
222 }
223
224 void FrameTree::setUniqueName(const AtomicString& uniqueName)
225 {
226 if (parent()) {
227 ASSERT(!uniqueName.isEmpty() && !uniqueNameExists(uniqueName));
228 } else {
229 ASSERT(uniqueName.isEmpty() || !uniqueNameExists(uniqueName));
230 }
231
232 m_uniqueName = uniqueName;
187 } 233 }
188 234
189 Frame* FrameTree::scopedChild(unsigned index) const 235 Frame* FrameTree::scopedChild(unsigned index) const
190 { 236 {
191 unsigned scopedIndex = 0; 237 unsigned scopedIndex = 0;
192 for (Frame* child = firstChild(); child; child = child->tree().nextSibling() ) { 238 for (Frame* child = firstChild(); child; child = child->tree().nextSibling() ) {
193 if (child->client()->inShadowTree()) 239 if (child->client()->inShadowTree())
194 continue; 240 continue;
195 if (scopedIndex == index) 241 if (scopedIndex == index)
196 return child; 242 return child;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 { 468 {
423 if (!frame) { 469 if (!frame) {
424 printf("Null input frame\n"); 470 printf("Null input frame\n");
425 return; 471 return;
426 } 472 }
427 473
428 printFrames(frame->tree().top(), frame, 0); 474 printFrames(frame->tree().top(), frame, 0);
429 } 475 }
430 476
431 #endif 477 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/FrameTree.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698