blob: c6b2ea824e9c7bbe778bb00e12813c4c3d3ed996 [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.
41 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE;
42 virtual void AcknowledgeExtension(
43 const std::string& extension_id,
44 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(
49 bool anchored_to_browser_action) const OVERRIDE;
[email protected]3d4d93372014-05-20 06:25:3150 virtual base::string16 GetOverflowText(
51 const base::string16& overflow_count) const OVERRIDE;
52 virtual base::string16 GetLearnMoreLabel() const OVERRIDE;
53 virtual GURL GetLearnMoreUrl() const OVERRIDE;
54 virtual base::string16 GetActionButtonLabel() const OVERRIDE;
55 virtual base::string16 GetDismissButtonLabel() const OVERRIDE;
56 virtual bool ShouldShowExtensionList() const OVERRIDE;
57 virtual void LogExtensionCount(size_t count) OVERRIDE;
58 virtual void LogAction(
59 ExtensionMessageBubbleController::BubbleAction action) OVERRIDE;
60
61 private:
62 // The associated profile (weak).
63 Profile* profile_;
64
65 // Our extension service. Weak, not owned by us.
66 ExtensionService* service_;
67
68 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
69};
70
[email protected]a74569b2014-03-25 02:56:3071DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
72 : profile_(profile),
73 service_(ExtensionSystem::Get(profile)->extension_service()) {}
[email protected]4f2f353d2014-01-14 11:21:0974
75DevModeBubbleDelegate::~DevModeBubbleDelegate() {
76}
77
78bool DevModeBubbleDelegate::ShouldIncludeExtension(
79 const std::string& extension_id) {
[email protected]a74569b2014-03-25 02:56:3080 const Extension* extension = service_->GetExtensionById(extension_id, false);
[email protected]4f2f353d2014-01-14 11:21:0981 if (!extension)
82 return false;
[email protected]a74569b2014-03-25 02:56:3083 return DevModeBubbleController::IsDevModeExtension(extension);
[email protected]4f2f353d2014-01-14 11:21:0984}
85
86void DevModeBubbleDelegate::AcknowledgeExtension(
87 const std::string& extension_id,
88 ExtensionMessageBubbleController::BubbleAction user_action) {
89}
90
[email protected]a74569b2014-03-25 02:56:3091void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
92 for (size_t i = 0; i < list.size(); ++i)
93 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
94}
95
96void DevModeBubbleDelegate::OnClose() {
97 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(profile_);
98 if (toolbar_model)
99 toolbar_model->StopHighlighting();
[email protected]4f2f353d2014-01-14 11:21:09100}
101
102base::string16 DevModeBubbleDelegate::GetTitle() const {
103 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
104}
105
[email protected]8dc56d02014-06-07 00:44:23106base::string16 DevModeBubbleDelegate::GetMessageBody(
107 bool anchored_to_browser_action) const {
[email protected]4f2f353d2014-01-14 11:21:09108 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
109}
110
111base::string16 DevModeBubbleDelegate::GetOverflowText(
112 const base::string16& overflow_count) const {
113 return l10n_util::GetStringFUTF16(
[email protected]d2469242014-05-09 11:56:58114 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
[email protected]4f2f353d2014-01-14 11:21:09115 overflow_count);
116}
117
118base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
119 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
120}
121
122GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
123 return GURL(chrome::kChromeUIExtensionsURL);
124}
125
126base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
127 return l10n_util::GetStringUTF16(IDS_DISABLE);
128}
129
130base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
131 return l10n_util::GetStringUTF16(IDS_CANCEL);
132}
133
134bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
135 return false;
136}
137
138void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
139 UMA_HISTOGRAM_COUNTS_100(
[email protected]b61b05ce8d2014-05-14 15:33:01140 "ExtensionBubble.ExtensionsInDevModeCount", count);
[email protected]4f2f353d2014-01-14 11:21:09141}
142
143void DevModeBubbleDelegate::LogAction(
144 ExtensionMessageBubbleController::BubbleAction action) {
145 UMA_HISTOGRAM_ENUMERATION(
[email protected]b61b05ce8d2014-05-14 15:33:01146 "ExtensionBubble.DevModeUserSelection",
[email protected]4f2f353d2014-01-14 11:21:09147 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
148}
[email protected]c72ebfe2013-12-13 21:57:53149
150} // namespace
151
[email protected]c72ebfe2013-12-13 21:57:53152////////////////////////////////////////////////////////////////////////////////
153// DevModeBubbleController
154
[email protected]4f2f353d2014-01-14 11:21:09155// static
156void DevModeBubbleController::ClearProfileListForTesting() {
157 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53158}
159
160// static
[email protected]c72ebfe2013-12-13 21:57:53161bool DevModeBubbleController::IsDevModeExtension(
[email protected]4f2f353d2014-01-14 11:21:09162 const Extension* extension) {
[email protected]d46c0502014-02-14 13:33:36163 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
[email protected]3d4d93372014-05-20 06:25:31164 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA)
[email protected]c72ebfe2013-12-13 21:57:53165 return false;
166 }
167 return extension->location() == Manifest::UNPACKED ||
168 extension->location() == Manifest::COMMAND_LINE;
169}
170
[email protected]4f2f353d2014-01-14 11:21:09171DevModeBubbleController::DevModeBubbleController(Profile* profile)
[email protected]a74569b2014-03-25 02:56:30172 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
173 profile),
[email protected]d46c0502014-02-14 13:33:36174 profile_(profile) {}
[email protected]c72ebfe2013-12-13 21:57:53175
[email protected]4f2f353d2014-01-14 11:21:09176DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53177}
178
[email protected]4f2f353d2014-01-14 11:21:09179bool DevModeBubbleController::ShouldShow() {
[email protected]dbc165c2014-04-18 19:59:12180 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
[email protected]4f2f353d2014-01-14 11:21:09181 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53182}
183
[email protected]4f2f353d2014-01-14 11:21:09184void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
[email protected]dbc165c2014-04-18 19:59:12185 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
[email protected]4f2f353d2014-01-14 11:21:09186 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53187}
188
189} // namespace extensions