| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "chrome/browser/extensions/extension_prefs.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 12 #include "chrome/browser/extensions/suspicious_extension_bubble.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_finder.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "content/public/browser/user_metrics.h" | |
| 17 #include "grit/chromium_strings.h" | |
| 18 #include "grit/generated_resources.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 | |
| 21 namespace { | |
| 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< | |
| 31 extensions::SuspiciousExtensionBubbleController> > | |
| 32 g_factory = LAZY_INSTANCE_INITIALIZER; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 namespace extensions { | |
| 37 | |
| 38 //////////////////////////////////////////////////////////////////////////////// | |
| 39 // SuspiciousExtensionBubbleController | |
| 40 | |
| 41 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( | |
| 42 Profile* profile) | |
| 43 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()), | |
| 44 profile_(profile), | |
| 45 has_notified_(false) { | |
| 46 } | |
| 47 | |
| 48 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 ProfileKeyedAPIFactory<SuspiciousExtensionBubbleController>* | |
| 53 SuspiciousExtensionBubbleController::GetFactoryInstance() { | |
| 54 return &g_factory.Get(); | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 SuspiciousExtensionBubbleController* SuspiciousExtensionBubbleController::Get( | |
| 59 Profile* profile) { | |
| 60 return ProfileKeyedAPIFactory< | |
| 61 SuspiciousExtensionBubbleController>::GetForProfile(profile); | |
| 62 } | |
| 63 | |
| 64 bool SuspiciousExtensionBubbleController::HasSuspiciousExtensions() { | |
| 65 if (has_notified_) | |
| 66 return false; | |
| 67 if (!service_) | |
| 68 return false; // Can happen during tests. | |
| 69 | |
| 70 suspicious_extensions_.clear(); | |
| 71 | |
| 72 ExtensionPrefs* prefs = service_->extension_prefs(); | |
| 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 } | |
| 97 | |
| 98 void SuspiciousExtensionBubbleController::Show( | |
| 99 SuspiciousExtensionBubble* bubble) { | |
| 100 // Wire up all the callbacks, to get notified what actions the user took. | |
| 101 base::Closure button_callback = | |
| 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 } | |
| 115 | |
| 116 string16 SuspiciousExtensionBubbleController::GetTitle() { | |
| 117 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); | |
| 118 } | |
| 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 base::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 } | |
| 205 | |
| 206 template <> | |
| 207 void ProfileKeyedAPIFactory< | |
| 208 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { | |
| 209 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | |
| 210 } | |
| 211 | |
| 212 } // namespace extensions | |
| OLD | NEW |