OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/render_view_host_manager.h" | 5 #include "content/browser/web_contents/render_view_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/logging.h" | 10 #include "base/logging.h" |
11 #include "content/browser/debugger/devtools_manager_impl.h" | 11 #include "content/browser/debugger/devtools_manager_impl.h" |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
15 #include "content/browser/web_contents/navigation_controller_impl.h" | 16 #include "content/browser/web_contents/navigation_controller_impl.h" |
16 #include "content/browser/web_contents/navigation_entry_impl.h" | 17 #include "content/browser/web_contents/navigation_entry_impl.h" |
17 #include "content/browser/webui/web_ui_impl.h" | 18 #include "content/browser/webui/web_ui_impl.h" |
18 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
19 #include "content/port/browser/render_widget_host_view_port.h" | 20 #include "content/port/browser/render_widget_host_view_port.h" |
20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
24 #include "content/public/browser/web_ui_controller.h" | 25 #include "content/public/browser/web_ui_controller.h" |
25 #include "content/public/browser/web_ui_controller_factory.h" | 26 #include "content/public/browser/web_ui_controller_factory.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
28 | 29 |
29 using content::NavigationController; | 30 using content::NavigationController; |
30 using content::NavigationEntry; | 31 using content::NavigationEntry; |
31 using content::NavigationEntryImpl; | 32 using content::NavigationEntryImpl; |
| 33 using content::RenderProcessHost; |
| 34 using content::RenderProcessHostImpl; |
32 using content::RenderViewHost; | 35 using content::RenderViewHost; |
33 using content::RenderViewHostImpl; | 36 using content::RenderViewHostImpl; |
34 using content::RenderWidgetHostView; | 37 using content::RenderWidgetHostView; |
35 using content::RenderWidgetHostViewPort; | 38 using content::RenderWidgetHostViewPort; |
36 using content::SiteInstance; | 39 using content::SiteInstance; |
37 using content::WebUIControllerFactory; | 40 using content::WebUIControllerFactory; |
38 | 41 |
39 RenderViewHostManager::RenderViewHostManager( | 42 RenderViewHostManager::RenderViewHostManager( |
40 content::RenderViewHostDelegate* render_view_delegate, | 43 content::RenderViewHostDelegate* render_view_delegate, |
41 content::RenderWidgetHostDelegate* render_widget_delegate, | 44 content::RenderWidgetHostDelegate* render_widget_delegate, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // leave the pending renderer around until the next navigation event | 251 // leave the pending renderer around until the next navigation event |
249 // (Navigate, DidNavigate, etc), which will clean it up properly. | 252 // (Navigate, DidNavigate, etc), which will clean it up properly. |
250 // TODO(creis): All of this will go away when we move the cross-site logic | 253 // TODO(creis): All of this will go away when we move the cross-site logic |
251 // to ResourceDispatcherHost, so that we intercept responses rather than | 254 // to ResourceDispatcherHost, so that we intercept responses rather than |
252 // navigation events. (That's necessary to support onunload anyway.) Once | 255 // navigation events. (That's necessary to support onunload anyway.) Once |
253 // we've made that change, we won't create a pending renderer until we know | 256 // we've made that change, we won't create a pending renderer until we know |
254 // the response is not a download. | 257 // the response is not a download. |
255 } | 258 } |
256 | 259 |
257 void RenderViewHostManager::RendererProcessClosing( | 260 void RenderViewHostManager::RendererProcessClosing( |
258 content::RenderProcessHost* render_process_host) { | 261 RenderProcessHost* render_process_host) { |
259 // Remove any swapped out RVHs from this process, so that we don't try to | 262 // Remove any swapped out RVHs from this process, so that we don't try to |
260 // swap them back in while the process is exiting. Start by finding them, | 263 // swap them back in while the process is exiting. Start by finding them, |
261 // since there could be more than one. | 264 // since there could be more than one. |
262 std::list<int> ids_to_remove; | 265 std::list<int> ids_to_remove; |
263 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 266 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); |
264 iter != swapped_out_hosts_.end(); | 267 iter != swapped_out_hosts_.end(); |
265 ++iter) { | 268 ++iter) { |
266 if (iter->second->GetProcess() == render_process_host) | 269 if (iter->second->GetProcess() == render_process_host) |
267 ids_to_remove.push_back(iter->first); | 270 ids_to_remove.push_back(iter->first); |
268 } | 271 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 new_request_id); | 340 new_request_id); |
338 } | 341 } |
339 | 342 |
340 void RenderViewHostManager::Observe( | 343 void RenderViewHostManager::Observe( |
341 int type, | 344 int type, |
342 const content::NotificationSource& source, | 345 const content::NotificationSource& source, |
343 const content::NotificationDetails& details) { | 346 const content::NotificationDetails& details) { |
344 switch (type) { | 347 switch (type) { |
345 case content::NOTIFICATION_RENDERER_PROCESS_CLOSING: | 348 case content::NOTIFICATION_RENDERER_PROCESS_CLOSING: |
346 RendererProcessClosing( | 349 RendererProcessClosing( |
347 content::Source<content::RenderProcessHost>(source).ptr()); | 350 content::Source<RenderProcessHost>(source).ptr()); |
348 break; | 351 break; |
349 | 352 |
350 default: | 353 default: |
351 NOTREACHED(); | 354 NOTREACHED(); |
352 } | 355 } |
353 } | 356 } |
354 | 357 |
355 bool RenderViewHostManager::ShouldTransitionCrossSite() { | 358 bool RenderViewHostManager::ShouldTransitionCrossSite() { |
356 // True if we are using process-per-site-instance (default) or | 359 // True if we are using process-per-site-instance (default) or |
357 // process-per-site (kProcessPerSite). | 360 // process-per-site (kProcessPerSite). |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // for this entry. We won't commit the SiteInstance to this site until the | 459 // for this entry. We won't commit the SiteInstance to this site until the |
457 // navigation commits (in DidNavigate), unless the navigation entry was | 460 // navigation commits (in DidNavigate), unless the navigation entry was |
458 // restored or it's a Web UI as described below. | 461 // restored or it's a Web UI as described below. |
459 if (!curr_site_instance->HasSite()) { | 462 if (!curr_site_instance->HasSite()) { |
460 // If we've already created a SiteInstance for our destination, we don't | 463 // If we've already created a SiteInstance for our destination, we don't |
461 // want to use this unused SiteInstance; use the existing one. (We don't | 464 // want to use this unused SiteInstance; use the existing one. (We don't |
462 // do this check if the curr_instance has a site, because for now, we want | 465 // do this check if the curr_instance has a site, because for now, we want |
463 // to compare against the current URL and not the SiteInstance's site. In | 466 // to compare against the current URL and not the SiteInstance's site. In |
464 // this case, there is no current URL, so comparing against the site is ok. | 467 // this case, there is no current URL, so comparing against the site is ok. |
465 // See additional comments below.) | 468 // See additional comments below.) |
466 if (curr_site_instance->HasRelatedSiteInstance(dest_url)) | 469 // |
| 470 // Also, if the URL should use process-per-site mode and there is an |
| 471 // existing process for the site, we should use it. We can call |
| 472 // GetRelatedSiteInstance() for this, which will eagerly set the site and |
| 473 // thus use the correct process. |
| 474 bool use_process_per_site = |
| 475 RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, |
| 476 dest_url) && |
| 477 RenderProcessHostImpl::GetProcessHostForSite(browser_context, dest_url); |
| 478 if (curr_site_instance->HasRelatedSiteInstance(dest_url) || |
| 479 use_process_per_site) { |
467 return curr_site_instance->GetRelatedSiteInstance(dest_url); | 480 return curr_site_instance->GetRelatedSiteInstance(dest_url); |
| 481 } |
468 | 482 |
469 // For extensions, Web UI URLs (such as the new tab page), and apps we do | 483 // For extensions, Web UI URLs (such as the new tab page), and apps we do |
470 // not want to use the curr_instance if it has no site, since it will have a | 484 // not want to use the curr_instance if it has no site, since it will have a |
471 // RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance for this | 485 // RenderProcessHost of PRIV_NORMAL. Create a new SiteInstance for this |
472 // URL instead (with the correct process type). | 486 // URL instead (with the correct process type). |
473 if (curr_site_instance->HasWrongProcessForURL(dest_url)) | 487 if (curr_site_instance->HasWrongProcessForURL(dest_url)) |
474 return curr_site_instance->GetRelatedSiteInstance(dest_url); | 488 return curr_site_instance->GetRelatedSiteInstance(dest_url); |
475 | 489 |
476 // Normally the "site" on the SiteInstance is set lazily when the load | 490 // Normally the "site" on the SiteInstance is set lazily when the load |
477 // actually commits. This is to support better process sharing in case | 491 // actually commits. This is to support better process sharing in case |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 912 } |
899 | 913 |
900 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost( | 914 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost( |
901 SiteInstance* instance) { | 915 SiteInstance* instance) { |
902 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 916 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
903 if (iter != swapped_out_hosts_.end()) | 917 if (iter != swapped_out_hosts_.end()) |
904 return iter->second; | 918 return iter->second; |
905 | 919 |
906 return NULL; | 920 return NULL; |
907 } | 921 } |
OLD | NEW |