Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1142123002: Remove swapped-out usage in --site-per-process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Readd back overriden version of CreateRenderView in TestRenderViewHost. Fixes CleanUpSwappedOutRVHO… Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 530
531 // static 531 // static
532 void RenderFrameImpl::CreateFrame( 532 void RenderFrameImpl::CreateFrame(
533 int routing_id, 533 int routing_id,
534 int parent_routing_id, 534 int parent_routing_id,
535 int previous_sibling_routing_id, 535 int previous_sibling_routing_id,
536 int proxy_routing_id, 536 int proxy_routing_id,
537 const FrameReplicationState& replicated_state, 537 const FrameReplicationState& replicated_state,
538 CompositorDependencies* compositor_deps, 538 CompositorDependencies* compositor_deps,
539 const FrameMsg_NewFrame_WidgetParams& widget_params) { 539 const FrameMsg_NewFrame_WidgetParams& widget_params) {
540 // TODO(nasko): For now, this message is only sent for subframes, as the
541 // top level frame is created when the RenderView is created through the
542 // ViewMsg_New IPC.
543 CHECK_NE(MSG_ROUTING_NONE, parent_routing_id);
544
545 blink::WebLocalFrame* web_frame; 540 blink::WebLocalFrame* web_frame;
546 RenderFrameImpl* render_frame; 541 RenderFrameImpl* render_frame;
547 if (proxy_routing_id == MSG_ROUTING_NONE) { 542 if (proxy_routing_id == MSG_ROUTING_NONE) {
548 RenderFrameProxy* parent_proxy = 543 RenderFrameProxy* parent_proxy =
549 RenderFrameProxy::FromRoutingID(parent_routing_id); 544 RenderFrameProxy::FromRoutingID(parent_routing_id);
550 // If the browser is sending a valid parent routing id, it should already 545 // If the browser is sending a valid parent routing id, it should already
551 // be created and registered. 546 // be created and registered.
552 CHECK(parent_proxy); 547 CHECK(parent_proxy);
553 blink::WebRemoteFrame* parent_web_frame = parent_proxy->web_frame(); 548 blink::WebRemoteFrame* parent_web_frame = parent_proxy->web_frame();
554 549
(...skipping 16 matching lines...) Expand all
571 CHECK(proxy); 566 CHECK(proxy);
572 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); 567 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id);
573 web_frame = 568 web_frame =
574 blink::WebLocalFrame::create(replicated_state.scope, render_frame); 569 blink::WebLocalFrame::create(replicated_state.scope, render_frame);
575 render_frame->proxy_routing_id_ = proxy_routing_id; 570 render_frame->proxy_routing_id_ = proxy_routing_id;
576 web_frame->initializeToReplaceRemoteFrame( 571 web_frame->initializeToReplaceRemoteFrame(
577 proxy->web_frame(), WebString::fromUTF8(replicated_state.name), 572 proxy->web_frame(), WebString::fromUTF8(replicated_state.name),
578 replicated_state.sandbox_flags); 573 replicated_state.sandbox_flags);
579 } 574 }
580 render_frame->SetWebFrame(web_frame); 575 render_frame->SetWebFrame(web_frame);
576 CHECK_IMPLIES(parent_routing_id == MSG_ROUTING_NONE, !web_frame->parent());
581 577
582 if (widget_params.routing_id != MSG_ROUTING_NONE) { 578 if (widget_params.routing_id != MSG_ROUTING_NONE) {
583 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 579 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
584 switches::kSitePerProcess)); 580 switches::kSitePerProcess));
585 render_frame->render_widget_ = RenderWidget::CreateForFrame( 581 render_frame->render_widget_ = RenderWidget::CreateForFrame(
586 widget_params.routing_id, widget_params.surface_id, 582 widget_params.routing_id, widget_params.surface_id,
587 widget_params.hidden, render_frame->render_view_->screen_info(), 583 widget_params.hidden, render_frame->render_view_->screen_info(),
588 compositor_deps, web_frame); 584 compositor_deps, web_frame);
589 // TODO(kenrb): Observing shouldn't be necessary when we sort out 585 // TODO(kenrb): Observing shouldn't be necessary when we sort out
590 // WasShown and WasHidden, separating page-level visibility from 586 // WasShown and WasHidden, separating page-level visibility from
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is 689 // RenderFrameProxy is "owned" by RenderFrameImpl in the case it is
694 // the main frame. Ensure it is deleted along with this object. 690 // the main frame. Ensure it is deleted along with this object.
695 if (render_frame_proxy_) { 691 if (render_frame_proxy_) {
696 // The following method calls back into this object and clears 692 // The following method calls back into this object and clears
697 // |render_frame_proxy_|. 693 // |render_frame_proxy_|.
698 render_frame_proxy_->frameDetached( 694 render_frame_proxy_->frameDetached(
699 blink::WebRemoteFrameClient::DetachType::Remove); 695 blink::WebRemoteFrameClient::DetachType::Remove);
700 } 696 }
701 697
702 // Ensure the RenderView doesn't point to this object, once it is destroyed. 698 // Ensure the RenderView doesn't point to this object, once it is destroyed.
703 CHECK_EQ(render_view_->main_render_frame_, this); 699 // TODO(nasko): Restore this check once we don't leak this object on
700 // frame swap.
701 //CHECK_EQ(render_view_->main_render_frame_, this);
Charlie Reis 2015/06/04 22:27:31 We don't keep commented out code checked in. Let'
nasko 2015/06/04 23:38:36 Done.
704 render_view_->main_render_frame_ = nullptr; 702 render_view_->main_render_frame_ = nullptr;
705 } 703 }
706 704
707 render_view_->UnregisterRenderFrame(this); 705 render_view_->UnregisterRenderFrame(this);
708 g_routing_id_frame_map.Get().erase(routing_id_); 706 g_routing_id_frame_map.Get().erase(routing_id_);
709 RenderThread::Get()->RemoveRoute(routing_id_); 707 RenderThread::Get()->RemoveRoute(routing_id_);
710 } 708 }
711 709
712 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) { 710 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) {
713 DCHECK(!frame_); 711 DCHECK(!frame_);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 // willCheckAndDispatchMessageEvent() that needs the proxy. 1143 // willCheckAndDispatchMessageEvent() that needs the proxy.
1146 if (proxy) 1144 if (proxy)
1147 set_render_frame_proxy(proxy); 1145 set_render_frame_proxy(proxy);
1148 1146
1149 // Now that we're swapped out and filtering IPC messages, stop loading to 1147 // Now that we're swapped out and filtering IPC messages, stop loading to
1150 // ensure that no other in-progress navigation continues. We do this here 1148 // ensure that no other in-progress navigation continues. We do this here
1151 // to avoid sending a DidStopLoading message to the browser process. 1149 // to avoid sending a DidStopLoading message to the browser process.
1152 // TODO(creis): Should we be stopping all frames here and using 1150 // TODO(creis): Should we be stopping all frames here and using
1153 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this 1151 // StopAltErrorPageFetcher with RenderView::OnStop, or just stopping this
1154 // frame? 1152 // frame?
1155 OnStop(); 1153 if (!is_site_per_process)
1154 OnStop();
1156 1155
1157 // Transfer settings such as initial drawing parameters to the remote frame, 1156 // Transfer settings such as initial drawing parameters to the remote frame,
1158 // if one is created, that will replace this frame. 1157 // if one is created, that will replace this frame.
1159 if (!is_main_frame && proxy) 1158 if (!is_main_frame && proxy)
1160 proxy->web_frame()->initializeFromFrame(frame_); 1159 proxy->web_frame()->initializeFromFrame(frame_);
1161 1160
1162 // Replace the page with a blank dummy URL. The unload handler will not be 1161 // Replace the page with a blank dummy URL. The unload handler will not be
1163 // run a second time, thanks to a check in FrameLoader::stopLoading. 1162 // run a second time, thanks to a check in FrameLoader::stopLoading.
1164 // TODO(creis): Need to add a better way to do this that avoids running the 1163 // TODO(creis): Need to add a better way to do this that avoids running the
1165 // beforeunload handler. For now, we just run it a second time silently. 1164 // beforeunload handler. For now, we just run it a second time silently.
1166 if (!is_site_per_process || is_main_frame) 1165 if (!is_site_per_process)
1167 NavigateToSwappedOutURL(); 1166 NavigateToSwappedOutURL();
1168 1167
1169 // Let WebKit know that this view is hidden so it can drop resources and 1168 // Let WebKit know that this view is hidden so it can drop resources and
1170 // stop compositing. 1169 // stop compositing.
1171 // TODO(creis): Support this for subframes as well. 1170 // TODO(creis): Support this for subframes as well.
1172 if (is_main_frame) { 1171 if (is_main_frame) {
1173 render_view_->webview()->setVisibilityState( 1172 render_view_->webview()->setVisibilityState(
1174 blink::WebPageVisibilityStateHidden, false); 1173 blink::WebPageVisibilityStateHidden, false);
1175 } 1174 }
1176 } 1175 }
1177 1176
1178 // It is now safe to show modal dialogs again. 1177 // It is now safe to show modal dialogs again.
1179 // TODO(creis): Deal with modal dialogs from subframes. 1178 // TODO(creis): Deal with modal dialogs from subframes.
1180 if (is_main_frame) 1179 if (is_main_frame)
1181 render_view_->suppress_dialogs_until_swap_out_ = false; 1180 render_view_->suppress_dialogs_until_swap_out_ = false;
1182 1181
1183 Send(new FrameHostMsg_SwapOut_ACK(routing_id_)); 1182 Send(new FrameHostMsg_SwapOut_ACK(routing_id_));
1184 1183
1184 RenderViewImpl* render_view = render_view_.get();
1185
1185 // Now that all of the cleanup is complete and the browser side is notified, 1186 // Now that all of the cleanup is complete and the browser side is notified,
1186 // start using the RenderFrameProxy, if one is created. 1187 // start using the RenderFrameProxy, if one is created.
1187 if (proxy) { 1188 if (proxy) {
1188 if (!is_main_frame) { 1189 if (is_site_per_process || !is_main_frame) {
1189 frame_->swap(proxy->web_frame()); 1190 frame_->swap(proxy->web_frame());
1190 1191
1191 if (is_loading) 1192 if (is_loading)
1192 proxy->OnDidStartLoading(); 1193 proxy->OnDidStartLoading();
1193
1194 if (is_site_per_process) {
1195 // TODO(nasko): delete the frame here, since we've replaced it with a
1196 // proxy.
1197 }
1198 } 1194 }
1199 } 1195 }
1200 1196
1201 // In --site-per-process, initialize the WebRemoteFrame with the replication 1197 // In --site-per-process, initialize the WebRemoteFrame with the replication
1202 // state passed by the process that is now rendering the frame. 1198 // state passed by the process that is now rendering the frame.
1203 // TODO(alexmos): We cannot yet do this for swapped-out main frames, because 1199 // TODO(alexmos): We cannot yet do this for swapped-out main frames, because
1204 // in that case we leave the LocalFrame as the main frame visible to Blink 1200 // in that case we leave the LocalFrame as the main frame visible to Blink
1205 // and don't call swap() above. Because swap() is what creates a RemoteFrame 1201 // and don't call swap() above. Because swap() is what creates a RemoteFrame
1206 // in proxy->web_frame(), the RemoteFrame will not exist for main frames. 1202 // in proxy->web_frame(), the RemoteFrame will not exist for main frames.
1207 // When we do an unconditional swap for all frames, we can remove 1203 // When we do an unconditional swap for all frames, we can remove
1208 // !is_main_frame below. 1204 // !is_main_frame below.
1209 if (is_site_per_process && proxy && !is_main_frame) 1205 if (is_site_per_process && proxy)
1210 proxy->SetReplicatedState(replicated_frame_state); 1206 proxy->SetReplicatedState(replicated_frame_state);
1211 1207
1212 // Safe to exit if no one else is using the process. 1208 // Safe to exit if no one else is using the process.
1213 if (is_main_frame) 1209 // TODO(nasko): Remove the dependency on RenderViewImpl here and ref count
1214 render_view_->WasSwappedOut(); 1210 // the process based on the lifetime of this RenderFrameImpl object.
1211 if (is_main_frame) {
1212 render_view->WasSwappedOut();
1213
1214 // TODO(nasko): Currently, this RenderFrame is leaked due to issues in
1215 // Blink, therefore the destructor won't be invoked to destroy this
1216 // object. In the meantime, set the main frame of the RenderView to null
1217 // here.
1218 if (is_site_per_process) {
1219 CHECK_EQ(render_view_->main_render_frame_, this);
1220 render_view->main_render_frame_ = nullptr;
1221 }
1222 }
1215 } 1223 }
1216 1224
1217 void RenderFrameImpl::OnContextMenuClosed( 1225 void RenderFrameImpl::OnContextMenuClosed(
1218 const CustomContextMenuContext& custom_context) { 1226 const CustomContextMenuContext& custom_context) {
1219 if (custom_context.request_id) { 1227 if (custom_context.request_id) {
1220 // External request, should be in our map. 1228 // External request, should be in our map.
1221 ContextMenuClient* client = 1229 ContextMenuClient* client =
1222 pending_context_menus_.Lookup(custom_context.request_id); 1230 pending_context_menus_.Lookup(custom_context.request_id);
1223 if (client) { 1231 if (client) {
1224 client->OnMenuClosed(custom_context.request_id); 1232 client->OnMenuClosed(custom_context.request_id);
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 static_cast<NavigationStateImpl*>(document_state->navigation_state()); 2594 static_cast<NavigationStateImpl*>(document_state->navigation_state());
2587 2595
2588 if (proxy_routing_id_ != MSG_ROUTING_NONE) { 2596 if (proxy_routing_id_ != MSG_ROUTING_NONE) {
2589 RenderFrameProxy* proxy = 2597 RenderFrameProxy* proxy =
2590 RenderFrameProxy::FromRoutingID(proxy_routing_id_); 2598 RenderFrameProxy::FromRoutingID(proxy_routing_id_);
2591 CHECK(proxy); 2599 CHECK(proxy);
2592 proxy->web_frame()->swap(frame_); 2600 proxy->web_frame()->swap(frame_);
2593 proxy_routing_id_ = MSG_ROUTING_NONE; 2601 proxy_routing_id_ = MSG_ROUTING_NONE;
2594 2602
2595 // If this is the main frame going from a remote frame to a local frame, 2603 // If this is the main frame going from a remote frame to a local frame,
2596 // it needs to set RenderViewImpl's pointer for the main frame to itself. 2604 // it needs to set RenderViewImpl's pointer for the main frame to itself
2605 // and ensure RenderWidget is no longer in swapped out mode.
2597 if (!is_subframe_) { 2606 if (!is_subframe_) {
2598 CHECK(!render_view_->main_render_frame_); 2607 CHECK(!render_view_->main_render_frame_);
2599 render_view_->main_render_frame_ = this; 2608 render_view_->main_render_frame_ = this;
2609 if (render_view_->is_swapped_out())
2610 render_view_->SetSwappedOut(false);
2600 } 2611 }
2601 } 2612 }
2602 2613
2603 // When we perform a new navigation, we need to update the last committed 2614 // When we perform a new navigation, we need to update the last committed
2604 // session history entry with state for the page we are leaving. Do this 2615 // session history entry with state for the page we are leaving. Do this
2605 // before updating the HistoryController state. 2616 // before updating the HistoryController state.
2606 render_view_->UpdateSessionHistory(frame); 2617 render_view_->UpdateSessionHistory(frame);
2607 2618
2608 render_view_->history_controller()->UpdateForCommit( 2619 render_view_->history_controller()->UpdateForCommit(
2609 this, item, commit_type, navigation_state->WasWithinSamePage()); 2620 this, item, commit_type, navigation_state->WasWithinSamePage());
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
4358 } 4369 }
4359 4370
4360 Send(new FrameHostMsg_OpenURL(routing_id_, params)); 4371 Send(new FrameHostMsg_OpenURL(routing_id_, params));
4361 } 4372 }
4362 4373
4363 void RenderFrameImpl::NavigateInternal( 4374 void RenderFrameImpl::NavigateInternal(
4364 const CommonNavigationParams& common_params, 4375 const CommonNavigationParams& common_params,
4365 const StartNavigationParams& start_params, 4376 const StartNavigationParams& start_params,
4366 const RequestNavigationParams& request_params, 4377 const RequestNavigationParams& request_params,
4367 scoped_ptr<StreamOverrideParameters> stream_params) { 4378 scoped_ptr<StreamOverrideParameters> stream_params) {
4379 if (proxy_routing_id_ != MSG_ROUTING_NONE) {
4380 RenderFrameProxy* proxy =
4381 RenderFrameProxy::FromRoutingID(proxy_routing_id_);
4382 CHECK(proxy);
4383 proxy->web_frame()->swap(frame_);
4384 proxy_routing_id_ = MSG_ROUTING_NONE;
4385
4386 // If this is the main frame going from a remote frame to a local frame,
4387 // it needs to set RenderViewImpl's pointer for the main frame to itself.
4388 if (!is_subframe_) {
4389 CHECK(!render_view_->main_render_frame_);
4390 render_view_->main_render_frame_ = this;
4391 }
4392 }
4393
4368 bool browser_side_navigation = 4394 bool browser_side_navigation =
4369 base::CommandLine::ForCurrentProcess()->HasSwitch( 4395 base::CommandLine::ForCurrentProcess()->HasSwitch(
4370 switches::kEnableBrowserSideNavigation); 4396 switches::kEnableBrowserSideNavigation);
4371 bool is_reload = IsReload(common_params.navigation_type); 4397 bool is_reload = IsReload(common_params.navigation_type);
4372 bool is_history_navigation = request_params.page_state.IsValid(); 4398 bool is_history_navigation = request_params.page_state.IsValid();
4373 WebURLRequest::CachePolicy cache_policy = 4399 WebURLRequest::CachePolicy cache_policy =
4374 WebURLRequest::UseProtocolCachePolicy; 4400 WebURLRequest::UseProtocolCachePolicy;
4375 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 4401 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
4376 common_params.url, is_history_navigation, request_params, &is_reload, 4402 common_params.url, is_history_navigation, request_params, &is_reload,
4377 &cache_policy)) { 4403 &cache_policy)) {
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
4913 #elif defined(ENABLE_BROWSER_CDMS) 4939 #elif defined(ENABLE_BROWSER_CDMS)
4914 cdm_manager_, 4940 cdm_manager_,
4915 #endif 4941 #endif
4916 this); 4942 this);
4917 } 4943 }
4918 4944
4919 return cdm_factory_; 4945 return cdm_factory_;
4920 } 4946 }
4921 4947
4922 } // namespace content 4948 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698