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(
content::WebContents* web_contents)
: web_contents_(web_contents),
browser_context_(web_contents->GetBrowserContext()),
action_manager_(ExtensionActionManager::Get(browser_context_)),
active_script_controller_(new ActiveScriptController(web_contents_)),
extension_registry_observer_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
......@@ -27,8 +28,6 @@ LocationBarController::~LocationBarController() {
std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
const ExtensionSet& extensions =
ExtensionRegistry::Get(browser_context_)->enabled_extensions();
ExtensionActionManager* action_manager =
ExtensionActionManager::Get(browser_context_);
std::vector<ExtensionAction*> current_actions;
for (ExtensionSet::const_iterator iter = extensions.begin();
iter != extensions.end();
......@@ -36,7 +35,7 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
// 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
// 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)
action = active_script_controller_->GetActionForExtension(iter->get());
if (action)
......@@ -46,12 +45,22 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
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(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
bool should_update = false;
if (ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension))
if (action_manager_->GetPageAction(*extension))
should_update = true;
if (active_script_controller_->GetActionForExtension(extension)) {
......
......@@ -23,6 +23,7 @@ namespace extensions {
class ActiveScriptController;
class Extension;
class ExtensionActionManager;
class ExtensionRegistry;
// Provides the UI with the current page actions for extensions. The execution
......@@ -41,6 +42,9 @@ class LocationBarController : public ExtensionRegistryObserver {
private:
// ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extnesion) OVERRIDE;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
......@@ -52,6 +56,9 @@ class LocationBarController : public ExtensionRegistryObserver {
// The associated BrowserContext.
content::BrowserContext* browser_context_;
// The ExtensionActionManager to provide page actions.
ExtensionActionManager* action_manager_;
// The ActiveScriptController, which could also add actions for extensions if
// they have a pending script.
scoped_ptr<ActiveScriptController> active_script_controller_;
......
......@@ -47,7 +47,6 @@ class ZoomDecorationTest;
class LocationBarViewMac : public LocationBar,
public LocationBarTesting,
public OmniboxEditController,
public content::NotificationObserver,
public SearchModelObserver {
public:
LocationBarViewMac(AutocompleteTextField* field,
......@@ -166,12 +165,6 @@ class LocationBarViewMac : public LocationBar,
AutocompleteTextField* GetAutocompleteTextField() { return field_; }
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// SearchModelObserver:
virtual void ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) OVERRIDE;
......@@ -277,9 +270,6 @@ class LocationBarViewMac : public LocationBar,
Browser* browser_;
// Used to register for notifications received by NotificationObserver.
content::NotificationRegistrar registrar_;
// Used to schedule a task for the first run info bubble.
base::WeakPtrFactory<LocationBarViewMac> weak_ptr_factory_;
......
......@@ -14,7 +14,6 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
......@@ -64,7 +63,6 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/translate/core/browser/language_state.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
......@@ -143,14 +141,6 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
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(
prefs::kEditBookmarksEnabled, profile->GetPrefs(),
base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged,
......@@ -620,15 +610,6 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
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,
const SearchModel::State& new_state) {
if (UpdateMicSearchDecorationVisibility())
......
......@@ -12,7 +12,6 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
......@@ -64,7 +63,6 @@
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.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/web_contents.h"
#include "extensions/browser/extension_registry.h"
......@@ -403,14 +401,6 @@ void LocationBarView::Init() {
hide_url_animation_->SetTweenType(kHideTweenType);
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
// visible when the location entry has just been initialized.
Update(NULL);
......@@ -1692,23 +1682,6 @@ void LocationBarView::OnTemplateURLServiceChanged() {
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:
......
......@@ -20,8 +20,6 @@
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.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/font.h"
#include "ui/gfx/rect.h"
......@@ -85,7 +83,6 @@ class LocationBarView : public LocationBar,
public DropdownBarHostDelegate,
public gfx::AnimationDelegate,
public TemplateURLServiceObserver,
public content::NotificationObserver,
public SearchModelObserver {
public:
// The location bar view's class name.
......@@ -406,11 +403,6 @@ class LocationBarView : public LocationBar,
// TemplateURLServiceObserver:
virtual void OnTemplateURLServiceChanged() OVERRIDE;
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// SearchModelObserver:
virtual void ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) OVERRIDE;
......@@ -553,9 +545,6 @@ class LocationBarView : public LocationBar,
int current_omnibox_width_;
int ending_omnibox_width_;
// Used to register for notifications received by NotificationObserver.
content::NotificationRegistrar registrar_;
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