blob: d3f9e2dddf5cc2dcd3e209e172c71026d5fd2eac [file] [log] [blame]
[email protected]b0b67cf2012-01-18 21:59:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_util.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]1ab4ddf2011-07-21 04:48:047#include "chrome/browser/extensions/extension_service.h"
8#include "chrome/browser/profiles/profile.h"
[email protected]863f70a2012-01-27 02:05:509#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]1ab4ddf2011-07-21 04:48:0410#include "chrome/common/chrome_switches.h"
[email protected]5de634712011-03-02 00:20:1911#include "content/browser/renderer_host/render_view_host.h"
[email protected]b0b67cf2012-01-18 21:59:5712#include "content/public/browser/render_view_host_delegate.h"
[email protected]b6583592012-01-25 19:52:3313#include "content/public/browser/site_instance.h"
[email protected]6acde6352012-01-04 16:52:2014#include "content/public/browser/web_contents.h"
[email protected]1ab4ddf2011-07-21 04:48:0415#include "googleurl/src/gurl.h"
initial.commit09911bf2008-07-26 23:55:2916
[email protected]b6583592012-01-25 19:52:3317using content::SiteInstance;
[email protected]6acde6352012-01-04 16:52:2018using content::WebContents;
19
[email protected]1ab4ddf2011-07-21 04:48:0420namespace tab_util {
21
[email protected]a81343d232011-12-27 07:39:2022content::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
[email protected]9f76c1e2012-03-05 15:15:5829 return render_view_host->GetDelegate()->GetAsWebContents();
[email protected]a81343d232011-12-27 07:39:2030}
31
[email protected]6acde6352012-01-04 16:52:2032SiteInstance* GetSiteInstanceForNewTab(WebContents* source_contents,
[email protected]1ab4ddf2011-07-21 04:48:0433 Profile* profile,
34 const GURL& url) {
35 // 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
37 // as part of creating the tab.
38 ExtensionService* service = profile->GetExtensionService();
[email protected]863f70a2012-01-27 02:05:5039 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
40 profile, url) ||
[email protected]615d88f2011-12-13 01:47:4441 (service &&
42 service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) {
[email protected]b6583592012-01-25 19:52:3343 return SiteInstance::CreateForURL(profile, url);
[email protected]1ab4ddf2011-07-21 04:48:0444 }
45
46 if (!source_contents)
47 return NULL;
48
49 // Don't use this logic when "--process-per-tab" is specified.
50 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) &&
[email protected]627e0512011-12-21 22:55:3051 SiteInstance::IsSameWebSite(source_contents->GetBrowserContext(),
[email protected]1ab4ddf2011-07-21 04:48:0452 source_contents->GetURL(),
53 url)) {
54 return source_contents->GetSiteInstance();
55 }
56 return NULL;
57}
58
59} // namespace tab_util