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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "content/browser/child_process_security_policy_impl.h" | 12 #include "content/browser/child_process_security_policy_impl.h" |
13 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 13 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
14 #include "content/browser/frame_host/interstitial_page_impl.h" | 14 #include "content/browser/frame_host/interstitial_page_impl.h" |
15 #include "content/browser/frame_host/navigation_controller_impl.h" | 15 #include "content/browser/frame_host/navigation_controller_impl.h" |
16 #include "content/browser/frame_host/navigation_entry_impl.h" | 16 #include "content/browser/frame_host/navigation_entry_impl.h" |
17 #include "content/browser/frame_host/render_frame_host_factory.h" | |
18 #include "content/browser/frame_host/render_frame_host_impl.h" | |
17 #include "content/browser/renderer_host/render_process_host_impl.h" | 19 #include "content/browser/renderer_host/render_process_host_impl.h" |
18 #include "content/browser/renderer_host/render_view_host_factory.h" | 20 #include "content/browser/renderer_host/render_view_host_factory.h" |
19 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
20 #include "content/browser/site_instance_impl.h" | 22 #include "content/browser/site_instance_impl.h" |
21 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 23 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
22 #include "content/browser/webui/web_ui_impl.h" | 24 #include "content/browser/webui/web_ui_impl.h" |
23 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
24 #include "content/port/browser/render_widget_host_view_port.h" | 26 #include "content/port/browser/render_widget_host_view_port.h" |
25 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
26 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
50 transfer_url_chain(transfer_url_chain), | 52 transfer_url_chain(transfer_url_chain), |
51 referrer(referrer), | 53 referrer(referrer), |
52 page_transition(page_transition), | 54 page_transition(page_transition), |
53 frame_id(frame_id), | 55 frame_id(frame_id), |
54 should_replace_current_entry(should_replace_current_entry) { | 56 should_replace_current_entry(should_replace_current_entry) { |
55 } | 57 } |
56 | 58 |
57 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {} | 59 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {} |
58 | 60 |
59 RenderFrameHostManager::RenderFrameHostManager( | 61 RenderFrameHostManager::RenderFrameHostManager( |
62 FrameTreeNode* frame_tree_node, | |
60 RenderFrameHostDelegate* render_frame_delegate, | 63 RenderFrameHostDelegate* render_frame_delegate, |
61 RenderViewHostDelegate* render_view_delegate, | 64 RenderViewHostDelegate* render_view_delegate, |
62 RenderWidgetHostDelegate* render_widget_delegate, | 65 RenderWidgetHostDelegate* render_widget_delegate, |
63 Delegate* delegate) | 66 Delegate* delegate) |
64 : delegate_(delegate), | 67 : frame_tree_node_(frame_tree_node), |
68 delegate_(delegate), | |
65 cross_navigation_pending_(false), | 69 cross_navigation_pending_(false), |
66 render_frame_delegate_(render_frame_delegate), | 70 render_frame_delegate_(render_frame_delegate), |
67 render_view_delegate_(render_view_delegate), | 71 render_view_delegate_(render_view_delegate), |
68 render_widget_delegate_(render_widget_delegate), | 72 render_widget_delegate_(render_widget_delegate), |
69 render_view_host_(NULL), | 73 render_frame_host_(NULL), |
70 pending_render_view_host_(NULL), | 74 pending_render_frame_host_(NULL), |
71 interstitial_page_(NULL) { | 75 interstitial_page_(NULL) { |
72 } | 76 } |
73 | 77 |
74 RenderFrameHostManager::~RenderFrameHostManager() { | 78 RenderFrameHostManager::~RenderFrameHostManager() { |
75 if (pending_render_view_host_) | 79 if (pending_render_frame_host_) |
76 CancelPending(); | 80 CancelPending(); |
77 | 81 |
78 // We should always have a main RenderViewHost except in some tests. | 82 // We should always have a current RenderFrameHost except in some tests. |
79 RenderViewHostImpl* render_view_host = render_view_host_; | 83 // TODO(creis): Now that we aren't using Shutdown, make render_frame_host_ and |
80 render_view_host_ = NULL; | 84 // RenderFrameHostMap use scoped_ptrs. |
81 if (render_view_host) | 85 RenderFrameHostImpl* render_frame_host = render_frame_host_; |
82 render_view_host->Shutdown(); | 86 render_frame_host_ = NULL; |
87 if (render_frame_host) | |
88 delete render_frame_host; | |
83 | 89 |
84 // Shut down any swapped out RenderViewHosts. | 90 // Delete any swapped out RenderFrameHosts. |
85 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 91 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); |
86 iter != swapped_out_hosts_.end(); | 92 iter != swapped_out_hosts_.end(); |
87 ++iter) { | 93 ++iter) { |
88 iter->second->Shutdown(); | 94 delete iter->second; |
89 } | 95 } |
90 } | 96 } |
91 | 97 |
92 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 98 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
93 SiteInstance* site_instance, | 99 SiteInstance* site_instance, |
94 int routing_id, | 100 int view_routing_id, |
95 int main_frame_routing_id) { | 101 int frame_routing_id) { |
96 // Create a RenderViewHost, once we have an instance. It is important to | 102 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It |
97 // immediately give this SiteInstance to a RenderViewHost so that it is | 103 // is important to immediately give this SiteInstance to a RenderViewHost so |
98 // ref counted. | 104 // that the SiteInstance is ref counted. |
99 if (!site_instance) | 105 if (!site_instance) |
100 site_instance = SiteInstance::Create(browser_context); | 106 site_instance = SiteInstance::Create(browser_context); |
101 render_view_host_ = static_cast<RenderViewHostImpl*>( | 107 |
102 RenderViewHostFactory::Create( | 108 // TODO(creis): Make render_frame_host_ a scoped_ptr. |
103 site_instance, render_view_delegate_, render_frame_delegate_, | 109 render_frame_host_ = CreateRenderFrameHost(site_instance, view_routing_id, |
104 render_widget_delegate_, routing_id, main_frame_routing_id, false, | 110 frame_routing_id, false, false); |
105 delegate_->IsHidden())); | |
106 render_view_host_->AttachToFrameTree(); | |
107 | 111 |
108 // Keep track of renderer processes as they start to shut down or are | 112 // Keep track of renderer processes as they start to shut down or are |
109 // crashed/killed. | 113 // crashed/killed. |
110 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 114 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
111 NotificationService::AllSources()); | 115 NotificationService::AllSources()); |
112 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, | 116 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, |
113 NotificationService::AllSources()); | 117 NotificationService::AllSources()); |
114 } | 118 } |
115 | 119 |
116 RenderViewHostImpl* RenderFrameHostManager::current_host() const { | 120 RenderViewHostImpl* RenderFrameHostManager::current_host() const { |
117 return render_view_host_; | 121 if (!render_frame_host_) |
122 return NULL; | |
123 return render_frame_host_->render_view_host(); | |
118 } | 124 } |
119 | 125 |
120 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const { | 126 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const { |
121 return pending_render_view_host_; | 127 if (!pending_render_frame_host_) |
128 return NULL; | |
129 return pending_render_frame_host_->render_view_host(); | |
122 } | 130 } |
123 | 131 |
124 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const { | 132 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const { |
125 if (interstitial_page_) | 133 if (interstitial_page_) |
126 return interstitial_page_->GetView(); | 134 return interstitial_page_->GetView(); |
127 if (!render_view_host_) | 135 if (!render_frame_host_) |
128 return NULL; | 136 return NULL; |
129 return render_view_host_->GetView(); | 137 return render_frame_host_->render_view_host()->GetView(); |
130 } | 138 } |
131 | 139 |
132 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { | 140 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { |
133 pending_web_ui_.reset( | 141 pending_web_ui_.reset( |
134 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | 142 delegate_->CreateWebUIForRenderManager(entry.GetURL())); |
135 pending_and_current_web_ui_.reset(); | 143 pending_and_current_web_ui_.reset(); |
136 | 144 |
137 // If we have assigned (zero or more) bindings to this NavigationEntry in the | 145 // If we have assigned (zero or more) bindings to this NavigationEntry in the |
138 // past, make sure we're not granting it different bindings than it had | 146 // past, make sure we're not granting it different bindings than it had |
139 // before. If so, note it and don't give it any bindings, to avoid a | 147 // before. If so, note it and don't give it any bindings, to avoid a |
140 // potential privilege escalation. | 148 // potential privilege escalation. |
141 if (pending_web_ui_.get() && | 149 if (pending_web_ui_.get() && |
142 entry.bindings() != NavigationEntryImpl::kInvalidBindings && | 150 entry.bindings() != NavigationEntryImpl::kInvalidBindings && |
143 pending_web_ui_->GetBindings() != entry.bindings()) { | 151 pending_web_ui_->GetBindings() != entry.bindings()) { |
144 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | 152 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
145 pending_web_ui_.reset(); | 153 pending_web_ui_.reset(); |
146 } | 154 } |
147 } | 155 } |
148 | 156 |
149 RenderViewHostImpl* RenderFrameHostManager::Navigate( | 157 RenderViewHostImpl* RenderFrameHostManager::Navigate( |
150 const NavigationEntryImpl& entry) { | 158 const NavigationEntryImpl& entry) { |
151 TRACE_EVENT0("browser", "RenderFrameHostManager:Navigate"); | 159 TRACE_EVENT0("browser", "RenderFrameHostManager:Navigate"); |
152 // Create a pending RenderViewHost. It will give us the one we should use | 160 // Create a pending RenderFrameHost to use for the navigation. |
153 RenderViewHostImpl* dest_render_view_host = | 161 RenderFrameHostImpl* dest_render_frame_host = |
154 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); | 162 UpdateRendererStateForNavigate(entry); |
155 if (!dest_render_view_host) | 163 if (!dest_render_frame_host) |
156 return NULL; // We weren't able to create a pending render view host. | 164 return NULL; // We weren't able to create a pending render frame host. |
157 | 165 |
158 // If the current render_view_host_ isn't live, we should create it so | 166 // If the current render_frame_host_ isn't live, we should create it so |
159 // that we don't show a sad tab while the dest_render_view_host fetches | 167 // that we don't show a sad tab while the dest_render_frame_host fetches |
160 // its first page. (Bug 1145340) | 168 // its first page. (Bug 1145340) |
161 if (dest_render_view_host != render_view_host_ && | 169 if (dest_render_frame_host != render_frame_host_ && |
162 !render_view_host_->IsRenderViewLive()) { | 170 !render_frame_host_->render_view_host()->IsRenderViewLive()) { |
163 // Note: we don't call InitRenderView here because we are navigating away | 171 // Note: we don't call InitRenderView here because we are navigating away |
164 // soon anyway, and we don't have the NavigationEntry for this host. | 172 // soon anyway, and we don't have the NavigationEntry for this host. |
165 delegate_->CreateRenderViewForRenderManager(render_view_host_, | 173 delegate_->CreateRenderViewForRenderManager( |
166 MSG_ROUTING_NONE); | 174 render_frame_host_->render_view_host(), MSG_ROUTING_NONE); |
167 } | 175 } |
168 | 176 |
169 // If the renderer crashed, then try to create a new one to satisfy this | 177 // If the renderer crashed, then try to create a new one to satisfy this |
170 // navigation request. | 178 // navigation request. |
171 if (!dest_render_view_host->IsRenderViewLive()) { | 179 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { |
172 // Recreate the opener chain. | 180 // Recreate the opener chain. |
173 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 181 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( |
174 dest_render_view_host->GetSiteInstance()); | 182 dest_render_frame_host->render_view_host()->GetSiteInstance()); |
175 if (!InitRenderView(dest_render_view_host, opener_route_id)) | 183 if (!InitRenderView(dest_render_frame_host->render_view_host(), |
184 opener_route_id)) | |
176 return NULL; | 185 return NULL; |
177 | 186 |
178 // Now that we've created a new renderer, be sure to hide it if it isn't | 187 // Now that we've created a new renderer, be sure to hide it if it isn't |
179 // our primary one. Otherwise, we might crash if we try to call Show() | 188 // our primary one. Otherwise, we might crash if we try to call Show() |
180 // on it later. | 189 // on it later. |
181 if (dest_render_view_host != render_view_host_ && | 190 if (dest_render_frame_host != render_frame_host_ && |
182 dest_render_view_host->GetView()) { | 191 dest_render_frame_host->render_view_host()->GetView()) { |
183 dest_render_view_host->GetView()->Hide(); | 192 dest_render_frame_host->render_view_host()->GetView()->Hide(); |
184 } else { | 193 } else { |
185 // This is our primary renderer, notify here as we won't be calling | 194 // This is our primary renderer, notify here as we won't be calling |
186 // CommitPending (which does the notify). | 195 // CommitPending (which does the notify). |
187 delegate_->NotifySwappedFromRenderManager(NULL, render_view_host_); | 196 delegate_->NotifySwappedFromRenderManager( |
197 NULL, render_frame_host_->render_view_host()); | |
188 } | 198 } |
189 } | 199 } |
190 | 200 |
191 return dest_render_view_host; | 201 // TODO(creis): Return the RFH instead, once we can navigate RFHs. |
202 return dest_render_frame_host->render_view_host(); | |
192 } | 203 } |
193 | 204 |
194 void RenderFrameHostManager::Stop() { | 205 void RenderFrameHostManager::Stop() { |
195 render_view_host_->Stop(); | 206 render_frame_host_->render_view_host()->Stop(); |
196 | 207 |
197 // If we are cross-navigating, we should stop the pending renderers. This | 208 // If we are cross-navigating, we should stop the pending renderers. This |
198 // will lead to a DidFailProvisionalLoad, which will properly destroy them. | 209 // will lead to a DidFailProvisionalLoad, which will properly destroy them. |
199 if (cross_navigation_pending_) { | 210 if (cross_navigation_pending_) { |
200 pending_render_view_host_->Send( | 211 pending_render_frame_host_->render_view_host()->Send(new ViewMsg_Stop( |
201 new ViewMsg_Stop(pending_render_view_host_->GetRoutingID())); | 212 pending_render_frame_host_->render_view_host()->GetRoutingID())); |
202 } | 213 } |
203 } | 214 } |
204 | 215 |
205 void RenderFrameHostManager::SetIsLoading(bool is_loading) { | 216 void RenderFrameHostManager::SetIsLoading(bool is_loading) { |
206 render_view_host_->SetIsLoading(is_loading); | 217 render_frame_host_->render_view_host()->SetIsLoading(is_loading); |
207 if (pending_render_view_host_) | 218 if (pending_render_frame_host_) |
208 pending_render_view_host_->SetIsLoading(is_loading); | 219 pending_render_frame_host_->render_view_host()->SetIsLoading(is_loading); |
209 } | 220 } |
210 | 221 |
211 bool RenderFrameHostManager::ShouldCloseTabOnUnresponsiveRenderer() { | 222 bool RenderFrameHostManager::ShouldCloseTabOnUnresponsiveRenderer() { |
212 if (!cross_navigation_pending_) | 223 if (!cross_navigation_pending_) |
213 return true; | 224 return true; |
214 | 225 |
215 // We should always have a pending RVH when there's a cross-process navigation | 226 // We should always have a pending RFH when there's a cross-process navigation |
216 // in progress. Sanity check this for http://crbug.com/276333. | 227 // in progress. Sanity check this for http://crbug.com/276333. |
217 CHECK(pending_render_view_host_); | 228 CHECK(pending_render_frame_host_); |
218 | 229 |
219 // If the tab becomes unresponsive during {before}unload while doing a | 230 // If the tab becomes unresponsive during {before}unload while doing a |
220 // cross-site navigation, proceed with the navigation. (This assumes that | 231 // cross-site navigation, proceed with the navigation. (This assumes that |
221 // the pending RenderViewHost is still responsive.) | 232 // the pending RenderFrameHost is still responsive.) |
222 if (render_view_host_->is_waiting_for_unload_ack()) { | 233 if (render_frame_host_->render_view_host()->is_waiting_for_unload_ack()) { |
223 // The request has been started and paused while we're waiting for the | 234 // The request has been started and paused while we're waiting for the |
224 // unload handler to finish. We'll pretend that it did. The pending | 235 // unload handler to finish. We'll pretend that it did. The pending |
225 // renderer will then be swapped in as part of the usual DidNavigate logic. | 236 // renderer will then be swapped in as part of the usual DidNavigate logic. |
226 // (If the unload handler later finishes, this call will be ignored because | 237 // (If the unload handler later finishes, this call will be ignored because |
227 // the pending_nav_params_ state will already be cleaned up.) | 238 // the pending_nav_params_ state will already be cleaned up.) |
228 current_host()->OnSwappedOut(true); | 239 current_host()->OnSwappedOut(true); |
229 } else if (render_view_host_->is_waiting_for_beforeunload_ack()) { | 240 } else if (render_frame_host_->render_view_host()-> |
241 is_waiting_for_beforeunload_ack()) { | |
230 // Haven't gotten around to starting the request, because we're still | 242 // Haven't gotten around to starting the request, because we're still |
231 // waiting for the beforeunload handler to finish. We'll pretend that it | 243 // waiting for the beforeunload handler to finish. We'll pretend that it |
232 // did finish, to let the navigation proceed. Note that there's a danger | 244 // did finish, to let the navigation proceed. Note that there's a danger |
233 // that the beforeunload handler will later finish and possibly return | 245 // that the beforeunload handler will later finish and possibly return |
234 // false (meaning the navigation should not proceed), but we'll ignore it | 246 // false (meaning the navigation should not proceed), but we'll ignore it |
235 // in this case because it took too long. | 247 // in this case because it took too long. |
236 if (pending_render_view_host_->are_navigations_suspended()) | 248 if (pending_render_frame_host_->render_view_host()-> |
237 pending_render_view_host_->SetNavigationsSuspended( | 249 are_navigations_suspended()) { |
250 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended( | |
238 false, base::TimeTicks::Now()); | 251 false, base::TimeTicks::Now()); |
252 } | |
239 } | 253 } |
240 return false; | 254 return false; |
241 } | 255 } |
242 | 256 |
257 // TODO(creis): This should take in a RenderFrameHost. | |
243 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) { | 258 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) { |
244 // Make sure this is from our current RVH, and that we have a pending | 259 // Make sure this is from our current RVH, and that we have a pending |
245 // navigation from OnCrossSiteResponse. (There may be no pending navigation | 260 // navigation from OnCrossSiteResponse. (There may be no pending navigation |
246 // for data URLs that don't make network requests, for example.) If not, | 261 // for data URLs that don't make network requests, for example.) If not, |
247 // just return early and ignore. | 262 // just return early and ignore. |
248 if (render_view_host != render_view_host_ || !pending_nav_params_.get()) { | 263 if (render_view_host != render_frame_host_->render_view_host() || |
264 !pending_nav_params_.get()) { | |
249 pending_nav_params_.reset(); | 265 pending_nav_params_.reset(); |
250 return; | 266 return; |
251 } | 267 } |
252 | 268 |
253 // Now that the unload handler has run, we need to either initiate the | 269 // Now that the unload handler has run, we need to either initiate the |
254 // pending transfer (if there is one) or resume the paused response (if not). | 270 // pending transfer (if there is one) or resume the paused response (if not). |
255 // TODO(creis): The blank swapped out page is visible during this time, but | 271 // TODO(creis): The blank swapped out page is visible during this time, but |
256 // we can shorten this by delivering the response directly, rather than | 272 // we can shorten this by delivering the response directly, rather than |
257 // forcing an identical request to be made. | 273 // forcing an identical request to be made. |
258 if (pending_nav_params_->is_transfer) { | 274 if (pending_nav_params_->is_transfer) { |
259 // Treat the last URL in the chain as the destination and the remainder as | 275 // Treat the last URL in the chain as the destination and the remainder as |
260 // the redirect chain. | 276 // the redirect chain. |
261 CHECK(pending_nav_params_->transfer_url_chain.size()); | 277 CHECK(pending_nav_params_->transfer_url_chain.size()); |
262 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); | 278 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); |
263 pending_nav_params_->transfer_url_chain.pop_back(); | 279 pending_nav_params_->transfer_url_chain.pop_back(); |
264 | 280 |
265 // We don't know whether the original request had |user_action| set to true. | 281 // We don't know whether the original request had |user_action| set to true. |
266 // However, since we force the navigation to be in the current tab, it | 282 // However, since we force the navigation to be in the current tab, it |
267 // doesn't matter. | 283 // doesn't matter. |
268 render_view_host->GetDelegate()->RequestTransferURL( | 284 render_view_host->GetDelegate()->RequestTransferURL( |
269 transfer_url, | 285 transfer_url, |
270 pending_nav_params_->transfer_url_chain, | 286 pending_nav_params_->transfer_url_chain, |
271 pending_nav_params_->referrer, | 287 pending_nav_params_->referrer, |
272 pending_nav_params_->page_transition, | 288 pending_nav_params_->page_transition, |
273 CURRENT_TAB, | 289 CURRENT_TAB, |
274 pending_nav_params_->frame_id, | 290 pending_nav_params_->frame_id, |
275 pending_nav_params_->global_request_id, | 291 pending_nav_params_->global_request_id, |
276 pending_nav_params_->should_replace_current_entry, | 292 pending_nav_params_->should_replace_current_entry, |
277 true); | 293 true); |
278 } else if (pending_render_view_host_) { | 294 } else if (pending_render_frame_host_) { |
279 RenderProcessHostImpl* pending_process = | 295 RenderProcessHostImpl* pending_process = |
280 static_cast<RenderProcessHostImpl*>( | 296 static_cast<RenderProcessHostImpl*>( |
281 pending_render_view_host_->GetProcess()); | 297 pending_render_frame_host_->GetProcess()); |
282 pending_process->ResumeDeferredNavigation( | 298 pending_process->ResumeDeferredNavigation( |
283 pending_nav_params_->global_request_id); | 299 pending_nav_params_->global_request_id); |
284 } | 300 } |
285 pending_nav_params_.reset(); | 301 pending_nav_params_.reset(); |
286 } | 302 } |
287 | 303 |
304 // TODO(creis): This should take in a RenderFrameHost. | |
288 void RenderFrameHostManager::DidNavigateMainFrame( | 305 void RenderFrameHostManager::DidNavigateMainFrame( |
289 RenderViewHost* render_view_host) { | 306 RenderViewHost* render_view_host) { |
290 if (!cross_navigation_pending_) { | 307 if (!cross_navigation_pending_) { |
291 DCHECK(!pending_render_view_host_); | 308 DCHECK(!pending_render_frame_host_); |
292 | 309 |
293 // We should only hear this from our current renderer. | 310 // We should only hear this from our current renderer. |
294 DCHECK(render_view_host == render_view_host_); | 311 DCHECK(render_view_host == render_frame_host_->render_view_host()); |
295 | 312 |
296 // Even when there is no pending RVH, there may be a pending Web UI. | 313 // Even when there is no pending RVH, there may be a pending Web UI. |
297 if (pending_web_ui()) | 314 if (pending_web_ui()) |
298 CommitPending(); | 315 CommitPending(); |
299 return; | 316 return; |
300 } | 317 } |
301 | 318 |
302 if (render_view_host == pending_render_view_host_) { | 319 if (render_view_host == pending_render_frame_host_->render_view_host()) { |
303 // The pending cross-site navigation completed, so show the renderer. | 320 // The pending cross-site navigation completed, so show the renderer. |
304 // If it committed without sending network requests (e.g., data URLs), | 321 // If it committed without sending network requests (e.g., data URLs), |
305 // then we still need to swap out the old RVH first and run its unload | 322 // then we still need to swap out the old RFH first and run its unload |
306 // handler. OK for that to happen in the background. | 323 // handler. OK for that to happen in the background. |
307 if (pending_render_view_host_->HasPendingCrossSiteRequest()) | 324 if (pending_render_frame_host_->render_view_host()-> |
325 HasPendingCrossSiteRequest()) | |
308 SwapOutOldPage(); | 326 SwapOutOldPage(); |
309 | 327 |
310 CommitPending(); | 328 CommitPending(); |
311 cross_navigation_pending_ = false; | 329 cross_navigation_pending_ = false; |
312 } else if (render_view_host == render_view_host_) { | 330 } else if (render_view_host == render_frame_host_->render_view_host()) { |
313 // A navigation in the original page has taken place. Cancel the pending | 331 // A navigation in the original page has taken place. Cancel the pending |
314 // one. | 332 // one. |
315 CancelPending(); | 333 CancelPending(); |
316 cross_navigation_pending_ = false; | 334 cross_navigation_pending_ = false; |
317 } else { | 335 } else { |
318 // No one else should be sending us DidNavigate in this state. | 336 // No one else should be sending us DidNavigate in this state. |
319 DCHECK(false); | 337 DCHECK(false); |
320 } | 338 } |
321 } | 339 } |
322 | 340 |
341 // TODO(creis): Take in RenderFrameHost instead, since frames can have openers. | |
323 void RenderFrameHostManager::DidDisownOpener(RenderViewHost* render_view_host) { | 342 void RenderFrameHostManager::DidDisownOpener(RenderViewHost* render_view_host) { |
324 // Notify all swapped out hosts, including the pending RVH. | 343 // Notify all swapped out hosts, including the pending RVH. |
325 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 344 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); |
326 iter != swapped_out_hosts_.end(); | 345 iter != swapped_out_hosts_.end(); |
327 ++iter) { | 346 ++iter) { |
328 DCHECK_NE(iter->second->GetSiteInstance(), | 347 DCHECK_NE(iter->second->render_view_host()->GetSiteInstance(), |
329 current_host()->GetSiteInstance()); | 348 current_host()->GetSiteInstance()); |
330 iter->second->DisownOpener(); | 349 iter->second->render_view_host()->DisownOpener(); |
nasko
2013/12/13 22:20:11
Since there are multiple frames that reference the
Charlie Reis
2013/12/16 16:13:55
I think we do want to loop here. swapped_out_host
| |
331 } | 350 } |
332 } | 351 } |
333 | 352 |
334 void RenderFrameHostManager::RendererAbortedProvisionalLoad( | 353 void RenderFrameHostManager::RendererAbortedProvisionalLoad( |
335 RenderViewHost* render_view_host) { | 354 RenderViewHost* render_view_host) { |
336 // We used to cancel the pending renderer here for cross-site downloads. | 355 // We used to cancel the pending renderer here for cross-site downloads. |
337 // However, it's not safe to do that because the download logic repeatedly | 356 // However, it's not safe to do that because the download logic repeatedly |
338 // looks for this WebContents based on a render view ID. Instead, we just | 357 // looks for this WebContents based on a render view ID. Instead, we just |
339 // leave the pending renderer around until the next navigation event | 358 // leave the pending renderer around until the next navigation event |
340 // (Navigate, DidNavigate, etc), which will clean it up properly. | 359 // (Navigate, DidNavigate, etc), which will clean it up properly. |
341 // TODO(creis): All of this will go away when we move the cross-site logic | 360 // TODO(creis): All of this will go away when we move the cross-site logic |
342 // to ResourceDispatcherHost, so that we intercept responses rather than | 361 // to ResourceDispatcherHost, so that we intercept responses rather than |
343 // navigation events. (That's necessary to support onunload anyway.) Once | 362 // navigation events. (That's necessary to support onunload anyway.) Once |
344 // we've made that change, we won't create a pending renderer until we know | 363 // we've made that change, we won't create a pending renderer until we know |
345 // the response is not a download. | 364 // the response is not a download. |
346 } | 365 } |
347 | 366 |
348 void RenderFrameHostManager::RendererProcessClosing( | 367 void RenderFrameHostManager::RendererProcessClosing( |
349 RenderProcessHost* render_process_host) { | 368 RenderProcessHost* render_process_host) { |
350 // Remove any swapped out RVHs from this process, so that we don't try to | 369 // Remove any swapped out RVHs from this process, so that we don't try to |
351 // swap them back in while the process is exiting. Start by finding them, | 370 // swap them back in while the process is exiting. Start by finding them, |
352 // since there could be more than one. | 371 // since there could be more than one. |
353 std::list<int> ids_to_remove; | 372 std::list<int> ids_to_remove; |
354 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 373 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); |
355 iter != swapped_out_hosts_.end(); | 374 iter != swapped_out_hosts_.end(); |
356 ++iter) { | 375 ++iter) { |
357 if (iter->second->GetProcess() == render_process_host) | 376 if (iter->second->GetProcess() == render_process_host) |
358 ids_to_remove.push_back(iter->first); | 377 ids_to_remove.push_back(iter->first); |
359 } | 378 } |
360 | 379 |
361 // Now delete them. | 380 // Now delete them. |
362 while (!ids_to_remove.empty()) { | 381 while (!ids_to_remove.empty()) { |
363 swapped_out_hosts_[ids_to_remove.back()]->Shutdown(); | 382 delete swapped_out_hosts_[ids_to_remove.back()]; |
364 swapped_out_hosts_.erase(ids_to_remove.back()); | 383 swapped_out_hosts_.erase(ids_to_remove.back()); |
365 ids_to_remove.pop_back(); | 384 ids_to_remove.pop_back(); |
366 } | 385 } |
367 } | 386 } |
368 | 387 |
369 void RenderFrameHostManager::ShouldClosePage( | 388 void RenderFrameHostManager::ShouldClosePage( |
370 bool for_cross_site_transition, | 389 bool for_cross_site_transition, |
371 bool proceed, | 390 bool proceed, |
372 const base::TimeTicks& proceed_time) { | 391 const base::TimeTicks& proceed_time) { |
373 if (for_cross_site_transition) { | 392 if (for_cross_site_transition) { |
374 // Ignore if we're not in a cross-site navigation. | 393 // Ignore if we're not in a cross-site navigation. |
375 if (!cross_navigation_pending_) | 394 if (!cross_navigation_pending_) |
376 return; | 395 return; |
377 | 396 |
378 if (proceed) { | 397 if (proceed) { |
379 // Ok to unload the current page, so proceed with the cross-site | 398 // Ok to unload the current page, so proceed with the cross-site |
380 // navigation. Note that if navigations are not currently suspended, it | 399 // navigation. Note that if navigations are not currently suspended, it |
381 // might be because the renderer was deemed unresponsive and this call was | 400 // might be because the renderer was deemed unresponsive and this call was |
382 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it | 401 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it |
383 // is ok to do nothing here. | 402 // is ok to do nothing here. |
384 if (pending_render_view_host_ && | 403 if (pending_render_frame_host_ && |
385 pending_render_view_host_->are_navigations_suspended()) { | 404 pending_render_frame_host_->render_view_host()-> |
386 pending_render_view_host_->SetNavigationsSuspended(false, proceed_time); | 405 are_navigations_suspended()) { |
406 pending_render_frame_host_->render_view_host()-> | |
407 SetNavigationsSuspended(false, proceed_time); | |
387 } | 408 } |
388 } else { | 409 } else { |
389 // Current page says to cancel. | 410 // Current page says to cancel. |
390 CancelPending(); | 411 CancelPending(); |
391 cross_navigation_pending_ = false; | 412 cross_navigation_pending_ = false; |
392 } | 413 } |
393 } else { | 414 } else { |
394 // Non-cross site transition means closing the entire tab. | 415 // Non-cross site transition means closing the entire tab. |
395 bool proceed_to_fire_unload; | 416 bool proceed_to_fire_unload; |
396 delegate_->BeforeUnloadFiredFromRenderManager(proceed, proceed_time, | 417 delegate_->BeforeUnloadFiredFromRenderManager(proceed, proceed_time, |
397 &proceed_to_fire_unload); | 418 &proceed_to_fire_unload); |
398 | 419 |
399 if (proceed_to_fire_unload) { | 420 if (proceed_to_fire_unload) { |
400 // If we're about to close the tab and there's a pending RVH, cancel it. | 421 // If we're about to close the tab and there's a pending RFH, cancel it. |
401 // Otherwise, if the navigation in the pending RVH completes before the | 422 // Otherwise, if the navigation in the pending RFH completes before the |
402 // close in the current RVH, we'll lose the tab close. | 423 // close in the current RFH, we'll lose the tab close. |
403 if (pending_render_view_host_) { | 424 if (pending_render_frame_host_) { |
404 CancelPending(); | 425 CancelPending(); |
405 cross_navigation_pending_ = false; | 426 cross_navigation_pending_ = false; |
406 } | 427 } |
407 | 428 |
408 // This is not a cross-site navigation, the tab is being closed. | 429 // This is not a cross-site navigation, the tab is being closed. |
409 render_view_host_->ClosePage(); | 430 render_frame_host_->render_view_host()->ClosePage(); |
410 } | 431 } |
411 } | 432 } |
412 } | 433 } |
413 | 434 |
435 // TODO(creis): Take in a RenderFrameHost from CSRH. | |
414 void RenderFrameHostManager::OnCrossSiteResponse( | 436 void RenderFrameHostManager::OnCrossSiteResponse( |
415 RenderViewHost* pending_render_view_host, | 437 RenderViewHost* pending_render_view_host, |
416 const GlobalRequestID& global_request_id, | 438 const GlobalRequestID& global_request_id, |
417 bool is_transfer, | 439 bool is_transfer, |
418 const std::vector<GURL>& transfer_url_chain, | 440 const std::vector<GURL>& transfer_url_chain, |
419 const Referrer& referrer, | 441 const Referrer& referrer, |
420 PageTransition page_transition, | 442 PageTransition page_transition, |
421 int64 frame_id, | 443 int64 frame_id, |
422 bool should_replace_current_entry) { | 444 bool should_replace_current_entry) { |
423 // This should be called either when the pending RVH is ready to commit or | 445 // This should be called either when the pending RVH is ready to commit or |
424 // when we realize that the current RVH's request requires a transfer. | 446 // when we realize that the current RVH's request requires a transfer. |
425 DCHECK( | 447 DCHECK(pending_render_view_host == render_frame_host_->render_view_host() || |
426 pending_render_view_host == pending_render_view_host_ || | 448 pending_render_view_host == |
427 pending_render_view_host == render_view_host_); | 449 pending_render_frame_host_->render_view_host()); |
428 | 450 |
429 // TODO(creis): Eventually we will want to check all navigation responses | 451 // TODO(creis): Eventually we will want to check all navigation responses |
430 // here, but currently we pass information for a transfer if | 452 // here, but currently we pass information for a transfer if |
431 // ShouldSwapProcessesForRedirect returned true in the network stack. | 453 // ShouldSwapProcessesForRedirect returned true in the network stack. |
432 // In that case, we should set up a transfer after the unload handler runs. | 454 // In that case, we should set up a transfer after the unload handler runs. |
433 // If is_transfer is false, we will just run the unload handler and resume. | 455 // If is_transfer is false, we will just run the unload handler and resume. |
434 pending_nav_params_.reset(new PendingNavigationParams( | 456 pending_nav_params_.reset(new PendingNavigationParams( |
435 global_request_id, is_transfer, transfer_url_chain, referrer, | 457 global_request_id, is_transfer, transfer_url_chain, referrer, |
436 page_transition, frame_id, should_replace_current_entry)); | 458 page_transition, frame_id, should_replace_current_entry)); |
437 | 459 |
438 // Run the unload handler of the current page. | 460 // Run the unload handler of the current page. |
439 SwapOutOldPage(); | 461 SwapOutOldPage(); |
440 } | 462 } |
441 | 463 |
442 void RenderFrameHostManager::SwapOutOldPage() { | 464 void RenderFrameHostManager::SwapOutOldPage() { |
443 // Should only see this while we have a pending renderer or transfer. | 465 // Should only see this while we have a pending renderer or transfer. |
444 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); | 466 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); |
445 | 467 |
446 // Tell the renderer to suppress any further modal dialogs so that we can swap | 468 // Tell the renderer to suppress any further modal dialogs so that we can swap |
447 // it out. This must be done before canceling any current dialog, in case | 469 // it out. This must be done before canceling any current dialog, in case |
448 // there is a loop creating additional dialogs. | 470 // there is a loop creating additional dialogs. |
449 render_view_host_->SuppressDialogsUntilSwapOut(); | 471 render_frame_host_->render_view_host()->SuppressDialogsUntilSwapOut(); |
450 | 472 |
451 // Now close any modal dialogs that would prevent us from swapping out. This | 473 // Now close any modal dialogs that would prevent us from swapping out. This |
452 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is | 474 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is |
453 // no longer on the stack when we send the SwapOut message. | 475 // no longer on the stack when we send the SwapOut message. |
454 delegate_->CancelModalDialogsForRenderManager(); | 476 delegate_->CancelModalDialogsForRenderManager(); |
455 | 477 |
456 // Tell the old renderer it is being swapped out. This will fire the unload | 478 // Tell the old renderer it is being swapped out. This will fire the unload |
457 // handler (without firing the beforeunload handler a second time). When the | 479 // handler (without firing the beforeunload handler a second time). When the |
458 // unload handler finishes and the navigation completes, we will send a | 480 // unload handler finishes and the navigation completes, we will send a |
459 // message to the ResourceDispatcherHost, allowing the pending RVH's response | 481 // message to the ResourceDispatcherHost, allowing the pending RVH's response |
460 // to resume. | 482 // to resume. |
461 render_view_host_->SwapOut(); | 483 // TODO(creis): This must be done on the RFH or else we'll swap out the |
nasko
2013/12/13 22:20:11
This comment is confusing. If this must be done on
Charlie Reis
2013/12/16 16:13:55
Rephrased. Let me know if it's still unclear.
| |
484 // top-level page. | |
485 render_frame_host_->render_view_host()->SwapOut(); | |
462 | 486 |
463 // ResourceDispatcherHost has told us to run the onunload handler, which | 487 // ResourceDispatcherHost has told us to run the onunload handler, which |
464 // means it is not a download or unsafe page, and we are going to perform the | 488 // means it is not a download or unsafe page, and we are going to perform the |
465 // navigation. Thus, we no longer need to remember that the RenderViewHost | 489 // navigation. Thus, we no longer need to remember that the RenderViewHost |
466 // is part of a pending cross-site request. | 490 // is part of a pending cross-site request. |
467 if (pending_render_view_host_) | 491 if (pending_render_frame_host_) { |
468 pending_render_view_host_->SetHasPendingCrossSiteRequest(false); | 492 pending_render_frame_host_->render_view_host()-> |
493 SetHasPendingCrossSiteRequest(false); | |
494 } | |
469 } | 495 } |
470 | 496 |
471 void RenderFrameHostManager::Observe( | 497 void RenderFrameHostManager::Observe( |
472 int type, | 498 int type, |
473 const NotificationSource& source, | 499 const NotificationSource& source, |
474 const NotificationDetails& details) { | 500 const NotificationDetails& details) { |
475 switch (type) { | 501 switch (type) { |
476 case NOTIFICATION_RENDERER_PROCESS_CLOSED: | 502 case NOTIFICATION_RENDERER_PROCESS_CLOSED: |
477 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 503 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
478 RendererProcessClosing( | 504 RendererProcessClosing( |
479 Source<RenderProcessHost>(source).ptr()); | 505 Source<RenderProcessHost>(source).ptr()); |
480 break; | 506 break; |
481 | 507 |
482 default: | 508 default: |
483 NOTREACHED(); | 509 NOTREACHED(); |
484 } | 510 } |
485 } | 511 } |
486 | 512 |
513 bool RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance( | |
514 int32 site_instance_id, | |
515 FrameTreeNode* node) { | |
516 RenderFrameHostMap::iterator iter = | |
517 node->render_manager()->swapped_out_hosts_.find(site_instance_id); | |
518 if (iter != node->render_manager()->swapped_out_hosts_.end()) | |
519 delete iter->second; | |
520 | |
521 return true; | |
522 } | |
523 | |
487 bool RenderFrameHostManager::ShouldTransitionCrossSite() { | 524 bool RenderFrameHostManager::ShouldTransitionCrossSite() { |
488 // False in the single-process mode, as it makes RVHs to accumulate | 525 // False in the single-process mode, as it makes RVHs to accumulate |
489 // in swapped_out_hosts_. | 526 // in swapped_out_hosts_. |
490 // True if we are using process-per-site-instance (default) or | 527 // True if we are using process-per-site-instance (default) or |
491 // process-per-site (kProcessPerSite). | 528 // process-per-site (kProcessPerSite). |
492 return | 529 return |
493 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && | 530 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && |
494 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); | 531 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); |
495 } | 532 } |
496 | 533 |
(...skipping 12 matching lines...) Expand all Loading... | |
509 | 546 |
510 // We use the effective URL here, since that's what is used in the | 547 // We use the effective URL here, since that's what is used in the |
511 // SiteInstance's site and when we later call IsSameWebSite. If there is no | 548 // SiteInstance's site and when we later call IsSameWebSite. If there is no |
512 // current_entry, check the current SiteInstance's site, which might already | 549 // current_entry, check the current SiteInstance's site, which might already |
513 // be committed to a Web UI URL (such as the NTP). | 550 // be committed to a Web UI URL (such as the NTP). |
514 BrowserContext* browser_context = | 551 BrowserContext* browser_context = |
515 delegate_->GetControllerForRenderManager().GetBrowserContext(); | 552 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
516 const GURL& current_url = (current_entry) ? | 553 const GURL& current_url = (current_entry) ? |
517 SiteInstanceImpl::GetEffectiveURL(browser_context, | 554 SiteInstanceImpl::GetEffectiveURL(browser_context, |
518 current_entry->GetURL()) : | 555 current_entry->GetURL()) : |
519 render_view_host_->GetSiteInstance()->GetSiteURL(); | 556 render_frame_host_->render_view_host()->GetSiteInstance()->GetSiteURL(); |
520 const GURL& new_url = SiteInstanceImpl::GetEffectiveURL(browser_context, | 557 const GURL& new_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
521 new_entry->GetURL()); | 558 new_entry->GetURL()); |
522 | 559 |
523 // For security, we should transition between processes when one is a Web UI | 560 // For security, we should transition between processes when one is a Web UI |
524 // page and one isn't. | 561 // page and one isn't. |
525 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 562 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
526 browser_context, current_url)) { | 563 browser_context, current_url)) { |
527 // If so, force a swap if destination is not an acceptable URL for Web UI. | 564 // If so, force a swap if destination is not an acceptable URL for Web UI. |
528 // Here, data URLs are never allowed. | 565 // Here, data URLs are never allowed. |
529 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 566 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
530 browser_context, new_url, false)) { | 567 browser_context, new_url, false)) { |
531 return true; | 568 return true; |
532 } | 569 } |
533 } else { | 570 } else { |
534 // Force a swap if it's a Web UI URL. | 571 // Force a swap if it's a Web UI URL. |
535 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 572 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
536 browser_context, new_url)) { | 573 browser_context, new_url)) { |
537 return true; | 574 return true; |
538 } | 575 } |
539 } | 576 } |
540 | 577 |
541 // Check with the content client as well. Important to pass current_url here, | 578 // Check with the content client as well. Important to pass current_url here, |
542 // which uses the SiteInstance's site if there is no current_entry. | 579 // which uses the SiteInstance's site if there is no current_entry. |
543 if (GetContentClient()->browser()->ShouldSwapBrowsingInstancesForNavigation( | 580 if (GetContentClient()->browser()->ShouldSwapBrowsingInstancesForNavigation( |
544 render_view_host_->GetSiteInstance(), current_url, new_url)) { | 581 render_frame_host_->render_view_host()->GetSiteInstance(), |
582 current_url, new_url)) { | |
545 return true; | 583 return true; |
546 } | 584 } |
547 | 585 |
548 // We can't switch a RenderView between view source and non-view source mode | 586 // We can't switch a RenderView between view source and non-view source mode |
549 // without screwing up the session history sometimes (when navigating between | 587 // without screwing up the session history sometimes (when navigating between |
550 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat | 588 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat |
551 // it as a new navigation). So require a BrowsingInstance switch. | 589 // it as a new navigation). So require a BrowsingInstance switch. |
552 if (current_entry && | 590 if (current_entry && |
553 current_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) | 591 current_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) |
554 return true; | 592 return true; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 } | 752 } |
715 | 753 |
716 // Start the new renderer in a new SiteInstance, but in the current | 754 // Start the new renderer in a new SiteInstance, but in the current |
717 // BrowsingInstance. It is important to immediately give this new | 755 // BrowsingInstance. It is important to immediately give this new |
718 // SiteInstance to a RenderViewHost (if it is different than our current | 756 // SiteInstance to a RenderViewHost (if it is different than our current |
719 // SiteInstance), so that it is ref counted. This will happen in | 757 // SiteInstance), so that it is ref counted. This will happen in |
720 // CreateRenderView. | 758 // CreateRenderView. |
721 return current_instance->GetRelatedSiteInstance(dest_url); | 759 return current_instance->GetRelatedSiteInstance(dest_url); |
722 } | 760 } |
723 | 761 |
724 int RenderFrameHostManager::CreateRenderView( | 762 RenderFrameHostImpl* RenderFrameHostManager::CreateRenderFrameHost( |
763 SiteInstance* site_instance, | |
764 int view_routing_id, | |
765 int frame_routing_id, | |
766 bool swapped_out, | |
767 bool hidden) { | |
768 if (frame_routing_id == MSG_ROUTING_NONE) | |
769 frame_routing_id = site_instance->GetProcess()->GetNextRoutingID(); | |
770 | |
771 // Create a RVH for main frames, or find the existing one for subframes. | |
772 FrameTree* frame_tree = frame_tree_node_->frame_tree(); | |
773 RenderViewHostImpl* render_view_host = frame_tree_node_->IsMainFrame() ? | |
nasko
2013/12/13 22:20:11
nit: Using tertiary operator across that many line
Charlie Reis
2013/12/16 16:13:55
Yeah, I was trying to avoid initializing it to NUL
| |
774 frame_tree->CreateRenderViewHostForMainFrame(site_instance, | |
775 view_routing_id, | |
776 frame_routing_id, | |
777 swapped_out, | |
778 hidden) : | |
779 frame_tree->GetRenderViewHostForSubFrame(site_instance); | |
780 | |
781 // TODO(creis): Make render_frame_host a scoped_ptr. | |
782 // TODO(creis): Pass hidden to RFH. | |
783 RenderFrameHostImpl* render_frame_host = | |
784 RenderFrameHostFactory::Create(render_view_host, | |
785 render_frame_delegate_, | |
786 frame_tree, | |
787 frame_tree_node_, | |
788 frame_routing_id, | |
789 swapped_out).release(); | |
790 return render_frame_host; | |
791 } | |
792 | |
793 int RenderFrameHostManager::CreateRenderFrame( | |
725 SiteInstance* instance, | 794 SiteInstance* instance, |
726 int opener_route_id, | 795 int opener_route_id, |
727 bool swapped_out, | 796 bool swapped_out, |
728 bool hidden) { | 797 bool hidden) { |
729 CHECK(instance); | 798 CHECK(instance); |
730 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. | 799 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. |
731 | 800 |
732 // We are creating a pending or swapped out RVH here. We should never create | 801 // We are creating a pending or swapped out RFH here. We should never create |
733 // it in the same SiteInstance as our current RVH. | 802 // it in the same SiteInstance as our current RFH. |
734 CHECK_NE(render_view_host_->GetSiteInstance(), instance); | 803 CHECK_NE(render_frame_host_->render_view_host()->GetSiteInstance(), instance); |
735 | 804 |
736 // Check if we've already created an RVH for this SiteInstance. If so, try | 805 // Check if we've already created an RFH for this SiteInstance. If so, try |
737 // to re-use the existing one, which has already been initialized. We'll | 806 // to re-use the existing one, which has already been initialized. We'll |
738 // remove it from the list of swapped out hosts if it commits. | 807 // remove it from the list of swapped out hosts if it commits. |
739 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( | 808 RenderFrameHostImpl* new_render_frame_host = |
740 GetSwappedOutRenderViewHost(instance)); | 809 GetSwappedOutRenderFrameHost(instance); |
741 if (new_render_view_host) { | 810 if (new_render_frame_host) { |
742 // Prevent the process from exiting while we're trying to use it. | 811 // Prevent the process from exiting while we're trying to use it. |
743 if (!swapped_out) | 812 if (!swapped_out) |
744 new_render_view_host->GetProcess()->AddPendingView(); | 813 new_render_frame_host->GetProcess()->AddPendingView(); |
745 } else { | 814 } else { |
746 // Create a new RenderViewHost if we don't find an existing one. | 815 // Create a new RenderFrameHost if we don't find an existing one. |
747 new_render_view_host = static_cast<RenderViewHostImpl*>( | 816 // TODO(creis): Make new_render_frame_host a scoped_ptr. |
748 RenderViewHostFactory::Create(instance, | 817 new_render_frame_host = CreateRenderFrameHost(instance, MSG_ROUTING_NONE, |
749 render_view_delegate_, | 818 MSG_ROUTING_NONE, swapped_out, |
750 render_frame_delegate_, | 819 hidden); |
751 render_widget_delegate_, | |
752 MSG_ROUTING_NONE, | |
753 MSG_ROUTING_NONE, | |
754 swapped_out, | |
755 hidden)); | |
756 | 820 |
757 // If the new RVH is swapped out already, store it. Otherwise prevent the | 821 // If the new RFH is swapped out already, store it. Otherwise prevent the |
758 // process from exiting while we're trying to navigate in it. | 822 // process from exiting while we're trying to navigate in it. |
759 if (swapped_out) { | 823 if (swapped_out) { |
760 swapped_out_hosts_[instance->GetId()] = new_render_view_host; | 824 swapped_out_hosts_[instance->GetId()] = new_render_frame_host; |
761 } else { | 825 } else { |
762 new_render_view_host->GetProcess()->AddPendingView(); | 826 new_render_frame_host->GetProcess()->AddPendingView(); |
763 } | 827 } |
764 | 828 |
765 bool success = InitRenderView(new_render_view_host, opener_route_id); | 829 RenderViewHostImpl* render_view_host = |
830 new_render_frame_host->render_view_host(); | |
831 bool success = InitRenderView(render_view_host, opener_route_id); | |
766 if (success) { | 832 if (success) { |
767 // Don't show the view until we get a DidNavigate from it. | 833 // Don't show the view until we get a DidNavigate from it. |
768 new_render_view_host->GetView()->Hide(); | 834 render_view_host->GetView()->Hide(); |
nasko
2013/12/13 22:20:11
Could this cause the RVH shared by several RFHs to
Charlie Reis
2013/12/16 16:13:55
Huh. We're not having trouble with that in the dr
| |
769 } else if (!swapped_out) { | 835 } else if (!swapped_out) { |
770 CancelPending(); | 836 CancelPending(); |
771 } | 837 } |
772 } | 838 } |
773 | 839 |
774 // Use this as our new pending RVH if it isn't swapped out. | 840 // Use this as our new pending RFH if it isn't swapped out. |
775 if (!swapped_out) | 841 if (!swapped_out) |
776 pending_render_view_host_ = new_render_view_host; | 842 pending_render_frame_host_ = new_render_frame_host; |
777 | 843 |
778 return new_render_view_host->GetRoutingID(); | 844 return new_render_frame_host->render_view_host()->GetRoutingID(); |
779 } | 845 } |
780 | 846 |
781 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, | 847 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, |
782 int opener_route_id) { | 848 int opener_route_id) { |
849 // We may have initialized this RenderViewHost for another RenderFrameHost. | |
850 if (render_view_host->IsRenderViewLive()) | |
851 return true; | |
852 | |
783 // If the pending navigation is to a WebUI and the RenderView is not in a | 853 // If the pending navigation is to a WebUI and the RenderView is not in a |
784 // guest process, tell the RenderView about any bindings it will need enabled. | 854 // guest process, tell the RenderViewHost about any bindings it will need |
855 // enabled. | |
785 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { | 856 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { |
786 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); | 857 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); |
787 } else { | 858 } else { |
788 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 859 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
789 // process unless it's swapped out. | 860 // process unless it's swapped out. |
790 RenderViewHostImpl* rvh_impl = | 861 RenderViewHostImpl* rvh_impl = |
791 static_cast<RenderViewHostImpl*>(render_view_host); | 862 static_cast<RenderViewHostImpl*>(render_view_host); |
792 if (!rvh_impl->is_swapped_out()) { | 863 if (!rvh_impl->is_swapped_out()) { |
793 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 864 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
794 render_view_host->GetProcess()->GetID())); | 865 render_view_host->GetProcess()->GetID())); |
(...skipping 20 matching lines...) Expand all Loading... | |
815 | 886 |
816 // Next commit the Web UI, if any. Either replace |web_ui_| with | 887 // Next commit the Web UI, if any. Either replace |web_ui_| with |
817 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or | 888 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or |
818 // leave |web_ui_| as is if reusing it. | 889 // leave |web_ui_| as is if reusing it. |
819 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); | 890 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); |
820 if (pending_web_ui_) | 891 if (pending_web_ui_) |
821 web_ui_.reset(pending_web_ui_.release()); | 892 web_ui_.reset(pending_web_ui_.release()); |
822 else if (!pending_and_current_web_ui_.get()) | 893 else if (!pending_and_current_web_ui_.get()) |
823 web_ui_.reset(); | 894 web_ui_.reset(); |
824 | 895 |
825 // It's possible for the pending_render_view_host_ to be NULL when we aren't | 896 // It's possible for the pending_render_frame_host_ to be NULL when we aren't |
826 // crossing process boundaries. If so, we just needed to handle the Web UI | 897 // crossing process boundaries. If so, we just needed to handle the Web UI |
827 // committing above and we're done. | 898 // committing above and we're done. |
828 if (!pending_render_view_host_) { | 899 if (!pending_render_frame_host_) { |
829 if (will_focus_location_bar) | 900 if (will_focus_location_bar) |
830 delegate_->SetFocusToLocationBar(false); | 901 delegate_->SetFocusToLocationBar(false); |
831 return; | 902 return; |
832 } | 903 } |
833 | 904 |
834 // Remember if the page was focused so we can focus the new renderer in | 905 // Remember if the page was focused so we can focus the new renderer in |
835 // that case. | 906 // that case. |
836 bool focus_render_view = !will_focus_location_bar && | 907 bool focus_render_view = !will_focus_location_bar && |
837 render_view_host_->GetView() && render_view_host_->GetView()->HasFocus(); | 908 render_frame_host_->render_view_host()->GetView() && |
909 render_frame_host_->render_view_host()->GetView()->HasFocus(); | |
838 | 910 |
839 // Swap in the pending view and make it active. Also ensure the FrameTree | 911 // Swap in the pending frame and make it active. Also ensure the FrameTree |
840 // stays in sync. | 912 // stays in sync. |
841 RenderViewHostImpl* old_render_view_host = render_view_host_; | 913 RenderFrameHostImpl* old_render_frame_host = render_frame_host_; |
842 render_view_host_ = pending_render_view_host_; | 914 render_frame_host_ = pending_render_frame_host_; |
843 pending_render_view_host_ = NULL; | 915 pending_render_frame_host_ = NULL; |
844 render_view_host_->AttachToFrameTree(); | 916 render_frame_host_->render_view_host()->AttachToFrameTree(); |
845 | 917 |
846 // The process will no longer try to exit, so we can decrement the count. | 918 // The process will no longer try to exit, so we can decrement the count. |
847 render_view_host_->GetProcess()->RemovePendingView(); | 919 render_frame_host_->GetProcess()->RemovePendingView(); |
920 | |
921 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for | |
922 // subframe navigations or they'll interfere with the top-level page. | |
923 bool is_main_frame = frame_tree_node_->IsMainFrame(); | |
848 | 924 |
849 // If the view is gone, then this RenderViewHost died while it was hidden. | 925 // If the view is gone, then this RenderViewHost died while it was hidden. |
850 // We ignored the RenderProcessGone call at the time, so we should send it now | 926 // We ignored the RenderProcessGone call at the time, so we should send it now |
851 // to make sure the sad tab shows up, etc. | 927 // to make sure the sad tab shows up, etc. |
852 if (!render_view_host_->GetView()) | 928 if (!render_frame_host_->render_view_host()->GetView()) { |
853 delegate_->RenderProcessGoneFromRenderManager(render_view_host_); | 929 delegate_->RenderProcessGoneFromRenderManager( |
854 else if (!delegate_->IsHidden()) | 930 render_frame_host_->render_view_host()); |
855 render_view_host_->GetView()->Show(); | 931 } else if (!delegate_->IsHidden() && is_main_frame) { |
932 render_frame_host_->render_view_host()->GetView()->Show(); | |
933 } | |
856 | 934 |
857 // Hide the old view now that the new one is visible. | 935 // Hide the old view now that the new one is visible. |
858 if (old_render_view_host->GetView()) { | 936 if (old_render_frame_host->render_view_host()->GetView()) { |
859 old_render_view_host->GetView()->Hide(); | 937 old_render_frame_host->render_view_host()->GetView()->Hide(); |
860 old_render_view_host->WasSwappedOut(); | 938 old_render_frame_host->render_view_host()->WasSwappedOut(); |
861 } | 939 } |
862 | 940 |
863 // Make sure the size is up to date. (Fix for bug 1079768.) | 941 // Make sure the size is up to date. (Fix for bug 1079768.) |
864 delegate_->UpdateRenderViewSizeForRenderManager(); | 942 delegate_->UpdateRenderViewSizeForRenderManager(); |
865 | 943 |
866 if (will_focus_location_bar) | 944 if (will_focus_location_bar) { |
867 delegate_->SetFocusToLocationBar(false); | 945 delegate_->SetFocusToLocationBar(false); |
868 else if (focus_render_view && render_view_host_->GetView()) | 946 } else if (focus_render_view && |
869 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus(); | 947 render_frame_host_->render_view_host()->GetView()) { |
948 RenderWidgetHostViewPort::FromRWHV( | |
949 render_frame_host_->render_view_host()->GetView())->Focus(); | |
950 } | |
870 | 951 |
871 // Notify that we've swapped RenderViewHosts. We do this | 952 // Notify that we've swapped RenderFrameHosts. We do this |
nasko
2013/12/13 22:20:11
nit: This comment can put more words on the same l
Charlie Reis
2013/12/16 16:13:55
Done.
| |
872 // before shutting down the RVH so that we can clean up | 953 // before shutting down the RFH so that we can clean up |
873 // RendererResources related to the RVH first. | 954 // RendererResources related to the RFH first. |
874 delegate_->NotifySwappedFromRenderManager(old_render_view_host, | 955 // TODO(creis): Only do this on top-level RFHs for now, and later update it to |
875 render_view_host_); | 956 // pass the RFHs. |
957 if (is_main_frame) { | |
958 delegate_->NotifySwappedFromRenderManager( | |
959 old_render_frame_host->render_view_host(), | |
960 render_frame_host_->render_view_host()); | |
961 } | |
876 | 962 |
877 // If the pending view was on the swapped out list, we can remove it. | 963 // If the pending frame was on the swapped out list, we can remove it. |
878 swapped_out_hosts_.erase(render_view_host_->GetSiteInstance()->GetId()); | 964 swapped_out_hosts_.erase(render_frame_host_->render_view_host()-> |
965 GetSiteInstance()->GetId()); | |
879 | 966 |
880 // If there are no active RVHs in this SiteInstance, it means that | 967 if (old_render_frame_host->render_view_host()->IsRenderViewLive()) { |
881 // this RVH was the last active one in the SiteInstance. Now that we | 968 // If the old RFH is live, we are swapping it out and should keep track of |
882 // know that all RVHs are swapped out, we can delete all the RVHs in | |
883 // this SiteInstance. | |
884 if (!static_cast<SiteInstanceImpl*>(old_render_view_host->GetSiteInstance())-> | |
885 active_view_count()) { | |
886 ShutdownRenderViewHostsInSiteInstance( | |
887 old_render_view_host->GetSiteInstance()->GetId()); | |
888 // This is deleted while cleaning up the SitaInstance's views. | |
889 old_render_view_host = NULL; | |
890 } else if (old_render_view_host->IsRenderViewLive()) { | |
891 // If the old RVH is live, we are swapping it out and should keep track of | |
892 // it in case we navigate back to it. | 969 // it in case we navigate back to it. |
893 DCHECK(old_render_view_host->is_swapped_out()); | 970 DCHECK(old_render_frame_host->render_view_host()->is_swapped_out()); |
894 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make | 971 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make |
895 // sure we don't get different rvh instances for the same site instance | 972 // sure we don't get different rvh instances for the same site instance |
896 // in the same rvhmgr. | 973 // in the same rvhmgr. |
897 // TODO(creis): Clean this up. | 974 // TODO(creis): Clean this up. |
898 int32 old_site_instance_id = | 975 int32 old_site_instance_id = |
899 old_render_view_host->GetSiteInstance()->GetId(); | 976 old_render_frame_host->render_view_host()->GetSiteInstance()->GetId(); |
900 RenderViewHostMap::iterator iter = | 977 RenderFrameHostMap::iterator iter = |
901 swapped_out_hosts_.find(old_site_instance_id); | 978 swapped_out_hosts_.find(old_site_instance_id); |
902 if (iter != swapped_out_hosts_.end() && | 979 if (iter != swapped_out_hosts_.end() && |
903 iter->second != old_render_view_host) { | 980 iter->second != old_render_frame_host) { |
904 // Shutdown the RVH that will be replaced in the map to avoid a leak. | 981 // Delete the RFH that will be replaced in the map to avoid a leak. |
905 iter->second->Shutdown(); | 982 delete iter->second; |
906 } | 983 } |
907 swapped_out_hosts_[old_site_instance_id] = old_render_view_host; | 984 swapped_out_hosts_[old_site_instance_id] = old_render_frame_host; |
985 | |
986 // If there are no active views in this SiteInstance, it means that | |
987 // this RFH was the last active one in the SiteInstance. Now that we | |
988 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs | |
989 // in this SiteInstance. We do this after ensuring the RFH is on the | |
990 // swapped out list to simplify the deletion. | |
991 if (!static_cast<SiteInstanceImpl*>( | |
992 old_render_frame_host->render_view_host()->GetSiteInstance())-> | |
993 active_view_count()) { | |
994 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); | |
995 // This is deleted while cleaning up the SiteInstance's views. | |
996 old_render_frame_host = NULL; | |
997 } | |
908 } else { | 998 } else { |
909 old_render_view_host->Shutdown(); | 999 delete old_render_frame_host; |
910 old_render_view_host = NULL; // Shutdown() deletes it. | |
911 } | 1000 } |
912 } | 1001 } |
913 | 1002 |
914 void RenderFrameHostManager::ShutdownRenderViewHostsInSiteInstance( | 1003 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( |
915 int32 site_instance_id) { | 1004 int32 site_instance_id) { |
916 // First remove any swapped out RVH for this SiteInstance from our | 1005 // First remove any swapped out RFH for this SiteInstance from our own list. |
917 // list. | 1006 ClearSwappedOutRFHsInSiteInstance(site_instance_id, frame_tree_node_); |
918 swapped_out_hosts_.erase(site_instance_id); | |
919 | 1007 |
1008 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts | |
1009 // in the SiteInstance, then tell their respective FrameTrees to remove all | |
1010 // swapped out RenderFrameHosts corresponding to them. | |
1011 // TODO(creis): Replace this with a RenderFrameHostIterator that protects | |
1012 // against use-after-frees if a later element is deleted before getting to it. | |
920 scoped_ptr<RenderWidgetHostIterator> widgets( | 1013 scoped_ptr<RenderWidgetHostIterator> widgets( |
921 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 1014 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
922 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 1015 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
923 if (!widget->IsRenderView()) | 1016 if (!widget->IsRenderView()) |
924 continue; | 1017 continue; |
925 RenderViewHostImpl* rvh = | 1018 RenderViewHostImpl* rvh = |
926 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget)); | 1019 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget)); |
927 if (site_instance_id == rvh->GetSiteInstance()->GetId()) | 1020 if (site_instance_id == rvh->GetSiteInstance()->GetId()) { |
928 rvh->Shutdown(); | 1021 // This deletes all RenderFrameHosts using the |rvh|, which then causes |
1022 // |rvh| to Shutdown. | |
1023 FrameTree* tree = rvh->GetDelegate()->GetFrameTree(); | |
1024 tree->ForEach(base::Bind( | |
1025 &RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance, | |
1026 site_instance_id)); | |
1027 // rvh is now deleted. | |
1028 } | |
929 } | 1029 } |
930 } | 1030 } |
931 | 1031 |
932 RenderViewHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate( | 1032 RenderFrameHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate( |
933 const NavigationEntryImpl& entry) { | 1033 const NavigationEntryImpl& entry) { |
934 // If we are currently navigating cross-process, we want to get back to normal | 1034 // If we are currently navigating cross-process, we want to get back to normal |
935 // and then navigate as usual. | 1035 // and then navigate as usual. |
936 if (cross_navigation_pending_) { | 1036 if (cross_navigation_pending_) { |
937 if (pending_render_view_host_) | 1037 if (pending_render_frame_host_) |
938 CancelPending(); | 1038 CancelPending(); |
939 cross_navigation_pending_ = false; | 1039 cross_navigation_pending_ = false; |
940 } | 1040 } |
941 | 1041 |
942 // render_view_host_'s SiteInstance and new_instance will not be deleted | 1042 // render_frame_host_'s SiteInstance and new_instance will not be deleted |
943 // before the end of this method, so we don't have to worry about their ref | 1043 // before the end of this method, so we don't have to worry about their ref |
944 // counts dropping to zero. | 1044 // counts dropping to zero. |
945 SiteInstance* current_instance = render_view_host_->GetSiteInstance(); | 1045 SiteInstance* current_instance = |
1046 render_frame_host_->render_view_host()->GetSiteInstance(); | |
946 SiteInstance* new_instance = current_instance; | 1047 SiteInstance* new_instance = current_instance; |
947 | 1048 |
948 // We do not currently swap processes for navigations in webview tag guests. | 1049 // We do not currently swap processes for navigations in webview tag guests. |
949 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); | 1050 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); |
950 | 1051 |
951 // Determine if we need a new BrowsingInstance for this entry. If true, this | 1052 // Determine if we need a new BrowsingInstance for this entry. If true, this |
952 // implies that it will get a new SiteInstance (and likely process), and that | 1053 // implies that it will get a new SiteInstance (and likely process), and that |
953 // other tabs in the current BrosingInstance will be unalbe to script it. | 1054 // other tabs in the current BrowsingInstance will be unable to script it. |
954 // This is used for cases that require a process swap even in the | 1055 // This is used for cases that require a process swap even in the |
955 // process-per-tab model, such as WebUI pages. | 1056 // process-per-tab model, such as WebUI pages. |
956 const NavigationEntry* current_entry = | 1057 const NavigationEntry* current_entry = |
957 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 1058 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
958 bool force_swap = !is_guest_scheme && | 1059 bool force_swap = !is_guest_scheme && |
959 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry); | 1060 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry); |
960 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap)) | 1061 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap)) |
961 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap); | 1062 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap); |
962 | 1063 |
963 // If force_swap is true, we must use a different SiteInstance. If we didn't, | 1064 // If force_swap is true, we must use a different SiteInstance. If we didn't, |
964 // we would have two RenderViewHosts in the same SiteInstance and the same | 1065 // we would have two RenderFrameHosts in the same SiteInstance and the same |
965 // tab, resulting in page_id conflicts for their NavigationEntries. | 1066 // frame, resulting in page_id conflicts for their NavigationEntries. |
966 if (force_swap) | 1067 if (force_swap) |
967 CHECK_NE(new_instance, current_instance); | 1068 CHECK_NE(new_instance, current_instance); |
968 | 1069 |
969 if (new_instance != current_instance) { | 1070 if (new_instance != current_instance) { |
970 // New SiteInstance: create a pending RVH to navigate. | 1071 // New SiteInstance: create a pending RFH to navigate. |
971 DCHECK(!cross_navigation_pending_); | 1072 DCHECK(!cross_navigation_pending_); |
972 | 1073 |
973 // This will possibly create (set to NULL) a Web UI object for the pending | 1074 // This will possibly create (set to NULL) a Web UI object for the pending |
974 // page. We'll use this later to give the page special access. This must | 1075 // page. We'll use this later to give the page special access. This must |
975 // happen before the new renderer is created below so it will get bindings. | 1076 // happen before the new renderer is created below so it will get bindings. |
976 // It must also happen after the above conditional call to CancelPending(), | 1077 // It must also happen after the above conditional call to CancelPending(), |
977 // otherwise CancelPending may clear the pending_web_ui_ and the page will | 1078 // otherwise CancelPending may clear the pending_web_ui_ and the page will |
978 // not have its bindings set appropriately. | 1079 // not have its bindings set appropriately. |
979 SetPendingWebUI(entry); | 1080 SetPendingWebUI(entry); |
980 | 1081 |
981 // Ensure that we have created RVHs for the new RVH's opener chain if | 1082 // Ensure that we have created RFHs for the new RFH's opener chain if |
982 // we are staying in the same BrowsingInstance. This allows the pending RVH | 1083 // we are staying in the same BrowsingInstance. This allows the pending RFH |
983 // to send cross-process script calls to its opener(s). | 1084 // to send cross-process script calls to its opener(s). |
984 int opener_route_id = MSG_ROUTING_NONE; | 1085 int opener_route_id = MSG_ROUTING_NONE; |
985 if (new_instance->IsRelatedSiteInstance(current_instance)) { | 1086 if (new_instance->IsRelatedSiteInstance(current_instance)) { |
986 opener_route_id = | 1087 opener_route_id = |
987 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 1088 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
988 } | 1089 } |
989 | 1090 |
990 // Create a non-swapped-out pending RVH with the given opener and navigate | 1091 // Create a non-swapped-out pending RFH with the given opener and navigate |
991 // it. | 1092 // it. |
992 int route_id = CreateRenderView(new_instance, opener_route_id, false, | 1093 int route_id = CreateRenderFrame(new_instance, opener_route_id, false, |
993 delegate_->IsHidden()); | 1094 delegate_->IsHidden()); |
994 if (route_id == MSG_ROUTING_NONE) | 1095 if (route_id == MSG_ROUTING_NONE) |
995 return NULL; | 1096 return NULL; |
996 | 1097 |
997 // Check if our current RVH is live before we set up a transition. | 1098 // Check if our current RFH is live before we set up a transition. |
998 if (!render_view_host_->IsRenderViewLive()) { | 1099 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { |
999 if (!cross_navigation_pending_) { | 1100 if (!cross_navigation_pending_) { |
1000 // The current RVH is not live. There's no reason to sit around with a | 1101 // The current RFH is not live. There's no reason to sit around with a |
1001 // sad tab or a newly created RVH while we wait for the pending RVH to | 1102 // sad tab or a newly created RFH while we wait for the pending RFH to |
1002 // navigate. Just switch to the pending RVH now and go back to non | 1103 // navigate. Just switch to the pending RFH now and go back to non |
1003 // cross-navigating (Note that we don't care about on{before}unload | 1104 // cross-navigating (Note that we don't care about on{before}unload |
1004 // handlers if the current RVH isn't live.) | 1105 // handlers if the current RFH isn't live.) |
1005 CommitPending(); | 1106 CommitPending(); |
1006 return render_view_host_; | 1107 return render_frame_host_; |
1007 } else { | 1108 } else { |
1008 NOTREACHED(); | 1109 NOTREACHED(); |
1009 return render_view_host_; | 1110 return render_frame_host_; |
1010 } | 1111 } |
1011 } | 1112 } |
1012 // Otherwise, it's safe to treat this as a pending cross-site transition. | 1113 // Otherwise, it's safe to treat this as a pending cross-site transition. |
1013 | 1114 |
1014 // We need to wait until the beforeunload handler has run, unless we are | 1115 // We need to wait until the beforeunload handler has run, unless we are |
1015 // transferring an existing request (in which case it has already run). | 1116 // transferring an existing request (in which case it has already run). |
1016 // Suspend the new render view (i.e., don't let it send the cross-site | 1117 // Suspend the new render view (i.e., don't let it send the cross-site |
1017 // Navigate message) until we hear back from the old renderer's | 1118 // Navigate message) until we hear back from the old renderer's |
1018 // beforeunload handler. If the handler returns false, we'll have to | 1119 // beforeunload handler. If the handler returns false, we'll have to |
1019 // cancel the request. | 1120 // cancel the request. |
1020 DCHECK(!pending_render_view_host_->are_navigations_suspended()); | 1121 DCHECK(!pending_render_frame_host_->render_view_host()-> |
1122 are_navigations_suspended()); | |
1021 bool is_transfer = | 1123 bool is_transfer = |
1022 entry.transferred_global_request_id() != GlobalRequestID(); | 1124 entry.transferred_global_request_id() != GlobalRequestID(); |
1023 if (is_transfer) { | 1125 if (is_transfer) { |
1024 // We don't need to stop the old renderer or run beforeunload/unload | 1126 // We don't need to stop the old renderer or run beforeunload/unload |
1025 // handlers, because those have already been done. | 1127 // handlers, because those have already been done. |
1026 DCHECK(pending_nav_params_->global_request_id == | 1128 DCHECK(pending_nav_params_->global_request_id == |
1027 entry.transferred_global_request_id()); | 1129 entry.transferred_global_request_id()); |
1028 } else { | 1130 } else { |
1029 // Also make sure the old render view stops, in case a load is in | 1131 // Also make sure the old render view stops, in case a load is in |
1030 // progress. (We don't want to do this for transfers, since it will | 1132 // progress. (We don't want to do this for transfers, since it will |
1031 // interrupt the transfer with an unexpected DidStopLoading.) | 1133 // interrupt the transfer with an unexpected DidStopLoading.) |
1032 render_view_host_->Send( | 1134 render_frame_host_->render_view_host()->Send(new ViewMsg_Stop( |
1033 new ViewMsg_Stop(render_view_host_->GetRoutingID())); | 1135 render_frame_host_->render_view_host()->GetRoutingID())); |
1034 | 1136 |
1035 pending_render_view_host_->SetNavigationsSuspended(true, | 1137 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended( |
1036 base::TimeTicks()); | 1138 true, base::TimeTicks()); |
1037 | 1139 |
1038 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site | 1140 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site |
1039 // request, so that ResourceDispatcherHost will know to tell us to run the | 1141 // request, so that ResourceDispatcherHost will know to tell us to run the |
1040 // old page's unload handler before it sends the response. | 1142 // old page's unload handler before it sends the response. |
1041 pending_render_view_host_->SetHasPendingCrossSiteRequest(true); | 1143 // TODO(creis): This needs to be on the RFH. |
1144 pending_render_frame_host_->render_view_host()-> | |
1145 SetHasPendingCrossSiteRequest(true); | |
1042 } | 1146 } |
1043 | 1147 |
1044 // We now have a pending RVH. | 1148 // We now have a pending RFH. |
1045 DCHECK(!cross_navigation_pending_); | 1149 DCHECK(!cross_navigation_pending_); |
1046 cross_navigation_pending_ = true; | 1150 cross_navigation_pending_ = true; |
1047 | 1151 |
1048 // Unless we are transferring an existing request, we should now | 1152 // Unless we are transferring an existing request, we should now |
1049 // tell the old render view to run its beforeunload handler, since it | 1153 // tell the old render view to run its beforeunload handler, since it |
1050 // doesn't otherwise know that the cross-site request is happening. This | 1154 // doesn't otherwise know that the cross-site request is happening. This |
1051 // will trigger a call to ShouldClosePage with the reply. | 1155 // will trigger a call to ShouldClosePage with the reply. |
1052 if (!is_transfer) | 1156 if (!is_transfer) |
1053 render_view_host_->FirePageBeforeUnload(true); | 1157 render_frame_host_->render_view_host()->FirePageBeforeUnload(true); |
1054 | 1158 |
1055 return pending_render_view_host_; | 1159 return pending_render_frame_host_; |
1056 } | 1160 } |
1057 | 1161 |
1058 // Otherwise the same SiteInstance can be used. Navigate render_view_host_. | 1162 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. |
1059 DCHECK(!cross_navigation_pending_); | 1163 DCHECK(!cross_navigation_pending_); |
1060 if (ShouldReuseWebUI(current_entry, &entry)) { | 1164 if (ShouldReuseWebUI(current_entry, &entry)) { |
1061 pending_web_ui_.reset(); | 1165 pending_web_ui_.reset(); |
1062 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | 1166 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); |
1063 } else { | 1167 } else { |
1064 SetPendingWebUI(entry); | 1168 SetPendingWebUI(entry); |
1065 | 1169 |
1066 // Make sure the new RenderViewHost has the right bindings. | 1170 // Make sure the new RenderViewHost has the right bindings. |
1067 if (pending_web_ui() && !render_view_host_->GetProcess()->IsGuest()) | 1171 if (pending_web_ui() && !render_frame_host_->GetProcess()->IsGuest()) { |
1068 render_view_host_->AllowBindings(pending_web_ui()->GetBindings()); | 1172 render_frame_host_->render_view_host()->AllowBindings( |
1173 pending_web_ui()->GetBindings()); | |
1174 } | |
1069 } | 1175 } |
1070 | 1176 |
1071 if (pending_web_ui() && render_view_host_->IsRenderViewLive()) | 1177 if (pending_web_ui() && |
1072 pending_web_ui()->GetController()->RenderViewReused(render_view_host_); | 1178 render_frame_host_->render_view_host()->IsRenderViewLive()) { |
1179 pending_web_ui()->GetController()->RenderViewReused( | |
1180 render_frame_host_->render_view_host()); | |
1181 } | |
1073 | 1182 |
1074 // The renderer can exit view source mode when any error or cancellation | 1183 // The renderer can exit view source mode when any error or cancellation |
1075 // happen. We must overwrite to recover the mode. | 1184 // happen. We must overwrite to recover the mode. |
1076 if (entry.IsViewSourceMode()) { | 1185 if (entry.IsViewSourceMode()) { |
1077 render_view_host_->Send( | 1186 render_frame_host_->render_view_host()->Send( |
1078 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID())); | 1187 new ViewMsg_EnableViewSourceMode( |
1188 render_frame_host_->render_view_host()->GetRoutingID())); | |
1079 } | 1189 } |
1080 | 1190 |
1081 return render_view_host_; | 1191 return render_frame_host_; |
1082 } | 1192 } |
1083 | 1193 |
1084 void RenderFrameHostManager::CancelPending() { | 1194 void RenderFrameHostManager::CancelPending() { |
1085 RenderViewHostImpl* pending_render_view_host = pending_render_view_host_; | 1195 RenderFrameHostImpl* pending_render_frame_host = pending_render_frame_host_; |
1086 pending_render_view_host_ = NULL; | 1196 pending_render_frame_host_ = NULL; |
1087 | 1197 |
1088 RenderViewDevToolsAgentHost::OnCancelPendingNavigation( | 1198 RenderViewDevToolsAgentHost::OnCancelPendingNavigation( |
1089 pending_render_view_host, | 1199 pending_render_frame_host->render_view_host(), |
1090 render_view_host_); | 1200 render_frame_host_->render_view_host()); |
1091 | 1201 |
1092 // We no longer need to prevent the process from exiting. | 1202 // We no longer need to prevent the process from exiting. |
1093 pending_render_view_host->GetProcess()->RemovePendingView(); | 1203 pending_render_frame_host->GetProcess()->RemovePendingView(); |
1094 | 1204 |
1095 // The pending RVH may already be on the swapped out list if we started to | 1205 // The pending RFH may already be on the swapped out list if we started to |
1096 // swap it back in and then canceled. If so, make sure it gets swapped out | 1206 // swap it back in and then canceled. If so, make sure it gets swapped out |
1097 // again. If it's not on the swapped out list (e.g., aborting a pending | 1207 // again. If it's not on the swapped out list (e.g., aborting a pending |
1098 // load), then it's safe to shut down. | 1208 // load), then it's safe to shut down. |
1099 if (IsOnSwappedOutList(pending_render_view_host)) { | 1209 if (IsOnSwappedOutList(pending_render_frame_host)) { |
1100 // Any currently suspended navigations are no longer needed. | 1210 // Any currently suspended navigations are no longer needed. |
1101 pending_render_view_host->CancelSuspendedNavigations(); | 1211 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); |
1102 | 1212 |
1103 pending_render_view_host->SwapOut(); | 1213 // TODO(creis): We need to swap out the RFH. |
1214 pending_render_frame_host->render_view_host()->SwapOut(); | |
1104 } else { | 1215 } else { |
1105 // We won't be coming back, so shut this one down. | 1216 // We won't be coming back, so shut this one down. |
1106 pending_render_view_host->Shutdown(); | 1217 delete pending_render_frame_host; |
1107 } | 1218 } |
1108 | 1219 |
1109 pending_web_ui_.reset(); | 1220 pending_web_ui_.reset(); |
1110 pending_and_current_web_ui_.reset(); | 1221 pending_and_current_web_ui_.reset(); |
1111 } | 1222 } |
1112 | 1223 |
1113 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) { | 1224 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) { |
1114 // We are doing this in order to work around and to track a crasher | 1225 // We are doing this in order to work around and to track a crasher |
1115 // (http://crbug.com/23411) where it seems that pending_render_view_host_ is | 1226 // (http://crbug.com/23411) where it seems that pending_render_frame_host_ is |
1116 // deleted (not sure from where) but not NULLed. | 1227 // deleted (not sure from where) but not NULLed. |
1117 if (rvh == pending_render_view_host_) { | 1228 if (pending_render_frame_host_ && |
1229 rvh == pending_render_frame_host_->render_view_host()) { | |
1118 // If you hit this NOTREACHED, please report it in the following bug | 1230 // If you hit this NOTREACHED, please report it in the following bug |
1119 // http://crbug.com/23411 Make sure to include what you were doing when it | 1231 // http://crbug.com/23411 Make sure to include what you were doing when it |
1120 // happened (navigating to a new page, closing a tab...) and if you can | 1232 // happened (navigating to a new page, closing a tab...) and if you can |
1121 // reproduce. | 1233 // reproduce. |
1122 NOTREACHED(); | 1234 NOTREACHED(); |
1123 pending_render_view_host_ = NULL; | 1235 pending_render_frame_host_ = NULL; |
1124 } | 1236 } |
1125 | 1237 |
1126 // Make sure deleted RVHs are not kept in the swapped out list while we are | 1238 // Make sure deleted RVHs are not kept in the swapped out list while we are |
1127 // still alive. (If render_view_host_ is null, we're already being deleted.) | 1239 // still alive. (If render_frame_host_ is null, we're already being deleted.) |
1128 if (!render_view_host_) | 1240 if (!render_frame_host_) |
1129 return; | 1241 return; |
1242 | |
1130 // We can't look it up by SiteInstance ID, which may no longer be valid. | 1243 // We can't look it up by SiteInstance ID, which may no longer be valid. |
1131 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 1244 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); |
1132 iter != swapped_out_hosts_.end(); | 1245 iter != swapped_out_hosts_.end(); |
1133 ++iter) { | 1246 ++iter) { |
1134 if (iter->second == rvh) { | 1247 if (iter->second->render_view_host() == rvh) { |
1135 swapped_out_hosts_.erase(iter); | 1248 swapped_out_hosts_.erase(iter); |
1136 break; | 1249 break; |
1137 } | 1250 } |
1138 } | 1251 } |
1139 } | 1252 } |
1140 | 1253 |
1141 bool RenderFrameHostManager::IsOnSwappedOutList(RenderViewHost* rvh) const { | 1254 bool RenderFrameHostManager::IsRVHOnSwappedOutList( |
1142 if (!rvh->GetSiteInstance()) | 1255 RenderViewHostImpl* rvh) const { |
1256 RenderFrameHostImpl* render_frame_host = GetSwappedOutRenderFrameHost( | |
1257 rvh->GetSiteInstance()); | |
1258 if (!render_frame_host) | |
1259 return false; | |
1260 return IsOnSwappedOutList(render_frame_host); | |
1261 } | |
1262 | |
1263 bool RenderFrameHostManager::IsOnSwappedOutList( | |
1264 RenderFrameHostImpl* rfh) const { | |
1265 if (!rfh->render_view_host()->GetSiteInstance()) | |
1143 return false; | 1266 return false; |
1144 | 1267 |
1145 RenderViewHostMap::const_iterator iter = swapped_out_hosts_.find( | 1268 RenderFrameHostMap::const_iterator iter = swapped_out_hosts_.find( |
1146 rvh->GetSiteInstance()->GetId()); | 1269 rfh->render_view_host()->GetSiteInstance()->GetId()); |
1147 if (iter == swapped_out_hosts_.end()) | 1270 if (iter == swapped_out_hosts_.end()) |
1148 return false; | 1271 return false; |
1149 | 1272 |
1150 return iter->second == rvh; | 1273 return iter->second == rfh; |
1151 } | 1274 } |
1152 | 1275 |
1153 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( | 1276 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( |
1154 SiteInstance* instance) { | 1277 SiteInstance* instance) const { |
1155 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 1278 RenderFrameHostImpl* render_frame_host = |
1279 GetSwappedOutRenderFrameHost(instance); | |
1280 if (render_frame_host) | |
1281 return render_frame_host->render_view_host(); | |
1282 return NULL; | |
1283 } | |
1284 | |
1285 RenderFrameHostImpl* RenderFrameHostManager::GetSwappedOutRenderFrameHost( | |
1286 SiteInstance* instance) const { | |
1287 RenderFrameHostMap::const_iterator iter = | |
1288 swapped_out_hosts_.find(instance->GetId()); | |
1156 if (iter != swapped_out_hosts_.end()) | 1289 if (iter != swapped_out_hosts_.end()) |
1157 return iter->second; | 1290 return iter->second; |
1158 | 1291 |
1159 return NULL; | 1292 return NULL; |
1160 } | 1293 } |
1161 | 1294 |
1162 } // namespace content | 1295 } // namespace content |
OLD | NEW |