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/appcache/appcache_frame_node_navigation.h" |
| 10 #include "content/browser/appcache/appcache_service_impl.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 12 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
11 #include "content/browser/frame_host/frame_tree.h" | 13 #include "content/browser/frame_host/frame_tree.h" |
12 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
13 #include "content/browser/frame_host/navigation_controller_impl.h" | 15 #include "content/browser/frame_host/navigation_controller_impl.h" |
14 #include "content/browser/frame_host/navigation_handle_impl.h" | 16 #include "content/browser/frame_host/navigation_handle_impl.h" |
15 #include "content/browser/frame_host/navigation_request_info.h" | 17 #include "content/browser/frame_host/navigation_request_info.h" |
16 #include "content/browser/frame_host/navigator.h" | 18 #include "content/browser/frame_host/navigator.h" |
17 #include "content/browser/frame_host/navigator_impl.h" | 19 #include "content/browser/frame_host/navigator_impl.h" |
18 #include "content/browser/loader/navigation_url_loader.h" | 20 #include "content/browser/loader/navigation_url_loader.h" |
19 #include "content/browser/renderer_host/render_process_host_impl.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
20 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 22 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
21 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 23 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
22 #include "content/browser/site_instance_impl.h" | 24 #include "content/browser/site_instance_impl.h" |
23 #include "content/common/resource_request_body_impl.h" | 25 #include "content/common/resource_request_body_impl.h" |
24 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
25 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
26 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
27 #include "content/public/browser/navigation_data.h" | 29 #include "content/public/browser/navigation_data.h" |
28 #include "content/public/browser/navigation_ui_data.h" | 30 #include "content/public/browser/navigation_ui_data.h" |
29 #include "content/public/browser/storage_partition.h" | 31 #include "content/public/browser/storage_partition.h" |
30 #include "content/public/browser/stream_handle.h" | 32 #include "content/public/browser/stream_handle.h" |
| 33 #include "content/public/common/appcache_info.h" |
31 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
32 #include "content/public/common/request_context_type.h" | 35 #include "content/public/common/request_context_type.h" |
33 #include "content/public/common/resource_response.h" | 36 #include "content/public/common/resource_response.h" |
34 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
35 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
36 #include "net/base/url_util.h" | 39 #include "net/base/url_util.h" |
37 #include "net/http/http_request_headers.h" | 40 #include "net/http/http_request_headers.h" |
38 #include "net/url_request/redirect_info.h" | 41 #include "net/url_request/redirect_info.h" |
39 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 42 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
40 | 43 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 const NavigationEntryImpl* entry) | 218 const NavigationEntryImpl* entry) |
216 : frame_tree_node_(frame_tree_node), | 219 : frame_tree_node_(frame_tree_node), |
217 common_params_(common_params), | 220 common_params_(common_params), |
218 begin_params_(begin_params), | 221 begin_params_(begin_params), |
219 request_params_(request_params), | 222 request_params_(request_params), |
220 browser_initiated_(browser_initiated), | 223 browser_initiated_(browser_initiated), |
221 state_(NOT_STARTED), | 224 state_(NOT_STARTED), |
222 restore_type_(RestoreType::NONE), | 225 restore_type_(RestoreType::NONE), |
223 is_view_source_(false), | 226 is_view_source_(false), |
224 bindings_(NavigationEntryImpl::kInvalidBindings), | 227 bindings_(NavigationEntryImpl::kInvalidBindings), |
225 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { | 228 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), |
| 229 appcache_host_id_(kAppCacheNoHostId), |
| 230 navigation_committed_(false) { |
226 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); | 231 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
227 if (browser_initiated) { | 232 if (browser_initiated) { |
228 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); | 233 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
229 if (frame_entry) { | 234 if (frame_entry) { |
230 source_site_instance_ = frame_entry->source_site_instance(); | 235 source_site_instance_ = frame_entry->source_site_instance(); |
231 dest_site_instance_ = frame_entry->site_instance(); | 236 dest_site_instance_ = frame_entry->site_instance(); |
232 } | 237 } |
233 | 238 |
234 restore_type_ = entry->restore_type(); | 239 restore_type_ = entry->restore_type(); |
235 is_view_source_ = entry->IsViewSourceMode(); | 240 is_view_source_ = entry->IsViewSourceMode(); |
(...skipping 13 matching lines...) Expand all Loading... |
249 // Add necessary headers that may not be present in the BeginNavigationParams. | 254 // Add necessary headers that may not be present in the BeginNavigationParams. |
250 net::HttpRequestHeaders headers; | 255 net::HttpRequestHeaders headers; |
251 headers.AddHeadersFromString(begin_params_.headers); | 256 headers.AddHeadersFromString(begin_params_.headers); |
252 AddAdditionalRequestHeaders( | 257 AddAdditionalRequestHeaders( |
253 &headers, common_params_.url, common_params_.navigation_type, | 258 &headers, common_params_.url, common_params_.navigation_type, |
254 frame_tree_node_->navigator()->GetController()->GetBrowserContext()); | 259 frame_tree_node_->navigator()->GetController()->GetBrowserContext()); |
255 begin_params_.headers = headers.ToString(); | 260 begin_params_.headers = headers.ToString(); |
256 } | 261 } |
257 | 262 |
258 NavigationRequest::~NavigationRequest() { | 263 NavigationRequest::~NavigationRequest() { |
| 264 // If the navigation was started but never committed we need to inform the |
| 265 // AppCacheFrameNavigationHandler about this so it can clean up any state. |
| 266 if ((state_ == STARTED || state_ == RESPONSE_STARTED) && |
| 267 !navigation_committed_) { |
| 268 AppCacheFrameNavigationHandler::FailedNavigation( |
| 269 frame_tree_node_->frame_tree_node_id()); |
| 270 } |
259 } | 271 } |
260 | 272 |
261 void NavigationRequest::BeginNavigation() { | 273 void NavigationRequest::BeginNavigation() { |
262 DCHECK(!loader_); | 274 DCHECK(!loader_); |
263 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 275 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
264 state_ = STARTED; | 276 state_ = STARTED; |
265 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 277 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
266 | 278 |
| 279 SiteInstance* site_instance = |
| 280 frame_tree_node_->current_frame_host()->GetSiteInstance(); |
| 281 StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 282 site_instance->GetBrowserContext(), site_instance); |
| 283 |
| 284 // Inform the AppCacheFrameNavigationHandler class about this navigation. |
| 285 // This function returns the AppCache host id which we need to pass to the |
| 286 // renderer when the navigation commits. |
| 287 appcache_host_id_ = AppCacheFrameNavigationHandler::BeginNavigation( |
| 288 static_cast<AppCacheServiceImpl*>(partition->GetAppCacheService()), |
| 289 frame_tree_node_->frame_tree_node_id()); |
| 290 |
267 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 291 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { |
268 // It's safe to use base::Unretained because this NavigationRequest owns | 292 // It's safe to use base::Unretained because this NavigationRequest owns |
269 // the NavigationHandle where the callback will be stored. | 293 // the NavigationHandle where the callback will be stored. |
270 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 294 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
271 // TODO(clamy): pass the method to the NavigationHandle instead of a | 295 // TODO(clamy): pass the method to the NavigationHandle instead of a |
272 // boolean. | 296 // boolean. |
273 navigation_handle_->WillStartRequest( | 297 navigation_handle_->WillStartRequest( |
274 common_params_.method, common_params_.post_data, | 298 common_params_.method, common_params_.post_data, |
275 Referrer::SanitizeForRequest(common_params_.url, | 299 Referrer::SanitizeForRequest(common_params_.url, |
276 common_params_.referrer), | 300 common_params_.referrer), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 common_params_.should_replace_current_entry, false, false, | 453 common_params_.should_replace_current_entry, false, false, |
430 base::Closure(), | 454 base::Closure(), |
431 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, | 455 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, |
432 base::Unretained(this))); | 456 base::Unretained(this))); |
433 } | 457 } |
434 | 458 |
435 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 459 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
436 int net_error) { | 460 int net_error) { |
437 DCHECK(state_ == STARTED); | 461 DCHECK(state_ == STARTED); |
438 state_ = FAILED; | 462 state_ = FAILED; |
| 463 |
| 464 AppCacheFrameNavigationHandler::FailedNavigation( |
| 465 frame_tree_node_->frame_tree_node_id()); |
| 466 |
439 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 467 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
440 frame_tree_node_->navigator()->FailedNavigation( | 468 frame_tree_node_->navigator()->FailedNavigation( |
441 frame_tree_node_, has_stale_copy_in_cache, net_error); | 469 frame_tree_node_, has_stale_copy_in_cache, net_error); |
442 } | 470 } |
443 | 471 |
444 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 472 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
445 if (frame_tree_node_->IsMainFrame()) { | 473 if (frame_tree_node_->IsMainFrame()) { |
446 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( | 474 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( |
447 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), | 475 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), |
448 timestamp); | 476 timestamp); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 bool report_raw_headers = | 552 bool report_raw_headers = |
525 RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled(frame_tree_node_); | 553 RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled(frame_tree_node_); |
526 | 554 |
527 loader_ = NavigationURLLoader::Create( | 555 loader_ = NavigationURLLoader::Create( |
528 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 556 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
529 base::MakeUnique<NavigationRequestInfo>( | 557 base::MakeUnique<NavigationRequestInfo>( |
530 common_params_, begin_params_, first_party_for_cookies, | 558 common_params_, begin_params_, first_party_for_cookies, |
531 frame_tree_node_->current_origin(), frame_tree_node_->IsMainFrame(), | 559 frame_tree_node_->current_origin(), frame_tree_node_->IsMainFrame(), |
532 parent_is_main_frame, IsSecureFrame(frame_tree_node_->parent()), | 560 parent_is_main_frame, IsSecureFrame(frame_tree_node_->parent()), |
533 frame_tree_node_->frame_tree_node_id(), is_for_guests_only, | 561 frame_tree_node_->frame_tree_node_id(), is_for_guests_only, |
534 report_raw_headers), | 562 report_raw_headers, appcache_host_id_, |
| 563 static_cast<AppCacheServiceImpl*>(partition->GetAppCacheService())), |
535 std::move(navigation_ui_data), | 564 std::move(navigation_ui_data), |
536 navigation_handle_->service_worker_handle(), this); | 565 navigation_handle_->service_worker_handle(), this); |
537 } | 566 } |
538 | 567 |
539 void NavigationRequest::OnRedirectChecksComplete( | 568 void NavigationRequest::OnRedirectChecksComplete( |
540 NavigationThrottle::ThrottleCheckResult result) { | 569 NavigationThrottle::ThrottleCheckResult result) { |
541 CHECK(result != NavigationThrottle::DEFER); | 570 CHECK(result != NavigationThrottle::DEFER); |
542 | 571 |
543 // Abort the request if needed. This will destroy the NavigationRequest. | 572 // Abort the request if needed. This will destroy the NavigationRequest. |
544 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | 573 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 navigation_handle_->GetRenderFrameHost(); | 610 navigation_handle_->GetRenderFrameHost(); |
582 DCHECK(render_frame_host == | 611 DCHECK(render_frame_host == |
583 frame_tree_node_->render_manager()->current_frame_host() || | 612 frame_tree_node_->render_manager()->current_frame_host() || |
584 render_frame_host == | 613 render_frame_host == |
585 frame_tree_node_->render_manager()->speculative_frame_host()); | 614 frame_tree_node_->render_manager()->speculative_frame_host()); |
586 | 615 |
587 TransferNavigationHandleOwnership(render_frame_host); | 616 TransferNavigationHandleOwnership(render_frame_host); |
588 | 617 |
589 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 618 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); |
590 | 619 |
| 620 AppCacheFrameNavigationHandler::CommitNavigation( |
| 621 frame_tree_node_->frame_tree_node_id(), |
| 622 render_frame_host->GetProcess()->GetID()); |
| 623 |
| 624 navigation_committed_ = true; |
| 625 |
| 626 request_params_.appcache_host_id = appcache_host_id_; |
| 627 |
591 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 628 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
592 common_params_, request_params_, | 629 common_params_, request_params_, |
593 is_view_source_); | 630 is_view_source_); |
594 | 631 |
595 frame_tree_node_->ResetNavigationRequest(true); | 632 frame_tree_node_->ResetNavigationRequest(true); |
596 } | 633 } |
597 | 634 |
598 } // namespace content | 635 } // namespace content |
OLD | NEW |