Commit 5681e2f2 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

Remove Extension Loaded/Unloaded notifications from LocationBarView(Mac)

Having the views observe these notifications is strange -- they don't know when
page actions are updated in any other ways, so they shouldn't need to know for
this. Move the notifications to LocationBarController.

Bonuses:
- Less code! By 50 lines!
- Remove four deprecated notification uses!

This has a very loose dependency on https://codereview.chromium.org/508563003/.

BUG=407672

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

Cr-Commit-Position: refs/heads/master@{#292225}
parent bb30da9b
...@@ -16,6 +16,7 @@ LocationBarController::LocationBarController( ...@@ -16,6 +16,7 @@ LocationBarController::LocationBarController(
content::WebContents* web_contents) content::WebContents* web_contents)
: web_contents_(web_contents), : web_contents_(web_contents),
browser_context_(web_contents->GetBrowserContext()), browser_context_(web_contents->GetBrowserContext()),
action_manager_(ExtensionActionManager::Get(browser_context_)),
active_script_controller_(new ActiveScriptController(web_contents_)), active_script_controller_(new ActiveScriptController(web_contents_)),
extension_registry_observer_(this) { extension_registry_observer_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
...@@ -27,8 +28,6 @@ LocationBarController::~LocationBarController() { ...@@ -27,8 +28,6 @@ LocationBarController::~LocationBarController() {
std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
const ExtensionSet& extensions = const ExtensionSet& extensions =
ExtensionRegistry::Get(browser_context_)->enabled_extensions(); ExtensionRegistry::Get(browser_context_)->enabled_extensions();
ExtensionActionManager* action_manager =
ExtensionActionManager::Get(browser_context_);
std::vector<ExtensionAction*> current_actions; std::vector<ExtensionAction*> current_actions;
for (ExtensionSet::const_iterator iter = extensions.begin(); for (ExtensionSet::const_iterator iter = extensions.begin();
iter != extensions.end(); iter != extensions.end();
...@@ -36,7 +35,7 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { ...@@ -36,7 +35,7 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
// Right now, we can consolidate these actions because we only want to show // Right now, we can consolidate these actions because we only want to show
// one action per extension. If clicking on an active script action ever // one action per extension. If clicking on an active script action ever
// has a response, then we will need to split the actions. // has a response, then we will need to split the actions.
ExtensionAction* action = action_manager->GetPageAction(**iter); ExtensionAction* action = action_manager_->GetPageAction(**iter);
if (!action) if (!action)
action = active_script_controller_->GetActionForExtension(iter->get()); action = active_script_controller_->GetActionForExtension(iter->get());
if (action) if (action)
...@@ -46,12 +45,22 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { ...@@ -46,12 +45,22 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
return current_actions; return current_actions;
} }
void LocationBarController::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
if (action_manager_->GetPageAction(*extension) ||
active_script_controller_->GetActionForExtension(extension)) {
ExtensionActionAPI::Get(browser_context)->
NotifyPageActionsChanged(web_contents_);
}
}
void LocationBarController::OnExtensionUnloaded( void LocationBarController::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
UnloadedExtensionInfo::Reason reason) { UnloadedExtensionInfo::Reason reason) {
bool should_update = false; bool should_update = false;
if (ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension)) if (action_manager_->GetPageAction(*extension))
should_update = true; should_update = true;
if (active_script_controller_->GetActionForExtension(extension)) { if (active_script_controller_->GetActionForExtension(extension)) {
......
...@@ -23,6 +23,7 @@ namespace extensions { ...@@ -23,6 +23,7 @@ namespace extensions {
class ActiveScriptController; class ActiveScriptController;
class Extension; class Extension;
class ExtensionActionManager;
class ExtensionRegistry; class ExtensionRegistry;
// Provides the UI with the current page actions for extensions. The execution // Provides the UI with the current page actions for extensions. The execution
...@@ -41,6 +42,9 @@ class LocationBarController : public ExtensionRegistryObserver { ...@@ -41,6 +42,9 @@ class LocationBarController : public ExtensionRegistryObserver {
private: private:
// ExtensionRegistryObserver implementation. // ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extnesion) OVERRIDE;
virtual void OnExtensionUnloaded( virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
...@@ -52,6 +56,9 @@ class LocationBarController : public ExtensionRegistryObserver { ...@@ -52,6 +56,9 @@ class LocationBarController : public ExtensionRegistryObserver {
// The associated BrowserContext. // The associated BrowserContext.
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
// The ExtensionActionManager to provide page actions.
ExtensionActionManager* action_manager_;
// The ActiveScriptController, which could also add actions for extensions if // The ActiveScriptController, which could also add actions for extensions if
// they have a pending script. // they have a pending script.
scoped_ptr<ActiveScriptController> active_script_controller_; scoped_ptr<ActiveScriptController> active_script_controller_;
......
...@@ -47,7 +47,6 @@ class ZoomDecorationTest; ...@@ -47,7 +47,6 @@ class ZoomDecorationTest;
class LocationBarViewMac : public LocationBar, class LocationBarViewMac : public LocationBar,
public LocationBarTesting, public LocationBarTesting,
public OmniboxEditController, public OmniboxEditController,
public content::NotificationObserver,
public SearchModelObserver { public SearchModelObserver {
public: public:
LocationBarViewMac(AutocompleteTextField* field, LocationBarViewMac(AutocompleteTextField* field,
...@@ -166,12 +165,6 @@ class LocationBarViewMac : public LocationBar, ...@@ -166,12 +165,6 @@ class LocationBarViewMac : public LocationBar,
AutocompleteTextField* GetAutocompleteTextField() { return field_; } AutocompleteTextField* GetAutocompleteTextField() { return field_; }
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// SearchModelObserver: // SearchModelObserver:
virtual void ModelChanged(const SearchModel::State& old_state, virtual void ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) OVERRIDE; const SearchModel::State& new_state) OVERRIDE;
...@@ -277,9 +270,6 @@ class LocationBarViewMac : public LocationBar, ...@@ -277,9 +270,6 @@ class LocationBarViewMac : public LocationBar,
Browser* browser_; Browser* browser_;
// Used to register for notifications received by NotificationObserver.
content::NotificationRegistrar registrar_;
// Used to schedule a task for the first run info bubble. // Used to schedule a task for the first run info bubble.
base::WeakPtrFactory<LocationBarViewMac> weak_ptr_factory_; base::WeakPtrFactory<LocationBarViewMac> weak_ptr_factory_;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#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"
#import "chrome/browser/app_controller_mac.h" #import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/command_updater.h" #include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h" #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
...@@ -64,7 +63,6 @@ ...@@ -64,7 +63,6 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/translate/core/browser/language_state.h" #include "components/translate/core/browser/language_state.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -143,14 +141,6 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, ...@@ -143,14 +141,6 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
new ContentSettingDecoration(type, this, profile)); new ContentSettingDecoration(type, this, profile));
} }
content::Source<Profile> profile_source = content::Source<Profile>(profile);
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
profile_source);
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
profile_source);
edit_bookmarks_enabled_.Init( edit_bookmarks_enabled_.Init(
prefs::kEditBookmarksEnabled, profile->GetPrefs(), prefs::kEditBookmarksEnabled, profile->GetPrefs(),
base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged,
...@@ -620,15 +610,6 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { ...@@ -620,15 +610,6 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
} }
void LocationBarViewMac::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED ||
type == extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
Update(NULL);
}
void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state, void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) { const SearchModel::State& new_state) {
if (UpdateMicSearchDecorationVisibility()) if (UpdateMicSearchDecorationVisibility())
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/stl_util.h" #include "base/stl_util.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/command_updater.h" #include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h" #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
...@@ -64,7 +63,6 @@ ...@@ -64,7 +63,6 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/translate/core/browser/language_state.h" #include "components/translate/core/browser/language_state.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
...@@ -403,14 +401,6 @@ void LocationBarView::Init() { ...@@ -403,14 +401,6 @@ void LocationBarView::Init() {
hide_url_animation_->SetTweenType(kHideTweenType); hide_url_animation_->SetTweenType(kHideTweenType);
hide_url_animation_->SetSlideDuration(175); hide_url_animation_->SetSlideDuration(175);
content::Source<Profile> profile_source = content::Source<Profile>(profile());
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
profile_source);
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
profile_source);
// Initialize the location entry. We do this to avoid a black flash which is // Initialize the location entry. We do this to avoid a black flash which is
// visible when the location entry has just been initialized. // visible when the location entry has just been initialized.
Update(NULL); Update(NULL);
...@@ -1692,23 +1682,6 @@ void LocationBarView::OnTemplateURLServiceChanged() { ...@@ -1692,23 +1682,6 @@ void LocationBarView::OnTemplateURLServiceChanged() {
ShowFirstRunBubble(); ShowFirstRunBubble();
} }
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private content::NotificationObserver implementation:
void LocationBarView::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
Update(NULL);
break;
default:
NOTREACHED() << "Unexpected notification.";
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private SearchModelObserver implementation: // LocationBarView, private SearchModelObserver implementation:
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include "chrome/browser/ui/views/extensions/extension_popup.h" #include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
...@@ -85,7 +83,6 @@ class LocationBarView : public LocationBar, ...@@ -85,7 +83,6 @@ class LocationBarView : public LocationBar,
public DropdownBarHostDelegate, public DropdownBarHostDelegate,
public gfx::AnimationDelegate, public gfx::AnimationDelegate,
public TemplateURLServiceObserver, public TemplateURLServiceObserver,
public content::NotificationObserver,
public SearchModelObserver { public SearchModelObserver {
public: public:
// The location bar view's class name. // The location bar view's class name.
...@@ -406,11 +403,6 @@ class LocationBarView : public LocationBar, ...@@ -406,11 +403,6 @@ class LocationBarView : public LocationBar,
// TemplateURLServiceObserver: // TemplateURLServiceObserver:
virtual void OnTemplateURLServiceChanged() OVERRIDE; virtual void OnTemplateURLServiceChanged() OVERRIDE;
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// SearchModelObserver: // SearchModelObserver:
virtual void ModelChanged(const SearchModel::State& old_state, virtual void ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) OVERRIDE; const SearchModel::State& new_state) OVERRIDE;
...@@ -553,9 +545,6 @@ class LocationBarView : public LocationBar, ...@@ -553,9 +545,6 @@ class LocationBarView : public LocationBar,
int current_omnibox_width_; int current_omnibox_width_;
int ending_omnibox_width_; int ending_omnibox_width_;
// Used to register for notifications received by NotificationObserver.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(LocationBarView); DISALLOW_COPY_AND_ASSIGN(LocationBarView);
}; };
......
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