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->AddObserver(this); | |
24 } | |
19 | 25 |
20 PageActionController::~PageActionController() {} | 26 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.
| |
21 | 27 |
22 scoped_ptr<ActionBoxController::DataList> | 28 scoped_ptr<std::vector<ExtensionAction*> > |
23 PageActionController::GetAllBadgeData() { | 29 PageActionController::GetCurrentActions() { |
30 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); | |
24 const ExtensionSet* extensions = GetExtensionService()->extensions(); | 31 const ExtensionSet* extensions = GetExtensionService()->extensions(); |
25 scoped_ptr<DataList> all_badge_data(new DataList()); | 32 scoped_ptr<std::vector<ExtensionAction*> > current_actions( |
33 new std::vector<ExtensionAction*>()); | |
26 for (ExtensionSet::const_iterator i = extensions->begin(); | 34 for (ExtensionSet::const_iterator i = extensions->begin(); |
27 i != extensions->end(); ++i) { | 35 i != extensions->end(); ++i) { |
28 ExtensionAction* action = (*i)->page_action(); | 36 ExtensionAction* action = (*i)->page_action(); |
29 if (action) { | 37 if (action && action->GetIsVisible(tab_id)) |
30 Data data = { | 38 current_actions->push_back(action); |
31 DECORATION_NONE, | |
32 action, | |
33 }; | |
34 all_badge_data->push_back(data); | |
35 } | |
36 } | 39 } |
37 return all_badge_data.Pass(); | 40 return current_actions.Pass(); |
38 } | 41 } |
39 | 42 |
40 ActionBoxController::Action PageActionController::OnClicked( | 43 ActionBoxController::Action PageActionController::OnClicked( |
41 const std::string& extension_id, int mouse_button) { | 44 const std::string& extension_id, int mouse_button) { |
42 const Extension* extension = | 45 const Extension* extension = |
43 GetExtensionService()->extensions()->GetByID(extension_id); | 46 GetExtensionService()->extensions()->GetByID(extension_id); |
44 CHECK(extension); | 47 CHECK(extension); |
45 ExtensionAction* page_action = extension->page_action(); | 48 ExtensionAction* page_action = extension->page_action(); |
46 CHECK(page_action); | 49 CHECK(page_action); |
47 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); | 50 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
(...skipping 14 matching lines...) Expand all Loading... | |
62 return ACTION_NONE; | 65 return ACTION_NONE; |
63 | 66 |
64 case 3: | 67 case 3: |
65 return extension->ShowConfigureContextMenus() ? | 68 return extension->ShowConfigureContextMenus() ? |
66 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | 69 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
67 } | 70 } |
68 | 71 |
69 return ACTION_NONE; | 72 return ACTION_NONE; |
70 } | 73 } |
71 | 74 |
75 void PageActionController::OnPageActionStateChanged() { | |
76 content::NotificationService::current()->Notify( | |
77 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, | |
78 content::Source<Profile>(tab_contents_->profile()), | |
79 content::Details<TabContentsWrapper>(tab_contents_)); | |
80 | |
81 // TODO(kalman): remove this, and all occurrences of | |
82 // NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, when views and | |
83 // cocoa have been updated to not use it. | |
84 // | |
85 // Only tests care about them, and they only ever use AllSources, so it can | |
86 // safely be a bogus value. | |
87 ExtensionAction bogus_action(""); | |
88 content::NotificationService::current()->Notify( | |
89 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | |
90 content::Source<ExtensionAction>(&bogus_action), | |
91 content::Details<content::WebContents>(tab_contents_->web_contents())); | |
92 } | |
93 | |
72 ExtensionService* PageActionController::GetExtensionService() { | 94 ExtensionService* PageActionController::GetExtensionService() { |
73 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); | 95 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
74 } | 96 } |
75 | 97 |
76 } // namespace extensions | 98 } // namespace extensions |
OLD | NEW |