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

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

Issue 288923004: Add an extension override bubble and warning box for proxy extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address UI team comments Created 6 years, 6 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
(Empty)
1 // Copyright 2014 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/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 namespace extensions {
18
19 namespace {
20
21 // The minimum time to wait (since the extension was installed) before notifying
22 // the user about it.
23 const int kDaysSinceInstallMin = 7;
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // ProxyOverriddenBubbleDelegate
27
28 class ProxyOverriddenBubbleDelegate
29 : public ExtensionMessageBubbleController::Delegate {
30 public:
31 ProxyOverriddenBubbleDelegate(ExtensionService* service, Profile* profile);
32 virtual ~ProxyOverriddenBubbleDelegate();
33
34 // ExtensionMessageBubbleController::Delegate methods.
35 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE;
36 virtual void AcknowledgeExtension(
37 const std::string& extension_id,
38 ExtensionMessageBubbleController::BubbleAction
39 user_action) OVERRIDE;
40 virtual void PerformAction(const ExtensionIdList& list) OVERRIDE;
41 virtual void OnClose() OVERRIDE;
42 virtual base::string16 GetTitle() const OVERRIDE;
43 virtual base::string16 GetMessageBody(
44 bool anchored_to_browser_action) const OVERRIDE;
45 virtual base::string16 GetOverflowText(
46 const base::string16& overflow_count) const OVERRIDE;
47 virtual base::string16 GetLearnMoreLabel() const OVERRIDE;
48 virtual GURL GetLearnMoreUrl() const OVERRIDE;
49 virtual base::string16 GetActionButtonLabel() const OVERRIDE;
50 virtual base::string16 GetDismissButtonLabel() const OVERRIDE;
51 virtual bool ShouldShowExtensionList() const OVERRIDE;
52 virtual void RestrictToSingleExtension(
53 const std::string& extension_id) OVERRIDE;
54 virtual void LogExtensionCount(size_t count) OVERRIDE;
55 virtual void LogAction(
56 ExtensionMessageBubbleController::BubbleAction
57 action) OVERRIDE;
58
59 private:
60 // Our extension service. Weak, not owned by us.
61 ExtensionService* service_;
62
63 // A weak pointer to the profile we are associated with. Not owned by us.
64 Profile* profile_;
65
66 // The ID of the extension we are showing the bubble for.
67 std::string extension_id_;
68
69 DISALLOW_COPY_AND_ASSIGN(ProxyOverriddenBubbleDelegate);
70 };
71
72 ProxyOverriddenBubbleDelegate::ProxyOverriddenBubbleDelegate(
73 ExtensionService* service,
74 Profile* profile)
75 : service_(service), profile_(profile) {}
76
77 ProxyOverriddenBubbleDelegate::~ProxyOverriddenBubbleDelegate() {}
78
79 bool ProxyOverriddenBubbleDelegate::ShouldIncludeExtension(
80 const std::string& extension_id) {
81 if (!extension_id_.empty() && extension_id_ != extension_id)
82 return false;
83
84 const Extension* extension =
85 ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID(
86 extension_id);
87 if (!extension)
88 return false; // The extension provided is no longer enabled.
89
90 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
91 base::TimeDelta since_install =
92 base::Time::Now() - prefs->GetInstallTime(extension->id());
93 if (since_install.InDays() < kDaysSinceInstallMin)
94 return false;
95
96 if (ExtensionPrefs::Get(profile_)->HasProxyOverriddenBubbleBeenAcknowledged(
97 extension_id))
98 return false;
99
100 return true;
Devlin 2014/06/05 17:16:31 It seems a bit weird to me that we never check her
Finnur 2014/06/05 19:37:28 It works, but is a bit weird. I agree. Added the c
101 }
102
103 void ProxyOverriddenBubbleDelegate::AcknowledgeExtension(
104 const std::string& extension_id,
105 ExtensionMessageBubbleController::BubbleAction user_action) {
106 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) {
107 ExtensionPrefs::Get(profile_)->SetProxyOverriddenBubbleBeenAcknowledged(
108 extension_id, true);
109 }
110 }
111
112 void ProxyOverriddenBubbleDelegate::PerformAction(const ExtensionIdList& list) {
113 for (size_t i = 0; i < list.size(); ++i)
114 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
115 }
116
117 void ProxyOverriddenBubbleDelegate::OnClose() {
118 ExtensionToolbarModel* toolbar_model =
119 ExtensionToolbarModel::Get(profile_);
120 if (toolbar_model)
121 toolbar_model->StopHighlighting();
122 }
123
124 base::string16 ProxyOverriddenBubbleDelegate::GetTitle() const {
125 return l10n_util::GetStringUTF16(
126 IDS_EXTENSIONS_PROXY_CONTROLLED_TITLE_HOME_PAGE_BUBBLE);
127 }
128
129 base::string16 ProxyOverriddenBubbleDelegate::GetMessageBody(
130 bool anchored_to_browser_action) const {
131 if (anchored_to_browser_action) {
132 return l10n_util::GetStringUTF16(
133 IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE_EXTENSION_SPECIFIC);
134 } else {
135 return l10n_util::GetStringUTF16(
136 IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE);
137 }
138 }
139
140 base::string16 ProxyOverriddenBubbleDelegate::GetOverflowText(
141 const base::string16& overflow_count) const {
142 // Does not have more than one extension in the list at a time.
143 NOTREACHED();
144 return base::string16();
145 }
146
147 base::string16 ProxyOverriddenBubbleDelegate::GetLearnMoreLabel() const {
148 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
149 }
150
151 GURL ProxyOverriddenBubbleDelegate::GetLearnMoreUrl() const {
152 return GURL(chrome::kExtensionControlledSettingLearnMoreURL);
153 }
154
155 base::string16 ProxyOverriddenBubbleDelegate::GetActionButtonLabel() const {
156 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_RESTORE_SETTINGS);
157 }
158
159 base::string16 ProxyOverriddenBubbleDelegate::GetDismissButtonLabel() const {
160 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_KEEP_CHANGES);
161 }
162
163 bool ProxyOverriddenBubbleDelegate::ShouldShowExtensionList() const {
164 return false;
165 }
166
167 void ProxyOverriddenBubbleDelegate::RestrictToSingleExtension(
168 const std::string& extension_id) {
169 extension_id_ = extension_id;
170 }
171
172 void ProxyOverriddenBubbleDelegate::LogExtensionCount(size_t count) {
173 UMA_HISTOGRAM_COUNTS_100("ProxyOverriddenBubble.ExtensionCount", count);
174 }
175
176 void ProxyOverriddenBubbleDelegate::LogAction(
177 ExtensionMessageBubbleController::BubbleAction action) {
178 UMA_HISTOGRAM_ENUMERATION("ProxyOverriddenBubble.UserSelection",
179 action,
180 ExtensionMessageBubbleController::ACTION_BOUNDARY);
181 }
182
183 } // namespace
184
185 ////////////////////////////////////////////////////////////////////////////////
186 // ProxyOverriddenBubbleController
187
188 ProxyOverriddenBubbleController::ProxyOverriddenBubbleController(
189 Profile* profile)
190 : ExtensionMessageBubbleController(
191 new ProxyOverriddenBubbleDelegate(
192 ExtensionSystem::Get(profile)->extension_service(),
193 profile),
194 profile),
195 profile_(profile) {}
196
197 ProxyOverriddenBubbleController::~ProxyOverriddenBubbleController() {}
198
199 bool ProxyOverriddenBubbleController::ShouldShow(
200 const std::string& extension_id) {
201 if (!delegate()->ShouldIncludeExtension(extension_id))
202 return false;
203
204 delegate()->RestrictToSingleExtension(extension_id);
205 return true;
206 }
207
208 bool ProxyOverriddenBubbleController::CloseOnDeactivate() {
209 return true;
210 }
211
212 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698