Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / dev_mode_bubble_controller.cc
blobcbce3dbee9ea669f1588cebf1075ca795d1e0ab2
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/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/browser/extension_system.h"
18 #include "grit/components_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
21 namespace extensions {
23 namespace {
25 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
26 LAZY_INSTANCE_INITIALIZER;
28 ////////////////////////////////////////////////////////////////////////////////
29 // DevModeBubbleDelegate
31 class DevModeBubbleDelegate
32 : public ExtensionMessageBubbleController::Delegate {
33 public:
34 explicit DevModeBubbleDelegate(Profile* profile);
35 ~DevModeBubbleDelegate() override;
37 // ExtensionMessageBubbleController::Delegate methods.
38 bool ShouldIncludeExtension(const std::string& extension_id) override;
39 void AcknowledgeExtension(
40 const std::string& extension_id,
41 ExtensionMessageBubbleController::BubbleAction user_action) override;
42 void PerformAction(const ExtensionIdList& list) override;
43 base::string16 GetTitle() const override;
44 base::string16 GetMessageBody(bool anchored_to_browser_action,
45 int extension_count) const override;
46 base::string16 GetOverflowText(
47 const base::string16& overflow_count) const override;
48 GURL GetLearnMoreUrl() const override;
49 base::string16 GetActionButtonLabel() const override;
50 base::string16 GetDismissButtonLabel() const override;
51 bool ShouldShowExtensionList() const override;
52 bool ShouldHighlightExtensions() const override;
53 void LogExtensionCount(size_t count) override;
54 void LogAction(
55 ExtensionMessageBubbleController::BubbleAction action) override;
57 private:
58 DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegate);
61 DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
62 : ExtensionMessageBubbleController::Delegate(profile) {
65 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
68 bool DevModeBubbleDelegate::ShouldIncludeExtension(
69 const std::string& extension_id) {
70 const Extension* extension = service()->GetExtensionById(extension_id, false);
71 if (!extension)
72 return false;
73 return (extension->location() == Manifest::UNPACKED ||
74 extension->location() == Manifest::COMMAND_LINE);
77 void DevModeBubbleDelegate::AcknowledgeExtension(
78 const std::string& extension_id,
79 ExtensionMessageBubbleController::BubbleAction user_action) {
82 void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
83 for (size_t i = 0; i < list.size(); ++i)
84 service()->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
87 base::string16 DevModeBubbleDelegate::GetTitle() const {
88 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
91 base::string16 DevModeBubbleDelegate::GetMessageBody(
92 bool anchored_to_browser_action,
93 int extension_count) const {
94 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
97 base::string16 DevModeBubbleDelegate::GetOverflowText(
98 const base::string16& overflow_count) const {
99 return l10n_util::GetStringFUTF16(
100 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
101 overflow_count);
104 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
105 return GURL(chrome::kChromeUIExtensionsURL);
108 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
109 return l10n_util::GetStringUTF16(IDS_DISABLE);
112 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
113 return l10n_util::GetStringUTF16(IDS_CANCEL);
116 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
117 return false;
120 bool DevModeBubbleDelegate::ShouldHighlightExtensions() const {
121 return true;
124 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
125 UMA_HISTOGRAM_COUNTS_100(
126 "ExtensionBubble.ExtensionsInDevModeCount", count);
129 void DevModeBubbleDelegate::LogAction(
130 ExtensionMessageBubbleController::BubbleAction action) {
131 UMA_HISTOGRAM_ENUMERATION(
132 "ExtensionBubble.DevModeUserSelection",
133 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
136 } // namespace
138 ////////////////////////////////////////////////////////////////////////////////
139 // DevModeBubbleController
141 // static
142 void DevModeBubbleController::ClearProfileListForTesting() {
143 g_shown_for_profiles.Get().clear();
146 DevModeBubbleController::DevModeBubbleController(Browser* browser)
147 : ExtensionMessageBubbleController(
148 new DevModeBubbleDelegate(browser->profile()), browser) {}
150 DevModeBubbleController::~DevModeBubbleController() {
153 bool DevModeBubbleController::ShouldShow() {
154 return !g_shown_for_profiles.Get().count(profile()->GetOriginalProfile()) &&
155 !GetExtensionList().empty();
158 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
159 g_shown_for_profiles.Get().insert(profile()->GetOriginalProfile());
160 ExtensionMessageBubbleController::Show(bubble);
163 } // namespace extensions