Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 namespace { | |
| 18 | |
| 19 int GetBrowserEventRouterButton(PageBoxController::MouseButton button) { | |
| 20 switch (button) { | |
| 21 case PageBoxController::MOUSE_LEFT: | |
| 22 return 1; | |
| 23 case PageBoxController::MOUSE_MIDDLE: | |
| 24 return 2; | |
| 25 case PageBoxController::MOUSE_RIGHT: | |
| 26 return 3; | |
| 27 } | |
| 28 NOTREACHED(); | |
| 29 return 1; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 PageActionController::PageActionController(TabContentsWrapper* tab_contents) | |
| 35 : tab_contents_(tab_contents) {} | |
| 36 | |
| 37 PageActionController::~PageActionController() {} | |
| 38 | |
| 39 scoped_ptr<PageBoxController::DataList> | |
| 40 PageActionController::GetAllBadgeData() { | |
| 41 const ExtensionSet* extensions = GetExtensionService()->extensions(); | |
| 42 scoped_ptr<DataList> all_badge_data(new DataList()); | |
| 43 for (ExtensionSet::const_iterator i = extensions->begin(); | |
| 44 i != extensions->end(); ++i) { | |
| 45 ExtensionAction* action = (*i)->page_action(); | |
| 46 if (action) { | |
| 47 Data data = { | |
| 48 DECORATION_NONE, | |
| 49 action, | |
| 50 }; | |
| 51 all_badge_data->push_back(data); | |
| 52 } | |
| 53 } | |
| 54 return all_badge_data.Pass(); | |
| 55 } | |
| 56 | |
| 57 PageBoxController::Action PageActionController::OnClicked( | |
| 58 const std::string& extension_id, PageBoxController::MouseButton button) { | |
| 59 const Extension* extension = | |
| 60 GetExtensionService()->extensions()->GetByID(extension_id); | |
| 61 CHECK(extension); | |
| 62 ExtensionAction* page_action = extension->page_action(); | |
| 63 CHECK(page_action); | |
| 64 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); | |
| 65 | |
| 66 switch (button) { | |
| 67 case MOUSE_LEFT: | |
| 68 case MOUSE_MIDDLE: | |
| 69 if (page_action->HasPopup(tab_id)) | |
| 70 return ACTION_SHOW_POPUP; | |
| 71 | |
| 72 GetExtensionService()->browser_event_router()->PageActionExecuted( | |
|
Evan Stade
2012/05/14 19:24:07
ah, I see now that this function takes an integer
not at google - send to devlin
2012/05/15 01:23:56
Done.
| |
| 73 tab_contents_->profile(), | |
| 74 extension->id(), | |
| 75 page_action->id(), | |
| 76 tab_id, | |
| 77 tab_contents_->web_contents()->GetURL().spec(), | |
| 78 GetBrowserEventRouterButton(button)); | |
| 79 return ACTION_NONE; | |
| 80 | |
| 81 case MOUSE_RIGHT: | |
| 82 return extension->ShowConfigureContextMenus() ? | |
| 83 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; | |
| 84 } | |
| 85 | |
| 86 NOTREACHED(); | |
| 87 return ACTION_NONE; | |
| 88 } | |
| 89 | |
| 90 ExtensionService* PageActionController::GetExtensionService() { | |
| 91 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); | |
| 92 } | |
| 93 | |
| 94 } // namespace extensions | |
| OLD | NEW |