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

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

Issue 10381105: Refactor UI "badge" (page action) logic into a BadgeController interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dont include badgecontroller.h 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/page_action_controller.h"
6
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
8 #include "chrome/browser/extensions/extension_browser_event_router.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/extensions/extension_tab_util.h"
12 #include "chrome/common/extensions/extension_set.h"
13 #include "content/public/browser/web_contents.h"
14
15 namespace extensions {
16
17 PageActionController::PageActionController(TabContentsWrapper* tab_contents)
18 : tab_contents_(tab_contents) {}
19
20 PageActionController::~PageActionController() {}
21
22 scoped_ptr<BadgeController::DataList> PageActionController::GetAllBadgeData() {
23 const ExtensionSet* extensions = GetExtensionService()->extensions();
24 scoped_ptr<DataList> all_badge_data(new DataList());
25 for (ExtensionSet::const_iterator i = extensions->begin();
26 i != extensions->end(); ++i) {
27 ExtensionAction* action = (*i)->page_action();
28 if (action) {
29 Data data = { badge_decoration::NONE, action };
30 all_badge_data->push_back(data);
31 }
32 }
33 return all_badge_data.Pass();
34 }
35
36 BadgeController::Reaction PageActionController::OnClicked(
37 const std::string& extension_id, int button_type) {
Evan Stade 2012/05/11 21:52:08 is an integer button_type going to easily work for
not at google - send to devlin 2012/05/14 03:59:01 The int matches the value that's being passed into
38 const Extension* extension =
39 GetExtensionService()->GetExtensionById(extension_id, false);
Matt Perry 2012/05/11 21:15:12 nit: use extensions()->GetByID(). I think we're ph
not at google - send to devlin 2012/05/14 03:59:01 Done.
40 CHECK(extension);
41 ExtensionAction* page_action = extension->page_action();
42 CHECK(page_action);
43 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents());
44
45 switch (button_type) {
46 case 1: // left
47 case 2: // middle
48 if (page_action->HasPopup(tab_id))
49 return SHOW_POPUP;
50
51 GetExtensionService()->browser_event_router()->PageActionExecuted(
52 tab_contents_->profile(),
53 extension->id(),
54 page_action->id(),
55 tab_id,
56 tab_contents_->web_contents()->GetURL().spec(),
57 button_type);
58 return NONE;
59
60 case 3: // right
61 return extension->ShowConfigureContextMenus() ? SHOW_CONTEXT_MENU : NONE;
Evan Stade 2012/05/11 21:52:08 doesn't this complain about missing default case?
not at google - send to devlin 2012/05/14 03:59:01 Not clang, at least. This is an enum now anyway.
62 }
63
64 NOTREACHED();
65 return NONE;
66 }
67
68 ExtensionService* PageActionController::GetExtensionService() {
69 return ExtensionSystem::Get(tab_contents_->profile())->extension_service();
70 }
71
72 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698