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

Side by Side Diff: third_party/WebKit/Source/core/dom/ChildFrameDisconnector.cpp

Issue 1770523002: Track connected subframes per-Document instead of per-Node. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix various crashes but still doesn't refcount tracked nodes (and needs to) Created 4 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/dom/ChildFrameDisconnector.h"
6
7 #include "core/dom/shadow/ElementShadow.h"
8 #include "core/dom/shadow/ShadowRoot.h"
9 #include "core/html/HTMLFrameOwnerElement.h"
10 #include "wtf/Assertions.h"
11
12 namespace blink {
13
14 #if ENABLE(ASSERT)
15 static unsigned checkConnectedSubframeCountIsConsistent(Node&);
16 #endif
17
18 void ChildFrameDisconnector::disconnect(DisconnectPolicy policy)
19 {
20 #if ENABLE(ASSERT)
21 checkConnectedSubframeCountIsConsistent(root());
22 #endif
23
24 if (!root().connectedSubframeCount())
25 return;
26
27 if (policy == RootAndDescendants) {
28 collectFrameOwners(root());
29 } else {
30 for (Node* child = root().firstChild(); child; child = child->nextSiblin g())
31 collectFrameOwners(*child);
32 }
33
34 disconnectCollectedFrameOwners();
35 }
36
37 void ChildFrameDisconnector::collectFrameOwners(Node& root)
38 {
39 if (!root.connectedSubframeCount())
40 return;
41
42 if (root.isHTMLElement() && root.isFrameOwnerElement())
43 m_frameOwners.append(&toHTMLFrameOwnerElement(root));
44
45 for (Node* child = root.firstChild(); child; child = child->nextSibling())
46 collectFrameOwners(*child);
47
48 ElementShadow* shadow = root.isElementNode() ? toElement(root).shadow() : 0;
49 if (shadow)
50 collectFrameOwners(*shadow);
51 }
52
53 void ChildFrameDisconnector::disconnectCollectedFrameOwners()
54 {
55 // Must disable frame loading in the subtree so an unload handler cannot
56 // insert more frames and create loaded frames in detached subtrees.
57 SubframeLoadingDisabler disabler(root());
58
59 for (unsigned i = 0; i < m_frameOwners.size(); ++i) {
60 HTMLFrameOwnerElement* owner = m_frameOwners[i].get();
61 // Don't need to traverse up the tree for the first owner since no
62 // script could have moved it.
63 if (!i || root().containsIncludingShadowDOM(owner))
64 owner->disconnectContentFrame();
65 }
66 }
67
68 void ChildFrameDisconnector::collectFrameOwners(ElementShadow& shadow)
69 {
70 for (ShadowRoot* root = &shadow.youngestShadowRoot(); root; root = root->old erShadowRoot())
71 collectFrameOwners(*root);
72 }
73
74 #if ENABLE(ASSERT)
75 static unsigned checkConnectedSubframeCountIsConsistent(Node& node)
76 {
77 unsigned count = 0;
78
79 if (node.isElementNode()) {
80 if (node.isFrameOwnerElement() && toHTMLFrameOwnerElement(node).contentF rame())
81 count++;
82
83 if (ElementShadow* shadow = toElement(node).shadow()) {
84 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
85 count += checkConnectedSubframeCountIsConsistent(*root);
86 }
87 }
88
89 for (Node* child = node.firstChild(); child; child = child->nextSibling())
90 count += checkConnectedSubframeCountIsConsistent(*child);
91
92 // If we undercount there's possibly a security bug since we'd leave frames
93 // in subtrees outside the document.
94 ASSERT(node.connectedSubframeCount() >= count);
95
96 // If we overcount it's safe, but not optimal because it means we'll travers e
97 // through the document in ChildFrameDisconnector looking for frames that ha ve
98 // already been disconnected.
99 ASSERT(node.connectedSubframeCount() == count);
100
101 return count;
102 }
103 #endif
104
105 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ChildFrameDisconnector.h ('k') | third_party/WebKit/Source/core/dom/ContainerNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698