blob: 854dcf77b638e2ef80af5831b28fc10ca2badcac [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]a74569b2014-03-25 02:56:3012#include "chrome/browser/extensions/extension_toolbar_model.h"
[email protected]f8454484652014-02-27 04:20:4213#include "chrome/browser/profiles/profile.h"
[email protected]c72ebfe2013-12-13 21:57:5314#include "chrome/browser/ui/browser.h"
[email protected]c72ebfe2013-12-13 21:57:5315#include "chrome/common/chrome_version_info.h"
16#include "chrome/common/url_constants.h"
[email protected]af39f002014-08-22 10:18:1817#include "chrome/grit/generated_resources.h"
[email protected]489db0842014-01-22 18:20:0318#include "extensions/browser/extension_prefs.h"
[email protected]d46c0502014-02-14 13:33:3619#include "extensions/browser/extension_system.h"
[email protected]c72ebfe2013-12-13 21:57:5320#include "extensions/common/feature_switch.h"
hashimotoa804d982014-09-02 10:35:5721#include "grit/components_strings.h"
[email protected]c72ebfe2013-12-13 21:57:5322#include "ui/base/l10n/l10n_util.h"
23
[email protected]a74569b2014-03-25 02:56:3024namespace extensions {
25
[email protected]c72ebfe2013-12-13 21:57:5326namespace {
27
[email protected]4f2f353d2014-01-14 11:21:0928base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 LAZY_INSTANCE_INITIALIZER;
30
31////////////////////////////////////////////////////////////////////////////////
32// DevModeBubbleDelegate
33
[email protected]3d4d93372014-05-20 06:25:3134class DevModeBubbleDelegate
35 : public ExtensionMessageBubbleController::Delegate {
36 public:
37 explicit DevModeBubbleDelegate(Profile* profile);
38 virtual ~DevModeBubbleDelegate();
39
40 // ExtensionMessageBubbleController::Delegate methods.
mostynba15bee12014-10-04 00:40:3241 virtual bool ShouldIncludeExtension(const std::string& extension_id) override;
[email protected]3d4d93372014-05-20 06:25:3142 virtual void AcknowledgeExtension(
43 const std::string& extension_id,
mostynba15bee12014-10-04 00:40:3244 ExtensionMessageBubbleController::BubbleAction user_action) override;
45 virtual void PerformAction(const ExtensionIdList& list) override;
46 virtual void OnClose() override;
47 virtual base::string16 GetTitle() const override;
[email protected]8dc56d02014-06-07 00:44:2348 virtual base::string16 GetMessageBody(
mostynba15bee12014-10-04 00:40:3249 bool anchored_to_browser_action) const override;
[email protected]3d4d93372014-05-20 06:25:3150 virtual base::string16 GetOverflowText(
mostynba15bee12014-10-04 00:40:3251 const base::string16& overflow_count) const override;
mostynba15bee12014-10-04 00:40:3252 virtual GURL GetLearnMoreUrl() const override;
53 virtual base::string16 GetActionButtonLabel() const override;
54 virtual base::string16 GetDismissButtonLabel() const override;
55 virtual bool ShouldShowExtensionList() const override;
56 virtual void LogExtensionCount(size_t count) override;
[email protected]3d4d93372014-05-20 06:25:3157 virtual void LogAction(
mostynba15bee12014-10-04 00:40:3258 ExtensionMessageBubbleController::BubbleAction action) override;
[email protected]3d4d93372014-05-20 06:25:3159
60 private:
[email protected]3d4d93372014-05-20 06:25:3161 // Our extension service. Weak, not owned by us.
62 ExtensionService* service_;
63
64 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
65};
66
[email protected]a74569b2014-03-25 02:56:3067DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
merkulova9be182e2014-10-07 14:57:5068 : ExtensionMessageBubbleController::Delegate(profile),
69 service_(ExtensionSystem::Get(profile)->extension_service()) {
70}
[email protected]4f2f353d2014-01-14 11:21:0971
72DevModeBubbleDelegate::~DevModeBubbleDelegate() {
73}
74
75bool DevModeBubbleDelegate::ShouldIncludeExtension(
76 const std::string& extension_id) {
[email protected]a74569b2014-03-25 02:56:3077 const Extension* extension = service_->GetExtensionById(extension_id, false);
[email protected]4f2f353d2014-01-14 11:21:0978 if (!extension)
79 return false;
[email protected]a74569b2014-03-25 02:56:3080 return DevModeBubbleController::IsDevModeExtension(extension);
[email protected]4f2f353d2014-01-14 11:21:0981}
82
83void DevModeBubbleDelegate::AcknowledgeExtension(
84 const std::string& extension_id,
85 ExtensionMessageBubbleController::BubbleAction user_action) {
86}
87
[email protected]a74569b2014-03-25 02:56:3088void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
89 for (size_t i = 0; i < list.size(); ++i)
90 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
91}
92
93void DevModeBubbleDelegate::OnClose() {
merkulova9be182e2014-10-07 14:57:5094 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(profile());
[email protected]a74569b2014-03-25 02:56:3095 if (toolbar_model)
96 toolbar_model->StopHighlighting();
[email protected]4f2f353d2014-01-14 11:21:0997}
98
99base::string16 DevModeBubbleDelegate::GetTitle() const {
100 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
101}
102
[email protected]8dc56d02014-06-07 00:44:23103base::string16 DevModeBubbleDelegate::GetMessageBody(
104 bool anchored_to_browser_action) const {
[email protected]4f2f353d2014-01-14 11:21:09105 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
106}
107
108base::string16 DevModeBubbleDelegate::GetOverflowText(
109 const base::string16& overflow_count) const {
110 return l10n_util::GetStringFUTF16(
[email protected]d2469242014-05-09 11:56:58111 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
[email protected]4f2f353d2014-01-14 11:21:09112 overflow_count);
113}
114
[email protected]4f2f353d2014-01-14 11:21:09115GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
116 return GURL(chrome::kChromeUIExtensionsURL);
117}
118
119base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
120 return l10n_util::GetStringUTF16(IDS_DISABLE);
121}
122
123base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
124 return l10n_util::GetStringUTF16(IDS_CANCEL);
125}
126
127bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
128 return false;
129}
130
131void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
132 UMA_HISTOGRAM_COUNTS_100(
[email protected]b61b05ce8d2014-05-14 15:33:01133 "ExtensionBubble.ExtensionsInDevModeCount", count);
[email protected]4f2f353d2014-01-14 11:21:09134}
135
136void DevModeBubbleDelegate::LogAction(
137 ExtensionMessageBubbleController::BubbleAction action) {
138 UMA_HISTOGRAM_ENUMERATION(
[email protected]b61b05ce8d2014-05-14 15:33:01139 "ExtensionBubble.DevModeUserSelection",
[email protected]4f2f353d2014-01-14 11:21:09140 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
141}
[email protected]c72ebfe2013-12-13 21:57:53142
143} // namespace
144
[email protected]c72ebfe2013-12-13 21:57:53145////////////////////////////////////////////////////////////////////////////////
146// DevModeBubbleController
147
[email protected]4f2f353d2014-01-14 11:21:09148// static
149void DevModeBubbleController::ClearProfileListForTesting() {
150 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53151}
152
153// static
[email protected]c72ebfe2013-12-13 21:57:53154bool DevModeBubbleController::IsDevModeExtension(
[email protected]4f2f353d2014-01-14 11:21:09155 const Extension* extension) {
[email protected]d46c0502014-02-14 13:33:36156 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
[email protected]3d4d93372014-05-20 06:25:31157 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA)
[email protected]c72ebfe2013-12-13 21:57:53158 return false;
159 }
160 return extension->location() == Manifest::UNPACKED ||
161 extension->location() == Manifest::COMMAND_LINE;
162}
163
[email protected]4f2f353d2014-01-14 11:21:09164DevModeBubbleController::DevModeBubbleController(Profile* profile)
[email protected]a74569b2014-03-25 02:56:30165 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
166 profile),
[email protected]d46c0502014-02-14 13:33:36167 profile_(profile) {}
[email protected]c72ebfe2013-12-13 21:57:53168
[email protected]4f2f353d2014-01-14 11:21:09169DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53170}
171
[email protected]4f2f353d2014-01-14 11:21:09172bool DevModeBubbleController::ShouldShow() {
[email protected]dbc165c2014-04-18 19:59:12173 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
[email protected]4f2f353d2014-01-14 11:21:09174 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53175}
176
[email protected]4f2f353d2014-01-14 11:21:09177void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
[email protected]dbc165c2014-04-18 19:59:12178 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
[email protected]4f2f353d2014-01-14 11:21:09179 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53180}
181
182} // namespace extensions