Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(951)

Side by Side Diff: chrome/browser/extensions/page_action_controller.cc

Issue 10392142: Revert 137630 - Broke ASAN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "chrome/browser/extensions/extension_tab_util.h" 11 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/common/extensions/extension_set.h" 12 #include "chrome/common/extensions/extension_set.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
17 14
18 namespace extensions { 15 namespace extensions {
19 16
20 PageActionController::PageActionController(TabContentsWrapper* tab_contents, 17 PageActionController::PageActionController(TabContentsWrapper* tab_contents)
21 ExtensionTabHelper* tab_helper) 18 : tab_contents_(tab_contents) {}
22 : tab_contents_(tab_contents),
23 tab_helper_(tab_helper) {
24 tab_helper->AddObserver(this);
25 }
26 19
27 PageActionController::~PageActionController() { 20 PageActionController::~PageActionController() {}
28 tab_helper_->RemoveObserver(this);
29 }
30 21
31 scoped_ptr<std::vector<ExtensionAction*> > 22 scoped_ptr<ActionBoxController::DataList>
32 PageActionController::GetCurrentActions() { 23 PageActionController::GetAllBadgeData() {
33 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents());
34 const ExtensionSet* extensions = GetExtensionService()->extensions(); 24 const ExtensionSet* extensions = GetExtensionService()->extensions();
35 scoped_ptr<std::vector<ExtensionAction*> > current_actions( 25 scoped_ptr<DataList> all_badge_data(new DataList());
36 new std::vector<ExtensionAction*>());
37 for (ExtensionSet::const_iterator i = extensions->begin(); 26 for (ExtensionSet::const_iterator i = extensions->begin();
38 i != extensions->end(); ++i) { 27 i != extensions->end(); ++i) {
39 ExtensionAction* action = (*i)->page_action(); 28 ExtensionAction* action = (*i)->page_action();
40 if (action && action->GetIsVisible(tab_id)) 29 if (action) {
41 current_actions->push_back(action); 30 Data data = {
31 DECORATION_NONE,
32 action,
33 };
34 all_badge_data->push_back(data);
35 }
42 } 36 }
43 return current_actions.Pass(); 37 return all_badge_data.Pass();
44 } 38 }
45 39
46 ActionBoxController::Action PageActionController::OnClicked( 40 ActionBoxController::Action PageActionController::OnClicked(
47 const std::string& extension_id, int mouse_button) { 41 const std::string& extension_id, int mouse_button) {
48 const Extension* extension = 42 const Extension* extension =
49 GetExtensionService()->extensions()->GetByID(extension_id); 43 GetExtensionService()->extensions()->GetByID(extension_id);
50 CHECK(extension); 44 CHECK(extension);
51 ExtensionAction* page_action = extension->page_action(); 45 ExtensionAction* page_action = extension->page_action();
52 CHECK(page_action); 46 CHECK(page_action);
53 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); 47 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents());
(...skipping 14 matching lines...) Expand all
68 return ACTION_NONE; 62 return ACTION_NONE;
69 63
70 case 3: 64 case 3:
71 return extension->ShowConfigureContextMenus() ? 65 return extension->ShowConfigureContextMenus() ?
72 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; 66 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE;
73 } 67 }
74 68
75 return ACTION_NONE; 69 return ACTION_NONE;
76 } 70 }
77 71
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
97 ExtensionService* PageActionController::GetExtensionService() { 72 ExtensionService* PageActionController::GetExtensionService() {
98 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); 73 return ExtensionSystem::Get(tab_contents_->profile())->extension_service();
99 } 74 }
100 75
101 } // namespace extensions 76 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/page_action_controller.h ('k') | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698