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 PageActionController::PageActionController(TabContentsWrapper* tab_contents) |
| 18 : tab_contents_(tab_contents) {} |
| 19 |
| 20 PageActionController::~PageActionController() {} |
| 21 |
| 22 scoped_ptr<ActionBoxController::DataList> |
| 23 PageActionController::GetAllBadgeData() { |
| 24 const ExtensionSet* extensions = GetExtensionService()->extensions(); |
| 25 scoped_ptr<DataList> all_badge_data(new DataList()); |
| 26 for (ExtensionSet::const_iterator i = extensions->begin(); |
| 27 i != extensions->end(); ++i) { |
| 28 ExtensionAction* action = (*i)->page_action(); |
| 29 if (action) { |
| 30 Data data = { |
| 31 DECORATION_NONE, |
| 32 action, |
| 33 }; |
| 34 all_badge_data->push_back(data); |
| 35 } |
| 36 } |
| 37 return all_badge_data.Pass(); |
| 38 } |
| 39 |
| 40 ActionBoxController::Action PageActionController::OnClicked( |
| 41 const std::string& extension_id, int mouse_button) { |
| 42 const Extension* extension = |
| 43 GetExtensionService()->extensions()->GetByID(extension_id); |
| 44 CHECK(extension); |
| 45 ExtensionAction* page_action = extension->page_action(); |
| 46 CHECK(page_action); |
| 47 int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
| 48 |
| 49 switch (mouse_button) { |
| 50 case 1: |
| 51 case 2: |
| 52 if (page_action->HasPopup(tab_id)) |
| 53 return ACTION_SHOW_POPUP; |
| 54 |
| 55 GetExtensionService()->browser_event_router()->PageActionExecuted( |
| 56 tab_contents_->profile(), |
| 57 extension->id(), |
| 58 page_action->id(), |
| 59 tab_id, |
| 60 tab_contents_->web_contents()->GetURL().spec(), |
| 61 mouse_button); |
| 62 return ACTION_NONE; |
| 63 |
| 64 case 3: |
| 65 return extension->ShowConfigureContextMenus() ? |
| 66 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
| 67 } |
| 68 |
| 69 return ACTION_NONE; |
| 70 } |
| 71 |
| 72 ExtensionService* PageActionController::GetExtensionService() { |
| 73 return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
| 74 } |
| 75 |
| 76 } // namespace extensions |
OLD | NEW |