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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()) { | 88 if (!request_body) |
89 request_body = new ResourceRequestBody(); | 89 request_body = entry.ConstructBodyFromBrowserInitiatedPostData(); |
clamy
2016/05/23 16:59:28
Won't this happen in ConstructCommonNavigationPara
Charlie Reis
2016/05/23 18:14:10
Yeah, seems unnecessary.
Łukasz Anforowicz
2016/05/23 18:38:47
Good point. I've removed these 2 lines.
| |
90 request_body->AppendBytes( | |
91 reinterpret_cast<const char*>( | |
92 entry.GetBrowserInitiatedPostData()->front()), | |
93 entry.GetBrowserInitiatedPostData()->size()); | |
94 } | |
95 } | 90 } |
96 | 91 |
97 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 92 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
98 frame_tree_node, entry.ConstructCommonNavigationParams( | 93 frame_tree_node, entry.ConstructCommonNavigationParams( |
99 frame_entry, dest_url, dest_referrer, | 94 frame_entry, request_body, dest_url, dest_referrer, |
100 navigation_type, lofi_state, navigation_start), | 95 navigation_type, lofi_state, navigation_start), |
101 BeginNavigationParams(headers.ToString(), | 96 BeginNavigationParams(headers.ToString(), |
102 LoadFlagFromNavigationType(navigation_type), | 97 LoadFlagFromNavigationType(navigation_type), |
103 false, // has_user_gestures | 98 false, // has_user_gestures |
104 false, // skip_service_worker | 99 false, // skip_service_worker |
105 REQUEST_CONTEXT_TYPE_LOCATION), | 100 REQUEST_CONTEXT_TYPE_LOCATION), |
106 entry.ConstructRequestNavigationParams( | 101 entry.ConstructRequestNavigationParams( |
107 frame_entry, is_same_document_history_load, | 102 frame_entry, is_same_document_history_load, |
108 frame_tree_node->has_committed_real_load(), | 103 frame_tree_node->has_committed_real_load(), |
109 controller->GetPendingEntryIndex() == -1, | 104 controller->GetPendingEntryIndex() == -1, |
110 controller->GetIndexOfEntry(&entry), | 105 controller->GetIndexOfEntry(&entry), |
111 controller->GetLastCommittedEntryIndex(), | 106 controller->GetLastCommittedEntryIndex(), |
112 controller->GetEntryCount()), | 107 controller->GetEntryCount()), |
113 request_body, true, &frame_entry, &entry)); | 108 true, &frame_entry, &entry)); |
114 return navigation_request; | 109 return navigation_request; |
115 } | 110 } |
116 | 111 |
117 // static | 112 // static |
118 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( | 113 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( |
119 FrameTreeNode* frame_tree_node, | 114 FrameTreeNode* frame_tree_node, |
120 const CommonNavigationParams& common_params, | 115 const CommonNavigationParams& common_params, |
121 const BeginNavigationParams& begin_params, | 116 const BeginNavigationParams& begin_params, |
122 scoped_refptr<ResourceRequestBody> body, | |
123 int current_history_list_offset, | 117 int current_history_list_offset, |
124 int current_history_list_length) { | 118 int current_history_list_length) { |
125 // TODO(clamy): Check if some PageState should be provided here. | 119 // 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 | 120 // 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. | 121 // 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 | 122 // 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. | 123 // renderer and sent to the browser instead of being measured here. |
130 // TODO(clamy): The pending history list offset should be properly set. | 124 // TODO(clamy): The pending history list offset should be properly set. |
131 RequestNavigationParams request_params( | 125 RequestNavigationParams request_params( |
132 false, // is_overriding_user_agent | 126 false, // is_overriding_user_agent |
133 std::vector<GURL>(), // redirects | 127 std::vector<GURL>(), // redirects |
134 false, // can_load_local_resources | 128 false, // can_load_local_resources |
135 base::Time::Now(), // request_time | 129 base::Time::Now(), // request_time |
136 PageState(), // page_state | 130 PageState(), // page_state |
137 -1, // page_id | 131 -1, // page_id |
138 0, // nav_entry_id | 132 0, // nav_entry_id |
139 false, // is_same_document_history_load | 133 false, // is_same_document_history_load |
140 frame_tree_node->has_committed_real_load(), | 134 frame_tree_node->has_committed_real_load(), |
141 false, // intended_as_new_entry | 135 false, // intended_as_new_entry |
142 -1, // pending_history_list_offset | 136 -1, // pending_history_list_offset |
143 current_history_list_offset, current_history_list_length, | 137 current_history_list_offset, current_history_list_length, |
144 false, // is_view_source | 138 false, // is_view_source |
145 false); // should_clear_history_list | 139 false); // should_clear_history_list |
146 std::unique_ptr<NavigationRequest> navigation_request( | 140 std::unique_ptr<NavigationRequest> navigation_request( |
147 new NavigationRequest(frame_tree_node, common_params, begin_params, | 141 new NavigationRequest(frame_tree_node, common_params, begin_params, |
148 request_params, body, false, nullptr, nullptr)); | 142 request_params, false, nullptr, nullptr)); |
149 return navigation_request; | 143 return navigation_request; |
150 } | 144 } |
151 | 145 |
152 NavigationRequest::NavigationRequest( | 146 NavigationRequest::NavigationRequest( |
153 FrameTreeNode* frame_tree_node, | 147 FrameTreeNode* frame_tree_node, |
154 const CommonNavigationParams& common_params, | 148 const CommonNavigationParams& common_params, |
155 const BeginNavigationParams& begin_params, | 149 const BeginNavigationParams& begin_params, |
156 const RequestNavigationParams& request_params, | 150 const RequestNavigationParams& request_params, |
157 scoped_refptr<ResourceRequestBody> body, | |
158 bool browser_initiated, | 151 bool browser_initiated, |
159 const FrameNavigationEntry* frame_entry, | 152 const FrameNavigationEntry* frame_entry, |
160 const NavigationEntryImpl* entry) | 153 const NavigationEntryImpl* entry) |
161 : frame_tree_node_(frame_tree_node), | 154 : frame_tree_node_(frame_tree_node), |
162 common_params_(common_params), | 155 common_params_(common_params), |
163 begin_params_(begin_params), | 156 begin_params_(begin_params), |
164 request_params_(request_params), | 157 request_params_(request_params), |
165 browser_initiated_(browser_initiated), | 158 browser_initiated_(browser_initiated), |
166 state_(NOT_STARTED), | 159 state_(NOT_STARTED), |
167 restore_type_(NavigationEntryImpl::RESTORE_NONE), | 160 restore_type_(NavigationEntryImpl::RESTORE_NONE), |
168 is_view_source_(false), | 161 is_view_source_(false), |
169 bindings_(NavigationEntryImpl::kInvalidBindings), | 162 bindings_(NavigationEntryImpl::kInvalidBindings), |
170 post_data_(body), | |
171 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { | 163 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { |
172 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); | 164 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
173 if (browser_initiated) { | 165 if (browser_initiated) { |
174 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); | 166 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
175 if (frame_entry) { | 167 if (frame_entry) { |
176 source_site_instance_ = frame_entry->source_site_instance(); | 168 source_site_instance_ = frame_entry->source_site_instance(); |
177 dest_site_instance_ = frame_entry->site_instance(); | 169 dest_site_instance_ = frame_entry->site_instance(); |
178 } | 170 } |
179 | 171 |
180 restore_type_ = entry->restore_type(); | 172 restore_type_ = entry->restore_type(); |
(...skipping 12 matching lines...) Expand all Loading... | |
193 // URLs). | 185 // URLs). |
194 const GURL& first_party_for_cookies = | 186 const GURL& first_party_for_cookies = |
195 frame_tree_node->IsMainFrame() | 187 frame_tree_node->IsMainFrame() |
196 ? common_params.url | 188 ? common_params.url |
197 : frame_tree_node->frame_tree()->root()->current_url(); | 189 : frame_tree_node->frame_tree()->root()->current_url(); |
198 bool parent_is_main_frame = !frame_tree_node->parent() ? | 190 bool parent_is_main_frame = !frame_tree_node->parent() ? |
199 false : frame_tree_node->parent()->IsMainFrame(); | 191 false : frame_tree_node->parent()->IsMainFrame(); |
200 info_.reset(new NavigationRequestInfo( | 192 info_.reset(new NavigationRequestInfo( |
201 common_params, begin_params, first_party_for_cookies, | 193 common_params, begin_params, first_party_for_cookies, |
202 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), | 194 frame_tree_node->current_origin(), frame_tree_node->IsMainFrame(), |
203 parent_is_main_frame, frame_tree_node->frame_tree_node_id(), body)); | 195 parent_is_main_frame, frame_tree_node->frame_tree_node_id())); |
204 } | 196 } |
205 | 197 |
206 NavigationRequest::~NavigationRequest() { | 198 NavigationRequest::~NavigationRequest() { |
207 } | 199 } |
208 | 200 |
209 void NavigationRequest::BeginNavigation() { | 201 void NavigationRequest::BeginNavigation() { |
210 DCHECK(!loader_); | 202 DCHECK(!loader_); |
211 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 203 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
212 state_ = STARTED; | 204 state_ = STARTED; |
213 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 205 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 void NavigationRequest::TransferNavigationHandleOwnership( | 249 void NavigationRequest::TransferNavigationHandleOwnership( |
258 RenderFrameHostImpl* render_frame_host) { | 250 RenderFrameHostImpl* render_frame_host) { |
259 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); | 251 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); |
260 } | 252 } |
261 | 253 |
262 void NavigationRequest::OnRequestRedirected( | 254 void NavigationRequest::OnRequestRedirected( |
263 const net::RedirectInfo& redirect_info, | 255 const net::RedirectInfo& redirect_info, |
264 const scoped_refptr<ResourceResponse>& response) { | 256 const scoped_refptr<ResourceResponse>& response) { |
265 // If the navigation is no longer a POST, the POST data should be reset. | 257 // If the navigation is no longer a POST, the POST data should be reset. |
266 if (redirect_info.new_method != "POST") | 258 if (redirect_info.new_method != "POST") |
267 post_data_ = nullptr; | 259 common_params_.post_data = nullptr; |
268 | 260 |
269 common_params_.url = redirect_info.new_url; | 261 common_params_.url = redirect_info.new_url; |
270 common_params_.method = redirect_info.new_method; | 262 common_params_.method = redirect_info.new_method; |
271 common_params_.referrer.url = GURL(redirect_info.new_referrer); | 263 common_params_.referrer.url = GURL(redirect_info.new_referrer); |
272 | 264 |
273 // TODO(clamy): Have CSP + security upgrade checks here. | 265 // TODO(clamy): Have CSP + security upgrade checks here. |
274 // TODO(clamy): Kill the renderer if FilterURL fails? | 266 // TODO(clamy): Kill the renderer if FilterURL fails? |
275 | 267 |
276 // It's safe to use base::Unretained because this NavigationRequest owns the | 268 // It's safe to use base::Unretained because this NavigationRequest owns the |
277 // NavigationHandle where the callback will be stored. | 269 // NavigationHandle where the callback will be stored. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 RenderFrameHostImpl* render_frame_host = | 420 RenderFrameHostImpl* render_frame_host = |
429 navigation_handle_->GetRenderFrameHost(); | 421 navigation_handle_->GetRenderFrameHost(); |
430 DCHECK(render_frame_host == | 422 DCHECK(render_frame_host == |
431 frame_tree_node_->render_manager()->current_frame_host() || | 423 frame_tree_node_->render_manager()->current_frame_host() || |
432 render_frame_host == | 424 render_frame_host == |
433 frame_tree_node_->render_manager()->speculative_frame_host()); | 425 frame_tree_node_->render_manager()->speculative_frame_host()); |
434 | 426 |
435 TransferNavigationHandleOwnership(render_frame_host); | 427 TransferNavigationHandleOwnership(render_frame_host); |
436 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 428 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
437 common_params_, request_params_, | 429 common_params_, request_params_, |
438 is_view_source_, post_data_); | 430 is_view_source_); |
439 | 431 |
440 // When navigating to a Javascript url, the NavigationRequest is not stored | 432 // 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 | 433 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an |
442 // existing pending navigation. | 434 // existing pending navigation. |
443 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) | 435 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) |
444 frame_tree_node_->ResetNavigationRequest(true); | 436 frame_tree_node_->ResetNavigationRequest(true); |
445 } | 437 } |
446 | 438 |
447 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { | 439 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { |
448 // Only initialize the ServiceWorkerNavigationHandle if it can be created for | 440 // Only initialize the ServiceWorkerNavigationHandle if it can be created for |
(...skipping 19 matching lines...) Expand all Loading... | |
468 browser_context, navigating_frame_host->GetSiteInstance()); | 460 browser_context, navigating_frame_host->GetSiteInstance()); |
469 DCHECK(partition); | 461 DCHECK(partition); |
470 | 462 |
471 ServiceWorkerContextWrapper* service_worker_context = | 463 ServiceWorkerContextWrapper* service_worker_context = |
472 static_cast<ServiceWorkerContextWrapper*>( | 464 static_cast<ServiceWorkerContextWrapper*>( |
473 partition->GetServiceWorkerContext()); | 465 partition->GetServiceWorkerContext()); |
474 navigation_handle_->InitServiceWorkerHandle(service_worker_context); | 466 navigation_handle_->InitServiceWorkerHandle(service_worker_context); |
475 } | 467 } |
476 | 468 |
477 } // namespace content | 469 } // namespace content |
OLD | NEW |