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