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

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: Rebase + addressed comments 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bool is_same_document_history_load, 74 bool is_same_document_history_load,
75 const base::TimeTicks& navigation_start, 75 const base::TimeTicks& navigation_start,
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 from the browser 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 (entry.GetHasPostData()) { 86 if (frame_entry.method() == "POST") {
87 request_body = new ResourceRequestBody(); 87 request_body = frame_entry.GetPostData();
88 request_body->AppendBytes( 88 if (!request_body && entry.GetBrowserInitiatedPostData()) {
89 reinterpret_cast<const char *>( 89 request_body = new ResourceRequestBody();
90 entry.GetBrowserInitiatedPostData()->front()), 90 request_body->AppendBytes(
91 entry.GetBrowserInitiatedPostData()->size()); 91 reinterpret_cast<const char*>(
92 entry.GetBrowserInitiatedPostData()->front()),
93 entry.GetBrowserInitiatedPostData()->size());
94 }
92 } 95 }
93 96
94 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 97 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
95 frame_tree_node, entry.ConstructCommonNavigationParams( 98 frame_tree_node, entry.ConstructCommonNavigationParams(
96 dest_url, dest_referrer, navigation_type, lofi_state, 99 frame_entry, dest_url, dest_referrer,
97 navigation_start), 100 navigation_type, lofi_state, navigation_start),
98 BeginNavigationParams(headers.ToString(), 101 BeginNavigationParams(headers.ToString(),
99 LoadFlagFromNavigationType(navigation_type), 102 LoadFlagFromNavigationType(navigation_type),
100 false, // has_user_gestures 103 false, // has_user_gestures
101 false, // skip_service_worker 104 false, // skip_service_worker
102 REQUEST_CONTEXT_TYPE_LOCATION), 105 REQUEST_CONTEXT_TYPE_LOCATION),
103 entry.ConstructRequestNavigationParams( 106 entry.ConstructRequestNavigationParams(
104 frame_entry, is_same_document_history_load, 107 frame_entry, is_same_document_history_load,
105 frame_tree_node->has_committed_real_load(), 108 frame_tree_node->has_committed_real_load(),
106 controller->GetPendingEntryIndex() == -1, 109 controller->GetPendingEntryIndex() == -1,
107 controller->GetIndexOfEntry(&entry), 110 controller->GetIndexOfEntry(&entry),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const NavigationEntryImpl* entry) 160 const NavigationEntryImpl* entry)
158 : frame_tree_node_(frame_tree_node), 161 : frame_tree_node_(frame_tree_node),
159 common_params_(common_params), 162 common_params_(common_params),
160 begin_params_(begin_params), 163 begin_params_(begin_params),
161 request_params_(request_params), 164 request_params_(request_params),
162 browser_initiated_(browser_initiated), 165 browser_initiated_(browser_initiated),
163 state_(NOT_STARTED), 166 state_(NOT_STARTED),
164 restore_type_(NavigationEntryImpl::RESTORE_NONE), 167 restore_type_(NavigationEntryImpl::RESTORE_NONE),
165 is_view_source_(false), 168 is_view_source_(false),
166 bindings_(NavigationEntryImpl::kInvalidBindings), 169 bindings_(NavigationEntryImpl::kInvalidBindings),
170 post_data_(body),
167 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { 171 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) {
168 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); 172 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr));
169 if (browser_initiated) { 173 if (browser_initiated) {
170 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); 174 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
171 if (frame_entry) { 175 if (frame_entry) {
172 source_site_instance_ = frame_entry->source_site_instance(); 176 source_site_instance_ = frame_entry->source_site_instance();
173 dest_site_instance_ = frame_entry->site_instance(); 177 dest_site_instance_ = frame_entry->site_instance();
174 } 178 }
175 179
176 restore_type_ = entry->restore_type(); 180 restore_type_ = entry->restore_type();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 255 }
252 256
253 void NavigationRequest::TransferNavigationHandleOwnership( 257 void NavigationRequest::TransferNavigationHandleOwnership(
254 RenderFrameHostImpl* render_frame_host) { 258 RenderFrameHostImpl* render_frame_host) {
255 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); 259 render_frame_host->SetNavigationHandle(std::move(navigation_handle_));
256 } 260 }
257 261
258 void NavigationRequest::OnRequestRedirected( 262 void NavigationRequest::OnRequestRedirected(
259 const net::RedirectInfo& redirect_info, 263 const net::RedirectInfo& redirect_info,
260 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 (redirect_info.new_method != "POST")
267 post_data_ = nullptr;
268
261 common_params_.url = redirect_info.new_url; 269 common_params_.url = redirect_info.new_url;
262 common_params_.method = redirect_info.new_method; 270 common_params_.method = redirect_info.new_method;
263 common_params_.referrer.url = GURL(redirect_info.new_referrer); 271 common_params_.referrer.url = GURL(redirect_info.new_referrer);
264 272
265 // TODO(clamy): Have CSP + security upgrade checks here. 273 // TODO(clamy): Have CSP + security upgrade checks here.
266 // TODO(clamy): Kill the renderer if FilterURL fails? 274 // TODO(clamy): Kill the renderer if FilterURL fails?
267 275
268 // 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
269 // NavigationHandle where the callback will be stored. 277 // NavigationHandle where the callback will be stored.
270 // 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 RenderFrameHostImpl* render_frame_host = 428 RenderFrameHostImpl* render_frame_host =
421 navigation_handle_->GetRenderFrameHost(); 429 navigation_handle_->GetRenderFrameHost();
422 DCHECK(render_frame_host == 430 DCHECK(render_frame_host ==
423 frame_tree_node_->render_manager()->current_frame_host() || 431 frame_tree_node_->render_manager()->current_frame_host() ||
424 render_frame_host == 432 render_frame_host ==
425 frame_tree_node_->render_manager()->speculative_frame_host()); 433 frame_tree_node_->render_manager()->speculative_frame_host());
426 434
427 TransferNavigationHandleOwnership(render_frame_host); 435 TransferNavigationHandleOwnership(render_frame_host);
428 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 436 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
429 common_params_, request_params_, 437 common_params_, request_params_,
430 is_view_source_); 438 is_view_source_, post_data_);
431 439
432 // When navigating to a Javascript url, the NavigationRequest is not stored 440 // When navigating to a Javascript url, the NavigationRequest is not stored
433 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an 441 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an
434 // existing pending navigation. 442 // existing pending navigation.
435 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) 443 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme))
436 frame_tree_node_->ResetNavigationRequest(true); 444 frame_tree_node_->ResetNavigationRequest(true);
437 } 445 }
438 446
439 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { 447 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
440 // Only initialize the ServiceWorkerNavigationHandle if it can be created for 448 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
(...skipping 19 matching lines...) Expand all
460 browser_context, navigating_frame_host->GetSiteInstance()); 468 browser_context, navigating_frame_host->GetSiteInstance());
461 DCHECK(partition); 469 DCHECK(partition);
462 470
463 ServiceWorkerContextWrapper* service_worker_context = 471 ServiceWorkerContextWrapper* service_worker_context =
464 static_cast<ServiceWorkerContextWrapper*>( 472 static_cast<ServiceWorkerContextWrapper*>(
465 partition->GetServiceWorkerContext()); 473 partition->GetServiceWorkerContext());
466 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 474 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
467 } 475 }
468 476
469 } // namespace content 477 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698