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

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

Issue 1999943002: Moving HTTP POST body from StartNavigationParams to CommonNavigationParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback from clamy@. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 9 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
10 #include "content/browser/frame_host/frame_tree.h" 10 #include "content/browser/frame_host/frame_tree.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 NavigationControllerImpl* controller) { 76 NavigationControllerImpl* controller) {
77 // Copy existing headers and add necessary headers that may not be present 77 // Copy existing headers and add necessary headers that may not be present
78 // in the RequestNavigationParams. 78 // in the RequestNavigationParams.
79 net::HttpRequestHeaders headers; 79 net::HttpRequestHeaders headers;
80 headers.AddHeadersFromString(entry.extra_headers()); 80 headers.AddHeadersFromString(entry.extra_headers());
81 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, 81 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
82 GetContentClient()->GetUserAgent()); 82 GetContentClient()->GetUserAgent());
83 83
84 // Fill POST data in the request body. 84 // Fill POST data in the request body.
85 scoped_refptr<ResourceRequestBody> request_body; 85 scoped_refptr<ResourceRequestBody> request_body;
86 if (frame_entry.method() == "POST") { 86 if (frame_entry.method() == "POST")
87 request_body = frame_entry.GetPostData(); 87 request_body = frame_entry.GetPostData();
88 if (!request_body && entry.GetBrowserInitiatedPostData()) {
89 request_body = new ResourceRequestBody();
90 request_body->AppendBytes(
91 reinterpret_cast<const char*>(
92 entry.GetBrowserInitiatedPostData()->front()),
93 entry.GetBrowserInitiatedPostData()->size());
94 }
95 }
96 88
97 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 89 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
98 frame_tree_node, entry.ConstructCommonNavigationParams( 90 frame_tree_node, entry.ConstructCommonNavigationParams(
99 frame_entry, dest_url, dest_referrer, 91 frame_entry, request_body, dest_url, dest_referrer,
100 navigation_type, lofi_state, navigation_start), 92 navigation_type, lofi_state, navigation_start),
101 BeginNavigationParams(headers.ToString(), 93 BeginNavigationParams(headers.ToString(),
102 LoadFlagFromNavigationType(navigation_type), 94 LoadFlagFromNavigationType(navigation_type),
103 false, // has_user_gestures 95 false, // has_user_gestures
104 false, // skip_service_worker 96 false, // skip_service_worker
105 REQUEST_CONTEXT_TYPE_LOCATION), 97 REQUEST_CONTEXT_TYPE_LOCATION),
106 entry.ConstructRequestNavigationParams( 98 entry.ConstructRequestNavigationParams(
107 frame_entry, is_same_document_history_load, 99 frame_entry, is_same_document_history_load,
108 frame_tree_node->has_committed_real_load(), 100 frame_tree_node->has_committed_real_load(),
109 controller->GetPendingEntryIndex() == -1, 101 controller->GetPendingEntryIndex() == -1,
110 controller->GetIndexOfEntry(&entry), 102 controller->GetIndexOfEntry(&entry),
111 controller->GetLastCommittedEntryIndex(), 103 controller->GetLastCommittedEntryIndex(),
112 controller->GetEntryCount()), 104 controller->GetEntryCount()),
113 request_body, true, &frame_entry, &entry)); 105 true, &frame_entry, &entry));
114 return navigation_request; 106 return navigation_request;
115 } 107 }
116 108
117 // static 109 // static
118 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 110 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
119 FrameTreeNode* frame_tree_node, 111 FrameTreeNode* frame_tree_node,
120 const CommonNavigationParams& common_params, 112 const CommonNavigationParams& common_params,
121 const BeginNavigationParams& begin_params, 113 const BeginNavigationParams& begin_params,
122 scoped_refptr<ResourceRequestBody> body,
123 int current_history_list_offset, 114 int current_history_list_offset,
124 int current_history_list_length) { 115 int current_history_list_length) {
125 // TODO(clamy): Check if some PageState should be provided here. 116 // TODO(clamy): Check if some PageState should be provided here.
126 // TODO(clamy): See how we should handle override of the user agent when the 117 // TODO(clamy): See how we should handle override of the user agent when the
127 // navigation may start in a renderer and commit in another one. 118 // navigation may start in a renderer and commit in another one.
128 // TODO(clamy): See if the navigation start time should be measured in the 119 // TODO(clamy): See if the navigation start time should be measured in the
129 // renderer and sent to the browser instead of being measured here. 120 // renderer and sent to the browser instead of being measured here.
130 // TODO(clamy): The pending history list offset should be properly set. 121 // TODO(clamy): The pending history list offset should be properly set.
131 RequestNavigationParams request_params( 122 RequestNavigationParams request_params(
132 false, // is_overriding_user_agent 123 false, // is_overriding_user_agent
133 std::vector<GURL>(), // redirects 124 std::vector<GURL>(), // redirects
134 false, // can_load_local_resources 125 false, // can_load_local_resources
135 base::Time::Now(), // request_time 126 base::Time::Now(), // request_time
136 PageState(), // page_state 127 PageState(), // page_state
137 -1, // page_id 128 -1, // page_id
138 0, // nav_entry_id 129 0, // nav_entry_id
139 false, // is_same_document_history_load 130 false, // is_same_document_history_load
140 frame_tree_node->has_committed_real_load(), 131 frame_tree_node->has_committed_real_load(),
141 false, // intended_as_new_entry 132 false, // intended_as_new_entry
142 -1, // pending_history_list_offset 133 -1, // pending_history_list_offset
143 current_history_list_offset, current_history_list_length, 134 current_history_list_offset, current_history_list_length,
144 false, // is_view_source 135 false, // is_view_source
145 false); // should_clear_history_list 136 false); // should_clear_history_list
146 std::unique_ptr<NavigationRequest> navigation_request( 137 std::unique_ptr<NavigationRequest> navigation_request(
147 new NavigationRequest(frame_tree_node, common_params, begin_params, 138 new NavigationRequest(frame_tree_node, common_params, begin_params,
148 request_params, body, false, nullptr, nullptr)); 139 request_params, false, nullptr, nullptr));
149 return navigation_request; 140 return navigation_request;
150 } 141 }
151 142
152 NavigationRequest::NavigationRequest( 143 NavigationRequest::NavigationRequest(
153 FrameTreeNode* frame_tree_node, 144 FrameTreeNode* frame_tree_node,
154 const CommonNavigationParams& common_params, 145 const CommonNavigationParams& common_params,
155 const BeginNavigationParams& begin_params, 146 const BeginNavigationParams& begin_params,
156 const RequestNavigationParams& request_params, 147 const RequestNavigationParams& request_params,
157 scoped_refptr<ResourceRequestBody> body,
158 bool browser_initiated, 148 bool browser_initiated,
159 const FrameNavigationEntry* frame_entry, 149 const FrameNavigationEntry* frame_entry,
160 const NavigationEntryImpl* entry) 150 const NavigationEntryImpl* entry)
161 : frame_tree_node_(frame_tree_node), 151 : frame_tree_node_(frame_tree_node),
162 common_params_(common_params), 152 common_params_(common_params),
163 begin_params_(begin_params), 153 begin_params_(begin_params),
164 request_params_(request_params), 154 request_params_(request_params),
165 browser_initiated_(browser_initiated), 155 browser_initiated_(browser_initiated),
166 state_(NOT_STARTED), 156 state_(NOT_STARTED),
167 restore_type_(NavigationEntryImpl::RESTORE_NONE), 157 restore_type_(NavigationEntryImpl::RESTORE_NONE),
168 is_view_source_(false), 158 is_view_source_(false),
169 bindings_(NavigationEntryImpl::kInvalidBindings), 159 bindings_(NavigationEntryImpl::kInvalidBindings),
170 post_data_(body),
171 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { 160 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) {
172 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); 161 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr));
173 if (browser_initiated) { 162 if (browser_initiated) {
174 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); 163 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
175 if (frame_entry) { 164 if (frame_entry) {
176 source_site_instance_ = frame_entry->source_site_instance(); 165 source_site_instance_ = frame_entry->source_site_instance();
177 dest_site_instance_ = frame_entry->site_instance(); 166 dest_site_instance_ = frame_entry->site_instance();
178 } 167 }
179 168
180 restore_type_ = entry->restore_type(); 169 restore_type_ = entry->restore_type();
(...skipping 12 matching lines...) Expand all
193 // URLs). 182 // URLs).
194 const GURL& first_party_for_cookies = 183 const GURL& first_party_for_cookies =
195 frame_tree_node->IsMainFrame() 184 frame_tree_node->IsMainFrame()
196 ? common_params.url 185 ? common_params.url
197 : frame_tree_node->frame_tree()->root()->current_url(); 186 : frame_tree_node->frame_tree()->root()->current_url();
198 bool parent_is_main_frame = !frame_tree_node->parent() ? 187 bool parent_is_main_frame = !frame_tree_node->parent() ?
199 false : frame_tree_node->parent()->IsMainFrame(); 188 false : frame_tree_node->parent()->IsMainFrame();
200 info_.reset(new NavigationRequestInfo( 189 info_.reset(new NavigationRequestInfo(
201 common_params, begin_params, first_party_for_cookies, 190 common_params, begin_params, first_party_for_cookies,
202 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), 191 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(),
203 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body)); 192 parent_is_main_frame, frame_tree_node->frame_tree_node_id()));
204 } 193 }
205 194
206 NavigationRequest::~NavigationRequest() { 195 NavigationRequest::~NavigationRequest() {
207 } 196 }
208 197
209 void NavigationRequest::BeginNavigation() { 198 void NavigationRequest::BeginNavigation() {
210 DCHECK(!loader_); 199 DCHECK(!loader_);
211 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 200 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
212 state_ = STARTED; 201 state_ = STARTED;
213 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 202 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void NavigationRequest::TransferNavigationHandleOwnership( 246 void NavigationRequest::TransferNavigationHandleOwnership(
258 RenderFrameHostImpl* render_frame_host) { 247 RenderFrameHostImpl* render_frame_host) {
259 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); 248 render_frame_host->SetNavigationHandle(std::move(navigation_handle_));
260 } 249 }
261 250
262 void NavigationRequest::OnRequestRedirected( 251 void NavigationRequest::OnRequestRedirected(
263 const net::RedirectInfo& redirect_info, 252 const net::RedirectInfo& redirect_info,
264 const scoped_refptr<ResourceResponse>& response) { 253 const scoped_refptr<ResourceResponse>& response) {
265 // If the navigation is no longer a POST, the POST data should be reset. 254 // If the navigation is no longer a POST, the POST data should be reset.
266 if (redirect_info.new_method != "POST") 255 if (redirect_info.new_method != "POST")
267 post_data_ = nullptr; 256 common_params_.post_data = nullptr;
268 257
269 common_params_.url = redirect_info.new_url; 258 common_params_.url = redirect_info.new_url;
270 common_params_.method = redirect_info.new_method; 259 common_params_.method = redirect_info.new_method;
271 common_params_.referrer.url = GURL(redirect_info.new_referrer); 260 common_params_.referrer.url = GURL(redirect_info.new_referrer);
272 261
273 // TODO(clamy): Have CSP + security upgrade checks here. 262 // TODO(clamy): Have CSP + security upgrade checks here.
274 // TODO(clamy): Kill the renderer if FilterURL fails? 263 // TODO(clamy): Kill the renderer if FilterURL fails?
275 264
276 // It's safe to use base::Unretained because this NavigationRequest owns the 265 // It's safe to use base::Unretained because this NavigationRequest owns the
277 // NavigationHandle where the callback will be stored. 266 // NavigationHandle where the callback will be stored.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 RenderFrameHostImpl* render_frame_host = 417 RenderFrameHostImpl* render_frame_host =
429 navigation_handle_->GetRenderFrameHost(); 418 navigation_handle_->GetRenderFrameHost();
430 DCHECK(render_frame_host == 419 DCHECK(render_frame_host ==
431 frame_tree_node_->render_manager()->current_frame_host() || 420 frame_tree_node_->render_manager()->current_frame_host() ||
432 render_frame_host == 421 render_frame_host ==
433 frame_tree_node_->render_manager()->speculative_frame_host()); 422 frame_tree_node_->render_manager()->speculative_frame_host());
434 423
435 TransferNavigationHandleOwnership(render_frame_host); 424 TransferNavigationHandleOwnership(render_frame_host);
436 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 425 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
437 common_params_, request_params_, 426 common_params_, request_params_,
438 is_view_source_, post_data_); 427 is_view_source_);
439 428
440 // When navigating to a Javascript url, the NavigationRequest is not stored 429 // When navigating to a Javascript url, the NavigationRequest is not stored
441 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an 430 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an
442 // existing pending navigation. 431 // existing pending navigation.
443 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) 432 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme))
444 frame_tree_node_->ResetNavigationRequest(true); 433 frame_tree_node_->ResetNavigationRequest(true);
445 } 434 }
446 435
447 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { 436 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
448 // Only initialize the ServiceWorkerNavigationHandle if it can be created for 437 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
(...skipping 19 matching lines...) Expand all
468 browser_context, navigating_frame_host->GetSiteInstance()); 457 browser_context, navigating_frame_host->GetSiteInstance());
469 DCHECK(partition); 458 DCHECK(partition);
470 459
471 ServiceWorkerContextWrapper* service_worker_context = 460 ServiceWorkerContextWrapper* service_worker_context =
472 static_cast<ServiceWorkerContextWrapper*>( 461 static_cast<ServiceWorkerContextWrapper*>(
473 partition->GetServiceWorkerContext()); 462 partition->GetServiceWorkerContext());
474 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 463 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
475 } 464 }
476 465
477 } // namespace content 466 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigation_request_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698