blob: 47519853c5e850fca5b1db1d75e89e0b0faad4fe [file] [log] [blame]
[email protected]c72ebfe2013-12-13 21:57:531// 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.cronin690e44f2015-11-06 00:27:145#include "chrome/browser/extensions/dev_mode_bubble_delegate.h"
[email protected]c72ebfe2013-12-13 21:57:536
[email protected]4f2f353d2014-01-14 11:21:097#include "base/lazy_instance.h"
asvitkineaa060312016-09-01 22:44:138#include "base/metrics/histogram_macros.h"
Allen Bauer6de866a2018-02-13 21:15:349#include "build/build_config.h"
[email protected]c72ebfe2013-12-13 21:57:5310#include "chrome/browser/extensions/extension_action_manager.h"
[email protected]c72ebfe2013-12-13 21:57:5311#include "chrome/browser/extensions/extension_service.h"
[email protected]f8454484652014-02-27 04:20:4212#include "chrome/browser/profiles/profile.h"
[email protected]c72ebfe2013-12-13 21:57:5313#include "chrome/browser/ui/browser.h"
[email protected]c72ebfe2013-12-13 21:57:5314#include "chrome/common/url_constants.h"
[email protected]af39f002014-08-22 10:18:1815#include "chrome/grit/generated_resources.h"
thestig4a2e88e2016-08-27 23:23:5116#include "components/strings/grit/components_strings.h"
[email protected]489db0842014-01-22 18:20:0317#include "extensions/browser/extension_prefs.h"
[email protected]d46c0502014-02-14 13:33:3618#include "extensions/browser/extension_system.h"
Scott Violetb72577d2019-01-09 22:18:1819#include "ui/base/buildflags.h"
[email protected]c72ebfe2013-12-13 21:57:5320#include "ui/base/l10n/l10n_util.h"
[email protected]c72ebfe2013-12-13 21:57:5321
[email protected]a74569b2014-03-25 02:56:3022namespace extensions {
23
Catherine Mullings478a0432017-11-22 07:06:0624namespace {
25
Oscar Johansson1b0d9072018-06-14 06:08:1826base::LazyInstance<std::set<Profile*>>::Leaky g_dev_mode_shown =
Catherine Mullings478a0432017-11-22 07:06:0627 LAZY_INSTANCE_INITIALIZER;
28
29} // namespace
30
[email protected]a74569b2014-03-25 02:56:3031DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
Catherine Mullings478a0432017-11-22 07:06:0632 : ExtensionMessageBubbleController::Delegate(profile), profile_(profile) {}
[email protected]4f2f353d2014-01-14 11:21:0933
34DevModeBubbleDelegate::~DevModeBubbleDelegate() {
35}
36
rdevlin.cronincce78d02015-09-24 19:50:5537bool DevModeBubbleDelegate::ShouldIncludeExtension(const Extension* extension) {
asargenta772c582015-05-08 18:59:0138 return (extension->location() == Manifest::UNPACKED ||
39 extension->location() == Manifest::COMMAND_LINE);
[email protected]4f2f353d2014-01-14 11:21:0940}
41
42void DevModeBubbleDelegate::AcknowledgeExtension(
43 const std::string& extension_id,
44 ExtensionMessageBubbleController::BubbleAction user_action) {
45}
46
[email protected]a74569b2014-03-25 02:56:3047void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
48 for (size_t i = 0; i < list.size(); ++i)
Minh X. Nguyen45479012017-08-18 21:35:3649 service()->DisableExtension(list[i], disable_reason::DISABLE_USER_ACTION);
[email protected]a74569b2014-03-25 02:56:3050}
51
[email protected]4f2f353d2014-01-14 11:21:0952base::string16 DevModeBubbleDelegate::GetTitle() const {
53 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
54}
55
[email protected]8dc56d02014-06-07 00:44:2356base::string16 DevModeBubbleDelegate::GetMessageBody(
rdevlin.cronin9cb84982015-05-15 16:57:4957 bool anchored_to_browser_action,
58 int extension_count) const {
[email protected]4f2f353d2014-01-14 11:21:0959 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
60}
61
62base::string16 DevModeBubbleDelegate::GetOverflowText(
63 const base::string16& overflow_count) const {
64 return l10n_util::GetStringFUTF16(
[email protected]d2469242014-05-09 11:56:5865 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
[email protected]4f2f353d2014-01-14 11:21:0966 overflow_count);
67}
68
Tim Judkins0c0936f52019-08-05 19:29:2569base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
70 return base::string16();
71}
72
[email protected]4f2f353d2014-01-14 11:21:0973GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
Tim Judkins0c0936f52019-08-05 19:29:2574 return GURL();
[email protected]4f2f353d2014-01-14 11:21:0975}
76
77base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
78 return l10n_util::GetStringUTF16(IDS_DISABLE);
79}
80
81base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
Devlin Cronin6916170c2018-05-03 05:25:2882 return base::string16();
[email protected]4f2f353d2014-01-14 11:21:0983}
84
rdevlin.cronin690e44f2015-11-06 00:27:1485bool DevModeBubbleDelegate::ShouldCloseOnDeactivate() const {
86 return false;
87}
88
rdevlin.cronincf27f866a2017-02-01 16:34:3989bool DevModeBubbleDelegate::ShouldAcknowledgeOnDeactivate() const {
90 return false;
91}
92
Catherine Mullings478a0432017-11-22 07:06:0693bool DevModeBubbleDelegate::ShouldShow(
94 const ExtensionIdList& extensions) const {
95 DCHECK_LE(1u, extensions.size());
Oscar Johansson1b0d9072018-06-14 06:08:1896 return !g_dev_mode_shown.Get().count(profile_->GetOriginalProfile());
Catherine Mullings478a0432017-11-22 07:06:0697}
98
99void DevModeBubbleDelegate::OnShown(const ExtensionIdList& extensions) {
100 DCHECK_LE(1u, extensions.size());
Oscar Johansson1b0d9072018-06-14 06:08:18101 DCHECK(!g_dev_mode_shown.Get().count(profile_));
102 g_dev_mode_shown.Get().insert(profile_->GetOriginalProfile());
Catherine Mullings478a0432017-11-22 07:06:06103}
104
105void DevModeBubbleDelegate::OnAction() {}
106
107void DevModeBubbleDelegate::ClearProfileSetForTesting() {
Oscar Johansson1b0d9072018-06-14 06:08:18108 g_dev_mode_shown.Get().clear();
Catherine Mullings478a0432017-11-22 07:06:06109}
110
[email protected]4f2f353d2014-01-14 11:21:09111bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
112 return false;
113}
114
rdevlin.cronin70fc6052015-04-15 17:49:06115bool DevModeBubbleDelegate::ShouldHighlightExtensions() const {
116 return true;
117}
118
rdevlin.cronincce78d02015-09-24 19:50:55119bool DevModeBubbleDelegate::ShouldLimitToEnabledExtensions() const {
120 return true;
121}
122
[email protected]4f2f353d2014-01-14 11:21:09123void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
124 UMA_HISTOGRAM_COUNTS_100(
[email protected]b61b05ce8d2014-05-14 15:33:01125 "ExtensionBubble.ExtensionsInDevModeCount", count);
[email protected]4f2f353d2014-01-14 11:21:09126}
127
128void DevModeBubbleDelegate::LogAction(
129 ExtensionMessageBubbleController::BubbleAction action) {
130 UMA_HISTOGRAM_ENUMERATION(
[email protected]b61b05ce8d2014-05-14 15:33:01131 "ExtensionBubble.DevModeUserSelection",
[email protected]4f2f353d2014-01-14 11:21:09132 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
133}
[email protected]c72ebfe2013-12-13 21:57:53134
catmullings22bc2372016-11-02 19:59:35135bool DevModeBubbleDelegate::SupportsPolicyIndicator() {
136 return false;
137}
138
[email protected]c72ebfe2013-12-13 21:57:53139} // namespace extensions