blob: b8b0f0e3e218dfb6ebba24b4d43d4103ee846409 [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"
[email protected]a74569b2014-03-25 02:56:3015#include "chrome/browser/extensions/extension_toolbar_model.h"
[email protected]f8454484652014-02-27 04:20:4216#include "chrome/browser/profiles/profile.h"
[email protected]c72ebfe2013-12-13 21:57:5317#include "chrome/browser/ui/browser.h"
18#include "chrome/browser/ui/browser_finder.h"
19#include "chrome/common/chrome_version_info.h"
20#include "chrome/common/url_constants.h"
21#include "content/public/browser/notification_service.h"
22#include "content/public/browser/user_metrics.h"
[email protected]489db0842014-01-22 18:20:0323#include "extensions/browser/extension_prefs.h"
[email protected]d46c0502014-02-14 13:33:3624#include "extensions/browser/extension_system.h"
[email protected]c72ebfe2013-12-13 21:57:5325#include "extensions/common/feature_switch.h"
26#include "grit/chromium_strings.h"
27#include "grit/generated_resources.h"
28#include "ui/base/l10n/l10n_util.h"
29
[email protected]a74569b2014-03-25 02:56:3030namespace extensions {
31
[email protected]c72ebfe2013-12-13 21:57:5332namespace {
33
[email protected]4f2f353d2014-01-14 11:21:0934base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
35 LAZY_INSTANCE_INITIALIZER;
36
37////////////////////////////////////////////////////////////////////////////////
38// DevModeBubbleDelegate
39
[email protected]a74569b2014-03-25 02:56:3040DevModeBubbleDelegate::DevModeBubbleDelegate(Profile* profile)
41 : profile_(profile),
42 service_(ExtensionSystem::Get(profile)->extension_service()) {}
[email protected]4f2f353d2014-01-14 11:21:0943
44DevModeBubbleDelegate::~DevModeBubbleDelegate() {
45}
46
47bool DevModeBubbleDelegate::ShouldIncludeExtension(
48 const std::string& extension_id) {
[email protected]a74569b2014-03-25 02:56:3049 const Extension* extension = service_->GetExtensionById(extension_id, false);
[email protected]4f2f353d2014-01-14 11:21:0950 if (!extension)
51 return false;
[email protected]a74569b2014-03-25 02:56:3052 return DevModeBubbleController::IsDevModeExtension(extension);
[email protected]4f2f353d2014-01-14 11:21:0953}
54
55void DevModeBubbleDelegate::AcknowledgeExtension(
56 const std::string& extension_id,
57 ExtensionMessageBubbleController::BubbleAction user_action) {
58}
59
[email protected]a74569b2014-03-25 02:56:3060void DevModeBubbleDelegate::PerformAction(const ExtensionIdList& list) {
61 for (size_t i = 0; i < list.size(); ++i)
62 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
63}
64
65void DevModeBubbleDelegate::OnClose() {
66 ExtensionToolbarModel* toolbar_model = ExtensionToolbarModel::Get(profile_);
67 if (toolbar_model)
68 toolbar_model->StopHighlighting();
[email protected]4f2f353d2014-01-14 11:21:0969}
70
71base::string16 DevModeBubbleDelegate::GetTitle() const {
72 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
73}
74
75base::string16 DevModeBubbleDelegate::GetMessageBody() const {
76 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
77}
78
79base::string16 DevModeBubbleDelegate::GetOverflowText(
80 const base::string16& overflow_count) const {
81 return l10n_util::GetStringFUTF16(
[email protected]d2469242014-05-09 11:56:5882 IDS_EXTENSIONS_DISABLED_AND_N_MORE,
[email protected]4f2f353d2014-01-14 11:21:0983 overflow_count);
84}
85
86base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
87 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
88}
89
90GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
91 return GURL(chrome::kChromeUIExtensionsURL);
92}
93
94base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
95 return l10n_util::GetStringUTF16(IDS_DISABLE);
96}
97
98base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
99 return l10n_util::GetStringUTF16(IDS_CANCEL);
100}
101
102bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
103 return false;
104}
105
106void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
107 UMA_HISTOGRAM_COUNTS_100(
[email protected]b61b05ce8d2014-05-14 15:33:01108 "ExtensionBubble.ExtensionsInDevModeCount", count);
[email protected]4f2f353d2014-01-14 11:21:09109}
110
111void DevModeBubbleDelegate::LogAction(
112 ExtensionMessageBubbleController::BubbleAction action) {
113 UMA_HISTOGRAM_ENUMERATION(
[email protected]b61b05ce8d2014-05-14 15:33:01114 "ExtensionBubble.DevModeUserSelection",
[email protected]4f2f353d2014-01-14 11:21:09115 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
116}
[email protected]c72ebfe2013-12-13 21:57:53117
118} // namespace
119
[email protected]c72ebfe2013-12-13 21:57:53120////////////////////////////////////////////////////////////////////////////////
121// DevModeBubbleController
122
[email protected]4f2f353d2014-01-14 11:21:09123// static
124void DevModeBubbleController::ClearProfileListForTesting() {
125 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53126}
127
128// static
[email protected]c72ebfe2013-12-13 21:57:53129bool DevModeBubbleController::IsDevModeExtension(
[email protected]4f2f353d2014-01-14 11:21:09130 const Extension* extension) {
[email protected]d46c0502014-02-14 13:33:36131 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
[email protected]c72ebfe2013-12-13 21:57:53132 if (chrome::VersionInfo::GetChannel() <
133 chrome::VersionInfo::CHANNEL_BETA)
134 return false;
135 }
136 return extension->location() == Manifest::UNPACKED ||
137 extension->location() == Manifest::COMMAND_LINE;
138}
139
[email protected]4f2f353d2014-01-14 11:21:09140DevModeBubbleController::DevModeBubbleController(Profile* profile)
[email protected]a74569b2014-03-25 02:56:30141 : ExtensionMessageBubbleController(new DevModeBubbleDelegate(profile),
142 profile),
[email protected]d46c0502014-02-14 13:33:36143 profile_(profile) {}
[email protected]c72ebfe2013-12-13 21:57:53144
[email protected]4f2f353d2014-01-14 11:21:09145DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53146}
147
[email protected]4f2f353d2014-01-14 11:21:09148bool DevModeBubbleController::ShouldShow() {
[email protected]dbc165c2014-04-18 19:59:12149 return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
[email protected]4f2f353d2014-01-14 11:21:09150 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53151}
152
[email protected]4f2f353d2014-01-14 11:21:09153void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
[email protected]dbc165c2014-04-18 19:59:12154 g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
[email protected]4f2f353d2014-01-14 11:21:09155 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53156}
157
158} // namespace extensions