Chromium Code Reviews| 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 frame_tree_node_->current_frame_host(), 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 } |
| 287 | 291 |
| 288 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 292 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
| 289 if (frame_tree_node_->IsMainFrame()) { | 293 if (frame_tree_node_->IsMainFrame()) { |
| 290 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( | 294 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( |
| 291 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), | 295 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), |
| 292 timestamp.ToInternalValue()); | 296 timestamp.ToInternalValue()); |
| 293 } | 297 } |
| 294 | 298 |
| 295 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, | 299 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, |
| 296 common_params_.url); | 300 common_params_.url); |
| 297 } | 301 } |
| 298 | 302 |
| 299 void NavigationRequest::OnStartChecksComplete( | 303 void NavigationRequest::OnStartChecksComplete( |
| 300 NavigationThrottle::ThrottleCheckResult result) { | 304 NavigationThrottle::ThrottleCheckResult result) { |
| 301 CHECK(result != NavigationThrottle::DEFER); | 305 CHECK(result != NavigationThrottle::DEFER); |
| 302 | 306 |
| 303 // Abort the request if needed. This will destroy the NavigationRequest. | 307 // Abort the request if needed. This will destroy the NavigationRequest. |
| 304 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | 308 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 305 result == NavigationThrottle::CANCEL) { | 309 result == NavigationThrottle::CANCEL || |
| 310 result == NavigationThrottle::BLOCK) { | |
| 306 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | 311 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
| 307 frame_tree_node_->ResetNavigationRequest(false); | 312 frame_tree_node_->ResetNavigationRequest(false); |
| 308 return; | 313 return; |
| 309 } | 314 } |
| 310 | 315 |
| 311 InitializeServiceWorkerHandleIfNeeded(); | 316 InitializeServiceWorkerHandleIfNeeded(); |
| 312 loader_ = NavigationURLLoader::Create( | 317 loader_ = NavigationURLLoader::Create( |
| 313 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 318 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 314 std::move(info_), navigation_handle_->service_worker_handle(), this); | 319 std::move(info_), navigation_handle_->service_worker_handle(), this); |
| 315 } | 320 } |
| 316 | 321 |
| 317 void NavigationRequest::OnRedirectChecksComplete( | 322 void NavigationRequest::OnRedirectChecksComplete( |
| 318 NavigationThrottle::ThrottleCheckResult result) { | 323 NavigationThrottle::ThrottleCheckResult result) { |
| 319 CHECK(result != NavigationThrottle::DEFER); | 324 CHECK(result != NavigationThrottle::DEFER); |
| 320 | 325 |
| 321 // Abort the request if needed. This will destroy the NavigationRequest. | 326 // Abort the request if needed. This will destroy the NavigationRequest. |
| 322 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | 327 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 323 result == NavigationThrottle::CANCEL) { | 328 result == NavigationThrottle::CANCEL || |
| 329 result == NavigationThrottle::BLOCK) { | |
| 324 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | 330 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
| 325 frame_tree_node_->ResetNavigationRequest(false); | 331 frame_tree_node_->ResetNavigationRequest(false); |
| 326 return; | 332 return; |
| 327 } | 333 } |
| 328 | 334 |
| 329 loader_->FollowRedirect(); | 335 loader_->FollowRedirect(); |
| 330 navigation_handle_->DidRedirectNavigation(common_params_.url); | 336 navigation_handle_->DidRedirectNavigation(common_params_.url); |
| 331 } | 337 } |
| 332 | 338 |
| 339 void NavigationRequest::OnResponseChecksComplete( | |
| 340 NavigationThrottle::ThrottleCheckResult result) { | |
| 341 CHECK(result != NavigationThrottle::DEFER); | |
| 342 | |
| 343 // Abort the request if needed. This will destroy the NavigationRequest. | |
| 344 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | |
| 345 result == NavigationThrottle::CANCEL || | |
| 346 result == NavigationThrottle::BLOCK) { | |
| 347 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | |
|
nasko
2016/01/20 23:15:07
Do we need to distinguish BLOCK as well?
| |
| 348 frame_tree_node_->ResetNavigationRequest(false); | |
| 349 return; | |
| 350 } | |
| 351 | |
| 352 frame_tree_node_->navigator()->CommitNavigation( | |
| 353 frame_tree_node_, response_.get(), std::move(body_)); | |
| 354 } | |
| 355 | |
| 333 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { | 356 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { |
| 334 // Only initialize the ServiceWorkerNavigationHandle if it can be created for | 357 // Only initialize the ServiceWorkerNavigationHandle if it can be created for |
| 335 // this frame. | 358 // this frame. |
| 336 bool can_create_service_worker = | 359 bool can_create_service_worker = |
| 337 (frame_tree_node_->pending_sandbox_flags() & | 360 (frame_tree_node_->pending_sandbox_flags() & |
| 338 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; | 361 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; |
| 339 if (!can_create_service_worker) | 362 if (!can_create_service_worker) |
| 340 return; | 363 return; |
| 341 | 364 |
| 342 // Use the SiteInstance of the navigating RenderFrameHost to get access to | 365 // 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()); | 377 browser_context, navigating_frame_host->GetSiteInstance()); |
| 355 DCHECK(partition); | 378 DCHECK(partition); |
| 356 | 379 |
| 357 ServiceWorkerContextWrapper* service_worker_context = | 380 ServiceWorkerContextWrapper* service_worker_context = |
| 358 static_cast<ServiceWorkerContextWrapper*>( | 381 static_cast<ServiceWorkerContextWrapper*>( |
| 359 partition->GetServiceWorkerContext()); | 382 partition->GetServiceWorkerContext()); |
| 360 navigation_handle_->InitServiceWorkerHandle(service_worker_context); | 383 navigation_handle_->InitServiceWorkerHandle(service_worker_context); |
| 361 } | 384 } |
| 362 | 385 |
| 363 } // namespace content | 386 } // namespace content |
| OLD | NEW |