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

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

Issue 95133002: Add an extension bubble explaining which extensions are in dev mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'ed Created 7 years 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/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h"
10 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/suspicious_extension_bubble.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/user_metrics.h" 16 #include "content/public/browser/user_metrics.h"
17 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 20
21 namespace { 21 namespace {
22 22
(...skipping 10 matching lines...) Expand all
33 33
34 } // namespace 34 } // namespace
35 35
36 namespace extensions { 36 namespace extensions {
37 37
38 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
39 // SuspiciousExtensionBubbleController 39 // SuspiciousExtensionBubbleController
40 40
41 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( 41 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
42 Profile* profile) 42 Profile* profile)
43 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()), 43 : ExtensionMessageBubbleController(SUSPICIOUS_EXTENSIONS, profile) {
44 profile_(profile),
45 has_notified_(false) {
46 } 44 }
47 45
48 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { 46 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
49 } 47 }
50 48
51 // static 49 // static
52 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>* 50 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>*
53 SuspiciousExtensionBubbleController::GetFactoryInstance() { 51 SuspiciousExtensionBubbleController::GetFactoryInstance() {
54 return &g_factory.Get(); 52 return &g_factory.Get();
55 } 53 }
56 54
57 // static 55 // static
58 SuspiciousExtensionBubbleController* SuspiciousExtensionBubbleController::Get( 56 SuspiciousExtensionBubbleController* SuspiciousExtensionBubbleController::Get(
59 Profile* profile) { 57 Profile* profile) {
60 return ProfileKeyedAPIFactory< 58 return ProfileKeyedAPIFactory<
61 SuspiciousExtensionBubbleController>::GetForProfile(profile); 59 SuspiciousExtensionBubbleController>::GetForProfile(profile);
62 } 60 }
63 61
64 bool SuspiciousExtensionBubbleController::HasSuspiciousExtensions() { 62 bool SuspiciousExtensionBubbleController::ShouldIncludeExtension(
65 if (has_notified_) 63 const std::string& extension_id) {
64 ExtensionPrefs* prefs = service_->extension_prefs();
65 if (!prefs->IsExtensionDisabled(extension_id))
66 return false; 66 return false;
67 if (!service_)
68 return false; // Can happen during tests.
69 67
70 suspicious_extensions_.clear(); 68 int disble_reasons = prefs->GetDisableReasons(extension_id);
69 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED)
70 return !prefs->HasWipeoutBeenAcknowledged(extension_id);
71 71
72 ExtensionPrefs* prefs = service_->extension_prefs(); 72 return false;
73
74 scoped_ptr<const ExtensionSet> extension_set(
75 service_->GenerateInstalledExtensionsSet());
76 for (ExtensionSet::const_iterator it = extension_set->begin();
77 it != extension_set->end(); ++it) {
78 std::string id = (*it)->id();
79 if (!prefs->IsExtensionDisabled(id))
80 continue;
81 int disble_reasons = prefs->GetDisableReasons(id);
82 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED) {
83 if (prefs->HasWipeoutBeenAcknowledged(id))
84 continue;
85
86 suspicious_extensions_.push_back(id);
87 }
88 }
89
90 UMA_HISTOGRAM_COUNTS_100(
91 "SuspiciousExtensionBubble.ExtensionWipeoutCount",
92 suspicious_extensions_.size());
93
94 has_notified_ = true;
95 return !suspicious_extensions_.empty();
96 } 73 }
97 74
98 void SuspiciousExtensionBubbleController::Show( 75 void SuspiciousExtensionBubbleController::AcknowledgeExtension(
99 SuspiciousExtensionBubble* bubble) { 76 const std::string& extension_id) {
100 // Wire up all the callbacks, to get notified what actions the user took. 77 ExtensionPrefs* prefs = service_->extension_prefs();
101 base::Closure button_callback = 78 prefs->SetWipeoutAcknowledged(extension_id, true);
102 base::Bind(&SuspiciousExtensionBubbleController::OnBubbleDismiss,
103 base::Unretained(this));
104 base::Closure link_callback =
105 base::Bind(&SuspiciousExtensionBubbleController::OnLinkClicked,
106 base::Unretained(this));
107 bubble->OnButtonClicked(button_callback);
108 bubble->OnLinkClicked(link_callback);
109
110 content::RecordAction(
111 content::UserMetricsAction("ExtensionWipeoutNotificationShown"));
112
113 bubble->Show();
114 } 79 }
115 80
116 string16 SuspiciousExtensionBubbleController::GetTitle() { 81 void SuspiciousExtensionBubbleController::PerformAction() {
117 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); 82 // This bubble solicits no action from the user. Or as Nimoy would have it:
118 } 83 // "Well, my work here is done".
119
120 string16 SuspiciousExtensionBubbleController::GetMessageBody() {
121 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY,
122 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
123 }
124
125 string16 SuspiciousExtensionBubbleController::GetOverflowText(
126 const string16& overflow_count) {
127 string16 overflow_string = l10n_util::GetStringUTF16(
128 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE);
129 string16 new_string;
130
131 // Just before string freeze, we checked in # as a substitution value for
132 // this string, whereas we should have used $1. It was discovered too late,
133 // so we do the substitution by hand in that case.
134 if (overflow_string.find(ASCIIToUTF16("#")) != string16::npos) {
135 ReplaceChars(overflow_string, ASCIIToUTF16("#").c_str(),
136 overflow_count, &new_string);
137 } else {
138 new_string = l10n_util::GetStringFUTF16(
139 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
140 overflow_count);
141 }
142
143 return new_string;
144 }
145
146 string16 SuspiciousExtensionBubbleController::GetLearnMoreLabel() {
147 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
148 }
149
150 string16 SuspiciousExtensionBubbleController::GetDismissButtonLabel() {
151 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON);
152 }
153
154 std::vector<string16>
155 SuspiciousExtensionBubbleController::GetSuspiciousExtensionNames() {
156 if (suspicious_extensions_.empty())
157 return std::vector<string16>();
158
159 std::vector<string16> return_value;
160 for (ExtensionIdList::const_iterator it = suspicious_extensions_.begin();
161 it != suspicious_extensions_.end(); ++it) {
162 const Extension* extension = service_->GetInstalledExtension(*it);
163 if (extension) {
164 return_value.push_back(UTF8ToUTF16(extension->name()));
165 } else {
166 return_value.push_back(
167 ASCIIToUTF16(std::string("(unknown name) ") + *it));
168 // TODO(finnur): Add this as a string to the grd, for next milestone.
169 }
170 }
171 return return_value;
172 }
173
174 void SuspiciousExtensionBubbleController::OnBubbleDismiss() {
175 content::RecordAction(
176 content::UserMetricsAction("SuspiciousExtensionBubbleDismissed"));
177 UMA_HISTOGRAM_ENUMERATION("SuspiciousExtensionBubble.UserSelection",
178 ACTION_DISMISS, ACTION_BOUNDARY);
179 AcknowledgeWipeout();
180 }
181
182 void SuspiciousExtensionBubbleController::OnLinkClicked() {
183 UMA_HISTOGRAM_ENUMERATION("SuspiciousExtensionBubble.UserSelection",
184 ACTION_LEARN_MORE, ACTION_BOUNDARY);
185 Browser* browser =
186 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
187 if (browser) {
188 browser->OpenURL(
189 content::OpenURLParams(GURL(chrome::kChromeUIExtensionsURL),
190 content::Referrer(),
191 NEW_FOREGROUND_TAB,
192 content::PAGE_TRANSITION_LINK,
193 false));
194 }
195 AcknowledgeWipeout();
196 }
197
198 void SuspiciousExtensionBubbleController::AcknowledgeWipeout() {
199 ExtensionPrefs* prefs = service_->extension_prefs();
200 for (ExtensionIdList::const_iterator it = suspicious_extensions_.begin();
201 it != suspicious_extensions_.end(); ++it) {
202 prefs->SetWipeoutAcknowledged(*it, true);
203 }
204 } 84 }
205 85
206 template <> 86 template <>
207 void ProfileKeyedAPIFactory< 87 void ProfileKeyedAPIFactory<
208 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { 88 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() {
209 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); 89 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
210 } 90 }
211 91
212 } // namespace extensions 92 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698