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/suspicious_extension_bubble_controller.h"
7 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension.h"
20 #include "grit/components_strings.h"
21 #include "ui/base/l10n/l10n_util.h"
23 using extensions::ExtensionMessageBubbleController
;
27 // Whether the user has been notified about extension being wiped out.
28 const char kWipeoutAcknowledged
[] = "ack_wiped";
30 base::LazyInstance
<std::set
<Profile
*> > g_shown_for_profiles
=
31 LAZY_INSTANCE_INITIALIZER
;
33 ////////////////////////////////////////////////////////////////////////////////
34 // SuspiciousExtensionBubbleDelegate
36 class SuspiciousExtensionBubbleDelegate
37 : public ExtensionMessageBubbleController::Delegate
{
39 explicit SuspiciousExtensionBubbleDelegate(Profile
* profile
);
40 ~SuspiciousExtensionBubbleDelegate() override
;
42 // ExtensionMessageBubbleController::Delegate methods.
43 bool ShouldIncludeExtension(const std::string
& extension_id
) override
;
44 void AcknowledgeExtension(
45 const std::string
& extension_id
,
46 ExtensionMessageBubbleController::BubbleAction user_action
) override
;
47 void PerformAction(const extensions::ExtensionIdList
& list
) override
;
48 base::string16
GetTitle() const override
;
49 base::string16
GetMessageBody(bool anchored_to_browser_action
) const override
;
50 base::string16
GetOverflowText(
51 const base::string16
& overflow_count
) const override
;
52 GURL
GetLearnMoreUrl() const override
;
53 base::string16
GetActionButtonLabel() const override
;
54 base::string16
GetDismissButtonLabel() const override
;
55 bool ShouldShowExtensionList() const override
;
56 void LogExtensionCount(size_t count
) override
;
58 ExtensionMessageBubbleController::BubbleAction action
) override
;
60 DISALLOW_COPY_AND_ASSIGN(SuspiciousExtensionBubbleDelegate
);
63 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
65 : extensions::ExtensionMessageBubbleController::Delegate(profile
) {
66 set_acknowledged_flag_pref_name(kWipeoutAcknowledged
);
69 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
72 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
73 const std::string
& extension_id
) {
74 extensions::ExtensionPrefs
* prefs
= extensions::ExtensionPrefs::Get(
76 if (!prefs
->IsExtensionDisabled(extension_id
))
79 int disable_reasons
= prefs
->GetDisableReasons(extension_id
);
80 if (disable_reasons
& extensions::Extension::DISABLE_NOT_VERIFIED
)
81 return !HasBubbleInfoBeenAcknowledged(extension_id
);
86 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
87 const std::string
& extension_id
,
88 ExtensionMessageBubbleController::BubbleAction user_action
) {
89 SetBubbleInfoBeenAcknowledged(extension_id
, true);
92 void SuspiciousExtensionBubbleDelegate::PerformAction(
93 const extensions::ExtensionIdList
& list
) {
94 // This bubble solicits no action from the user. Or as Nimoy would have it:
95 // "Well, my work here is done".
98 base::string16
SuspiciousExtensionBubbleDelegate::GetTitle() const {
99 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_TITLE
);
102 base::string16
SuspiciousExtensionBubbleDelegate::GetMessageBody(
103 bool anchored_to_browser_action
) const {
104 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BODY
,
105 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE
));
108 base::string16
SuspiciousExtensionBubbleDelegate::GetOverflowText(
109 const base::string16
& overflow_count
) const {
110 return l10n_util::GetStringFUTF16(
111 IDS_EXTENSIONS_DISABLED_AND_N_MORE
,
115 GURL
SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
116 return GURL(chrome::kRemoveNonCWSExtensionURL
);
120 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
121 return base::string16();
125 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
126 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BUTTON
);
130 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
134 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
136 UMA_HISTOGRAM_COUNTS_100(
137 "ExtensionBubble.ExtensionWipeoutCount", count
);
140 void SuspiciousExtensionBubbleDelegate::LogAction(
141 ExtensionMessageBubbleController::BubbleAction action
) {
142 UMA_HISTOGRAM_ENUMERATION(
143 "ExtensionBubble.WipeoutUserSelection",
144 action
, ExtensionMessageBubbleController::ACTION_BOUNDARY
);
149 namespace extensions
{
151 ////////////////////////////////////////////////////////////////////////////////
152 // SuspiciousExtensionBubbleController
155 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
156 g_shown_for_profiles
.Get().clear();
159 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
161 : ExtensionMessageBubbleController(
162 new SuspiciousExtensionBubbleDelegate(profile
),
166 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
169 bool SuspiciousExtensionBubbleController::ShouldShow() {
170 return !g_shown_for_profiles
.Get().count(profile_
->GetOriginalProfile()) &&
171 !GetExtensionList().empty();
174 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble
* bubble
) {
175 g_shown_for_profiles
.Get().insert(profile_
->GetOriginalProfile());
176 ExtensionMessageBubbleController::Show(bubble
);
179 } // namespace extensions