| OLD | NEW |
| 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 |
| 23 // UMA histogram constants. | |
| 24 enum UmaWipeoutHistogramOptions { | |
| 25 ACTION_LEARN_MORE = 0, | |
| 26 ACTION_DISMISS, | |
| 27 ACTION_BOUNDARY, // Must be the last value. | |
| 28 }; | |
| 29 | |
| 30 static base::LazyInstance<extensions::ProfileKeyedAPIFactory< | 23 static base::LazyInstance<extensions::ProfileKeyedAPIFactory< |
| 31 extensions::SuspiciousExtensionBubbleController> > | 24 extensions::SuspiciousExtensionBubbleController> > |
| 32 g_factory = LAZY_INSTANCE_INITIALIZER; | 25 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 33 | 26 |
| 34 } // namespace | 27 } // namespace |
| 35 | 28 |
| 36 namespace extensions { | 29 namespace extensions { |
| 37 | 30 |
| 38 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 39 // SuspiciousExtensionBubbleController | 32 // SuspiciousExtensionBubbleController |
| 40 | 33 |
| 41 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( | 34 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( |
| 42 Profile* profile) | 35 Profile* profile) |
| 43 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()), | 36 : ExtensionMessageBubbleController(this, profile), |
| 44 profile_(profile), | 37 service_(extensions::ExtensionSystem::Get(profile)->extension_service()), |
| 45 has_notified_(false) { | 38 profile_(profile) { |
| 46 } | 39 } |
| 47 | 40 |
| 48 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { | 41 SuspiciousExtensionBubbleController:: |
| 42 ~SuspiciousExtensionBubbleController() { |
| 49 } | 43 } |
| 50 | 44 |
| 51 // static | 45 // static |
| 52 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>* | 46 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>* |
| 53 SuspiciousExtensionBubbleController::GetFactoryInstance() { | 47 SuspiciousExtensionBubbleController::GetFactoryInstance() { |
| 54 return &g_factory.Get(); | 48 return &g_factory.Get(); |
| 55 } | 49 } |
| 56 | 50 |
| 57 // static | 51 // static |
| 58 SuspiciousExtensionBubbleController* SuspiciousExtensionBubbleController::Get( | 52 SuspiciousExtensionBubbleController* |
| 59 Profile* profile) { | 53 SuspiciousExtensionBubbleController::Get(Profile* profile) { |
| 60 return ProfileKeyedAPIFactory< | 54 return ProfileKeyedAPIFactory< |
| 61 SuspiciousExtensionBubbleController>::GetForProfile(profile); | 55 SuspiciousExtensionBubbleController>::GetForProfile(profile); |
| 62 } | 56 } |
| 63 | 57 |
| 64 bool SuspiciousExtensionBubbleController::HasSuspiciousExtensions() { | 58 bool SuspiciousExtensionBubbleController::ShouldIncludeExtension( |
| 65 if (has_notified_) | 59 const std::string& extension_id) { |
| 60 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 61 if (!prefs->IsExtensionDisabled(extension_id)) |
| 66 return false; | 62 return false; |
| 67 if (!service_) | |
| 68 return false; // Can happen during tests. | |
| 69 | 63 |
| 70 suspicious_extensions_.clear(); | 64 int disble_reasons = prefs->GetDisableReasons(extension_id); |
| 65 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED) |
| 66 return !prefs->HasWipeoutBeenAcknowledged(extension_id); |
| 71 | 67 |
| 72 ExtensionPrefs* prefs = service_->extension_prefs(); | 68 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 } | 69 } |
| 97 | 70 |
| 98 void SuspiciousExtensionBubbleController::Show( | 71 void SuspiciousExtensionBubbleController::AcknowledgeExtension( |
| 99 SuspiciousExtensionBubble* bubble) { | 72 const std::string& extension_id, |
| 100 // Wire up all the callbacks, to get notified what actions the user took. | 73 ExtensionMessageBubbleController::BubbleAction user_action) { |
| 101 base::Closure button_callback = | 74 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 102 base::Bind(&SuspiciousExtensionBubbleController::OnBubbleDismiss, | 75 prefs->SetWipeoutAcknowledged(extension_id, true); |
| 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 } | 76 } |
| 115 | 77 |
| 116 base::string16 SuspiciousExtensionBubbleController::GetTitle() { | 78 void SuspiciousExtensionBubbleController::PerformAction( |
| 79 const ExtensionIdList& list) { |
| 80 // This bubble solicits no action from the user. Or as Nimoy would have it: |
| 81 // "Well, my work here is done". |
| 82 } |
| 83 |
| 84 base::string16 SuspiciousExtensionBubbleController::GetTitle() const { |
| 117 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); | 85 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); |
| 118 } | 86 } |
| 119 | 87 |
| 120 base::string16 SuspiciousExtensionBubbleController::GetMessageBody() { | 88 base::string16 SuspiciousExtensionBubbleController::GetMessageBody() const { |
| 121 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, | 89 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, |
| 122 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); | 90 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
| 123 } | 91 } |
| 124 | 92 |
| 125 base::string16 SuspiciousExtensionBubbleController::GetOverflowText( | 93 base::string16 SuspiciousExtensionBubbleController::GetOverflowText( |
| 126 const base::string16& overflow_count) { | 94 const base::string16& overflow_count) const { |
| 127 base::string16 overflow_string = l10n_util::GetStringUTF16( | 95 base::string16 overflow_string = l10n_util::GetStringUTF16( |
| 128 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); | 96 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); |
| 129 base::string16 new_string; | 97 base::string16 new_string; |
| 130 | 98 |
| 131 // Just before string freeze, we checked in # as a substitution value for | 99 // 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, | 100 // this string, whereas we should have used $1. It was discovered too late, |
| 133 // so we do the substitution by hand in that case. | 101 // so we do the substitution by hand in that case. |
| 134 if (overflow_string.find(ASCIIToUTF16("#")) != base::string16::npos) { | 102 if (overflow_string.find(ASCIIToUTF16("#")) != base::string16::npos) { |
| 135 base::ReplaceChars(overflow_string, ASCIIToUTF16("#").c_str(), | 103 base::ReplaceChars(overflow_string, ASCIIToUTF16("#").c_str(), |
| 136 overflow_count, &new_string); | 104 overflow_count, &new_string); |
| 137 } else { | 105 } else { |
| 138 new_string = l10n_util::GetStringFUTF16( | 106 new_string = l10n_util::GetStringFUTF16( |
| 139 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, | 107 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, |
| 140 overflow_count); | 108 overflow_count); |
| 141 } | 109 } |
| 142 | 110 |
| 143 return new_string; | 111 return new_string; |
| 144 } | 112 } |
| 145 | 113 |
| 146 base::string16 SuspiciousExtensionBubbleController::GetLearnMoreLabel() { | 114 base::string16 |
| 115 SuspiciousExtensionBubbleController::GetLearnMoreLabel() const { |
| 147 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 116 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 148 } | 117 } |
| 149 | 118 |
| 150 base::string16 SuspiciousExtensionBubbleController::GetDismissButtonLabel() { | 119 GURL SuspiciousExtensionBubbleController::GetLearnMoreUrl() const { |
| 120 return GURL(chrome::kRemoveNonCWSExtensionURL); |
| 121 } |
| 122 |
| 123 base::string16 |
| 124 SuspiciousExtensionBubbleController::GetActionButtonLabel() const { |
| 125 return string16(); |
| 126 } |
| 127 |
| 128 base::string16 |
| 129 SuspiciousExtensionBubbleController::GetDismissButtonLabel() const { |
| 151 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); | 130 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); |
| 152 } | 131 } |
| 153 | 132 |
| 154 std::vector<base::string16> | 133 bool |
| 155 SuspiciousExtensionBubbleController::GetSuspiciousExtensionNames() { | 134 SuspiciousExtensionBubbleController::ShouldShowExtensionList() const { |
| 156 if (suspicious_extensions_.empty()) | 135 return true; |
| 157 return std::vector<base::string16>(); | |
| 158 | |
| 159 std::vector<base::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 } | 136 } |
| 173 | 137 |
| 174 void SuspiciousExtensionBubbleController::OnBubbleDismiss() { | 138 std::vector<string16> |
| 175 content::RecordAction( | 139 SuspiciousExtensionBubbleController::GetExtensions() { |
| 176 content::UserMetricsAction("SuspiciousExtensionBubbleDismissed")); | 140 return GetExtensionList(); |
| 177 UMA_HISTOGRAM_ENUMERATION("SuspiciousExtensionBubble.UserSelection", | |
| 178 ACTION_DISMISS, ACTION_BOUNDARY); | |
| 179 AcknowledgeWipeout(); | |
| 180 } | 141 } |
| 181 | 142 |
| 182 void SuspiciousExtensionBubbleController::OnLinkClicked() { | 143 void SuspiciousExtensionBubbleController::LogExtensionCount( |
| 183 UMA_HISTOGRAM_ENUMERATION("SuspiciousExtensionBubble.UserSelection", | 144 size_t count) { |
| 184 ACTION_LEARN_MORE, ACTION_BOUNDARY); | 145 UMA_HISTOGRAM_COUNTS_100( |
| 185 Browser* browser = | 146 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count); |
| 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 } | 147 } |
| 197 | 148 |
| 198 void SuspiciousExtensionBubbleController::AcknowledgeWipeout() { | 149 void SuspiciousExtensionBubbleController::LogAction( |
| 199 ExtensionPrefs* prefs = service_->extension_prefs(); | 150 ExtensionMessageBubbleController::BubbleAction action) { |
| 200 for (ExtensionIdList::const_iterator it = suspicious_extensions_.begin(); | 151 UMA_HISTOGRAM_ENUMERATION( |
| 201 it != suspicious_extensions_.end(); ++it) { | 152 "ExtensionWipeoutBubble.UserSelection", |
| 202 prefs->SetWipeoutAcknowledged(*it, true); | 153 action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| 203 } | |
| 204 } | 154 } |
| 205 | 155 |
| 206 template <> | 156 template <> |
| 207 void ProfileKeyedAPIFactory< | 157 void ProfileKeyedAPIFactory< |
| 208 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { | 158 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { |
| 209 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | 159 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| 210 } | 160 } |
| 211 | 161 |
| 212 } // namespace extensions | 162 } // namespace extensions |
| OLD | NEW |