Index: chrome/browser/extensions/page_action_controller.cc |
diff --git a/chrome/browser/extensions/page_action_controller.cc b/chrome/browser/extensions/page_action_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..763c7204abc1e475d10bb712124bb743ba3d8c9c |
--- /dev/null |
+++ b/chrome/browser/extensions/page_action_controller.cc |
@@ -0,0 +1,94 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/page_action_controller.h" |
+ |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+#include "chrome/browser/extensions/extension_browser_event_router.h" |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/extensions/extension_system.h" |
+#include "chrome/browser/extensions/extension_tab_util.h" |
+#include "chrome/common/extensions/extension_set.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+namespace extensions { |
+ |
+namespace { |
+ |
+int GetBrowserEventRouterButton(PageBoxController::MouseButton button) { |
+ switch (button) { |
+ case PageBoxController::MOUSE_LEFT: |
+ return 1; |
+ case PageBoxController::MOUSE_MIDDLE: |
+ return 2; |
+ case PageBoxController::MOUSE_RIGHT: |
+ return 3; |
+ } |
+ NOTREACHED(); |
+ return 1; |
+} |
+ |
+} // namespace |
+ |
+PageActionController::PageActionController(TabContentsWrapper* tab_contents) |
+ : tab_contents_(tab_contents) {} |
+ |
+PageActionController::~PageActionController() {} |
+ |
+scoped_ptr<PageBoxController::DataList> |
+PageActionController::GetAllBadgeData() { |
+ const ExtensionSet* extensions = GetExtensionService()->extensions(); |
+ scoped_ptr<DataList> all_badge_data(new DataList()); |
+ for (ExtensionSet::const_iterator i = extensions->begin(); |
+ i != extensions->end(); ++i) { |
+ ExtensionAction* action = (*i)->page_action(); |
+ if (action) { |
+ Data data = { |
+ DECORATION_NONE, |
+ action, |
+ }; |
+ all_badge_data->push_back(data); |
+ } |
+ } |
+ return all_badge_data.Pass(); |
+} |
+ |
+PageBoxController::Action PageActionController::OnClicked( |
+ const std::string& extension_id, PageBoxController::MouseButton button) { |
+ const Extension* extension = |
+ GetExtensionService()->extensions()->GetByID(extension_id); |
+ CHECK(extension); |
+ ExtensionAction* page_action = extension->page_action(); |
+ CHECK(page_action); |
+ int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
+ |
+ switch (button) { |
+ case MOUSE_LEFT: |
+ case MOUSE_MIDDLE: |
+ if (page_action->HasPopup(tab_id)) |
+ return ACTION_SHOW_POPUP; |
+ |
+ 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.
|
+ tab_contents_->profile(), |
+ extension->id(), |
+ page_action->id(), |
+ tab_id, |
+ tab_contents_->web_contents()->GetURL().spec(), |
+ GetBrowserEventRouterButton(button)); |
+ return ACTION_NONE; |
+ |
+ case MOUSE_RIGHT: |
+ return extension->ShowConfigureContextMenus() ? |
+ ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
+ } |
+ |
+ NOTREACHED(); |
+ return ACTION_NONE; |
+} |
+ |
+ExtensionService* PageActionController::GetExtensionService() { |
+ return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
+} |
+ |
+} // namespace extensions |