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..e48fbb11a2b453a63fd042bb3472364028c9d18b |
--- /dev/null |
+++ b/chrome/browser/extensions/page_action_controller.cc |
@@ -0,0 +1,72 @@ |
+// 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 { |
+ |
+PageActionController::PageActionController(TabContentsWrapper* tab_contents) |
+ : tab_contents_(tab_contents) {} |
+ |
+PageActionController::~PageActionController() {} |
+ |
+scoped_ptr<BadgeController::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 = { badge_decoration::NONE, action }; |
+ all_badge_data->push_back(data); |
+ } |
+ } |
+ return all_badge_data.Pass(); |
+} |
+ |
+BadgeController::Reaction PageActionController::OnClicked( |
+ 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
|
+ const Extension* extension = |
+ 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.
|
+ CHECK(extension); |
+ ExtensionAction* page_action = extension->page_action(); |
+ CHECK(page_action); |
+ int tab_id = ExtensionTabUtil::GetTabId(tab_contents_->web_contents()); |
+ |
+ switch (button_type) { |
+ case 1: // left |
+ case 2: // middle |
+ if (page_action->HasPopup(tab_id)) |
+ return SHOW_POPUP; |
+ |
+ GetExtensionService()->browser_event_router()->PageActionExecuted( |
+ tab_contents_->profile(), |
+ extension->id(), |
+ page_action->id(), |
+ tab_id, |
+ tab_contents_->web_contents()->GetURL().spec(), |
+ button_type); |
+ return NONE; |
+ |
+ case 3: // right |
+ 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.
|
+ } |
+ |
+ NOTREACHED(); |
+ return NONE; |
+} |
+ |
+ExtensionService* PageActionController::GetExtensionService() { |
+ return ExtensionSystem::Get(tab_contents_->profile())->extension_service(); |
+} |
+ |
+} // namespace extensions |