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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 781 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 782 return tree_node ? tree_node->frame_entry.get() : nullptr; | 782 return tree_node ? tree_node->frame_entry.get() : nullptr; |
| 783 } | 783 } |
| 784 | 784 |
| 785 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { | 785 void NavigationEntryImpl::ClearChildren(FrameTreeNode* frame_tree_node) { |
| 786 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 786 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 787 if (tree_node) | 787 if (tree_node) |
| 788 tree_node->children.clear(); | 788 tree_node->children.clear(); |
| 789 } | 789 } |
| 790 | 790 |
| 791 void NavigationEntryImpl::ClearMatchingFrameEntries( | |
| 792 FrameTreeNode* frame_tree_node) { | |
| 793 DCHECK(!frame_tree_node->IsMainFrame()); | |
| 794 | |
| 795 bool match_found = false; | |
| 796 NavigationEntryImpl::TreeNode* node = nullptr; | |
| 797 NavigationEntryImpl::TreeNode* parent_node = nullptr; | |
| 798 std::map<NavigationEntryImpl::TreeNode*, NavigationEntryImpl::TreeNode*> | |
| 799 parenting_map; | |
| 800 std::queue<NavigationEntryImpl::TreeNode*> work_queue; | |
| 801 work_queue.push(root_node()); | |
| 802 parenting_map.insert(std::make_pair(root_node(), nullptr)); | |
| 803 | |
| 804 while (!work_queue.empty()) { | |
| 805 node = work_queue.front(); | |
| 806 parent_node = parenting_map.find(node)->second; | |
| 807 work_queue.pop(); | |
| 808 | |
| 809 if (node->MatchesFrame(frame_tree_node, node == root_node())) { | |
| 810 match_found = true; | |
| 811 break; | |
|
Charlie Reis
2016/07/28 22:57:01
It's a little unfortunate that we stop after the f
nasko
2016/07/29 15:52:22
Done.
| |
| 812 } | |
| 813 | |
| 814 // Enqueue any children and keep looking. | |
| 815 for (auto* child : node->children) { | |
| 816 work_queue.push(child); | |
| 817 parenting_map.insert(std::make_pair(child, node)); | |
| 818 } | |
| 819 } | |
| 820 | |
| 821 if (!match_found) | |
| 822 return; | |
| 823 | |
| 824 // Walk the ancestor chain for both the FrameTreeNode and the | |
| 825 // FrameNavigationEntry. If a mismatch in unique name is detected, the | |
| 826 // matched FrameNavigationEntry needs to be removed. | |
| 827 // The FTN and FNE are a match, guaranteed by the while loop above. | |
| 828 // Start with the parent nodes. | |
| 829 FrameTreeNode* ftn = frame_tree_node->parent(); | |
| 830 TreeNode* current_node = parent_node; | |
| 831 while (ftn && current_node) { | |
| 832 if (!current_node->MatchesFrame(ftn, current_node == root_node())) { | |
| 833 auto it = std::find(parent_node->children.begin(), | |
| 834 parent_node->children.end(), node); | |
| 835 DCHECK(it != parent_node->children.end()); | |
| 836 parent_node->children.erase(it); | |
| 837 break; | |
| 838 } | |
| 839 ftn = ftn->parent(); | |
| 840 auto it = parenting_map.find(current_node); | |
| 841 if (it != parenting_map.end()) | |
| 842 current_node = it->second; | |
|
Charlie Reis
2016/07/28 22:57:01
Need to handle the else branch, right? (If the FT
nasko
2016/07/29 15:52:22
Done.
| |
| 843 } | |
| 844 } | |
| 845 | |
| 791 void NavigationEntryImpl::SetScreenshotPNGData( | 846 void NavigationEntryImpl::SetScreenshotPNGData( |
| 792 scoped_refptr<base::RefCountedBytes> png_data) { | 847 scoped_refptr<base::RefCountedBytes> png_data) { |
| 793 screenshot_ = png_data; | 848 screenshot_ = png_data; |
| 794 if (screenshot_.get()) | 849 if (screenshot_.get()) |
| 795 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 850 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
| 796 } | 851 } |
| 797 | 852 |
| 798 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 853 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
| 799 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 854 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
| 800 } | 855 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 811 return node; | 866 return node; |
| 812 | 867 |
| 813 // Enqueue any children and keep looking. | 868 // Enqueue any children and keep looking. |
| 814 for (auto* child : node->children) | 869 for (auto* child : node->children) |
| 815 work_queue.push(child); | 870 work_queue.push(child); |
| 816 } | 871 } |
| 817 return nullptr; | 872 return nullptr; |
| 818 } | 873 } |
| 819 | 874 |
| 820 } // namespace content | 875 } // namespace content |
| OLD | NEW |