| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 (receive_before_unload_ack_time - send_before_unload_start_time_) - | 1559 (receive_before_unload_ack_time - send_before_unload_start_time_) - |
| 1560 (renderer_before_unload_end_time - renderer_before_unload_start_time); | 1560 (renderer_before_unload_end_time - renderer_before_unload_start_time); |
| 1561 UMA_HISTOGRAM_TIMES("Navigation.OnBeforeUnloadOverheadTime", | 1561 UMA_HISTOGRAM_TIMES("Navigation.OnBeforeUnloadOverheadTime", |
| 1562 on_before_unload_overhead_time); | 1562 on_before_unload_overhead_time); |
| 1563 | 1563 |
| 1564 frame_tree_node_->navigator()->LogBeforeUnloadTime( | 1564 frame_tree_node_->navigator()->LogBeforeUnloadTime( |
| 1565 renderer_before_unload_start_time, renderer_before_unload_end_time); | 1565 renderer_before_unload_start_time, renderer_before_unload_end_time); |
| 1566 } | 1566 } |
| 1567 // Resets beforeunload waiting state. | 1567 // Resets beforeunload waiting state. |
| 1568 is_waiting_for_beforeunload_ack_ = false; | 1568 is_waiting_for_beforeunload_ack_ = false; |
| 1569 beforeunload_timeout_->Stop(); | 1569 if (beforeunload_timeout_) |
| 1570 beforeunload_timeout_->Stop(); |
| 1570 send_before_unload_start_time_ = base::TimeTicks(); | 1571 send_before_unload_start_time_ = base::TimeTicks(); |
| 1571 | 1572 |
| 1572 // PlzNavigate: if the ACK is for a navigation, send it to the Navigator to | 1573 // PlzNavigate: if the ACK is for a navigation, send it to the Navigator to |
| 1573 // have the current navigation stop/proceed. Otherwise, send it to the | 1574 // have the current navigation stop/proceed. Otherwise, send it to the |
| 1574 // RenderFrameHostManager which handles closing. | 1575 // RenderFrameHostManager which handles closing. |
| 1575 if (IsBrowserSideNavigationEnabled() && unload_ack_is_for_navigation_) { | 1576 if (IsBrowserSideNavigationEnabled() && unload_ack_is_for_navigation_) { |
| 1576 // TODO(clamy): see if before_unload_end_time should be transmitted to the | 1577 // TODO(clamy): see if before_unload_end_time should be transmitted to the |
| 1577 // Navigator. | 1578 // Navigator. |
| 1578 frame_tree_node_->navigator()->OnBeforeUnloadACK( | 1579 frame_tree_node_->navigator()->OnBeforeUnloadACK( |
| 1579 frame_tree_node_, proceed); | 1580 frame_tree_node_, proceed); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 const GURL& frame_url, | 1784 const GURL& frame_url, |
| 1784 bool is_reload, | 1785 bool is_reload, |
| 1785 IPC::Message* reply_msg) { | 1786 IPC::Message* reply_msg) { |
| 1786 // While a JS beforeunload dialog is showing, tabs in the same process | 1787 // While a JS beforeunload dialog is showing, tabs in the same process |
| 1787 // shouldn't process input events. | 1788 // shouldn't process input events. |
| 1788 GetProcess()->SetIgnoreInputEvents(true); | 1789 GetProcess()->SetIgnoreInputEvents(true); |
| 1789 | 1790 |
| 1790 // The beforeunload dialog for this frame may have been triggered by a | 1791 // The beforeunload dialog for this frame may have been triggered by a |
| 1791 // browser-side request to this frame or a frame up in the frame hierarchy. | 1792 // browser-side request to this frame or a frame up in the frame hierarchy. |
| 1792 // Stop any timers that are waiting. | 1793 // Stop any timers that are waiting. |
| 1793 for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) | 1794 for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) { |
| 1794 frame->beforeunload_timeout_->Stop(); | 1795 if (frame->beforeunload_timeout_) |
| 1796 frame->beforeunload_timeout_->Stop(); |
| 1797 } |
| 1795 | 1798 |
| 1796 delegate_->RunBeforeUnloadConfirm(this, is_reload, reply_msg); | 1799 delegate_->RunBeforeUnloadConfirm(this, is_reload, reply_msg); |
| 1797 } | 1800 } |
| 1798 | 1801 |
| 1799 void RenderFrameHostImpl::OnRunFileChooser(const FileChooserParams& params) { | 1802 void RenderFrameHostImpl::OnRunFileChooser(const FileChooserParams& params) { |
| 1800 // Do not allow messages with absolute paths in them as this can permit a | 1803 // Do not allow messages with absolute paths in them as this can permit a |
| 1801 // renderer to coerce the browser to perform I/O on a renderer controlled | 1804 // renderer to coerce the browser to perform I/O on a renderer controlled |
| 1802 // path. | 1805 // path. |
| 1803 if (params.default_file_name != params.default_file_name.BaseName()) { | 1806 if (params.default_file_name != params.default_file_name.BaseName()) { |
| 1804 bad_message::ReceivedBadMessage(GetProcess(), | 1807 bad_message::ReceivedBadMessage(GetProcess(), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1889 base::Bind(&ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute)); | 1892 base::Bind(&ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute)); |
| 1890 } | 1893 } |
| 1891 | 1894 |
| 1892 void RenderFrameHostImpl::CancelBlockedRequestsForFrame() { | 1895 void RenderFrameHostImpl::CancelBlockedRequestsForFrame() { |
| 1893 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1896 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1894 NotifyForEachFrameFromUI( | 1897 NotifyForEachFrameFromUI( |
| 1895 this, | 1898 this, |
| 1896 base::Bind(&ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute)); | 1899 base::Bind(&ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute)); |
| 1897 } | 1900 } |
| 1898 | 1901 |
| 1902 void RenderFrameHostImpl::DisableBeforeUnloadHangMonitorForTesting() { |
| 1903 beforeunload_timeout_.reset(); |
| 1904 } |
| 1905 |
| 1899 void RenderFrameHostImpl::OnDidAccessInitialDocument() { | 1906 void RenderFrameHostImpl::OnDidAccessInitialDocument() { |
| 1900 delegate_->DidAccessInitialDocument(); | 1907 delegate_->DidAccessInitialDocument(); |
| 1901 } | 1908 } |
| 1902 | 1909 |
| 1903 void RenderFrameHostImpl::OnDidChangeOpener(int32_t opener_routing_id) { | 1910 void RenderFrameHostImpl::OnDidChangeOpener(int32_t opener_routing_id) { |
| 1904 frame_tree_node_->render_manager()->DidChangeOpener(opener_routing_id, | 1911 frame_tree_node_->render_manager()->DidChangeOpener(opener_routing_id, |
| 1905 GetSiteInstance()); | 1912 GetSiteInstance()); |
| 1906 } | 1913 } |
| 1907 | 1914 |
| 1908 void RenderFrameHostImpl::OnDidChangeName(const std::string& name, | 1915 void RenderFrameHostImpl::OnDidChangeName(const std::string& name, |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 } | 2537 } |
| 2531 | 2538 |
| 2532 void RenderFrameHostImpl::ResetWaitingState() { | 2539 void RenderFrameHostImpl::ResetWaitingState() { |
| 2533 DCHECK(is_active()); | 2540 DCHECK(is_active()); |
| 2534 | 2541 |
| 2535 // Whenever we reset the RFH state, we should not be waiting for beforeunload | 2542 // Whenever we reset the RFH state, we should not be waiting for beforeunload |
| 2536 // or close acks. We clear them here to be safe, since they can cause | 2543 // or close acks. We clear them here to be safe, since they can cause |
| 2537 // navigations to be ignored in OnDidCommitProvisionalLoad. | 2544 // navigations to be ignored in OnDidCommitProvisionalLoad. |
| 2538 if (is_waiting_for_beforeunload_ack_) { | 2545 if (is_waiting_for_beforeunload_ack_) { |
| 2539 is_waiting_for_beforeunload_ack_ = false; | 2546 is_waiting_for_beforeunload_ack_ = false; |
| 2540 beforeunload_timeout_->Stop(); | 2547 if (beforeunload_timeout_) |
| 2548 beforeunload_timeout_->Stop(); |
| 2541 } | 2549 } |
| 2542 send_before_unload_start_time_ = base::TimeTicks(); | 2550 send_before_unload_start_time_ = base::TimeTicks(); |
| 2543 render_view_host_->is_waiting_for_close_ack_ = false; | 2551 render_view_host_->is_waiting_for_close_ack_ = false; |
| 2544 } | 2552 } |
| 2545 | 2553 |
| 2546 bool RenderFrameHostImpl::CanCommitOrigin( | 2554 bool RenderFrameHostImpl::CanCommitOrigin( |
| 2547 const url::Origin& origin, | 2555 const url::Origin& origin, |
| 2548 const GURL& url) { | 2556 const GURL& url) { |
| 2549 // If the --disable-web-security flag is specified, all bets are off and the | 2557 // If the --disable-web-security flag is specified, all bets are off and the |
| 2550 // renderer process can send any origin it wishes. | 2558 // renderer process can send any origin it wishes. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 // Start the hang monitor in case the renderer hangs in the beforeunload | 2685 // Start the hang monitor in case the renderer hangs in the beforeunload |
| 2678 // handler. | 2686 // handler. |
| 2679 is_waiting_for_beforeunload_ack_ = true; | 2687 is_waiting_for_beforeunload_ack_ = true; |
| 2680 unload_ack_is_for_navigation_ = for_navigation; | 2688 unload_ack_is_for_navigation_ = for_navigation; |
| 2681 if (render_view_host_->GetDelegate()->IsJavaScriptDialogShowing()) { | 2689 if (render_view_host_->GetDelegate()->IsJavaScriptDialogShowing()) { |
| 2682 // If there is a JavaScript dialog up, don't bother sending the renderer | 2690 // If there is a JavaScript dialog up, don't bother sending the renderer |
| 2683 // the unload event because it is known unresponsive, waiting for the | 2691 // the unload event because it is known unresponsive, waiting for the |
| 2684 // reply from the dialog. | 2692 // reply from the dialog. |
| 2685 SimulateBeforeUnloadAck(); | 2693 SimulateBeforeUnloadAck(); |
| 2686 } else { | 2694 } else { |
| 2687 beforeunload_timeout_->Start( | 2695 if (beforeunload_timeout_) { |
| 2688 TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 2696 beforeunload_timeout_->Start( |
| 2697 TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
| 2698 } |
| 2689 send_before_unload_start_time_ = base::TimeTicks::Now(); | 2699 send_before_unload_start_time_ = base::TimeTicks::Now(); |
| 2690 Send(new FrameMsg_BeforeUnload(routing_id_, is_reload)); | 2700 Send(new FrameMsg_BeforeUnload(routing_id_, is_reload)); |
| 2691 } | 2701 } |
| 2692 } | 2702 } |
| 2693 } | 2703 } |
| 2694 | 2704 |
| 2695 void RenderFrameHostImpl::SimulateBeforeUnloadAck() { | 2705 void RenderFrameHostImpl::SimulateBeforeUnloadAck() { |
| 2696 DCHECK(is_waiting_for_beforeunload_ack_); | 2706 DCHECK(is_waiting_for_beforeunload_ack_); |
| 2697 base::TimeTicks approx_renderer_start_time = send_before_unload_start_time_; | 2707 base::TimeTicks approx_renderer_start_time = send_before_unload_start_time_; |
| 2698 OnBeforeUnloadACK(true, approx_renderer_start_time, base::TimeTicks::Now()); | 2708 OnBeforeUnloadACK(true, approx_renderer_start_time, base::TimeTicks::Now()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 // timers stopped in this frame or a frame up in the frame hierarchy. Restart | 2769 // timers stopped in this frame or a frame up in the frame hierarchy. Restart |
| 2760 // any timers that were stopped in OnRunBeforeUnloadConfirm(). | 2770 // any timers that were stopped in OnRunBeforeUnloadConfirm(). |
| 2761 for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) { | 2771 for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) { |
| 2762 if (frame->is_waiting_for_beforeunload_ack_) { | 2772 if (frame->is_waiting_for_beforeunload_ack_) { |
| 2763 // If we are waiting for a beforeunload ack and the user has suppressed | 2773 // If we are waiting for a beforeunload ack and the user has suppressed |
| 2764 // messages, kill the tab immediately. A page that's spamming is | 2774 // messages, kill the tab immediately. A page that's spamming is |
| 2765 // presumably malicious, so there's no point in continuing to run its | 2775 // presumably malicious, so there's no point in continuing to run its |
| 2766 // script and dragging out the process. | 2776 // script and dragging out the process. |
| 2767 if (dialog_was_suppressed) { | 2777 if (dialog_was_suppressed) { |
| 2768 frame->SimulateBeforeUnloadAck(); | 2778 frame->SimulateBeforeUnloadAck(); |
| 2769 } else { | 2779 } else if (frame->beforeunload_timeout_) { |
| 2770 frame->beforeunload_timeout_->Start( | 2780 frame->beforeunload_timeout_->Start( |
| 2771 TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 2781 TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
| 2772 } | 2782 } |
| 2773 } | 2783 } |
| 2774 } | 2784 } |
| 2775 } | 2785 } |
| 2776 | 2786 |
| 2777 void RenderFrameHostImpl::SendJavaScriptDialogReply( | 2787 void RenderFrameHostImpl::SendJavaScriptDialogReply( |
| 2778 IPC::Message* reply_msg, | 2788 IPC::Message* reply_msg, |
| 2779 bool success, | 2789 bool success, |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3628 service_manager::mojom::InterfaceProviderPtr provider; | 3638 service_manager::mojom::InterfaceProviderPtr provider; |
| 3629 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this); | 3639 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this); |
| 3630 java_interfaces_.reset(new service_manager::InterfaceProvider); | 3640 java_interfaces_.reset(new service_manager::InterfaceProvider); |
| 3631 java_interfaces_->Bind(std::move(provider)); | 3641 java_interfaces_->Bind(std::move(provider)); |
| 3632 } | 3642 } |
| 3633 return java_interfaces_.get(); | 3643 return java_interfaces_.get(); |
| 3634 } | 3644 } |
| 3635 #endif | 3645 #endif |
| 3636 | 3646 |
| 3637 } // namespace content | 3647 } // namespace content |
| OLD | NEW |