[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 1 | // Copyright (c) 2012 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" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 9 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 10 | #include "chrome/common/chrome_switches.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 11 | #include "content/public/browser/render_view_host.h" |
[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 12 | #include "content/public/browser/render_view_host_delegate.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 13 | #include "content/public/browser/site_instance.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 14 | #include "content/public/browser/web_contents.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 15 | #include "googleurl/src/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 17 | using content::RenderViewHost; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 18 | using content::SiteInstance; |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 19 | using content::WebContents; |
| 20 | |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 21 | namespace tab_util { |
| 22 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 23 | content::WebContents* GetWebContentsByID(int render_process_id, |
| 24 | int render_view_id) { |
| 25 | RenderViewHost* render_view_host = |
| 26 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 27 | if (!render_view_host) |
| 28 | return NULL; |
| 29 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 30 | return render_view_host->GetDelegate()->GetAsWebContents(); |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 31 | } |
| 32 | |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 33 | SiteInstance* GetSiteInstanceForNewTab(WebContents* source_contents, |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 34 | Profile* profile, |
| 35 | const GURL& url) { |
| 36 | // If url is a WebUI or extension, we need to be sure to use the right type |
| 37 | // of renderer process up front. Otherwise, we create a normal SiteInstance |
| 38 | // as part of creating the tab. |
| 39 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 40 | if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 41 | profile, url) || |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 42 | (service && |
| 43 | service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 44 | return SiteInstance::CreateForURL(profile, url); |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | if (!source_contents) |
| 48 | return NULL; |
| 49 | |
| 50 | // Don't use this logic when "--process-per-tab" is specified. |
| 51 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) && |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 52 | SiteInstance::IsSameWebSite(source_contents->GetBrowserContext(), |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 53 | source_contents->GetURL(), |
| 54 | url)) { |
| 55 | return source_contents->GetSiteInstance(); |
| 56 | } |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | } // namespace tab_util |