EME test page application.
[chromium-blink-merge.git] / chrome / browser / extensions / suspicious_extension_bubble_controller.cc
blob64803a0ff17708bed96815377b7d43d3412a09ed
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 "extensions/browser/extension_prefs.h"
16 #include "extensions/browser/extension_system.h"
17 #include "extensions/common/extension.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
22 using extensions::ExtensionMessageBubbleController;
24 namespace {
26 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
27 LAZY_INSTANCE_INITIALIZER;
29 ////////////////////////////////////////////////////////////////////////////////
30 // SuspiciousExtensionBubbleDelegate
32 class SuspiciousExtensionBubbleDelegate
33 : public ExtensionMessageBubbleController::Delegate {
34 public:
35 explicit SuspiciousExtensionBubbleDelegate(Profile* profile);
36 virtual ~SuspiciousExtensionBubbleDelegate();
38 // ExtensionMessageBubbleController::Delegate methods.
39 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE;
40 virtual void AcknowledgeExtension(
41 const std::string& extension_id,
42 ExtensionMessageBubbleController::BubbleAction user_action) OVERRIDE;
43 virtual void PerformAction(const extensions::ExtensionIdList& list) OVERRIDE;
44 virtual base::string16 GetTitle() const OVERRIDE;
45 virtual base::string16 GetMessageBody() const OVERRIDE;
46 virtual base::string16 GetOverflowText(
47 const base::string16& overflow_count) const OVERRIDE;
48 virtual base::string16 GetLearnMoreLabel() const OVERRIDE;
49 virtual GURL GetLearnMoreUrl() const OVERRIDE;
50 virtual base::string16 GetActionButtonLabel() const OVERRIDE;
51 virtual base::string16 GetDismissButtonLabel() const OVERRIDE;
52 virtual bool ShouldShowExtensionList() const OVERRIDE;
53 virtual void LogExtensionCount(size_t count) OVERRIDE;
54 virtual void LogAction(
55 ExtensionMessageBubbleController::BubbleAction action) OVERRIDE;
57 private:
58 // Our profile. Weak, not owned by us.
59 Profile* profile_;
61 DISALLOW_COPY_AND_ASSIGN(SuspiciousExtensionBubbleDelegate);
64 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
65 Profile* profile)
66 : profile_(profile) {}
68 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
71 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
72 const std::string& extension_id) {
73 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
74 if (!prefs->IsExtensionDisabled(extension_id))
75 return false;
77 int disble_reasons = prefs->GetDisableReasons(extension_id);
78 if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED)
79 return !prefs->HasWipeoutBeenAcknowledged(extension_id);
81 return false;
84 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
85 const std::string& extension_id,
86 ExtensionMessageBubbleController::BubbleAction user_action) {
87 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
88 prefs->SetWipeoutAcknowledged(extension_id, true);
91 void SuspiciousExtensionBubbleDelegate::PerformAction(
92 const extensions::ExtensionIdList& list) {
93 // This bubble solicits no action from the user. Or as Nimoy would have it:
94 // "Well, my work here is done".
97 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const {
98 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_TITLE);
101 base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const {
102 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BODY,
103 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
106 base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText(
107 const base::string16& overflow_count) const {
108 return l10n_util::GetStringFUTF16(
109 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
110 overflow_count);
113 base::string16
114 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const {
115 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
118 GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
119 return GURL(chrome::kRemoveNonCWSExtensionURL);
122 base::string16
123 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
124 return base::string16();
127 base::string16
128 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
129 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BUTTON);
132 bool
133 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
134 return true;
137 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
138 size_t count) {
139 UMA_HISTOGRAM_COUNTS_100(
140 "ExtensionBubble.ExtensionWipeoutCount", count);
143 void SuspiciousExtensionBubbleDelegate::LogAction(
144 ExtensionMessageBubbleController::BubbleAction action) {
145 UMA_HISTOGRAM_ENUMERATION(
146 "ExtensionBubble.WipeoutUserSelection",
147 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
150 } // namespace
152 namespace extensions {
154 ////////////////////////////////////////////////////////////////////////////////
155 // SuspiciousExtensionBubbleController
157 // static
158 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
159 g_shown_for_profiles.Get().clear();
162 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
163 Profile* profile)
164 : ExtensionMessageBubbleController(
165 new SuspiciousExtensionBubbleDelegate(profile),
166 profile),
167 profile_(profile) {}
169 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
172 bool SuspiciousExtensionBubbleController::ShouldShow() {
173 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
174 !GetExtensionList().empty();
177 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) {
178 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
179 ExtensionMessageBubbleController::Show(bubble);
182 } // namespace extensions