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/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 while ((observer = it.GetNext()) != NULL) { | 733 while ((observer = it.GetNext()) != NULL) { |
734 if (observer->OnMessageReceived(msg)) | 734 if (observer->OnMessageReceived(msg)) |
735 return true; | 735 return true; |
736 } | 736 } |
737 | 737 |
738 bool handled = true; | 738 bool handled = true; |
739 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) | 739 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) |
740 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) | 740 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) |
741 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) | 741 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) |
742 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) | 742 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) |
| 743 IPC_MESSAGE_HANDLER(FrameMsg_Stop, OnStop) |
743 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) | 744 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) |
744 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, | 745 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, |
745 OnCustomContextMenuAction) | 746 OnCustomContextMenuAction) |
746 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) | 747 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
747 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) | 748 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
748 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) | 749 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
749 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) | 750 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
750 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) | 751 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
751 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) | 752 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
752 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) | 753 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); | 989 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
989 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, | 990 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, |
990 before_unload_start_time, | 991 before_unload_start_time, |
991 before_unload_end_time)); | 992 before_unload_end_time)); |
992 } | 993 } |
993 | 994 |
994 void RenderFrameImpl::OnSwapOut(int proxy_routing_id) { | 995 void RenderFrameImpl::OnSwapOut(int proxy_routing_id) { |
995 RenderFrameProxy* proxy = NULL; | 996 RenderFrameProxy* proxy = NULL; |
996 bool is_site_per_process = | 997 bool is_site_per_process = |
997 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); | 998 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); |
| 999 bool is_main_frame = !frame_->parent(); |
998 | 1000 |
999 // Only run unload if we're not swapped out yet, but send the ack either way. | 1001 // Only run unload if we're not swapped out yet, but send the ack either way. |
1000 if (!is_swapped_out_ || !render_view_->is_swapped_out_) { | 1002 if (!is_swapped_out_ || !render_view_->is_swapped_out_) { |
1001 // Swap this RenderFrame out so the frame can navigate to a page rendered by | 1003 // Swap this RenderFrame out so the frame can navigate to a page rendered by |
1002 // a different process. This involves running the unload handler and | 1004 // a different process. This involves running the unload handler and |
1003 // clearing the page. We also allow this process to exit if there are no | 1005 // clearing the page. We also allow this process to exit if there are no |
1004 // other active RenderFrames in it. | 1006 // other active RenderFrames in it. |
1005 | 1007 |
1006 // Send an UpdateState message before we get swapped out. Create the | 1008 // Send an UpdateState message before we get swapped out. Create the |
1007 // RenderFrameProxy as well so its routing id is registered for receiving | 1009 // RenderFrameProxy as well so its routing id is registered for receiving |
1008 // IPC messages. | 1010 // IPC messages. |
1009 render_view_->SyncNavigationState(); | 1011 render_view_->SyncNavigationState(); |
1010 proxy = RenderFrameProxy::CreateProxyToReplaceFrame(this, | 1012 proxy = RenderFrameProxy::CreateProxyToReplaceFrame(this, |
1011 proxy_routing_id); | 1013 proxy_routing_id); |
1012 | 1014 |
1013 // Synchronously run the unload handler before sending the ACK. | 1015 // Synchronously run the unload handler before sending the ACK. |
1014 // TODO(creis): Call dispatchUnloadEvent unconditionally here to support | 1016 // TODO(creis): Call dispatchUnloadEvent unconditionally here to support |
1015 // unload on subframes as well. | 1017 // unload on subframes as well. |
1016 if (!frame_->parent()) | 1018 if (is_main_frame) |
1017 frame_->dispatchUnloadEvent(); | 1019 frame_->dispatchUnloadEvent(); |
1018 | 1020 |
1019 // Swap out and stop sending any IPC messages that are not ACKs. | 1021 // Swap out and stop sending any IPC messages that are not ACKs. |
1020 // TODO(nasko): Do we need RenderFrameImpl::is_swapped_out_ anymore? | 1022 // TODO(nasko): Do we need RenderFrameImpl::is_swapped_out_ anymore? |
1021 if (!frame_->parent()) | 1023 if (is_main_frame) |
1022 render_view_->SetSwappedOut(true); | 1024 render_view_->SetSwappedOut(true); |
1023 is_swapped_out_ = true; | 1025 is_swapped_out_ = true; |
1024 | 1026 |
1025 // Now that we're swapped out and filtering IPC messages, stop loading to | 1027 // Now that we're swapped out and filtering IPC messages, stop loading to |
1026 // ensure that no other in-progress navigation continues. We do this here | 1028 // ensure that no other in-progress navigation continues. We do this here |
1027 // to avoid sending a DidStopLoading message to the browser process. | 1029 // to avoid sending a DidStopLoading message to the browser process. |
1028 // TODO(creis): Should we be stopping all frames here and using | 1030 // TODO(creis): Should we be stopping all frames here and using |
1029 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this | 1031 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this |
1030 // frame? | 1032 // frame? |
1031 if (!frame_->parent()) | 1033 OnStop(); |
1032 render_view_->OnStop(); | |
1033 else | |
1034 frame_->stopLoading(); | |
1035 | 1034 |
1036 // Let subframes know that the frame is now rendered remotely, for the | 1035 // Let subframes know that the frame is now rendered remotely, for the |
1037 // purposes of compositing and input events. | 1036 // purposes of compositing and input events. |
1038 if (frame_->parent()) | 1037 if (!is_main_frame) |
1039 frame_->setIsRemote(true); | 1038 frame_->setIsRemote(true); |
1040 | 1039 |
1041 // Replace the page with a blank dummy URL. The unload handler will not be | 1040 // Replace the page with a blank dummy URL. The unload handler will not be |
1042 // run a second time, thanks to a check in FrameLoader::stopLoading. | 1041 // run a second time, thanks to a check in FrameLoader::stopLoading. |
1043 // TODO(creis): Need to add a better way to do this that avoids running the | 1042 // TODO(creis): Need to add a better way to do this that avoids running the |
1044 // beforeunload handler. For now, we just run it a second time silently. | 1043 // beforeunload handler. For now, we just run it a second time silently. |
1045 if (!is_site_per_process || frame_->parent() == NULL) | 1044 if (!is_site_per_process || is_main_frame) |
1046 render_view_->NavigateToSwappedOutURL(frame_); | 1045 render_view_->NavigateToSwappedOutURL(frame_); |
1047 | 1046 |
1048 // Let WebKit know that this view is hidden so it can drop resources and | 1047 // Let WebKit know that this view is hidden so it can drop resources and |
1049 // stop compositing. | 1048 // stop compositing. |
1050 // TODO(creis): Support this for subframes as well. | 1049 // TODO(creis): Support this for subframes as well. |
1051 if (!frame_->parent()) { | 1050 if (is_main_frame) { |
1052 render_view_->webview()->setVisibilityState( | 1051 render_view_->webview()->setVisibilityState( |
1053 blink::WebPageVisibilityStateHidden, false); | 1052 blink::WebPageVisibilityStateHidden, false); |
1054 } | 1053 } |
1055 } | 1054 } |
1056 | 1055 |
1057 // It is now safe to show modal dialogs again. | 1056 // It is now safe to show modal dialogs again. |
1058 // TODO(creis): Deal with modal dialogs from subframes. | 1057 // TODO(creis): Deal with modal dialogs from subframes. |
1059 if (!frame_->parent()) | 1058 if (is_main_frame) |
1060 render_view_->suppress_dialogs_until_swap_out_ = false; | 1059 render_view_->suppress_dialogs_until_swap_out_ = false; |
1061 | 1060 |
1062 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); | 1061 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); |
1063 | 1062 |
1064 // Now that all of the cleanup is complete and the browser side is notified, | 1063 // Now that all of the cleanup is complete and the browser side is notified, |
1065 // start using the RenderFrameProxy, if one is created. | 1064 // start using the RenderFrameProxy, if one is created. |
1066 if (proxy) { | 1065 if (proxy) { |
1067 if (frame_->parent()) { | 1066 if (!is_main_frame) { |
1068 frame_->swap(proxy->web_frame()); | 1067 frame_->swap(proxy->web_frame()); |
1069 if (is_site_per_process) { | 1068 if (is_site_per_process) { |
1070 // TODO(nasko): delete the frame here, since we've replaced it with a | 1069 // TODO(nasko): delete the frame here, since we've replaced it with a |
1071 // proxy. | 1070 // proxy. |
1072 } | 1071 } |
1073 } else { | 1072 } else { |
1074 set_render_frame_proxy(proxy); | 1073 set_render_frame_proxy(proxy); |
1075 } | 1074 } |
1076 } | 1075 } |
1077 | 1076 |
1078 // Safe to exit if no one else is using the process. | 1077 // Safe to exit if no one else is using the process. |
1079 if (!frame_->parent()) | 1078 if (is_main_frame) |
1080 render_view_->WasSwappedOut(); | 1079 render_view_->WasSwappedOut(); |
1081 } | 1080 } |
1082 | 1081 |
1083 void RenderFrameImpl::OnContextMenuClosed( | 1082 void RenderFrameImpl::OnContextMenuClosed( |
1084 const CustomContextMenuContext& custom_context) { | 1083 const CustomContextMenuContext& custom_context) { |
1085 if (custom_context.request_id) { | 1084 if (custom_context.request_id) { |
1086 // External request, should be in our map. | 1085 // External request, should be in our map. |
1087 ContextMenuClient* client = | 1086 ContextMenuClient* client = |
1088 pending_context_menus_.Lookup(custom_context.request_id); | 1087 pending_context_menus_.Lookup(custom_context.request_id); |
1089 if (client) { | 1088 if (client) { |
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3053 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { | 3052 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { |
3054 observers_.AddObserver(observer); | 3053 observers_.AddObserver(observer); |
3055 } | 3054 } |
3056 | 3055 |
3057 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { | 3056 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { |
3058 observer->RenderFrameGone(); | 3057 observer->RenderFrameGone(); |
3059 observers_.RemoveObserver(observer); | 3058 observers_.RemoveObserver(observer); |
3060 } | 3059 } |
3061 | 3060 |
3062 void RenderFrameImpl::OnStop() { | 3061 void RenderFrameImpl::OnStop() { |
| 3062 DCHECK(frame_); |
| 3063 frame_->stopLoading(); |
| 3064 if (!frame_->parent()) |
| 3065 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, OnStop()); |
| 3066 |
3063 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); | 3067 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); |
3064 } | 3068 } |
3065 | 3069 |
3066 void RenderFrameImpl::WasHidden() { | 3070 void RenderFrameImpl::WasHidden() { |
3067 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasHidden()); | 3071 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasHidden()); |
3068 } | 3072 } |
3069 | 3073 |
3070 void RenderFrameImpl::WasShown() { | 3074 void RenderFrameImpl::WasShown() { |
3071 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown()); | 3075 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown()); |
3072 } | 3076 } |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3723 | 3727 |
3724 #if defined(ENABLE_BROWSER_CDMS) | 3728 #if defined(ENABLE_BROWSER_CDMS) |
3725 RendererCdmManager* RenderFrameImpl::GetCdmManager() { | 3729 RendererCdmManager* RenderFrameImpl::GetCdmManager() { |
3726 if (!cdm_manager_) | 3730 if (!cdm_manager_) |
3727 cdm_manager_ = new RendererCdmManager(this); | 3731 cdm_manager_ = new RendererCdmManager(this); |
3728 return cdm_manager_; | 3732 return cdm_manager_; |
3729 } | 3733 } |
3730 #endif // defined(ENABLE_BROWSER_CDMS) | 3734 #endif // defined(ENABLE_BROWSER_CDMS) |
3731 | 3735 |
3732 } // namespace content | 3736 } // namespace content |
OLD | NEW |