diff options
author | limasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-22 19:49:58 +0000 |
---|---|---|
committer | limasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-22 19:49:58 +0000 |
commit | 96ac5969e6f5f48c093faba2beaa6648f8ef6600 (patch) | |
tree | 1a72b0df5a5cfd91b069725dc2a99ac197f1e008 | |
parent | 76ba92dce754205e0fa6487467cd81a6632c3948 (diff) | |
download | chromium_src-96ac5969e6f5f48c093faba2beaa6648f8ef6600.zip chromium_src-96ac5969e6f5f48c093faba2beaa6648f8ef6600.tar.gz chromium_src-96ac5969e6f5f48c093faba2beaa6648f8ef6600.tar.bz2 |
Remove some NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED
from c/b/extension
and some cleanup.
BUG=354046
Review URL: https://codereview.chromium.org/244143002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265336 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 343 insertions, 333 deletions
diff --git a/chrome/browser/extensions/active_tab_permission_granter.cc b/chrome/browser/extensions/active_tab_permission_granter.cc index 51ea1f2..ef87525 100644 --- a/chrome/browser/extensions/active_tab_permission_granter.cc +++ b/chrome/browser/extensions/active_tab_permission_granter.cc @@ -4,19 +4,11 @@ #include "chrome/browser/extensions/active_tab_permission_granter.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sessions/session_id.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" #include "extensions/browser/extension_registry.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/extension.h" #include "extensions/common/extension_messages.h" #include "extensions/common/permissions/permission_set.h" #include "extensions/common/permissions/permissions_data.h" @@ -28,10 +20,13 @@ using content::WebContentsObserver; namespace extensions { ActiveTabPermissionGranter::ActiveTabPermissionGranter( - content::WebContents* web_contents, int tab_id, Profile* profile) - : WebContentsObserver(web_contents), tab_id_(tab_id), - scoped_extension_registry_observer_(this) { - scoped_extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); + content::WebContents* web_contents, + int tab_id, + Profile* profile) + : WebContentsObserver(web_contents), + tab_id_(tab_id), + extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); } ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} diff --git a/chrome/browser/extensions/active_tab_permission_granter.h b/chrome/browser/extensions/active_tab_permission_granter.h index be02bd08..bf51ed0 100644 --- a/chrome/browser/extensions/active_tab_permission_granter.h +++ b/chrome/browser/extensions/active_tab_permission_granter.h @@ -66,8 +66,8 @@ class ActiveTabPermissionGranter ExtensionSet granted_extensions_; // Listen to extension unloaded notifications. - ScopedObserver<ExtensionRegistry, - ExtensionRegistryObserver> scoped_extension_registry_observer_; + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter); }; diff --git a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc index 6b11c14..61f6da26 100644 --- a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc +++ b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc @@ -72,11 +72,10 @@ const Extension* GetExtensionById(Profile* profile, } // namespace GalleryWatchStateTracker::GalleryWatchStateTracker(Profile* profile) - : profile_(profile), - scoped_extension_registry_observer_(this) { + : profile_(profile), extension_registry_observer_(this) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(profile_); - scoped_extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); MediaGalleriesPreferences* preferences = g_browser_process->media_file_system_registry()->GetPreferences(profile); preferences->AddGalleryChangeObserver(this); diff --git a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h index 53e082b..7443166 100644 --- a/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h +++ b/chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.h @@ -138,8 +138,8 @@ class GalleryWatchStateTracker // Current profile. Profile* profile_; - ScopedObserver<ExtensionRegistry, - ExtensionRegistryObserver> scoped_extension_registry_observer_; + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; // A map of watched gallery details, per extension. WatchedExtensionsMap watched_extensions_map_; diff --git a/chrome/browser/extensions/extension_action_manager.cc b/chrome/browser/extensions/extension_action_manager.cc index 98e2466..b4799741 100644 --- a/chrome/browser/extensions/extension_action_manager.cc +++ b/chrome/browser/extensions/extension_action_manager.cc @@ -4,23 +4,14 @@ #include "chrome/browser/extensions/extension_action_manager.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/api/system_indicator/system_indicator_manager.h" #include "chrome/browser/extensions/api/system_indicator/system_indicator_manager_factory.h" #include "chrome/browser/extensions/extension_action.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/extensions/api/extension_action/action_info.h" -#include "chrome/common/extensions/api/extension_action/page_action_handler.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" -#include "components/keyed_service/content/browser_context_keyed_service_factory.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" #include "extensions/browser/extensions_browser_client.h" -#include "extensions/common/extension.h" -#include "extensions/common/feature_switch.h" namespace extensions { @@ -65,11 +56,10 @@ ExtensionActionManagerFactory::GetInstance() { } // namespace ExtensionActionManager::ExtensionActionManager(Profile* profile) - : profile_(profile), - scoped_extension_registry_observer_(this) { + : profile_(profile), extension_registry_observer_(this) { CHECK_EQ(profile, profile->GetOriginalProfile()) << "Don't instantiate this with an incognito profile."; - scoped_extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); } ExtensionActionManager::~ExtensionActionManager() { diff --git a/chrome/browser/extensions/extension_action_manager.h b/chrome/browser/extensions/extension_action_manager.h index 3315bdc..b78e8a2 100644 --- a/chrome/browser/extensions/extension_action_manager.h +++ b/chrome/browser/extensions/extension_action_manager.h @@ -8,7 +8,6 @@ #include <map> #include <string> -#include "base/memory/linked_ptr.h" #include "base/scoped_observer.h" #include "components/keyed_service/core/keyed_service.h" #include "extensions/browser/extension_registry_observer.h" @@ -52,8 +51,8 @@ class ExtensionActionManager : public KeyedService, Profile* profile_; // Listen to extension unloaded notifications. - ScopedObserver<ExtensionRegistry, - ExtensionRegistryObserver> scoped_extension_registry_observer_; + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; // Keyed by Extension ID. These maps are populated lazily when their // ExtensionAction is first requested, and the entries are removed when the diff --git a/chrome/browser/extensions/extension_gcm_app_handler.cc b/chrome/browser/extensions/extension_gcm_app_handler.cc index 86ef5bb..879a351 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler.cc +++ b/chrome/browser/extensions/extension_gcm_app_handler.cc @@ -44,14 +44,9 @@ ExtensionGCMAppHandler::GetFactoryInstance() { ExtensionGCMAppHandler::ExtensionGCMAppHandler(content::BrowserContext* context) : profile_(Profile::FromBrowserContext(context)), + extension_registry_observer_(this), weak_factory_(this) { - // Listen to various extension related notifications. - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile_)); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile_)); + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, content::Source<Profile>(profile_)); @@ -100,38 +95,34 @@ void ExtensionGCMAppHandler::OnSendError( #endif } +void ExtensionGCMAppHandler::OnExtensionLoaded( + content::BrowserContext* browser_context, + const Extension* extension) { + if (IsGCMPermissionEnabled(extension)) + GetGCMProfileService()->AddAppHandler(extension->id(), this); +} + +void ExtensionGCMAppHandler::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + if (IsGCMPermissionEnabled(extension)) + GetGCMProfileService()->RemoveAppHandler(extension->id()); +} + void ExtensionGCMAppHandler::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { - const Extension* extension = content::Details<Extension>(details).ptr(); - if (IsGCMPermissionEnabled(extension)) - GetGCMProfileService()->AddAppHandler(extension->id(), this); - break; - } - case chrome:: NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { - const Extension* extension = - content::Details<UnloadedExtensionInfo>(details)->extension; - if (IsGCMPermissionEnabled(extension)) - GetGCMProfileService()->RemoveAppHandler(extension->id()); - break; - } - case chrome:: NOTIFICATION_EXTENSION_UNINSTALLED: { - const Extension* extension = content::Details<Extension>(details).ptr(); - if (IsGCMPermissionEnabled(extension)) { - GetGCMProfileService()->Unregister( - extension->id(), - base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, - weak_factory_.GetWeakPtr(), - extension->id())); - GetGCMProfileService()->RemoveAppHandler(extension->id()); - } - break; - } - default: - NOTREACHED(); + DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); + const Extension* extension = content::Details<Extension>(details).ptr(); + if (IsGCMPermissionEnabled(extension)) { + GetGCMProfileService()->Unregister( + extension->id(), + base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, + weak_factory_.GetWeakPtr(), + extension->id())); + GetGCMProfileService()->RemoveAppHandler(extension->id()); } } diff --git a/chrome/browser/extensions/extension_gcm_app_handler.h b/chrome/browser/extensions/extension_gcm_app_handler.h index c1fac2d..8e90ddf 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler.h +++ b/chrome/browser/extensions/extension_gcm_app_handler.h @@ -7,10 +7,12 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/scoped_observer.h" #include "chrome/browser/services/gcm/gcm_app_handler.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "extensions/browser/browser_context_keyed_api_factory.h" +#include "extensions/browser/extension_registry_observer.h" #include "google_apis/gcm/gcm_client.h" class Profile; @@ -23,12 +25,14 @@ class GCMProfileService; namespace extensions { +class ExtensionRegistry; class GcmJsEventRouter; // Defines the interface to provide handling logic for a given app. class ExtensionGCMAppHandler : public gcm::GCMAppHandler, public BrowserContextKeyedAPI, - public content::NotificationObserver { + public content::NotificationObserver, + public ExtensionRegistryObserver { public: explicit ExtensionGCMAppHandler(content::BrowserContext* context); virtual ~ExtensionGCMAppHandler(); @@ -59,6 +63,14 @@ class ExtensionGCMAppHandler : public gcm::GCMAppHandler, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; + gcm::GCMProfileService* GetGCMProfileService() const; // BrowserContextKeyedAPI implementation. @@ -68,6 +80,10 @@ class ExtensionGCMAppHandler : public gcm::GCMAppHandler, Profile* profile_; content::NotificationRegistrar registrar_; + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; + #if !defined(OS_ANDROID) scoped_ptr<extensions::GcmJsEventRouter> js_event_router_; #endif diff --git a/chrome/browser/extensions/extension_keybinding_registry.cc b/chrome/browser/extensions/extension_keybinding_registry.cc index 623f78e..d372e13 100644 --- a/chrome/browser/extensions/extension_keybinding_registry.cc +++ b/chrome/browser/extensions/extension_keybinding_registry.cc @@ -12,6 +12,7 @@ #include "chrome/common/extensions/command.h" #include "content/public/browser/browser_context.h" #include "extensions/browser/event_router.h" +#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" #include "extensions/common/extension_set.h" #include "extensions/common/manifest_constants.h" @@ -22,21 +23,19 @@ ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( content::BrowserContext* context, ExtensionFilter extension_filter, Delegate* delegate) - : profile_(Profile::FromBrowserContext(context)), + : browser_context_(context), extension_filter_(extension_filter), - delegate_(delegate) { - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile_->GetOriginalProfile())); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile_->GetOriginalProfile())); + delegate_(delegate), + extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); + + Profile* profile = Profile::FromBrowserContext(browser_context_); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, - content::Source<Profile>(profile_->GetOriginalProfile())); + content::Source<Profile>(profile->GetOriginalProfile())); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, - content::Source<Profile>(profile_->GetOriginalProfile())); + content::Source<Profile>(profile->GetOriginalProfile())); } ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { @@ -73,7 +72,7 @@ void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( void ExtensionKeybindingRegistry::Init() { ExtensionService* service = - extensions::ExtensionSystem::Get(profile_)->extension_service(); + ExtensionSystem::Get(browser_context_)->extension_service(); if (!service) return; // ExtensionService can be null during testing. @@ -98,7 +97,7 @@ bool ExtensionKeybindingRegistry::NotifyEventTargets( void ExtensionKeybindingRegistry::CommandExecuted( const std::string& extension_id, const std::string& command) { ExtensionService* service = - ExtensionSystem::Get(profile_)->extension_service(); + ExtensionSystem::Get(browser_context_)->extension_service(); const Extension* extension = service->extensions()->GetByID(extension_id); if (!extension) @@ -117,9 +116,9 @@ void ExtensionKeybindingRegistry::CommandExecuted( args->Append(new base::StringValue(command)); scoped_ptr<Event> event(new Event("commands.onCommand", args.Pass())); - event->restrict_to_browser_context = profile_; + event->restrict_to_browser_context = browser_context_; event->user_gesture = EventRouter::USER_GESTURE_ENABLED; - EventRouter::Get(profile_) + EventRouter::Get(browser_context_) ->DispatchEventToExtension(extension_id, event.Pass()); } @@ -165,34 +164,36 @@ void ExtensionKeybindingRegistry::ExecuteCommand( ExecuteCommands(accelerator, extension_id); } +void ExtensionKeybindingRegistry::OnExtensionLoaded( + content::BrowserContext* browser_context, + const Extension* extension) { + if (ExtensionMatchesFilter(extension)) + AddExtensionKeybinding(extension, std::string()); +} + +void ExtensionKeybindingRegistry::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + if (ExtensionMatchesFilter(extension)) + RemoveExtensionKeybinding(extension, std::string()); +} + void ExtensionKeybindingRegistry::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { - const extensions::Extension* extension = - content::Details<const extensions::Extension>(details).ptr(); - if (ExtensionMatchesFilter(extension)) - AddExtensionKeybinding(extension, std::string()); - break; - } - case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { - const extensions::Extension* extension = - content::Details<UnloadedExtensionInfo>(details)->extension; - if (ExtensionMatchesFilter(extension)) - RemoveExtensionKeybinding(extension, std::string()); - break; - } case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { std::pair<const std::string, const std::string>* payload = content::Details<std::pair<const std::string, const std::string> >( details).ptr(); - const extensions::Extension* extension = - ExtensionSystem::Get(profile_)->extension_service()-> - extensions()->GetByID(payload->first); + const Extension* extension = ExtensionSystem::Get(browser_context_) + ->extension_service() + ->extensions() + ->GetByID(payload->first); // During install and uninstall the extension won't be found. We'll catch // those events above, with the LOADED/UNLOADED, so we ignore this event. if (!extension) diff --git a/chrome/browser/extensions/extension_keybinding_registry.h b/chrome/browser/extensions/extension_keybinding_registry.h index 5c4cc50..1fb656c 100644 --- a/chrome/browser/extensions/extension_keybinding_registry.h +++ b/chrome/browser/extensions/extension_keybinding_registry.h @@ -10,12 +10,12 @@ #include <string> #include "base/compiler_specific.h" +#include "base/scoped_observer.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" - -class Profile; +#include "extensions/browser/extension_registry_observer.h" namespace content { class BrowserContext; @@ -29,11 +29,13 @@ namespace extensions { class ActiveTabPermissionGranter; class Extension; +class ExtensionRegistry; // The ExtensionKeybindingRegistry is a class that handles the cross-platform // logic for keyboard accelerators. See platform-specific implementations for // implementation details for each platform. -class ExtensionKeybindingRegistry : public content::NotificationObserver { +class ExtensionKeybindingRegistry : public content::NotificationObserver, + public ExtensionRegistryObserver { public: enum ExtensionFilter { ALL_EXTENSIONS, @@ -64,11 +66,6 @@ class ExtensionKeybindingRegistry : public content::NotificationObserver { void ExecuteCommand(const std::string& extension_id, const ui::Accelerator& accelerator); - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - protected: // Add extension keybinding for the events defined by the |extension|. // |command_name| is optional, but if not blank then only the command @@ -125,6 +122,19 @@ class ExtensionKeybindingRegistry : public content::NotificationObserver { bool IsEventTargetsEmpty() const; private: + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; + // Returns true if the |extension| matches our extension filter. bool ExtensionMatchesFilter(const extensions::Extension* extension); @@ -138,8 +148,7 @@ class ExtensionKeybindingRegistry : public content::NotificationObserver { // The content notification registrar for listening to extension events. content::NotificationRegistrar registrar_; - // Weak pointer to our profile. Not owned by us. - Profile* profile_; + content::BrowserContext* browser_context_; // What extensions to register keybindings for. ExtensionFilter extension_filter_; @@ -158,6 +167,10 @@ class ExtensionKeybindingRegistry : public content::NotificationObserver { typedef std::map<ui::Accelerator, TargetList> EventTargets; EventTargets event_targets_; + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; + DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); }; diff --git a/chrome/browser/extensions/extension_warning_service.cc b/chrome/browser/extensions/extension_warning_service.cc index bfb9977..ab929a2 100644 --- a/chrome/browser/extensions/extension_warning_service.cc +++ b/chrome/browser/extensions/extension_warning_service.cc @@ -4,28 +4,23 @@ #include "chrome/browser/extensions/extension_warning_service.h" -#include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" -#include "extensions/common/extension.h" using content::BrowserThread; namespace extensions { ExtensionWarningService::ExtensionWarningService(Profile* profile) - : profile_(profile), - scoped_extension_registry_observer_(this) { + : profile_(profile), extension_registry_observer_(this) { DCHECK(CalledOnValidThread()); if (profile_) { - scoped_extension_registry_observer_.Add( + extension_registry_observer_.Add( ExtensionRegistry::Get(profile_->GetOriginalProfile())); } } diff --git a/chrome/browser/extensions/extension_warning_service.h b/chrome/browser/extensions/extension_warning_service.h index 5a6ecf7..c311859 100644 --- a/chrome/browser/extensions/extension_warning_service.h +++ b/chrome/browser/extensions/extension_warning_service.h @@ -85,8 +85,8 @@ class ExtensionWarningService : public ExtensionRegistryObserver, Profile* profile_; // Listen to extension unloaded notifications. - ScopedObserver<ExtensionRegistry, - ExtensionRegistryObserver> scoped_extension_registry_observer_; + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; ObserverList<Observer> observer_list_; }; diff --git a/chrome/browser/extensions/extension_web_ui_override_registrar.cc b/chrome/browser/extensions/extension_web_ui_override_registrar.cc index 56c84a6..a0ffd99 100644 --- a/chrome/browser/extensions/extension_web_ui_override_registrar.cc +++ b/chrome/browser/extensions/extension_web_ui_override_registrar.cc @@ -5,44 +5,36 @@ #include "chrome/browser/extensions/extension_web_ui_override_registrar.h" #include "base/lazy_instance.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_web_ui.h" #include "chrome/browser/profiles/profile.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_service.h" +#include "extensions/browser/extension_registry.h" namespace extensions { ExtensionWebUIOverrideRegistrar::ExtensionWebUIOverrideRegistrar( content::BrowserContext* context) - : profile_(Profile::FromBrowserContext(context)) { - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile_)); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile_)); + : extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(context)); } ExtensionWebUIOverrideRegistrar::~ExtensionWebUIOverrideRegistrar() { } -void ExtensionWebUIOverrideRegistrar::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { - const Extension* extension = - content::Details<const Extension>(details).ptr(); - ExtensionWebUI::RegisterChromeURLOverrides( - profile_, URLOverrides::GetChromeURLOverrides(extension)); - - } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { - const Extension* extension = - content::Details<UnloadedExtensionInfo>(details)->extension; - ExtensionWebUI::UnregisterChromeURLOverrides( - profile_, URLOverrides::GetChromeURLOverrides(extension)); - } +void ExtensionWebUIOverrideRegistrar::OnExtensionLoaded( + content::BrowserContext* browser_context, + const Extension* extension) { + ExtensionWebUI::RegisterChromeURLOverrides( + Profile::FromBrowserContext(browser_context), + URLOverrides::GetChromeURLOverrides(extension)); +} + +void ExtensionWebUIOverrideRegistrar::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + ExtensionWebUI::UnregisterChromeURLOverrides( + Profile::FromBrowserContext(browser_context), + URLOverrides::GetChromeURLOverrides(extension)); } static base::LazyInstance< diff --git a/chrome/browser/extensions/extension_web_ui_override_registrar.h b/chrome/browser/extensions/extension_web_ui_override_registrar.h index 6b02ac19..4c3344e7 100644 --- a/chrome/browser/extensions/extension_web_ui_override_registrar.h +++ b/chrome/browser/extensions/extension_web_ui_override_registrar.h @@ -6,20 +6,19 @@ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_OVERRIDE_REGISTRAR_H_ #include "base/basictypes.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "base/scoped_observer.h" #include "extensions/browser/browser_context_keyed_api_factory.h" - -class Profile; +#include "extensions/browser/extension_registry_observer.h" namespace content { class BrowserContext; } namespace extensions { +class ExtensionRegistry; class ExtensionWebUIOverrideRegistrar : public BrowserContextKeyedAPI, - public content::NotificationObserver { + public ExtensionRegistryObserver { public: explicit ExtensionWebUIOverrideRegistrar(content::BrowserContext* context); virtual ~ExtensionWebUIOverrideRegistrar(); @@ -28,21 +27,25 @@ class ExtensionWebUIOverrideRegistrar : public BrowserContextKeyedAPI, static BrowserContextKeyedAPIFactory<ExtensionWebUIOverrideRegistrar>* GetFactoryInstance(); - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: friend class BrowserContextKeyedAPIFactory<ExtensionWebUIOverrideRegistrar>; + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; + // BrowserContextKeyedAPI implementation. static const char* service_name() { return "ExtensionWebUIOverrideRegistrar"; } - Profile* const profile_; - content::NotificationRegistrar registrar_; + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIOverrideRegistrar); }; diff --git a/chrome/browser/extensions/install_tracker.cc b/chrome/browser/extensions/install_tracker.cc index a37e2f5..81e72fed 100644 --- a/chrome/browser/extensions/install_tracker.cc +++ b/chrome/browser/extensions/install_tracker.cc @@ -11,26 +11,24 @@ #include "chrome/common/pref_names.h" #include "content/public/browser/notification_service.h" #include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_registry.h" #include "extensions/browser/pref_names.h" namespace extensions { InstallTracker::InstallTracker(Profile* profile, - extensions::ExtensionPrefs* prefs) { - AppSorting* sorting = prefs->app_sorting(); + extensions::ExtensionPrefs* prefs) + : extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, content::Source<Profile>(profile)); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile)); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, content::Source<Profile>(profile)); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, content::Source<Profile>(profile)); + AppSorting* sorting = prefs->app_sorting(); registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, content::Source<AppSorting>(sorting)); registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, @@ -97,6 +95,19 @@ void InstallTracker::Shutdown() { FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown()); } +void InstallTracker::OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) { + FOR_EACH_OBSERVER(InstallObserver, observers_, OnExtensionLoaded(extension)); +} + +void InstallTracker::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + FOR_EACH_OBSERVER( + InstallObserver, observers_, OnExtensionUnloaded(extension)); +} + void InstallTracker::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -109,21 +120,6 @@ void InstallTracker::Observe(int type, OnExtensionInstalled(extension)); break; } - case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { - const Extension* extension = - content::Details<const Extension>(details).ptr(); - FOR_EACH_OBSERVER(InstallObserver, observers_, - OnExtensionLoaded(extension)); - break; - } - case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { - const content::Details<extensions::UnloadedExtensionInfo>& unload_info( - details); - const Extension* extension = unload_info->extension; - FOR_EACH_OBSERVER(InstallObserver, observers_, - OnExtensionUnloaded(extension)); - break; - } case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { const Extension* extension = content::Details<const Extension>(details).ptr(); diff --git a/chrome/browser/extensions/install_tracker.h b/chrome/browser/extensions/install_tracker.h index ea3c945..8342ec9 100644 --- a/chrome/browser/extensions/install_tracker.h +++ b/chrome/browser/extensions/install_tracker.h @@ -7,10 +7,12 @@ #include "base/observer_list.h" #include "base/prefs/pref_change_registrar.h" +#include "base/scoped_observer.h" #include "chrome/browser/extensions/install_observer.h" #include "components/keyed_service/core/keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "extensions/browser/extension_registry_observer.h" class Profile; @@ -21,9 +23,11 @@ class BrowserContext; namespace extensions { class ExtensionPrefs; +class ExtensionRegistry; class InstallTracker : public KeyedService, - public content::NotificationObserver { + public content::NotificationObserver, + public ExtensionRegistryObserver { public: InstallTracker(Profile* profile, extensions::ExtensionPrefs* prefs); @@ -43,21 +47,33 @@ class InstallTracker : public KeyedService, void OnFinishCrxInstall(const std::string& extension_id, bool success); void OnInstallFailure(const std::string& extension_id); - // Overriddes for KeyedService: + // Overriddes for KeyedService. virtual void Shutdown() OVERRIDE; - // content::NotificationObserver + private: + void OnAppsReordered(); + + // content::NotificationObserver. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - private: - void OnAppsReordered(); + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; ObserverList<InstallObserver> observers_; content::NotificationRegistrar registrar_; PrefChangeRegistrar pref_change_registrar_; + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; + DISALLOW_COPY_AND_ASSIGN(InstallTracker); }; diff --git a/chrome/browser/extensions/plugin_manager.cc b/chrome/browser/extensions/plugin_manager.cc index 57506d1..526aa0c 100644 --- a/chrome/browser/extensions/plugin_manager.cc +++ b/chrome/browser/extensions/plugin_manager.cc @@ -6,33 +6,27 @@ #include "base/lazy_instance.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/plugin_manager.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/api/plugins/plugins_handler.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" #include "content/public/browser/plugin_service.h" #include "content/public/common/pepper_plugin_info.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/extension.h" #include "url/gurl.h" using content::PluginService; -static const char* kNaClPluginMimeType = "application/x-nacl"; +static const char kNaClPluginMimeType[] = "application/x-nacl"; namespace extensions { PluginManager::PluginManager(content::BrowserContext* context) - : profile_(Profile::FromBrowserContext(context)) { - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile_)); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile_)); + : profile_(Profile::FromBrowserContext(context)), + extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); } PluginManager::~PluginManager() { @@ -47,85 +41,78 @@ PluginManager::GetFactoryInstance() { return g_factory.Pointer(); } -void PluginManager::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { - const Extension* extension = - content::Details<const Extension>(details).ptr(); - - bool plugins_or_nacl_changed = false; - if (PluginInfo::HasPlugins(extension)) { - const PluginInfo::PluginVector* plugins = - PluginInfo::GetPlugins(extension); - CHECK(plugins); - plugins_or_nacl_changed = true; - for (PluginInfo::PluginVector::const_iterator plugin = plugins->begin(); - plugin != plugins->end(); ++plugin) { - PluginService::GetInstance()->RefreshPlugins(); - PluginService::GetInstance()->AddExtraPluginPath(plugin->path); - ChromePluginServiceFilter* filter = - ChromePluginServiceFilter::GetInstance(); - if (plugin->is_public) { - filter->RestrictPluginToProfileAndOrigin( - plugin->path, profile_, GURL()); - } else { - filter->RestrictPluginToProfileAndOrigin( - plugin->path, profile_, extension->url()); - } +void PluginManager::OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) { + bool plugins_or_nacl_changed = false; + if (PluginInfo::HasPlugins(extension)) { + const PluginInfo::PluginVector* plugins = PluginInfo::GetPlugins(extension); + CHECK(plugins); + plugins_or_nacl_changed = true; + for (PluginInfo::PluginVector::const_iterator plugin = plugins->begin(); + plugin != plugins->end(); + ++plugin) { + PluginService::GetInstance()->RefreshPlugins(); + PluginService::GetInstance()->AddExtraPluginPath(plugin->path); + ChromePluginServiceFilter* filter = + ChromePluginServiceFilter::GetInstance(); + if (plugin->is_public) { + filter->RestrictPluginToProfileAndOrigin( + plugin->path, profile_, GURL()); + } else { + filter->RestrictPluginToProfileAndOrigin( + plugin->path, profile_, extension->url()); } } + } - const NaClModuleInfo::List* nacl_modules = - NaClModuleInfo::GetNaClModules(extension); - if (nacl_modules) { - plugins_or_nacl_changed = true; - for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); - module != nacl_modules->end(); ++module) { - RegisterNaClModule(*module); - } - UpdatePluginListWithNaClModules(); + const NaClModuleInfo::List* nacl_modules = + NaClModuleInfo::GetNaClModules(extension); + if (nacl_modules) { + plugins_or_nacl_changed = true; + for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); + module != nacl_modules->end(); + ++module) { + RegisterNaClModule(*module); } + UpdatePluginListWithNaClModules(); + } - if (plugins_or_nacl_changed) - PluginService::GetInstance()->PurgePluginListCache(profile_, false); - - } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { - const Extension* extension = - content::Details<UnloadedExtensionInfo>(details)->extension; - - bool plugins_or_nacl_changed = false; - if (PluginInfo::HasPlugins(extension)) { - const PluginInfo::PluginVector* plugins = - PluginInfo::GetPlugins(extension); - plugins_or_nacl_changed = true; - for (PluginInfo::PluginVector::const_iterator plugin = plugins->begin(); - plugin != plugins->end(); ++plugin) { - PluginService::GetInstance()->ForcePluginShutdown(plugin->path); - PluginService::GetInstance()->RefreshPlugins(); - PluginService::GetInstance()->RemoveExtraPluginPath(plugin->path); - ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin( - plugin->path); - } - } + if (plugins_or_nacl_changed) + PluginService::GetInstance()->PurgePluginListCache(profile_, false); +} - const NaClModuleInfo::List* nacl_modules = - NaClModuleInfo::GetNaClModules(extension); - if (nacl_modules) { - plugins_or_nacl_changed = true; - for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); - module != nacl_modules->end(); ++module) { - UnregisterNaClModule(*module); - } - UpdatePluginListWithNaClModules(); +void PluginManager::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + bool plugins_or_nacl_changed = false; + if (PluginInfo::HasPlugins(extension)) { + const PluginInfo::PluginVector* plugins = PluginInfo::GetPlugins(extension); + plugins_or_nacl_changed = true; + for (PluginInfo::PluginVector::const_iterator plugin = plugins->begin(); + plugin != plugins->end(); + ++plugin) { + PluginService::GetInstance()->ForcePluginShutdown(plugin->path); + PluginService::GetInstance()->RefreshPlugins(); + PluginService::GetInstance()->RemoveExtraPluginPath(plugin->path); + ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin->path); } + } - if (plugins_or_nacl_changed) - PluginService::GetInstance()->PurgePluginListCache(profile_, false); - - } else { - NOTREACHED(); + const NaClModuleInfo::List* nacl_modules = + NaClModuleInfo::GetNaClModules(extension); + if (nacl_modules) { + plugins_or_nacl_changed = true; + for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); + module != nacl_modules->end(); + ++module) { + UnregisterNaClModule(*module); + } + UpdatePluginListWithNaClModules(); } + + if (plugins_or_nacl_changed) + PluginService::GetInstance()->PurgePluginListCache(profile_, false); } void PluginManager::RegisterNaClModule(const NaClModuleInfo& info) { diff --git a/chrome/browser/extensions/plugin_manager.h b/chrome/browser/extensions/plugin_manager.h index c66ac5a..9c8d046 100644 --- a/chrome/browser/extensions/plugin_manager.h +++ b/chrome/browser/extensions/plugin_manager.h @@ -5,10 +5,10 @@ #ifndef CHROME_BROWSER_EXTENSIONS_PLUGIN_MANAGER_H_ #define CHROME_BROWSER_EXTENSIONS_PLUGIN_MANAGER_H_ +#include "base/scoped_observer.h" #include "chrome/common/extensions/manifest_handlers/nacl_modules_handler.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "extensions/browser/browser_context_keyed_api_factory.h" +#include "extensions/browser/extension_registry_observer.h" class GURL; class Profile; @@ -18,9 +18,10 @@ class BrowserContext; } namespace extensions { +class ExtensionRegistry; class PluginManager : public BrowserContextKeyedAPI, - public content::NotificationObserver { + public ExtensionRegistryObserver { public: explicit PluginManager(content::BrowserContext* context); virtual ~PluginManager(); @@ -28,11 +29,6 @@ class PluginManager : public BrowserContextKeyedAPI, // BrowserContextKeyedAPI implementation. static BrowserContextKeyedAPIFactory<PluginManager>* GetFactoryInstance(); - // content::NotificationObserver impelmentation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: friend class BrowserContextKeyedAPIFactory<PluginManager>; @@ -51,15 +47,25 @@ class PluginManager : public BrowserContextKeyedAPI, extensions::NaClModuleInfo::List::iterator FindNaClModule(const GURL& url); + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; + // BrowserContextKeyedAPI implementation. static const char* service_name() { return "PluginManager"; } static const bool kServiceIsNULLWhileTesting = true; extensions::NaClModuleInfo::List nacl_module_list_; - content::NotificationRegistrar registrar_; - Profile* profile_; + + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; }; } // namespace extensions diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 972ea8b..9a72d8b 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -4,17 +4,11 @@ #include "chrome/browser/extensions/user_script_master.h" -#include <map> #include <string> -#include <vector> #include "base/bind.h" #include "base/file_util.h" #include "base/files/file_path.h" -#include "base/pickle.h" -#include "base/stl_util.h" -#include "base/strings/string_util.h" -#include "base/threading/thread.h" #include "base/version.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_service.h" @@ -25,10 +19,7 @@ #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/extension.h" -#include "extensions/common/extension_resource.h" -#include "extensions/common/extension_set.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/file_util.h" #include "extensions/common/message_bundle.h" #include "ui/base/resource/resource_bundle.h" @@ -315,18 +306,14 @@ void UserScriptMaster::ScriptReloader::RunLoad( &ScriptReloader::NotifyMaster, this, Serialize(user_scripts))); } - UserScriptMaster::UserScriptMaster(Profile* profile) : extensions_service_ready_(false), pending_load_(false), - profile_(profile) { + profile_(profile), + extension_registry_observer_(this) { + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, content::Source<Profile>(profile_)); - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, - content::Source<Profile>(profile_)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::Source<Profile>(profile_)); registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, content::NotificationService::AllBrowserContextsAndSources()); } @@ -364,6 +351,52 @@ void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) { } } +void UserScriptMaster::OnExtensionLoaded( + content::BrowserContext* browser_context, + const Extension* extension) { + // Add any content scripts inside the extension. + extensions_info_[extension->id()] = + ExtensionSet::ExtensionPathAndDefaultLocale( + extension->path(), LocaleInfo::GetDefaultLocale(extension)); + bool incognito_enabled = util::IsIncognitoEnabled(extension->id(), profile_); + const UserScriptList& scripts = + ContentScriptsInfo::GetContentScripts(extension); + for (UserScriptList::const_iterator iter = scripts.begin(); + iter != scripts.end(); + ++iter) { + user_scripts_.push_back(*iter); + user_scripts_.back().set_incognito_enabled(incognito_enabled); + } + if (extensions_service_ready_) { + if (script_reloader_.get()) { + pending_load_ = true; + } else { + StartLoad(); + } + } +} + +void UserScriptMaster::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) { + // Remove any content scripts. + extensions_info_.erase(extension->id()); + UserScriptList new_user_scripts; + for (UserScriptList::iterator iter = user_scripts_.begin(); + iter != user_scripts_.end(); + ++iter) { + if (iter->extension_id() != extension->id()) + new_user_scripts.push_back(*iter); + } + user_scripts_ = new_user_scripts; + if (script_reloader_.get()) { + pending_load_ = true; + } else { + StartLoad(); + } +} + void UserScriptMaster::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -373,41 +406,6 @@ void UserScriptMaster::Observe(int type, extensions_service_ready_ = true; should_start_load = true; break; - case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { - // Add any content scripts inside the extension. - const Extension* extension = - content::Details<const Extension>(details).ptr(); - extensions_info_[extension->id()] = - ExtensionSet::ExtensionPathAndDefaultLocale( - extension->path(), LocaleInfo::GetDefaultLocale(extension)); - bool incognito_enabled = - util::IsIncognitoEnabled(extension->id(), profile_); - const UserScriptList& scripts = - ContentScriptsInfo::GetContentScripts(extension); - for (UserScriptList::const_iterator iter = scripts.begin(); - iter != scripts.end(); ++iter) { - user_scripts_.push_back(*iter); - user_scripts_.back().set_incognito_enabled(incognito_enabled); - } - if (extensions_service_ready_) - should_start_load = true; - break; - } - case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { - // Remove any content scripts. - const Extension* extension = - content::Details<UnloadedExtensionInfo>(details)->extension; - extensions_info_.erase(extension->id()); - UserScriptList new_user_scripts; - for (UserScriptList::iterator iter = user_scripts_.begin(); - iter != user_scripts_.end(); ++iter) { - if (iter->extension_id() != extension->id()) - new_user_scripts.push_back(*iter); - } - user_scripts_ = new_user_scripts; - should_start_load = true; - break; - } case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { content::RenderProcessHost* process = content::Source<content::RenderProcessHost>(source).ptr(); diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h index c764992..a7f9172 100644 --- a/chrome/browser/extensions/user_script_master.h +++ b/chrome/browser/extensions/user_script_master.h @@ -9,14 +9,12 @@ #include <string> #include "base/compiler_specific.h" -#include "base/files/file_path.h" -#include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/shared_memory.h" -#include "base/strings/string_piece.h" +#include "base/scoped_observer.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "extensions/browser/extension_registry_observer.h" #include "extensions/common/extension_messages.h" #include "extensions/common/extension_set.h" #include "extensions/common/user_script.h" @@ -29,13 +27,16 @@ class Profile; namespace extensions { +class ExtensionRegistry; + typedef std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale> ExtensionsInfo; // Manages a segment of shared memory that contains the user scripts the user // has installed. Lives on the UI thread. class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, - public content::NotificationObserver { + public content::NotificationObserver, + public ExtensionRegistryObserver { public: explicit UserScriptMaster(Profile* profile); @@ -134,6 +135,14 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // ExtensionRegistryObserver implementation. + virtual void OnExtensionLoaded(content::BrowserContext* browser_context, + const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + UnloadedExtensionInfo::Reason reason) OVERRIDE; + // Sends the renderer process a new set of user scripts. void SendUpdate(content::RenderProcessHost* process, base::SharedMemory* shared_memory); @@ -165,6 +174,10 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, // The profile for which the scripts managed here are installed. Profile* profile_; + // Listen to extension load, unloaded notifications. + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> + extension_registry_observer_; + DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); }; |