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_service.h"
13 #include "chrome/browser/profiles/profile.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 "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_system.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
26 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
27 LAZY_INSTANCE_INITIALIZER;
29 ////////////////////////////////////////////////////////////////////////////////
30 // SuspiciousExtensionBubbleDelegate
32 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
34 : profile_(profile) {}
36 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
39 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
40 const std::string& extension_id) {
41 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
42 if (!prefs->IsExtensionDisabled(extension_id))
45 int disble_reasons = prefs->GetDisableReasons(extension_id);
46 if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED)
47 return !prefs->HasWipeoutBeenAcknowledged(extension_id);
52 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
53 const std::string& extension_id,
54 ExtensionMessageBubbleController::BubbleAction user_action) {
55 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
56 prefs->SetWipeoutAcknowledged(extension_id, true);
59 void SuspiciousExtensionBubbleDelegate::PerformAction(
60 const extensions::ExtensionIdList& list) {
61 // This bubble solicits no action from the user. Or as Nimoy would have it:
62 // "Well, my work here is done".
65 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const {
66 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_TITLE);
69 base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const {
70 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BODY,
71 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
74 base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText(
75 const base::string16& overflow_count) const {
76 return l10n_util::GetStringFUTF16(
77 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
82 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const {
83 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
86 GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
87 return GURL(chrome::kRemoveNonCWSExtensionURL);
91 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
92 return base::string16();
96 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
97 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BUTTON);
101 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
105 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
107 UMA_HISTOGRAM_COUNTS_100(
108 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count);
111 void SuspiciousExtensionBubbleDelegate::LogAction(
112 ExtensionMessageBubbleController::BubbleAction action) {
113 UMA_HISTOGRAM_ENUMERATION(
114 "ExtensionWipeoutBubble.UserSelection",
115 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
120 namespace extensions {
122 ////////////////////////////////////////////////////////////////////////////////
123 // SuspiciousExtensionBubbleController
126 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
127 g_shown_for_profiles.Get().clear();
130 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
132 : ExtensionMessageBubbleController(
133 new SuspiciousExtensionBubbleDelegate(profile),
137 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
140 bool SuspiciousExtensionBubbleController::ShouldShow() {
141 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
142 !GetExtensionList().empty();
145 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) {
146 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
147 ExtensionMessageBubbleController::Show(bubble);
150 } // namespace extensions