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