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 21 matching lines...) Expand all Loading... |
32 // Use this to get a new unique ID for a NavigationEntry during construction. | 32 // Use this to get a new unique ID for a NavigationEntry during construction. |
33 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | 33 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
34 int GetUniqueIDInConstructor() { | 34 int GetUniqueIDInConstructor() { |
35 static int unique_id_counter = 0; | 35 static int unique_id_counter = 0; |
36 return ++unique_id_counter; | 36 return ++unique_id_counter; |
37 } | 37 } |
38 | 38 |
39 void RecursivelyGenerateFrameEntries(const ExplodedFrameState& state, | 39 void RecursivelyGenerateFrameEntries(const ExplodedFrameState& state, |
40 NavigationEntryImpl::TreeNode* node) { | 40 NavigationEntryImpl::TreeNode* node) { |
41 node->frame_entry = new FrameNavigationEntry( | 41 node->frame_entry = new FrameNavigationEntry( |
42 -1, UTF16ToUTF8(state.target.string()), state.item_sequence_number, | 42 UTF16ToUTF8(state.target.string()), state.item_sequence_number, |
43 state.document_sequence_number, nullptr, GURL(state.url_string.string()), | 43 state.document_sequence_number, nullptr, GURL(state.url_string.string()), |
44 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", | 44 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", |
45 -1); | 45 -1); |
46 | 46 |
47 // Set a single-frame PageState on the entry. | 47 // Set a single-frame PageState on the entry. |
48 ExplodedPageState page_state; | 48 ExplodedPageState page_state; |
49 page_state.top = state; | 49 page_state.top = state; |
50 std::string data; | 50 std::string data; |
51 if (EncodePageState(page_state, &data)) | 51 if (EncodePageState(page_state, &data)) |
52 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); | 52 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 int NavigationEntryImpl::kInvalidBindings = -1; | 94 int NavigationEntryImpl::kInvalidBindings = -1; |
95 | 95 |
96 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) | 96 NavigationEntryImpl::TreeNode::TreeNode(FrameNavigationEntry* frame_entry) |
97 : frame_entry(frame_entry) { | 97 : frame_entry(frame_entry) { |
98 } | 98 } |
99 | 99 |
100 NavigationEntryImpl::TreeNode::~TreeNode() { | 100 NavigationEntryImpl::TreeNode::~TreeNode() { |
101 } | 101 } |
102 | 102 |
103 bool NavigationEntryImpl::TreeNode::MatchesFrame( | 103 bool NavigationEntryImpl::TreeNode::MatchesFrame(FrameTreeNode* frame_tree_node, |
104 FrameTreeNode* frame_tree_node) const { | 104 bool is_root_tree_node) const { |
105 if (frame_tree_node->frame_tree_node_id() == | 105 // The root node is for the main frame whether the unique name matches or not. |
106 frame_entry->frame_tree_node_id()) | 106 if (is_root_tree_node) |
107 return true; | 107 return frame_tree_node->IsMainFrame(); |
108 | 108 |
109 // For now, we set the root FNE's FrameTreeNode ID to -1. | 109 // Otherwise check the unique name for subframes. |
110 return frame_tree_node->IsMainFrame() && | 110 return !frame_tree_node->IsMainFrame() && |
111 frame_entry->frame_tree_node_id() == -1; | 111 frame_tree_node->unique_name() == frame_entry->frame_unique_name(); |
112 } | 112 } |
113 | 113 |
114 std::unique_ptr<NavigationEntryImpl::TreeNode> | 114 std::unique_ptr<NavigationEntryImpl::TreeNode> |
115 NavigationEntryImpl::TreeNode::CloneAndReplace( | 115 NavigationEntryImpl::TreeNode::CloneAndReplace( |
116 FrameTreeNode* frame_tree_node, | 116 FrameTreeNode* frame_tree_node, |
117 FrameNavigationEntry* frame_navigation_entry) const { | 117 FrameNavigationEntry* frame_navigation_entry, |
118 if (frame_tree_node && MatchesFrame(frame_tree_node)) { | 118 bool is_root_tree_node) const { |
| 119 if (frame_tree_node && MatchesFrame(frame_tree_node, is_root_tree_node)) { |
119 // Replace this node in the cloned tree and prune its children. | 120 // Replace this node in the cloned tree and prune its children. |
120 return base::WrapUnique( | 121 return base::WrapUnique( |
121 new NavigationEntryImpl::TreeNode(frame_navigation_entry)); | 122 new NavigationEntryImpl::TreeNode(frame_navigation_entry)); |
122 } | 123 } |
123 | 124 |
124 // Clone the tree using a copy of the FrameNavigationEntry, without sharing. | 125 // Clone the tree using a copy of the FrameNavigationEntry, without sharing. |
125 // TODO(creis): Share FNEs unless it's for another tab. | 126 // TODO(creis): Share FNEs unless it's for another tab. |
126 std::unique_ptr<NavigationEntryImpl::TreeNode> copy( | 127 std::unique_ptr<NavigationEntryImpl::TreeNode> copy( |
127 new NavigationEntryImpl::TreeNode(frame_entry->Clone())); | 128 new NavigationEntryImpl::TreeNode(frame_entry->Clone())); |
128 | 129 |
129 // Recursively clone the children. | 130 // Recursively clone the children. |
130 for (auto& child : children) { | 131 for (auto& child : children) { |
131 copy->children.push_back( | 132 copy->children.push_back( |
132 child->CloneAndReplace(frame_tree_node, frame_navigation_entry)); | 133 child->CloneAndReplace(frame_tree_node, frame_navigation_entry, false)); |
133 } | 134 } |
134 | 135 |
135 return copy; | 136 return copy; |
136 } | 137 } |
137 | 138 |
138 std::unique_ptr<NavigationEntry> NavigationEntry::Create() { | 139 std::unique_ptr<NavigationEntry> NavigationEntry::Create() { |
139 return base::WrapUnique(new NavigationEntryImpl()); | 140 return base::WrapUnique(new NavigationEntryImpl()); |
140 } | 141 } |
141 | 142 |
142 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | 143 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( |
(...skipping 17 matching lines...) Expand all Loading... |
160 } | 161 } |
161 | 162 |
162 NavigationEntryImpl::NavigationEntryImpl( | 163 NavigationEntryImpl::NavigationEntryImpl( |
163 scoped_refptr<SiteInstanceImpl> instance, | 164 scoped_refptr<SiteInstanceImpl> instance, |
164 int page_id, | 165 int page_id, |
165 const GURL& url, | 166 const GURL& url, |
166 const Referrer& referrer, | 167 const Referrer& referrer, |
167 const base::string16& title, | 168 const base::string16& title, |
168 ui::PageTransition transition_type, | 169 ui::PageTransition transition_type, |
169 bool is_renderer_initiated) | 170 bool is_renderer_initiated) |
170 : frame_tree_(new TreeNode(new FrameNavigationEntry(-1, | 171 : frame_tree_(new TreeNode(new FrameNavigationEntry("", |
171 "", | |
172 -1, | 172 -1, |
173 -1, | 173 -1, |
174 std::move(instance), | 174 std::move(instance), |
175 url, | 175 url, |
176 referrer, | 176 referrer, |
177 "GET", | 177 "GET", |
178 -1))), | 178 -1))), |
179 unique_id_(GetUniqueIDInConstructor()), | 179 unique_id_(GetUniqueIDInConstructor()), |
180 bindings_(kInvalidBindings), | 180 bindings_(kInvalidBindings), |
181 page_type_(PAGE_TYPE_NORMAL), | 181 page_type_(PAGE_TYPE_NORMAL), |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 524 } |
525 | 525 |
526 std::unique_ptr<NavigationEntryImpl> NavigationEntryImpl::CloneAndReplace( | 526 std::unique_ptr<NavigationEntryImpl> NavigationEntryImpl::CloneAndReplace( |
527 FrameTreeNode* frame_tree_node, | 527 FrameTreeNode* frame_tree_node, |
528 FrameNavigationEntry* frame_navigation_entry) const { | 528 FrameNavigationEntry* frame_navigation_entry) const { |
529 std::unique_ptr<NavigationEntryImpl> copy = | 529 std::unique_ptr<NavigationEntryImpl> copy = |
530 base::WrapUnique(new NavigationEntryImpl()); | 530 base::WrapUnique(new NavigationEntryImpl()); |
531 | 531 |
532 // TODO(creis): Only share the same FrameNavigationEntries if cloning within | 532 // TODO(creis): Only share the same FrameNavigationEntries if cloning within |
533 // the same tab. | 533 // the same tab. |
534 copy->frame_tree_ = | 534 copy->frame_tree_ = frame_tree_->CloneAndReplace( |
535 frame_tree_->CloneAndReplace(frame_tree_node, frame_navigation_entry); | 535 frame_tree_node, frame_navigation_entry, true); |
536 | 536 |
537 // Copy most state over, unless cleared in ResetForCommit. | 537 // Copy most state over, unless cleared in ResetForCommit. |
538 // Don't copy unique_id_, otherwise it won't be unique. | 538 // Don't copy unique_id_, otherwise it won't be unique. |
539 copy->bindings_ = bindings_; | 539 copy->bindings_ = bindings_; |
540 copy->page_type_ = page_type_; | 540 copy->page_type_ = page_type_; |
541 copy->virtual_url_ = virtual_url_; | 541 copy->virtual_url_ = virtual_url_; |
542 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; | 542 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; |
543 copy->title_ = title_; | 543 copy->title_ = title_; |
544 copy->favicon_ = favicon_; | 544 copy->favicon_ = favicon_; |
545 copy->page_id_ = page_id_; | 545 copy->page_id_ = page_id_; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 | 679 |
680 #if defined(OS_ANDROID) | 680 #if defined(OS_ANDROID) |
681 // Reset the time stamp so that the metrics are not reported if this entry is | 681 // Reset the time stamp so that the metrics are not reported if this entry is |
682 // loaded again in the future. | 682 // loaded again in the future. |
683 set_intent_received_timestamp(base::TimeTicks()); | 683 set_intent_received_timestamp(base::TimeTicks()); |
684 #endif | 684 #endif |
685 } | 685 } |
686 | 686 |
687 void NavigationEntryImpl::AddOrUpdateFrameEntry( | 687 void NavigationEntryImpl::AddOrUpdateFrameEntry( |
688 FrameTreeNode* frame_tree_node, | 688 FrameTreeNode* frame_tree_node, |
689 const std::string& frame_unique_name, | |
690 int64_t item_sequence_number, | 689 int64_t item_sequence_number, |
691 int64_t document_sequence_number, | 690 int64_t document_sequence_number, |
692 SiteInstanceImpl* site_instance, | 691 SiteInstanceImpl* site_instance, |
693 const GURL& url, | 692 const GURL& url, |
694 const Referrer& referrer, | 693 const Referrer& referrer, |
695 const PageState& page_state, | 694 const PageState& page_state, |
696 const std::string& method, | 695 const std::string& method, |
697 int64_t post_id) { | 696 int64_t post_id) { |
698 // We should already have a TreeNode for the parent node by the time this node | 697 // We should already have a TreeNode for the parent node by the time this node |
699 // commits. Find it first. | 698 // commits. Find it first. |
700 DCHECK(frame_tree_node->parent()); | 699 DCHECK(frame_tree_node->parent()); |
701 NavigationEntryImpl::TreeNode* parent_node = | 700 NavigationEntryImpl::TreeNode* parent_node = |
702 FindFrameEntry(frame_tree_node->parent()); | 701 FindFrameEntry(frame_tree_node->parent()); |
703 if (!parent_node) { | 702 if (!parent_node) { |
704 // The renderer should not send a commit for a subframe before its parent. | 703 // The renderer should not send a commit for a subframe before its parent. |
705 // TODO(creis): Kill the renderer if we get here. | 704 // TODO(creis): Kill the renderer if we get here. |
706 return; | 705 return; |
707 } | 706 } |
708 | 707 |
709 // Now check whether we have a TreeNode for the node itself. | 708 // Now check whether we have a TreeNode for the node itself. |
710 int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 709 const std::string& unique_name = frame_tree_node->unique_name(); |
711 for (TreeNode* child : parent_node->children) { | 710 for (TreeNode* child : parent_node->children) { |
712 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { | 711 if (child->frame_entry->frame_unique_name() == unique_name) { |
713 // Update the existing FrameNavigationEntry (e.g., for replaceState). | 712 // Update the existing FrameNavigationEntry (e.g., for replaceState). |
714 child->frame_entry->UpdateEntry( | 713 child->frame_entry->UpdateEntry( |
715 frame_unique_name, item_sequence_number, document_sequence_number, | 714 unique_name, item_sequence_number, document_sequence_number, |
716 site_instance, url, referrer, page_state, method, post_id); | 715 site_instance, url, referrer, page_state, method, post_id); |
717 return; | 716 return; |
718 } | 717 } |
719 } | 718 } |
720 | 719 |
721 // No entry exists yet, so create a new one. | 720 // No entry exists yet, so create a new one. |
722 // Unordered list, since we expect to look up entries by frame sequence number | 721 // Unordered list, since we expect to look up entries by frame sequence number |
723 // or unique name. | 722 // or unique name. |
724 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( | 723 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( |
725 frame_tree_node_id, frame_unique_name, item_sequence_number, | 724 unique_name, item_sequence_number, document_sequence_number, |
726 document_sequence_number, site_instance, url, referrer, method, post_id); | 725 site_instance, url, referrer, method, post_id); |
727 frame_entry->set_page_state(page_state); | 726 frame_entry->set_page_state(page_state); |
728 parent_node->children.push_back( | 727 parent_node->children.push_back( |
729 new NavigationEntryImpl::TreeNode(frame_entry)); | 728 new NavigationEntryImpl::TreeNode(frame_entry)); |
730 } | 729 } |
731 | 730 |
732 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( | 731 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( |
733 FrameTreeNode* frame_tree_node) const { | 732 FrameTreeNode* frame_tree_node) const { |
734 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 733 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
735 return tree_node ? tree_node->frame_entry.get() : nullptr; | 734 return tree_node ? tree_node->frame_entry.get() : nullptr; |
736 } | 735 } |
737 | 736 |
738 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntryByUniqueName( | |
739 const std::string& unique_name) const { | |
740 NavigationEntryImpl::TreeNode* node = nullptr; | |
741 std::queue<NavigationEntryImpl::TreeNode*> work_queue; | |
742 work_queue.push(root_node()); | |
743 while (!work_queue.empty()) { | |
744 node = work_queue.front(); | |
745 work_queue.pop(); | |
746 if (node->frame_entry->frame_unique_name() == unique_name) | |
747 return node->frame_entry.get(); | |
748 | |
749 // Enqueue any children and keep looking. | |
750 for (auto& child : node->children) | |
751 work_queue.push(child); | |
752 } | |
753 return nullptr; | |
754 } | |
755 | |
756 void NavigationEntryImpl::SetScreenshotPNGData( | 737 void NavigationEntryImpl::SetScreenshotPNGData( |
757 scoped_refptr<base::RefCountedBytes> png_data) { | 738 scoped_refptr<base::RefCountedBytes> png_data) { |
758 screenshot_ = png_data; | 739 screenshot_ = png_data; |
759 if (screenshot_.get()) | 740 if (screenshot_.get()) |
760 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 741 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
761 } | 742 } |
762 | 743 |
763 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { | 744 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { |
764 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); | 745 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); |
765 } | 746 } |
766 | 747 |
767 NavigationEntryImpl::TreeNode* NavigationEntryImpl::FindFrameEntry( | 748 NavigationEntryImpl::TreeNode* NavigationEntryImpl::FindFrameEntry( |
768 FrameTreeNode* frame_tree_node) const { | 749 FrameTreeNode* frame_tree_node) const { |
769 NavigationEntryImpl::TreeNode* node = nullptr; | 750 NavigationEntryImpl::TreeNode* node = nullptr; |
770 std::queue<NavigationEntryImpl::TreeNode*> work_queue; | 751 std::queue<NavigationEntryImpl::TreeNode*> work_queue; |
771 work_queue.push(root_node()); | 752 work_queue.push(root_node()); |
772 while (!work_queue.empty()) { | 753 while (!work_queue.empty()) { |
773 node = work_queue.front(); | 754 node = work_queue.front(); |
774 work_queue.pop(); | 755 work_queue.pop(); |
775 if (node->MatchesFrame(frame_tree_node)) { | 756 if (node->MatchesFrame(frame_tree_node, node == root_node())) |
776 // Only the root TreeNode should have a FTN ID of -1. | |
777 DCHECK(node->frame_entry->frame_tree_node_id() != -1 || | |
778 node == root_node()); | |
779 return node; | 757 return node; |
780 } | 758 |
781 // Enqueue any children and keep looking. | 759 // Enqueue any children and keep looking. |
782 for (auto& child : node->children) | 760 for (auto& child : node->children) |
783 work_queue.push(child); | 761 work_queue.push(child); |
784 } | 762 } |
785 return nullptr; | 763 return nullptr; |
786 } | 764 } |
787 | 765 |
788 } // namespace content | 766 } // namespace content |
OLD | NEW |