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

Unified Diff: third_party/WebKit/Source/core/dom/SubframeTracker.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, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/SubframeTracker.cpp
diff --git a/third_party/WebKit/Source/core/dom/SubframeTracker.cpp b/third_party/WebKit/Source/core/dom/SubframeTracker.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f661676f82255de0c1daf1dfde44fcba75e66e1d
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/SubframeTracker.cpp
@@ -0,0 +1,92 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/SubframeTracker.h"
+
+#include "core/dom/Node.h"
+#include "core/html/HTMLFrameOwnerElement.h"
+
+namespace blink {
+
+SubframeTracker::SubframeTracker() = default;
+
+bool SubframeTracker::hasConnectedSubframes(Node& node) const
+{
+ return m_connectedSubframeNodes.contains(&node);
+}
+
+void SubframeTracker::disconnectSubframesAt(Node& root, DisconnectPolicy policy)
+{
+ auto it = m_connectedSubframeNodes.find(&root);
+ if (it == m_connectedSubframeNodes.end())
+ return;
+
+ if (policy == DescendantsOnly)
+ ++it;
+
+ WillBeHeapVector<RefPtrWillBeMember<HTMLFrameOwnerElement>, 10> frameOwners;
+ for (; it != m_connectedSubframeNodes.end() && root.containsIncludingShadowDOM(*it); ++it) {
+ if ((*it)->isFrameOwnerElement())
+ frameOwners.append(toHTMLFrameOwnerElement(*it));
+ }
+
+ for (size_t i = 0; i < frameOwners.size(); ++i) {
+ HTMLFrameOwnerElement* owner = frameOwners[i].get();
+ // Don't need to traverse up the tree for the first owner since no
+ // script could have moved it.
+ if (!i || root.containsIncludingShadowDOM(owner))
+ owner->disconnectContentFrame();
+ }
+}
+
+DEFINE_TRACE(SubframeTracker)
+{
+#if ENABLE(OILPAN)
+ visitor->trace(m_connectedSubframeNodes);
+#endif // ENABLE(OILPAN)
+}
+
+void SubframeTracker::connectSubframe(HTMLFrameOwnerElement& owner)
+{
+ WillBeHeapVector<RawPtrWillBeMember<Node>> pathToOwner;
+ for (ContainerNode* node = &owner; node; node = node->parentOrShadowHostNode())
+ pathToOwner.append(node);
+
+ // Find the lowest node in the ancestor chain that's not already tracked in
+ // the set of connected subframe nodes.
+ SubframeNodeSet::iterator insertionLocation = m_connectedSubframeNodes.end();
+ auto node = pathToOwner.rbegin();
+ for (; node != pathToOwner.rend(); ++node) {
+ auto it = m_connectedSubframeNodes.find(*node);
+ if (it == m_connectedSubframeNodes.end())
+ break;
+ insertionLocation = it;
+ }
+
+ // Insert the remainder of the chain immediately after the last found node.
+ if (insertionLocation != m_connectedSubframeNodes.end()) {
+ // LinkedHashSet only exposes insertBefore(), so increment the iterator.
+ ++insertionLocation;
+ }
+
+ for (; node != pathToOwner.rend(); ++node)
+ m_connectedSubframeNodes.insertBefore(insertionLocation, *node);
+}
+
+void SubframeTracker::disconnectSubframe(HTMLFrameOwnerElement& owner)
+{
+ for (ContainerNode* node = &owner; node; node = node->parentOrShadowHostNode()) {
+ ASSERT(!m_connectedSubframeNodes.isEmpty());
+ auto it = m_connectedSubframeNodes.find(node);
+ ASSERT(it != m_connectedSubframeNodes.end());
+ auto nextNode = it;
+ // If the next node in |m_connectedSubframeNodes| is a child of this
+ // node, it can't be removed since there are still connected subframes.
+ if (*nextNode != m_connectedSubframeNodes.last() && (*++nextNode)->parentOrShadowHostNode() == node)
+ return;
+ m_connectedSubframeNodes.remove(it);
+ }
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/SubframeTracker.h ('k') | third_party/WebKit/Source/core/html/HTMLFrameOwnerElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698