Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: content/browser/frame_host/navigation_entry_impl.cc

Issue 1906213003: OOPIF: Fix subframe back/forward after recreating FTNs (try #2). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up and add tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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->current_replication_state().unique_name ==
alexmos 2016/04/28 01:05:03 Would it make sense to add a FrameTreeNode::unique
Charlie Reis 2016/04/28 05:37:42 Good idea. Done.
112 frame_entry->frame_unique_name();
112 } 113 }
113 114
114 std::unique_ptr<NavigationEntryImpl::TreeNode> 115 std::unique_ptr<NavigationEntryImpl::TreeNode>
115 NavigationEntryImpl::TreeNode::CloneAndReplace( 116 NavigationEntryImpl::TreeNode::CloneAndReplace(
116 FrameTreeNode* frame_tree_node, 117 FrameTreeNode* frame_tree_node,
117 FrameNavigationEntry* frame_navigation_entry) const { 118 FrameNavigationEntry* frame_navigation_entry,
118 if (frame_tree_node && MatchesFrame(frame_tree_node)) { 119 bool is_root_tree_node) const {
120 if (frame_tree_node && MatchesFrame(frame_tree_node, is_root_tree_node)) {
119 // Replace this node in the cloned tree and prune its children. 121 // Replace this node in the cloned tree and prune its children.
120 return base::WrapUnique( 122 return base::WrapUnique(
121 new NavigationEntryImpl::TreeNode(frame_navigation_entry)); 123 new NavigationEntryImpl::TreeNode(frame_navigation_entry));
122 } 124 }
123 125
124 // Clone the tree using a copy of the FrameNavigationEntry, without sharing. 126 // Clone the tree using a copy of the FrameNavigationEntry, without sharing.
125 // TODO(creis): Share FNEs unless it's for another tab. 127 // TODO(creis): Share FNEs unless it's for another tab.
126 std::unique_ptr<NavigationEntryImpl::TreeNode> copy( 128 std::unique_ptr<NavigationEntryImpl::TreeNode> copy(
127 new NavigationEntryImpl::TreeNode(frame_entry->Clone())); 129 new NavigationEntryImpl::TreeNode(frame_entry->Clone()));
128 130
129 // Recursively clone the children. 131 // Recursively clone the children.
130 for (auto& child : children) { 132 for (auto& child : children) {
131 copy->children.push_back( 133 copy->children.push_back(
132 child->CloneAndReplace(frame_tree_node, frame_navigation_entry)); 134 child->CloneAndReplace(frame_tree_node, frame_navigation_entry, false));
133 } 135 }
134 136
135 return copy; 137 return copy;
136 } 138 }
137 139
138 std::unique_ptr<NavigationEntry> NavigationEntry::Create() { 140 std::unique_ptr<NavigationEntry> NavigationEntry::Create() {
139 return base::WrapUnique(new NavigationEntryImpl()); 141 return base::WrapUnique(new NavigationEntryImpl());
140 } 142 }
141 143
142 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( 144 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry(
(...skipping 17 matching lines...) Expand all
160 } 162 }
161 163
162 NavigationEntryImpl::NavigationEntryImpl( 164 NavigationEntryImpl::NavigationEntryImpl(
163 scoped_refptr<SiteInstanceImpl> instance, 165 scoped_refptr<SiteInstanceImpl> instance,
164 int page_id, 166 int page_id,
165 const GURL& url, 167 const GURL& url,
166 const Referrer& referrer, 168 const Referrer& referrer,
167 const base::string16& title, 169 const base::string16& title,
168 ui::PageTransition transition_type, 170 ui::PageTransition transition_type,
169 bool is_renderer_initiated) 171 bool is_renderer_initiated)
170 : frame_tree_(new TreeNode(new FrameNavigationEntry(-1, 172 : frame_tree_(new TreeNode(new FrameNavigationEntry("",
171 "",
172 -1, 173 -1,
173 -1, 174 -1,
174 std::move(instance), 175 std::move(instance),
175 url, 176 url,
176 referrer, 177 referrer,
177 "GET", 178 "GET",
178 -1))), 179 -1))),
179 unique_id_(GetUniqueIDInConstructor()), 180 unique_id_(GetUniqueIDInConstructor()),
180 bindings_(kInvalidBindings), 181 bindings_(kInvalidBindings),
181 page_type_(PAGE_TYPE_NORMAL), 182 page_type_(PAGE_TYPE_NORMAL),
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 525 }
525 526
526 std::unique_ptr<NavigationEntryImpl> NavigationEntryImpl::CloneAndReplace( 527 std::unique_ptr<NavigationEntryImpl> NavigationEntryImpl::CloneAndReplace(
527 FrameTreeNode* frame_tree_node, 528 FrameTreeNode* frame_tree_node,
528 FrameNavigationEntry* frame_navigation_entry) const { 529 FrameNavigationEntry* frame_navigation_entry) const {
529 std::unique_ptr<NavigationEntryImpl> copy = 530 std::unique_ptr<NavigationEntryImpl> copy =
530 base::WrapUnique(new NavigationEntryImpl()); 531 base::WrapUnique(new NavigationEntryImpl());
531 532
532 // TODO(creis): Only share the same FrameNavigationEntries if cloning within 533 // TODO(creis): Only share the same FrameNavigationEntries if cloning within
533 // the same tab. 534 // the same tab.
534 copy->frame_tree_ = 535 copy->frame_tree_ = frame_tree_->CloneAndReplace(
535 frame_tree_->CloneAndReplace(frame_tree_node, frame_navigation_entry); 536 frame_tree_node, frame_navigation_entry, true);
536 537
537 // Copy most state over, unless cleared in ResetForCommit. 538 // Copy most state over, unless cleared in ResetForCommit.
538 // Don't copy unique_id_, otherwise it won't be unique. 539 // Don't copy unique_id_, otherwise it won't be unique.
539 copy->bindings_ = bindings_; 540 copy->bindings_ = bindings_;
540 copy->page_type_ = page_type_; 541 copy->page_type_ = page_type_;
541 copy->virtual_url_ = virtual_url_; 542 copy->virtual_url_ = virtual_url_;
542 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_; 543 copy->update_virtual_url_with_url_ = update_virtual_url_with_url_;
543 copy->title_ = title_; 544 copy->title_ = title_;
544 copy->favicon_ = favicon_; 545 copy->favicon_ = favicon_;
545 copy->page_id_ = page_id_; 546 copy->page_id_ = page_id_;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 680
680 #if defined(OS_ANDROID) 681 #if defined(OS_ANDROID)
681 // Reset the time stamp so that the metrics are not reported if this entry is 682 // Reset the time stamp so that the metrics are not reported if this entry is
682 // loaded again in the future. 683 // loaded again in the future.
683 set_intent_received_timestamp(base::TimeTicks()); 684 set_intent_received_timestamp(base::TimeTicks());
684 #endif 685 #endif
685 } 686 }
686 687
687 void NavigationEntryImpl::AddOrUpdateFrameEntry( 688 void NavigationEntryImpl::AddOrUpdateFrameEntry(
688 FrameTreeNode* frame_tree_node, 689 FrameTreeNode* frame_tree_node,
689 const std::string& frame_unique_name,
690 int64_t item_sequence_number, 690 int64_t item_sequence_number,
691 int64_t document_sequence_number, 691 int64_t document_sequence_number,
692 SiteInstanceImpl* site_instance, 692 SiteInstanceImpl* site_instance,
693 const GURL& url, 693 const GURL& url,
694 const Referrer& referrer, 694 const Referrer& referrer,
695 const PageState& page_state, 695 const PageState& page_state,
696 const std::string& method, 696 const std::string& method,
697 int64_t post_id) { 697 int64_t post_id) {
698 // We should already have a TreeNode for the parent node by the time this node 698 // We should already have a TreeNode for the parent node by the time this node
699 // commits. Find it first. 699 // commits. Find it first.
700 DCHECK(frame_tree_node->parent()); 700 DCHECK(frame_tree_node->parent());
701 NavigationEntryImpl::TreeNode* parent_node = 701 NavigationEntryImpl::TreeNode* parent_node =
702 FindFrameEntry(frame_tree_node->parent()); 702 FindFrameEntry(frame_tree_node->parent());
703 if (!parent_node) { 703 if (!parent_node) {
704 // The renderer should not send a commit for a subframe before its parent. 704 // The renderer should not send a commit for a subframe before its parent.
705 // TODO(creis): Kill the renderer if we get here. 705 // TODO(creis): Kill the renderer if we get here.
706 return; 706 return;
707 } 707 }
708 708
709 // Now check whether we have a TreeNode for the node itself. 709 // Now check whether we have a TreeNode for the node itself.
710 int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); 710 const std::string& unique_name =
711 frame_tree_node->current_replication_state().unique_name;
711 for (TreeNode* child : parent_node->children) { 712 for (TreeNode* child : parent_node->children) {
712 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { 713 if (child->frame_entry->frame_unique_name() == unique_name) {
713 // Update the existing FrameNavigationEntry (e.g., for replaceState). 714 // Update the existing FrameNavigationEntry (e.g., for replaceState).
714 child->frame_entry->UpdateEntry( 715 child->frame_entry->UpdateEntry(
715 frame_unique_name, item_sequence_number, document_sequence_number, 716 unique_name, item_sequence_number, document_sequence_number,
716 site_instance, url, referrer, page_state, method, post_id); 717 site_instance, url, referrer, page_state, method, post_id);
717 return; 718 return;
718 } 719 }
719 } 720 }
720 721
721 // No entry exists yet, so create a new one. 722 // No entry exists yet, so create a new one.
722 // Unordered list, since we expect to look up entries by frame sequence number 723 // Unordered list, since we expect to look up entries by frame sequence number
723 // or unique name. 724 // or unique name.
724 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( 725 FrameNavigationEntry* frame_entry = new FrameNavigationEntry(
725 frame_tree_node_id, frame_unique_name, item_sequence_number, 726 unique_name, item_sequence_number, document_sequence_number,
726 document_sequence_number, site_instance, url, referrer, method, post_id); 727 site_instance, url, referrer, method, post_id);
727 frame_entry->set_page_state(page_state); 728 frame_entry->set_page_state(page_state);
728 parent_node->children.push_back( 729 parent_node->children.push_back(
729 new NavigationEntryImpl::TreeNode(frame_entry)); 730 new NavigationEntryImpl::TreeNode(frame_entry));
730 } 731 }
731 732
732 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( 733 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry(
733 FrameTreeNode* frame_tree_node) const { 734 FrameTreeNode* frame_tree_node) const {
734 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); 735 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node);
735 return tree_node ? tree_node->frame_entry.get() : nullptr; 736 return tree_node ? tree_node->frame_entry.get() : nullptr;
736 } 737 }
737 738
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( 739 void NavigationEntryImpl::SetScreenshotPNGData(
757 scoped_refptr<base::RefCountedBytes> png_data) { 740 scoped_refptr<base::RefCountedBytes> png_data) {
758 screenshot_ = png_data; 741 screenshot_ = png_data;
759 if (screenshot_.get()) 742 if (screenshot_.get())
760 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); 743 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size());
761 } 744 }
762 745
763 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const { 746 GURL NavigationEntryImpl::GetHistoryURLForDataURL() const {
764 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL(); 747 return GetBaseURLForDataURL().is_empty() ? GURL() : GetVirtualURL();
765 } 748 }
766 749
767 NavigationEntryImpl::TreeNode* NavigationEntryImpl::FindFrameEntry( 750 NavigationEntryImpl::TreeNode* NavigationEntryImpl::FindFrameEntry(
768 FrameTreeNode* frame_tree_node) const { 751 FrameTreeNode* frame_tree_node) const {
769 NavigationEntryImpl::TreeNode* node = nullptr; 752 NavigationEntryImpl::TreeNode* node = nullptr;
770 std::queue<NavigationEntryImpl::TreeNode*> work_queue; 753 std::queue<NavigationEntryImpl::TreeNode*> work_queue;
771 work_queue.push(root_node()); 754 work_queue.push(root_node());
772 while (!work_queue.empty()) { 755 while (!work_queue.empty()) {
773 node = work_queue.front(); 756 node = work_queue.front();
774 work_queue.pop(); 757 work_queue.pop();
775 if (node->MatchesFrame(frame_tree_node)) { 758 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; 759 return node;
780 } 760
781 // Enqueue any children and keep looking. 761 // Enqueue any children and keep looking.
782 for (auto& child : node->children) 762 for (auto& child : node->children)
783 work_queue.push(child); 763 work_queue.push(child);
784 } 764 }
785 return nullptr; 765 return nullptr;
786 } 766 }
787 767
788 } // namespace content 768 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698