| 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/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 | |
| 27 } // namespace | |
| 28 | |
| 29 namespace extensions { | |
| 30 | 26 |
| 31 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
| 32 // SuspiciousExtensionBubbleController | 28 // SuspiciousExtensionBubbleDelegate |
| 33 | 29 |
| 34 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( | 30 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate( |
| 35 Profile* profile) | 31 ExtensionService* service) |
| 36 : ExtensionMessageBubbleController(this, profile), | 32 : service_(service) { |
| 37 service_(extensions::ExtensionSystem::Get(profile)->extension_service()), | |
| 38 profile_(profile) { | |
| 39 } | 33 } |
| 40 | 34 |
| 41 SuspiciousExtensionBubbleController:: | 35 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() { |
| 42 ~SuspiciousExtensionBubbleController() { | |
| 43 } | 36 } |
| 44 | 37 |
| 45 // static | 38 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) { | 39 const std::string& extension_id) { |
| 60 ExtensionPrefs* prefs = service_->extension_prefs(); | 40 extensions::ExtensionPrefs* prefs = service_->extension_prefs(); |
| 61 if (!prefs->IsExtensionDisabled(extension_id)) | 41 if (!prefs->IsExtensionDisabled(extension_id)) |
| 62 return false; | 42 return false; |
| 63 | 43 |
| 64 int disble_reasons = prefs->GetDisableReasons(extension_id); | 44 int disble_reasons = prefs->GetDisableReasons(extension_id); |
| 65 if (disble_reasons & Extension::DISABLE_NOT_VERIFIED) | 45 if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED) |
| 66 return !prefs->HasWipeoutBeenAcknowledged(extension_id); | 46 return !prefs->HasWipeoutBeenAcknowledged(extension_id); |
| 67 | 47 |
| 68 return false; | 48 return false; |
| 69 } | 49 } |
| 70 | 50 |
| 71 void SuspiciousExtensionBubbleController::AcknowledgeExtension( | 51 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension( |
| 72 const std::string& extension_id, | 52 const std::string& extension_id, |
| 73 ExtensionMessageBubbleController::BubbleAction user_action) { | 53 ExtensionMessageBubbleController::BubbleAction user_action) { |
| 74 ExtensionPrefs* prefs = service_->extension_prefs(); | 54 extensions::ExtensionPrefs* prefs = service_->extension_prefs(); |
| 75 prefs->SetWipeoutAcknowledged(extension_id, true); | 55 prefs->SetWipeoutAcknowledged(extension_id, true); |
| 76 } | 56 } |
| 77 | 57 |
| 78 void SuspiciousExtensionBubbleController::PerformAction( | 58 void SuspiciousExtensionBubbleDelegate::PerformAction( |
| 79 const ExtensionIdList& list) { | 59 const extensions::ExtensionIdList& list) { |
| 80 // This bubble solicits no action from the user. Or as Nimoy would have it: | 60 // This bubble solicits no action from the user. Or as Nimoy would have it: |
| 81 // "Well, my work here is done". | 61 // "Well, my work here is done". |
| 82 } | 62 } |
| 83 | 63 |
| 84 base::string16 SuspiciousExtensionBubbleController::GetTitle() const { | 64 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const { |
| 85 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); | 65 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_TITLE); |
| 86 } | 66 } |
| 87 | 67 |
| 88 base::string16 SuspiciousExtensionBubbleController::GetMessageBody() const { | 68 base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const { |
| 89 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, | 69 return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BODY, |
| 90 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); | 70 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
| 91 } | 71 } |
| 92 | 72 |
| 93 base::string16 SuspiciousExtensionBubbleController::GetOverflowText( | 73 base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText( |
| 94 const base::string16& overflow_count) const { | 74 const base::string16& overflow_count) const { |
| 95 base::string16 overflow_string = l10n_util::GetStringUTF16( | 75 base::string16 overflow_string = l10n_util::GetStringUTF16( |
| 96 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); | 76 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE); |
| 97 base::string16 new_string; | 77 base::string16 new_string; |
| 98 | 78 |
| 99 // Just before string freeze, we checked in # as a substitution value for | 79 // 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, | 80 // this string, whereas we should have used $1. It was discovered too late, |
| 101 // so we do the substitution by hand in that case. | 81 // so we do the substitution by hand in that case. |
| 102 if (overflow_string.find(base::ASCIIToUTF16("#")) != base::string16::npos) { | 82 if (overflow_string.find(base::ASCIIToUTF16("#")) != base::string16::npos) { |
| 103 base::ReplaceChars(overflow_string, base::ASCIIToUTF16("#").c_str(), | 83 base::ReplaceChars(overflow_string, base::ASCIIToUTF16("#").c_str(), |
| 104 overflow_count, &new_string); | 84 overflow_count, &new_string); |
| 105 } else { | 85 } else { |
| 106 new_string = l10n_util::GetStringFUTF16( | 86 new_string = l10n_util::GetStringFUTF16( |
| 107 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, | 87 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, |
| 108 overflow_count); | 88 overflow_count); |
| 109 } | 89 } |
| 110 | 90 |
| 111 return new_string; | 91 return new_string; |
| 112 } | 92 } |
| 113 | 93 |
| 114 base::string16 | 94 base::string16 |
| 115 SuspiciousExtensionBubbleController::GetLearnMoreLabel() const { | 95 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const { |
| 116 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 96 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 117 } | 97 } |
| 118 | 98 |
| 119 GURL SuspiciousExtensionBubbleController::GetLearnMoreUrl() const { | 99 GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const { |
| 120 return GURL(chrome::kRemoveNonCWSExtensionURL); | 100 return GURL(chrome::kRemoveNonCWSExtensionURL); |
| 121 } | 101 } |
| 122 | 102 |
| 123 base::string16 | 103 base::string16 |
| 124 SuspiciousExtensionBubbleController::GetActionButtonLabel() const { | 104 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const { |
| 125 return base::string16(); | 105 return base::string16(); |
| 126 } | 106 } |
| 127 | 107 |
| 128 base::string16 | 108 base::string16 |
| 129 SuspiciousExtensionBubbleController::GetDismissButtonLabel() const { | 109 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const { |
| 130 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); | 110 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_SUSPICIOUS_DISABLED_BUTTON); |
| 131 } | 111 } |
| 132 | 112 |
| 133 bool | 113 bool |
| 134 SuspiciousExtensionBubbleController::ShouldShowExtensionList() const { | 114 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const { |
| 135 return true; | 115 return true; |
| 136 } | 116 } |
| 137 | 117 |
| 138 std::vector<base::string16> | 118 void SuspiciousExtensionBubbleDelegate::LogExtensionCount( |
| 139 SuspiciousExtensionBubbleController::GetExtensions() { | |
| 140 return GetExtensionList(); | |
| 141 } | |
| 142 | |
| 143 void SuspiciousExtensionBubbleController::LogExtensionCount( | |
| 144 size_t count) { | 119 size_t count) { |
| 145 UMA_HISTOGRAM_COUNTS_100( | 120 UMA_HISTOGRAM_COUNTS_100( |
| 146 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count); | 121 "ExtensionWipeoutBubble.ExtensionWipeoutCount", count); |
| 147 } | 122 } |
| 148 | 123 |
| 149 void SuspiciousExtensionBubbleController::LogAction( | 124 void SuspiciousExtensionBubbleDelegate::LogAction( |
| 150 ExtensionMessageBubbleController::BubbleAction action) { | 125 ExtensionMessageBubbleController::BubbleAction action) { |
| 151 UMA_HISTOGRAM_ENUMERATION( | 126 UMA_HISTOGRAM_ENUMERATION( |
| 152 "ExtensionWipeoutBubble.UserSelection", | 127 "ExtensionWipeoutBubble.UserSelection", |
| 153 action, ExtensionMessageBubbleController::ACTION_BOUNDARY); | 128 action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| 154 } | 129 } |
| 155 | 130 |
| 156 template <> | 131 } // namespace |
| 157 void ProfileKeyedAPIFactory< | 132 |
| 158 SuspiciousExtensionBubbleController>::DeclareFactoryDependencies() { | 133 namespace extensions { |
| 159 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | 134 |
| 135 //////////////////////////////////////////////////////////////////////////////// |
| 136 // SuspiciousExtensionBubbleController |
| 137 |
| 138 // static |
| 139 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() { |
| 140 g_shown_for_profiles.Get().clear(); |
| 141 } |
| 142 |
| 143 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( |
| 144 Profile* profile) |
| 145 : ExtensionMessageBubbleController( |
| 146 new SuspiciousExtensionBubbleDelegate( |
| 147 extensions::ExtensionSystem::Get(profile)->extension_service()), |
| 148 profile), |
| 149 profile_(profile) { |
| 150 } |
| 151 |
| 152 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { |
| 153 } |
| 154 |
| 155 bool SuspiciousExtensionBubbleController::ShouldShow() { |
| 156 return !g_shown_for_profiles.Get().count(profile_) && |
| 157 !GetExtensionList().empty(); |
| 158 } |
| 159 |
| 160 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) { |
| 161 g_shown_for_profiles.Get().insert(profile_); |
| 162 ExtensionMessageBubbleController::Show(bubble); |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace extensions | 165 } // namespace extensions |
| OLD | NEW |