| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/page_action_controller.h" | 5 #include "chrome/browser/extensions/page_action_controller.h" |
| 6 | 6 |
| 7 #include <set> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 12 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 13 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 14 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "content/public/browser/navigation_details.h" | |
| 18 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 19 #include "extensions/browser/extension_registry.h" | |
| 20 #include "extensions/common/extension_set.h" | |
| 21 | 13 |
| 22 namespace extensions { | 14 namespace extensions { |
| 23 | 15 |
| 24 // Keeps track of the profiles for which we've sent UMA statistics. | |
| 25 base::LazyInstance<std::set<Profile*> > g_reported_for_profiles = | |
| 26 LAZY_INSTANCE_INITIALIZER; | |
| 27 | |
| 28 PageActionController::PageActionController(content::WebContents* web_contents) | 16 PageActionController::PageActionController(content::WebContents* web_contents) |
| 29 : web_contents_(web_contents), | 17 : web_contents_(web_contents), |
| 30 extension_action_observer_(this) { | 18 browser_context_(web_contents_->GetBrowserContext()) { |
| 31 extension_action_observer_.Add( | |
| 32 ExtensionActionAPI::Get(web_contents_->GetBrowserContext())); | |
| 33 } | 19 } |
| 34 | 20 |
| 35 PageActionController::~PageActionController() { | 21 PageActionController::~PageActionController() { |
| 36 } | 22 } |
| 37 | 23 |
| 38 ExtensionAction* PageActionController::GetActionForExtension( | 24 ExtensionAction* PageActionController::GetActionForExtension( |
| 39 const Extension* extension) { | 25 const Extension* extension) { |
| 40 return ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); | 26 return ExtensionActionManager::Get(browser_context_)->GetPageAction( |
| 27 *extension); |
| 41 } | 28 } |
| 42 | 29 |
| 43 ExtensionAction::ShowAction PageActionController::OnClicked( | 30 ExtensionAction::ShowAction PageActionController::OnClicked( |
| 44 const Extension* extension) { | 31 const Extension* extension) { |
| 45 ExtensionAction* page_action = | 32 ExtensionAction* page_action = |
| 46 ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); | 33 ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension); |
| 47 CHECK(page_action); | 34 CHECK(page_action); |
| 48 | 35 |
| 49 int tab_id = SessionTabHelper::IdForTab(web_contents_); | 36 int tab_id = SessionTabHelper::IdForTab(web_contents_); |
| 50 TabHelper::FromWebContents(web_contents_)-> | 37 TabHelper::FromWebContents(web_contents_)-> |
| 51 active_tab_permission_granter()->GrantIfRequested(extension); | 38 active_tab_permission_granter()->GrantIfRequested(extension); |
| 52 | 39 |
| 53 if (page_action->HasPopup(tab_id)) | 40 if (page_action->HasPopup(tab_id)) |
| 54 return ExtensionAction::ACTION_SHOW_POPUP; | 41 return ExtensionAction::ACTION_SHOW_POPUP; |
| 55 | 42 |
| 56 ExtensionActionAPI::PageActionExecuted( | 43 ExtensionActionAPI::PageActionExecuted( |
| 57 web_contents_->GetBrowserContext(), | 44 browser_context_, |
| 58 *page_action, | 45 *page_action, |
| 59 tab_id, | 46 tab_id, |
| 60 web_contents_->GetLastCommittedURL().spec(), | 47 web_contents_->GetLastCommittedURL().spec(), |
| 61 1 /* Button indication. We only ever pass left-click. */); | 48 1 /* Button indication. We only ever pass left-click. */); |
| 62 | 49 |
| 63 return ExtensionAction::ACTION_NONE; | 50 return ExtensionAction::ACTION_NONE; |
| 64 } | 51 } |
| 65 | 52 |
| 66 void PageActionController::OnNavigated() { | 53 void PageActionController::OnNavigated() { |
| 67 // Clearing extension action values is handled in TabHelper, so nothing to | 54 // Clearing extension action values is handled in TabHelper, so nothing to |
| 68 // do here. | 55 // do here. |
| 69 } | 56 } |
| 70 | 57 |
| 71 void PageActionController::OnExtensionActionUpdated( | |
| 72 ExtensionAction* extension_action, | |
| 73 content::WebContents* web_contents, | |
| 74 content::BrowserContext* browser_context) { | |
| 75 if (web_contents == web_contents_ && | |
| 76 extension_action->action_type() == ActionInfo::TYPE_PAGE) | |
| 77 LocationBarController::NotifyChange(web_contents_); | |
| 78 } | |
| 79 | |
| 80 Profile* PageActionController::GetProfile() { | |
| 81 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 82 } | |
| 83 | |
| 84 } // namespace extensions | 58 } // namespace extensions |
| OLD | NEW |