Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/navigation_entry_impl.h" | 5 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 for (auto& file : exploded_page_state.referenced_files) | 91 for (auto& file : exploded_page_state.referenced_files) |
| 92 referenced_files->push_back(file); | 92 referenced_files->push_back(file); |
| 93 | 93 |
| 94 state->children.resize(node->children.size()); | 94 state->children.resize(node->children.size()); |
| 95 for (size_t i = 0; i < node->children.size(); ++i) { | 95 for (size_t i = 0; i < node->children.size(); ++i) { |
| 96 RecursivelyGenerateFrameState(node->children[i], &state->children[i], | 96 RecursivelyGenerateFrameState(node->children[i], &state->children[i], |
| 97 referenced_files); | 97 referenced_files); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 using ParentingMap = | |
| 102 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.
| |
| 103 | |
| 104 // Walk the ancestor chain for both the |frame_tree_node| and the | |
| 105 // |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.
| |
| 106 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.
| |
| 107 const ParentingMap& parenting_map, | |
| 108 FrameTreeNode* frame_tree_node, | |
| 109 NavigationEntryImpl::TreeNode* root_node, | |
| 110 NavigationEntryImpl::TreeNode* node_to_remove, | |
| 111 NavigationEntryImpl::TreeNode* parent_node) { | |
| 112 FrameTreeNode* ftn = frame_tree_node; | |
| 113 NavigationEntryImpl::TreeNode* current_node = parent_node; | |
| 114 while (ftn && current_node) { | |
| 115 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.
| |
| 116 auto it = std::find(parent_node->children.begin(), | |
| 117 parent_node->children.end(), node_to_remove); | |
| 118 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.
| |
| 119 parent_node->children.erase(it); | |
| 120 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.
| |
| 121 } | |
| 122 | |
| 123 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.
| |
| 124 if (parent_iterator == parenting_map.end()) { | |
| 125 auto it = std::find(parent_node->children.begin(), | |
| 126 parent_node->children.end(), node_to_remove); | |
| 127 DCHECK(it != parent_node->children.end()); | |
| 128 parent_node->children.erase(it); | |
| 129 return; | |
| 130 } | |
| 131 ftn = ftn->parent(); | |
| 132 current_node = parent_iterator->second; | |
| 133 } | |
| 134 } | |
| 135 | |
| 101 } // namespace | 136 } // namespace |
| 102 | 137 |
| 103 int NavigationEntryImpl::kInvalidBindings = -1; | 138 int NavigationEntryImpl::kInvalidBindings = -1; |
| 104 | 139 |
| 105 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) | 140 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) |
| 106 : frame_entry(frame_entry) { | 141 : frame_entry(frame_entry) { |
| 107 } | 142 } |
| 108 | 143 |
| 109 NavigationEntryImpl::TreeNode::~TreeNode() { | 144 NavigationEntryImpl::TreeNode::~TreeNode() { |
| 110 } | 145 } |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 830 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 796 return tree_node ? tree_node->frame_entry.get() : nullptr; | 831 return tree_node ? tree_node->frame_entry.get() : nullptr; |
| 797 } | 832 } |
| 798 | 833 |
| 799 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { | 834 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { |
| 800 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 835 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 801 if (tree_node) | 836 if (tree_node) |
| 802 tree_node->children.clear(); | 837 tree_node->children.clear(); |
| 803 } | 838 } |
| 804 | 839 |
| 840 void NavigationEntryImpl::ClearMatchingFrameEntries( | |
| 841 FrameTreeNode* frame_tree_node) { | |
| 842 DCHECK(!frame_tree_node->IsMainFrame()); | |
| 843 | |
| 844 int count = 0; | |
| 845 NavigationEntryImpl::TreeNode* node = nullptr; | |
| 846 NavigationEntryImpl::TreeNode* parent_node = nullptr; | |
| 847 std::queue<NavigationEntryImpl::TreeNode*> work_queue; | |
| 848 ParentingMap parenting_map; | |
| 849 | |
| 850 work_queue.push(root_node()); | |
| 851 parenting_map.insert(std::make_pair(root_node(), nullptr)); | |
| 852 | |
| 853 while (!work_queue.empty()) { | |
| 854 node = work_queue.front(); | |
| 855 parent_node = parenting_map.find(node)->second; | |
| 856 work_queue.pop(); | |
| 857 | |
| 858 if (node->MatchesFrame(frame_tree_node, node == root_node())) { | |
| 859 WalkAncestorsAndRemoveIfMismatchFound(parenting_map, | |
| 860 frame_tree_node->parent(), | |
| 861 root_node(), node, parent_node); | |
| 862 ++count; | |
| 863 continue; | |
| 864 } | |
| 865 | |
| 866 // Enqueue any children and keep looking. | |
| 867 for (auto* child : node->children) { | |
| 868 work_queue.push(child); | |
| 869 parenting_map.insert(std::make_pair(child, node)); | |
| 870 } | |
| 871 } | |
| 872 | |
| 873 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.
| |
| 874 } | |
| 875 | |
| 805 void NavigationEntryImpl::SetScreenshotPNGData( | 876 void NavigationEntryImpl::SetScreenshotPNGData( |
| 806 scoped_refptr<base::RefCountedBytes> png_data) { | 877 scoped_refptr<base::RefCountedBytes> png_data) { |
| 807 screenshot_ = png_data; | 878 screenshot_ = png_data; |
| 808 if (screenshot_.get()) | 879 if (screenshot_.get()) |
| 809 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 880 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
| 810 } | 881 } |
| 811 | 882 |
| 812 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 883 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
| 813 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 884 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
| 814 } | 885 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 825 return node; | 896 return node; |
| 826 | 897 |
| 827 // Enqueue any children and keep looking. | 898 // Enqueue any children and keep looking. |
| 828 for (auto* child : node->children) | 899 for (auto* child : node->children) |
| 829 work_queue.push(child); | 900 work_queue.push(child); |
| 830 } | 901 } |
| 831 return nullptr; | 902 return nullptr; |
| 832 } | 903 } |
| 833 | 904 |
| 834 } // namespace content | 905 } // namespace content |
| OLD | NEW |