| 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/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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 navigation_handle_->WillRedirectRequest( | 252 navigation_handle_->WillRedirectRequest( |
| 253 common_params_.url, begin_params_.method == "POST", | 253 common_params_.url, begin_params_.method == "POST", |
| 254 common_params_.referrer.url, false, response->head.headers, | 254 common_params_.referrer.url, false, response->head.headers, |
| 255 base::Bind(&NavigationRequest::OnRedirectChecksComplete, | 255 base::Bind(&NavigationRequest::OnRedirectChecksComplete, |
| 256 base::Unretained(this))); | 256 base::Unretained(this))); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void NavigationRequest::OnResponseStarted( | 259 void NavigationRequest::OnResponseStarted( |
| 260 const scoped_refptr<ResourceResponse>& response, | 260 const scoped_refptr<ResourceResponse>& response, |
| 261 scoped_ptr<StreamHandle> body) { | 261 scoped_ptr<StreamHandle> body) { |
| 262 DCHECK(state_ == STARTED); | 262 DCHECK(state_ == STARTED && !response_ && !body_); |
| 263 state_ = RESPONSE_STARTED; | 263 state_ = RESPONSE_STARTED; |
| 264 response_ = response.get(); |
| 265 body_ = std::move(body); |
| 264 | 266 |
| 265 // Update the service worker params of the request params. | 267 // Update the service worker params of the request params. |
| 266 request_params_.should_create_service_worker = | 268 request_params_.should_create_service_worker = |
| 267 (frame_tree_node_->pending_sandbox_flags() & | 269 (frame_tree_node_->pending_sandbox_flags() & |
| 268 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; | 270 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; |
| 269 if (navigation_handle_->service_worker_handle()) { | 271 if (navigation_handle_->service_worker_handle()) { |
| 270 request_params_.service_worker_provider_id = | 272 request_params_.service_worker_provider_id = |
| 271 navigation_handle_->service_worker_handle() | 273 navigation_handle_->service_worker_handle() |
| 272 ->service_worker_provider_host_id(); | 274 ->service_worker_provider_host_id(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 frame_tree_node_->navigator()->CommitNavigation( | 277 navigation_handle_->WillProcessResponse( |
| 276 frame_tree_node_, response.get(), std::move(body)); | 278 response->head.headers, |
| 279 base::Bind(&NavigationRequest::OnResponseChecksComplete, |
| 280 base::Unretained(this))); |
| 277 } | 281 } |
| 278 | 282 |
| 279 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 283 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
| 280 int net_error) { | 284 int net_error) { |
| 281 DCHECK(state_ == STARTED); | 285 DCHECK(state_ == STARTED); |
| 282 state_ = FAILED; | 286 state_ = FAILED; |
| 283 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 287 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
| 284 frame_tree_node_->navigator()->FailedNavigation( | 288 frame_tree_node_->navigator()->FailedNavigation( |
| 285 frame_tree_node_, has_stale_copy_in_cache, net_error); | 289 frame_tree_node_, has_stale_copy_in_cache, net_error); |
| 286 } | 290 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 result == NavigationThrottle::CANCEL) { | 327 result == NavigationThrottle::CANCEL) { |
| 324 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | 328 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
| 325 frame_tree_node_->ResetNavigationRequest(false); | 329 frame_tree_node_->ResetNavigationRequest(false); |
| 326 return; | 330 return; |
| 327 } | 331 } |
| 328 | 332 |
| 329 loader_->FollowRedirect(); | 333 loader_->FollowRedirect(); |
| 330 navigation_handle_->DidRedirectNavigation(common_params_.url); | 334 navigation_handle_->DidRedirectNavigation(common_params_.url); |
| 331 } | 335 } |
| 332 | 336 |
| 337 void NavigationRequest::OnResponseChecksComplete( |
| 338 NavigationThrottle::ThrottleCheckResult result) { |
| 339 CHECK(result != NavigationThrottle::DEFER); |
| 340 |
| 341 // Abort the request if needed. This will destroy the NavigationRequest. |
| 342 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 343 result == NavigationThrottle::CANCEL) { |
| 344 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
| 345 frame_tree_node_->ResetNavigationRequest(false); |
| 346 return; |
| 347 } |
| 348 |
| 349 frame_tree_node_->navigator()->CommitNavigation( |
| 350 frame_tree_node_, response_.get(), std::move(body_)); |
| 351 } |
| 352 |
| 333 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { | 353 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { |
| 334 // Only initialize the ServiceWorkerNavigationHandle if it can be created for | 354 // Only initialize the ServiceWorkerNavigationHandle if it can be created for |
| 335 // this frame. | 355 // this frame. |
| 336 bool can_create_service_worker = | 356 bool can_create_service_worker = |
| 337 (frame_tree_node_->pending_sandbox_flags() & | 357 (frame_tree_node_->pending_sandbox_flags() & |
| 338 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; | 358 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; |
| 339 if (!can_create_service_worker) | 359 if (!can_create_service_worker) |
| 340 return; | 360 return; |
| 341 | 361 |
| 342 // Use the SiteInstance of the navigating RenderFrameHost to get access to | 362 // Use the SiteInstance of the navigating RenderFrameHost to get access to |
| (...skipping 11 matching lines...) Expand all Loading... |
| 354 browser_context, navigating_frame_host->GetSiteInstance()); | 374 browser_context, navigating_frame_host->GetSiteInstance()); |
| 355 DCHECK(partition); | 375 DCHECK(partition); |
| 356 | 376 |
| 357 ServiceWorkerContextWrapper* service_worker_context = | 377 ServiceWorkerContextWrapper* service_worker_context = |
| 358 static_cast<ServiceWorkerContextWrapper*>( | 378 static_cast<ServiceWorkerContextWrapper*>( |
| 359 partition->GetServiceWorkerContext()); | 379 partition->GetServiceWorkerContext()); |
| 360 navigation_handle_->InitServiceWorkerHandle(service_worker_context); | 380 navigation_handle_->InitServiceWorkerHandle(service_worker_context); |
| 361 } | 381 } |
| 362 | 382 |
| 363 } // namespace content | 383 } // namespace content |
| OLD | NEW |