| 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/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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // Doing this is important in the case where the replacement proxy is created | 629 // Doing this is important in the case where the replacement proxy is created |
| 630 // above, as the RenderViewHost will continue to exist and should be | 630 // above, as the RenderViewHost will continue to exist and should be |
| 631 // considered swapped out if it is ever reused. When there's no replacement | 631 // considered swapped out if it is ever reused. When there's no replacement |
| 632 // proxy, this doesn't really matter, as the RenderViewHost will be destroyed | 632 // proxy, this doesn't really matter, as the RenderViewHost will be destroyed |
| 633 // shortly, since |render_frame_host| is its last active frame and will be | 633 // shortly, since |render_frame_host| is its last active frame and will be |
| 634 // deleted below. See https://crbug.com/627400. | 634 // deleted below. See https://crbug.com/627400. |
| 635 if (frame_tree_node_->IsMainFrame()) { | 635 if (frame_tree_node_->IsMainFrame()) { |
| 636 rvh->set_main_frame_routing_id(MSG_ROUTING_NONE); | 636 rvh->set_main_frame_routing_id(MSG_ROUTING_NONE); |
| 637 rvh->set_is_active(false); | 637 rvh->set_is_active(false); |
| 638 rvh->set_is_swapped_out(true); | 638 rvh->set_is_swapped_out(true); |
| 639 | |
| 640 if (rvh->GetWidget()->GetView()) { | |
| 641 rvh->GetWidget()->GetView()->Destroy(); | |
| 642 rvh->GetWidget()->SetView(nullptr); | |
| 643 } | |
| 644 } | 639 } |
| 645 | 640 |
| 646 render_frame_host.reset(); | 641 render_frame_host.reset(); |
| 647 | 642 |
| 648 // If a new RenderFrameProxyHost was created above, or if the old proxy isn't | 643 // If a new RenderFrameProxyHost was created above, or if the old proxy isn't |
| 649 // live, create the RenderFrameProxy in the renderer, so that other frames | 644 // live, create the RenderFrameProxy in the renderer, so that other frames |
| 650 // can still communicate with this frame. See https://crbug.com/653746. | 645 // can still communicate with this frame. See https://crbug.com/653746. |
| 651 if (proxy && !proxy->is_render_frame_proxy_live()) | 646 if (proxy && !proxy->is_render_frame_proxy_live()) |
| 652 proxy->InitRenderFrameProxy(); | 647 proxy->InitRenderFrameProxy(); |
| 653 } | 648 } |
| 654 | 649 |
| 655 bool RenderFrameHostManager::DeleteFromPendingList( | 650 bool RenderFrameHostManager::DeleteFromPendingList( |
| 656 RenderFrameHostImpl* render_frame_host) { | 651 RenderFrameHostImpl* render_frame_host) { |
| 657 // If this is a main frame RFH that's about to be deleted, update its RVH's | |
| 658 // swapped-out state here. https://crbug.com/505887 | |
| 659 if (frame_tree_node_->IsMainFrame()) { | |
| 660 RenderViewHostImpl* rvh = render_frame_host->render_view_host(); | |
| 661 | |
| 662 if (!rvh->is_active()) | |
| 663 rvh->set_is_swapped_out(true); | |
| 664 } | |
| 665 | |
| 666 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin(); | 652 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin(); |
| 667 iter != pending_delete_hosts_.end(); | 653 iter != pending_delete_hosts_.end(); |
| 668 iter++) { | 654 iter++) { |
| 669 if (iter->get() == render_frame_host) { | 655 if (iter->get() == render_frame_host) { |
| 670 pending_delete_hosts_.erase(iter); | 656 pending_delete_hosts_.erase(iter); |
| 671 return true; | 657 return true; |
| 672 } | 658 } |
| 673 } | 659 } |
| 674 return false; | 660 return false; |
| 675 } | 661 } |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, hidden, | 1735 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, hidden, |
| 1750 false); | 1736 false); |
| 1751 RenderViewHostImpl* render_view_host = | 1737 RenderViewHostImpl* render_view_host = |
| 1752 new_render_frame_host->render_view_host(); | 1738 new_render_frame_host->render_view_host(); |
| 1753 | 1739 |
| 1754 // Prevent the process from exiting while we're trying to navigate in it. | 1740 // Prevent the process from exiting while we're trying to navigate in it. |
| 1755 new_render_frame_host->GetProcess()->AddPendingView(); | 1741 new_render_frame_host->GetProcess()->AddPendingView(); |
| 1756 | 1742 |
| 1757 if (frame_tree_node_->IsMainFrame()) { | 1743 if (frame_tree_node_->IsMainFrame()) { |
| 1758 success = InitRenderView(render_view_host, proxy); | 1744 success = InitRenderView(render_view_host, proxy); |
| 1745 |
| 1746 // If we are reusing the RenderViewHost and it doesn't already have a |
| 1747 // RenderWidgetHostView, we need to create one if this is the main frame. |
| 1748 if (!render_view_host->GetWidget()->GetView()) |
| 1749 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host); |
| 1759 } else { | 1750 } else { |
| 1760 DCHECK(render_view_host->IsRenderViewLive()); | 1751 DCHECK(render_view_host->IsRenderViewLive()); |
| 1761 } | 1752 } |
| 1762 | 1753 |
| 1763 if (success) { | 1754 if (success) { |
| 1764 if (frame_tree_node_->IsMainFrame()) { | 1755 if (frame_tree_node_->IsMainFrame()) { |
| 1765 // Don't show the main frame's view until we get a DidNavigate from it. | 1756 // Don't show the main frame's view until we get a DidNavigate from it. |
| 1766 // Only the RenderViewHost for the top-level RenderFrameHost has a | 1757 // Only the RenderViewHost for the top-level RenderFrameHost has a |
| 1767 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes | 1758 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes |
| 1768 // will be created later and hidden. | 1759 // will be created later and hidden. |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 | 2152 |
| 2162 // Save off the old background color before possibly deleting the | 2153 // Save off the old background color before possibly deleting the |
| 2163 // old RenderWidgetHostView. | 2154 // old RenderWidgetHostView. |
| 2164 SkColor old_background_color = SK_ColorWHITE; | 2155 SkColor old_background_color = SK_ColorWHITE; |
| 2165 bool has_old_background_color = false; | 2156 bool has_old_background_color = false; |
| 2166 if (old_render_frame_host->GetView()) { | 2157 if (old_render_frame_host->GetView()) { |
| 2167 has_old_background_color = true; | 2158 has_old_background_color = true; |
| 2168 old_background_color = old_render_frame_host->GetView()->background_color(); | 2159 old_background_color = old_render_frame_host->GetView()->background_color(); |
| 2169 } | 2160 } |
| 2170 | 2161 |
| 2171 // The RenderViewHost keeps track of the main RenderFrameHost routing id. | |
| 2172 // If this is committing a main frame navigation, update it and set the | |
| 2173 // routing id in the RenderViewHost associated with the old RenderFrameHost | |
| 2174 // to MSG_ROUTING_NONE. | |
| 2175 if (is_main_frame) { | |
| 2176 RenderViewHostImpl* rvh = render_frame_host_->render_view_host(); | |
| 2177 rvh->set_main_frame_routing_id(render_frame_host_->routing_id()); | |
| 2178 | |
| 2179 // If we are reusing the RenderViewHost, we need to create the | |
| 2180 // RenderWidgetHostView if this is the main frame. | |
| 2181 if (rvh->IsRenderViewLive() && !rvh->is_active()) | |
| 2182 delegate_->CreateRenderWidgetHostViewForRenderManager(rvh); | |
| 2183 | |
| 2184 // If the RenderViewHost is transitioning from swapped out to active state, | |
| 2185 // it was reused, so dispatch a RenderViewReady event. For example, this | |
| 2186 // is necessary to hide the sad tab if one is currently displayed. See | |
| 2187 // https://crbug.com/591984. | |
| 2188 // | |
| 2189 // TODO(alexmos): Remove this and move RenderViewReady consumers to use | |
| 2190 // the main frame's RenderFrameCreated instead. | |
| 2191 if (!rvh->is_active()) | |
| 2192 rvh->PostRenderViewReady(); | |
| 2193 | |
| 2194 rvh->set_is_active(true); | |
| 2195 rvh->set_is_swapped_out(false); | |
| 2196 | |
| 2197 // Tell the old RenderViewHost it is no longer active. | |
| 2198 RenderViewHostImpl* old_rvh = old_render_frame_host->render_view_host(); | |
| 2199 old_rvh->set_main_frame_routing_id(MSG_ROUTING_NONE); | |
| 2200 old_rvh->set_is_active(false); | |
| 2201 | |
| 2202 // Destroy the old RenderWidgetHostView. | |
| 2203 if (old_rvh->GetWidget()->GetView()) { | |
| 2204 old_rvh->GetWidget()->GetView()->Destroy(); | |
| 2205 old_rvh->GetWidget()->SetView(nullptr); | |
| 2206 } | |
| 2207 } | |
| 2208 | |
| 2209 // Show the new view (or a sad tab) if necessary. | 2162 // Show the new view (or a sad tab) if necessary. |
| 2210 bool new_rfh_has_view = !!render_frame_host_->GetView(); | 2163 bool new_rfh_has_view = !!render_frame_host_->GetView(); |
| 2211 if (!delegate_->IsHidden() && new_rfh_has_view) { | 2164 if (!delegate_->IsHidden() && new_rfh_has_view) { |
| 2212 // In most cases, we need to show the new view. | 2165 // In most cases, we need to show the new view. |
| 2213 render_frame_host_->GetView()->Show(); | 2166 render_frame_host_->GetView()->Show(); |
| 2214 } | 2167 } |
| 2215 if (!new_rfh_has_view) { | 2168 if (!new_rfh_has_view) { |
| 2216 // If the view is gone, then this RenderViewHost died while it was hidden. | 2169 // If the view is gone, then this RenderViewHost died while it was hidden. |
| 2217 // We ignored the RenderProcessGone call at the time, so we should send it | 2170 // We ignored the RenderProcessGone call at the time, so we should send it |
| 2218 // now to make sure the sad tab shows up, etc. | 2171 // now to make sure the sad tab shows up, etc. |
| 2219 DCHECK(!render_frame_host_->IsRenderFrameLive()); | 2172 DCHECK(!render_frame_host_->IsRenderFrameLive()); |
| 2220 DCHECK(!render_frame_host_->render_view_host()->IsRenderViewLive()); | 2173 DCHECK(!render_frame_host_->render_view_host()->IsRenderViewLive()); |
| 2221 render_frame_host_->ResetLoadingState(); | 2174 render_frame_host_->ResetLoadingState(); |
| 2222 delegate_->RenderProcessGoneFromRenderManager( | 2175 delegate_->RenderProcessGoneFromRenderManager( |
| 2223 render_frame_host_->render_view_host()); | 2176 render_frame_host_->render_view_host()); |
| 2224 } | 2177 } |
| 2225 | 2178 |
| 2179 // For top-level frames, also hide the old RenderViewHost's view. |
| 2180 // TODO(creis): As long as show/hide are on RVH, we don't want to hide on |
| 2181 // subframe navigations or we will interfere with the top-level frame. |
| 2182 if (is_main_frame && |
| 2183 old_render_frame_host->render_view_host()->GetWidget()->GetView()) { |
| 2184 old_render_frame_host->render_view_host()->GetWidget()->GetView()->Hide(); |
| 2185 } |
| 2186 |
| 2226 // Make sure the size is up to date. (Fix for bug 1079768.) | 2187 // Make sure the size is up to date. (Fix for bug 1079768.) |
| 2227 delegate_->UpdateRenderViewSizeForRenderManager(); | 2188 delegate_->UpdateRenderViewSizeForRenderManager(); |
| 2228 | 2189 |
| 2229 if (will_focus_location_bar) { | 2190 if (will_focus_location_bar) { |
| 2230 delegate_->SetFocusToLocationBar(false); | 2191 delegate_->SetFocusToLocationBar(false); |
| 2231 } else if (focus_render_view && render_frame_host_->GetView()) { | 2192 } else if (focus_render_view && render_frame_host_->GetView()) { |
| 2232 if (is_main_frame) { | 2193 if (is_main_frame) { |
| 2233 render_frame_host_->GetView()->Focus(); | 2194 render_frame_host_->GetView()->Focus(); |
| 2234 } else { | 2195 } else { |
| 2235 // The main frame's view is already focused, but we need to set | 2196 // The main frame's view is already focused, but we need to set |
| 2236 // page-level focus in the subframe's renderer. | 2197 // page-level focus in the subframe's renderer. |
| 2237 frame_tree_node_->frame_tree()->SetPageFocus( | 2198 frame_tree_node_->frame_tree()->SetPageFocus( |
| 2238 render_frame_host_->GetSiteInstance(), true); | 2199 render_frame_host_->GetSiteInstance(), true); |
| 2239 } | 2200 } |
| 2240 } | 2201 } |
| 2241 | 2202 |
| 2242 // Notify that we've swapped RenderFrameHosts. We do this before shutting down | 2203 // Notify that we've swapped RenderFrameHosts. We do this before shutting down |
| 2243 // the RFH so that we can clean up RendererResources related to the RFH first. | 2204 // the RFH so that we can clean up RendererResources related to the RFH first. |
| 2244 delegate_->NotifySwappedFromRenderManager( | 2205 delegate_->NotifySwappedFromRenderManager( |
| 2245 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame); | 2206 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame); |
| 2246 | 2207 |
| 2247 if (has_old_background_color && render_frame_host_->GetView()) | 2208 if (has_old_background_color && render_frame_host_->GetView()) |
| 2248 render_frame_host_->GetView()->SetBackgroundColor(old_background_color); | 2209 render_frame_host_->GetView()->SetBackgroundColor(old_background_color); |
| 2249 | 2210 |
| 2211 // The RenderViewHost keeps track of the main RenderFrameHost routing id. |
| 2212 // If this is committing a main frame navigation, update it and set the |
| 2213 // routing id in the RenderViewHost associated with the old RenderFrameHost |
| 2214 // to MSG_ROUTING_NONE. |
| 2215 if (is_main_frame) { |
| 2216 RenderViewHostImpl* rvh = render_frame_host_->render_view_host(); |
| 2217 rvh->set_main_frame_routing_id(render_frame_host_->routing_id()); |
| 2218 |
| 2219 // If the RenderViewHost is transitioning from swapped out to active state, |
| 2220 // it was reused, so dispatch a RenderViewReady event. For example, this |
| 2221 // is necessary to hide the sad tab if one is currently displayed. See |
| 2222 // https://crbug.com/591984. |
| 2223 // |
| 2224 // TODO(alexmos): Remove this and move RenderViewReady consumers to use |
| 2225 // the main frame's RenderFrameCreated instead. |
| 2226 if (!rvh->is_active()) |
| 2227 rvh->PostRenderViewReady(); |
| 2228 |
| 2229 rvh->set_is_active(true); |
| 2230 rvh->set_is_swapped_out(false); |
| 2231 old_render_frame_host->render_view_host()->set_main_frame_routing_id( |
| 2232 MSG_ROUTING_NONE); |
| 2233 } |
| 2234 |
| 2250 // Swap out the old frame now that the new one is visible. | 2235 // Swap out the old frame now that the new one is visible. |
| 2251 // This will swap it out and schedule it for deletion when the swap out ack | 2236 // This will swap it out and schedule it for deletion when the swap out ack |
| 2252 // arrives (or immediately if the process isn't live). | 2237 // arrives (or immediately if the process isn't live). |
| 2253 SwapOutOldFrame(std::move(old_render_frame_host)); | 2238 SwapOutOldFrame(std::move(old_render_frame_host)); |
| 2254 | 2239 |
| 2255 // Since the new RenderFrameHost is now committed, there must be no proxies | 2240 // Since the new RenderFrameHost is now committed, there must be no proxies |
| 2256 // for its SiteInstance. Delete any existing ones. | 2241 // for its SiteInstance. Delete any existing ones. |
| 2257 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance()); | 2242 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance()); |
| 2258 | 2243 |
| 2259 // If this is a subframe, it should have a CrossProcessFrameConnector | 2244 // If this is a subframe, it should have a CrossProcessFrameConnector |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2801 delegate_->IsHidden()) { | 2786 delegate_->IsHidden()) { |
| 2802 if (delegate_->IsHidden()) { | 2787 if (delegate_->IsHidden()) { |
| 2803 render_frame_host_->GetView()->Hide(); | 2788 render_frame_host_->GetView()->Hide(); |
| 2804 } else { | 2789 } else { |
| 2805 render_frame_host_->GetView()->Show(); | 2790 render_frame_host_->GetView()->Show(); |
| 2806 } | 2791 } |
| 2807 } | 2792 } |
| 2808 } | 2793 } |
| 2809 | 2794 |
| 2810 } // namespace content | 2795 } // namespace content |
| OLD | NEW |