diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-07 00:12:29 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-07 00:12:29 +0000 |
commit | 4814b51fe8210920ec1ebdde20c8deb9e65a1ff9 (patch) | |
tree | 1849897669aa067acc1751bfd16941872aacd855 /chrome/browser | |
parent | cb99b6afc24241e7e42e7e51ab1c51472ce9b43c (diff) | |
download | chromium_src-4814b51fe8210920ec1ebdde20c8deb9e65a1ff9.zip chromium_src-4814b51fe8210920ec1ebdde20c8deb9e65a1ff9.tar.gz chromium_src-4814b51fe8210920ec1ebdde20c8deb9e65a1ff9.tar.bz2 |
Make the inspector for the background page stay open when
reloading an extension.
BUG=25287
TEST=Load an extension that has a background page and reload it. Inspector should stay open and continue
working.
Review URL: http://codereview.chromium.org/371040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.cc | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 43 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 20 |
4 files changed, 75 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index 06f3d58..64419bf 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -111,6 +111,17 @@ ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( return host; } +ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension( + Extension* extension) { + for (ExtensionHostSet::iterator iter = background_hosts_.begin(); + iter != background_hosts_.end(); ++iter) { + ExtensionHost* host = *iter; + if (host->extension() == extension) + return host; + } + return NULL; +} + void ExtensionProcessManager::RegisterExtensionProcess( const std::string& extension_id, int process_id) { ProcessIDMap::const_iterator it = process_ids_.find(extension_id); diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h index d2d62ef..f399a0b 100644 --- a/chrome/browser/extensions/extension_process_manager.h +++ b/chrome/browser/extensions/extension_process_manager.h @@ -55,6 +55,10 @@ class ExtensionProcessManager : public NotificationObserver { // displayed anywhere. ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url); + // Gets the ExtensionHost for the background page for an extension, or NULL if + // the extension isn't running or doesn't have a background page. + ExtensionHost* GetBackgroundHostForExtension(Extension* extension); + // Returns the SiteInstance that the given URL belongs to. SiteInstance* GetSiteInstanceForURL(const GURL& url); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index a2193ef..2323e6dd 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -12,11 +12,13 @@ #include "base/values.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_dom_ui.h" #include "chrome/browser/extensions/extension_file_util.h" #include "chrome/browser/extensions/extension_history_api.h" +#include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_updater.h" #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/external_pref_extension_provider.h" @@ -27,6 +29,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_error_reporter.h" #include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/url_constants.h" @@ -99,6 +102,9 @@ ExtensionsService::ExtensionsService(Profile* profile, extensions_enabled_ = false; } + registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, + NotificationService::AllSources()); + // Set up the ExtensionUpdater if (autoupdate_enabled) { int update_frequency = kDefaultUpdateFrequencySeconds; @@ -171,6 +177,20 @@ void ExtensionsService::ReloadExtension(const std::string& extension_id) { // Unload the extension if it's loaded. It might not be loaded if it crashed. if (current_extension) { + // If the extension has an inspector open for its background page, detach + // the inspector and hang onto a cookie for it, so that we can reattach + // later. + ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); + ExtensionHost* host = manager->GetBackgroundHostForExtension( + current_extension); + if (host) { + // Look for an open inspector for the background page. + int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( + host->render_view_host()); + if (devtools_cookie >= 0) + orphaned_dev_tools_[extension_id] = devtools_cookie; + } + path = current_extension->path(); UnloadExtension(extension_id); } @@ -757,6 +777,29 @@ std::vector<FilePath> ExtensionsService::GetTransientBlacklistPaths() { return result; } +void ExtensionsService::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: { + ExtensionHost* host = Details<ExtensionHost>(details).ptr(); + OrphanedDevTools::iterator iter = + orphaned_dev_tools_.find(host->extension()->id()); + if (iter == orphaned_dev_tools_.end()) + return; + + DevToolsManager::GetInstance()->AttachClientHost( + iter->second, host->render_view_host()); + orphaned_dev_tools_.erase(iter); + break; + } + + default: + NOTREACHED() << "Unexpected notification type."; + } +} + + // ExtensionsServicesBackend ExtensionsServiceBackend::ExtensionsServiceBackend( diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index a73263d..60b17c3 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -22,6 +22,8 @@ #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" #include "chrome/browser/privacy_blacklist/blacklist_manager.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "chrome/common/extensions/extension.h" class Browser; @@ -51,11 +53,11 @@ class ExtensionUpdateService { // Manages installed and running Chromium extensions. class ExtensionsService - : public ExtensionUpdateService, + : public base::RefCountedThreadSafe<ExtensionsService>, public BlacklistPathProvider, - public base::RefCountedThreadSafe<ExtensionsService> { + public ExtensionUpdateService, + public NotificationObserver { public: - // The name of the directory inside the profile where extensions are // installed to. static const char* kInstallDirectoryName; @@ -226,6 +228,11 @@ class ExtensionsService virtual std::vector<FilePath> GetPersistentBlacklistPaths(); virtual std::vector<FilePath> GetTransientBlacklistPaths(); + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + private: friend class base::RefCountedThreadSafe<ExtensionsService>; @@ -279,6 +286,13 @@ class ExtensionsService // Our extension updater, if updates are turned on. scoped_refptr<ExtensionUpdater> updater_; + // Map of inspector cookies that are detached, waiting for an extension to be + // reloaded. + typedef std::map<std::string, int> OrphanedDevTools; + OrphanedDevTools orphaned_dev_tools_; + + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(ExtensionsService); }; |