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

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

Issue 1907443006: PlzNavigate: store POST data in the FrameNavigationEntry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/url_formatter/url_formatter.h" 17 #include "components/url_formatter/url_formatter.h"
18 #include "content/common/content_constants_internal.h" 18 #include "content/common/content_constants_internal.h"
19 #include "content/common/navigation_params.h" 19 #include "content/common/navigation_params.h"
20 #include "content/common/page_state_serialization.h" 20 #include "content/common/page_state_serialization.h"
21 #include "content/common/site_isolation_policy.h" 21 #include "content/common/site_isolation_policy.h"
22 #include "content/public/common/browser_side_navigation_policy.h"
22 #include "content/public/common/content_constants.h" 23 #include "content/public/common/content_constants.h"
23 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
24 #include "ui/gfx/text_elider.h" 25 #include "ui/gfx/text_elider.h"
25 26
26 using base::UTF16ToUTF8; 27 using base::UTF16ToUTF8;
27 28
28 namespace content { 29 namespace content {
29 30
30 namespace { 31 namespace {
31 32
32 // Use this to get a new unique ID for a NavigationEntry during construction. 33 // 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). 34 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator).
34 int GetUniqueIDInConstructor() { 35 int GetUniqueIDInConstructor() {
35 static int unique_id_counter = 0; 36 static int unique_id_counter = 0;
36 return ++unique_id_counter; 37 return ++unique_id_counter;
37 } 38 }
38 39
39 void RecursivelyGenerateFrameEntries(const ExplodedFrameState& state, 40 void RecursivelyGenerateFrameEntries(const ExplodedFrameState& state,
40 NavigationEntryImpl::TreeNode* node) { 41 NavigationEntryImpl::TreeNode* node) {
42 scoped_refptr<ResourceRequestBody> post_data = new ResourceRequestBody;
43 if (!GeneratePostData(state.http_body, post_data.get()))
44 post_data = nullptr;
41 node->frame_entry = new FrameNavigationEntry( 45 node->frame_entry = new FrameNavigationEntry(
42 -1, UTF16ToUTF8(state.target.string()), state.item_sequence_number, 46 -1, UTF16ToUTF8(state.target.string()), state.item_sequence_number,
43 state.document_sequence_number, nullptr, GURL(state.url_string.string()), 47 state.document_sequence_number, nullptr, GURL(state.url_string.string()),
44 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", 48 Referrer(GURL(state.referrer.string()), state.referrer_policy), "GET", -1,
45 -1); 49 post_data);
46 50
47 // Set a single-frame PageState on the entry. 51 // Set a single-frame PageState on the entry.
48 ExplodedPageState page_state; 52 ExplodedPageState page_state;
49 page_state.top = state; 53 page_state.top = state;
50 std::string data; 54 std::string data;
51 if (EncodePageState(page_state, &data)) 55 if (EncodePageState(page_state, &data))
52 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data)); 56 node->frame_entry->set_page_state(PageState::CreateFromEncodedData(data));
53 57
54 for (const ExplodedFrameState& child_state : state.children) { 58 for (const ExplodedFrameState& child_state : state.children) {
55 NavigationEntryImpl::TreeNode* child_node = 59 NavigationEntryImpl::TreeNode* child_node =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ui::PageTransition transition_type, 172 ui::PageTransition transition_type,
169 bool is_renderer_initiated) 173 bool is_renderer_initiated)
170 : frame_tree_(new TreeNode(new FrameNavigationEntry(-1, 174 : frame_tree_(new TreeNode(new FrameNavigationEntry(-1,
171 "", 175 "",
172 -1, 176 -1,
173 -1, 177 -1,
174 std::move(instance), 178 std::move(instance),
175 url, 179 url,
176 referrer, 180 referrer,
177 "GET", 181 "GET",
178 -1))), 182 -1,
183 nullptr))),
179 unique_id_(GetUniqueIDInConstructor()), 184 unique_id_(GetUniqueIDInConstructor()),
180 bindings_(kInvalidBindings), 185 bindings_(kInvalidBindings),
181 page_type_(PAGE_TYPE_NORMAL), 186 page_type_(PAGE_TYPE_NORMAL),
182 update_virtual_url_with_url_(false), 187 update_virtual_url_with_url_(false),
183 title_(title), 188 title_(title),
184 page_id_(page_id), 189 page_id_(page_id),
185 transition_type_(transition_type), 190 transition_type_(transition_type),
186 restore_type_(RESTORE_NONE), 191 restore_type_(RESTORE_NONE),
187 is_overriding_user_agent_(false), 192 is_overriding_user_agent_(false),
188 http_status_code_(0), 193 http_status_code_(0),
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 copy->redirect_chain_ = redirect_chain_; 571 copy->redirect_chain_ = redirect_chain_;
567 // ResetForCommit: should_clear_history_list_ 572 // ResetForCommit: should_clear_history_list_
568 // ResetForCommit: frame_tree_node_id_ 573 // ResetForCommit: frame_tree_node_id_
569 // ResetForCommit: intent_received_timestamp_ 574 // ResetForCommit: intent_received_timestamp_
570 copy->extra_data_ = extra_data_; 575 copy->extra_data_ = extra_data_;
571 576
572 return copy; 577 return copy;
573 } 578 }
574 579
575 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( 580 CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams(
581 const FrameNavigationEntry& frame_entry,
576 const GURL& dest_url, 582 const GURL& dest_url,
577 const Referrer& dest_referrer, 583 const Referrer& dest_referrer,
578 FrameMsg_Navigate_Type::Value navigation_type, 584 FrameMsg_Navigate_Type::Value navigation_type,
579 LoFiState lofi_state, 585 LoFiState lofi_state,
580 const base::TimeTicks& navigation_start) const { 586 const base::TimeTicks& navigation_start) const {
581 FrameMsg_UILoadMetricsReportType::Value report_type = 587 FrameMsg_UILoadMetricsReportType::Value report_type =
582 FrameMsg_UILoadMetricsReportType::NO_REPORT; 588 FrameMsg_UILoadMetricsReportType::NO_REPORT;
583 base::TimeTicks ui_timestamp = base::TimeTicks(); 589 base::TimeTicks ui_timestamp = base::TimeTicks();
584 #if defined(OS_ANDROID) 590 #if defined(OS_ANDROID)
585 if (!intent_received_timestamp().is_null()) 591 if (!intent_received_timestamp().is_null())
586 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; 592 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT;
587 ui_timestamp = intent_received_timestamp(); 593 ui_timestamp = intent_received_timestamp();
588 #endif 594 #endif
589 595
596 std::string method;
597
598 if (IsBrowserSideNavigationEnabled())
599 method = frame_entry.method();
600 else
601 method = GetHasPostData() ? "POST" : "GET";
602
590 return CommonNavigationParams( 603 return CommonNavigationParams(
591 dest_url, dest_referrer, GetTransitionType(), navigation_type, 604 dest_url, dest_referrer, GetTransitionType(), navigation_type,
592 !IsViewSourceMode(), should_replace_entry(), ui_timestamp, report_type, 605 !IsViewSourceMode(), should_replace_entry(), ui_timestamp, report_type,
593 GetBaseURLForDataURL(), GetHistoryURLForDataURL(), lofi_state, 606 GetBaseURLForDataURL(), GetHistoryURLForDataURL(), lofi_state,
594 navigation_start, GetHasPostData() ? "POST" : "GET"); 607 navigation_start, method);
595 } 608 }
596 609
597 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams() 610 StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams()
598 const { 611 const {
599 std::vector<unsigned char> browser_initiated_post_data; 612 std::vector<unsigned char> browser_initiated_post_data;
600 if (GetBrowserInitiatedPostData()) { 613 if (GetBrowserInitiatedPostData()) {
601 browser_initiated_post_data.assign( 614 browser_initiated_post_data.assign(
602 GetBrowserInitiatedPostData()->front(), 615 GetBrowserInitiatedPostData()->front(),
603 GetBrowserInitiatedPostData()->front() + 616 GetBrowserInitiatedPostData()->front() +
604 GetBrowserInitiatedPostData()->size()); 617 GetBrowserInitiatedPostData()->size());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 void NavigationEntryImpl::AddOrUpdateFrameEntry( 700 void NavigationEntryImpl::AddOrUpdateFrameEntry(
688 FrameTreeNode* frame_tree_node, 701 FrameTreeNode* frame_tree_node,
689 const std::string& frame_unique_name, 702 const std::string& frame_unique_name,
690 int64_t item_sequence_number, 703 int64_t item_sequence_number,
691 int64_t document_sequence_number, 704 int64_t document_sequence_number,
692 SiteInstanceImpl* site_instance, 705 SiteInstanceImpl* site_instance,
693 const GURL& url, 706 const GURL& url,
694 const Referrer& referrer, 707 const Referrer& referrer,
695 const PageState& page_state, 708 const PageState& page_state,
696 const std::string& method, 709 const std::string& method,
697 int64_t post_id) { 710 int64_t post_id,
711 scoped_refptr<ResourceRequestBody> post_data) {
698 // We should already have a TreeNode for the parent node by the time this node 712 // We should already have a TreeNode for the parent node by the time this node
699 // commits. Find it first. 713 // commits. Find it first.
700 DCHECK(frame_tree_node->parent()); 714 DCHECK(frame_tree_node->parent());
701 NavigationEntryImpl::TreeNode* parent_node = 715 NavigationEntryImpl::TreeNode* parent_node =
702 FindFrameEntry(frame_tree_node->parent()); 716 FindFrameEntry(frame_tree_node->parent());
703 if (!parent_node) { 717 if (!parent_node) {
704 // The renderer should not send a commit for a subframe before its parent. 718 // The renderer should not send a commit for a subframe before its parent.
705 // TODO(creis): Kill the renderer if we get here. 719 // TODO(creis): Kill the renderer if we get here.
706 return; 720 return;
707 } 721 }
708 722
709 // Now check whether we have a TreeNode for the node itself. 723 // Now check whether we have a TreeNode for the node itself.
710 int frame_tree_node_id = frame_tree_node->frame_tree_node_id(); 724 int frame_tree_node_id = frame_tree_node->frame_tree_node_id();
711 for (TreeNode* child : parent_node->children) { 725 for (TreeNode* child : parent_node->children) {
712 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) { 726 if (child->frame_entry->frame_tree_node_id() == frame_tree_node_id) {
713 // Update the existing FrameNavigationEntry (e.g., for replaceState). 727 // Update the existing FrameNavigationEntry (e.g., for replaceState).
714 child->frame_entry->UpdateEntry( 728 child->frame_entry->UpdateEntry(
715 frame_unique_name, item_sequence_number, document_sequence_number, 729 frame_unique_name, item_sequence_number, document_sequence_number,
716 site_instance, url, referrer, page_state, method, post_id); 730 site_instance, url, referrer, page_state, method, post_id, post_data);
717 return; 731 return;
718 } 732 }
719 } 733 }
720 734
721 // No entry exists yet, so create a new one. 735 // No entry exists yet, so create a new one.
722 // Unordered list, since we expect to look up entries by frame sequence number 736 // Unordered list, since we expect to look up entries by frame sequence number
723 // or unique name. 737 // or unique name.
724 FrameNavigationEntry* frame_entry = new FrameNavigationEntry( 738 FrameNavigationEntry* frame_entry = new FrameNavigationEntry(
725 frame_tree_node_id, frame_unique_name, item_sequence_number, 739 frame_tree_node_id, frame_unique_name, item_sequence_number,
726 document_sequence_number, site_instance, url, referrer, method, post_id); 740 document_sequence_number, site_instance, url, referrer, method, post_id,
741 post_data);
727 frame_entry->set_page_state(page_state); 742 frame_entry->set_page_state(page_state);
728 parent_node->children.push_back( 743 parent_node->children.push_back(
729 new NavigationEntryImpl::TreeNode(frame_entry)); 744 new NavigationEntryImpl::TreeNode(frame_entry));
730 } 745 }
731 746
732 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry( 747 FrameNavigationEntry* NavigationEntryImpl::GetFrameEntry(
733 FrameTreeNode* frame_tree_node) const { 748 FrameTreeNode* frame_tree_node) const {
734 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node); 749 NavigationEntryImpl::TreeNode* tree_node = FindFrameEntry(frame_tree_node);
735 return tree_node ? tree_node->frame_entry.get() : nullptr; 750 return tree_node ? tree_node->frame_entry.get() : nullptr;
736 } 751 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 return node; 794 return node;
780 } 795 }
781 // Enqueue any children and keep looking. 796 // Enqueue any children and keep looking.
782 for (auto& child : node->children) 797 for (auto& child : node->children)
783 work_queue.push(child); 798 work_queue.push(child);
784 } 799 }
785 return nullptr; 800 return nullptr;
786 } 801 }
787 802
788 } // namespace content 803 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698