OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 gfx::NativeViewAccessible | 457 gfx::NativeViewAccessible |
458 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { | 458 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { |
459 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 459 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
460 render_view_host_->GetView()); | 460 render_view_host_->GetView()); |
461 if (view) | 461 if (view) |
462 return view->AccessibilityGetNativeViewAccessible(); | 462 return view->AccessibilityGetNativeViewAccessible(); |
463 return NULL; | 463 return NULL; |
464 } | 464 } |
465 | 465 |
466 bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id) { | 466 bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id) { |
467 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::CreateRenderFrame"); | 467 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); |
468 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; | 468 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; |
469 | 469 |
470 // The process may (if we're sharing a process with another host that already | 470 // The process may (if we're sharing a process with another host that already |
471 // initialized it) or may not (we have our own process or the old process | 471 // initialized it) or may not (we have our own process or the old process |
472 // crashed) have been initialized. Calling Init multiple times will be | 472 // crashed) have been initialized. Calling Init multiple times will be |
473 // ignored, so this is safe. | 473 // ignored, so this is safe. |
474 if (!GetProcess()->Init()) | 474 if (!GetProcess()->Init()) |
475 return false; | 475 return false; |
476 | 476 |
477 DCHECK(GetProcess()->HasConnection()); | 477 DCHECK(GetProcess()->HasConnection()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 522 |
523 void RenderFrameHostImpl::OnFrameFocused() { | 523 void RenderFrameHostImpl::OnFrameFocused() { |
524 frame_tree_->SetFocusedFrame(frame_tree_node_); | 524 frame_tree_->SetFocusedFrame(frame_tree_node_); |
525 } | 525 } |
526 | 526 |
527 void RenderFrameHostImpl::OnOpenURL( | 527 void RenderFrameHostImpl::OnOpenURL( |
528 const FrameHostMsg_OpenURL_Params& params) { | 528 const FrameHostMsg_OpenURL_Params& params) { |
529 GURL validated_url(params.url); | 529 GURL validated_url(params.url); |
530 GetProcess()->FilterURL(false, &validated_url); | 530 GetProcess()->FilterURL(false, &validated_url); |
531 | 531 |
| 532 TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnOpenURL", |
| 533 "url", validated_url.possibly_invalid_spec()); |
532 frame_tree_node_->navigator()->RequestOpenURL( | 534 frame_tree_node_->navigator()->RequestOpenURL( |
533 this, validated_url, params.referrer, params.disposition, | 535 this, validated_url, params.referrer, params.disposition, |
534 params.should_replace_current_entry, params.user_gesture); | 536 params.should_replace_current_entry, params.user_gesture); |
535 } | 537 } |
536 | 538 |
537 void RenderFrameHostImpl::OnDocumentOnLoadCompleted() { | 539 void RenderFrameHostImpl::OnDocumentOnLoadCompleted() { |
538 // This message is only sent for top-level frames. TODO(avi): when frame tree | 540 // This message is only sent for top-level frames. TODO(avi): when frame tree |
539 // mirroring works correctly, add a check here to enforce it. | 541 // mirroring works correctly, add a check here to enforce it. |
540 delegate_->DocumentOnLoadCompleted(this); | 542 delegate_->DocumentOnLoadCompleted(this); |
541 } | 543 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 // get a new page_id because we need to create a new navigation entry for that | 582 // get a new page_id because we need to create a new navigation entry for that |
581 // action. | 583 // action. |
582 void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) { | 584 void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) { |
583 // Read the parameters out of the IPC message directly to avoid making another | 585 // Read the parameters out of the IPC message directly to avoid making another |
584 // copy when we filter the URLs. | 586 // copy when we filter the URLs. |
585 PickleIterator iter(msg); | 587 PickleIterator iter(msg); |
586 FrameHostMsg_DidCommitProvisionalLoad_Params validated_params; | 588 FrameHostMsg_DidCommitProvisionalLoad_Params validated_params; |
587 if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>:: | 589 if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>:: |
588 Read(&msg, &iter, &validated_params)) | 590 Read(&msg, &iter, &validated_params)) |
589 return; | 591 return; |
| 592 TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnNavigate", |
| 593 "url", validated_params.url.possibly_invalid_spec()); |
590 | 594 |
591 // If we're waiting for a cross-site beforeunload ack from this renderer and | 595 // If we're waiting for a cross-site beforeunload ack from this renderer and |
592 // we receive a Navigate message from the main frame, then the renderer was | 596 // we receive a Navigate message from the main frame, then the renderer was |
593 // navigating already and sent it before hearing the FrameMsg_Stop message. | 597 // navigating already and sent it before hearing the FrameMsg_Stop message. |
594 // We do not want to cancel the pending navigation in this case, since the | 598 // We do not want to cancel the pending navigation in this case, since the |
595 // old page will soon be stopped. Instead, treat this as a beforeunload ack | 599 // old page will soon be stopped. Instead, treat this as a beforeunload ack |
596 // to allow the pending navigation to continue. | 600 // to allow the pending navigation to continue. |
597 if (render_view_host_->is_waiting_for_beforeunload_ack_ && | 601 if (render_view_host_->is_waiting_for_beforeunload_ack_ && |
598 render_view_host_->unload_ack_is_for_cross_site_transition_ && | 602 render_view_host_->unload_ack_is_for_cross_site_transition_ && |
599 PageTransitionIsMainFrame(validated_params.transition)) { | 603 PageTransitionIsMainFrame(validated_params.transition)) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 frame_tree_node_->render_manager()->OnDeferredAfterResponseStarted( | 680 frame_tree_node_->render_manager()->OnDeferredAfterResponseStarted( |
677 global_request_id, this); | 681 global_request_id, this); |
678 | 682 |
679 if (GetParent() || !delegate_->WillHandleDeferAfterResponseStarted()) | 683 if (GetParent() || !delegate_->WillHandleDeferAfterResponseStarted()) |
680 frame_tree_node_->render_manager()->ResumeResponseDeferredAtStart(); | 684 frame_tree_node_->render_manager()->ResumeResponseDeferredAtStart(); |
681 else | 685 else |
682 delegate_->DidDeferAfterResponseStarted(transition_data); | 686 delegate_->DidDeferAfterResponseStarted(transition_data); |
683 } | 687 } |
684 | 688 |
685 void RenderFrameHostImpl::SwapOut(RenderFrameProxyHost* proxy) { | 689 void RenderFrameHostImpl::SwapOut(RenderFrameProxyHost* proxy) { |
| 690 // The end of this event is in OnSwapOutACK when the RenderFrame has completed |
| 691 // the operation and sends back an IPC message. |
| 692 // The trace event may not end properly if the ACK times out. We expect this |
| 693 // to be fixed when RenderViewHostImpl::OnSwapOut moves to RenderFrameHost. |
| 694 TRACE_EVENT_ASYNC_BEGIN0("navigation", "RenderFrameHostImpl::SwapOut", this); |
| 695 |
686 // TODO(creis): Move swapped out state to RFH. Until then, only update it | 696 // TODO(creis): Move swapped out state to RFH. Until then, only update it |
687 // when swapping out the main frame. | 697 // when swapping out the main frame. |
688 if (!GetParent()) { | 698 if (!GetParent()) { |
689 // If this RenderViewHost is not in the default state, it must have already | 699 // If this RenderViewHost is not in the default state, it must have already |
690 // gone through this, therefore just return. | 700 // gone through this, therefore just return. |
691 if (render_view_host_->rvh_state_ != RenderViewHostImpl::STATE_DEFAULT) | 701 if (render_view_host_->rvh_state_ != RenderViewHostImpl::STATE_DEFAULT) |
692 return; | 702 return; |
693 | 703 |
694 render_view_host_->SetState( | 704 render_view_host_->SetState( |
695 RenderViewHostImpl::STATE_PENDING_SWAP_OUT); | 705 RenderViewHostImpl::STATE_PENDING_SWAP_OUT); |
(...skipping 10 matching lines...) Expand all Loading... |
706 if (!GetParent()) | 716 if (!GetParent()) |
707 delegate_->SwappedOut(this); | 717 delegate_->SwappedOut(this); |
708 else | 718 else |
709 set_swapped_out(true); | 719 set_swapped_out(true); |
710 } | 720 } |
711 | 721 |
712 void RenderFrameHostImpl::OnBeforeUnloadACK( | 722 void RenderFrameHostImpl::OnBeforeUnloadACK( |
713 bool proceed, | 723 bool proceed, |
714 const base::TimeTicks& renderer_before_unload_start_time, | 724 const base::TimeTicks& renderer_before_unload_start_time, |
715 const base::TimeTicks& renderer_before_unload_end_time) { | 725 const base::TimeTicks& renderer_before_unload_end_time) { |
| 726 TRACE_EVENT_ASYNC_END0( |
| 727 "navigation", "RenderFrameHostImpl::BeforeUnload", this); |
716 // TODO(creis): Support properly beforeunload on subframes. For now just | 728 // TODO(creis): Support properly beforeunload on subframes. For now just |
717 // pretend that the handler ran and allowed the navigation to proceed. | 729 // pretend that the handler ran and allowed the navigation to proceed. |
718 if (GetParent()) { | 730 if (GetParent()) { |
719 render_view_host_->is_waiting_for_beforeunload_ack_ = false; | 731 render_view_host_->is_waiting_for_beforeunload_ack_ = false; |
720 frame_tree_node_->render_manager()->OnBeforeUnloadACK( | 732 frame_tree_node_->render_manager()->OnBeforeUnloadACK( |
721 render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, | 733 render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, |
722 renderer_before_unload_end_time); | 734 renderer_before_unload_end_time); |
723 return; | 735 return; |
724 } | 736 } |
725 | 737 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, | 790 render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, |
779 before_unload_end_time); | 791 before_unload_end_time); |
780 | 792 |
781 // If canceled, notify the delegate to cancel its pending navigation entry. | 793 // If canceled, notify the delegate to cancel its pending navigation entry. |
782 if (!proceed) | 794 if (!proceed) |
783 render_view_host_->GetDelegate()->DidCancelLoading(); | 795 render_view_host_->GetDelegate()->DidCancelLoading(); |
784 } | 796 } |
785 | 797 |
786 void RenderFrameHostImpl::OnSwapOutACK() { | 798 void RenderFrameHostImpl::OnSwapOutACK() { |
787 OnSwappedOut(false); | 799 OnSwappedOut(false); |
| 800 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); |
788 } | 801 } |
789 | 802 |
790 void RenderFrameHostImpl::OnSwappedOut(bool timed_out) { | 803 void RenderFrameHostImpl::OnSwappedOut(bool timed_out) { |
791 // For now, we only need to update the RVH state machine for top-level swaps. | 804 // For now, we only need to update the RVH state machine for top-level swaps. |
792 if (!GetParent()) | 805 if (!GetParent()) |
793 render_view_host_->OnSwappedOut(timed_out); | 806 render_view_host_->OnSwappedOut(timed_out); |
794 } | 807 } |
795 | 808 |
796 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { | 809 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { |
797 // Validate the URLs in |params|. If the renderer can't request the URLs | 810 // Validate the URLs in |params|. If the renderer can't request the URLs |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { | 1053 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { |
1041 // TODO(creis): We should also check for WebUI pages here. Also, when the | 1054 // TODO(creis): We should also check for WebUI pages here. Also, when the |
1042 // out-of-process iframes implementation is ready, we should check for | 1055 // out-of-process iframes implementation is ready, we should check for |
1043 // cross-site URLs that are not allowed to commit in this process. | 1056 // cross-site URLs that are not allowed to commit in this process. |
1044 | 1057 |
1045 // Give the client a chance to disallow URLs from committing. | 1058 // Give the client a chance to disallow URLs from committing. |
1046 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); | 1059 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); |
1047 } | 1060 } |
1048 | 1061 |
1049 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { | 1062 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { |
1050 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); | 1063 TRACE_EVENT0("navigation", "RenderFrameHostImpl::Navigate"); |
1051 // Browser plugin guests are not allowed to navigate outside web-safe schemes, | 1064 // Browser plugin guests are not allowed to navigate outside web-safe schemes, |
1052 // so do not grant them the ability to request additional URLs. | 1065 // so do not grant them the ability to request additional URLs. |
1053 if (!GetProcess()->IsIsolatedGuest()) { | 1066 if (!GetProcess()->IsIsolatedGuest()) { |
1054 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( | 1067 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( |
1055 GetProcess()->GetID(), params.url); | 1068 GetProcess()->GetID(), params.url); |
1056 if (params.url.SchemeIs(url::kDataScheme) && | 1069 if (params.url.SchemeIs(url::kDataScheme) && |
1057 params.base_url_for_data_url.SchemeIs(url::kFileScheme)) { | 1070 params.base_url_for_data_url.SchemeIs(url::kFileScheme)) { |
1058 // If 'data:' is used, and we have a 'file:' base url, grant access to | 1071 // If 'data:' is used, and we have a 'file:' base url, grant access to |
1059 // local files. | 1072 // local files. |
1060 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( | 1073 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 1118 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1106 params.browser_navigation_start = base::TimeTicks::Now(); | 1119 params.browser_navigation_start = base::TimeTicks::Now(); |
1107 Navigate(params); | 1120 Navigate(params); |
1108 } | 1121 } |
1109 | 1122 |
1110 void RenderFrameHostImpl::Stop() { | 1123 void RenderFrameHostImpl::Stop() { |
1111 Send(new FrameMsg_Stop(routing_id_)); | 1124 Send(new FrameMsg_Stop(routing_id_)); |
1112 } | 1125 } |
1113 | 1126 |
1114 void RenderFrameHostImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1127 void RenderFrameHostImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
| 1128 TRACE_EVENT_ASYNC_BEGIN0( |
| 1129 "navigation", "RenderFrameHostImpl::BeforeUnload", this); |
1115 // TODO(creis): Support subframes. | 1130 // TODO(creis): Support subframes. |
1116 if (!render_view_host_->IsRenderViewLive() || GetParent()) { | 1131 if (!render_view_host_->IsRenderViewLive() || GetParent()) { |
1117 // We don't have a live renderer, so just skip running beforeunload. | 1132 // We don't have a live renderer, so just skip running beforeunload. |
1118 render_view_host_->is_waiting_for_beforeunload_ack_ = true; | 1133 render_view_host_->is_waiting_for_beforeunload_ack_ = true; |
1119 render_view_host_->unload_ack_is_for_cross_site_transition_ = | 1134 render_view_host_->unload_ack_is_for_cross_site_transition_ = |
1120 for_cross_site_transition; | 1135 for_cross_site_transition; |
1121 base::TimeTicks now = base::TimeTicks::Now(); | 1136 base::TimeTicks now = base::TimeTicks::Now(); |
1122 OnBeforeUnloadACK(true, now, now); | 1137 OnBeforeUnloadACK(true, now, now); |
1123 return; | 1138 return; |
1124 } | 1139 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 routing_id_)); | 1297 routing_id_)); |
1283 } | 1298 } |
1284 | 1299 |
1285 void RenderFrameHostImpl::SetNavigationsSuspended( | 1300 void RenderFrameHostImpl::SetNavigationsSuspended( |
1286 bool suspend, | 1301 bool suspend, |
1287 const base::TimeTicks& proceed_time) { | 1302 const base::TimeTicks& proceed_time) { |
1288 // This should only be called to toggle the state. | 1303 // This should only be called to toggle the state. |
1289 DCHECK(navigations_suspended_ != suspend); | 1304 DCHECK(navigations_suspended_ != suspend); |
1290 | 1305 |
1291 navigations_suspended_ = suspend; | 1306 navigations_suspended_ = suspend; |
| 1307 if (navigations_suspended_) { |
| 1308 TRACE_EVENT_ASYNC_BEGIN0("navigation", |
| 1309 "RenderFrameHostImpl navigation suspended", this); |
| 1310 } else { |
| 1311 TRACE_EVENT_ASYNC_END0("navigation", |
| 1312 "RenderFrameHostImpl navigation suspended", this); |
| 1313 } |
| 1314 |
1292 if (!suspend && suspended_nav_params_) { | 1315 if (!suspend && suspended_nav_params_) { |
1293 // There's navigation message params waiting to be sent. Now that we're not | 1316 // There's navigation message params waiting to be sent. Now that we're not |
1294 // suspended anymore, resume navigation by sending them. If we were swapped | 1317 // suspended anymore, resume navigation by sending them. If we were swapped |
1295 // out, we should also stop filtering out the IPC messages now. | 1318 // out, we should also stop filtering out the IPC messages now. |
1296 render_view_host_->SetState(RenderViewHostImpl::STATE_DEFAULT); | 1319 render_view_host_->SetState(RenderViewHostImpl::STATE_DEFAULT); |
1297 | 1320 |
1298 DCHECK(!proceed_time.is_null()); | 1321 DCHECK(!proceed_time.is_null()); |
1299 suspended_nav_params_->browser_navigation_start = proceed_time; | 1322 suspended_nav_params_->browser_navigation_start = proceed_time; |
1300 Send(new FrameMsg_Navigate(routing_id_, *suspended_nav_params_)); | 1323 Send(new FrameMsg_Navigate(routing_id_, *suspended_nav_params_)); |
1301 suspended_nav_params_.reset(); | 1324 suspended_nav_params_.reset(); |
1302 } | 1325 } |
1303 } | 1326 } |
1304 | 1327 |
1305 void RenderFrameHostImpl::CancelSuspendedNavigations() { | 1328 void RenderFrameHostImpl::CancelSuspendedNavigations() { |
1306 // Clear any state if a pending navigation is canceled or preempted. | 1329 // Clear any state if a pending navigation is canceled or preempted. |
1307 if (suspended_nav_params_) | 1330 if (suspended_nav_params_) |
1308 suspended_nav_params_.reset(); | 1331 suspended_nav_params_.reset(); |
| 1332 |
| 1333 TRACE_EVENT_ASYNC_END0("navigation", |
| 1334 "RenderFrameHostImpl navigation suspended", this); |
1309 navigations_suspended_ = false; | 1335 navigations_suspended_ = false; |
1310 } | 1336 } |
1311 | 1337 |
1312 } // namespace content | 1338 } // namespace content |
OLD | NEW |