| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/dom/ChildFrameDisconnector.h" | 6 #include "core/dom/ChildFrameDisconnector.h" |
| 7 | 7 |
| 8 #include "core/dom/shadow/ElementShadow.h" | 8 #include "core/dom/shadow/ElementShadow.h" |
| 9 #include "core/dom/shadow/ShadowRoot.h" | 9 #include "core/dom/shadow/ShadowRoot.h" |
| 10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
| 11 | 11 |
| 12 namespace WebCore { | 12 namespace WebCore { |
| 13 | 13 |
| 14 #ifndef NDEBUG | 14 #ifndef NDEBUG |
| 15 static unsigned checkConnectedSubrameCountIsConsistent(Node&); | 15 static unsigned checkConnectedSubframeCountIsConsistent(Node&); |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 void ChildFrameDisconnector::disconnect(DisconnectPolicy policy) | 18 void ChildFrameDisconnector::disconnect(DisconnectPolicy policy) |
| 19 { | 19 { |
| 20 #ifndef NDEBUG | 20 #ifndef NDEBUG |
| 21 checkConnectedSubrameCountIsConsistent(m_root); | 21 checkConnectedSubframeCountIsConsistent(m_root); |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 if (!m_root.connectedSubframeCount()) | 24 if (!m_root.connectedSubframeCount()) |
| 25 return; | 25 return; |
| 26 | 26 |
| 27 if (policy == RootAndDescendants) { | 27 if (policy == RootAndDescendants) { |
| 28 collectFrameOwners(m_root); | 28 collectFrameOwners(m_root); |
| 29 } else { | 29 } else { |
| 30 for (Node* child = m_root.firstChild(); child; child = child->nextSiblin
g()) | 30 for (Node* child = m_root.firstChild(); child; child = child->nextSiblin
g()) |
| 31 collectFrameOwners(*child); | 31 collectFrameOwners(*child); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ChildFrameDisconnector::collectFrameOwners(ElementShadow& shadow) | 68 void ChildFrameDisconnector::collectFrameOwners(ElementShadow& shadow) |
| 69 { | 69 { |
| 70 for (ShadowRoot* root = shadow.youngestShadowRoot(); root; root = root->olde
rShadowRoot()) | 70 for (ShadowRoot* root = shadow.youngestShadowRoot(); root; root = root->olde
rShadowRoot()) |
| 71 collectFrameOwners(*root); | 71 collectFrameOwners(*root); |
| 72 } | 72 } |
| 73 | 73 |
| 74 #ifndef NDEBUG | 74 #ifndef NDEBUG |
| 75 static unsigned checkConnectedSubrameCountIsConsistent(Node& node) | 75 static unsigned checkConnectedSubframeCountIsConsistent(Node& node) |
| 76 { | 76 { |
| 77 unsigned count = 0; | 77 unsigned count = 0; |
| 78 | 78 |
| 79 if (node.isElementNode()) { | 79 if (node.isElementNode()) { |
| 80 if (node.isFrameOwnerElement() && toHTMLFrameOwnerElement(node).contentF
rame()) | 80 if (node.isFrameOwnerElement() && toHTMLFrameOwnerElement(node).contentF
rame()) |
| 81 count++; | 81 count++; |
| 82 | 82 |
| 83 if (ElementShadow* shadow = toElement(node).shadow()) { | 83 if (ElementShadow* shadow = toElement(node).shadow()) { |
| 84 for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = r
oot->olderShadowRoot()) | 84 for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = r
oot->olderShadowRoot()) |
| 85 count += checkConnectedSubrameCountIsConsistent(*root); | 85 count += checkConnectedSubframeCountIsConsistent(*root); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 for (Node* child = node.firstChild(); child; child = child->nextSibling()) | 89 for (Node* child = node.firstChild(); child; child = child->nextSibling()) |
| 90 count += checkConnectedSubrameCountIsConsistent(*child); | 90 count += checkConnectedSubframeCountIsConsistent(*child); |
| 91 | 91 |
| 92 // If we undercount there's possibly a security bug since we'd leave frames | 92 // If we undercount there's possibly a security bug since we'd leave frames |
| 93 // in subtrees outside the document. | 93 // in subtrees outside the document. |
| 94 ASSERT(node.connectedSubframeCount() >= count); | 94 ASSERT(node.connectedSubframeCount() >= count); |
| 95 | 95 |
| 96 // If we overcount it's safe, but not optimal because it means we'll travers
e | 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 | 97 // through the document in ChildFrameDisconnector looking for frames that ha
ve |
| 98 // already been disconnected. | 98 // already been disconnected. |
| 99 ASSERT(node.connectedSubframeCount() == count); | 99 ASSERT(node.connectedSubframeCount() == count); |
| 100 | 100 |
| 101 return count; | 101 return count; |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 } | 105 } |
| OLD | NEW |