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"
8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/extensions/extension_message_bubble.h"
12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/user_metrics.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
24 base::LazyInstance
<std::set
<Profile
*> > g_shown_for_profiles
=
25 LAZY_INSTANCE_INITIALIZER
;
27 ////////////////////////////////////////////////////////////////////////////////
28 // SuspiciousExtensionBubbleDelegate
30 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
31 ExtensionService
* service
)
35 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
38 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
39 const std::string
& extension_id
) {
40 extensions::ExtensionPrefs
* prefs
= service_
->extension_prefs();
41 if (!prefs
->IsExtensionDisabled(extension_id
))
44 int disble_reasons
= prefs
->GetDisableReasons(extension_id
);
45 if (disble_reasons
& extensions::Extension::DISABLE_NOT_VERIFIED
)
46 return !prefs
->HasWipeoutBeenAcknowledged(extension_id
);
51 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
52 const std::string
& extension_id
,
53 ExtensionMessageBubbleController::BubbleAction user_action
) {
54 extensions::ExtensionPrefs
* prefs
= service_
->extension_prefs();
55 prefs
->SetWipeoutAcknowledged(extension_id
, true);
58 void SuspiciousExtensionBubbleDelegate::PerformAction(
59 const extensions::ExtensionIdList
& list
) {
60 // This bubble solicits no action from the user. Or as Nimoy would have it:
61 // "Well, my work here is done".
64 base::string16
SuspiciousExtensionBubbleDelegate::GetTitle() const {
65 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE
);
68 base::string16
SuspiciousExtensionBubbleDelegate::GetMessageBody() const {
69 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY
,
70 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE
));
73 base::string16
SuspiciousExtensionBubbleDelegate::GetOverflowText(
74 const base::string16
& overflow_count
) const {
75 base::string16 overflow_string
= l10n_util::GetStringUTF16(
76 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE
);
77 base::string16 new_string
;
79 // Just before string freeze, we checked in # as a substitution value for
80 // this string, whereas we should have used $1. It was discovered too late,
81 // so we do the substitution by hand in that case.
82 if (overflow_string
.find(base::ASCIIToUTF16("#")) != base::string16::npos
) {
83 base::ReplaceChars(overflow_string
, base::ASCIIToUTF16("#").c_str(),
84 overflow_count
, &new_string
);
86 new_string
= l10n_util::GetStringFUTF16(
87 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE
,
95 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const {
96 return l10n_util::GetStringUTF16(IDS_LEARN_MORE
);
99 GURL
SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
100 return GURL(chrome::kRemoveNonCWSExtensionURL
);
104 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
105 return base::string16();
109 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
110 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON
);
114 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
118 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
120 UMA_HISTOGRAM_COUNTS_100(
121 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count
);
124 void SuspiciousExtensionBubbleDelegate::LogAction(
125 ExtensionMessageBubbleController::BubbleAction action
) {
126 UMA_HISTOGRAM_ENUMERATION(
127 "ExtensionWipeoutBubble.UserSelection",
128 action
, ExtensionMessageBubbleController::ACTION_BOUNDARY
);
133 namespace extensions
{
135 ////////////////////////////////////////////////////////////////////////////////
136 // SuspiciousExtensionBubbleController
139 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
140 g_shown_for_profiles
.Get().clear();
143 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
145 : ExtensionMessageBubbleController(
146 new SuspiciousExtensionBubbleDelegate(
147 extensions::ExtensionSystem::Get(profile
)->extension_service()),
152 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
155 bool SuspiciousExtensionBubbleController::ShouldShow() {
156 return !g_shown_for_profiles
.Get().count(profile_
) &&
157 !GetExtensionList().empty();
160 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble
* bubble
) {
161 g_shown_for_profiles
.Get().insert(profile_
);
162 ExtensionMessageBubbleController::Show(bubble
);
165 } // namespace extensions