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