OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
Devlin
2014/05/20 17:26:31
no (c)
Finnur
2014/05/21 16:30:32
Done.
| |
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/proxy_overridden_bubble_controller.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "chrome/browser/extensions/extension_service.h" | |
9 #include "chrome/browser/extensions/extension_toolbar_model.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/common/url_constants.h" | |
12 #include "extensions/browser/extension_registry.h" | |
13 #include "extensions/browser/extension_system.h" | |
14 #include "grit/generated_resources.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 using extensions::ExtensionMessageBubbleController; | |
18 using extensions::ProxyOverriddenBubbleController; | |
Devlin
2014/05/20 17:26:31
instead, why not just move the extensions namespac
Finnur
2014/05/21 16:30:32
See? You're not as dumb as I look! :)
| |
19 | |
20 namespace { | |
21 | |
22 //////////////////////////////////////////////////////////////////////////////// | |
23 // ProxyOverriddenBubbleDelegate | |
24 | |
25 class ProxyOverriddenBubbleDelegate | |
26 : public extensions::ExtensionMessageBubbleController::Delegate { | |
27 public: | |
28 ProxyOverriddenBubbleDelegate(ExtensionService* service, Profile* profile); | |
29 virtual ~ProxyOverriddenBubbleDelegate(); | |
30 | |
31 // ExtensionMessageBubbleController::Delegate methods. | |
32 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE; | |
33 virtual void AcknowledgeExtension( | |
34 const std::string& extension_id, | |
35 extensions::ExtensionMessageBubbleController::BubbleAction | |
36 user_action) OVERRIDE; | |
37 virtual void PerformAction(const extensions::ExtensionIdList& list) OVERRIDE; | |
38 virtual void OnClose() OVERRIDE; | |
39 virtual base::string16 GetTitle() const OVERRIDE; | |
40 virtual base::string16 GetMessageBody() const OVERRIDE; | |
41 virtual base::string16 GetOverflowText( | |
42 const base::string16& overflow_count) const OVERRIDE; | |
43 virtual base::string16 GetLearnMoreLabel() const OVERRIDE; | |
44 virtual GURL GetLearnMoreUrl() const OVERRIDE; | |
45 virtual base::string16 GetActionButtonLabel() const OVERRIDE; | |
46 virtual base::string16 GetDismissButtonLabel() const OVERRIDE; | |
47 virtual bool ShouldShowExtensionList() const OVERRIDE; | |
48 virtual void RestrictToSingleExtension( | |
49 const std::string& extension_id) OVERRIDE; | |
50 virtual void LogExtensionCount(size_t count) OVERRIDE; | |
51 virtual void LogAction( | |
52 extensions::ExtensionMessageBubbleController::BubbleAction | |
53 action) OVERRIDE; | |
54 | |
55 private: | |
56 // Our extension service. Weak, not owned by us. | |
57 ExtensionService* service_; | |
58 | |
59 // A weak pointer to the profile we are associated with. Not owned by us. | |
60 Profile* profile_; | |
61 | |
62 // The ID of the extension we are showing the bubble for. | |
63 std::string extension_id_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(ProxyOverriddenBubbleDelegate); | |
66 }; | |
67 | |
68 ProxyOverriddenBubbleDelegate::ProxyOverriddenBubbleDelegate( | |
69 ExtensionService* service, | |
70 Profile* profile) | |
71 : service_(service), profile_(profile) {} | |
72 | |
73 ProxyOverriddenBubbleDelegate::~ProxyOverriddenBubbleDelegate() {} | |
74 | |
75 bool ProxyOverriddenBubbleDelegate::ShouldIncludeExtension( | |
76 const std::string& extension_id) { | |
77 if (!extension_id_.empty() && extension_id_ != extension_id) | |
78 return false; | |
79 | |
80 using extensions::ExtensionRegistry; | |
81 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | |
Devlin
2014/05/20 17:26:31
Only used once - why not inline? ExtensionRegistr
Finnur
2014/05/21 16:30:32
Done.
| |
82 const extensions::Extension* extension = | |
83 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | |
Devlin
2014/05/20 17:26:31
nit: slightly more efficient:
registry->enabled_ex
Finnur
2014/05/21 16:30:32
Done.
| |
84 if (!extension) | |
85 return false; // The extension provided is no longer enabled. | |
86 | |
87 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); | |
Devlin
2014/05/20 17:26:31
Only used once - inline.
Finnur
2014/05/21 16:30:32
Done.
| |
88 if (prefs->HasProxyOverriddenBubbleBeenAcknowledged(extension_id)) | |
89 return false; | |
90 | |
91 return true; | |
92 } | |
93 | |
94 void ProxyOverriddenBubbleDelegate::AcknowledgeExtension( | |
95 const std::string& extension_id, | |
96 ExtensionMessageBubbleController::BubbleAction user_action) { | |
97 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) { | |
98 extensions::ExtensionPrefs* prefs = | |
99 extensions::ExtensionPrefs::Get(profile_); | |
100 prefs->SetProxyOverriddenBubbleBeenAcknowledged(extension_id, true); | |
Devlin
2014/05/20 17:26:31
inline.
Finnur
2014/05/21 16:30:32
I find my way generally helps readability and avoi
Devlin
2014/05/21 17:00:39
If it's just one object, I find inline perfectly e
| |
101 } | |
102 } | |
103 | |
104 void ProxyOverriddenBubbleDelegate::PerformAction( | |
105 const extensions::ExtensionIdList& list) { | |
106 for (size_t i = 0; i < list.size(); ++i) { | |
107 service_->DisableExtension(list[i], | |
108 extensions::Extension::DISABLE_USER_ACTION); | |
109 } | |
110 } | |
111 | |
112 void ProxyOverriddenBubbleDelegate::OnClose() { | |
113 extensions::ExtensionToolbarModel* toolbar_model = | |
114 extensions::ExtensionToolbarModel::Get(profile_); | |
115 if (toolbar_model) | |
116 toolbar_model->StopHighlighting(); | |
117 } | |
118 | |
119 base::string16 ProxyOverriddenBubbleDelegate::GetTitle() const { | |
120 return l10n_util::GetStringUTF16( | |
121 IDS_EXTENSIONS_PROXY_CONTROLLED_TITLE_HOME_PAGE_BUBBLE); | |
122 } | |
123 | |
124 base::string16 ProxyOverriddenBubbleDelegate::GetMessageBody() const { | |
125 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE); | |
126 } | |
127 | |
128 base::string16 ProxyOverriddenBubbleDelegate::GetOverflowText( | |
129 const base::string16& overflow_count) const { | |
130 // Does not have more than one extension in the list at a time. | |
131 NOTREACHED(); | |
132 return base::string16(); | |
133 } | |
134 | |
135 base::string16 ProxyOverriddenBubbleDelegate::GetLearnMoreLabel() const { | |
136 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
137 } | |
138 | |
139 GURL ProxyOverriddenBubbleDelegate::GetLearnMoreUrl() const { | |
140 return GURL(chrome::kExtensionControlledSettingLearnMoreURL); | |
141 } | |
142 | |
143 base::string16 ProxyOverriddenBubbleDelegate::GetActionButtonLabel() const { | |
144 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_RESTORE_SETTINGS); | |
145 } | |
146 | |
147 base::string16 ProxyOverriddenBubbleDelegate::GetDismissButtonLabel() const { | |
148 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_KEEP_CHANGES); | |
149 } | |
150 | |
151 bool ProxyOverriddenBubbleDelegate::ShouldShowExtensionList() const { | |
152 return false; | |
153 } | |
154 | |
155 void ProxyOverriddenBubbleDelegate::RestrictToSingleExtension( | |
156 const std::string& extension_id) { | |
157 extension_id_ = extension_id; | |
158 } | |
159 | |
160 void ProxyOverriddenBubbleDelegate::LogExtensionCount(size_t count) { | |
161 UMA_HISTOGRAM_COUNTS_100("ProxyOverriddenBubble.ExtensionCount", count); | |
162 } | |
163 | |
164 void ProxyOverriddenBubbleDelegate::LogAction( | |
165 ExtensionMessageBubbleController::BubbleAction action) { | |
166 UMA_HISTOGRAM_ENUMERATION("ProxyOverriddenBubble.UserSelection", | |
167 action, | |
168 ExtensionMessageBubbleController::ACTION_BOUNDARY); | |
169 } | |
170 | |
171 } // namespace | |
172 | |
173 namespace extensions { | |
174 | |
175 //////////////////////////////////////////////////////////////////////////////// | |
176 // ProxyOverriddenBubbleController | |
177 | |
178 ProxyOverriddenBubbleController::ProxyOverriddenBubbleController( | |
179 Profile* profile) | |
180 : ExtensionMessageBubbleController( | |
181 new ProxyOverriddenBubbleDelegate( | |
182 ExtensionSystem::Get(profile)->extension_service(), | |
183 profile), | |
184 profile), | |
185 profile_(profile) {} | |
186 | |
187 ProxyOverriddenBubbleController::~ProxyOverriddenBubbleController() {} | |
188 | |
189 bool ProxyOverriddenBubbleController::ShouldShow( | |
190 const std::string& extension_id) { | |
191 if (!delegate()->ShouldIncludeExtension(extension_id)) | |
192 return false; | |
193 | |
194 delegate()->RestrictToSingleExtension(extension_id); | |
195 return true; | |
196 } | |
197 | |
198 bool ProxyOverriddenBubbleController::CloseOnDeactivate() { | |
199 return true; | |
200 } | |
201 | |
202 } // namespace extensions | |
OLD | NEW |