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

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

Issue 1907443006: PlzNavigate: store POST data in the FrameNavigationEntry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Not sending POST data when cross-site redirect 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 bool is_same_document_history_load, 73 bool is_same_document_history_load,
74 const base::TimeTicks& navigation_start, 74 const base::TimeTicks& navigation_start,
75 NavigationControllerImpl* controller) { 75 NavigationControllerImpl* controller) {
76 // Copy existing headers and add necessary headers that may not be present 76 // Copy existing headers and add necessary headers that may not be present
77 // in the RequestNavigationParams. 77 // in the RequestNavigationParams.
78 net::HttpRequestHeaders headers; 78 net::HttpRequestHeaders headers;
79 headers.AddHeadersFromString(entry.extra_headers()); 79 headers.AddHeadersFromString(entry.extra_headers());
80 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, 80 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
81 GetContentClient()->GetUserAgent()); 81 GetContentClient()->GetUserAgent());
82 82
83 // Fill POST data from the browser in the request body. 83 // Fill POST data in the request body.
84 scoped_refptr<ResourceRequestBody> request_body; 84 scoped_refptr<ResourceRequestBody> request_body;
85 if (entry.GetHasPostData()) { 85 if (frame_entry.method() == "POST") {
86 request_body = new ResourceRequestBody(); 86 request_body = frame_entry.GetPostData();
87 request_body->AppendBytes( 87 if (!request_body && entry.GetBrowserInitiatedPostData()) {
88 reinterpret_cast<const char *>( 88 request_body = new ResourceRequestBody();
89 entry.GetBrowserInitiatedPostData()->front()), 89 request_body->AppendBytes(
90 entry.GetBrowserInitiatedPostData()->size()); 90 reinterpret_cast<const char*>(
91 entry.GetBrowserInitiatedPostData()->front()),
92 entry.GetBrowserInitiatedPostData()->size());
93 }
91 } 94 }
92 95
93 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 96 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
94 frame_tree_node, entry.ConstructCommonNavigationParams( 97 frame_tree_node, entry.ConstructCommonNavigationParams(
95 dest_url, dest_referrer, navigation_type, lofi_state, 98 frame_entry, dest_url, dest_referrer,
96 navigation_start), 99 navigation_type, lofi_state, navigation_start),
97 BeginNavigationParams(headers.ToString(), 100 BeginNavigationParams(headers.ToString(),
98 LoadFlagFromNavigationType(navigation_type), 101 LoadFlagFromNavigationType(navigation_type),
99 false, // has_user_gestures 102 false, // has_user_gestures
100 false, // skip_service_worker 103 false, // skip_service_worker
101 REQUEST_CONTEXT_TYPE_LOCATION), 104 REQUEST_CONTEXT_TYPE_LOCATION),
102 entry.ConstructRequestNavigationParams( 105 entry.ConstructRequestNavigationParams(
103 frame_entry, is_same_document_history_load, 106 frame_entry, is_same_document_history_load,
104 frame_tree_node->has_committed_real_load(), 107 frame_tree_node->has_committed_real_load(),
105 controller->GetPendingEntryIndex() == -1, 108 controller->GetPendingEntryIndex() == -1,
106 controller->GetIndexOfEntry(&entry), 109 controller->GetIndexOfEntry(&entry),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 const GURL& first_party_for_cookies = 190 const GURL& first_party_for_cookies =
188 frame_tree_node->IsMainFrame() 191 frame_tree_node->IsMainFrame()
189 ? common_params.url 192 ? common_params.url
190 : frame_tree_node->frame_tree()->root()->current_url(); 193 : frame_tree_node->frame_tree()->root()->current_url();
191 bool parent_is_main_frame = !frame_tree_node->parent() ? 194 bool parent_is_main_frame = !frame_tree_node->parent() ?
192 false : frame_tree_node->parent()->IsMainFrame(); 195 false : frame_tree_node->parent()->IsMainFrame();
193 info_.reset(new NavigationRequestInfo( 196 info_.reset(new NavigationRequestInfo(
194 common_params, begin_params, first_party_for_cookies, 197 common_params, begin_params, first_party_for_cookies,
195 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), 198 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(),
196 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body)); 199 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body));
200
201 if (body)
202 post_data_ = body->MakeCopy();
197 } 203 }
198 204
199 NavigationRequest::~NavigationRequest() { 205 NavigationRequest::~NavigationRequest() {
200 } 206 }
201 207
202 void NavigationRequest::BeginNavigation() { 208 void NavigationRequest::BeginNavigation() {
203 DCHECK(!loader_); 209 DCHECK(!loader_);
204 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 210 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
205 state_ = STARTED; 211 state_ = STARTED;
206 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 212 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
(...skipping 12 matching lines...) Expand all
219 base::Unretained(this))); 225 base::Unretained(this)));
220 return; 226 return;
221 } 227 }
222 228
223 // There is no need to make a network request for this navigation, so commit 229 // There is no need to make a network request for this navigation, so commit
224 // it immediately. 230 // it immediately.
225 state_ = RESPONSE_STARTED; 231 state_ = RESPONSE_STARTED;
226 232
227 // Select an appropriate RenderFrameHost. 233 // Select an appropriate RenderFrameHost.
228 RenderFrameHostImpl* render_frame_host = 234 RenderFrameHostImpl* render_frame_host =
229 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 235 frame_tree_node_->render_manager()->GetFrameHostForNavigation(this, true);
230 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 236 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
231 common_params_.url); 237 common_params_.url);
232 238
233 // Inform the NavigationHandle that the navigation will commit. 239 // Inform the NavigationHandle that the navigation will commit.
234 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 240 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
235 241
236 CommitNavigation(); 242 CommitNavigation();
237 } 243 }
238 244
239 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 245 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
240 // TODO(nasko): Update the NavigationHandle creation to ensure that the 246 // TODO(nasko): Update the NavigationHandle creation to ensure that the
241 // proper values are specified for is_synchronous and is_srcdoc. 247 // proper values are specified for is_synchronous and is_srcdoc.
242 navigation_handle_ = NavigationHandleImpl::Create( 248 navigation_handle_ = NavigationHandleImpl::Create(
243 common_params_.url, frame_tree_node_, 249 common_params_.url, frame_tree_node_,
244 false, // is_synchronous 250 false, // is_synchronous
245 false, // is_srcdoc 251 false, // is_srcdoc
246 common_params_.navigation_start, pending_nav_entry_id); 252 common_params_.navigation_start, pending_nav_entry_id);
247 } 253 }
248 254
249 void NavigationRequest::TransferNavigationHandleOwnership( 255 void NavigationRequest::TransferNavigationHandleOwnership(
250 RenderFrameHostImpl* render_frame_host) { 256 RenderFrameHostImpl* render_frame_host) {
251 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); 257 render_frame_host->SetNavigationHandle(std::move(navigation_handle_));
252 } 258 }
253 259
260 void NavigationRequest::ResetPostData() {
261 post_data_ = nullptr;
262 }
263
254 void NavigationRequest::OnRequestRedirected( 264 void NavigationRequest::OnRequestRedirected(
255 const net::RedirectInfo& redirect_info, 265 const net::RedirectInfo& redirect_info,
256 const scoped_refptr<ResourceResponse>& response) { 266 const scoped_refptr<ResourceResponse>& response) {
257 common_params_.url = redirect_info.new_url; 267 common_params_.url = redirect_info.new_url;
258 common_params_.method = redirect_info.new_method; 268 common_params_.method = redirect_info.new_method;
259 common_params_.referrer.url = GURL(redirect_info.new_referrer); 269 common_params_.referrer.url = GURL(redirect_info.new_referrer);
260 270
261 // TODO(clamy): Have CSP + security upgrade checks here. 271 // TODO(clamy): Have CSP + security upgrade checks here.
262 // TODO(clamy): Kill the renderer if FilterURL fails? 272 // TODO(clamy): Kill the renderer if FilterURL fails?
263 273
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 308 }
299 309
300 // Update the lofi state of the request. 310 // Update the lofi state of the request.
301 if (response->head.is_using_lofi) 311 if (response->head.is_using_lofi)
302 common_params_.lofi_state = LOFI_ON; 312 common_params_.lofi_state = LOFI_ON;
303 else 313 else
304 common_params_.lofi_state = LOFI_OFF; 314 common_params_.lofi_state = LOFI_OFF;
305 315
306 // Select an appropriate renderer to commit the navigation. 316 // Select an appropriate renderer to commit the navigation.
307 RenderFrameHostImpl* render_frame_host = 317 RenderFrameHostImpl* render_frame_host =
308 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 318 frame_tree_node_->render_manager()->GetFrameHostForNavigation(this, true);
309 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 319 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
310 common_params_.url); 320 common_params_.url);
311 321
312 // For renderer-initiated navigations that are set to commit in a different 322 // For renderer-initiated navigations that are set to commit in a different
313 // renderer, allow the embedder to cancel the transfer. 323 // renderer, allow the embedder to cancel the transfer.
314 if (!browser_initiated_ && 324 if (!browser_initiated_ &&
315 render_frame_host != frame_tree_node_->current_frame_host() && 325 render_frame_host != frame_tree_node_->current_frame_host() &&
316 !frame_tree_node_->navigator() 326 !frame_tree_node_->navigator()
317 ->GetDelegate() 327 ->GetDelegate()
318 ->ShouldTransferNavigation()) { 328 ->ShouldTransferNavigation()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 RenderFrameHostImpl* render_frame_host = 422 RenderFrameHostImpl* render_frame_host =
413 navigation_handle_->GetRenderFrameHost(); 423 navigation_handle_->GetRenderFrameHost();
414 DCHECK(render_frame_host == 424 DCHECK(render_frame_host ==
415 frame_tree_node_->render_manager()->current_frame_host() || 425 frame_tree_node_->render_manager()->current_frame_host() ||
416 render_frame_host == 426 render_frame_host ==
417 frame_tree_node_->render_manager()->speculative_frame_host()); 427 frame_tree_node_->render_manager()->speculative_frame_host());
418 428
419 TransferNavigationHandleOwnership(render_frame_host); 429 TransferNavigationHandleOwnership(render_frame_host);
420 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 430 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
421 common_params_, request_params_, 431 common_params_, request_params_,
422 is_view_source_); 432 is_view_source_, post_data_);
423 433
424 // When navigating to a Javascript url, the NavigationRequest is not stored 434 // When navigating to a Javascript url, the NavigationRequest is not stored
425 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an 435 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an
426 // existing pending navigation. 436 // existing pending navigation.
427 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) 437 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme))
428 frame_tree_node_->ResetNavigationRequest(true); 438 frame_tree_node_->ResetNavigationRequest(true);
429 } 439 }
430 440
431 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { 441 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
432 // Only initialize the ServiceWorkerNavigationHandle if it can be created for 442 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
(...skipping 19 matching lines...) Expand all
452 browser_context, navigating_frame_host->GetSiteInstance()); 462 browser_context, navigating_frame_host->GetSiteInstance());
453 DCHECK(partition); 463 DCHECK(partition);
454 464
455 ServiceWorkerContextWrapper* service_worker_context = 465 ServiceWorkerContextWrapper* service_worker_context =
456 static_cast<ServiceWorkerContextWrapper*>( 466 static_cast<ServiceWorkerContextWrapper*>(
457 partition->GetServiceWorkerContext()); 467 partition->GetServiceWorkerContext());
458 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 468 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
459 } 469 }
460 470
461 } // namespace content 471 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698