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

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 review comments Created 6 years, 7 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 ////////////////////////////////////////////////////////////////////////////////
22 // ProxyOverriddenBubbleDelegate
23
24 class ProxyOverriddenBubbleDelegate
25 : public ExtensionMessageBubbleController::Delegate {
26 public:
27 ProxyOverriddenBubbleDelegate(ExtensionService* service, Profile* profile);
28 virtual ~ProxyOverriddenBubbleDelegate();
29
30 // ExtensionMessageBubbleController::Delegate methods.
31 virtual bool ShouldIncludeExtension(const std::string& extension_id) OVERRIDE;
32 virtual void AcknowledgeExtension(
33 const std::string& extension_id,
34 ExtensionMessageBubbleController::BubbleAction
35 user_action) OVERRIDE;
36 virtual void PerformAction(const ExtensionIdList& list) OVERRIDE;
37 virtual void OnClose() OVERRIDE;
38 virtual base::string16 GetTitle() const OVERRIDE;
39 virtual base::string16 GetMessageBody() const OVERRIDE;
40 virtual base::string16 GetOverflowText(
41 const base::string16& overflow_count) const OVERRIDE;
42 virtual base::string16 GetLearnMoreLabel() const OVERRIDE;
43 virtual GURL GetLearnMoreUrl() const OVERRIDE;
44 virtual base::string16 GetActionButtonLabel() const OVERRIDE;
45 virtual base::string16 GetDismissButtonLabel() const OVERRIDE;
46 virtual bool ShouldShowExtensionList() const OVERRIDE;
47 virtual void RestrictToSingleExtension(
48 const std::string& extension_id) OVERRIDE;
49 virtual void LogExtensionCount(size_t count) OVERRIDE;
50 virtual void LogAction(
51 ExtensionMessageBubbleController::BubbleAction
52 action) OVERRIDE;
53
54 private:
55 // Our extension service. Weak, not owned by us.
56 ExtensionService* service_;
57
58 // A weak pointer to the profile we are associated with. Not owned by us.
59 Profile* profile_;
60
61 // The ID of the extension we are showing the bubble for.
62 std::string extension_id_;
63
64 DISALLOW_COPY_AND_ASSIGN(ProxyOverriddenBubbleDelegate);
65 };
66
67 ProxyOverriddenBubbleDelegate::ProxyOverriddenBubbleDelegate(
68 ExtensionService* service,
69 Profile* profile)
70 : service_(service), profile_(profile) {}
71
72 ProxyOverriddenBubbleDelegate::~ProxyOverriddenBubbleDelegate() {}
73
74 bool ProxyOverriddenBubbleDelegate::ShouldIncludeExtension(
75 const std::string& extension_id) {
76 if (!extension_id_.empty() && extension_id_ != extension_id)
77 return false;
78
79 const Extension* extension =
80 ExtensionRegistry::Get(profile_)->enabled_extensions().GetByID(
81 extension_id);
82 if (!extension)
83 return false; // The extension provided is no longer enabled.
84
85 if (ExtensionPrefs::Get(profile_)->HasProxyOverriddenBubbleBeenAcknowledged(
86 extension_id))
87 return false;
88
89 return true;
90 }
91
92 void ProxyOverriddenBubbleDelegate::AcknowledgeExtension(
93 const std::string& extension_id,
94 ExtensionMessageBubbleController::BubbleAction user_action) {
95 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE) {
96 ExtensionPrefs::Get(profile_)->SetProxyOverriddenBubbleBeenAcknowledged(
97 extension_id, true);
98 }
99 }
100
101 void ProxyOverriddenBubbleDelegate::PerformAction(const ExtensionIdList& list) {
102 for (size_t i = 0; i < list.size(); ++i)
103 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
104 }
105
106 void ProxyOverriddenBubbleDelegate::OnClose() {
107 ExtensionToolbarModel* toolbar_model =
108 ExtensionToolbarModel::Get(profile_);
109 if (toolbar_model)
110 toolbar_model->StopHighlighting();
111 }
112
113 base::string16 ProxyOverriddenBubbleDelegate::GetTitle() const {
114 return l10n_util::GetStringUTF16(
115 IDS_EXTENSIONS_PROXY_CONTROLLED_TITLE_HOME_PAGE_BUBBLE);
116 }
117
118 base::string16 ProxyOverriddenBubbleDelegate::GetMessageBody() const {
119 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE);
120 }
121
122 base::string16 ProxyOverriddenBubbleDelegate::GetOverflowText(
123 const base::string16& overflow_count) const {
124 // Does not have more than one extension in the list at a time.
125 NOTREACHED();
126 return base::string16();
127 }
128
129 base::string16 ProxyOverriddenBubbleDelegate::GetLearnMoreLabel() const {
130 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
131 }
132
133 GURL ProxyOverriddenBubbleDelegate::GetLearnMoreUrl() const {
134 return GURL(chrome::kExtensionControlledSettingLearnMoreURL);
135 }
136
137 base::string16 ProxyOverriddenBubbleDelegate::GetActionButtonLabel() const {
138 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_RESTORE_SETTINGS);
139 }
140
141 base::string16 ProxyOverriddenBubbleDelegate::GetDismissButtonLabel() const {
142 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_KEEP_CHANGES);
143 }
144
145 bool ProxyOverriddenBubbleDelegate::ShouldShowExtensionList() const {
146 return false;
147 }
148
149 void ProxyOverriddenBubbleDelegate::RestrictToSingleExtension(
150 const std::string& extension_id) {
151 extension_id_ = extension_id;
152 }
153
154 void ProxyOverriddenBubbleDelegate::LogExtensionCount(size_t count) {
155 UMA_HISTOGRAM_COUNTS_100("ProxyOverriddenBubble.ExtensionCount", count);
156 }
157
158 void ProxyOverriddenBubbleDelegate::LogAction(
159 ExtensionMessageBubbleController::BubbleAction action) {
160 UMA_HISTOGRAM_ENUMERATION("ProxyOverriddenBubble.UserSelection",
161 action,
162 ExtensionMessageBubbleController::ACTION_BOUNDARY);
163 }
164
165 } // namespace
166
167 ////////////////////////////////////////////////////////////////////////////////
168 // ProxyOverriddenBubbleController
169
170 ProxyOverriddenBubbleController::ProxyOverriddenBubbleController(
171 Profile* profile)
172 : ExtensionMessageBubbleController(
173 new ProxyOverriddenBubbleDelegate(
174 ExtensionSystem::Get(profile)->extension_service(),
175 profile),
176 profile),
177 profile_(profile) {}
178
179 ProxyOverriddenBubbleController::~ProxyOverriddenBubbleController() {}
180
181 bool ProxyOverriddenBubbleController::ShouldShow(
182 const std::string& extension_id) {
183 if (!delegate()->ShouldIncludeExtension(extension_id))
184 return false;
185
186 delegate()->RestrictToSingleExtension(extension_id);
187 return true;
188 }
189
190 bool ProxyOverriddenBubbleController::CloseOnDeactivate() {
191 return true;
192 }
193
194 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698