| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/render_view_host_manager.h" | 5 #include "content/browser/tab_contents/render_view_host_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/browser/debugger/devtools_manager.h" | 9 #include "content/browser/debugger/devtools_manager.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 pending_render_view_host_->SetNavigationsSuspended(false); | 160 pending_render_view_host_->SetNavigationsSuspended(false); |
| 161 } else { | 161 } else { |
| 162 // The request has been started and paused while we're waiting for the | 162 // The request has been started and paused while we're waiting for the |
| 163 // unload handler to finish. We'll pretend that it did, by notifying the | 163 // unload handler to finish. We'll pretend that it did, by notifying the |
| 164 // IO thread to let the response continue. The pending renderer will then | 164 // IO thread to let the response continue. The pending renderer will then |
| 165 // be swapped in as part of the usual DidNavigate logic. (If the unload | 165 // be swapped in as part of the usual DidNavigate logic. (If the unload |
| 166 // handler later finishes, this call will be ignored because the state in | 166 // handler later finishes, this call will be ignored because the state in |
| 167 // CrossSiteResourceHandler will already be cleaned up.) | 167 // CrossSiteResourceHandler will already be cleaned up.) |
| 168 ViewMsg_SwapOut_Params params; | 168 ViewMsg_SwapOut_Params params; |
| 169 params.new_render_process_host_id = | 169 params.new_render_process_host_id = |
| 170 pending_render_view_host_->process()->id(); | 170 pending_render_view_host_->process()->GetID(); |
| 171 params.new_request_id = pending_request_id; | 171 params.new_request_id = pending_request_id; |
| 172 current_host()->process()->CrossSiteSwapOutACK(params); | 172 current_host()->process()->CrossSiteSwapOutACK(params); |
| 173 } | 173 } |
| 174 return false; | 174 return false; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void RenderViewHostManager::DidNavigateMainFrame( | 177 void RenderViewHostManager::DidNavigateMainFrame( |
| 178 RenderViewHost* render_view_host) { | 178 RenderViewHost* render_view_host) { |
| 179 if (!cross_navigation_pending_) { | 179 if (!cross_navigation_pending_) { |
| 180 DCHECK(!pending_render_view_host_); | 180 DCHECK(!pending_render_view_host_); |
| 181 | 181 |
| 182 // We should only hear this from our current renderer. | 182 // We should only hear this from our current renderer. |
| 183 DCHECK(render_view_host == render_view_host_); | 183 DCHECK(render_view_host == render_view_host_); |
| 184 | 184 |
| 185 // Even when there is no pending RVH, there may be a pending Web UI. | 185 // Even when there is no pending RVH, there may be a pending Web UI. |
| 186 if (pending_web_ui_.get()) | 186 if (pending_web_ui_.get()) |
| 187 CommitPending(); | 187 CommitPending(); |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (render_view_host == pending_render_view_host_) { | 191 if (render_view_host == pending_render_view_host_) { |
| 192 // The pending cross-site navigation completed, so show the renderer. | 192 // The pending cross-site navigation completed, so show the renderer. |
| 193 // If it committed without sending network requests (e.g., data URLs), | 193 // If it committed without sending network requests (e.g., data URLs), |
| 194 // then we still need to swap out the old RVH first and run its unload | 194 // then we still need to swap out the old RVH first and run its unload |
| 195 // handler. OK for that to happen in the background. | 195 // handler. OK for that to happen in the background. |
| 196 if (pending_render_view_host_->GetPendingRequestId() == -1) { | 196 if (pending_render_view_host_->GetPendingRequestId() == -1) { |
| 197 OnCrossSiteResponse(pending_render_view_host_->process()->id(), | 197 OnCrossSiteResponse(pending_render_view_host_->process()->GetID(), |
| 198 pending_render_view_host_->routing_id()); | 198 pending_render_view_host_->routing_id()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 CommitPending(); | 201 CommitPending(); |
| 202 cross_navigation_pending_ = false; | 202 cross_navigation_pending_ = false; |
| 203 } else if (render_view_host == render_view_host_) { | 203 } else if (render_view_host == render_view_host_) { |
| 204 // A navigation in the original page has taken place. Cancel the pending | 204 // A navigation in the original page has taken place. Cancel the pending |
| 205 // one. | 205 // one. |
| 206 CancelPending(); | 206 CancelPending(); |
| 207 cross_navigation_pending_ = false; | 207 cross_navigation_pending_ = false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 224 // leave the pending renderer around until the next navigation event | 224 // leave the pending renderer around until the next navigation event |
| 225 // (Navigate, DidNavigate, etc), which will clean it up properly. | 225 // (Navigate, DidNavigate, etc), which will clean it up properly. |
| 226 // TODO(creis): All of this will go away when we move the cross-site logic | 226 // TODO(creis): All of this will go away when we move the cross-site logic |
| 227 // to ResourceDispatcherHost, so that we intercept responses rather than | 227 // to ResourceDispatcherHost, so that we intercept responses rather than |
| 228 // navigation events. (That's necessary to support onunload anyway.) Once | 228 // navigation events. (That's necessary to support onunload anyway.) Once |
| 229 // we've made that change, we won't create a pending renderer until we know | 229 // we've made that change, we won't create a pending renderer until we know |
| 230 // the response is not a download. | 230 // the response is not a download. |
| 231 } | 231 } |
| 232 | 232 |
| 233 void RenderViewHostManager::RendererProcessClosing( | 233 void RenderViewHostManager::RendererProcessClosing( |
| 234 RenderProcessHost* render_process_host) { | 234 content::RenderProcessHost* render_process_host) { |
| 235 // Remove any swapped out RVHs from this process, so that we don't try to | 235 // Remove any swapped out RVHs from this process, so that we don't try to |
| 236 // swap them back in while the process is exiting. Start by finding them, | 236 // swap them back in while the process is exiting. Start by finding them, |
| 237 // since there could be more than one. | 237 // since there could be more than one. |
| 238 std::list<int> ids_to_remove; | 238 std::list<int> ids_to_remove; |
| 239 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 239 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); |
| 240 iter != swapped_out_hosts_.end(); | 240 iter != swapped_out_hosts_.end(); |
| 241 ++iter) { | 241 ++iter) { |
| 242 if (iter->second->process() == render_process_host) | 242 if (iter->second->process() == render_process_host) |
| 243 ids_to_remove.push_back(iter->first); | 243 ids_to_remove.push_back(iter->first); |
| 244 } | 244 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (pending_render_view_host_) | 313 if (pending_render_view_host_) |
| 314 CancelPending(); | 314 CancelPending(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void RenderViewHostManager::Observe( | 317 void RenderViewHostManager::Observe( |
| 318 int type, | 318 int type, |
| 319 const content::NotificationSource& source, | 319 const content::NotificationSource& source, |
| 320 const content::NotificationDetails& details) { | 320 const content::NotificationDetails& details) { |
| 321 switch (type) { | 321 switch (type) { |
| 322 case content::NOTIFICATION_RENDERER_PROCESS_CLOSING: | 322 case content::NOTIFICATION_RENDERER_PROCESS_CLOSING: |
| 323 RendererProcessClosing(content::Source<RenderProcessHost>(source).ptr()); | 323 RendererProcessClosing( |
| 324 content::Source<content::RenderProcessHost>(source).ptr()); |
| 324 break; | 325 break; |
| 325 | 326 |
| 326 default: | 327 default: |
| 327 NOTREACHED(); | 328 NOTREACHED(); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 | 331 |
| 331 bool RenderViewHostManager::ShouldTransitionCrossSite() { | 332 bool RenderViewHostManager::ShouldTransitionCrossSite() { |
| 332 // True if we are using process-per-site-instance (default) or | 333 // True if we are using process-per-site-instance (default) or |
| 333 // process-per-site (kProcessPerSite). | 334 // process-per-site (kProcessPerSite). |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 } | 804 } |
| 804 } | 805 } |
| 805 | 806 |
| 806 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 807 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
| 807 if (!rvh->site_instance()) | 808 if (!rvh->site_instance()) |
| 808 return false; | 809 return false; |
| 809 | 810 |
| 810 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 811 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
| 811 swapped_out_hosts_.end(); | 812 swapped_out_hosts_.end(); |
| 812 } | 813 } |
| OLD | NEW |