OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dev_mode_bubble_controller.h" | 5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
9 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "chrome/browser/chrome_notification_types.h" | |
12 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
13 #include "chrome/browser/extensions/extension_message_bubble.h" | 10 #include "chrome/browser/extensions/extension_message_bubble.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_toolbar_model.h" | 12 #include "chrome/browser/extensions/extension_toolbar_model.h" |
16 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_finder.h" | |
19 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
20 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
21 #include "content/public/browser/notification_service.h" | |
22 #include "content/public/browser/user_metrics.h" | |
23 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
24 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
25 #include "extensions/common/feature_switch.h" | 19 #include "extensions/common/feature_switch.h" |
26 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
29 | 23 |
30 namespace extensions { | 24 namespace extensions { |
31 | 25 |
32 namespace { | 26 namespace { |
33 | 27 |
34 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = | 28 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
35 LAZY_INSTANCE_INITIALIZER; | 29 LAZY_INSTANCE_INITIALIZER; |
36 | 30 |
37 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
38 // DevModeBubbleDelegate | 32 // DevModeBubbleDelegate |
39 | 33 |
| 34 class DevModeBubbleDelegate |
| 35 : public ExtensionMessageBubbleController::Delegate { |
| 36 public: |
| 37 explicit DevModeBubbleDelegate(Profile* profile); |
| 38 virtual ~DevModeBubbleDelegate(); |
| 39 |
| 40 // ExtensionMessageBubbleController::Delegate methods. |
| 41 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE; |
| 42 virtual void AcknowledgeExtension( |
| 43 const std::string& extension_id, |
| 44 ExtensionMessageBubbleController::BubbleAction user_action) OVERRIDE; |
| 45 virtual void PerformAction(const ExtensionIdList& list) OVERRIDE; |
| 46 virtual void OnClose() OVERRIDE; |
| 47 virtual base::string16 GetTitle() const OVERRIDE; |
| 48 virtual base::string16 GetMessageBody() const OVERRIDE; |
| 49 virtual base::string16 GetOverflowText( |
| 50 const base::string16& overflow_count) const OVERRIDE; |
| 51 virtual base::string16 GetLearnMoreLabel() const OVERRIDE; |
| 52 virtual GURL GetLearnMoreUrl() const OVERRIDE; |
| 53 virtual base::string16 GetActionButtonLabel() const OVERRIDE; |
| 54 virtual base::string16 GetDismissButtonLabel() const OVERRIDE; |
| 55 virtual bool ShouldShowExtensionList() const OVERRIDE; |
| 56 virtual void LogExtensionCount(size_t count) OVERRIDE; |
| 57 virtual void LogAction( |
| 58 ExtensionMessageBubbleController::BubbleAction action) OVERRIDE; |
| 59 |
| 60 private: |
| 61 // The associated profile (weak). |
| 62 Profile* profile_; |
| 63 |
| 64 // Our extension service. Weak, not owned by us. |
| 65 ExtensionService* service_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate); |
| 68 }; |
| 69 |
40 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) | 70 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) |
41 : profile_(profile), | 71 : profile_(profile), |
42 service_(ExtensionSystem::Get(profile)->extension_service()) {} | 72 service_(ExtensionSystem::Get(profile)->extension_service()) {} |
43 | 73 |
44 DevModeBubbleDelegate::~DevModeBubbleDelegate() { | 74 DevModeBubbleDelegate::~DevModeBubbleDelegate() { |
45 } | 75 } |
46 | 76 |
47 bool DevModeBubbleDelegate::ShouldIncludeExtension( | 77 bool DevModeBubbleDelegate::ShouldIncludeExtension( |
48 const std::string& extension_id) { | 78 const std::string& extension_id) { |
49 const Extension* extension = service_->GetExtensionById(extension_id, false); | 79 const Extension* extension = service_->GetExtensionById(extension_id, false); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 152 |
123 // static | 153 // static |
124 void DevModeBubbleController::ClearProfileListForTesting() { | 154 void DevModeBubbleController::ClearProfileListForTesting() { |
125 g_shown_for_profiles.Get().clear(); | 155 g_shown_for_profiles.Get().clear(); |
126 } | 156 } |
127 | 157 |
128 // static | 158 // static |
129 bool DevModeBubbleController::IsDevModeExtension( | 159 bool DevModeBubbleController::IsDevModeExtension( |
130 const Extension* extension) { | 160 const Extension* extension) { |
131 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { | 161 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { |
132 if (chrome::VersionInfo::GetChannel() < | 162 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA) |
133 chrome::VersionInfo::CHANNEL_BETA) | |
134 return false; | 163 return false; |
135 } | 164 } |
136 return extension->location() == Manifest::UNPACKED || | 165 return extension->location() == Manifest::UNPACKED || |
137 extension->location() == Manifest::COMMAND_LINE; | 166 extension->location() == Manifest::COMMAND_LINE; |
138 } | 167 } |
139 | 168 |
140 DevModeBubbleController::DevModeBubbleController(Profile* profile) | 169 DevModeBubbleController::DevModeBubbleController(Profile* profile) |
141 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), | 170 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), |
142 profile), | 171 profile), |
143 profile_(profile) {} | 172 profile_(profile) {} |
144 | 173 |
145 DevModeBubbleController::~DevModeBubbleController() { | 174 DevModeBubbleController::~DevModeBubbleController() { |
146 } | 175 } |
147 | 176 |
148 bool DevModeBubbleController::ShouldShow() { | 177 bool DevModeBubbleController::ShouldShow() { |
149 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && | 178 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && |
150 !GetExtensionList().empty(); | 179 !GetExtensionList().empty(); |
151 } | 180 } |
152 | 181 |
153 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { | 182 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { |
154 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); | 183 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); |
155 ExtensionMessageBubbleController::Show(bubble); | 184 ExtensionMessageBubbleController::Show(bubble); |
156 } | 185 } |
157 | 186 |
158 } // namespace extensions | 187 } // namespace extensions |
OLD | NEW |