summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 04:48:04 +0000
committermihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 04:48:04 +0000
commit1ab4ddf6636cdb88ea138aa5820ddeed29f72b98 (patch)
tree21d3e76e58c677353fe2729a1e021f727563975f
parentde6bcb042602c73fba8b5e603dc8be45eb819f39 (diff)
downloadchromium_src-1ab4ddf6636cdb88ea138aa5820ddeed29f72b98.zip
chromium_src-1ab4ddf6636cdb88ea138aa5820ddeed29f72b98.tar.gz
chromium_src-1ab4ddf6636cdb88ea138aa5820ddeed29f72b98.tar.bz2
Create the correct SiteInstance when restoring tabs that belong to apps.
BUG=89371 TEST=see bug Review URL: http://codereview.chromium.org/7448012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93337 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_content_browser_client.cc3
-rw-r--r--chrome/browser/tab_contents/tab_util.cc40
-rw-r--r--chrome/browser/tab_contents/tab_util.h12
-rw-r--r--chrome/browser/ui/browser.cc11
-rw-r--r--chrome/browser/ui/browser_navigator.cc33
-rw-r--r--content/browser/tab_contents/render_view_host_manager.cc3
6 files changed, 63 insertions, 39 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index c2f46ad..16456aa 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -83,7 +83,6 @@ void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
// chrome-extension:// URL for their site, so we can ignore that wrinkle here.
SiteInstance* site_instance = render_view_host->site_instance();
const GURL& site = site_instance->site();
- RenderProcessHost* process = render_view_host->process();
if (!site.SchemeIs(chrome::kExtensionScheme))
return;
@@ -110,6 +109,8 @@ void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
process_manager->RegisterExtensionSiteInstance(site_instance->id(),
extension->id());
+ RenderProcessHost* process = render_view_host->process();
+
if (extension->is_app()) {
render_view_host->Send(
new ExtensionMsg_ActivateApplication(extension->id()));
diff --git a/chrome/browser/tab_contents/tab_util.cc b/chrome/browser/tab_contents/tab_util.cc
index cef319d..36e2560 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
diff --git a/chrome/browser/tab_contents/tab_util.h b/chrome/browser/tab_contents/tab_util.h
index 896be7c..6362d77 100644
--- a/chrome/browser/tab_contents/tab_util.h
+++ b/chrome/browser/tab_contents/tab_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -6,6 +6,9 @@
#define CHROME_BROWSER_TAB_CONTENTS_TAB_UTIL_H_
#pragma once
+class GURL;
+class Profile;
+class SiteInstance;
class TabContents;
namespace tab_util {
@@ -15,6 +18,13 @@ namespace tab_util {
// Should only be called from the UI thread, since it accesses TabContent.
TabContents* GetTabContentsByID(int render_process_host_id, int routing_id);
+// Returns a new SiteInstance for WebUI and app URLs. Returns the SiteInstance
+// for |source_contents| if it represents the same website as |url|. Returns
+// NULL otherwise.
+SiteInstance* GetSiteInstanceForNewTab(TabContents* source_contents,
+ Profile* profile,
+ const GURL& url);
+
} // namespace tab_util
#endif // CHROME_BROWSER_TAB_CONTENTS_TAB_UTIL_H_
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 4365161..e84ce48 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -69,6 +69,7 @@
#include "chrome/browser/tab_closeable_state_watcher.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
+#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/tabs/tab_finder.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/themes/theme_service.h"
@@ -1152,7 +1153,10 @@ TabContents* Browser::AddRestoredTab(
bool pin,
bool from_last_session,
SessionStorageNamespace* session_storage_namespace) {
- TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL,
+ GURL restore_url = navigations.at(selected_navigation).virtual_url();
+ TabContentsWrapper* wrapper = TabContentsFactory(
+ profile(),
+ tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url),
MSG_ROUTING_NONE,
GetSelectedTabContents(),
session_storage_namespace);
@@ -1198,7 +1202,10 @@ void Browser::ReplaceRestoredTab(
bool from_last_session,
const std::string& extension_app_id,
SessionStorageNamespace* session_storage_namespace) {
- TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL,
+ GURL restore_url = navigations.at(selected_navigation).virtual_url();
+ TabContentsWrapper* wrapper = TabContentsFactory(
+ profile(),
+ tab_util::GetSiteInstanceForNewTab(NULL, profile_, restore_url),
MSG_ROUTING_NONE,
GetSelectedTabContents(),
session_storage_namespace);
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index 6075d73..ff2645e 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -12,15 +12,14 @@
#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/status_bubble.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
#include "chrome/browser/web_applications/web_app.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
#include "content/browser/browser_url_handler.h"
@@ -29,33 +28,6 @@
namespace {
-// Returns an appropriate SiteInstance for WebUI URLs, or the SiteInstance for
-// |source_contents| if it represents the same website as |url|. Returns NULL
-// otherwise.
-SiteInstance* GetSiteInstance(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;
-}
-
// Returns true if the specified Browser can open tabs. Not all Browsers support
// multiple tabs, such as app frames and popups. This function returns false for
// those types of Browser.
@@ -412,7 +384,8 @@ void Navigate(NavigateParams* params) {
params->target_contents =
Browser::TabContentsFactory(
params->browser->profile(),
- GetSiteInstance(source_contents, params->browser->profile(), url),
+ tab_util::GetSiteInstanceForNewTab(
+ source_contents, params->browser->profile(), url),
MSG_ROUTING_NONE,
source_contents,
NULL);
diff --git a/content/browser/tab_contents/render_view_host_manager.cc b/content/browser/tab_contents/render_view_host_manager.cc
index 7d2dc58..3386f24 100644
--- a/content/browser/tab_contents/render_view_host_manager.cc
+++ b/content/browser/tab_contents/render_view_host_manager.cc
@@ -670,8 +670,7 @@ RenderViewHost* RenderViewHostManager::UpdateRendererStateForNavigate(
// is safe to use a normal pointer here.
SiteInstance* new_instance = curr_instance;
bool force_swap = ShouldSwapProcessesForNavigation(
- delegate_->GetLastCommittedNavigationEntryForRenderManager(),
- &entry);
+ delegate_->GetLastCommittedNavigationEntryForRenderManager(), &entry);
if (ShouldTransitionCrossSite() || force_swap)
new_instance = GetSiteInstanceForEntry(entry, curr_instance);