| 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/lazy_instance.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/extension_message_bubble.h" | 11 #include "chrome/browser/extensions/extension_message_bubble.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.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 "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
| 18 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 19 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = | 26 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| 26 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
| 27 | 28 |
| 28 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 29 // SuspiciousExtensionBubbleDelegate | 30 // SuspiciousExtensionBubbleDelegate |
| 30 | 31 |
| 31 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate( | 32 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate( |
| 32 ExtensionService* service) | 33 Profile* profile) |
| 33 : service_(service) { | 34 : profile_(profile) {} |
| 34 } | |
| 35 | 35 |
| 36 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() { | 36 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension( | 39 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension( |
| 40 const std::string& extension_id) { | 40 const std::string& extension_id) { |
| 41 extensions::ExtensionPrefs* prefs = service_->extension_prefs(); | 41 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
| 42 if (!prefs->IsExtensionDisabled(extension_id)) | 42 if (!prefs->IsExtensionDisabled(extension_id)) |
| 43 return false; | 43 return false; |
| 44 | 44 |
| 45 int disble_reasons = prefs->GetDisableReasons(extension_id); | 45 int disble_reasons = prefs->GetDisableReasons(extension_id); |
| 46 if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED) | 46 if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED) |
| 47 return !prefs->HasWipeoutBeenAcknowledged(extension_id); | 47 return !prefs->HasWipeoutBeenAcknowledged(extension_id); |
| 48 | 48 |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension( | 52 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension( |
| 53 const std::string& extension_id, | 53 const std::string& extension_id, |
| 54 ExtensionMessageBubbleController::BubbleAction user_action) { | 54 ExtensionMessageBubbleController::BubbleAction user_action) { |
| 55 extensions::ExtensionPrefs* prefs = service_->extension_prefs(); | 55 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
| 56 prefs->SetWipeoutAcknowledged(extension_id, true); | 56 prefs->SetWipeoutAcknowledged(extension_id, true); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SuspiciousExtensionBubbleDelegate::PerformAction( | 59 void SuspiciousExtensionBubbleDelegate::PerformAction( |
| 60 const extensions::ExtensionIdList& list) { | 60 const extensions::ExtensionIdList& list) { |
| 61 // This bubble solicits no action from the user. Or as Nimoy would have it: | 61 // This bubble solicits no action from the user. Or as Nimoy would have it: |
| 62 // "Well, my work here is done". | 62 // "Well, my work here is done". |
| 63 } | 63 } |
| 64 | 64 |
| 65 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const { | 65 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // SuspiciousExtensionBubbleController | 137 // SuspiciousExtensionBubbleController |
| 138 | 138 |
| 139 // static | 139 // static |
| 140 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() { | 140 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() { |
| 141 g_shown_for_profiles.Get().clear(); | 141 g_shown_for_profiles.Get().clear(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( | 144 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController( |
| 145 Profile* profile) | 145 Profile* profile) |
| 146 : ExtensionMessageBubbleController( | 146 : ExtensionMessageBubbleController( |
| 147 new SuspiciousExtensionBubbleDelegate( | 147 new SuspiciousExtensionBubbleDelegate(profile), |
| 148 extensions::ExtensionSystem::Get(profile)->extension_service()), | |
| 149 profile), | 148 profile), |
| 150 profile_(profile) { | 149 profile_(profile) {} |
| 151 } | |
| 152 | 150 |
| 153 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { | 151 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() { |
| 154 } | 152 } |
| 155 | 153 |
| 156 bool SuspiciousExtensionBubbleController::ShouldShow() { | 154 bool SuspiciousExtensionBubbleController::ShouldShow() { |
| 157 return !g_shown_for_profiles.Get().count(profile_) && | 155 return !g_shown_for_profiles.Get().count(profile_) && |
| 158 !GetExtensionList().empty(); | 156 !GetExtensionList().empty(); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) { | 159 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) { |
| 162 g_shown_for_profiles.Get().insert(profile_); | 160 g_shown_for_profiles.Get().insert(profile_); |
| 163 ExtensionMessageBubbleController::Show(bubble); | 161 ExtensionMessageBubbleController::Show(bubble); |
| 164 } | 162 } |
| 165 | 163 |
| 166 } // namespace extensions | 164 } // namespace extensions |
| OLD | NEW |