| 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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 while ((observer = it.GetNext()) != NULL) { | 745 while ((observer = it.GetNext()) != NULL) { |
| 746 if (observer->OnMessageReceived(msg)) | 746 if (observer->OnMessageReceived(msg)) |
| 747 return true; | 747 return true; |
| 748 } | 748 } |
| 749 | 749 |
| 750 bool handled = true; | 750 bool handled = true; |
| 751 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) | 751 IPC_BEGIN_MESSAGE_MAP(RenderFrameImpl, msg) |
| 752 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) | 752 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate) |
| 753 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) | 753 IPC_MESSAGE_HANDLER(FrameMsg_BeforeUnload, OnBeforeUnload) |
| 754 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) | 754 IPC_MESSAGE_HANDLER(FrameMsg_SwapOut, OnSwapOut) |
| 755 IPC_MESSAGE_HANDLER(FrameMsg_Stop, OnStop) |
| 755 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) | 756 IPC_MESSAGE_HANDLER(FrameMsg_ContextMenuClosed, OnContextMenuClosed) |
| 756 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, | 757 IPC_MESSAGE_HANDLER(FrameMsg_CustomContextMenuAction, |
| 757 OnCustomContextMenuAction) | 758 OnCustomContextMenuAction) |
| 758 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) | 759 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
| 759 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) | 760 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
| 760 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) | 761 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
| 761 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) | 762 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
| 762 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) | 763 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
| 763 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) | 764 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| 764 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) | 765 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, | 1010 Send(new FrameHostMsg_BeforeUnload_ACK(routing_id_, proceed, |
| 1010 before_unload_start_time, | 1011 before_unload_start_time, |
| 1011 before_unload_end_time)); | 1012 before_unload_end_time)); |
| 1012 } | 1013 } |
| 1013 | 1014 |
| 1014 void RenderFrameImpl::OnSwapOut(int proxy_routing_id) { | 1015 void RenderFrameImpl::OnSwapOut(int proxy_routing_id) { |
| 1015 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); | 1016 TRACE_EVENT1("navigation", "RenderFrameImpl::OnSwapOut", "id", routing_id_); |
| 1016 RenderFrameProxy* proxy = NULL; | 1017 RenderFrameProxy* proxy = NULL; |
| 1017 bool is_site_per_process = | 1018 bool is_site_per_process = |
| 1018 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); | 1019 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess); |
| 1020 bool is_main_frame = !frame_->parent(); |
| 1019 | 1021 |
| 1020 // Only run unload if we're not swapped out yet, but send the ack either way. | 1022 // Only run unload if we're not swapped out yet, but send the ack either way. |
| 1021 if (!is_swapped_out_ || !render_view_->is_swapped_out_) { | 1023 if (!is_swapped_out_ || !render_view_->is_swapped_out_) { |
| 1022 // Swap this RenderFrame out so the frame can navigate to a page rendered by | 1024 // Swap this RenderFrame out so the frame can navigate to a page rendered by |
| 1023 // a different process. This involves running the unload handler and | 1025 // a different process. This involves running the unload handler and |
| 1024 // clearing the page. We also allow this process to exit if there are no | 1026 // clearing the page. We also allow this process to exit if there are no |
| 1025 // other active RenderFrames in it. | 1027 // other active RenderFrames in it. |
| 1026 | 1028 |
| 1027 // Send an UpdateState message before we get swapped out. Create the | 1029 // Send an UpdateState message before we get swapped out. Create the |
| 1028 // RenderFrameProxy as well so its routing id is registered for receiving | 1030 // RenderFrameProxy as well so its routing id is registered for receiving |
| 1029 // IPC messages. | 1031 // IPC messages. |
| 1030 render_view_->SyncNavigationState(); | 1032 render_view_->SyncNavigationState(); |
| 1031 proxy = RenderFrameProxy::CreateProxyToReplaceFrame(this, | 1033 proxy = RenderFrameProxy::CreateProxyToReplaceFrame(this, |
| 1032 proxy_routing_id); | 1034 proxy_routing_id); |
| 1033 | 1035 |
| 1034 // Synchronously run the unload handler before sending the ACK. | 1036 // Synchronously run the unload handler before sending the ACK. |
| 1035 // TODO(creis): Call dispatchUnloadEvent unconditionally here to support | 1037 // TODO(creis): Call dispatchUnloadEvent unconditionally here to support |
| 1036 // unload on subframes as well. | 1038 // unload on subframes as well. |
| 1037 if (!frame_->parent()) | 1039 if (is_main_frame) |
| 1038 frame_->dispatchUnloadEvent(); | 1040 frame_->dispatchUnloadEvent(); |
| 1039 | 1041 |
| 1040 // Swap out and stop sending any IPC messages that are not ACKs. | 1042 // Swap out and stop sending any IPC messages that are not ACKs. |
| 1041 // TODO(nasko): Do we need RenderFrameImpl::is_swapped_out_ anymore? | 1043 // TODO(nasko): Do we need RenderFrameImpl::is_swapped_out_ anymore? |
| 1042 if (!frame_->parent()) | 1044 if (is_main_frame) |
| 1043 render_view_->SetSwappedOut(true); | 1045 render_view_->SetSwappedOut(true); |
| 1044 is_swapped_out_ = true; | 1046 is_swapped_out_ = true; |
| 1045 | 1047 |
| 1046 // Now that we're swapped out and filtering IPC messages, stop loading to | 1048 // Now that we're swapped out and filtering IPC messages, stop loading to |
| 1047 // ensure that no other in-progress navigation continues. We do this here | 1049 // ensure that no other in-progress navigation continues. We do this here |
| 1048 // to avoid sending a DidStopLoading message to the browser process. | 1050 // to avoid sending a DidStopLoading message to the browser process. |
| 1049 // TODO(creis): Should we be stopping all frames here and using | 1051 // TODO(creis): Should we be stopping all frames here and using |
| 1050 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this | 1052 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this |
| 1051 // frame? | 1053 // frame? |
| 1052 if (!frame_->parent()) | 1054 OnStop(); |
| 1053 render_view_->OnStop(); | |
| 1054 else | |
| 1055 frame_->stopLoading(); | |
| 1056 | 1055 |
| 1057 // Let subframes know that the frame is now rendered remotely, for the | 1056 // Let subframes know that the frame is now rendered remotely, for the |
| 1058 // purposes of compositing and input events. | 1057 // purposes of compositing and input events. |
| 1059 if (frame_->parent()) | 1058 if (!is_main_frame) |
| 1060 frame_->setIsRemote(true); | 1059 frame_->setIsRemote(true); |
| 1061 | 1060 |
| 1062 // Replace the page with a blank dummy URL. The unload handler will not be | 1061 // Replace the page with a blank dummy URL. The unload handler will not be |
| 1063 // run a second time, thanks to a check in FrameLoader::stopLoading. | 1062 // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 1064 // TODO(creis): Need to add a better way to do this that avoids running the | 1063 // TODO(creis): Need to add a better way to do this that avoids running the |
| 1065 // beforeunload handler. For now, we just run it a second time silently. | 1064 // beforeunload handler. For now, we just run it a second time silently. |
| 1066 if (!is_site_per_process || frame_->parent() == NULL) | 1065 if (!is_site_per_process || is_main_frame) |
| 1067 render_view_->NavigateToSwappedOutURL(frame_); | 1066 render_view_->NavigateToSwappedOutURL(frame_); |
| 1068 | 1067 |
| 1069 // Let WebKit know that this view is hidden so it can drop resources and | 1068 // Let WebKit know that this view is hidden so it can drop resources and |
| 1070 // stop compositing. | 1069 // stop compositing. |
| 1071 // TODO(creis): Support this for subframes as well. | 1070 // TODO(creis): Support this for subframes as well. |
| 1072 if (!frame_->parent()) { | 1071 if (is_main_frame) { |
| 1073 render_view_->webview()->setVisibilityState( | 1072 render_view_->webview()->setVisibilityState( |
| 1074 blink::WebPageVisibilityStateHidden, false); | 1073 blink::WebPageVisibilityStateHidden, false); |
| 1075 } | 1074 } |
| 1076 } | 1075 } |
| 1077 | 1076 |
| 1078 // It is now safe to show modal dialogs again. | 1077 // It is now safe to show modal dialogs again. |
| 1079 // TODO(creis): Deal with modal dialogs from subframes. | 1078 // TODO(creis): Deal with modal dialogs from subframes. |
| 1080 if (!frame_->parent()) | 1079 if (is_main_frame) |
| 1081 render_view_->suppress_dialogs_until_swap_out_ = false; | 1080 render_view_->suppress_dialogs_until_swap_out_ = false; |
| 1082 | 1081 |
| 1083 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); | 1082 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); |
| 1084 | 1083 |
| 1085 // Now that all of the cleanup is complete and the browser side is notified, | 1084 // Now that all of the cleanup is complete and the browser side is notified, |
| 1086 // start using the RenderFrameProxy, if one is created. | 1085 // start using the RenderFrameProxy, if one is created. |
| 1087 if (proxy) { | 1086 if (proxy) { |
| 1088 if (frame_->parent()) { | 1087 if (!is_main_frame) { |
| 1089 frame_->swap(proxy->web_frame()); | 1088 frame_->swap(proxy->web_frame()); |
| 1090 if (is_site_per_process) { | 1089 if (is_site_per_process) { |
| 1091 // TODO(nasko): delete the frame here, since we've replaced it with a | 1090 // TODO(nasko): delete the frame here, since we've replaced it with a |
| 1092 // proxy. | 1091 // proxy. |
| 1093 } | 1092 } |
| 1094 } else { | 1093 } else { |
| 1095 set_render_frame_proxy(proxy); | 1094 set_render_frame_proxy(proxy); |
| 1096 } | 1095 } |
| 1097 } | 1096 } |
| 1098 | 1097 |
| 1099 // Safe to exit if no one else is using the process. | 1098 // Safe to exit if no one else is using the process. |
| 1100 if (!frame_->parent()) | 1099 if (is_main_frame) |
| 1101 render_view_->WasSwappedOut(); | 1100 render_view_->WasSwappedOut(); |
| 1102 } | 1101 } |
| 1103 | 1102 |
| 1104 void RenderFrameImpl::OnContextMenuClosed( | 1103 void RenderFrameImpl::OnContextMenuClosed( |
| 1105 const CustomContextMenuContext& custom_context) { | 1104 const CustomContextMenuContext& custom_context) { |
| 1106 if (custom_context.request_id) { | 1105 if (custom_context.request_id) { |
| 1107 // External request, should be in our map. | 1106 // External request, should be in our map. |
| 1108 ContextMenuClient* client = | 1107 ContextMenuClient* client = |
| 1109 pending_context_menus_.Lookup(custom_context.request_id); | 1108 pending_context_menus_.Lookup(custom_context.request_id); |
| 1110 if (client) { | 1109 if (client) { |
| (...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3166 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { | 3165 void RenderFrameImpl::AddObserver(RenderFrameObserver* observer) { |
| 3167 observers_.AddObserver(observer); | 3166 observers_.AddObserver(observer); |
| 3168 } | 3167 } |
| 3169 | 3168 |
| 3170 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { | 3169 void RenderFrameImpl::RemoveObserver(RenderFrameObserver* observer) { |
| 3171 observer->RenderFrameGone(); | 3170 observer->RenderFrameGone(); |
| 3172 observers_.RemoveObserver(observer); | 3171 observers_.RemoveObserver(observer); |
| 3173 } | 3172 } |
| 3174 | 3173 |
| 3175 void RenderFrameImpl::OnStop() { | 3174 void RenderFrameImpl::OnStop() { |
| 3175 DCHECK(frame_); |
| 3176 frame_->stopLoading(); |
| 3177 if (!frame_->parent()) |
| 3178 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, OnStop()); |
| 3179 |
| 3176 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); | 3180 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, OnStop()); |
| 3177 } | 3181 } |
| 3178 | 3182 |
| 3179 void RenderFrameImpl::WasHidden() { | 3183 void RenderFrameImpl::WasHidden() { |
| 3180 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasHidden()); | 3184 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasHidden()); |
| 3181 } | 3185 } |
| 3182 | 3186 |
| 3183 void RenderFrameImpl::WasShown() { | 3187 void RenderFrameImpl::WasShown() { |
| 3184 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown()); | 3188 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, WasShown()); |
| 3185 } | 3189 } |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3840 | 3844 |
| 3841 #if defined(ENABLE_BROWSER_CDMS) | 3845 #if defined(ENABLE_BROWSER_CDMS) |
| 3842 RendererCdmManager* RenderFrameImpl::GetCdmManager() { | 3846 RendererCdmManager* RenderFrameImpl::GetCdmManager() { |
| 3843 if (!cdm_manager_) | 3847 if (!cdm_manager_) |
| 3844 cdm_manager_ = new RendererCdmManager(this); | 3848 cdm_manager_ = new RendererCdmManager(this); |
| 3845 return cdm_manager_; | 3849 return cdm_manager_; |
| 3846 } | 3850 } |
| 3847 #endif // defined(ENABLE_BROWSER_CDMS) | 3851 #endif // defined(ENABLE_BROWSER_CDMS) |
| 3848 | 3852 |
| 3849 } // namespace content | 3853 } // namespace content |
| OLD | NEW |