OLD | NEW |
---|---|
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 Loading... | |
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 const GURL& first_party_for_cookies = | 192 const GURL& first_party_for_cookies = |
190 frame_tree_node->IsMainFrame() | 193 frame_tree_node->IsMainFrame() |
191 ? common_params.url | 194 ? common_params.url |
192 : frame_tree_node->frame_tree()->root()->current_url(); | 195 : frame_tree_node->frame_tree()->root()->current_url(); |
193 bool parent_is_main_frame = !frame_tree_node->parent() ? | 196 bool parent_is_main_frame = !frame_tree_node->parent() ? |
194 false : frame_tree_node->parent()->IsMainFrame(); | 197 false : frame_tree_node->parent()->IsMainFrame(); |
195 info_.reset(new NavigationRequestInfo( | 198 info_.reset(new NavigationRequestInfo( |
196 common_params, begin_params, first_party_for_cookies, | 199 common_params, begin_params, first_party_for_cookies, |
197 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), | 200 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), |
198 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body)); | 201 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body)); |
202 | |
203 if (body) | |
204 post_data_ = body->MakeCopy(); | |
Łukasz Anforowicz
2016/05/12 02:53:59
Can you help me understand why we need to make a d
clamy
2016/05/12 08:53:13
I wasn't sure about this so I made a copy to stay
Łukasz Anforowicz
2016/05/12 19:44:12
I think it should be safe not to make a copy - I'v
Charlie Reis
2016/05/16 21:16:41
+1 to removing the deep copy if we can.
clamy
2016/05/19 13:11:57
Done.
| |
199 } | 205 } |
200 | 206 |
201 NavigationRequest::~NavigationRequest() { | 207 NavigationRequest::~NavigationRequest() { |
202 } | 208 } |
203 | 209 |
204 void NavigationRequest::BeginNavigation() { | 210 void NavigationRequest::BeginNavigation() { |
205 DCHECK(!loader_); | 211 DCHECK(!loader_); |
206 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 212 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
207 state_ = STARTED; | 213 state_ = STARTED; |
208 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 214 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 } | 255 } |
250 | 256 |
251 void NavigationRequest::TransferNavigationHandleOwnership( | 257 void NavigationRequest::TransferNavigationHandleOwnership( |
252 RenderFrameHostImpl* render_frame_host) { | 258 RenderFrameHostImpl* render_frame_host) { |
253 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); | 259 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); |
254 } | 260 } |
255 | 261 |
256 void NavigationRequest::OnRequestRedirected( | 262 void NavigationRequest::OnRequestRedirected( |
257 const net::RedirectInfo& redirect_info, | 263 const net::RedirectInfo& redirect_info, |
258 const scoped_refptr<ResourceResponse>& response) { | 264 const scoped_refptr<ResourceResponse>& response) { |
265 // If the navigation is no longer a POST, the POST data should be reset. | |
266 if (common_params_.method == "POST" && redirect_info.new_method != "POST") | |
Łukasz Anforowicz
2016/05/12 02:53:59
Shouldn't the second part of the condition be suff
clamy
2016/05/12 08:53:13
No but I thought it made a bit clearer the case in
Łukasz Anforowicz
2016/05/12 19:44:12
Acknowledged. I don't strongly feel one way or an
Charlie Reis
2016/05/16 21:16:41
I think we should remove the first part (common_pa
| |
267 post_data_ = nullptr; | |
268 | |
259 common_params_.url = redirect_info.new_url; | 269 common_params_.url = redirect_info.new_url; |
260 common_params_.method = redirect_info.new_method; | 270 common_params_.method = redirect_info.new_method; |
261 common_params_.referrer.url = GURL(redirect_info.new_referrer); | 271 common_params_.referrer.url = GURL(redirect_info.new_referrer); |
262 | 272 |
263 // TODO(clamy): Have CSP + security upgrade checks here. | 273 // TODO(clamy): Have CSP + security upgrade checks here. |
264 // TODO(clamy): Kill the renderer if FilterURL fails? | 274 // TODO(clamy): Kill the renderer if FilterURL fails? |
265 | 275 |
266 // It's safe to use base::Unretained because this NavigationRequest owns the | 276 // It's safe to use base::Unretained because this NavigationRequest owns the |
267 // NavigationHandle where the callback will be stored. | 277 // NavigationHandle where the callback will be stored. |
268 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 278 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 RenderFrameHostImpl* render_frame_host = | 424 RenderFrameHostImpl* render_frame_host = |
415 navigation_handle_->GetRenderFrameHost(); | 425 navigation_handle_->GetRenderFrameHost(); |
416 DCHECK(render_frame_host == | 426 DCHECK(render_frame_host == |
417 frame_tree_node_->render_manager()->current_frame_host() || | 427 frame_tree_node_->render_manager()->current_frame_host() || |
418 render_frame_host == | 428 render_frame_host == |
419 frame_tree_node_->render_manager()->speculative_frame_host()); | 429 frame_tree_node_->render_manager()->speculative_frame_host()); |
420 | 430 |
421 TransferNavigationHandleOwnership(render_frame_host); | 431 TransferNavigationHandleOwnership(render_frame_host); |
422 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 432 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
423 common_params_, request_params_, | 433 common_params_, request_params_, |
424 is_view_source_); | 434 is_view_source_, post_data_); |
425 | 435 |
426 // When navigating to a Javascript url, the NavigationRequest is not stored | 436 // When navigating to a Javascript url, the NavigationRequest is not stored |
427 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an | 437 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an |
428 // existing pending navigation. | 438 // existing pending navigation. |
429 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) | 439 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) |
430 frame_tree_node_->ResetNavigationRequest(true); | 440 frame_tree_node_->ResetNavigationRequest(true); |
431 } | 441 } |
432 | 442 |
433 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { | 443 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { |
434 // Only initialize the ServiceWorkerNavigationHandle if it can be created for | 444 // Only initialize the ServiceWorkerNavigationHandle if it can be created for |
(...skipping 19 matching lines...) Expand all Loading... | |
454 browser_context, navigating_frame_host->GetSiteInstance()); | 464 browser_context, navigating_frame_host->GetSiteInstance()); |
455 DCHECK(partition); | 465 DCHECK(partition); |
456 | 466 |
457 ServiceWorkerContextWrapper* service_worker_context = | 467 ServiceWorkerContextWrapper* service_worker_context = |
458 static_cast<ServiceWorkerContextWrapper*>( | 468 static_cast<ServiceWorkerContextWrapper*>( |
459 partition->GetServiceWorkerContext()); | 469 partition->GetServiceWorkerContext()); |
460 navigation_handle_->InitServiceWorkerHandle(service_worker_context); | 470 navigation_handle_->InitServiceWorkerHandle(service_worker_context); |
461 } | 471 } |
462 | 472 |
463 } // namespace content | 473 } // namespace content |
OLD | NEW |