[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 5 | #include "chrome/browser/tab_contents/tab_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 7 | #include "chrome/browser/extensions/extension_service.h" |
| 8 | #include "chrome/browser/profiles/profile.h" |
| 9 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
| 10 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 11 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 12 | #include "content/browser/site_instance.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 13 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 14 | #include "googleurl/src/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 16 | namespace tab_util { |
| 17 | |
| 18 | TabContents* GetTabContentsByID(int render_process_id, int render_view_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | RenderViewHost* render_view_host = |
| 20 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 21 | if (!render_view_host) |
| 22 | return NULL; |
| 23 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 24 | return render_view_host->delegate()->GetAsTabContents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | } |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 26 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame^] | 27 | content::WebContents* GetWebContentsByID(int render_process_id, |
| 28 | int render_view_id) { |
| 29 | RenderViewHost* render_view_host = |
| 30 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 31 | if (!render_view_host) |
| 32 | return NULL; |
| 33 | |
| 34 | return render_view_host->delegate()->GetAsWebContents(); |
| 35 | } |
| 36 | |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 37 | SiteInstance* GetSiteInstanceForNewTab(TabContents* source_contents, |
| 38 | Profile* profile, |
| 39 | const GURL& url) { |
| 40 | // If url is a WebUI or extension, we need to be sure to use the right type |
| 41 | // of renderer process up front. Otherwise, we create a normal SiteInstance |
| 42 | // as part of creating the tab. |
| 43 | ExtensionService* service = profile->GetExtensionService(); |
| 44 | if (ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, url) || |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 45 | (service && |
| 46 | service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) { |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 47 | return SiteInstance::CreateSiteInstanceForURL(profile, url); |
| 48 | } |
| 49 | |
| 50 | if (!source_contents) |
| 51 | return NULL; |
| 52 | |
| 53 | // Don't use this logic when "--process-per-tab" is specified. |
| 54 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) && |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 55 | SiteInstance::IsSameWebSite(source_contents->GetBrowserContext(), |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 56 | source_contents->GetURL(), |
| 57 | url)) { |
| 58 | return source_contents->GetSiteInstance(); |
| 59 | } |
| 60 | return NULL; |
| 61 | } |
| 62 | |
| 63 | } // namespace tab_util |