Chromium Code Reviews| 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; |