Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: chrome/browser/extensions/dev_mode_bubble_controller.cc

Issue 134103002: Refactor the extension message bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" 5 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_message_bubble.h" 13 #include "chrome/browser/extensions/extension_message_bubble.h"
13 #include "chrome/browser/extensions/extension_prefs.h" 14 #include "chrome/browser/extensions/extension_prefs.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_finder.h" 17 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/user_metrics.h" 21 #include "content/public/browser/user_metrics.h"
21 #include "extensions/common/feature_switch.h" 22 #include "extensions/common/feature_switch.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 26
26 namespace { 27 namespace {
27 28
28 static base::LazyInstance<extensions::ProfileKeyedAPIFactory< 29 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
29 extensions::DevModeBubbleController> > 30 LAZY_INSTANCE_INITIALIZER;
30 g_factory = LAZY_INSTANCE_INITIALIZER; 31
32 ////////////////////////////////////////////////////////////////////////////////
33 // DevModeBubbleDelegate
34
35 DevModeBubbleDelegate::DevModeBubbleDelegate(ExtensionService* service)
36 : service_(service) {
37 }
38
39 DevModeBubbleDelegate::~DevModeBubbleDelegate() {
40 }
41
42 bool 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
51 void DevModeBubbleDelegate::AcknowledgeExtension(
52 const std::string& extension_id,
53 ExtensionMessageBubbleController::BubbleAction user_action) {
54 }
55
56 void 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
64 base::string16 DevModeBubbleDelegate::GetTitle() const {
65 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
66 }
67
68 base::string16 DevModeBubbleDelegate::GetMessageBody() const {
69 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
70 }
71
72 base::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
79 base::string16 DevModeBubbleDelegate::GetLearnMoreLabel() const {
80 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
81 }
82
83 GURL DevModeBubbleDelegate::GetLearnMoreUrl() const {
84 return GURL(chrome::kChromeUIExtensionsURL);
85 }
86
87 base::string16 DevModeBubbleDelegate::GetActionButtonLabel() const {
88 return l10n_util::GetStringUTF16(IDS_DISABLE);
89 }
90
91 base::string16 DevModeBubbleDelegate::GetDismissButtonLabel() const {
92 return l10n_util::GetStringUTF16(IDS_CANCEL);
93 }
94
95 bool DevModeBubbleDelegate::ShouldShowExtensionList() const {
96 return false;
97 }
98
99 void DevModeBubbleDelegate::LogExtensionCount(size_t count) {
100 UMA_HISTOGRAM_COUNTS_100(
101 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
102 }
103
104 void DevModeBubbleDelegate::LogAction(
105 ExtensionMessageBubbleController::BubbleAction action) {
106 UMA_HISTOGRAM_ENUMERATION(
107 "DevModeExtensionBubble.UserSelection",
108 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
109 }
31 110
32 } // namespace 111 } // namespace
33 112
34 namespace extensions { 113 namespace extensions {
35 114
36 //////////////////////////////////////////////////////////////////////////////// 115 ////////////////////////////////////////////////////////////////////////////////
37 // DevModeBubbleController 116 // DevModeBubbleController
38 117
39 DevModeBubbleController::DevModeBubbleController( 118 // static
40 Profile* profile) 119 void DevModeBubbleController::ClearProfileListForTesting() {
41 : ExtensionMessageBubbleController(this, profile), 120 g_shown_for_profiles.Get().clear();
42 service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
43 profile_(profile) {
44 }
45
46 DevModeBubbleController::~DevModeBubbleController() {
47 } 121 }
48 122
49 // static 123 // static
50 ProfileKeyedAPIFactory<DevModeBubbleController>*
51 DevModeBubbleController::GetFactoryInstance() {
52 return &g_factory.Get();
53 }
54
55 // static
56 DevModeBubbleController* DevModeBubbleController::Get(
57 Profile* profile) {
58 return ProfileKeyedAPIFactory<
59 DevModeBubbleController>::GetForProfile(profile);
60 }
61
62 bool DevModeBubbleController::IsDevModeExtension( 124 bool DevModeBubbleController::IsDevModeExtension(
63 const Extension* extension) const { 125 const Extension* extension) {
64 if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) { 126 if (!extensions::FeatureSwitch::force_dev_mode_highlighting()->IsEnabled()) {
65 if (chrome::VersionInfo::GetChannel() < 127 if (chrome::VersionInfo::GetChannel() <
66 chrome::VersionInfo::CHANNEL_BETA) 128 chrome::VersionInfo::CHANNEL_BETA)
67 return false; 129 return false;
68 } 130 }
69 return extension->location() == Manifest::UNPACKED || 131 return extension->location() == Manifest::UNPACKED ||
70 extension->location() == Manifest::COMMAND_LINE; 132 extension->location() == Manifest::COMMAND_LINE;
71 } 133 }
72 134
73 bool DevModeBubbleController::ShouldIncludeExtension( 135 DevModeBubbleController::DevModeBubbleController(Profile* profile)
74 const std::string& extension_id) { 136 : ExtensionMessageBubbleController(
75 const Extension* extension = service_->GetExtensionById(extension_id, false); 137 new DevModeBubbleDelegate(
76 if (!extension) 138 extensions::ExtensionSystem::Get(profile)->extension_service()),
77 return false; 139 profile),
78 return IsDevModeExtension(extension); 140 profile_(profile) {
79 } 141 }
80 142
81 void DevModeBubbleController::AcknowledgeExtension( 143 DevModeBubbleController::~DevModeBubbleController() {
82 const std::string& extension_id,
83 ExtensionMessageBubbleController::BubbleAction user_action) {
84 } 144 }
85 145
86 void DevModeBubbleController::PerformAction( 146 bool DevModeBubbleController::ShouldShow() {
87 const ExtensionIdList& list) { 147 return !g_shown_for_profiles.Get().count(profile_) &&
88 for (size_t i = 0; i < list.size(); ++i) 148 !GetExtensionList().empty();
89 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
90 } 149 }
91 150
92 base::string16 DevModeBubbleController::GetTitle() const { 151 void DevModeBubbleController::Show(ExtensionMessageBubble* bubble) {
93 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE); 152 g_shown_for_profiles.Get().insert(profile_);
94 } 153 ExtensionMessageBubbleController::Show(bubble);
95
96 base::string16 DevModeBubbleController::GetMessageBody() const {
97 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
98 }
99
100 base::string16 DevModeBubbleController::GetOverflowText(
101 const base::string16& overflow_count) const {
102 return l10n_util::GetStringFUTF16(
103 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
104 overflow_count);
105 }
106
107 base::string16 DevModeBubbleController::GetLearnMoreLabel() const {
108 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
109 }
110
111 GURL DevModeBubbleController::GetLearnMoreUrl() const {
112 return GURL(chrome::kChromeUIExtensionsURL);
113 }
114
115 base::string16 DevModeBubbleController::GetActionButtonLabel() const {
116 return l10n_util::GetStringUTF16(IDS_DISABLE);
117 }
118
119 base::string16 DevModeBubbleController::GetDismissButtonLabel() const {
120 return l10n_util::GetStringUTF16(IDS_CANCEL);
121 }
122
123 bool DevModeBubbleController::ShouldShowExtensionList() const {
124 return false;
125 }
126
127 std::vector<base::string16> DevModeBubbleController::GetExtensions() {
128 return GetExtensionList();
129 }
130
131 void DevModeBubbleController::LogExtensionCount(size_t count) {
132 UMA_HISTOGRAM_COUNTS_100(
133 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
134 }
135
136 void DevModeBubbleController::LogAction(
137 ExtensionMessageBubbleController::BubbleAction action) {
138 UMA_HISTOGRAM_ENUMERATION(
139 "DevModeExtensionBubble.UserSelection",
140 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
141 }
142
143 template <>
144 void ProfileKeyedAPIFactory<
145 DevModeBubbleController>::DeclareFactoryDependencies() {
146 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
147 } 154 }
148 155
149 } // namespace extensions 156 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698