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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 2798673002: Revert "Destroy the old RenderWidgetHostView when swapping out a main frame." (Closed)
Patch Set: Created 3 years, 8 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/browser/frame_host/render_frame_host_manager.h" 5 #include "content/browser/frame_host/render_frame_host_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // Doing this is important in the case where the replacement proxy is created 680 // Doing this is important in the case where the replacement proxy is created
681 // above, as the RenderViewHost will continue to exist and should be 681 // above, as the RenderViewHost will continue to exist and should be
682 // considered swapped out if it is ever reused. When there's no replacement 682 // considered swapped out if it is ever reused. When there's no replacement
683 // proxy, this doesn't really matter, as the RenderViewHost will be destroyed 683 // proxy, this doesn't really matter, as the RenderViewHost will be destroyed
684 // shortly, since |render_frame_host| is its last active frame and will be 684 // shortly, since |render_frame_host| is its last active frame and will be
685 // deleted below. See https://crbug.com/627400. 685 // deleted below. See https://crbug.com/627400.
686 if (frame_tree_node_->IsMainFrame()) { 686 if (frame_tree_node_->IsMainFrame()) {
687 rvh->set_main_frame_routing_id(MSG_ROUTING_NONE); 687 rvh->set_main_frame_routing_id(MSG_ROUTING_NONE);
688 rvh->set_is_active(false); 688 rvh->set_is_active(false);
689 rvh->set_is_swapped_out(true); 689 rvh->set_is_swapped_out(true);
690
691 if (rvh->GetWidget()->GetView()) {
692 rvh->GetWidget()->GetView()->Destroy();
693 rvh->GetWidget()->SetView(nullptr);
694 }
695 } 690 }
696 691
697 render_frame_host.reset(); 692 render_frame_host.reset();
698 693
699 // If a new RenderFrameProxyHost was created above, or if the old proxy isn't 694 // If a new RenderFrameProxyHost was created above, or if the old proxy isn't
700 // live, create the RenderFrameProxy in the renderer, so that other frames 695 // live, create the RenderFrameProxy in the renderer, so that other frames
701 // can still communicate with this frame. See https://crbug.com/653746. 696 // can still communicate with this frame. See https://crbug.com/653746.
702 if (proxy && !proxy->is_render_frame_proxy_live()) 697 if (proxy && !proxy->is_render_frame_proxy_live())
703 proxy->InitRenderFrameProxy(); 698 proxy->InitRenderFrameProxy();
704 } 699 }
705 700
706 bool RenderFrameHostManager::DeleteFromPendingList( 701 bool RenderFrameHostManager::DeleteFromPendingList(
707 RenderFrameHostImpl* render_frame_host) { 702 RenderFrameHostImpl* render_frame_host) {
708 // If this is a main frame RFH that's about to be deleted, update its RVH's
709 // swapped-out state here. https://crbug.com/505887
710 if (frame_tree_node_->IsMainFrame()) {
711 RenderViewHostImpl* rvh = render_frame_host->render_view_host();
712
713 if (!rvh->is_active())
714 rvh->set_is_swapped_out(true);
715 }
716
717 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin(); 703 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin();
718 iter != pending_delete_hosts_.end(); 704 iter != pending_delete_hosts_.end();
719 iter++) { 705 iter++) {
720 if (iter->get() == render_frame_host) { 706 if (iter->get() == render_frame_host) {
721 pending_delete_hosts_.erase(iter); 707 pending_delete_hosts_.erase(iter);
722 return true; 708 return true;
723 } 709 }
724 } 710 }
725 return false; 711 return false;
726 } 712 }
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, hidden, 1786 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, hidden,
1801 false); 1787 false);
1802 RenderViewHostImpl* render_view_host = 1788 RenderViewHostImpl* render_view_host =
1803 new_render_frame_host->render_view_host(); 1789 new_render_frame_host->render_view_host();
1804 1790
1805 // Prevent the process from exiting while we're trying to navigate in it. 1791 // Prevent the process from exiting while we're trying to navigate in it.
1806 new_render_frame_host->GetProcess()->AddPendingView(); 1792 new_render_frame_host->GetProcess()->AddPendingView();
1807 1793
1808 if (frame_tree_node_->IsMainFrame()) { 1794 if (frame_tree_node_->IsMainFrame()) {
1809 success = InitRenderView(render_view_host, proxy); 1795 success = InitRenderView(render_view_host, proxy);
1796
1797 // If we are reusing the RenderViewHost and it doesn't already have a
1798 // RenderWidgetHostView, we need to create one if this is the main frame.
1799 if (!render_view_host->GetWidget()->GetView())
1800 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host);
1810 } else { 1801 } else {
1811 DCHECK(render_view_host->IsRenderViewLive()); 1802 DCHECK(render_view_host->IsRenderViewLive());
1812 } 1803 }
1813 1804
1814 if (success) { 1805 if (success) {
1815 if (frame_tree_node_->IsMainFrame()) { 1806 if (frame_tree_node_->IsMainFrame()) {
1816 // Don't show the main frame's view until we get a DidNavigate from it. 1807 // Don't show the main frame's view until we get a DidNavigate from it.
1817 // Only the RenderViewHost for the top-level RenderFrameHost has a 1808 // Only the RenderViewHost for the top-level RenderFrameHost has a
1818 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes 1809 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes
1819 // will be created later and hidden. 1810 // will be created later and hidden.
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 2203
2213 // Save off the old background color before possibly deleting the 2204 // Save off the old background color before possibly deleting the
2214 // old RenderWidgetHostView. 2205 // old RenderWidgetHostView.
2215 SkColor old_background_color = SK_ColorWHITE; 2206 SkColor old_background_color = SK_ColorWHITE;
2216 bool has_old_background_color = false; 2207 bool has_old_background_color = false;
2217 if (old_render_frame_host->GetView()) { 2208 if (old_render_frame_host->GetView()) {
2218 has_old_background_color = true; 2209 has_old_background_color = true;
2219 old_background_color = old_render_frame_host->GetView()->background_color(); 2210 old_background_color = old_render_frame_host->GetView()->background_color();
2220 } 2211 }
2221 2212
2222 // The RenderViewHost keeps track of the main RenderFrameHost routing id.
2223 // If this is committing a main frame navigation, update it and set the
2224 // routing id in the RenderViewHost associated with the old RenderFrameHost
2225 // to MSG_ROUTING_NONE.
2226 if (is_main_frame) {
2227 RenderViewHostImpl* rvh = render_frame_host_->render_view_host();
2228 rvh->set_main_frame_routing_id(render_frame_host_->routing_id());
2229
2230 // If we are reusing the RenderViewHost, we need to create the
2231 // RenderWidgetHostView if this is the main frame.
2232 if (rvh->IsRenderViewLive() && !rvh->is_active())
2233 delegate_->CreateRenderWidgetHostViewForRenderManager(rvh);
2234
2235 // If the RenderViewHost is transitioning from swapped out to active state,
2236 // it was reused, so dispatch a RenderViewReady event. For example, this
2237 // is necessary to hide the sad tab if one is currently displayed. See
2238 // https://crbug.com/591984.
2239 //
2240 // TODO(alexmos): Remove this and move RenderViewReady consumers to use
2241 // the main frame's RenderFrameCreated instead.
2242 if (!rvh->is_active())
2243 rvh->PostRenderViewReady();
2244
2245 rvh->set_is_active(true);
2246 rvh->set_is_swapped_out(false);
2247
2248 // Tell the old RenderViewHost it is no longer active.
2249 RenderViewHostImpl* old_rvh = old_render_frame_host->render_view_host();
2250 old_rvh->set_main_frame_routing_id(MSG_ROUTING_NONE);
2251 old_rvh->set_is_active(false);
2252
2253 // Destroy the old RenderWidgetHostView.
2254 if (old_rvh->GetWidget()->GetView()) {
2255 old_rvh->GetWidget()->GetView()->Destroy();
2256 old_rvh->GetWidget()->SetView(nullptr);
2257 }
2258 }
2259
2260 // Show the new view (or a sad tab) if necessary. 2213 // Show the new view (or a sad tab) if necessary.
2261 bool new_rfh_has_view = !!render_frame_host_->GetView(); 2214 bool new_rfh_has_view = !!render_frame_host_->GetView();
2262 if (!delegate_->IsHidden() && new_rfh_has_view) { 2215 if (!delegate_->IsHidden() && new_rfh_has_view) {
2263 // In most cases, we need to show the new view. 2216 // In most cases, we need to show the new view.
2264 render_frame_host_->GetView()->Show(); 2217 render_frame_host_->GetView()->Show();
2265 } 2218 }
2266 if (!new_rfh_has_view) { 2219 if (!new_rfh_has_view) {
2267 // If the view is gone, then this RenderViewHost died while it was hidden. 2220 // If the view is gone, then this RenderViewHost died while it was hidden.
2268 // We ignored the RenderProcessGone call at the time, so we should send it 2221 // We ignored the RenderProcessGone call at the time, so we should send it
2269 // now to make sure the sad tab shows up, etc. 2222 // now to make sure the sad tab shows up, etc.
2270 DCHECK(!render_frame_host_->IsRenderFrameLive()); 2223 DCHECK(!render_frame_host_->IsRenderFrameLive());
2271 DCHECK(!render_frame_host_->render_view_host()->IsRenderViewLive()); 2224 DCHECK(!render_frame_host_->render_view_host()->IsRenderViewLive());
2272 render_frame_host_->ResetLoadingState(); 2225 render_frame_host_->ResetLoadingState();
2273 delegate_->RenderProcessGoneFromRenderManager( 2226 delegate_->RenderProcessGoneFromRenderManager(
2274 render_frame_host_->render_view_host()); 2227 render_frame_host_->render_view_host());
2275 } 2228 }
2276 2229
2230 // For top-level frames, also hide the old RenderViewHost's view.
2231 // TODO(creis): As long as show/hide are on RVH, we don't want to hide on
2232 // subframe navigations or we will interfere with the top-level frame.
2233 if (is_main_frame &&
2234 old_render_frame_host->render_view_host()->GetWidget()->GetView()) {
2235 old_render_frame_host->render_view_host()->GetWidget()->GetView()->Hide();
2236 }
2237
2277 // Make sure the size is up to date. (Fix for bug 1079768.) 2238 // Make sure the size is up to date. (Fix for bug 1079768.)
2278 delegate_->UpdateRenderViewSizeForRenderManager(); 2239 delegate_->UpdateRenderViewSizeForRenderManager();
2279 2240
2280 if (will_focus_location_bar) { 2241 if (will_focus_location_bar) {
2281 delegate_->SetFocusToLocationBar(false); 2242 delegate_->SetFocusToLocationBar(false);
2282 } else if (focus_render_view && render_frame_host_->GetView()) { 2243 } else if (focus_render_view && render_frame_host_->GetView()) {
2283 if (is_main_frame) { 2244 if (is_main_frame) {
2284 render_frame_host_->GetView()->Focus(); 2245 render_frame_host_->GetView()->Focus();
2285 } else { 2246 } else {
2286 // The main frame's view is already focused, but we need to set 2247 // The main frame's view is already focused, but we need to set
2287 // page-level focus in the subframe's renderer. 2248 // page-level focus in the subframe's renderer.
2288 frame_tree_node_->frame_tree()->SetPageFocus( 2249 frame_tree_node_->frame_tree()->SetPageFocus(
2289 render_frame_host_->GetSiteInstance(), true); 2250 render_frame_host_->GetSiteInstance(), true);
2290 } 2251 }
2291 } 2252 }
2292 2253
2293 // Notify that we've swapped RenderFrameHosts. We do this before shutting down 2254 // Notify that we've swapped RenderFrameHosts. We do this before shutting down
2294 // the RFH so that we can clean up RendererResources related to the RFH first. 2255 // the RFH so that we can clean up RendererResources related to the RFH first.
2295 delegate_->NotifySwappedFromRenderManager( 2256 delegate_->NotifySwappedFromRenderManager(
2296 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame); 2257 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame);
2297 2258
2298 if (has_old_background_color && render_frame_host_->GetView()) 2259 if (has_old_background_color && render_frame_host_->GetView())
2299 render_frame_host_->GetView()->SetBackgroundColor(old_background_color); 2260 render_frame_host_->GetView()->SetBackgroundColor(old_background_color);
2300 2261
2262 // The RenderViewHost keeps track of the main RenderFrameHost routing id.
2263 // If this is committing a main frame navigation, update it and set the
2264 // routing id in the RenderViewHost associated with the old RenderFrameHost
2265 // to MSG_ROUTING_NONE.
2266 if (is_main_frame) {
2267 RenderViewHostImpl* rvh = render_frame_host_->render_view_host();
2268 rvh->set_main_frame_routing_id(render_frame_host_->routing_id());
2269
2270 // If the RenderViewHost is transitioning from swapped out to active state,
2271 // it was reused, so dispatch a RenderViewReady event. For example, this
2272 // is necessary to hide the sad tab if one is currently displayed. See
2273 // https://crbug.com/591984.
2274 //
2275 // TODO(alexmos): Remove this and move RenderViewReady consumers to use
2276 // the main frame's RenderFrameCreated instead.
2277 if (!rvh->is_active())
2278 rvh->PostRenderViewReady();
2279
2280 rvh->set_is_active(true);
2281 rvh->set_is_swapped_out(false);
2282 old_render_frame_host->render_view_host()->set_main_frame_routing_id(
2283 MSG_ROUTING_NONE);
2284 }
2285
2301 // Swap out the old frame now that the new one is visible. 2286 // Swap out the old frame now that the new one is visible.
2302 // This will swap it out and schedule it for deletion when the swap out ack 2287 // This will swap it out and schedule it for deletion when the swap out ack
2303 // arrives (or immediately if the process isn't live). 2288 // arrives (or immediately if the process isn't live).
2304 SwapOutOldFrame(std::move(old_render_frame_host)); 2289 SwapOutOldFrame(std::move(old_render_frame_host));
2305 2290
2306 // Since the new RenderFrameHost is now committed, there must be no proxies 2291 // Since the new RenderFrameHost is now committed, there must be no proxies
2307 // for its SiteInstance. Delete any existing ones. 2292 // for its SiteInstance. Delete any existing ones.
2308 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance()); 2293 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance());
2309 2294
2310 // If this is a subframe, it should have a CrossProcessFrameConnector 2295 // If this is a subframe, it should have a CrossProcessFrameConnector
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 resolved_url)) { 2814 resolved_url)) {
2830 DCHECK(!dest_instance || 2815 DCHECK(!dest_instance ||
2831 dest_instance == render_frame_host_->GetSiteInstance()); 2816 dest_instance == render_frame_host_->GetSiteInstance());
2832 return false; 2817 return false;
2833 } 2818 }
2834 2819
2835 return true; 2820 return true;
2836 } 2821 }
2837 2822
2838 } // namespace content 2823 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698