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> | 7 #include <set> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
12 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
13 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sessions/session_id.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 | 23 |
24 // Keeps track of the profiles for which we've sent UMA statistics. | 24 // Keeps track of the profiles for which we've sent UMA statistics. |
25 base::LazyInstance<std::set<Profile*> > g_reported_for_profiles = | 25 base::LazyInstance<std::set<Profile*> > g_reported_for_profiles = |
26 LAZY_INSTANCE_INITIALIZER; | 26 LAZY_INSTANCE_INITIALIZER; |
27 | 27 |
28 PageActionController::PageActionController(content::WebContents* web_contents) | 28 PageActionController::PageActionController(content::WebContents* web_contents) |
29 : web_contents_(web_contents) { | 29 : web_contents_(web_contents) { |
30 } | 30 } |
31 | 31 |
32 PageActionController::~PageActionController() { | 32 PageActionController::~PageActionController() { |
33 } | 33 } |
34 | 34 |
35 ExtensionAction* PageActionController::GetActionForExtension( | 35 ExtensionAction* PageActionController::GetActionForExtension( |
36 const Extension* extension) { | 36 const Extension* extension) { |
37 return ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); | 37 return ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); |
38 } | 38 } |
39 | 39 |
40 ExtensionAction::ShowAction PageActionController::OnClicked( | 40 ExtensionAction::ShowAction PageActionController::OnClicked( |
41 const Extension* extension) { | 41 const Extension* extension) { |
42 ExtensionAction* page_action = | 42 ExtensionAction* page_action = |
43 ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); | 43 ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); |
44 CHECK(page_action); | 44 CHECK(page_action); |
45 | 45 |
46 int tab_id = SessionID::IdForTab(web_contents_); | 46 int tab_id = SessionTabHelper::IdForTab(web_contents_); |
47 TabHelper::FromWebContents(web_contents_)-> | 47 TabHelper::FromWebContents(web_contents_)-> |
48 active_tab_permission_granter()->GrantIfRequested(extension); | 48 active_tab_permission_granter()->GrantIfRequested(extension); |
49 | 49 |
50 if (page_action->HasPopup(tab_id)) | 50 if (page_action->HasPopup(tab_id)) |
51 return ExtensionAction::ACTION_SHOW_POPUP; | 51 return ExtensionAction::ACTION_SHOW_POPUP; |
52 | 52 |
53 ExtensionActionAPI::PageActionExecuted( | 53 ExtensionActionAPI::PageActionExecuted( |
54 web_contents_->GetBrowserContext(), | 54 web_contents_->GetBrowserContext(), |
55 *page_action, | 55 *page_action, |
56 tab_id, | 56 tab_id, |
57 web_contents_->GetLastCommittedURL().spec(), | 57 web_contents_->GetLastCommittedURL().spec(), |
58 1 /* Button indication. We only ever pass left-click. */); | 58 1 /* Button indication. We only ever pass left-click. */); |
59 | 59 |
60 return ExtensionAction::ACTION_NONE; | 60 return ExtensionAction::ACTION_NONE; |
61 } | 61 } |
62 | 62 |
63 void PageActionController::OnNavigated() { | 63 void PageActionController::OnNavigated() { |
64 const ExtensionSet& extensions = | 64 const ExtensionSet& extensions = |
65 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) | 65 ExtensionRegistry::Get(web_contents_->GetBrowserContext()) |
66 ->enabled_extensions(); | 66 ->enabled_extensions(); |
67 int tab_id = SessionID::IdForTab(web_contents_); | 67 int tab_id = SessionTabHelper::IdForTab(web_contents_); |
68 size_t num_current_actions = 0u; | 68 size_t num_current_actions = 0u; |
69 for (ExtensionSet::const_iterator iter = extensions.begin(); | 69 for (ExtensionSet::const_iterator iter = extensions.begin(); |
70 iter != extensions.end(); | 70 iter != extensions.end(); |
71 ++iter) { | 71 ++iter) { |
72 ExtensionAction* action = GetActionForExtension(*iter); | 72 ExtensionAction* action = GetActionForExtension(*iter); |
73 if (action) { | 73 if (action) { |
74 action->ClearAllValuesForTab(tab_id); | 74 action->ClearAllValuesForTab(tab_id); |
75 ++num_current_actions; | 75 ++num_current_actions; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 Profile* profile = GetProfile(); | 79 Profile* profile = GetProfile(); |
80 // Report the number of page actions for this profile, if we haven't already. | 80 // Report the number of page actions for this profile, if we haven't already. |
81 // TODO(rdevlin.cronin): This is wrong. Instead, it should record the number | 81 // TODO(rdevlin.cronin): This is wrong. Instead, it should record the number |
82 // of page actions displayed per page. | 82 // of page actions displayed per page. |
83 if (!g_reported_for_profiles.Get().count(profile)) { | 83 if (!g_reported_for_profiles.Get().count(profile)) { |
84 UMA_HISTOGRAM_COUNTS_100("PageActionController.ExtensionsWithPageActions", | 84 UMA_HISTOGRAM_COUNTS_100("PageActionController.ExtensionsWithPageActions", |
85 num_current_actions); | 85 num_current_actions); |
86 g_reported_for_profiles.Get().insert(profile); | 86 g_reported_for_profiles.Get().insert(profile); |
87 } | 87 } |
88 | 88 |
89 LocationBarController::NotifyChange(web_contents_); | 89 LocationBarController::NotifyChange(web_contents_); |
90 } | 90 } |
91 | 91 |
92 Profile* PageActionController::GetProfile() { | 92 Profile* PageActionController::GetProfile() { |
93 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 93 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
94 } | 94 } |
95 | 95 |
96 } // namespace extensions | 96 } // namespace extensions |
OLD | NEW |