Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/extensions/suspicious_extension_bubble_controller.cc

Issue 134103002: Refactor the extension message bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile errors on non-Win platform Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" 5 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h" 11 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
17 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 static base::LazyInstance<extensions::ProfileKeyedAPIFactory< 24 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
24 extensions::SuspiciousExtensionBubbleController> > 25 LAZY_INSTANCE_INITIALIZER;
25 g_factory = LAZY_INSTANCE_INITIALIZER;
26 26
27 } // namespace 27 } // namespace
28 28
29 namespace extensions { 29 namespace extensions {
30 30
31 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
32 // SuspiciousExtensionBubbleController 32 // SuspiciousExtensionBubbleDelegate
33 33
34 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( 34 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
35 Profile* profile) 35 Profile* profile)
36 : ExtensionMessageBubbleController(this, profile), 36 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()) {
not at google - send to devlin 2014/01/10 21:28:43 likewise, only need prefs not whole profile
Finnur 2014/01/13 15:36:32 Done.
37 service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
38 profile_(profile) {
39 } 37 }
40 38
41 SuspiciousExtensionBubbleController:: 39 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
42 ~SuspiciousExtensionBubbleController() {
43 } 40 }
44 41
45 // static 42 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
46 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>*
47 SuspiciousExtensionBubbleController::GetFactoryInstance() {
48 return &g_factory.Get();
49 }
50
51 // static
52 SuspiciousExtensionBubbleController*
53 SuspiciousExtensionBubbleController::Get(Profile* profile) {
54 return ProfileKeyedAPIFactory<
55 SuspiciousExtensionBubbleController>::GetForProfile(profile);
56 }
57
58 bool SuspiciousExtensionBubbleController::ShouldIncludeExtension(
59 const std::string& extension_id) { 43 const std::string& extension_id) {
60 ExtensionPrefs* prefs = service_->extension_prefs(); 44 ExtensionPrefs* prefs = service_->extension_prefs();
61 if (!prefs->IsExtensionDisabled(extension_id)) 45 if (!prefs->IsExtensionDisabled(extension_id))
62 return false; 46 return false;
63 47
64 int disble_reasons = prefs->GetDisableReasons(extension_id); 48 int disble_reasons = prefs->GetDisableReasons(extension_id);
65 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED) 49 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED)
66 return !prefs->HasWipeoutBeenAcknowledged(extension_id); 50 return !prefs->HasWipeoutBeenAcknowledged(extension_id);
67 51
68 return false; 52 return false;
69 } 53 }
70 54
71 void SuspiciousExtensionBubbleController::AcknowledgeExtension( 55 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
72 const std::string& extension_id, 56 const std::string& extension_id,
73 ExtensionMessageBubbleController::BubbleAction user_action) { 57 ExtensionMessageBubbleController::BubbleAction user_action) {
74 ExtensionPrefs* prefs = service_->extension_prefs(); 58 ExtensionPrefs* prefs = service_->extension_prefs();
75 prefs->SetWipeoutAcknowledged(extension_id, true); 59 prefs->SetWipeoutAcknowledged(extension_id, true);
76 } 60 }
77 61
78 void SuspiciousExtensionBubbleController::PerformAction( 62 void SuspiciousExtensionBubbleDelegate::PerformAction(
79 const ExtensionIdList& list) { 63 const ExtensionIdList& list) {
80 // This bubble solicits no action from the user. Or as Nimoy would have it: 64 // This bubble solicits no action from the user. Or as Nimoy would have it:
81 // "Well, my work here is done". 65 // "Well, my work here is done".
82 } 66 }
83 67
84 base::string16 SuspiciousExtensionBubbleController::GetTitle() const { 68 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const {
85 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); 69 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE);
86 } 70 }
87 71
88 base::string16 SuspiciousExtensionBubbleController::GetMessageBody() const { 72 base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const {
89 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, 73 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY,
90 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); 74 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
91 } 75 }
92 76
93 base::string16 SuspiciousExtensionBubbleController::GetOverflowText( 77 base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText(
94 const base::string16& overflow_count) const { 78 const base::string16& overflow_count) const {
95 base::string16 overflow_string = l10n_util::GetStringUTF16( 79 base::string16 overflow_string = l10n_util::GetStringUTF16(
96 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); 80 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE);
97 base::string16 new_string; 81 base::string16 new_string;
98 82
99 // Just before string freeze, we checked in # as a substitution value for 83 // Just before string freeze, we checked in # as a substitution value for
100 // this string, whereas we should have used $1. It was discovered too late, 84 // this string, whereas we should have used $1. It was discovered too late,
101 // so we do the substitution by hand in that case. 85 // so we do the substitution by hand in that case.
102 if (overflow_string.find(base::ASCIIToUTF16("#")) != base::string16::npos) { 86 if (overflow_string.find(base::ASCIIToUTF16("#")) != base::string16::npos) {
103 base::ReplaceChars(overflow_string, base::ASCIIToUTF16("#").c_str(), 87 base::ReplaceChars(overflow_string, base::ASCIIToUTF16("#").c_str(),
104 overflow_count, &new_string); 88 overflow_count, &new_string);
105 } else { 89 } else {
106 new_string = l10n_util::GetStringFUTF16( 90 new_string = l10n_util::GetStringFUTF16(
107 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, 91 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
108 overflow_count); 92 overflow_count);
109 } 93 }
110 94
111 return new_string; 95 return new_string;
112 } 96 }
113 97
114 base::string16 98 base::string16
115 SuspiciousExtensionBubbleController::GetLearnMoreLabel() const { 99 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const {
116 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 100 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
117 } 101 }
118 102
119 GURL SuspiciousExtensionBubbleController::GetLearnMoreUrl() const { 103 GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
120 return GURL(chrome::kRemoveNonCWSExtensionURL); 104 return GURL(chrome::kRemoveNonCWSExtensionURL);
121 } 105 }
122 106
123 base::string16 107 base::string16
124 SuspiciousExtensionBubbleController::GetActionButtonLabel() const { 108 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
125 return base::string16(); 109 return base::string16();
126 } 110 }
127 111
128 base::string16 112 base::string16
129 SuspiciousExtensionBubbleController::GetDismissButtonLabel() const { 113 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
130 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); 114 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON);
131 } 115 }
132 116
133 bool 117 bool
134 SuspiciousExtensionBubbleController::ShouldShowExtensionList() const { 118 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
135 return true; 119 return true;
136 } 120 }
137 121
138 std::vector<base::string16> 122 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
139 SuspiciousExtensionBubbleController::GetExtensions() {
140 return GetExtensionList();
141 }
142
143 void SuspiciousExtensionBubbleController::LogExtensionCount(
144 size_t count) { 123 size_t count) {
145 UMA_HISTOGRAM_COUNTS_100( 124 UMA_HISTOGRAM_COUNTS_100(
146 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count); 125 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count);
147 } 126 }
148 127
149 void SuspiciousExtensionBubbleController::LogAction( 128 void SuspiciousExtensionBubbleDelegate::LogAction(
150 ExtensionMessageBubbleController::BubbleAction action) { 129 ExtensionMessageBubbleController::BubbleAction action) {
151 UMA_HISTOGRAM_ENUMERATION( 130 UMA_HISTOGRAM_ENUMERATION(
152 "ExtensionWipeoutBubble.UserSelection", 131 "ExtensionWipeoutBubble.UserSelection",
153 action, ExtensionMessageBubbleController::ACTION_BOUNDARY); 132 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
154 } 133 }
155 134
156 template <> 135 ////////////////////////////////////////////////////////////////////////////////
157 void ProfileKeyedAPIFactory< 136 // SuspiciousExtensionBubbleController
158 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { 137
159 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); 138 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
139 Profile* profile)
140 : ExtensionMessageBubbleController(
141 new SuspiciousExtensionBubbleDelegate(profile), profile),
142 profile_(profile) {
143 }
144
145 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
146 }
147
148 bool SuspiciousExtensionBubbleController::ShouldShow() {
149 return !g_shown_for_profiles.Get().count(profile_) &&
150 !GetExtensionList().empty();
151 }
152
153 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) {
154 g_shown_for_profiles.Get().insert(profile_);
155 ExtensionMessageBubbleController::Show(bubble);
156 }
157
158 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
159 g_shown_for_profiles.Get().clear();
160 } 160 }
161 161
162 } // namespace extensions 162 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698