[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 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/dev_mode_bubble_controller.h" |
| 6 | |
| 7 | #include "base/bind.h" |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 8 | #include "base/lazy_instance.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 9 | #include "base/metrics/histogram.h" |
| 10 | #include "base/strings/utf_string_conversions.h" |
| 11 | #include "chrome/browser/chrome_notification_types.h" |
| 12 | #include "chrome/browser/extensions/extension_action_manager.h" |
| 13 | #include "chrome/browser/extensions/extension_message_bubble.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_service.h" |
| 15 | #include "chrome/browser/ui/browser.h" |
| 16 | #include "chrome/browser/ui/browser_finder.h" |
| 17 | #include "chrome/common/chrome_version_info.h" |
| 18 | #include "chrome/common/url_constants.h" |
| 19 | #include "content/public/browser/notification_service.h" |
| 20 | #include "content/public/browser/user_metrics.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame^] | 21 | #include "extensions/browser/extension_prefs.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 22 | #include "extensions/common/feature_switch.h" |
| 23 | #include "grit/chromium_strings.h" |
| 24 | #include "grit/generated_resources.h" |
| 25 | #include "ui/base/l10n/l10n_util.h" |
| 26 | |
| 27 | namespace { |
| 28 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 29 | base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| 30 | LAZY_INSTANCE_INITIALIZER; |
| 31 | |
| 32 | //////////////////////////////////////////////////////////////////////////////// |
| 33 | // DevModeBubbleDelegate |
| 34 | |
| 35 | DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service) |
| 36 | : service_(service) { |
| 37 | } |
| 38 | |
| 39 | DevModeBubbleDelegate::~DevModeBubbleDelegate() { |
| 40 | } |
| 41 | |
| 42 | bool DevModeBubbleDelegate::ShouldIncludeExtension( |
| 43 | const std::string& extension_id) { |
| 44 | const extensions::Extension* extension = |
| 45 | service_->GetExtensionById(extension_id, false); |
| 46 | if (!extension) |
| 47 | return false; |
| 48 | return extensions::DevModeBubbleController::IsDevModeExtension(extension); |
| 49 | } |
| 50 | |
| 51 | void DevModeBubbleDelegate::AcknowledgeExtension( |
| 52 | const std::string& extension_id, |
| 53 | ExtensionMessageBubbleController::BubbleAction user_action) { |
| 54 | } |
| 55 | |
| 56 | void DevModeBubbleDelegate::PerformAction( |
| 57 | const extensions::ExtensionIdList& list) { |
| 58 | for (size_t i = 0; i < list.size(); ++i) { |
| 59 | service_->DisableExtension( |
| 60 | list[i], extensions::Extension::DISABLE_USER_ACTION); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | base::string16 DevModeBubbleDelegate::GetTitle() const { |
| 65 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); |
| 66 | } |
| 67 | |
| 68 | base::string16 DevModeBubbleDelegate::GetMessageBody() const { |
| 69 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); |
| 70 | } |
| 71 | |
| 72 | base::string16 DevModeBubbleDelegate::GetOverflowText( |
| 73 | const base::string16& overflow_count) const { |
| 74 | return l10n_util::GetStringFUTF16( |
| 75 | IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE, |
| 76 | overflow_count); |
| 77 | } |
| 78 | |
| 79 | base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const { |
| 80 | return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 81 | } |
| 82 | |
| 83 | GURL DevModeBubbleDelegate::GetLearnMoreUrl() const { |
| 84 | return GURL(chrome::kChromeUIExtensionsURL); |
| 85 | } |
| 86 | |
| 87 | base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const { |
| 88 | return l10n_util::GetStringUTF16(IDS_DISABLE); |
| 89 | } |
| 90 | |
| 91 | base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const { |
| 92 | return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 93 | } |
| 94 | |
| 95 | bool DevModeBubbleDelegate::ShouldShowExtensionList() const { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | void DevModeBubbleDelegate::LogExtensionCount(size_t count) { |
| 100 | UMA_HISTOGRAM_COUNTS_100( |
| 101 | "DevModeExtensionBubble.ExtensionsInDevModeCount", count); |
| 102 | } |
| 103 | |
| 104 | void DevModeBubbleDelegate::LogAction( |
| 105 | ExtensionMessageBubbleController::BubbleAction action) { |
| 106 | UMA_HISTOGRAM_ENUMERATION( |
| 107 | "DevModeExtensionBubble.UserSelection", |
| 108 | action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| 109 | } |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 110 | |
| 111 | } // namespace |
| 112 | |
| 113 | namespace extensions { |
| 114 | |
| 115 | //////////////////////////////////////////////////////////////////////////////// |
| 116 | // DevModeBubbleController |
| 117 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 118 | // static |
| 119 | void DevModeBubbleController::ClearProfileListForTesting() { |
| 120 | g_shown_for_profiles.Get().clear(); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // static |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 124 | bool DevModeBubbleController::IsDevModeExtension( |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 125 | const Extension* extension) { |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 126 | if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { |
| 127 | if (chrome::VersionInfo::GetChannel() < |
| 128 | chrome::VersionInfo::CHANNEL_BETA) |
| 129 | return false; |
| 130 | } |
| 131 | return extension->location() == Manifest::UNPACKED || |
| 132 | extension->location() == Manifest::COMMAND_LINE; |
| 133 | } |
| 134 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 135 | DevModeBubbleController::DevModeBubbleController(Profile* profile) |
| 136 | : ExtensionMessageBubbleController( |
| 137 | new DevModeBubbleDelegate( |
| 138 | extensions::ExtensionSystem::Get(profile)->extension_service()), |
| 139 | profile), |
| 140 | profile_(profile) { |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 143 | DevModeBubbleController::~DevModeBubbleController() { |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 146 | bool DevModeBubbleController::ShouldShow() { |
| 147 | return !g_shown_for_profiles.Get().count(profile_) && |
| 148 | !GetExtensionList().empty(); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 151 | void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { |
| 152 | g_shown_for_profiles.Get().insert(profile_); |
| 153 | ExtensionMessageBubbleController::Show(bubble); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | } // namespace extensions |