NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / dev_mode_bubble_controller.cc
blob2bf7136c8f32870476cc7ee211233e2eef6d1812
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/bind.h"
8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_action_manager.h"
13 #include "chrome/browser/extensions/extension_message_bubble.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/user_metrics.h"
21 #include "extensions/browser/extension_prefs.h"
22 #include "extensions/browser/extension_system.h"
23 #include "extensions/common/feature_switch.h"
24 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h"
28 namespace {
30 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
31 LAZY_INSTANCE_INITIALIZER;
33 ////////////////////////////////////////////////////////////////////////////////
34 // DevModeBubbleDelegate
36 DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service)
37 : service_(service) {
40 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
43 bool DevModeBubbleDelegate::ShouldIncludeExtension(
44 const std::string& extension_id) {
45 const extensions::Extension* extension =
46 service_->GetExtensionById(extension_id, false);
47 if (!extension)
48 return false;
49 return extensions::DevModeBubbleController::IsDevModeExtension(extension);
52 void DevModeBubbleDelegate::AcknowledgeExtension(
53 const std::string& extension_id,
54 ExtensionMessageBubbleController::BubbleAction user_action) {
57 void DevModeBubbleDelegate::PerformAction(
58 const extensions::ExtensionIdList& list) {
59 for (size_t i = 0; i < list.size(); ++i) {
60 service_->DisableExtension(
61 list[i], extensions::Extension::DISABLE_USER_ACTION);
65 base::string16 DevModeBubbleDelegate::GetTitle() const {
66 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
69 base::string16 DevModeBubbleDelegate::GetMessageBody() const {
70 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
73 base::string16 DevModeBubbleDelegate::GetOverflowText(
74 const base::string16& overflow_count) const {
75 return l10n_util::GetStringFUTF16(
76 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
77 overflow_count);
80 base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
81 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
84 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
85 return GURL(chrome::kChromeUIExtensionsURL);
88 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
89 return l10n_util::GetStringUTF16(IDS_DISABLE);
92 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
93 return l10n_util::GetStringUTF16(IDS_CANCEL);
96 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
97 return false;
100 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
101 UMA_HISTOGRAM_COUNTS_100(
102 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
105 void DevModeBubbleDelegate::LogAction(
106 ExtensionMessageBubbleController::BubbleAction action) {
107 UMA_HISTOGRAM_ENUMERATION(
108 "DevModeExtensionBubble.UserSelection",
109 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
112 } // namespace
114 namespace extensions {
116 ////////////////////////////////////////////////////////////////////////////////
117 // DevModeBubbleController
119 // static
120 void DevModeBubbleController::ClearProfileListForTesting() {
121 g_shown_for_profiles.Get().clear();
124 // static
125 bool DevModeBubbleController::IsDevModeExtension(
126 const Extension* extension) {
127 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
128 if (chrome::VersionInfo::GetChannel() <
129 chrome::VersionInfo::CHANNEL_BETA)
130 return false;
132 return extension->location() == Manifest::UNPACKED ||
133 extension->location() == Manifest::COMMAND_LINE;
136 DevModeBubbleController::DevModeBubbleController(Profile* profile)
137 : ExtensionMessageBubbleController(
138 new DevModeBubbleDelegate(
139 ExtensionSystem::Get(profile)->extension_service()),
140 profile),
141 profile_(profile) {}
143 DevModeBubbleController::~DevModeBubbleController() {
146 bool DevModeBubbleController::ShouldShow() {
147 return !g_shown_for_profiles.Get().count(profile_) &&
148 !GetExtensionList().empty();
151 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
152 g_shown_for_profiles.Get().insert(profile_);
153 ExtensionMessageBubbleController::Show(bubble);
156 } // namespace extensions