MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / extensions / dev_mode_bubble_controller.cc
blob202207ca5783c6f5f20d920d10e5b9cbe689aa2c
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.
5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
7 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_toolbar_model.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_version_info.h"
16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/feature_switch.h"
21 #include "grit/components_strings.h"
22 #include "ui/base/l10n/l10n_util.h"
24 namespace extensions {
26 namespace {
28 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 LAZY_INSTANCE_INITIALIZER;
31 ////////////////////////////////////////////////////////////////////////////////
32 // DevModeBubbleDelegate
34 class DevModeBubbleDelegate
35 : public ExtensionMessageBubbleController::Delegate {
36 public:
37 explicit DevModeBubbleDelegate(Profile* profile);
38 ~DevModeBubbleDelegate() override;
40 // ExtensionMessageBubbleController::Delegate methods.
41 bool ShouldIncludeExtension(const std::string& extension_id) override;
42 void AcknowledgeExtension(
43 const std::string& extension_id,
44 ExtensionMessageBubbleController::BubbleAction user_action) override;
45 void PerformAction(const ExtensionIdList& list) override;
46 void OnClose() override;
47 base::string16 GetTitle() const override;
48 base::string16 GetMessageBody(bool anchored_to_browser_action) const override;
49 base::string16 GetOverflowText(
50 const base::string16& overflow_count) const override;
51 GURL GetLearnMoreUrl() const override;
52 base::string16 GetActionButtonLabel() const override;
53 base::string16 GetDismissButtonLabel() const override;
54 bool ShouldShowExtensionList() const override;
55 void LogExtensionCount(size_t count) override;
56 void LogAction(
57 ExtensionMessageBubbleController::BubbleAction action) override;
59 private:
60 // Our extension service. Weak, not owned by us.
61 ExtensionService* service_;
63 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
66 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
67 : ExtensionMessageBubbleController::Delegate(profile),
68 service_(ExtensionSystem::Get(profile)->extension_service()) {
71 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
74 bool DevModeBubbleDelegate::ShouldIncludeExtension(
75 const std::string& extension_id) {
76 const Extension* extension = service_->GetExtensionById(extension_id, false);
77 if (!extension)
78 return false;
79 return DevModeBubbleController::IsDevModeExtension(extension);
82 void DevModeBubbleDelegate::AcknowledgeExtension(
83 const std::string& extension_id,
84 ExtensionMessageBubbleController::BubbleAction user_action) {
87 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
88 for (size_t i = 0; i < list.size(); ++i)
89 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
92 void DevModeBubbleDelegate::OnClose() {
93 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(profile());
94 if (toolbar_model)
95 toolbar_model->StopHighlighting();
98 base::string16 DevModeBubbleDelegate::GetTitle() const {
99 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
102 base::string16 DevModeBubbleDelegate::GetMessageBody(
103 bool anchored_to_browser_action) const {
104 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
107 base::string16 DevModeBubbleDelegate::GetOverflowText(
108 const base::string16& overflow_count) const {
109 return l10n_util::GetStringFUTF16(
110 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
111 overflow_count);
114 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
115 return GURL(chrome::kChromeUIExtensionsURL);
118 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
119 return l10n_util::GetStringUTF16(IDS_DISABLE);
122 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
123 return l10n_util::GetStringUTF16(IDS_CANCEL);
126 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
127 return false;
130 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
131 UMA_HISTOGRAM_COUNTS_100(
132 "ExtensionBubble.ExtensionsInDevModeCount", count);
135 void DevModeBubbleDelegate::LogAction(
136 ExtensionMessageBubbleController::BubbleAction action) {
137 UMA_HISTOGRAM_ENUMERATION(
138 "ExtensionBubble.DevModeUserSelection",
139 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
142 } // namespace
144 ////////////////////////////////////////////////////////////////////////////////
145 // DevModeBubbleController
147 // static
148 void DevModeBubbleController::ClearProfileListForTesting() {
149 g_shown_for_profiles.Get().clear();
152 // static
153 bool DevModeBubbleController::IsDevModeExtension(
154 const Extension* extension) {
155 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
156 if (chrome::VersionInfo::GetChannel() < chrome::VersionInfo::CHANNEL_BETA)
157 return false;
159 return extension->location() == Manifest::UNPACKED ||
160 extension->location() == Manifest::COMMAND_LINE;
163 DevModeBubbleController::DevModeBubbleController(Profile* profile)
164 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
165 profile),
166 profile_(profile) {}
168 DevModeBubbleController::~DevModeBubbleController() {
171 bool DevModeBubbleController::ShouldShow() {
172 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
173 !GetExtensionList().empty();
176 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
177 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
178 ExtensionMessageBubbleController::Show(bubble);
181 } // namespace extensions