[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 | |||||
rdevlin.cronin | 690e44f | 2015-11-06 00:27:14 | [diff] [blame] | 5 | #include "chrome/browser/extensions/dev_mode_bubble_delegate.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 6 | |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 7 | #include "base/lazy_instance.h" |
asvitkine | aa06031 | 2016-09-01 22:44:13 | [diff] [blame] | 8 | #include "base/metrics/histogram_macros.h" |
Allen Bauer | 6de866a | 2018-02-13 21:15:34 | [diff] [blame] | 9 | #include "build/build_config.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f845448465 | 2014-02-27 04:20:42 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 13 | #include "chrome/common/url_constants.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 14 | #include "chrome/grit/generated_resources.h" |
thestig | 4a2e88e | 2016-08-27 23:23:51 | [diff] [blame] | 15 | #include "components/strings/grit/components_strings.h" |
Devlin Cronin | 94832fc | 2020-08-04 18:39:41 | [diff] [blame] | 16 | #include "extensions/browser/extension_action_manager.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 17 | #include "extensions/browser/extension_prefs.h" |
[email protected] | d46c050 | 2014-02-14 13:33:36 | [diff] [blame] | 18 | #include "extensions/browser/extension_system.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 19 | #include "ui/base/buildflags.h" |
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 20 | #include "ui/base/l10n/l10n_util.h" |
21 | |||||
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 22 | namespace extensions { |
23 | |||||
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 24 | namespace { |
25 | |||||
Oscar Johansson | 1b0d907 | 2018-06-14 06:08:18 | [diff] [blame] | 26 | base::LazyInstance<std::set<Profile*>>::Leaky g_dev_mode_shown = |
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 27 | LAZY_INSTANCE_INITIALIZER; |
28 | |||||
29 | } // namespace | ||||
30 | |||||
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 31 | DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile) |
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 32 | : ExtensionMessageBubbleController::Delegate(profile), profile_(profile) {} |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 33 | |
34 | DevModeBubbleDelegate::~DevModeBubbleDelegate() { | ||||
35 | } | ||||
36 | |||||
rdevlin.cronin | cce78d0 | 2015-09-24 19:50:55 | [diff] [blame] | 37 | bool DevModeBubbleDelegate::ShouldIncludeExtension(const Extension* extension) { |
Gyuyoung Kim | 5626c75 | 2021-03-18 22:58:11 | [diff] [blame] | 38 | return (extension->location() == mojom::ManifestLocation::kUnpacked || |
39 | extension->location() == mojom::ManifestLocation::kCommandLine); | ||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 40 | } |
41 | |||||
42 | void DevModeBubbleDelegate::AcknowledgeExtension( | ||||
43 | const std::string& extension_id, | ||||
44 | ExtensionMessageBubbleController::BubbleAction user_action) { | ||||
45 | } | ||||
46 | |||||
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 47 | void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) { |
48 | for (size_t i = 0; i < list.size(); ++i) | ||||
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 49 | service()->DisableExtension(list[i], disable_reason::DISABLE_USER_ACTION); |
[email protected] | a74569b | 2014-03-25 02:56:30 | [diff] [blame] | 50 | } |
51 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 52 | std::u16string DevModeBubbleDelegate::GetTitle() const { |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 53 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); |
54 | } | ||||
55 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 56 | std::u16string DevModeBubbleDelegate::GetMessageBody( |
rdevlin.cronin | 9cb8498 | 2015-05-15 16:57:49 | [diff] [blame] | 57 | bool anchored_to_browser_action, |
58 | int extension_count) const { | ||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 59 | return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY); |
60 | } | ||||
61 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 62 | std::u16string DevModeBubbleDelegate::GetOverflowText( |
63 | const std::u16string& overflow_count) const { | ||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 64 | return l10n_util::GetStringFUTF16( |
[email protected] | d246924 | 2014-05-09 11:56:58 | [diff] [blame] | 65 | IDS_EXTENSIONS_DISABLED_AND_N_MORE, |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 66 | overflow_count); |
67 | } | ||||
68 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 69 | std::u16string DevModeBubbleDelegate::GetLearnMoreLabel() const { |
70 | return std::u16string(); | ||||
Tim Judkins | 0c0936f5 | 2019-08-05 19:29:25 | [diff] [blame] | 71 | } |
72 | |||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 73 | GURL DevModeBubbleDelegate::GetLearnMoreUrl() const { |
Tim Judkins | 0c0936f5 | 2019-08-05 19:29:25 | [diff] [blame] | 74 | return GURL(); |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 75 | } |
76 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 77 | std::u16string DevModeBubbleDelegate::GetActionButtonLabel() const { |
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 78 | return l10n_util::GetStringUTF16(IDS_DISABLE); |
79 | } | ||||
80 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 81 | std::u16string DevModeBubbleDelegate::GetDismissButtonLabel() const { |
82 | return std::u16string(); | ||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 83 | } |
84 | |||||
rdevlin.cronin | 690e44f | 2015-11-06 00:27:14 | [diff] [blame] | 85 | bool DevModeBubbleDelegate::ShouldCloseOnDeactivate() const { |
86 | return false; | ||||
87 | } | ||||
88 | |||||
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 89 | bool DevModeBubbleDelegate::ShouldShow( |
90 | const ExtensionIdList& extensions) const { | ||||
91 | DCHECK_LE(1u, extensions.size()); | ||||
Oscar Johansson | 1b0d907 | 2018-06-14 06:08:18 | [diff] [blame] | 92 | return !g_dev_mode_shown.Get().count(profile_->GetOriginalProfile()); |
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 93 | } |
94 | |||||
95 | void DevModeBubbleDelegate::OnShown(const ExtensionIdList& extensions) { | ||||
96 | DCHECK_LE(1u, extensions.size()); | ||||
Oscar Johansson | 1b0d907 | 2018-06-14 06:08:18 | [diff] [blame] | 97 | DCHECK(!g_dev_mode_shown.Get().count(profile_)); |
98 | g_dev_mode_shown.Get().insert(profile_->GetOriginalProfile()); | ||||
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 99 | } |
100 | |||||
101 | void DevModeBubbleDelegate::OnAction() {} | ||||
102 | |||||
103 | void DevModeBubbleDelegate::ClearProfileSetForTesting() { | ||||
Oscar Johansson | 1b0d907 | 2018-06-14 06:08:18 | [diff] [blame] | 104 | g_dev_mode_shown.Get().clear(); |
Catherine Mullings | 478a043 | 2017-11-22 07:06:06 | [diff] [blame] | 105 | } |
106 | |||||
[email protected] | 4f2f353d | 2014-01-14 11:21:09 | [diff] [blame] | 107 | bool DevModeBubbleDelegate::ShouldShowExtensionList() const { |
108 | return false; | ||||
109 | } | ||||
110 | |||||
rdevlin.cronin | cce78d0 | 2015-09-24 19:50:55 | [diff] [blame] | 111 | bool DevModeBubbleDelegate::ShouldLimitToEnabledExtensions() const { |
112 | return true; | ||||
113 | } | ||||
114 | |||||
catmullings | 22bc237 | 2016-11-02 19:59:35 | [diff] [blame] | 115 | bool DevModeBubbleDelegate::SupportsPolicyIndicator() { |
116 | return false; | ||||
117 | } | ||||
118 | |||||
[email protected] | c72ebfe | 2013-12-13 21:57:53 | [diff] [blame] | 119 | } // namespace extensions |