blob: 7b3051257236ec95025b48f9c10c84578e2bc5a7 [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]f8454484652014-02-27 04:20:4215#include "chrome/browser/profiles/profile.h"
[email protected]c72ebfe2013-12-13 21:57:5316#include "chrome/browser/ui/browser.h"
17#include "chrome/browser/ui/browser_finder.h"
18#include "chrome/common/chrome_version_info.h"
19#include "chrome/common/url_constants.h"
20#include "content/public/browser/notification_service.h"
21#include "content/public/browser/user_metrics.h"
[email protected]489db0842014-01-22 18:20:0322#include "extensions/browser/extension_prefs.h"
[email protected]d46c0502014-02-14 13:33:3623#include "extensions/browser/extension_system.h"
[email protected]c72ebfe2013-12-13 21:57:5324#include "extensions/common/feature_switch.h"
25#include "grit/chromium_strings.h"
26#include "grit/generated_resources.h"
27#include "ui/base/l10n/l10n_util.h"
28
29namespace {
30
[email protected]4f2f353d2014-01-14 11:21:0931base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
32 LAZY_INSTANCE_INITIALIZER;
33
34////////////////////////////////////////////////////////////////////////////////
35// DevModeBubbleDelegate
36
37DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service)
38 : service_(service) {
39}
40
41DevModeBubbleDelegate::~DevModeBubbleDelegate() {
42}
43
44bool DevModeBubbleDelegate::ShouldIncludeExtension(
45 const std::string& extension_id) {
46 const extensions::Extension* extension =
47 service_->GetExtensionById(extension_id, false);
48 if (!extension)
49 return false;
50 return extensions::DevModeBubbleController::IsDevModeExtension(extension);
51}
52
53void DevModeBubbleDelegate::AcknowledgeExtension(
54 const std::string& extension_id,
55 ExtensionMessageBubbleController::BubbleAction user_action) {
56}
57
58void DevModeBubbleDelegate::PerformAction(
59 const extensions::ExtensionIdList& list) {
60 for (size_t i = 0; i < list.size(); ++i) {
61 service_->DisableExtension(
62 list[i], extensions::Extension::DISABLE_USER_ACTION);
63 }
64}
65
66base::string16 DevModeBubbleDelegate::GetTitle() const {
67 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
68}
69
70base::string16 DevModeBubbleDelegate::GetMessageBody() const {
71 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
72}
73
74base::string16 DevModeBubbleDelegate::GetOverflowText(
75 const base::string16& overflow_count) const {
76 return l10n_util::GetStringFUTF16(
77 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
78 overflow_count);
79}
80
81base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
82 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
83}
84
85GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
86 return GURL(chrome::kChromeUIExtensionsURL);
87}
88
89base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
90 return l10n_util::GetStringUTF16(IDS_DISABLE);
91}
92
93base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
94 return l10n_util::GetStringUTF16(IDS_CANCEL);
95}
96
97bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
98 return false;
99}
100
101void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
102 UMA_HISTOGRAM_COUNTS_100(
103 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
104}
105
106void DevModeBubbleDelegate::LogAction(
107 ExtensionMessageBubbleController::BubbleAction action) {
108 UMA_HISTOGRAM_ENUMERATION(
109 "DevModeExtensionBubble.UserSelection",
110 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
111}
[email protected]c72ebfe2013-12-13 21:57:53112
113} // namespace
114
115namespace extensions {
116
117////////////////////////////////////////////////////////////////////////////////
118// DevModeBubbleController
119
[email protected]4f2f353d2014-01-14 11:21:09120// static
121void DevModeBubbleController::ClearProfileListForTesting() {
122 g_shown_for_profiles.Get().clear();
[email protected]c72ebfe2013-12-13 21:57:53123}
124
125// static
[email protected]c72ebfe2013-12-13 21:57:53126bool DevModeBubbleController::IsDevModeExtension(
[email protected]4f2f353d2014-01-14 11:21:09127 const Extension* extension) {
[email protected]d46c0502014-02-14 13:33:36128 if (!FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
[email protected]c72ebfe2013-12-13 21:57:53129 if (chrome::VersionInfo::GetChannel() <
130 chrome::VersionInfo::CHANNEL_BETA)
131 return false;
132 }
133 return extension->location() == Manifest::UNPACKED ||
134 extension->location() == Manifest::COMMAND_LINE;
135}
136
[email protected]4f2f353d2014-01-14 11:21:09137DevModeBubbleController::DevModeBubbleController(Profile* profile)
138 : ExtensionMessageBubbleController(
139 new DevModeBubbleDelegate(
[email protected]d46c0502014-02-14 13:33:36140 ExtensionSystem::Get(profile)->extension_service()),
[email protected]4f2f353d2014-01-14 11:21:09141 profile),
[email protected]d46c0502014-02-14 13:33:36142 profile_(profile) {}
[email protected]c72ebfe2013-12-13 21:57:53143
[email protected]4f2f353d2014-01-14 11:21:09144DevModeBubbleController::~DevModeBubbleController() {
[email protected]c72ebfe2013-12-13 21:57:53145}
146
[email protected]4f2f353d2014-01-14 11:21:09147bool DevModeBubbleController::ShouldShow() {
148 return !g_shown_for_profiles.Get().count(profile_) &&
149 !GetExtensionList().empty();
[email protected]c72ebfe2013-12-13 21:57:53150}
151
[email protected]4f2f353d2014-01-14 11:21:09152void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
153 g_shown_for_profiles.Get().insert(profile_);
154 ExtensionMessageBubbleController::Show(bubble);
[email protected]c72ebfe2013-12-13 21:57:53155}
156
157} // namespace extensions