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

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

Issue 95133002: Add an extension bubble explaining which extensions are in dev mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error Created 7 years 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
(Empty)
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.
4
5 #include "chrome/browser/extensions/dev_mode_bubble_controller_delegate.h"
6
7 #include "base/bind.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_message_bubble.h"
13 #include "chrome/browser/extensions/extension_prefs.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/url_constants.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/user_metrics.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace {
25
26 static base::LazyInstance<extensions::ProfileKeyedAPIFactory<
27 extensions::DevModeBubbleControllerDelegate> >
28 g_factory = LAZY_INSTANCE_INITIALIZER;
29
30 } // namespace
31
32 namespace extensions {
33
34 ////////////////////////////////////////////////////////////////////////////////
35 // DevModeBubbleControllerDelegate
36
37 DevModeBubbleControllerDelegate::DevModeBubbleControllerDelegate(
38 Profile* profile)
39 : controller_(new ExtensionMessageBubbleController(this, profile)),
40 service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
41 profile_(profile) {
42 }
43
44 DevModeBubbleControllerDelegate::~DevModeBubbleControllerDelegate() {
45 }
46
47 // static
48 ProfileKeyedAPIFactory<DevModeBubbleControllerDelegate>*
49 DevModeBubbleControllerDelegate::GetFactoryInstance() {
50 return &g_factory.Get();
51 }
52
53 // static
54 DevModeBubbleControllerDelegate* DevModeBubbleControllerDelegate::Get(
55 Profile* profile) {
56 return ProfileKeyedAPIFactory<
57 DevModeBubbleControllerDelegate>::GetForProfile(profile);
58 }
59
60 bool DevModeBubbleControllerDelegate::IsDevModeExtension(
61 const Extension* extension) const {
62 return extension->location() == Manifest::UNPACKED ||
63 extension->location() == Manifest::COMMAND_LINE;
64 }
65
66 void DevModeBubbleControllerDelegate::Show(ExtensionMessageBubble* bubble) {
67 controller_->Show(bubble);
68 }
69
70 bool DevModeBubbleControllerDelegate::ShowingBubble() const {
71 return controller_->showing_bubble();
72 }
73
74 bool DevModeBubbleControllerDelegate::HasExtensionList() const {
75 return controller_->HasExtensionList();
76 }
77
78 std::vector<string16>
79 DevModeBubbleControllerDelegate::GetExtensionList() const {
80 return controller_->GetExtensionList();
81 }
82
83 const ExtensionIdList&
84 DevModeBubbleControllerDelegate::GetExtensionIdList() const {
85 return controller_->extension_id_list();
86 }
87
88 bool DevModeBubbleControllerDelegate::ShouldIncludeExtension(
89 const std::string& extension_id) {
90 const Extension* extension = service_->GetExtensionById(extension_id, false);
91 if (!extension)
92 return false;
93 if (!IsDevModeExtension(extension))
94 return false;
95 return true;
96 }
97
98 void DevModeBubbleControllerDelegate::AcknowledgeExtension(
99 const std::string& extension_id,
100 ExtensionMessageBubbleController::BubbleAction user_action) {
101 if (user_action == ExtensionMessageBubbleController::ACTION_EXECUTE)
102 return; // Extension is gone, no further action required.
103
104 // We'll need to let the browser action know that the state has been updated
105 // so the highlighting on the badge can be removed (if the extension has a
106 // browser action).
107 const Extension* extension = service_->GetExtensionById(extension_id, false);
108 if (!extension)
109 return;
110 ExtensionAction* action = ExtensionActionManager::Get(profile_)->
111 GetBrowserAction(*extension);
112 if (!action)
113 return;
114
115 content::NotificationService::current()->Notify(
116 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
117 content::Source<ExtensionAction>(action),
118 content::Details<Profile>(profile_));
119 }
120
121 void DevModeBubbleControllerDelegate::PerformAction(
122 const ExtensionIdList& list) {
123 for (size_t i = 0; i < list.size(); ++i)
124 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
125 }
126
127 string16 DevModeBubbleControllerDelegate::GetTitle() const {
128 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_TITLE);
129 }
130
131 string16 DevModeBubbleControllerDelegate::GetMessageBody() const {
132 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE_DEVELOPER_MODE_BODY);
133 }
134
135 string16 DevModeBubbleControllerDelegate::GetOverflowText(
136 const string16& overflow_count) const {
137 return l10n_util::GetStringFUTF16(
138 IDS_EXTENSIONS_SUSPICIOUS_DISABLED_AND_N_MORE,
139 overflow_count);
140 }
141
142 string16 DevModeBubbleControllerDelegate::GetLearnMoreLabel() const {
143 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
144 }
145
146 GURL DevModeBubbleControllerDelegate::GetLearnMoreUrl() const {
147 return GURL(chrome::kChromeUIExtensionsURL);
148 }
149
150 string16 DevModeBubbleControllerDelegate::GetActionButtonLabel() const {
151 return l10n_util::GetStringUTF16(IDS_DISABLE);
152 }
153
154 string16 DevModeBubbleControllerDelegate::GetDismissButtonLabel() const {
155 return l10n_util::GetStringUTF16(IDS_CANCEL);
156 }
157
158 bool DevModeBubbleControllerDelegate::ShouldShowExtensionList() const {
159 return true;
160 }
161
162 void DevModeBubbleControllerDelegate::LogExtensionCount(size_t count) {
163 UMA_HISTOGRAM_COUNTS_100(
164 "DevModeExtensionBubble.ExtensionsInDevModeCount", count);
165 }
166
167 void DevModeBubbleControllerDelegate::LogAction(
168 ExtensionMessageBubbleController::BubbleAction action) {
169 UMA_HISTOGRAM_ENUMERATION(
170 "DevModeExtensionBubble.UserSelection",
171 action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
172 }
173
174 template <>
175 void ProfileKeyedAPIFactory<
176 DevModeBubbleControllerDelegate>::DeclareFactoryDependencies() {
177 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
178 }
179
180 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698