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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/tab_contents/tab_util.h" 6 7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 10 #include "chrome/common/chrome_switches.h" 11 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/site_instance.h" 13 #include "content/public/browser/web_contents.h" 14 #include "url/gurl.h" 15 16 using content::RenderViewHost; 17 using content::SiteInstance; 18 using content::WebContents; 19 20 namespace tab_util { 21 22 content::WebContents* GetWebContentsByID(int render_process_id, 23 int render_view_id) { 24 RenderViewHost* render_view_host = 25 RenderViewHost::FromID(render_process_id, render_view_id); 26 if (!render_view_host) 27 return NULL; 28 29 return WebContents::FromRenderViewHost(render_view_host); 30 } 31 32 SiteInstance* GetSiteInstanceForNewTab(Profile* profile, 33 const GURL& url) { 34 // If |url| is a WebUI or extension, we set the SiteInstance up front so that 35 // we don't end up with an extra process swap on the first navigation. 36 ExtensionService* service = profile->GetExtensionService(); 37 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 38 profile, url) || 39 (service && 40 service->extensions()->GetHostedAppByURL(url))) { 41 return SiteInstance::CreateForURL(profile, url); 42 } 43 44 // We used to share the SiteInstance for same-site links opened in new tabs, 45 // to leverage the in-memory cache and reduce process creation. It now 46 // appears that it is more useful to have such links open in a new process, 47 // so we create new tabs in a new BrowsingInstance. 48 return NULL; 49 } 50 51 } // namespace tab_util 52