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