OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/page_action_controller.h" | 5 #include "chrome/browser/extensions/page_action_controller.h" |
6 | 6 |
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
8 #include "chrome/browser/extensions/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_tab_helper.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/common/extensions/extension_set.h" | 13 #include "chrome/common/extensions/extension_set.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
14 | 17 |
15 namespace extensions { | 18 namespace extensions { |
16 | 19 |
17 PageActionController::PageActionController(TabContentsWrapper* tab_contents) | 20 PageActionController::PageActionController(TabContentsWrapper* tab_contents, |
18 : tab_contents_(tab_contents) {} | 21 ExtensionTabHelper* tab_helper) |
| 22 : tab_contents_(tab_contents), |
| 23 tab_helper_(tab_helper) { |
| 24 tab_helper->AddObserver(this); |
| 25 } |
19 | 26 |
20 PageActionController::~PageActionController() {} | 27 PageActionController::~PageActionController() { |
| 28 tab_helper_->RemoveObserver(this); |
| 29 } |
21 | 30 |
22 scoped_ptr<ActionBoxController::DataList> | 31 scoped_ptr<std::vector<ExtensionAction*> > |
23 PageActionController::GetAllBadgeData() { | 32 PageActionController::GetCurrentActions() { |
| 33 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
24 const ExtensionSet* extensions = GetExtensionService()->extensions(); | 34 const ExtensionSet* extensions = GetExtensionService()->extensions(); |
25 scoped_ptr<DataList> all_badge_data(new DataList()); | 35 scoped_ptr<std::vector<ExtensionAction*> > current_actions( |
| 36 new std::vector<ExtensionAction*>()); |
26 for (ExtensionSet::const_iterator i = extensions->begin(); | 37 for (ExtensionSet::const_iterator i = extensions->begin(); |
27 i != extensions->end(); ++i) { | 38 i != extensions->end(); ++i) { |
28 ExtensionAction* action = (*i)->page_action(); | 39 ExtensionAction* action = (*i)->page_action(); |
29 if (action) { | 40 if (action && action->GetIsVisible(tab_id)) |
30 Data data = { | 41 current_actions->push_back(action); |
31 DECORATION_NONE, | |
32 action, | |
33 }; | |
34 all_badge_data->push_back(data); | |
35 } | |
36 } | 42 } |
37 return all_badge_data.Pass(); | 43 return current_actions.Pass(); |
38 } | 44 } |
39 | 45 |
40 ActionBoxController::Action PageActionController::OnClicked( | 46 ActionBoxController::Action PageActionController::OnClicked( |
41 const std::string& extension_id, int mouse_button) { | 47 const std::string& extension_id, int mouse_button) { |
42 const Extension* extension = | 48 const Extension* extension = |
43 GetExtensionService()->extensions()->GetByID(extension_id); | 49 GetExtensionService()->extensions()->GetByID(extension_id); |
44 CHECK(extension); | 50 CHECK(extension); |
45 ExtensionAction* page_action = extension->page_action(); | 51 ExtensionAction* page_action = extension->page_action(); |
46 CHECK(page_action); | 52 CHECK(page_action); |
47 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); | 53 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
(...skipping 14 matching lines...) Expand all Loading... |
62 return ACTION_NONE; | 68 return ACTION_NONE; |
63 | 69 |
64 case 3: | 70 case 3: |
65 return extension->ShowConfigureContextMenus() ? | 71 return extension->ShowConfigureContextMenus() ? |
66 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | 72 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
67 } | 73 } |
68 | 74 |
69 return ACTION_NONE; | 75 return ACTION_NONE; |
70 } | 76 } |
71 | 77 |
| 78 void PageActionController::OnPageActionStateChanged() { |
| 79 content::NotificationService::current()->Notify( |
| 80 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, |
| 81 content::Source<Profile>(tab_contents_->profile()), |
| 82 content::Details<TabContentsWrapper>(tab_contents_)); |
| 83 |
| 84 // TODO(kalman): remove this, and all occurrences of |
| 85 // NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, when views and |
| 86 // cocoa have been updated to not use it. |
| 87 // |
| 88 // Only tests care about them, and they only ever use AllSources, so it can |
| 89 // safely be a bogus value. |
| 90 ExtensionAction bogus_action(""); |
| 91 content::NotificationService::current()->Notify( |
| 92 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 93 content::Source<ExtensionAction>(&bogus_action), |
| 94 content::Details<content::WebContents>(tab_contents_->web_contents())); |
| 95 } |
| 96 |
72 ExtensionService* PageActionController::GetExtensionService() { | 97 ExtensionService* PageActionController::GetExtensionService() { |
73 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); | 98 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
74 } | 99 } |
75 | 100 |
76 } // namespace extensions | 101 } // namespace extensions |
OLD | NEW |