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 "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/navigation_controller_impl.h" | 9 #include "content/browser/frame_host/navigation_controller_impl.h" |
10 #include "content/browser/frame_host/navigation_handle_impl.h" | 10 #include "content/browser/frame_host/navigation_handle_impl.h" |
11 #include "content/browser/frame_host/navigation_request_info.h" | 11 #include "content/browser/frame_host/navigation_request_info.h" |
12 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/loader/navigation_url_loader.h" | 13 #include "content/browser/loader/navigation_url_loader.h" |
14 #include "content/browser/site_instance_impl.h" | 14 #include "content/browser/site_instance_impl.h" |
15 #include "content/common/resource_request_body.h" | 15 #include "content/common/resource_request_body.h" |
16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_throttle.h" | |
18 #include "content/public/browser/stream_handle.h" | 17 #include "content/public/browser/stream_handle.h" |
19 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
20 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
21 #include "net/http/http_request_headers.h" | 20 #include "net/http/http_request_headers.h" |
22 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 NavigationRequest::~NavigationRequest() { | 173 NavigationRequest::~NavigationRequest() { |
175 } | 174 } |
176 | 175 |
177 bool NavigationRequest::BeginNavigation() { | 176 bool NavigationRequest::BeginNavigation() { |
178 DCHECK(!loader_); | 177 DCHECK(!loader_); |
179 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 178 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
180 state_ = STARTED; | 179 state_ = STARTED; |
181 | 180 |
182 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 181 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { |
183 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | |
184 NavigationThrottle::ThrottleCheckResult result = | |
185 navigation_handle_->WillStartRequest( | |
186 begin_params_.method == "POST", | |
187 Referrer::SanitizeForRequest(common_params_.url, | |
188 common_params_.referrer), | |
189 begin_params_.has_user_gesture, common_params_.transition, false); | |
190 | |
191 // Abort the request if needed. This will destroy the NavigationRequest. | |
192 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
193 frame_tree_node_->ResetNavigationRequest(false); | |
194 return false; | |
195 } | |
196 | |
197 loader_ = NavigationURLLoader::Create( | 182 loader_ = NavigationURLLoader::Create( |
198 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 183 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
199 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); | 184 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); |
200 return true; | 185 return true; |
201 } | 186 } |
202 | 187 |
203 // There is no need to make a network request for this navigation, so commit | 188 // There is no need to make a network request for this navigation, so commit |
204 // it immediately. | 189 // it immediately. |
205 state_ = RESPONSE_STARTED; | 190 state_ = RESPONSE_STARTED; |
206 frame_tree_node_->navigator()->CommitNavigation( | 191 frame_tree_node_->navigator()->CommitNavigation( |
(...skipping 10 matching lines...) Expand all Loading... |
217 } | 202 } |
218 | 203 |
219 void NavigationRequest::TransferNavigationHandleOwnership( | 204 void NavigationRequest::TransferNavigationHandleOwnership( |
220 RenderFrameHostImpl* render_frame_host) { | 205 RenderFrameHostImpl* render_frame_host) { |
221 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); | 206 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); |
222 } | 207 } |
223 | 208 |
224 void NavigationRequest::OnRequestRedirected( | 209 void NavigationRequest::OnRequestRedirected( |
225 const net::RedirectInfo& redirect_info, | 210 const net::RedirectInfo& redirect_info, |
226 const scoped_refptr<ResourceResponse>& response) { | 211 const scoped_refptr<ResourceResponse>& response) { |
| 212 // TODO(davidben): Track other changes from redirects. These are important |
| 213 // for, e.g., reloads. |
227 common_params_.url = redirect_info.new_url; | 214 common_params_.url = redirect_info.new_url; |
228 begin_params_.method = redirect_info.new_method; | |
229 common_params_.referrer.url = GURL(redirect_info.new_referrer); | |
230 | 215 |
231 // TODO(clamy): Have CSP + security upgrade checks here. | 216 // TODO(davidben): This where prerender and navigation_interceptor should be |
232 // TODO(clamy): Kill the renderer if FilterURL fails? | 217 // integrated. For now, just always follow all redirects. |
233 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | |
234 NavigationThrottle::ThrottleCheckResult result = | |
235 navigation_handle_->WillRedirectRequest( | |
236 common_params_.url, begin_params_.method == "POST", | |
237 common_params_.referrer.url, false); | |
238 | |
239 // Abort the request if needed. This will destroy the NavigationRequest. | |
240 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
241 frame_tree_node_->ResetNavigationRequest(false); | |
242 return; | |
243 } | |
244 | |
245 loader_->FollowRedirect(); | 218 loader_->FollowRedirect(); |
246 | 219 |
247 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); | 220 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); |
248 } | 221 } |
249 | 222 |
250 void NavigationRequest::OnResponseStarted( | 223 void NavigationRequest::OnResponseStarted( |
251 const scoped_refptr<ResourceResponse>& response, | 224 const scoped_refptr<ResourceResponse>& response, |
252 scoped_ptr<StreamHandle> body) { | 225 scoped_ptr<StreamHandle> body) { |
253 DCHECK(state_ == STARTED); | 226 DCHECK(state_ == STARTED); |
254 state_ = RESPONSE_STARTED; | 227 state_ = RESPONSE_STARTED; |
255 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, | 228 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, |
256 response.get(), body.Pass()); | 229 response.get(), body.Pass()); |
257 } | 230 } |
258 | 231 |
259 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 232 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
260 int net_error) { | 233 int net_error) { |
261 DCHECK(state_ == STARTED); | 234 DCHECK(state_ == STARTED); |
262 state_ = FAILED; | 235 state_ = FAILED; |
263 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 236 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
264 frame_tree_node_->navigator()->FailedNavigation( | 237 frame_tree_node_->navigator()->FailedNavigation( |
265 frame_tree_node_, has_stale_copy_in_cache, net_error); | 238 frame_tree_node_, has_stale_copy_in_cache, net_error); |
266 } | 239 } |
267 | 240 |
268 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 241 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
269 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, | 242 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, |
270 common_params_.url); | 243 common_params_.url); |
271 } | 244 } |
272 | 245 |
273 } // namespace content | 246 } // namespace content |
OLD | NEW |