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