diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 17:12:21 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-23 17:12:21 +0000 |
commit | da5683db1bbf401694c72f7d4216f38249ac2c13 (patch) | |
tree | 458e91e25e3c033bf1296de4b58e24cb1b7022d9 /chrome/browser | |
parent | 77a6970c962882244b57219681acd109acd9f3fc (diff) | |
download | chromium_src-da5683db1bbf401694c72f7d4216f38249ac2c13.zip chromium_src-da5683db1bbf401694c72f7d4216f38249ac2c13.tar.gz chromium_src-da5683db1bbf401694c72f7d4216f38249ac2c13.tar.bz2 |
Don't hold the installed app in BrowserProcessRenderHost, since that's in content layer now. ExtensionService keeps a map from renderer child ids to installed extensions instead.
Review URL: http://codereview.chromium.org/6880089
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/automation_util.cc | 31 | ||||
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 20 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/isolated_app_apitest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/notifications/balloon_host.cc | 6 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.cc | 15 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.h | 11 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 14 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_render_message_filter.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sidebar/sidebar_container.cc | 8 |
13 files changed, 94 insertions, 53 deletions
diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc index 98c9c6f..89224ef 100644 --- a/chrome/browser/automation/automation_util.cc +++ b/chrome/browser/automation/automation_util.cc @@ -11,12 +11,13 @@ #include "base/values.h" #include "chrome/browser/automation/automation_provider.h" #include "chrome/browser/automation/automation_provider_json.h" +#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser.h" #include "content/browser/browser_thread.h" -#include "content/browser/renderer_host/browser_render_process_host.h" +#include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "net/base/cookie_monster.h" @@ -105,19 +106,21 @@ TabContents* GetTabContentsAt(int browser_index, int tab_index) { return browser->GetTabContentsAt(tab_index); } +net::URLRequestContextGetter* GetRequestContext(TabContents* contents) { + // Since we may be on the UI thread don't call GetURLRequestContext(). + // Get the request context specific to the current TabContents and app. + return contents->profile()->GetRequestContextForRenderProcess( + contents->render_view_host()->process()->id()); +} + void GetCookies(const GURL& url, TabContents* contents, int* value_size, std::string* value) { *value_size = -1; if (url.is_valid() && contents) { - // Since we may be on the UI thread don't call GetURLRequestContext(). - // Get the request context specific to the current TabContents and app. - const Extension* installed_app = static_cast<BrowserRenderProcessHost*>( - contents->render_view_host()->process())->installed_app(); scoped_refptr<net::URLRequestContextGetter> context_getter = - contents->profile()->GetRequestContextForPossibleApp(installed_app); - + GetRequestContext(contents); base::WaitableEvent event(true /* manual reset */, false /* not initially signaled */); CHECK(BrowserThread::PostTask( @@ -137,13 +140,8 @@ void SetCookie(const GURL& url, *response_value = -1; if (url.is_valid() && contents) { - // Since we may be on the UI thread don't call GetURLRequestContext(). - // Get the request context specific to the current TabContents and app. - const Extension* installed_app = static_cast<BrowserRenderProcessHost*>( - contents->render_view_host()->process())->installed_app(); scoped_refptr<net::URLRequestContextGetter> context_getter = - contents->profile()->GetRequestContextForPossibleApp(installed_app); - + GetRequestContext(contents); base::WaitableEvent event(true /* manual reset */, false /* not initially signaled */); bool success = false; @@ -164,13 +162,8 @@ void DeleteCookie(const GURL& url, bool* success) { *success = false; if (url.is_valid() && contents) { - // Since we may be on the UI thread don't call GetURLRequestContext(). - // Get the request context specific to the current TabContents and app. - const Extension* installed_app = static_cast<BrowserRenderProcessHost*>( - contents->render_view_host()->process())->installed_app(); scoped_refptr<net::URLRequestContextGetter> context_getter = - contents->profile()->GetRequestContextForPossibleApp(installed_app); - + GetRequestContext(contents); base::WaitableEvent event(true /* manual reset */, false /* not initially signaled */); CHECK(BrowserThread::PostTask( diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 0ba282b..4a1264d 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -37,8 +37,10 @@ void ChromeContentBrowserClient::PreCreateRenderView( render_view_host->set_is_extension_process(is_extension_process); const Extension* installed_app = service->GetInstalledApp(url); - static_cast<BrowserRenderProcessHost*>(render_view_host->process())-> - set_installed_app(installed_app); + if (installed_app) { + service->SetInstalledAppForRenderer( + render_view_host->process()->id(), installed_app); + } } } @@ -47,8 +49,7 @@ void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( host->channel()->AddFilter(new ChromeRenderMessageFilter( host->id(), host->profile(), - host->profile()->GetRequestContextForPossibleApp( - host->installed_app()))); + host->profile()->GetRequestContextForRenderProcess(host->id()))); host->channel()->AddFilter(new PrintingMessageFilter()); host->channel()->AddFilter( new SearchProviderInstallStateMessageFilter(host->id(), host->profile())); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 11859e9..74f28e3 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -135,9 +135,8 @@ ExtensionHost::ExtensionHost(const Extension* extension, NULL); render_view_host_->set_is_extension_process(true); if (extension->is_app()) { - BrowserRenderProcessHost* process = static_cast<BrowserRenderProcessHost*>( - render_view_host_->process()); - process->set_installed_app(extension); + profile()->GetExtensionService()->SetInstalledAppForRenderer( + render_view_host_->process()->id(), extension); } render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); if (enable_dom_automation_) diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 00f1800..0462912 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -377,6 +377,19 @@ bool ExtensionService::IsInstalledApp(const GURL& url) { return !!GetInstalledApp(url); } +void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, + const Extension* app) { + installed_app_hosts_[renderer_child_id] = app; +} + +const Extension* ExtensionService::GetInstalledAppForRenderer( + int renderer_child_id) { + InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); + if (i == installed_app_hosts_.end()) + return NULL; + return i->second; +} + // static // This function is used to implement the command-line switch // --uninstall-extension. The LOG statements within this function are used to @@ -440,6 +453,8 @@ ExtensionService::ExtensionService(Profile* profile, NotificationService::AllSources()); registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, NotificationService::AllSources()); + registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, + NotificationService::AllSources()); pref_change_registrar_.Init(profile->GetPrefs()); pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); @@ -2062,6 +2077,11 @@ void ExtensionService::Observe(NotificationType type, } break; } + case NotificationType::RENDERER_PROCESS_TERMINATED: { + RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); + installed_app_hosts_.erase(process->id()); + break; + } case NotificationType::PREF_CHANGED: { std::string* pref_name = Details<std::string>(details).ptr(); if (*pref_name == prefs::kExtensionInstallAllowList || diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index eb87da9..5898605 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -156,6 +156,13 @@ class ExtensionService // Returns whether the URL is from either a hosted or packaged app. bool IsInstalledApp(const GURL& url); + // Associates a renderer process with the given installed app. + void SetInstalledAppForRenderer(int renderer_child_id, const Extension* app); + + // If the renderer is hosting an installed app, returns it, otherwise returns + // NULL. + const Extension* GetInstalledAppForRenderer(int renderer_child_id); + // Attempts to uninstall an extension from a given ExtensionService. Returns // true iff the target extension exists. static bool UninstallExtensionHelper(ExtensionService* extensions_service, @@ -578,6 +585,11 @@ class ExtensionService // The map of extension IDs to their runtime data. ExtensionRuntimeDataMap extension_runtime_data_; + // Holds a map between renderer process IDs that are associated with an + // installed app and their app. + typedef std::map<int, scoped_refptr<const Extension> > InstalledAppMap; + InstalledAppMap installed_app_hosts_; + // The full path to the directory where extensions are installed. FilePath install_directory_; diff --git a/chrome/browser/extensions/isolated_app_apitest.cc b/chrome/browser/extensions/isolated_app_apitest.cc index bc9e221..ed69e42 100644 --- a/chrome/browser/extensions/isolated_app_apitest.cc +++ b/chrome/browser/extensions/isolated_app_apitest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/automation/automation_util.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_host.h" +#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" @@ -29,8 +30,13 @@ class IsolatedAppApiTest : public ExtensionApiTest { } const Extension* GetInstalledApp(TabContents* contents) { - return static_cast<BrowserRenderProcessHost*>( - contents->render_view_host()->process())->installed_app(); + const Extension* installed_app = NULL; + ExtensionService* service = contents->profile()->GetExtensionService(); + if (service) { + installed_app = service->GetInstalledAppForRenderer( + contents->render_view_host()->process()->id()); + } + return installed_app; } }; diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index 3ff9344..ff6a035 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -206,8 +206,10 @@ void BalloonHost::Init() { const Extension* installed_app = GetProfile()->GetExtensionService()->GetInstalledApp( balloon_->notification().content_url()); - static_cast<BrowserRenderProcessHost*>(rvh->process())->set_installed_app( - installed_app); + if (installed_app) { + GetProfile()->GetExtensionService()->SetInstalledAppForRenderer( + rvh->process()->id(), installed_app); + } } else if (enable_web_ui_) { rvh->AllowBindings(BindingsPolicy::WEB_UI); } diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index 5fc6a13..7ed0c6c 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -21,6 +21,7 @@ #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extension_pref_store.h" #include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/net/pref_proxy_config_service.h" #include "chrome/browser/prefs/pref_service.h" @@ -406,13 +407,15 @@ class OffTheRecordProfileImpl : public Profile, return io_data_.GetMainRequestContextGetter(); } - virtual net::URLRequestContextGetter* GetRequestContextForPossibleApp( - const Extension* installed_app) { + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id) { if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableExperimentalAppManifests) && - installed_app != NULL && - installed_app->is_storage_isolated()) - return GetRequestContextForIsolatedApp(installed_app->id()); + switches::kEnableExperimentalAppManifests)) { + const Extension* installed_app = GetExtensionService()-> + GetInstalledAppForRenderer(renderer_child_id); + if (installed_app != NULL && installed_app->is_storage_isolated()) + return GetRequestContextForIsolatedApp(installed_app->id()); + } return GetRequestContext(); } diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index ad93c6c..80e8bdf 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -333,13 +333,14 @@ class Profile { // happen on the UI thread. virtual net::URLRequestContextGetter* GetRequestContext() = 0; - // Returns the request context appropriate for the given app. If installed_app - // is null or installed_app->is_storage_isolated() returns false, this is - // equivalent to calling GetRequestContext(). + // Returns the request context appropriate for the given renderer. If the + // renderer process doesn't have an assosicated installed app, or if the + // installed app's is_storage_isolated() returns false, this is equivalent to + // calling GetRequestContext(). // TODO(creis): After isolated app storage is no longer an experimental // feature, consider making this the default contract for GetRequestContext. - virtual net::URLRequestContextGetter* GetRequestContextForPossibleApp( - const Extension* installed_app) = 0; + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id) = 0; // Returns the request context for media resources asociated with this // profile. diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index d132545..cff96f9 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -879,13 +879,15 @@ net::URLRequestContextGetter* ProfileImpl::GetRequestContext() { return request_context; } -net::URLRequestContextGetter* ProfileImpl::GetRequestContextForPossibleApp( - const Extension* installed_app) { +net::URLRequestContextGetter* ProfileImpl::GetRequestContextForRenderProcess( + int renderer_child_id) { if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableExperimentalAppManifests) && - installed_app != NULL && - installed_app->is_storage_isolated()) - return GetRequestContextForIsolatedApp(installed_app->id()); + switches::kEnableExperimentalAppManifests)) { + const Extension* installed_app = extension_service_-> + GetInstalledAppForRenderer(renderer_child_id); + if (installed_app != NULL && installed_app->is_storage_isolated()) + return GetRequestContextForIsolatedApp(installed_app->id()); + } return GetRequestContext(); } diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index c28204f..027715c 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -81,8 +81,8 @@ class ProfileImpl : public Profile, virtual fileapi::FileSystemContext* GetFileSystemContext(); virtual bool HasCreatedDownloadManager() const; virtual net::URLRequestContextGetter* GetRequestContext(); - virtual net::URLRequestContextGetter* GetRequestContextForPossibleApp( - const Extension* installed_app); + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id); virtual net::URLRequestContextGetter* GetRequestContextForMedia(); virtual net::URLRequestContextGetter* GetRequestContextForExtensions(); virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp( diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index 8094fe5..77aac3c 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -195,7 +195,7 @@ void ChromeRenderMessageFilter::OpenChannelToTabOnUIThread( void ChromeRenderMessageFilter::OnGetExtensionMessageBundle( const std::string& extension_id, IPC::Message* reply_msg) { ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( - request_context_->GetURLRequestContext()); + request_context_->GetURLRequestContext()); FilePath extension_path = context->extension_info_map()->GetPathForExtension(extension_id); diff --git a/chrome/browser/sidebar/sidebar_container.cc b/chrome/browser/sidebar/sidebar_container.cc index 1c1c2ac..99c69a5 100644 --- a/chrome/browser/sidebar/sidebar_container.cc +++ b/chrome/browser/sidebar/sidebar_container.cc @@ -35,9 +35,11 @@ SidebarContainer::SidebarContainer(TabContents* tab, sidebar_contents_->render_view_host()->set_is_extension_process(true); const Extension* extension = GetExtension(); if (extension && extension->is_app()) { - BrowserRenderProcessHost* process = static_cast<BrowserRenderProcessHost*>( - sidebar_contents_->render_view_host()->process()); - process->set_installed_app(extension); + ExtensionService* service = tab->profile()->GetExtensionService(); + if (service) { + service->SetInstalledAppForRenderer( + sidebar_contents_->render_view_host()->process()->id(), extension); + } } sidebar_contents_->render_view_host()->AllowBindings( BindingsPolicy::EXTENSION); |