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

Side by Side Diff: Source/core/dom/ContainerNodeAlgorithms.h

Issue 51273002: Have ChildFrameDisconnector / ChildListMutationScope deal with references (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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 | « Source/core/dom/ContainerNode.cpp ('k') | Source/core/dom/ContainerNodeAlgorithms.cpp » ('j') | 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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 notifyNodeRemovedFromTree(toContainerNode(node)); 266 notifyNodeRemovedFromTree(toContainerNode(node));
267 } 267 }
268 268
269 class ChildFrameDisconnector { 269 class ChildFrameDisconnector {
270 public: 270 public:
271 enum DisconnectPolicy { 271 enum DisconnectPolicy {
272 RootAndDescendants, 272 RootAndDescendants,
273 DescendantsOnly 273 DescendantsOnly
274 }; 274 };
275 275
276 explicit ChildFrameDisconnector(Node* root) 276 explicit ChildFrameDisconnector(Node& root)
277 : m_root(root) 277 : m_root(root)
278 { 278 {
279 } 279 }
280 280
281 void disconnect(DisconnectPolicy = RootAndDescendants); 281 void disconnect(DisconnectPolicy = RootAndDescendants);
282 282
283 private: 283 private:
284 void collectFrameOwners(Node* root); 284 void collectFrameOwners(Node& root);
285 void collectFrameOwners(ElementShadow*); 285 void collectFrameOwners(ElementShadow&);
286 void disconnectCollectedFrameOwners(); 286 void disconnectCollectedFrameOwners();
287 287
288 Vector<RefPtr<HTMLFrameOwnerElement>, 10> m_frameOwners; 288 Vector<RefPtr<HTMLFrameOwnerElement>, 10> m_frameOwners;
289 Node* m_root; 289 Node& m_root;
290 }; 290 };
291 291
292 #ifndef NDEBUG 292 #ifndef NDEBUG
293 unsigned assertConnectedSubrameCountIsConsistent(Node*); 293 unsigned assertConnectedSubrameCountIsConsistent(Node&);
294 #endif 294 #endif
295 295
296 inline void ChildFrameDisconnector::collectFrameOwners(Node* root) 296 inline void ChildFrameDisconnector::collectFrameOwners(Node& root)
297 { 297 {
298 if (!root->connectedSubframeCount()) 298 if (!root.connectedSubframeCount())
299 return; 299 return;
300 300
301 if (root->isHTMLElement() && root->isFrameOwnerElement()) 301 if (root.isHTMLElement() && root.isFrameOwnerElement())
302 m_frameOwners.append(toHTMLFrameOwnerElement(root)); 302 m_frameOwners.append(&toHTMLFrameOwnerElement(root));
303 303
304 for (Node* child = root->firstChild(); child; child = child->nextSibling()) 304 for (Node* child = root.firstChild(); child; child = child->nextSibling())
305 collectFrameOwners(child); 305 collectFrameOwners(*child);
306 306
307 ElementShadow* shadow = root->isElementNode() ? toElement(root)->shadow() : 0; 307 ElementShadow* shadow = root.isElementNode() ? toElement(root).shadow() : 0;
308 if (shadow) 308 if (shadow)
309 collectFrameOwners(shadow); 309 collectFrameOwners(*shadow);
310 } 310 }
311 311
312 inline void ChildFrameDisconnector::disconnectCollectedFrameOwners() 312 inline void ChildFrameDisconnector::disconnectCollectedFrameOwners()
313 { 313 {
314 // Must disable frame loading in the subtree so an unload handler cannot 314 // Must disable frame loading in the subtree so an unload handler cannot
315 // insert more frames and create loaded frames in detached subtrees. 315 // insert more frames and create loaded frames in detached subtrees.
316 SubframeLoadingDisabler disabler(m_root); 316 SubframeLoadingDisabler disabler(&m_root);
317 317
318 for (unsigned i = 0; i < m_frameOwners.size(); ++i) { 318 for (unsigned i = 0; i < m_frameOwners.size(); ++i) {
319 HTMLFrameOwnerElement* owner = m_frameOwners[i].get(); 319 HTMLFrameOwnerElement* owner = m_frameOwners[i].get();
320 // Don't need to traverse up the tree for the first owner since no 320 // Don't need to traverse up the tree for the first owner since no
321 // script could have moved it. 321 // script could have moved it.
322 if (!i || m_root->containsIncludingShadowDOM(owner)) 322 if (!i || m_root.containsIncludingShadowDOM(owner))
323 owner->disconnectContentFrame(); 323 owner->disconnectContentFrame();
324 } 324 }
325 } 325 }
326 326
327 inline void ChildFrameDisconnector::disconnect(DisconnectPolicy policy) 327 inline void ChildFrameDisconnector::disconnect(DisconnectPolicy policy)
328 { 328 {
329 #ifndef NDEBUG 329 #ifndef NDEBUG
330 assertConnectedSubrameCountIsConsistent(m_root); 330 assertConnectedSubrameCountIsConsistent(m_root);
331 #endif 331 #endif
332 332
333 if (!m_root->connectedSubframeCount()) 333 if (!m_root.connectedSubframeCount())
334 return; 334 return;
335 335
336 if (policy == RootAndDescendants) 336 if (policy == RootAndDescendants)
337 collectFrameOwners(m_root); 337 collectFrameOwners(m_root);
338 else { 338 else {
339 for (Node* child = m_root->firstChild(); child; child = child->nextSibli ng()) 339 for (Node* child = m_root.firstChild(); child; child = child->nextSiblin g())
340 collectFrameOwners(child); 340 collectFrameOwners(*child);
341 } 341 }
342 342
343 disconnectCollectedFrameOwners(); 343 disconnectCollectedFrameOwners();
344 } 344 }
345 345
346 } // namespace WebCore 346 } // namespace WebCore
347 347
348 #endif // ContainerNodeAlgorithms_h 348 #endif // ContainerNodeAlgorithms_h
OLDNEW
« no previous file with comments | « Source/core/dom/ContainerNode.cpp ('k') | Source/core/dom/ContainerNodeAlgorithms.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698