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 |
index 6d9bfad11a903e1ce8c72e7a0fb8e4b015600cc8..dd96e48c96d99fe490410800d5ff24e1d414220e 100644 |
--- a/chrome/browser/extensions/page_action_controller.cc |
+++ b/chrome/browser/extensions/page_action_controller.cc |
@@ -9,14 +9,11 @@ |
#include "base/lazy_instance.h" |
#include "base/metrics/histogram.h" |
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
-#include "chrome/browser/extensions/component_loader.h" |
#include "chrome/browser/extensions/extension_action.h" |
#include "chrome/browser/extensions/extension_action_manager.h" |
-#include "chrome/browser/extensions/extension_tab_util.h" |
#include "chrome/browser/extensions/tab_helper.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sessions/session_id.h" |
-#include "content/public/browser/invalidate_type.h" |
#include "content/public/browser/navigation_details.h" |
#include "content/public/browser/web_contents.h" |
#include "extensions/browser/extension_registry.h" |
@@ -29,27 +26,26 @@ base::LazyInstance<std::set<Profile*> > g_reported_for_profiles = |
LAZY_INSTANCE_INITIALIZER; |
PageActionController::PageActionController(content::WebContents* web_contents) |
- : content::WebContentsObserver(web_contents) {} |
- |
-PageActionController::~PageActionController() {} |
+ : LocationBarControllerProvider(web_contents) { |
+} |
-std::vector<ExtensionAction*> PageActionController::GetCurrentActions() const { |
- ExtensionRegistry* registry = GetExtensionRegistry(); |
- if (!registry) |
- return std::vector<ExtensionAction*>(); |
+PageActionController::~PageActionController() { |
+} |
+std::vector<ExtensionAction*> PageActionController::GetCurrentActions() { |
// Accumulate the list of all page actions to display. |
std::vector<ExtensionAction*> current_actions; |
ExtensionActionManager* extension_action_manager = |
ExtensionActionManager::Get(GetProfile()); |
- const ExtensionSet& enabled_set = registry->enabled_extensions(); |
- for (ExtensionSet::const_iterator i = enabled_set.begin(); |
- i != enabled_set.end(); |
- ++i) { |
+ const ExtensionSet& enabled_set = |
+ GetExtensionRegistry()->enabled_extensions(); |
+ for (ExtensionSet::const_iterator iter = enabled_set.begin(); |
+ iter != enabled_set.end(); |
+ ++iter) { |
ExtensionAction* action = |
- extension_action_manager->GetPageAction(*i->get()); |
+ extension_action_manager->GetPageAction(*iter->get()); |
if (action) |
current_actions.push_back(action); |
} |
@@ -64,47 +60,40 @@ std::vector<ExtensionAction*> PageActionController::GetCurrentActions() const { |
} |
LocationBarController::Action PageActionController::OnClicked( |
- const std::string& extension_id, int mouse_button) { |
- ExtensionRegistry* registry = GetExtensionRegistry(); |
- if (!registry) |
- return ACTION_NONE; |
- |
- const Extension* extension = |
- registry->enabled_extensions().GetByID(extension_id); |
- CHECK(extension); |
+ const Extension* extension, |
+ LocationBarController::MouseButton button) { |
ExtensionAction* page_action = |
ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); |
CHECK(page_action); |
- int tab_id = ExtensionTabUtil::GetTabId(web_contents()); |
+ int tab_id = SessionID::IdForTab(web_contents()); |
extensions::TabHelper::FromWebContents(web_contents())-> |
active_tab_permission_granter()->GrantIfRequested(extension); |
- switch (mouse_button) { |
- case 1: // left |
- case 2: // middle |
+ switch (button) { |
+ case LocationBarController::MOUSE_BUTTON_LEFT: |
+ case LocationBarController::MOUSE_BUTTON_MIDDLE: |
if (page_action->HasPopup(tab_id)) |
- return ACTION_SHOW_POPUP; |
+ return LocationBarController::ACTION_SHOW_POPUP; |
ExtensionActionAPI::PageActionExecuted( |
- GetProfile(), *page_action, tab_id, |
- web_contents()->GetURL().spec(), mouse_button); |
- return ACTION_NONE; |
- |
- case 3: // right |
+ web_contents()->GetBrowserContext(), |
+ *page_action, |
+ tab_id, |
+ web_contents()->GetLastCommittedURL().spec(), |
+ button); |
+ return LocationBarController::ACTION_NONE; |
+ |
+ case LocationBarController::MOUSE_BUTTON_RIGHT: |
return extension->ShowConfigureContextMenus() ? |
- ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; |
+ LocationBarController::ACTION_SHOW_CONTEXT_MENU : |
+ LocationBarController::ACTION_NONE; |
} |
- return ACTION_NONE; |
-} |
- |
-void PageActionController::NotifyChange() { |
- web_contents()->NotifyNavigationStateChanged( |
- content::INVALIDATE_TYPE_PAGE_ACTIONS); |
+ return LocationBarController::ACTION_NONE; |
} |
-void PageActionController::DidNavigateMainFrame( |
+void PageActionController::NavigatedMainFrame( |
const content::LoadCommittedDetails& details, |
const content::FrameNavigateParams& params) { |
if (details.is_in_page) |
@@ -115,25 +104,15 @@ void PageActionController::DidNavigateMainFrame( |
if (current_actions.empty()) |
return; |
- for (size_t i = 0; i < current_actions.size(); ++i) { |
- current_actions[i]->ClearAllValuesForTab( |
- SessionID::IdForTab(web_contents())); |
- } |
+ int tab_id = SessionID::IdForTab(web_contents()); |
+ for (size_t i = 0; i < current_actions.size(); ++i) |
+ current_actions[i]->ClearAllValuesForTab(tab_id); |
NotifyChange(); |
} |
-Profile* PageActionController::GetProfile() const { |
- content::WebContents* web_contents = this->web_contents(); |
- if (web_contents) |
- return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
- |
- return NULL; |
-} |
- |
-ExtensionRegistry* PageActionController::GetExtensionRegistry() const { |
- Profile* profile = this->GetProfile(); |
- return profile ? ExtensionRegistry::Get(profile) : NULL; |
+Profile* PageActionController::GetProfile() { |
+ return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
} |
} // namespace extensions |