| 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 22 matching lines...) Expand all Loading... |
| 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 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, nullptr, |
| 44 GURL(state.url_string.string()), |
| 44 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", | 45 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", |
| 45 -1); | 46 -1); |
| 46 | 47 |
| 47 // Set a single-frame PageState on the entry. | 48 // Set a single-frame PageState on the entry. |
| 48 ExplodedPageState page_state; | 49 ExplodedPageState page_state; |
| 49 page_state.top = state; | 50 page_state.top = state; |
| 50 std::string data; | 51 std::string data; |
| 51 if (EncodePageState(page_state, &data)) | 52 if (EncodePageState(page_state, &data)) |
| 52 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); | 53 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); |
| 53 | 54 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 int page_id, | 166 int page_id, |
| 166 const GURL& url, | 167 const GURL& url, |
| 167 const Referrer& referrer, | 168 const Referrer& referrer, |
| 168 const base::string16& title, | 169 const base::string16& title, |
| 169 ui::PageTransition transition_type, | 170 ui::PageTransition transition_type, |
| 170 bool is_renderer_initiated) | 171 bool is_renderer_initiated) |
| 171 : frame_tree_(new TreeNode(new FrameNavigationEntry("", | 172 : frame_tree_(new TreeNode(new FrameNavigationEntry("", |
| 172 -1, | 173 -1, |
| 173 -1, | 174 -1, |
| 174 std::move(instance), | 175 std::move(instance), |
| 176 nullptr, |
| 175 url, | 177 url, |
| 176 referrer, | 178 referrer, |
| 177 "GET", | 179 "GET", |
| 178 -1))), | 180 -1))), |
| 179 unique_id_(GetUniqueIDInConstructor()), | 181 unique_id_(GetUniqueIDInConstructor()), |
| 180 bindings_(kInvalidBindings), | 182 bindings_(kInvalidBindings), |
| 181 page_type_(PAGE_TYPE_NORMAL), | 183 page_type_(PAGE_TYPE_NORMAL), |
| 182 update_virtual_url_with_url_(false), | 184 update_virtual_url_with_url_(false), |
| 183 title_(title), | 185 title_(title), |
| 184 page_id_(page_id), | 186 page_id_(page_id), |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 int32_t NavigationEntryImpl::GetPageID() const { | 328 int32_t NavigationEntryImpl::GetPageID() const { |
| 327 return page_id_; | 329 return page_id_; |
| 328 } | 330 } |
| 329 | 331 |
| 330 void NavigationEntryImpl::set_site_instance( | 332 void NavigationEntryImpl::set_site_instance( |
| 331 scoped_refptr<SiteInstanceImpl> site_instance) { | 333 scoped_refptr<SiteInstanceImpl> site_instance) { |
| 332 // TODO(creis): Update all callers and remove this method. | 334 // TODO(creis): Update all callers and remove this method. |
| 333 frame_tree_->frame_entry->set_site_instance(std::move(site_instance)); | 335 frame_tree_->frame_entry->set_site_instance(std::move(site_instance)); |
| 334 } | 336 } |
| 335 | 337 |
| 336 void NavigationEntryImpl::set_source_site_instance( | |
| 337 SiteInstanceImpl* source_site_instance) { | |
| 338 source_site_instance_ = source_site_instance; | |
| 339 } | |
| 340 | |
| 341 void NavigationEntryImpl::SetBindings(int bindings) { | 338 void NavigationEntryImpl::SetBindings(int bindings) { |
| 342 // Ensure this is set to a valid value, and that it stays the same once set. | 339 // Ensure this is set to a valid value, and that it stays the same once set. |
| 343 CHECK_NE(bindings, kInvalidBindings); | 340 CHECK_NE(bindings, kInvalidBindings); |
| 344 CHECK(bindings_ == kInvalidBindings || bindings_ == bindings); | 341 CHECK(bindings_ == kInvalidBindings || bindings_ == bindings); |
| 345 bindings_ = bindings; | 342 bindings_ = bindings; |
| 346 } | 343 } |
| 347 | 344 |
| 348 const base::string16& NavigationEntryImpl::GetTitleForDisplay() const { | 345 const base::string16& NavigationEntryImpl::GetTitleForDisplay() const { |
| 349 // Most pages have real titles. Don't even bother caching anything if this is | 346 // Most pages have real titles. Don't even bother caching anything if this is |
| 350 // the case. | 347 // the case. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 copy->transition_type_ = transition_type_; | 544 copy->transition_type_ = transition_type_; |
| 548 copy->user_typed_url_ = user_typed_url_; | 545 copy->user_typed_url_ = user_typed_url_; |
| 549 copy->restore_type_ = restore_type_; | 546 copy->restore_type_ = restore_type_; |
| 550 copy->original_request_url_ = original_request_url_; | 547 copy->original_request_url_ = original_request_url_; |
| 551 copy->is_overriding_user_agent_ = is_overriding_user_agent_; | 548 copy->is_overriding_user_agent_ = is_overriding_user_agent_; |
| 552 copy->timestamp_ = timestamp_; | 549 copy->timestamp_ = timestamp_; |
| 553 copy->http_status_code_ = http_status_code_; | 550 copy->http_status_code_ = http_status_code_; |
| 554 // ResetForCommit: browser_initiated_post_data_ | 551 // ResetForCommit: browser_initiated_post_data_ |
| 555 copy->screenshot_ = screenshot_; | 552 copy->screenshot_ = screenshot_; |
| 556 copy->extra_headers_ = extra_headers_; | 553 copy->extra_headers_ = extra_headers_; |
| 557 // ResetForCommit: source_site_instance_ | |
| 558 copy->base_url_for_data_url_ = base_url_for_data_url_; | 554 copy->base_url_for_data_url_ = base_url_for_data_url_; |
| 559 #if defined(OS_ANDROID) | 555 #if defined(OS_ANDROID) |
| 560 copy->data_url_as_string_ = data_url_as_string_; | 556 copy->data_url_as_string_ = data_url_as_string_; |
| 561 #endif | 557 #endif |
| 562 // ResetForCommit: is_renderer_initiated_ | 558 // ResetForCommit: is_renderer_initiated_ |
| 563 copy->cached_display_title_ = cached_display_title_; | 559 copy->cached_display_title_ = cached_display_title_; |
| 564 // ResetForCommit: transferred_global_request_id_ | 560 // ResetForCommit: transferred_global_request_id_ |
| 565 // ResetForCommit: should_replace_entry_ | 561 // ResetForCommit: should_replace_entry_ |
| 566 copy->redirect_chain_ = redirect_chain_; | 562 copy->redirect_chain_ = redirect_chain_; |
| 567 // ResetForCommit: should_clear_history_list_ | 563 // ResetForCommit: should_clear_history_list_ |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 GURL data_url(std::string( | 652 GURL data_url(std::string( |
| 657 GetDataURLAsString()->front_as<char>(), | 653 GetDataURLAsString()->front_as<char>(), |
| 658 std::min(GetDataURLAsString()->size(), kDataUriPrefixMaxLen))); | 654 std::min(GetDataURLAsString()->size(), kDataUriPrefixMaxLen))); |
| 659 if (data_url.is_valid() && data_url.SchemeIs(url::kDataScheme)) | 655 if (data_url.is_valid() && data_url.SchemeIs(url::kDataScheme)) |
| 660 request_params.data_url_as_string = GetDataURLAsString()->data(); | 656 request_params.data_url_as_string = GetDataURLAsString()->data(); |
| 661 } | 657 } |
| 662 #endif | 658 #endif |
| 663 return request_params; | 659 return request_params; |
| 664 } | 660 } |
| 665 | 661 |
| 666 void NavigationEntryImpl::ResetForCommit() { | 662 void NavigationEntryImpl::ResetForCommit(FrameNavigationEntry* frame_entry) { |
| 667 // Any state that only matters when a navigation entry is pending should be | 663 // Any state that only matters when a navigation entry is pending should be |
| 668 // cleared here. | 664 // cleared here. |
| 669 // TODO(creis): This state should be moved to NavigationRequest once | 665 // TODO(creis): This state should be moved to NavigationRequest once |
| 670 // PlzNavigate is enabled. | 666 // PlzNavigate is enabled. |
| 671 SetBrowserInitiatedPostData(nullptr); | 667 SetBrowserInitiatedPostData(nullptr); |
| 672 set_source_site_instance(nullptr); | |
| 673 set_is_renderer_initiated(false); | 668 set_is_renderer_initiated(false); |
| 674 set_transferred_global_request_id(GlobalRequestID()); | 669 set_transferred_global_request_id(GlobalRequestID()); |
| 675 set_should_replace_entry(false); | 670 set_should_replace_entry(false); |
| 676 | 671 |
| 677 set_should_clear_history_list(false); | 672 set_should_clear_history_list(false); |
| 678 set_frame_tree_node_id(-1); | 673 set_frame_tree_node_id(-1); |
| 679 | 674 |
| 675 if (frame_entry) |
| 676 frame_entry->set_source_site_instance(nullptr); |
| 677 |
| 680 #if defined(OS_ANDROID) | 678 #if defined(OS_ANDROID) |
| 681 // Reset the time stamp so that the metrics are not reported if this entry is | 679 // Reset the time stamp so that the metrics are not reported if this entry is |
| 682 // loaded again in the future. | 680 // loaded again in the future. |
| 683 set_intent_received_timestamp(base::TimeTicks()); | 681 set_intent_received_timestamp(base::TimeTicks()); |
| 684 #endif | 682 #endif |
| 685 } | 683 } |
| 686 | 684 |
| 687 void NavigationEntryImpl::AddOrUpdateFrameEntry( | 685 void NavigationEntryImpl::AddOrUpdateFrameEntry( |
| 688 FrameTreeNode* frame_tree_node, | 686 FrameTreeNode* frame_tree_node, |
| 689 int64_t item_sequence_number, | 687 int64_t item_sequence_number, |
| 690 int64_t document_sequence_number, | 688 int64_t document_sequence_number, |
| 691 SiteInstanceImpl* site_instance, | 689 SiteInstanceImpl* site_instance, |
| 690 scoped_refptr<SiteInstanceImpl> source_site_instance, |
| 692 const GURL& url, | 691 const GURL& url, |
| 693 const Referrer& referrer, | 692 const Referrer& referrer, |
| 694 const PageState& page_state, | 693 const PageState& page_state, |
| 695 const std::string& method, | 694 const std::string& method, |
| 696 int64_t post_id) { | 695 int64_t post_id) { |
| 697 // We should already have a TreeNode for the parent node by the time this node | 696 // We should already have a TreeNode for the parent node by the time this node |
| 698 // commits. Find it first. | 697 // commits. Find it first. |
| 699 DCHECK(frame_tree_node->parent()); | 698 DCHECK(frame_tree_node->parent()); |
| 700 NavigationEntryImpl::TreeNode* parent_node = | 699 NavigationEntryImpl::TreeNode* parent_node = |
| 701 FindFrameEntry(frame_tree_node->parent()); | 700 FindFrameEntry(frame_tree_node->parent()); |
| 702 if (!parent_node) { | 701 if (!parent_node) { |
| 703 // The renderer should not send a commit for a subframe before its parent. | 702 // The renderer should not send a commit for a subframe before its parent. |
| 704 // TODO(creis): Kill the renderer if we get here. | 703 // TODO(creis): Kill the renderer if we get here. |
| 705 return; | 704 return; |
| 706 } | 705 } |
| 707 | 706 |
| 708 // Now check whether we have a TreeNode for the node itself. | 707 // Now check whether we have a TreeNode for the node itself. |
| 709 const std::string& unique_name = frame_tree_node->unique_name(); | 708 const std::string& unique_name = frame_tree_node->unique_name(); |
| 710 for (TreeNode* child : parent_node->children) { | 709 for (TreeNode* child : parent_node->children) { |
| 711 if (child->frame_entry->frame_unique_name() == unique_name) { | 710 if (child->frame_entry->frame_unique_name() == unique_name) { |
| 712 // Update the existing FrameNavigationEntry (e.g., for replaceState). | 711 // Update the existing FrameNavigationEntry (e.g., for replaceState). |
| 713 child->frame_entry->UpdateEntry( | 712 child->frame_entry->UpdateEntry(unique_name, item_sequence_number, |
| 714 unique_name, item_sequence_number, document_sequence_number, | 713 document_sequence_number, site_instance, |
| 715 site_instance, url, referrer, page_state, method, post_id); | 714 std::move(source_site_instance), url, |
| 715 referrer, page_state, method, post_id); |
| 716 return; | 716 return; |
| 717 } | 717 } |
| 718 } | 718 } |
| 719 | 719 |
| 720 // No entry exists yet, so create a new one. | 720 // No entry exists yet, so create a new one. |
| 721 // 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 |
| 722 // or unique name. | 722 // or unique name. |
| 723 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( | 723 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( |
| 724 unique_name, item_sequence_number, document_sequence_number, | 724 unique_name, item_sequence_number, document_sequence_number, |
| 725 site_instance, url, referrer, method, post_id); | 725 site_instance, std::move(source_site_instance), url, referrer, method, |
| 726 post_id); |
| 726 frame_entry->set_page_state(page_state); | 727 frame_entry->set_page_state(page_state); |
| 727 parent_node->children.push_back( | 728 parent_node->children.push_back( |
| 728 new NavigationEntryImpl::TreeNode(frame_entry)); | 729 new NavigationEntryImpl::TreeNode(frame_entry)); |
| 729 } | 730 } |
| 730 | 731 |
| 731 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( | 732 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( |
| 732 FrameTreeNode* frame_tree_node) const { | 733 FrameTreeNode* frame_tree_node) const { |
| 733 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); | 734 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); |
| 734 return tree_node ? tree_node->frame_entry.get() : nullptr; | 735 return tree_node ? tree_node->frame_entry.get() : nullptr; |
| 735 } | 736 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 757 return node; | 758 return node; |
| 758 | 759 |
| 759 // Enqueue any children and keep looking. | 760 // Enqueue any children and keep looking. |
| 760 for (auto& child : node->children) | 761 for (auto& child : node->children) |
| 761 work_queue.push(child); | 762 work_queue.push(child); |
| 762 } | 763 } |
| 763 return nullptr; | 764 return nullptr; |
| 764 } | 765 } |
| 765 | 766 |
| 766 } // namespace content | 767 } // namespace content |
| OLD | NEW |