blob: 9ed8c748ef2c6eaf874ba96f81d96c8ad0daa2a3 [file] [log] [blame]
[email protected]1ab4ddf2011-07-21 04:48:041// Copyright (c) 2011 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"
9#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
10#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]1ab4ddf2011-07-21 04:48:0412#include "content/browser/site_instance.h"
[email protected]5de634712011-03-02 00:20:1913#include "content/browser/tab_contents/tab_contents.h"
[email protected]1ab4ddf2011-07-21 04:48:0414#include "googleurl/src/gurl.h"
initial.commit09911bf2008-07-26 23:55:2915
[email protected]1ab4ddf2011-07-21 04:48:0416namespace tab_util {
17
18TabContents* GetTabContentsByID(int render_process_id, int render_view_id) {
initial.commit09911bf2008-07-26 23:55:2919 RenderViewHost* render_view_host =
20 RenderViewHost::FromID(render_process_id, render_view_id);
21 if (!render_view_host)
22 return NULL;
23
[email protected]57c6a652009-05-04 07:58:3424 return render_view_host->delegate()->GetAsTabContents();
initial.commit09911bf2008-07-26 23:55:2925}
[email protected]1ab4ddf2011-07-21 04:48:0426
27SiteInstance* GetSiteInstanceForNewTab(TabContents* source_contents,
28 Profile* profile,
29 const GURL& url) {
30 // If url is a WebUI or extension, we need to be sure to use the right type
31 // of renderer process up front. Otherwise, we create a normal SiteInstance
32 // as part of creating the tab.
33 ExtensionService* service = profile->GetExtensionService();
34 if (ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, url) ||
[email protected]615d88f2011-12-13 01:47:4435 (service &&
36 service->extensions()->GetHostedAppByURL(ExtensionURLInfo(url)))) {
[email protected]1ab4ddf2011-07-21 04:48:0437 return SiteInstance::CreateSiteInstanceForURL(profile, url);
38 }
39
40 if (!source_contents)
41 return NULL;
42
43 // Don't use this logic when "--process-per-tab" is specified.
44 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) &&
[email protected]627e0512011-12-21 22:55:3045 SiteInstance::IsSameWebSite(source_contents->GetBrowserContext(),
[email protected]1ab4ddf2011-07-21 04:48:0446 source_contents->GetURL(),
47 url)) {
48 return source_contents->GetSiteInstance();
49 }
50 return NULL;
51}
52
53} // namespace tab_util