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