[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 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 7 | #include "base/lazy_instance.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 8 | #include "base/metrics/histogram.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 | #include "chrome/browser/extensions/extension_message_bubble.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f845448465 | 2014-02-27 04:20:42 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 14 | #include "chrome/common/url_constants.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 15 | #include "chrome/grit/generated_resources.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 16 | #include "extensions/browser/extension_prefs.h" |
[email protected] | d46c050 | 2014-02-14 13:33:36 | [diff] [blame] | 17 | #include "extensions/browser/extension_system.h" |
hashimoto | a804d98 | 2014-09-02 10:35:57 | [diff] [blame] | 18 | #include "grit/components_strings.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 19 | #include "ui/base/l10n/l10n_util.h" |
| 20 | |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 21 | namespace extensions { |
| 22 | |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 23 | namespace { |
| 24 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 25 | base::LazyInstance<std::set<Profile*> > g_shown_for_profiles = |
| 26 | LAZY_INSTANCE_INITIALIZER; |
| 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////// |
| 29 | // DevModeBubbleDelegate |
| 30 | |
[email protected] | 3d4d9337 | 2014-05-20 06:25:31 | [diff] [blame] | 31 | class DevModeBubbleDelegate |
| 32 | : public ExtensionMessageBubbleController::Delegate { |
| 33 | public: |
| 34 | explicit DevModeBubbleDelegate(Profile* profile); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 35 | ~DevModeBubbleDelegate() override; |
[email protected] | 3d4d9337 | 2014-05-20 06:25:31 | [diff] [blame] | 36 | |
| 37 | // ExtensionMessageBubbleController::Delegate methods. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 38 | bool ShouldIncludeExtension(const std::string& extension_id) override; |
| 39 | void AcknowledgeExtension( |
[email protected] | 3d4d9337 | 2014-05-20 06:25:31 | [diff] [blame] | 40 | const std::string& extension_id, |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 41 | ExtensionMessageBubbleController::BubbleAction user_action) override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 42 | void PerformAction(const ExtensionIdList& list) override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 43 | base::string16 GetTitle() const override; |
rdevlin.cronin | 9cb8498 | 2015-05-15 16:57:49 | [diff] [blame^] | 44 | base::string16 GetMessageBody(bool anchored_to_browser_action, |
| 45 | int extension_count) const override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 46 | base::string16 GetOverflowText( |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 47 | const base::string16& overflow_count) const override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 48 | GURL GetLearnMoreUrl() const override; |
| 49 | base::string16 GetActionButtonLabel() const override; |
| 50 | base::string16 GetDismissButtonLabel() const override; |
| 51 | bool ShouldShowExtensionList() const override; |
rdevlin.cronin | 70fc605 | 2015-04-15 17:49:06 | [diff] [blame] | 52 | bool ShouldHighlightExtensions() const override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 53 | void LogExtensionCount(size_t count) override; |
| 54 | void LogAction( |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 55 | ExtensionMessageBubbleController::BubbleAction action) override; |
[email protected] | 3d4d9337 | 2014-05-20 06:25:31 | [diff] [blame] | 56 | |
| 57 | private: |
[email protected] | 3d4d9337 | 2014-05-20 06:25:31 | [diff] [blame] | 58 | // Our extension service. Weak, not owned by us. |
| 59 | ExtensionService* service_; |
| 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate); |
| 62 | }; |
| 63 | |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 64 | DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) |
merkulova | 9be182e | 2014-10-07 14:57:50 | [diff] [blame] | 65 | : ExtensionMessageBubbleController::Delegate(profile), |
| 66 | service_(ExtensionSystem::Get(profile)->extension_service()) { |
| 67 | } |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 68 | |
| 69 | DevModeBubbleDelegate::~DevModeBubbleDelegate() { |
| 70 | } |
| 71 | |
| 72 | bool DevModeBubbleDelegate::ShouldIncludeExtension( |
| 73 | const std::string& extension_id) { |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 74 | const Extension* extension = service_->GetExtensionById(extension_id, false); |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 75 | if (!extension) |
| 76 | return false; |
asargent | a772c58 | 2015-05-08 18:59:01 | [diff] [blame] | 77 | return (extension->location() == Manifest::UNPACKED || |
| 78 | extension->location() == Manifest::COMMAND_LINE); |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void DevModeBubbleDelegate::AcknowledgeExtension( |
| 82 | const std::string& extension_id, |
| 83 | ExtensionMessageBubbleController::BubbleAction user_action) { |
| 84 | } |
| 85 | |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 86 | void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { |
| 87 | for (size_t i = 0; i < list.size(); ++i) |
| 88 | service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION); |
| 89 | } |
| 90 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 91 | base::string16 DevModeBubbleDelegate::GetTitle() const { |
| 92 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); |
| 93 | } |
| 94 | |
[email protected] | 8dc56d0 | 2014-06-07 00:44:23 | [diff] [blame] | 95 | base::string16 DevModeBubbleDelegate::GetMessageBody( |
rdevlin.cronin | 9cb8498 | 2015-05-15 16:57:49 | [diff] [blame^] | 96 | bool anchored_to_browser_action, |
| 97 | int extension_count) const { |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 98 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); |
| 99 | } |
| 100 | |
| 101 | base::string16 DevModeBubbleDelegate::GetOverflowText( |
| 102 | const base::string16& overflow_count) const { |
| 103 | return l10n_util::GetStringFUTF16( |
[email protected] | d246924 | 2014-05-09 11:56:58 | [diff] [blame] | 104 | IDS_EXTENSIONS_DISABLED_AND_N_MORE, |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 105 | overflow_count); |
| 106 | } |
| 107 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 108 | GURL DevModeBubbleDelegate::GetLearnMoreUrl() const { |
| 109 | return GURL(chrome::kChromeUIExtensionsURL); |
| 110 | } |
| 111 | |
| 112 | base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const { |
| 113 | return l10n_util::GetStringUTF16(IDS_DISABLE); |
| 114 | } |
| 115 | |
| 116 | base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const { |
| 117 | return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 118 | } |
| 119 | |
| 120 | bool DevModeBubbleDelegate::ShouldShowExtensionList() const { |
| 121 | return false; |
| 122 | } |
| 123 | |
rdevlin.cronin | 70fc605 | 2015-04-15 17:49:06 | [diff] [blame] | 124 | bool DevModeBubbleDelegate::ShouldHighlightExtensions() const { |
| 125 | return true; |
| 126 | } |
| 127 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 128 | void DevModeBubbleDelegate::LogExtensionCount(size_t count) { |
| 129 | UMA_HISTOGRAM_COUNTS_100( |
[email protected] | b61b05ce8d | 2014-05-14 15:33:01 | [diff] [blame] | 130 | "ExtensionBubble.ExtensionsInDevModeCount", count); |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void DevModeBubbleDelegate::LogAction( |
| 134 | ExtensionMessageBubbleController::BubbleAction action) { |
| 135 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | b61b05ce8d | 2014-05-14 15:33:01 | [diff] [blame] | 136 | "ExtensionBubble.DevModeUserSelection", |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 137 | action, ExtensionMessageBubbleController::ACTION_BOUNDARY); |
| 138 | } |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 139 | |
| 140 | } // namespace |
| 141 | |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 142 | //////////////////////////////////////////////////////////////////////////////// |
| 143 | // DevModeBubbleController |
| 144 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 145 | // static |
| 146 | void DevModeBubbleController::ClearProfileListForTesting() { |
| 147 | g_shown_for_profiles.Get().clear(); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 150 | DevModeBubbleController::DevModeBubbleController(Profile* profile) |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 151 | : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile), |
| 152 | profile), |
[email protected] | d46c050 | 2014-02-14 13:33:36 | [diff] [blame] | 153 | profile_(profile) {} |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 154 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 155 | DevModeBubbleController::~DevModeBubbleController() { |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 158 | bool DevModeBubbleController::ShouldShow() { |
[email protected] | dbc165c | 2014-04-18 19:59:12 | [diff] [blame] | 159 | return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) && |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 160 | !GetExtensionList().empty(); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 163 | void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) { |
[email protected] | dbc165c | 2014-04-18 19:59:12 | [diff] [blame] | 164 | g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile()); |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 165 | ExtensionMessageBubbleController::Show(bubble); |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | } // namespace extensions |