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

Unified Diff: content/browser/frame_host/navigation_entry_impl.cc

Issue 2191543003: Remove existing FrameNavigationEntry when new named frame is added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed and refactored on top of TreeNode::parent. Created 4 years, 5 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: content/browser/frame_host/navigation_entry_impl.cc
diff --git a/content/browser/frame_host/navigation_entry_impl.cc b/content/browser/frame_host/navigation_entry_impl.cc
index c50a8d2229e498f4d6bb709429192ba6f0c4a057..28335ec4024d5c705f08341994d7a444bc7cab5b 100644
--- a/content/browser/frame_host/navigation_entry_impl.cc
+++ b/content/browser/frame_host/navigation_entry_impl.cc
@@ -99,6 +99,29 @@ void RecursivelyGenerateFrameState(
}
}
+// Walk the ancestor chain for both the |frame_tree_node| and the |node|.
+// Comparing the inputs directly is not performed, as this method assumes they
+// already match each other. Returns false if a mismatch in unique name or
+// ancestor chain is detected, otherwise true.
+bool InSameTreePosition(
+ FrameTreeNode* frame_tree_node,
Charlie Reis 2016/08/01 21:04:25 Style nit: I think this will fit on the previous l
nasko 2016/08/01 23:05:19 I wonder why git cl format didn't pick it up initi
+ NavigationEntryImpl::TreeNode* node) {
+ FrameTreeNode* ftn = frame_tree_node->parent();
+ NavigationEntryImpl::TreeNode* current_node = node->parent;
+ while (ftn && current_node) {
+ if (!current_node->MatchesFrame(ftn))
+ return false;
+
+ if (!current_node->parent)
Charlie Reis 2016/08/01 21:04:25 Is this a bug? Seems like if you call this for a
nasko 2016/08/01 23:05:19 Done.
+ return false;
+
+ ftn = ftn->parent();
+ current_node = current_node->parent;
+ }
+
+ return true;
+}
+
} // namespace
int NavigationEntryImpl::kInvalidBindings = -1;
@@ -810,6 +833,43 @@ void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) {
tree_node->children.clear();
}
+void NavigationEntryImpl::ClearStaleFrameEntriesForNewFrame(
+ FrameTreeNode* frame_tree_node) {
+ DCHECK(!frame_tree_node->IsMainFrame());
+
+ NavigationEntryImpl::TreeNode* node = nullptr;
+ std::queue<NavigationEntryImpl::TreeNode*> work_queue;
+ int count = 0;
+
+ work_queue.push(root_node());
+ while (!work_queue.empty()) {
+ node = work_queue.front();
+ work_queue.pop();
+
+ // Enqueue any children and keep looking if the current node doesn't match.
+ if (!node->MatchesFrame(frame_tree_node)) {
+ for (auto* child : node->children) {
+ work_queue.push(child);
+ }
+ continue;
+ }
+
+ // Remove the node from the tree if it is not for in the same position in
Charlie Reis 2016/08/01 21:04:25 nit: Drop "for"
nasko 2016/08/01 23:05:19 Done.
+ // the tree of FrameNavigationEntries and the FrameTree.
+ if (!InSameTreePosition(frame_tree_node, node)) {
+ NavigationEntryImpl::TreeNode* parent_node = node->parent;
+ auto it = std::find(parent_node->children.begin(),
+ parent_node->children.end(), node);
+ DCHECK(it != parent_node->children.end());
Charlie Reis 2016/08/01 21:04:25 Let's upgrade this to a CHECK. (Otherwise, could
nasko 2016/08/01 23:05:19 Done.
+ parent_node->children.erase(it);
+ }
+ ++count;
+ }
+
+ // At most one match is expected, since it is based on unique frame name.
+ DCHECK_LE(count, 1);
+}
+
void NavigationEntryImpl::SetScreenshotPNGData(
scoped_refptr<base::RefCountedBytes> png_data) {
screenshot_ = png_data;

Powered by Google App Engine
This is Rietveld 408576698