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" | |
12 #include "chrome/browser/extensions/extension_action.h" | |
13 #include "chrome/browser/extensions/extension_action_manager.h" | 7 #include "chrome/browser/extensions/extension_action_manager.h" |
14 #include "chrome/browser/extensions/tab_helper.h" | |
15 #include "chrome/browser/profiles/profile.h" | |
16 #include "chrome/browser/sessions/session_tab_helper.h" | |
17 #include "content/public/browser/navigation_details.h" | |
18 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
19 #include "extensions/browser/extension_registry.h" | |
20 #include "extensions/common/extension_set.h" | |
21 | 9 |
22 namespace extensions { | 10 namespace extensions { |
23 | 11 |
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) | 12 PageActionController::PageActionController(content::WebContents* web_contents) |
29 : web_contents_(web_contents), | 13 : web_contents_(web_contents), |
30 extension_action_observer_(this) { | 14 browser_context_(web_contents_->GetBrowserContext()) { |
31 extension_action_observer_.Add( | |
32 ExtensionActionAPI::Get(web_contents_->GetBrowserContext())); | |
33 } | 15 } |
34 | 16 |
35 PageActionController::~PageActionController() { | 17 PageActionController::~PageActionController() { |
36 } | 18 } |
37 | 19 |
38 ExtensionAction* PageActionController::GetActionForExtension( | 20 ExtensionAction* PageActionController::GetActionForExtension( |
39 const Extension* extension) { | 21 const Extension* extension) { |
40 return ExtensionActionManager::Get(GetProfile())->GetPageAction(*extension); | 22 return ExtensionActionManager::Get(browser_context_)->GetPageAction( |
| 23 *extension); |
41 } | 24 } |
42 | 25 |
43 void PageActionController::OnNavigated() { | 26 void PageActionController::OnNavigated() { |
44 // Clearing extension action values is handled in TabHelper, so nothing to | 27 // Clearing extension action values is handled in TabHelper, so nothing to |
45 // do here. | 28 // do here. |
46 } | 29 } |
47 | 30 |
48 void PageActionController::OnExtensionActionUpdated( | |
49 ExtensionAction* extension_action, | |
50 content::WebContents* web_contents, | |
51 content::BrowserContext* browser_context) { | |
52 if (web_contents == web_contents_ && | |
53 extension_action->action_type() == ActionInfo::TYPE_PAGE) | |
54 LocationBarController::NotifyChange(web_contents_); | |
55 } | |
56 | |
57 Profile* PageActionController::GetProfile() { | |
58 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
59 } | |
60 | |
61 } // namespace extensions | 31 } // namespace extensions |
OLD | NEW |