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

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

Issue 1678303004: PlzNavigate: inform the renderer that a navigation is a POST (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/frame_tree_node.h" 10 #include "content/browser/frame_host/frame_tree_node.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( 63 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
64 FrameTreeNode* frame_tree_node, 64 FrameTreeNode* frame_tree_node,
65 const GURL& dest_url, 65 const GURL& dest_url,
66 const Referrer& dest_referrer, 66 const Referrer& dest_referrer,
67 const FrameNavigationEntry& frame_entry, 67 const FrameNavigationEntry& frame_entry,
68 const NavigationEntryImpl& entry, 68 const NavigationEntryImpl& entry,
69 FrameMsg_Navigate_Type::Value navigation_type, 69 FrameMsg_Navigate_Type::Value navigation_type,
70 bool is_same_document_history_load, 70 bool is_same_document_history_load,
71 const base::TimeTicks& navigation_start, 71 const base::TimeTicks& navigation_start,
72 NavigationControllerImpl* controller) { 72 NavigationControllerImpl* controller) {
73 std::string method = entry.GetHasPostData() ? "POST" : "GET";
74
75 // Copy existing headers and add necessary headers that may not be present 73 // Copy existing headers and add necessary headers that may not be present
76 // in the RequestNavigationParams. 74 // in the RequestNavigationParams.
77 net::HttpRequestHeaders headers; 75 net::HttpRequestHeaders headers;
78 headers.AddHeadersFromString(entry.extra_headers()); 76 headers.AddHeadersFromString(entry.extra_headers());
79 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, 77 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent,
80 GetContentClient()->GetUserAgent()); 78 GetContentClient()->GetUserAgent());
81 // TODO(clamy): match what blink is doing with accept headers. 79 // TODO(clamy): match what blink is doing with accept headers.
82 headers.SetHeaderIfMissing("Accept", "*/*"); 80 headers.SetHeaderIfMissing("Accept", "*/*");
83 81
84 // Fill POST data from the browser in the request body. 82 // Fill POST data from the browser in the request body.
85 scoped_refptr<ResourceRequestBody> request_body; 83 scoped_refptr<ResourceRequestBody> request_body;
86 if (entry.GetHasPostData()) { 84 if (entry.GetHasPostData()) {
87 request_body = new ResourceRequestBody(); 85 request_body = new ResourceRequestBody();
88 request_body->AppendBytes( 86 request_body->AppendBytes(
89 reinterpret_cast<const char *>( 87 reinterpret_cast<const char *>(
90 entry.GetBrowserInitiatedPostData()->front()), 88 entry.GetBrowserInitiatedPostData()->front()),
91 entry.GetBrowserInitiatedPostData()->size()); 89 entry.GetBrowserInitiatedPostData()->size());
92 } 90 }
93 91
94 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( 92 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
95 frame_tree_node, entry.ConstructCommonNavigationParams( 93 frame_tree_node, entry.ConstructCommonNavigationParams(
96 dest_url, dest_referrer, navigation_type, 94 dest_url, dest_referrer, navigation_type,
97 LOFI_UNSPECIFIED, navigation_start), 95 LOFI_UNSPECIFIED, navigation_start),
98 BeginNavigationParams(method, headers.ToString(), 96 BeginNavigationParams(headers.ToString(),
99 LoadFlagFromNavigationType(navigation_type), 97 LoadFlagFromNavigationType(navigation_type),
100 false, // has_user_gestures 98 false, // has_user_gestures
101 false, // skip_service_worker 99 false, // skip_service_worker
102 REQUEST_CONTEXT_TYPE_LOCATION), 100 REQUEST_CONTEXT_TYPE_LOCATION),
103 entry.ConstructRequestNavigationParams( 101 entry.ConstructRequestNavigationParams(
104 frame_entry, is_same_document_history_load, 102 frame_entry, is_same_document_history_load,
105 frame_tree_node->has_committed_real_load(), 103 frame_tree_node->has_committed_real_load(),
106 controller->GetPendingEntryIndex() == -1, 104 controller->GetPendingEntryIndex() == -1,
107 controller->GetIndexOfEntry(&entry), 105 controller->GetIndexOfEntry(&entry),
108 controller->GetLastCommittedEntryIndex(), 106 controller->GetLastCommittedEntryIndex(),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void NavigationRequest::BeginNavigation() { 201 void NavigationRequest::BeginNavigation() {
204 DCHECK(!loader_); 202 DCHECK(!loader_);
205 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 203 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
206 state_ = STARTED; 204 state_ = STARTED;
207 205
208 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 206 if (ShouldMakeNetworkRequestForURL(common_params_.url)) {
209 // It's safe to use base::Unretained because this NavigationRequest owns 207 // It's safe to use base::Unretained because this NavigationRequest owns
210 // the NavigationHandle where the callback will be stored. 208 // the NavigationHandle where the callback will be stored.
211 // TODO(clamy): pass the real value for |is_external_protocol| if needed. 209 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
212 navigation_handle_->WillStartRequest( 210 navigation_handle_->WillStartRequest(
213 begin_params_.method == "POST", 211 common_params_.is_post,
214 Referrer::SanitizeForRequest(common_params_.url, 212 Referrer::SanitizeForRequest(common_params_.url,
215 common_params_.referrer), 213 common_params_.referrer),
216 begin_params_.has_user_gesture, common_params_.transition, false, 214 begin_params_.has_user_gesture, common_params_.transition, false,
217 base::Bind(&NavigationRequest::OnStartChecksComplete, 215 base::Bind(&NavigationRequest::OnStartChecksComplete,
218 base::Unretained(this))); 216 base::Unretained(this)));
219 return; 217 return;
220 } 218 }
221 219
222 // There is no need to make a network request for this navigation, so commit 220 // There is no need to make a network request for this navigation, so commit
223 // it immediately. 221 // it immediately.
(...skipping 14 matching lines...) Expand all
238 236
239 void NavigationRequest::TransferNavigationHandleOwnership( 237 void NavigationRequest::TransferNavigationHandleOwnership(
240 RenderFrameHostImpl* render_frame_host) { 238 RenderFrameHostImpl* render_frame_host) {
241 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); 239 render_frame_host->SetNavigationHandle(std::move(navigation_handle_));
242 } 240 }
243 241
244 void NavigationRequest::OnRequestRedirected( 242 void NavigationRequest::OnRequestRedirected(
245 const net::RedirectInfo& redirect_info, 243 const net::RedirectInfo& redirect_info,
246 const scoped_refptr<ResourceResponse>& response) { 244 const scoped_refptr<ResourceResponse>& response) {
247 common_params_.url = redirect_info.new_url; 245 common_params_.url = redirect_info.new_url;
248 begin_params_.method = redirect_info.new_method; 246 common_params_.is_post = redirect_info.new_method == "POST";
249 common_params_.referrer.url = GURL(redirect_info.new_referrer); 247 common_params_.referrer.url = GURL(redirect_info.new_referrer);
250 248
251 // TODO(clamy): Have CSP + security upgrade checks here. 249 // TODO(clamy): Have CSP + security upgrade checks here.
252 // TODO(clamy): Kill the renderer if FilterURL fails? 250 // TODO(clamy): Kill the renderer if FilterURL fails?
253 251
254 // It's safe to use base::Unretained because this NavigationRequest owns the 252 // It's safe to use base::Unretained because this NavigationRequest owns the
255 // NavigationHandle where the callback will be stored. 253 // NavigationHandle where the callback will be stored.
256 // TODO(clamy): pass the real value for |is_external_protocol| if needed. 254 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
257 navigation_handle_->WillRedirectRequest( 255 navigation_handle_->WillRedirectRequest(
258 common_params_.url, begin_params_.method == "POST", 256 common_params_.url, common_params_.is_post, common_params_.referrer.url,
259 common_params_.referrer.url, false, response->head.headers, 257 false, response->head.headers,
260 base::Bind(&NavigationRequest::OnRedirectChecksComplete, 258 base::Bind(&NavigationRequest::OnRedirectChecksComplete,
261 base::Unretained(this))); 259 base::Unretained(this)));
262 } 260 }
263 261
264 void NavigationRequest::OnResponseStarted( 262 void NavigationRequest::OnResponseStarted(
265 const scoped_refptr<ResourceResponse>& response, 263 const scoped_refptr<ResourceResponse>& response,
266 scoped_ptr<StreamHandle> body) { 264 scoped_ptr<StreamHandle> body) {
267 DCHECK(state_ == STARTED); 265 DCHECK(state_ == STARTED);
268 state_ = RESPONSE_STARTED; 266 state_ = RESPONSE_STARTED;
269 267
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 browser_context, navigating_frame_host->GetSiteInstance()); 356 browser_context, navigating_frame_host->GetSiteInstance());
359 DCHECK(partition); 357 DCHECK(partition);
360 358
361 ServiceWorkerContextWrapper* service_worker_context = 359 ServiceWorkerContextWrapper* service_worker_context =
362 static_cast<ServiceWorkerContextWrapper*>( 360 static_cast<ServiceWorkerContextWrapper*>(
363 partition->GetServiceWorkerContext()); 361 partition->GetServiceWorkerContext());
364 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 362 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
365 } 363 }
366 364
367 } // namespace content 365 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698