Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2779)

Unified Diff: chrome/browser/tab_contents/tab_util.cc

Issue 7448012: Create the correct SiteInstance when restoring tabs that belong to apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/tab_util.cc
diff --git a/chrome/browser/tab_contents/tab_util.cc b/chrome/browser/tab_contents/tab_util.cc
index cef319d4fd018f26ae5d59dd679cbcb6b2d7bc3e..36e25606e900244f8a02bbd3cc21c3197e6af39e 100644
--- a/chrome/browser/tab_contents/tab_util.cc
+++ b/chrome/browser/tab_contents/tab_util.cc
@@ -1,15 +1,22 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
+#include "chrome/common/chrome_switches.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
+#include "content/browser/site_instance.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "googleurl/src/gurl.h"
-TabContents* tab_util::GetTabContentsByID(int render_process_id,
- int render_view_id) {
+namespace tab_util {
+
+TabContents* GetTabContentsByID(int render_process_id, int render_view_id) {
RenderViewHost* render_view_host =
RenderViewHost::FromID(render_process_id, render_view_id);
if (!render_view_host)
@@ -17,3 +24,30 @@ TabContents* tab_util::GetTabContentsByID(int render_process_id,
return render_view_host->delegate()->GetAsTabContents();
}
+
+SiteInstance* GetSiteInstanceForNewTab(TabContents* source_contents,
+ Profile* profile,
+ const GURL& url) {
+ // If url is a WebUI or extension, we need to be sure to use the right type
+ // of renderer process up front. Otherwise, we create a normal SiteInstance
+ // as part of creating the tab.
+ ExtensionService* service = profile->GetExtensionService();
+ if (ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, url) ||
+ (service && service->GetExtensionByWebExtent(url))) {
+ return SiteInstance::CreateSiteInstanceForURL(profile, url);
+ }
+
+ if (!source_contents)
+ return NULL;
+
+ // Don't use this logic when "--process-per-tab" is specified.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab) &&
+ SiteInstance::IsSameWebSite(source_contents->profile(),
+ source_contents->GetURL(),
+ url)) {
+ return source_contents->GetSiteInstance();
+ }
+ return NULL;
+}
+
+} // namespace tab_util

Powered by Google App Engine
This is Rietveld 408576698