blob: 6845105eaccb830aab20046325c8b06934ba8a9d [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
7#include "base/bind.h"
[email protected]4f2f353d2014-01-14 11:21:098#include "base/lazy_instance.h"
[email protected]c72ebfe2013-12-13 21:57:539#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"
[email protected]c72ebfe2013-12-13 21:57:5314#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"
[email protected]489db0842014-01-22 18:20:0321#include "extensions/browser/extension_prefs.h"
[email protected]c72ebfe2013-12-13 21:57:5322#include "extensions/common/feature_switch.h"
23#include "grit/chromium_strings.h"
24#include "grit/generated_resources.h"
25#include "ui/base/l10n/l10n_util.h"
26
27namespace {
28
[email protected]4f2f353d2014-01-14 11:21:0929base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
30 LAZY_INSTANCE_INITIALIZER;
31
32////////////////////////////////////////////////////////////////////////////////
33// DevModeBubbleDelegate
34
35DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service)
36 : service_(service) {
37}
38
39DevModeBubbleDelegate::~DevModeBubbleDelegate() {
40}
41
42bool DevModeBubbleDelegate::ShouldIncludeExtension(
43 const std::string& extension_id) {
44 const extensions::Extension* extension =
45 service_->GetExtensionById(extension_id, false);
46 if (!extension)
47 return false;
48 return extensions::DevModeBubbleController::IsDevModeExtension(extension);
49}
50
51void DevModeBubbleDelegate::AcknowledgeExtension(
52 const std::string& extension_id,
53 ExtensionMessageBubbleController::BubbleAction user_action) {
54}
55
56void DevModeBubbleDelegate::PerformAction(
57 const extensions::ExtensionIdList& list) {
58 for (size_t i = 0; i < list.size(); ++i) {
59 service_->DisableExtension(
60 list[i], extensions::Extension::DISABLE_USER_ACTION);
61 }
62}
63
64base::string16 DevModeBubbleDelegate::GetTitle() const {
65 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
66}
67
68base::string16 DevModeBubbleDelegate::GetMessageBody() const {
69 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
70}
71
72base::string16 DevModeBubbleDelegate::GetOverflowText(
73 const base::string16& overflow_count) const {
74 return l10n_util::GetStringFUTF16(
75 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
76 overflow_count);
77}
78
79base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
80 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
81}
82
83GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
84 return GURL(chrome::kChromeUIExtensionsURL);
85}
86
87base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
88 return l10n_util::GetStringUTF16(IDS_DISABLE);
89}
90
91base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
92 return l10n_util::GetStringUTF16(IDS_CANCEL);
93}
94
95bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
96 return false;
97}
98
99void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
100 UMA_HISTOGRAM_COUNTS_100(
101 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
102}
103
104void DevModeBubbleDelegate::LogAction(
105 ExtensionMessageBubbleController::BubbleAction action) {
106 UMA_HISTOGRAM_ENUMERATION(
107 "DevModeExtensionBubble.UserSelection",
108 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
109}
[email protected]c72ebfe2013-12-13 21:57:53110
111} // namespace
112
113namespace extensions {
114
115////////////////////////////////////////////////////////////////////////////////
116// DevModeBubbleController
117
[email protected]4f2f353d2014-01-14 11:21:09118// static
119void DevModeBubbleController::ClearProfileListForTesting() {
120 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53121}
122
123// static
[email protected]c72ebfe2013-12-13 21:57:53124bool DevModeBubbleController::IsDevModeExtension(
[email protected]4f2f353d2014-01-14 11:21:09125 const Extension* extension) {
[email protected]c72ebfe2013-12-13 21:57:53126 if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
127 if (chrome::VersionInfo::GetChannel() <
128 chrome::VersionInfo::CHANNEL_BETA)
129 return false;
130 }
131 return extension->location() == Manifest::UNPACKED ||
132 extension->location() == Manifest::COMMAND_LINE;
133}
134
[email protected]4f2f353d2014-01-14 11:21:09135DevModeBubbleController::DevModeBubbleController(Profile* profile)
136 : ExtensionMessageBubbleController(
137 new DevModeBubbleDelegate(
138 extensions::ExtensionSystem::Get(profile)->extension_service()),
139 profile),
140 profile_(profile) {
[email protected]c72ebfe2013-12-13 21:57:53141}
142
[email protected]4f2f353d2014-01-14 11:21:09143DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53144}
145
[email protected]4f2f353d2014-01-14 11:21:09146bool DevModeBubbleController::ShouldShow() {
147 return !g_shown_for_profiles.Get().count(profile_) &&
148 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53149}
150
[email protected]4f2f353d2014-01-14 11:21:09151void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
152 g_shown_for_profiles.Get().insert(profile_);
153 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53154}
155
156} // namespace extensions