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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 for (auto& file : exploded_page_state.referenced_files) | 92 for (auto& file : exploded_page_state.referenced_files) |
93 referenced_files->push_back(file); | 93 referenced_files->push_back(file); |
94 | 94 |
95 state->children.resize(node->children.size()); | 95 state->children.resize(node->children.size()); |
96 for (size_t i = 0; i < node->children.size(); ++i) { | 96 for (size_t i = 0; i < node->children.size(); ++i) { |
97 RecursivelyGenerateFrameState(node->children[i], &state->children[i], | 97 RecursivelyGenerateFrameState(node->children[i], &state->children[i], |
98 referenced_files); | 98 referenced_files); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
| 102 // Walk the ancestor chain for both the |frame_tree_node| and the |node|. |
| 103 // Comparing the inputs directly is not performed, as this method assumes they |
| 104 // already match each other. Returns false if a mismatch in unique name or |
| 105 // ancestor chain is detected, otherwise true. |
| 106 bool InSameTreePosition(FrameTreeNode* frame_tree_node, |
| 107 NavigationEntryImpl::TreeNode* node) { |
| 108 FrameTreeNode* ftn = frame_tree_node->parent(); |
| 109 NavigationEntryImpl::TreeNode* current_node = node->parent; |
| 110 while (ftn && current_node) { |
| 111 if (!current_node->MatchesFrame(ftn)) |
| 112 return false; |
| 113 |
| 114 if ((!current_node->parent && ftn->parent()) || |
| 115 (current_node->parent && !ftn->parent())) { |
| 116 return false; |
| 117 } |
| 118 |
| 119 ftn = ftn->parent(); |
| 120 current_node = current_node->parent; |
| 121 } |
| 122 return true; |
| 123 } |
| 124 |
102 } // namespace | 125 } // namespace |
103 | 126 |
104 int NavigationEntryImpl::kInvalidBindings = -1; | 127 int NavigationEntryImpl::kInvalidBindings = -1; |
105 | 128 |
106 NavigationEntryImpl::TreeNode::TreeNode(TreeNode* parent, | 129 NavigationEntryImpl::TreeNode::TreeNode(TreeNode* parent, |
107 FrameNavigationEntry* frame_entry) | 130 FrameNavigationEntry* frame_entry) |
108 : parent(parent), frame_entry(frame_entry) {} | 131 : parent(parent), frame_entry(frame_entry) {} |
109 | 132 |
110 NavigationEntryImpl::TreeNode::~TreeNode() { | 133 NavigationEntryImpl::TreeNode::~TreeNode() { |
111 } | 134 } |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 826 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
804 return tree_node ? tree_node->frame_entry.get() : nullptr; | 827 return tree_node ? tree_node->frame_entry.get() : nullptr; |
805 } | 828 } |
806 | 829 |
807 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { | 830 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { |
808 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 831 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
809 if (tree_node) | 832 if (tree_node) |
810 tree_node->children.clear(); | 833 tree_node->children.clear(); |
811 } | 834 } |
812 | 835 |
| 836 void NavigationEntryImpl::ClearStaleFrameEntriesForNewFrame( |
| 837 FrameTreeNode* frame_tree_node) { |
| 838 DCHECK(!frame_tree_node->IsMainFrame()); |
| 839 |
| 840 NavigationEntryImpl::TreeNode* node = nullptr; |
| 841 std::queue<NavigationEntryImpl::TreeNode*> work_queue; |
| 842 int count = 0; |
| 843 |
| 844 work_queue.push(root_node()); |
| 845 while (!work_queue.empty()) { |
| 846 node = work_queue.front(); |
| 847 work_queue.pop(); |
| 848 |
| 849 // Enqueue any children and keep looking if the current node doesn't match. |
| 850 if (!node->MatchesFrame(frame_tree_node)) { |
| 851 for (auto* child : node->children) { |
| 852 work_queue.push(child); |
| 853 } |
| 854 continue; |
| 855 } |
| 856 |
| 857 // Remove the node from the tree if it is not in the same position in the |
| 858 // tree of FrameNavigationEntries and the FrameTree. |
| 859 if (!InSameTreePosition(frame_tree_node, node)) { |
| 860 NavigationEntryImpl::TreeNode* parent_node = node->parent; |
| 861 auto it = std::find(parent_node->children.begin(), |
| 862 parent_node->children.end(), node); |
| 863 CHECK(it != parent_node->children.end()); |
| 864 parent_node->children.erase(it); |
| 865 } |
| 866 ++count; |
| 867 } |
| 868 |
| 869 // At most one match is expected, since it is based on unique frame name. |
| 870 DCHECK_LE(count, 1); |
| 871 } |
| 872 |
813 void NavigationEntryImpl::SetScreenshotPNGData( | 873 void NavigationEntryImpl::SetScreenshotPNGData( |
814 scoped_refptr<base::RefCountedBytes> png_data) { | 874 scoped_refptr<base::RefCountedBytes> png_data) { |
815 screenshot_ = png_data; | 875 screenshot_ = png_data; |
816 if (screenshot_.get()) | 876 if (screenshot_.get()) |
817 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 877 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
818 } | 878 } |
819 | 879 |
820 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 880 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
821 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 881 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
822 } | 882 } |
(...skipping 10 matching lines...) Expand all Loading... |
833 return node; | 893 return node; |
834 | 894 |
835 // Enqueue any children and keep looking. | 895 // Enqueue any children and keep looking. |
836 for (auto* child : node->children) | 896 for (auto* child : node->children) |
837 work_queue.push(child); | 897 work_queue.push(child); |
838 } | 898 } |
839 return nullptr; | 899 return nullptr; |
840 } | 900 } |
841 | 901 |
842 } // namespace content | 902 } // namespace content |
OLD | NEW |