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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
8 #include "base/lazy_instance.h"
9 #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"
13 #include "chrome/browser/extensions/extension_message_bubble.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_toolbar_model.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/common/chrome_version_info.h"
20 #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"
24 #include "extensions/browser/extension_system.h"
25 #include "extensions/common/feature_switch.h"
26 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h"
28 #include "ui/base/l10n/l10n_util.h"
30 namespace extensions
{
34 base::LazyInstance
<std::set
<Profile
*> > g_shown_for_profiles
=
35 LAZY_INSTANCE_INITIALIZER
;
37 ////////////////////////////////////////////////////////////////////////////////
38 // DevModeBubbleDelegate
40 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile
* profile
)
42 service_(ExtensionSystem::Get(profile
)->extension_service()) {}
44 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
47 bool DevModeBubbleDelegate::ShouldIncludeExtension(
48 const std::string
& extension_id
) {
49 const Extension
* extension
= service_
->GetExtensionById(extension_id
, false);
52 return DevModeBubbleController::IsDevModeExtension(extension
);
55 void DevModeBubbleDelegate::AcknowledgeExtension(
56 const std::string
& extension_id
,
57 ExtensionMessageBubbleController::BubbleAction user_action
) {
60 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList
& list
) {
61 for (size_t i
= 0; i
< list
.size(); ++i
)
62 service_
->DisableExtension(list
[i
], Extension::DISABLE_USER_ACTION
);
65 void DevModeBubbleDelegate::OnClose() {
66 ExtensionToolbarModel
* toolbar_model
= ExtensionToolbarModel::Get(profile_
);
68 toolbar_model
->StopHighlighting();
71 base::string16
DevModeBubbleDelegate::GetTitle() const {
72 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE
);
75 base::string16
DevModeBubbleDelegate::GetMessageBody() const {
76 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY
);
79 base::string16
DevModeBubbleDelegate::GetOverflowText(
80 const base::string16
& overflow_count
) const {
81 return l10n_util::GetStringFUTF16(
82 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE
,
86 base::string16
DevModeBubbleDelegate::GetLearnMoreLabel() const {
87 return l10n_util::GetStringUTF16(IDS_LEARN_MORE
);
90 GURL
DevModeBubbleDelegate::GetLearnMoreUrl() const {
91 return GURL(chrome::kChromeUIExtensionsURL
);
94 base::string16
DevModeBubbleDelegate::GetActionButtonLabel() const {
95 return l10n_util::GetStringUTF16(IDS_DISABLE
);
98 base::string16
DevModeBubbleDelegate::GetDismissButtonLabel() const {
99 return l10n_util::GetStringUTF16(IDS_CANCEL
);
102 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
106 void DevModeBubbleDelegate::LogExtensionCount(size_t count
) {
107 UMA_HISTOGRAM_COUNTS_100(
108 "DevModeExtensionBubble.ExtensionsInDevModeCount", count
);
111 void DevModeBubbleDelegate::LogAction(
112 ExtensionMessageBubbleController::BubbleAction action
) {
113 UMA_HISTOGRAM_ENUMERATION(
114 "DevModeExtensionBubble.UserSelection",
115 action
, ExtensionMessageBubbleController::ACTION_BOUNDARY
);
120 ////////////////////////////////////////////////////////////////////////////////
121 // DevModeBubbleController
124 void DevModeBubbleController::ClearProfileListForTesting() {
125 g_shown_for_profiles
.Get().clear();
129 bool DevModeBubbleController::IsDevModeExtension(
130 const Extension
* extension
) {
131 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
132 if (chrome::VersionInfo::GetChannel() <
133 chrome::VersionInfo::CHANNEL_BETA
)
136 return extension
->location() == Manifest::UNPACKED
||
137 extension
->location() == Manifest::COMMAND_LINE
;
140 DevModeBubbleController::DevModeBubbleController(Profile
* profile
)
141 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile
),
145 DevModeBubbleController::~DevModeBubbleController() {
148 bool DevModeBubbleController::ShouldShow() {
149 return !g_shown_for_profiles
.Get().count(profile_
->GetOriginalProfile()) &&
150 !GetExtensionList().empty();
153 void DevModeBubbleController::Show(ExtensionMessageBubble
* bubble
) {
154 g_shown_for_profiles
.Get().insert(profile_
->GetOriginalProfile());
155 ExtensionMessageBubbleController::Show(bubble
);
158 } // namespace extensions