Commit a3b110b9 authored by limasdf@gmail.com's avatar limasdf@gmail.com

Remove some NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED from c/b/extensions Part2

BUG=354046,354458

Review URL: https://codereview.chromium.org/259843004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266649 0039d316-1c4b-4281-b951-d872f2087c98
parent a60c649c
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "content/public/common/frame_navigate_params.h" #include "content/public/common/frame_navigate_params.h"
#include "content/public/common/page_transition_types.h" #include "content/public/common/page_transition_types.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "extensions/common/features/feature.h" #include "extensions/common/features/feature.h"
...@@ -290,13 +291,10 @@ TEST_F(ActiveTabTest, Uninstalling) { ...@@ -290,13 +291,10 @@ TEST_F(ActiveTabTest, Uninstalling) {
EXPECT_TRUE(IsAllowed(extension, google)); EXPECT_TRUE(IsAllowed(extension, google));
// Uninstalling the extension should clear its tab permissions. // Uninstalling the extension should clear its tab permissions.
UnloadedExtensionInfo details(extension.get(), ExtensionRegistry* registry =
UnloadedExtensionInfo::REASON_DISABLE); ExtensionRegistry::Get(web_contents()->GetBrowserContext());
content::NotificationService::current()->Notify( registry->TriggerOnUnloaded(extension.get(),
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, UnloadedExtensionInfo::REASON_DISABLE);
content::Source<Profile>(Profile::FromBrowserContext(
web_contents()->GetBrowserContext())),
content::Details<UnloadedExtensionInfo>(&details));
// Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions // Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions
// are just that... considered to be uninstalled, and the manager might // are just that... considered to be uninstalled, and the manager might
......
...@@ -6,15 +6,13 @@ ...@@ -6,15 +6,13 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/api/input_ime.h" #include "chrome/common/extensions/api/input_ime.h"
#include "chrome/common/extensions/api/input_ime/input_components_handler.h" #include "chrome/common/extensions/api/input_ime/input_components_handler.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_registry.h" #include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_registry.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "chrome/browser/chromeos/input_method/input_method_engine.h" #include "chrome/browser/chromeos/input_method/input_method_engine.h"
...@@ -776,21 +774,16 @@ bool InputImeKeyEventHandledFunction::RunImpl() { ...@@ -776,21 +774,16 @@ bool InputImeKeyEventHandledFunction::RunImpl() {
} }
InputImeAPI::InputImeAPI(content::BrowserContext* context) InputImeAPI::InputImeAPI(content::BrowserContext* context)
: profile_(Profile::FromBrowserContext(context)) { : browser_context_(context), extension_registry_observer_(this) {
registrar_.Add(this, extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile_)); EventRouter* event_router = EventRouter::Get(browser_context_);
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile_));
EventRouter* event_router = EventRouter::Get(profile_);
event_router->RegisterObserver(this, input_ime::OnActivate::kEventName); event_router->RegisterObserver(this, input_ime::OnActivate::kEventName);
event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); event_router->RegisterObserver(this, input_ime::OnFocus::kEventName);
} }
InputImeAPI::~InputImeAPI() { InputImeAPI::~InputImeAPI() {
EventRouter::Get(profile_)->UnregisterObserver(this); EventRouter::Get(browser_context_)->UnregisterObserver(this);
} }
static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> >
...@@ -801,42 +794,40 @@ BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { ...@@ -801,42 +794,40 @@ BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() {
return g_factory.Pointer(); return g_factory.Pointer();
} }
void InputImeAPI::Observe(int type, void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const content::NotificationSource& source, const Extension* extension) {
const content::NotificationDetails& details) { const std::vector<InputComponentInfo>* input_components =
if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { extensions::InputComponents::GetInputComponents(extension);
const Extension* extension = if (!input_components)
content::Details<const Extension>(details).ptr(); return;
const std::vector<InputComponentInfo>* input_components = for (std::vector<extensions::InputComponentInfo>::const_iterator component =
extensions::InputComponents::GetInputComponents(extension); input_components->begin();
if (!input_components) component != input_components->end();
return; ++component) {
for (std::vector<extensions::InputComponentInfo>::const_iterator component = if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) {
input_components->begin(); component != input_components->end(); // Don't pass profile_ to register ime, instead always use
++component) { // GetActiveUserProfile. It is because:
if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) { // The original profile for login screen is called signin profile.
// Don't pass profile_ to register ime, instead always use // And the active profile is the incognito profile based on signin
// GetActiveUserProfile. It is because: // profile. So if |profile_| is signin profile, we need to make sure
// The original profile for login screen is called signin profile. // the router/observer runs under its incognito profile, because the
// And the active profile is the incognito profile based on signin // component extensions were installed under its incognito profile.
// profile. So if |profile_| is signin profile, we need to make sure input_ime_event_router()->RegisterIme(extension->id(), *component);
// the router/observer runs under its incognito profile, because the
// component extensions were installed under its incognito profile.
input_ime_event_router()->RegisterIme(extension->id(), *component);
}
} }
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
const Extension* extension =
content::Details<const UnloadedExtensionInfo>(details)->extension;
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
if (input_components->size() > 0)
input_ime_event_router()->UnregisterAllImes(extension->id());
} }
} }
void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
if (input_components->size() > 0)
input_ime_event_router()->UnregisterAllImes(extension->id());
}
void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {
InputMethodEngineInterface* engine = InputMethodEngineInterface* engine =
input_ime_event_router()->GetActiveEngine(details.extension_id); input_ime_event_router()->GetActiveEngine(details.extension_id);
......
...@@ -10,15 +10,15 @@ ...@@ -10,15 +10,15 @@
#include <vector> #include <vector>
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/scoped_observer.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h" #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.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/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
class Profile; class Profile;
...@@ -29,6 +29,7 @@ class ImeObserver; ...@@ -29,6 +29,7 @@ class ImeObserver;
} // namespace chromeos } // namespace chromeos
namespace extensions { namespace extensions {
class ExtensionRegistry;
struct InputComponentInfo; struct InputComponentInfo;
class InputImeEventRouter { class InputImeEventRouter {
...@@ -219,7 +220,7 @@ class InputImeHideInputViewFunction : public AsyncExtensionFunction { ...@@ -219,7 +220,7 @@ class InputImeHideInputViewFunction : public AsyncExtensionFunction {
}; };
class InputImeAPI : public BrowserContextKeyedAPI, class InputImeAPI : public BrowserContextKeyedAPI,
public content::NotificationObserver, public ExtensionRegistryObserver,
public EventRouter::Observer { public EventRouter::Observer {
public: public:
explicit InputImeAPI(content::BrowserContext* context); explicit InputImeAPI(content::BrowserContext* context);
...@@ -228,10 +229,13 @@ class InputImeAPI : public BrowserContextKeyedAPI, ...@@ -228,10 +229,13 @@ class InputImeAPI : public BrowserContextKeyedAPI,
// BrowserContextKeyedAPI implementation. // BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance(); static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance();
// content::NotificationObserver implementation. // ExtensionRegistryObserver implementation.
virtual void Observe(int type, virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const content::NotificationSource& source, const Extension* extension) OVERRIDE;
const content::NotificationDetails& details) OVERRIDE; virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) OVERRIDE;
// EventRouter::Observer implementation. // EventRouter::Observer implementation.
virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
...@@ -246,8 +250,11 @@ class InputImeAPI : public BrowserContextKeyedAPI, ...@@ -246,8 +250,11 @@ class InputImeAPI : public BrowserContextKeyedAPI,
} }
static const bool kServiceIsNULLWhileTesting = true; static const bool kServiceIsNULLWhileTesting = true;
Profile* const profile_; content::BrowserContext* const browser_context_;
content::NotificationRegistrar registrar_;
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
}; };
} // namespace extensions } // namespace extensions
......
...@@ -35,6 +35,7 @@ class FilterHandler { ...@@ -35,6 +35,7 @@ class FilterHandler {
bool IsValidProcess(const std::string& process) const; bool IsValidProcess(const std::string& process) const;
const api::log_private::Filter* GetFilter() const { return &filter_; } const api::log_private::Filter* GetFilter() const { return &filter_; }
private: private:
api::log_private::Filter filter_; api::log_private::Filter filter_;
......
...@@ -8,26 +8,25 @@ ...@@ -8,26 +8,25 @@
#include <set> #include <set>
#include <string> #include <string>
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h" #include "chrome/browser/extensions/api/log_private/filter_handler.h"
#include "chrome/browser/extensions/api/log_private/log_parser.h" #include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/chrome_extension_function.h" #include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" #include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h"
#include "chrome/common/extensions/api/log_private.h" #include "chrome/common/extensions/api/log_private.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/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_registry_observer.h"
#include "net/base/net_log.h" #include "net/base/net_log.h"
class Profile;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
} }
namespace extensions { namespace extensions {
class ExtensionRegistry;
class LogPrivateAPI : public BrowserContextKeyedAPI, class LogPrivateAPI : public BrowserContextKeyedAPI,
public content::NotificationObserver, public ExtensionRegistryObserver,
public net::NetLog::ThreadSafeObserver { public net::NetLog::ThreadSafeObserver {
public: public:
// Convenience method to get the LogPrivateAPI for a profile. // Convenience method to get the LogPrivateAPI for a profile.
...@@ -42,14 +41,15 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, ...@@ -42,14 +41,15 @@ class LogPrivateAPI : public BrowserContextKeyedAPI,
// BrowserContextKeyedAPI implementation. // BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance();
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private: private:
friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>;
// ExtensionRegistryObserver implementation.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) OVERRIDE;
// ChromeNetLog::ThreadSafeObserver implementation: // ChromeNetLog::ThreadSafeObserver implementation:
virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
...@@ -67,11 +67,14 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, ...@@ -67,11 +67,14 @@ class LogPrivateAPI : public BrowserContextKeyedAPI,
static const bool kServiceIsNULLWhileTesting = true; static const bool kServiceIsNULLWhileTesting = true;
static const bool kServiceRedirectedInIncognito = true; static const bool kServiceRedirectedInIncognito = true;
Profile* const profile_; content::BrowserContext* const browser_context_;
bool logging_net_internals_; bool logging_net_internals_;
content::NotificationRegistrar registrar_;
std::set<std::string> net_internal_watches_; std::set<std::string> net_internal_watches_;
scoped_ptr<base::ListValue> pending_entries_; scoped_ptr<base::ListValue> pending_entries_;
// Listen to extension unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
}; };
class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/memory/linked_ptr.h" #include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h" #include "chrome/browser/extensions/api/log_private/filter_handler.h"
#include "chrome/browser/extensions/api/log_private/log_parser.h" #include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/api/log_private/syslog_parser.h" #include "chrome/browser/extensions/api/log_private/syslog_parser.h"
...@@ -22,10 +21,9 @@ ...@@ -22,10 +21,9 @@
#include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/log_private.h" #include "chrome/common/extensions/api/log_private.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -71,11 +69,10 @@ LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) { ...@@ -71,11 +69,10 @@ LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) {
} }
LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context) LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context)
: profile_(Profile::FromBrowserContext(context)), : browser_context_(context),
logging_net_internals_(false) { logging_net_internals_(false),
registrar_.Add(this, extension_registry_observer_(this) {
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
content::Source<Profile>(profile_));
} }
LogPrivateAPI::~LogPrivateAPI() { LogPrivateAPI::~LogPrivateAPI() {
...@@ -100,7 +97,7 @@ static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> > ...@@ -100,7 +97,7 @@ static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> >
// static // static
BrowserContextKeyedAPIFactory<LogPrivateAPI>* BrowserContextKeyedAPIFactory<LogPrivateAPI>*
LogPrivateAPI::GetFactoryInstance() { LogPrivateAPI::GetFactoryInstance() {
return &g_factory.Get(); return g_factory.Pointer();
} }
void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) { void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) {
...@@ -133,7 +130,8 @@ void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) { ...@@ -133,7 +130,8 @@ void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) {
event_args->Append(value->DeepCopy()); event_args->Append(value->DeepCopy());
scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries, scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries,
event_args.Pass())); event_args.Pass()));
EventRouter::Get(profile_)->DispatchEventToExtension(*ix, event.Pass()); EventRouter::Get(browser_context_)
->DispatchEventToExtension(*ix, event.Pass());
} }
} }
...@@ -163,14 +161,11 @@ void LogPrivateAPI::StopNetInternalLogging() { ...@@ -163,14 +161,11 @@ void LogPrivateAPI::StopNetInternalLogging() {
} }
} }
void LogPrivateAPI::Observe(int type, void LogPrivateAPI::OnExtensionUnloaded(
const content::NotificationSource& source, content::BrowserContext* browser_context,
const content::NotificationDetails& details) { const Extension* extension,
if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { UnloadedExtensionInfo::Reason reason) {
const Extension* extension = StopNetInternalsWatch(extension->id());
content::Details<const UnloadedExtensionInfo>(details)->extension;
StopNetInternalsWatch(extension->id());
}
} }
LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() { LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
...@@ -41,15 +42,16 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( ...@@ -41,15 +42,16 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
browser_(browser), browser_(browser),
#endif #endif
extension_(extension), extension_(extension),
extension_registry_observer_(this),
closing_(false) { closing_(false) {
extension_view_host_.reset( extension_view_host_.reset(
extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser)); extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser));
extension_view_host_->SetAssociatedWebContents(web_contents); extension_view_host_->SetAssociatedWebContents(web_contents);
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
content::Source<Profile>(browser->profile())); content::Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser->profile()));
height_ = std::max(0, height); height_ = std::max(0, height);
height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_); height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_);
...@@ -95,18 +97,20 @@ ExtensionInfoBarDelegate* ...@@ -95,18 +97,20 @@ ExtensionInfoBarDelegate*
return this; return this;
} }
void ExtensionInfoBarDelegate::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (extension_ == extension)
infobar()->RemoveSelf();
}
void ExtensionInfoBarDelegate::Observe( void ExtensionInfoBarDelegate::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE);
if (extension_view_host_.get() == if (extension_view_host_.get() ==
content::Details<extensions::ExtensionHost>(details).ptr()) content::Details<extensions::ExtensionHost>(details).ptr())
infobar()->RemoveSelf(); infobar()->RemoveSelf();
} else {
DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
if (extension_ == content::Details<extensions::UnloadedExtensionInfo>(
details)->extension)
infobar()->RemoveSelf();
}
} }
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class Browser; class Browser;
class GURL; class GURL;
...@@ -19,13 +21,15 @@ class WebContents; ...@@ -19,13 +21,15 @@ class WebContents;
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionRegistry;
class ExtensionViewHost; class ExtensionViewHost;
} }
// The InfobarDelegate for creating and managing state for the ExtensionInfobar // The InfobarDelegate for creating and managing state for the ExtensionInfobar
// plus monitor when the extension goes away. // plus monitor when the extension goes away.
class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate, class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
public content::NotificationObserver { public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public: public:
virtual ~ExtensionInfoBarDelegate(); virtual ~ExtensionInfoBarDelegate();
...@@ -59,18 +63,24 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate, ...@@ -59,18 +63,24 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
static scoped_ptr<infobars::InfoBar> CreateInfoBar( static scoped_ptr<infobars::InfoBar> CreateInfoBar(
scoped_ptr<ExtensionInfoBarDelegate> delegate); scoped_ptr<ExtensionInfoBarDelegate> delegate);
// InfoBarDelegate: // InfoBarDelegate.
virtual bool EqualsDelegate( virtual bool EqualsDelegate(
infobars::InfoBarDelegate* delegate) const OVERRIDE; infobars::InfoBarDelegate* delegate) const OVERRIDE;
virtual void InfoBarDismissed() OVERRIDE; virtual void InfoBarDismissed() OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE; virtual Type GetInfoBarType() const OVERRIDE;
virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE; virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
// content::NotificationObserver: // content::NotificationObserver.
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
Browser* browser_; // We pass this to the ExtensionInfoBar. Browser* browser_; // We pass this to the ExtensionInfoBar.
#endif #endif
...@@ -82,6 +92,10 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate, ...@@ -82,6 +92,10 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
const extensions::Extension* extension_; const extensions::Extension* extension_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
// The requested height of the infobar (in pixels). // The requested height of the infobar (in pixels).
int height_; int height_;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h" #include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -47,12 +48,10 @@ ExtensionToolbarModel::ExtensionToolbarModel( ...@@ -47,12 +48,10 @@ ExtensionToolbarModel::ExtensionToolbarModel(
prefs_(profile_->GetPrefs()), prefs_(profile_->GetPrefs()),
extensions_initialized_(false), extensions_initialized_(false),
is_highlighting_(false), is_highlighting_(false),
extension_registry_observer_(this),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
registrar_.Add(this, extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
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_EXTENSIONS_READY, registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_)); content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
...@@ -180,6 +179,29 @@ void ExtensionToolbarModel::SetVisibleIconCount(int count) { ...@@ -180,6 +179,29 @@ void ExtensionToolbarModel::SetVisibleIconCount(int count) {
} }
} }
void ExtensionToolbarModel::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
// We don't want to add the same extension twice. It may have already been
// added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
// hides the browser action and then disables and enables the extension.
for (size_t i = 0; i < toolbar_items_.size(); i++) {
if (toolbar_items_[i].get() == extension)
return;
}
if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension->id())) {
AddExtension(extension);
}
}
void ExtensionToolbarModel::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
RemoveExtension(extension);
}
void ExtensionToolbarModel::Observe( void ExtensionToolbarModel::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
...@@ -194,29 +216,6 @@ void ExtensionToolbarModel::Observe( ...@@ -194,29 +216,6 @@ void ExtensionToolbarModel::Observe(
case chrome::NOTIFICATION_EXTENSIONS_READY: case chrome::NOTIFICATION_EXTENSIONS_READY:
InitializeExtensionList(extension_service); InitializeExtensionList(extension_service);
break; break;
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
// We don't want to add the same extension twice. It may have already been
// added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
// hides the browser action and then disables and enables the extension.
for (size_t i = 0; i < toolbar_items_.size(); i++) {
if (toolbar_items_[i].get() == extension)
return; // Already exists.
}
if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension->id())) {
AddExtension(extension);
}
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
content::Details<extensions::UnloadedExtensionInfo>(details)
->extension;
RemoveExtension(extension);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension = const Extension* extension =
content::Details<const Extension>(details).ptr(); content::Details<const Extension>(details).ptr();
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/prefs/pref_change_registrar.h" #include "base/prefs/pref_change_registrar.h"
#include "base/scoped_observer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
class Browser; class Browser;
...@@ -20,9 +22,11 @@ class PrefService; ...@@ -20,9 +22,11 @@ class PrefService;
class Profile; class Profile;
namespace extensions { namespace extensions {
class ExtensionRegistry;
// Model for the browser actions toolbar. // Model for the browser actions toolbar.
class ExtensionToolbarModel : public content::NotificationObserver, class ExtensionToolbarModel : public content::NotificationObserver,
public ExtensionRegistryObserver,
public KeyedService { public KeyedService {
public: public:
ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs);
...@@ -137,6 +141,14 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -137,6 +141,14 @@ class ExtensionToolbarModel : public content::NotificationObserver,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; 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;
// To be called after the extension service is ready; gets loaded extensions // To be called after the extension service is ready; gets loaded extensions
// from the extension service and their saved order from the pref service // from the extension service and their saved order from the pref service
// and constructs |toolbar_items_| from these data. // and constructs |toolbar_items_| from these data.
...@@ -193,6 +205,10 @@ class ExtensionToolbarModel : public content::NotificationObserver, ...@@ -193,6 +205,10 @@ class ExtensionToolbarModel : public content::NotificationObserver,
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
// For observing change of toolbar order preference by external entity (sync). // For observing change of toolbar order preference by external entity (sync).
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
base::Closure pref_change_callback_; base::Closure pref_change_callback_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/scoped_observer.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
...@@ -27,21 +28,17 @@ ...@@ -27,21 +28,17 @@
#include "chrome/browser/ui/global_error/global_error.h" #include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_url_handler.h" #include "chrome/common/extensions/manifest_url_handler.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "extensions/common/extension.h" #include "extensions/browser/extension_registry.h"
#include "grit/chromium_strings.h" #include "extensions/browser/extension_registry_observer.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/size.h"
namespace extensions { namespace extensions {
...@@ -58,6 +55,10 @@ static const int kMenuCommandId = IDC_EXTERNAL_EXTENSION_ALERT; ...@@ -58,6 +55,10 @@ static const int kMenuCommandId = IDC_EXTERNAL_EXTENSION_ALERT;
class ExternalInstallGlobalError; class ExternalInstallGlobalError;
namespace extensions {
class ExtensionRegistry;
}
// This class is refcounted to stay alive while we try and pull webstore data. // This class is refcounted to stay alive while we try and pull webstore data.
class ExternalInstallDialogDelegate class ExternalInstallDialogDelegate
: public ExtensionInstallPrompt::Delegate, : public ExtensionInstallPrompt::Delegate,
...@@ -89,7 +90,7 @@ class ExternalInstallDialogDelegate ...@@ -89,7 +90,7 @@ class ExternalInstallDialogDelegate
virtual void OnWebstoreResponseParseFailure( virtual void OnWebstoreResponseParseFailure(
const std::string& error) OVERRIDE; const std::string& error) OVERRIDE;
// NotificationObserver: // content::NotificationObserver:
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
...@@ -114,7 +115,8 @@ class ExternalInstallDialogDelegate ...@@ -114,7 +115,8 @@ class ExternalInstallDialogDelegate
// Only shows a menu item, no bubble. Clicking the menu item shows // Only shows a menu item, no bubble. Clicking the menu item shows
// an external install dialog. // an external install dialog.
class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble, class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble,
public content::NotificationObserver { public content::NotificationObserver,
public ExtensionRegistryObserver {
public: public:
ExternalInstallMenuAlert(ExtensionService* service, ExternalInstallMenuAlert(ExtensionService* service,
const Extension* extension); const Extension* extension);
...@@ -135,17 +137,29 @@ class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble, ...@@ -135,17 +137,29 @@ class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble,
virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
protected:
ExtensionService* service_;
const Extension* extension_;
private:
// Delete this instance after cleaning jobs.
void Clean();
// content::NotificationObserver implementation. // content::NotificationObserver implementation.
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
protected: // ExtensionRegistryObserver implementation.
ExtensionService* service_; virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension_; const Extension* extension) OVERRIDE;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
private: // Listen to extension load notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(ExternalInstallMenuAlert); DISALLOW_COPY_AND_ASSIGN(ExternalInstallMenuAlert);
}; };
...@@ -335,14 +349,12 @@ void ExternalInstallDialogDelegate::InstallUIAbort(bool user_initiated) { ...@@ -335,14 +349,12 @@ void ExternalInstallDialogDelegate::InstallUIAbort(bool user_initiated) {
// ExternalInstallMenuAlert ------------------------------------------------- // ExternalInstallMenuAlert -------------------------------------------------
ExternalInstallMenuAlert::ExternalInstallMenuAlert( ExternalInstallMenuAlert::ExternalInstallMenuAlert(ExtensionService* service,
ExtensionService* service, const Extension* extension)
const Extension* extension)
: service_(service), : service_(service),
extension_(extension) { extension_(extension),
registrar_.Add(this, extension_registry_observer_(this) {
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, extension_registry_observer_.Add(ExtensionRegistry::Get(service->profile()));
content::Source<Profile>(service->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED, registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED,
content::Source<Profile>(service->profile())); content::Source<Profile>(service->profile()));
} }
...@@ -410,16 +422,25 @@ void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed( ...@@ -410,16 +422,25 @@ void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed(
NOTREACHED(); NOTREACHED();
} }
void ExternalInstallMenuAlert::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
if (extension == extension_)
Clean();
}
void ExternalInstallMenuAlert::Observe( void ExternalInstallMenuAlert::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
// The error is invalidated if the extension has been loaded or removed. // The error is invalidated if the extension has been loaded or removed.
DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED || DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_REMOVED);
type == chrome::NOTIFICATION_EXTENSION_REMOVED);
const Extension* extension = content::Details<const Extension>(details).ptr(); const Extension* extension = content::Details<const Extension>(details).ptr();
if (extension != extension_) if (extension == extension_)
return; Clean();
}
void ExternalInstallMenuAlert::Clean() {
GlobalErrorService* error_service = GlobalErrorService* error_service =
GlobalErrorServiceFactory::GetForProfile(service_->profile()); GlobalErrorServiceFactory::GetForProfile(service_->profile());
error_service->RemoveGlobalError(this); error_service->RemoveGlobalError(this);
......
...@@ -20,8 +20,9 @@ void AddExternalInstallError(ExtensionService* service, ...@@ -20,8 +20,9 @@ void AddExternalInstallError(ExtensionService* service,
bool is_new_profile); bool is_new_profile);
void RemoveExternalInstallError(ExtensionService* service); void RemoveExternalInstallError(ExtensionService* service);
// Used for testing.
bool HasExternalInstallError(ExtensionService* service); bool HasExternalInstallError(ExtensionService* service);
// Used for testing.
bool HasExternalInstallBubble(ExtensionService* service); bool HasExternalInstallBubble(ExtensionService* service);
} // namespace extensions } // namespace extensions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment