Chromium Code Reviews| Index: chrome/browser/extensions/page_action_controller.cc |
| diff --git a/chrome/browser/extensions/page_action_controller.cc b/chrome/browser/extensions/page_action_controller.cc |
| index c21b768e8a3463c95e091e98304415fc4d790b8e..96fe7b2f8d4c07d892c6a40af46294cead77def8 100644 |
| --- a/chrome/browser/extensions/page_action_controller.cc |
| +++ b/chrome/browser/extensions/page_action_controller.cc |
| @@ -8,33 +8,36 @@ |
| #include "chrome/browser/extensions/extension_browser_event_router.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_system.h" |
| +#include "chrome/browser/extensions/extension_tab_helper.h" |
| #include "chrome/browser/extensions/extension_tab_util.h" |
| #include "chrome/common/extensions/extension_set.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_contents.h" |
| namespace extensions { |
| -PageActionController::PageActionController(TabContentsWrapper* tab_contents) |
| - : tab_contents_(tab_contents) {} |
| +PageActionController::PageActionController(TabContentsWrapper* tab_contents, |
| + ExtensionTabHelper* tab_helper) |
| + : tab_contents_(tab_contents) { |
| + tab_helper->AddObserver(this); |
| +} |
| PageActionController::~PageActionController() {} |
|
Matt Perry
2012/05/17 00:17:24
RemoveObserver here
not at google - send to devlin
2012/05/17 01:30:35
Done.
|
| -scoped_ptr<ActionBoxController::DataList> |
| -PageActionController::GetAllBadgeData() { |
| +scoped_ptr<std::vector<ExtensionAction*> > |
| +PageActionController::GetCurrentActions() { |
| + int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
| const ExtensionSet* extensions = GetExtensionService()->extensions(); |
| - scoped_ptr<DataList> all_badge_data(new DataList()); |
| + scoped_ptr<std::vector<ExtensionAction*> > current_actions( |
| + new std::vector<ExtensionAction*>()); |
| for (ExtensionSet::const_iterator i = extensions->begin(); |
| i != extensions->end(); ++i) { |
| ExtensionAction* action = (*i)->page_action(); |
| - if (action) { |
| - Data data = { |
| - DECORATION_NONE, |
| - action, |
| - }; |
| - all_badge_data->push_back(data); |
| - } |
| + if (action && action->GetIsVisible(tab_id)) |
| + current_actions->push_back(action); |
| } |
| - return all_badge_data.Pass(); |
| + return current_actions.Pass(); |
| } |
| ActionBoxController::Action PageActionController::OnClicked( |
| @@ -69,6 +72,25 @@ ActionBoxController::Action PageActionController::OnClicked( |
| return ACTION_NONE; |
| } |
| +void PageActionController::OnPageActionStateChanged() { |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, |
| + content::Source<Profile>(tab_contents_->profile()), |
| + content::Details<TabContentsWrapper>(tab_contents_)); |
| + |
| + // TODO(kalman): remove this, and all occurrences of |
| + // NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, when views and |
| + // cocoa have been updated to not use it. |
| + // |
| + // Only tests care about them, and they only ever use AllSources, so it can |
| + // safely be a bogus value. |
| + ExtensionAction bogus_action(""); |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| + content::Source<ExtensionAction>(&bogus_action), |
| + content::Details<content::WebContents>(tab_contents_->web_contents())); |
| +} |
| + |
| ExtensionService* PageActionController::GetExtensionService() { |
| return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
| } |