| 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 "chrome/browser/tab_contents/tab_util.h" | 5 #include "chrome/browser/tab_contents/tab_util.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/render_view_host_delegate.h" | |
| 13 #include "content/public/browser/site_instance.h" | 12 #include "content/public/browser/site_instance.h" |
| 14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 16 | 15 |
| 17 using content::RenderViewHost; | 16 using content::RenderViewHost; |
| 18 using content::SiteInstance; | 17 using content::SiteInstance; |
| 19 using content::WebContents; | 18 using content::WebContents; |
| 20 | 19 |
| 21 namespace tab_util { | 20 namespace tab_util { |
| 22 | 21 |
| 23 content::WebContents* GetWebContentsByID(int render_process_id, | 22 content::WebContents* GetWebContentsByID(int render_process_id, |
| 24 int render_view_id) { | 23 int render_view_id) { |
| 25 RenderViewHost* render_view_host = | 24 RenderViewHost* render_view_host = |
| 26 RenderViewHost::FromID(render_process_id, render_view_id); | 25 RenderViewHost::FromID(render_process_id, render_view_id); |
| 27 if (!render_view_host) | 26 if (!render_view_host) |
| 28 return NULL; | 27 return NULL; |
| 29 | 28 |
| 30 return render_view_host->GetDelegate()->GetAsWebContents(); | 29 return WebContents::FromRenderViewHost(render_view_host); |
| 31 } | 30 } |
| 32 | 31 |
| 33 SiteInstance* GetSiteInstanceForNewTab(Profile* profile, | 32 SiteInstance* GetSiteInstanceForNewTab(Profile* profile, |
| 34 const GURL& url) { | 33 const GURL& url) { |
| 35 // If url is a WebUI or extension, we need to be sure to use the right type | 34 // If url is a WebUI or extension, we need to be sure to use the right type |
| 36 // of renderer process up front. Otherwise, we create a normal SiteInstance | 35 // of renderer process up front. Otherwise, we create a normal SiteInstance |
| 37 // as part of creating the tab. | 36 // as part of creating the tab. |
| 38 ExtensionService* service = profile->GetExtensionService(); | 37 ExtensionService* service = profile->GetExtensionService(); |
| 39 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | 38 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 40 profile, url) || | 39 profile, url) || |
| 41 (service && | 40 (service && |
| 42 service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) { | 41 service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) { |
| 43 return SiteInstance::CreateForURL(profile, url); | 42 return SiteInstance::CreateForURL(profile, url); |
| 44 } | 43 } |
| 45 | 44 |
| 46 // We used to share the SiteInstance for same-site links opened in new tabs, | 45 // We used to share the SiteInstance for same-site links opened in new tabs, |
| 47 // to leverage the in-memory cache and reduce process creation. It now | 46 // to leverage the in-memory cache and reduce process creation. It now |
| 48 // appears that it is more useful to have such links open in a new process. | 47 // appears that it is more useful to have such links open in a new process. |
| 49 return NULL; | 48 return NULL; |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace tab_util | 51 } // namespace tab_util |
| OLD | NEW |