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/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, | 319 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, |
320 OnNavigate(msg)) | 320 OnNavigate(msg)) |
321 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading) | 321 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading) |
322 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading) | 322 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading) |
323 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) | 323 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) |
324 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) | 324 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) |
325 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) | 325 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) |
326 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) | 326 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) |
327 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, | 327 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, |
328 OnJavaScriptExecuteResponse) | 328 OnJavaScriptExecuteResponse) |
| 329 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunJavaScriptMessage, |
| 330 OnRunJavaScriptMessage) |
| 331 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, |
| 332 OnRunBeforeUnloadConfirm) |
329 IPC_END_MESSAGE_MAP_EX() | 333 IPC_END_MESSAGE_MAP_EX() |
330 | 334 |
331 if (!msg_is_ok) { | 335 if (!msg_is_ok) { |
332 // The message had a handler, but its de-serialization failed. | 336 // The message had a handler, but its de-serialization failed. |
333 // Kill the renderer. | 337 // Kill the renderer. |
334 RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); | 338 RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); |
335 GetProcess()->ReceivedBadMessage(); | 339 GetProcess()->ReceivedBadMessage(); |
336 } | 340 } |
337 | 341 |
338 return handled; | 342 return handled; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 std::map<int, JavaScriptResultCallback>::iterator it = | 644 std::map<int, JavaScriptResultCallback>::iterator it = |
641 javascript_callbacks_.find(id); | 645 javascript_callbacks_.find(id); |
642 if (it != javascript_callbacks_.end()) { | 646 if (it != javascript_callbacks_.end()) { |
643 it->second.Run(result_value); | 647 it->second.Run(result_value); |
644 javascript_callbacks_.erase(it); | 648 javascript_callbacks_.erase(it); |
645 } else { | 649 } else { |
646 NOTREACHED() << "Received script response for unknown request"; | 650 NOTREACHED() << "Received script response for unknown request"; |
647 } | 651 } |
648 } | 652 } |
649 | 653 |
| 654 void RenderFrameHostImpl::OnRunJavaScriptMessage( |
| 655 const base::string16& message, |
| 656 const base::string16& default_prompt, |
| 657 const GURL& frame_url, |
| 658 JavaScriptMessageType type, |
| 659 IPC::Message* reply_msg) { |
| 660 // While a JS message dialog is showing, tabs in the same process shouldn't |
| 661 // process input events. |
| 662 GetProcess()->SetIgnoreInputEvents(true); |
| 663 render_view_host_->StopHangMonitorTimeout(); |
| 664 delegate_->RunJavaScriptMessage(this, message, default_prompt, |
| 665 frame_url, type, reply_msg); |
| 666 } |
| 667 |
| 668 void RenderFrameHostImpl::OnRunBeforeUnloadConfirm( |
| 669 const GURL& frame_url, |
| 670 const base::string16& message, |
| 671 bool is_reload, |
| 672 IPC::Message* reply_msg) { |
| 673 // While a JS before unload dialog is showing, tabs in the same process |
| 674 // shouldn't process input events. |
| 675 GetProcess()->SetIgnoreInputEvents(true); |
| 676 render_view_host_->StopHangMonitorTimeout(); |
| 677 delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg); |
| 678 } |
| 679 |
650 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { | 680 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { |
651 render_view_host_->SetPendingShutdown(on_swap_out); | 681 render_view_host_->SetPendingShutdown(on_swap_out); |
652 } | 682 } |
653 | 683 |
654 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { | 684 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { |
655 // TODO(creis): We should also check for WebUI pages here. Also, when the | 685 // TODO(creis): We should also check for WebUI pages here. Also, when the |
656 // out-of-process iframes implementation is ready, we should check for | 686 // out-of-process iframes implementation is ready, we should check for |
657 // cross-site URLs that are not allowed to commit in this process. | 687 // cross-site URLs that are not allowed to commit in this process. |
658 | 688 |
659 // Give the client a chance to disallow URLs from committing. | 689 // Give the client a chance to disallow URLs from committing. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 void RenderFrameHostImpl::SelectRange(const gfx::Point& start, | 754 void RenderFrameHostImpl::SelectRange(const gfx::Point& start, |
725 const gfx::Point& end) { | 755 const gfx::Point& end) { |
726 Send(new InputMsg_SelectRange(routing_id_, start, end)); | 756 Send(new InputMsg_SelectRange(routing_id_, start, end)); |
727 } | 757 } |
728 | 758 |
729 void RenderFrameHostImpl::ExtendSelectionAndDelete(size_t before, | 759 void RenderFrameHostImpl::ExtendSelectionAndDelete(size_t before, |
730 size_t after) { | 760 size_t after) { |
731 Send(new FrameMsg_ExtendSelectionAndDelete(routing_id_, before, after)); | 761 Send(new FrameMsg_ExtendSelectionAndDelete(routing_id_, before, after)); |
732 } | 762 } |
733 | 763 |
| 764 void RenderFrameHostImpl::JavaScriptDialogClosed( |
| 765 IPC::Message* reply_msg, |
| 766 bool success, |
| 767 const base::string16& user_input, |
| 768 bool dialog_was_suppressed) { |
| 769 GetProcess()->SetIgnoreInputEvents(false); |
| 770 bool is_waiting = render_view_host_->is_waiting_for_beforeunload_ack() || |
| 771 render_view_host_->IsWaitingForUnloadACK(); |
| 772 |
| 773 // If we are executing as part of (before)unload event handling, we don't |
| 774 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to |
| 775 // leave the current page. In this case, use the regular timeout value used |
| 776 // during the (before)unload handling. |
| 777 if (is_waiting) { |
| 778 render_view_host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds( |
| 779 success ? RenderViewHostImpl::kUnloadTimeoutMS |
| 780 : render_view_host_->hung_renderer_delay_ms_)); |
| 781 } |
| 782 |
| 783 FrameHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, |
| 784 success, user_input); |
| 785 Send(reply_msg); |
| 786 |
| 787 // If we are waiting for an unload or beforeunload ack and the user has |
| 788 // suppressed messages, kill the tab immediately; a page that's spamming |
| 789 // alerts in onbeforeunload is presumably malicious, so there's no point in |
| 790 // continuing to run its script and dragging out the process. |
| 791 // This must be done after sending the reply since RenderView can't close |
| 792 // correctly while waiting for a response. |
| 793 if (is_waiting && dialog_was_suppressed) |
| 794 render_view_host_->delegate_->RendererUnresponsive( |
| 795 render_view_host_, |
| 796 render_view_host_->is_waiting_for_beforeunload_ack(), |
| 797 render_view_host_->IsWaitingForUnloadACK()); |
| 798 } |
| 799 |
734 } // namespace content | 800 } // namespace content |
OLD | NEW |