blob: 7f4a3e79fe951b20da318d9ec8023e40f20adc4e [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
5#include "chrome/browser/extensions/dev_mode_bubble_controller.h"
6
[email protected]4f2f353d2014-01-14 11:21:097#include "base/lazy_instance.h"
[email protected]c72ebfe2013-12-13 21:57:538#include "base/metrics/histogram.h"
[email protected]c72ebfe2013-12-13 21:57:539#include "chrome/browser/extensions/extension_action_manager.h"
10#include "chrome/browser/extensions/extension_message_bubble.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"
[email protected]489db0842014-01-22 18:20:0316#include "extensions/browser/extension_prefs.h"
[email protected]d46c0502014-02-14 13:33:3617#include "extensions/browser/extension_system.h"
hashimotoa804d982014-09-02 10:35:5718#include "grit/components_strings.h"
[email protected]c72ebfe2013-12-13 21:57:5319#include "ui/base/l10n/l10n_util.h"
20
[email protected]a74569b2014-03-25 02:56:3021namespace extensions {
22
[email protected]c72ebfe2013-12-13 21:57:5323namespace {
24
[email protected]4f2f353d2014-01-14 11:21:0925base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
26 LAZY_INSTANCE_INITIALIZER;
27
28////////////////////////////////////////////////////////////////////////////////
29// DevModeBubbleDelegate
30
[email protected]3d4d93372014-05-20 06:25:3131class DevModeBubbleDelegate
32 : public ExtensionMessageBubbleController::Delegate {
33 public:
34 explicit DevModeBubbleDelegate(Profile* profile);
dchengae36a4a2014-10-21 12:36:3635 ~DevModeBubbleDelegate() override;
[email protected]3d4d93372014-05-20 06:25:3136
37 // ExtensionMessageBubbleController::Delegate methods.
dchengae36a4a2014-10-21 12:36:3638 bool ShouldIncludeExtension(const std::string& extension_id) override;
39 void AcknowledgeExtension(
[email protected]3d4d93372014-05-20 06:25:3140 const std::string& extension_id,
mostynba15bee12014-10-04 00:40:3241 ExtensionMessageBubbleController::BubbleAction user_action) override;
dchengae36a4a2014-10-21 12:36:3642 void PerformAction(const ExtensionIdList& list) override;
dchengae36a4a2014-10-21 12:36:3643 base::string16 GetTitle() const override;
rdevlin.cronin9cb84982015-05-15 16:57:4944 base::string16 GetMessageBody(bool anchored_to_browser_action,
45 int extension_count) const override;
dchengae36a4a2014-10-21 12:36:3646 base::string16 GetOverflowText(
mostynba15bee12014-10-04 00:40:3247 const base::string16& overflow_count) const override;
dchengae36a4a2014-10-21 12:36:3648 GURL GetLearnMoreUrl() const override;
49 base::string16 GetActionButtonLabel() const override;
50 base::string16 GetDismissButtonLabel() const override;
51 bool ShouldShowExtensionList() const override;
rdevlin.cronin70fc6052015-04-15 17:49:0652 bool ShouldHighlightExtensions() const override;
dchengae36a4a2014-10-21 12:36:3653 void LogExtensionCount(size_t count) override;
54 void LogAction(
mostynba15bee12014-10-04 00:40:3255 ExtensionMessageBubbleController::BubbleAction action) override;
[email protected]3d4d93372014-05-20 06:25:3156
57 private:
[email protected]3d4d93372014-05-20 06:25:3158 // Our extension service. Weak, not owned by us.
59 ExtensionService* service_;
60
61 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
62};
63
[email protected]a74569b2014-03-25 02:56:3064DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
merkulova9be182e2014-10-07 14:57:5065 : ExtensionMessageBubbleController::Delegate(profile),
66 service_(ExtensionSystem::Get(profile)->extension_service()) {
67}
[email protected]4f2f353d2014-01-14 11:21:0968
69DevModeBubbleDelegate::~DevModeBubbleDelegate() {
70}
71
72bool DevModeBubbleDelegate::ShouldIncludeExtension(
73 const std::string& extension_id) {
[email protected]a74569b2014-03-25 02:56:3074 const Extension* extension = service_->GetExtensionById(extension_id, false);
[email protected]4f2f353d2014-01-14 11:21:0975 if (!extension)
76 return false;
asargenta772c582015-05-08 18:59:0177 return (extension->location() == Manifest::UNPACKED ||
78 extension->location() == Manifest::COMMAND_LINE);
[email protected]4f2f353d2014-01-14 11:21:0979}
80
81void DevModeBubbleDelegate::AcknowledgeExtension(
82 const std::string& extension_id,
83 ExtensionMessageBubbleController::BubbleAction user_action) {
84}
85
[email protected]a74569b2014-03-25 02:56:3086void 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]4f2f353d2014-01-14 11:21:0991base::string16 DevModeBubbleDelegate::GetTitle() const {
92 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
93}
94
[email protected]8dc56d02014-06-07 00:44:2395base::string16 DevModeBubbleDelegate::GetMessageBody(
rdevlin.cronin9cb84982015-05-15 16:57:4996 bool anchored_to_browser_action,
97 int extension_count) const {
[email protected]4f2f353d2014-01-14 11:21:0998 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
99}
100
101base::string16 DevModeBubbleDelegate::GetOverflowText(
102 const base::string16& overflow_count) const {
103 return l10n_util::GetStringFUTF16(
[email protected]d2469242014-05-09 11:56:58104 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
[email protected]4f2f353d2014-01-14 11:21:09105 overflow_count);
106}
107
[email protected]4f2f353d2014-01-14 11:21:09108GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
109 return GURL(chrome::kChromeUIExtensionsURL);
110}
111
112base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
113 return l10n_util::GetStringUTF16(IDS_DISABLE);
114}
115
116base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
117 return l10n_util::GetStringUTF16(IDS_CANCEL);
118}
119
120bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
121 return false;
122}
123
rdevlin.cronin70fc6052015-04-15 17:49:06124bool DevModeBubbleDelegate::ShouldHighlightExtensions() const {
125 return true;
126}
127
[email protected]4f2f353d2014-01-14 11:21:09128void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
129 UMA_HISTOGRAM_COUNTS_100(
[email protected]b61b05ce8d2014-05-14 15:33:01130 "ExtensionBubble.ExtensionsInDevModeCount", count);
[email protected]4f2f353d2014-01-14 11:21:09131}
132
133void DevModeBubbleDelegate::LogAction(
134 ExtensionMessageBubbleController::BubbleAction action) {
135 UMA_HISTOGRAM_ENUMERATION(
[email protected]b61b05ce8d2014-05-14 15:33:01136 "ExtensionBubble.DevModeUserSelection",
[email protected]4f2f353d2014-01-14 11:21:09137 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
138}
[email protected]c72ebfe2013-12-13 21:57:53139
140} // namespace
141
[email protected]c72ebfe2013-12-13 21:57:53142////////////////////////////////////////////////////////////////////////////////
143// DevModeBubbleController
144
[email protected]4f2f353d2014-01-14 11:21:09145// static
146void DevModeBubbleController::ClearProfileListForTesting() {
147 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53148}
149
[email protected]4f2f353d2014-01-14 11:21:09150DevModeBubbleController::DevModeBubbleController(Profile* profile)
[email protected]a74569b2014-03-25 02:56:30151 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
152 profile),
[email protected]d46c0502014-02-14 13:33:36153 profile_(profile) {}
[email protected]c72ebfe2013-12-13 21:57:53154
[email protected]4f2f353d2014-01-14 11:21:09155DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53156}
157
[email protected]4f2f353d2014-01-14 11:21:09158bool DevModeBubbleController::ShouldShow() {
[email protected]dbc165c2014-04-18 19:59:12159 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
[email protected]4f2f353d2014-01-14 11:21:09160 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53161}
162
[email protected]4f2f353d2014-01-14 11:21:09163void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
[email protected]dbc165c2014-04-18 19:59:12164 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
[email protected]4f2f353d2014-01-14 11:21:09165 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53166}
167
168} // namespace extensions