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

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: Rebase to fix conflict 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 97413c7b639baf003f4afc20a781f3c034f989d5..73366374b7e3590fa5ceb9c0d49d8a6ab6c9fb93 100644
--- a/content/browser/frame_host/navigation_entry_impl.cc
+++ b/content/browser/frame_host/navigation_entry_impl.cc
@@ -98,6 +98,41 @@ void RecursivelyGenerateFrameState(
}
}
+using ParentingMap =
+ std::map<NavigationEntryImpl::TreeNode*, NavigationEntryImpl::TreeNode*>;
Charlie Reis 2016/07/29 17:21:36 nit: Please document which parameter is which.
nasko 2016/08/01 20:42:16 Removed in refactor.
+
+// Walk the ancestor chain for both the |frame_tree_node| and the
+// |node|. If a mismatch in unique name is detected, |node| needs to be removed.
Charlie Reis 2016/07/29 17:21:35 nit: There's no |node| parameter. :) It's also u
nasko 2016/08/01 20:42:16 Done.
+void WalkAncestorsAndRemoveIfMismatchFound(
Charlie Reis 2016/07/29 17:21:36 Can we make this just return whether the ancestors
nasko 2016/08/01 20:42:16 Done.
+ const ParentingMap& parenting_map,
+ FrameTreeNode* frame_tree_node,
+ NavigationEntryImpl::TreeNode* root_node,
+ NavigationEntryImpl::TreeNode* node_to_remove,
+ NavigationEntryImpl::TreeNode* parent_node) {
+ FrameTreeNode* ftn = frame_tree_node;
+ NavigationEntryImpl::TreeNode* current_node = parent_node;
+ while (ftn && current_node) {
+ if (!current_node->MatchesFrame(ftn, current_node == root_node)) {
Charlie Reis 2016/07/29 17:21:36 I apologize for MatchesFrame taking in is_root_tre
nasko 2016/08/01 20:42:16 Done.
+ auto it = std::find(parent_node->children.begin(),
+ parent_node->children.end(), node_to_remove);
+ DCHECK(it != parent_node->children.end());
Charlie Reis 2016/07/29 17:21:35 nit: DCHECK_NE, unless the compiler doesn't like i
nasko 2016/08/01 20:42:16 Compiler complains about it.
+ parent_node->children.erase(it);
+ return;
Charlie Reis 2016/07/29 17:21:36 Both of these erase blocks could just be return fa
nasko 2016/08/01 20:42:16 Done.
+ }
+
+ auto parent_iterator = parenting_map.find(current_node);
Charlie Reis 2016/07/29 17:21:35 Do we still need parenting_map as opposed to havin
nasko 2016/08/01 20:42:16 Done.
+ if (parent_iterator == parenting_map.end()) {
+ auto it = std::find(parent_node->children.begin(),
+ parent_node->children.end(), node_to_remove);
+ DCHECK(it != parent_node->children.end());
+ parent_node->children.erase(it);
+ return;
+ }
+ ftn = ftn->parent();
+ current_node = parent_iterator->second;
+ }
+}
+
} // namespace
int NavigationEntryImpl::kInvalidBindings = -1;
@@ -802,6 +837,42 @@ void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) {
tree_node->children.clear();
}
+void NavigationEntryImpl::ClearMatchingFrameEntries(
+ FrameTreeNode* frame_tree_node) {
+ DCHECK(!frame_tree_node->IsMainFrame());
+
+ int count = 0;
+ NavigationEntryImpl::TreeNode* node = nullptr;
+ NavigationEntryImpl::TreeNode* parent_node = nullptr;
+ std::queue<NavigationEntryImpl::TreeNode*> work_queue;
+ ParentingMap parenting_map;
+
+ work_queue.push(root_node());
+ parenting_map.insert(std::make_pair(root_node(), nullptr));
+
+ while (!work_queue.empty()) {
+ node = work_queue.front();
+ parent_node = parenting_map.find(node)->second;
+ work_queue.pop();
+
+ if (node->MatchesFrame(frame_tree_node, node == root_node())) {
+ WalkAncestorsAndRemoveIfMismatchFound(parenting_map,
+ frame_tree_node->parent(),
+ root_node(), node, parent_node);
+ ++count;
+ continue;
+ }
+
+ // Enqueue any children and keep looking.
+ for (auto* child : node->children) {
+ work_queue.push(child);
+ parenting_map.insert(std::make_pair(child, node));
+ }
+ }
+
+ DCHECK_GE(1, count);
Charlie Reis 2016/07/29 17:21:35 I think this might be easier to read as DCHECK_LE(
nasko 2016/08/01 20:42:16 Done.
+}
+
void NavigationEntryImpl::SetScreenshotPNGData(
scoped_refptr<base::RefCountedBytes> png_data) {
screenshot_ = png_data;

Powered by Google App Engine
This is Rietveld 408576698