Remove keyboard_ui.css and manifest_keyboard.json
[chromium-blink-merge.git] / chrome / browser / extensions / proxy_overridden_bubble_controller.cc
blob0a401413c0cf95d08d1906360f00c6ec532b5e10
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.
5 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h"
7 #include "base/metrics/histogram.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/settings_api_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "extensions/browser/extension_prefs.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_system.h"
17 #include "grit/components_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
20 namespace extensions {
22 namespace {
24 // The minimum time to wait (since the extension was installed) before notifying
25 // the user about it.
26 const int kDaysSinceInstallMin = 7;
28 // Whether the user has been notified about extension overriding the proxy.
29 const char kProxyBubbleAcknowledged[] = "ack_proxy_bubble";
31 ////////////////////////////////////////////////////////////////////////////////
32 // ProxyOverriddenBubbleDelegate
34 class ProxyOverriddenBubbleDelegate
35 : public ExtensionMessageBubbleController::Delegate {
36 public:
37 ProxyOverriddenBubbleDelegate(ExtensionService* service, Profile* profile);
38 ~ProxyOverriddenBubbleDelegate() override;
40 // ExtensionMessageBubbleController::Delegate methods.
41 bool ShouldIncludeExtension(const std::string& extension_id) override;
42 void AcknowledgeExtension(
43 const std::string& extension_id,
44 ExtensionMessageBubbleController::BubbleAction user_action) override;
45 void PerformAction(const ExtensionIdList& list) override;
46 base::string16 GetTitle() const override;
47 base::string16 GetMessageBody(bool anchored_to_browser_action,
48 int extension_count) const override;
49 base::string16 GetOverflowText(
50 const base::string16& overflow_count) const override;
51 GURL GetLearnMoreUrl() const override;
52 base::string16 GetActionButtonLabel() const override;
53 base::string16 GetDismissButtonLabel() const override;
54 bool ShouldShowExtensionList() const override;
55 bool ShouldHighlightExtensions() const override;
56 void RestrictToSingleExtension(const std::string& extension_id) override;
57 void LogExtensionCount(size_t count) override;
58 void LogAction(
59 ExtensionMessageBubbleController::BubbleAction action) override;
61 private:
62 // Our extension service. Weak, not owned by us.
63 ExtensionService* service_;
65 // The ID of the extension we are showing the bubble for.
66 std::string extension_id_;
68 DISALLOW_COPY_AND_ASSIGN(ProxyOverriddenBubbleDelegate);
71 ProxyOverriddenBubbleDelegate::ProxyOverriddenBubbleDelegate(
72 ExtensionService* service,
73 Profile* profile)
74 : ExtensionMessageBubbleController::Delegate(profile),
75 service_(service) {
76 set_acknowledged_flag_pref_name(kProxyBubbleAcknowledged);
79 ProxyOverriddenBubbleDelegate::~ProxyOverriddenBubbleDelegate() {}
81 bool ProxyOverriddenBubbleDelegate::ShouldIncludeExtension(
82 const std::string& extension_id) {
83 if (!extension_id_.empty() && extension_id_ != extension_id)
84 return false;
86 const Extension* extension =
87 ExtensionRegistry::Get(profile())->enabled_extensions().GetByID(
88 extension_id);
89 if (!extension)
90 return false; // The extension provided is no longer enabled.
92 const Extension* overriding = GetExtensionOverridingProxy(profile());
93 if (!overriding || overriding->id() != extension_id)
94 return false;
96 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
97 base::TimeDelta since_install =
98 base::Time::Now() - prefs->GetInstallTime(extension->id());
99 if (since_install.InDays() < kDaysSinceInstallMin)
100 return false;
102 if (HasBubbleInfoBeenAcknowledged(extension_id))
103 return false;
105 return true;
108 void ProxyOverriddenBubbleDelegate::AcknowledgeExtension(
109 const std::string& extension_id,
110 ExtensionMessageBubbleController::BubbleAction user_action) {
111 if (user_action != ExtensionMessageBubbleController::ACTION_EXECUTE)
112 SetBubbleInfoBeenAcknowledged(extension_id, true);
115 void ProxyOverriddenBubbleDelegate::PerformAction(const ExtensionIdList& list) {
116 for (size_t i = 0; i < list.size(); ++i)
117 service_->DisableExtension(list[i], Extension::DISABLE_USER_ACTION);
120 base::string16 ProxyOverriddenBubbleDelegate::GetTitle() const {
121 return l10n_util::GetStringUTF16(
122 IDS_EXTENSIONS_PROXY_CONTROLLED_TITLE_HOME_PAGE_BUBBLE);
125 base::string16 ProxyOverriddenBubbleDelegate::GetMessageBody(
126 bool anchored_to_browser_action,
127 int extension_count) const {
128 if (anchored_to_browser_action) {
129 return l10n_util::GetStringUTF16(
130 IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE_EXTENSION_SPECIFIC);
131 } else {
132 const Extension* extension =
133 ExtensionRegistry::Get(profile())->GetExtensionById(
134 extension_id_, ExtensionRegistry::EVERYTHING);
135 // If the bubble is about to show, the extension should certainly exist.
136 CHECK(extension);
137 return l10n_util::GetStringFUTF16(
138 IDS_EXTENSIONS_PROXY_CONTROLLED_FIRST_LINE,
139 base::UTF8ToUTF16(extension->name()));
143 base::string16 ProxyOverriddenBubbleDelegate::GetOverflowText(
144 const base::string16& overflow_count) const {
145 // Does not have more than one extension in the list at a time.
146 NOTREACHED();
147 return base::string16();
150 GURL ProxyOverriddenBubbleDelegate::GetLearnMoreUrl() const {
151 return GURL(chrome::kExtensionControlledSettingLearnMoreURL);
154 base::string16 ProxyOverriddenBubbleDelegate::GetActionButtonLabel() const {
155 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_RESTORE_SETTINGS);
158 base::string16 ProxyOverriddenBubbleDelegate::GetDismissButtonLabel() const {
159 return l10n_util::GetStringUTF16(IDS_EXTENSION_CONTROLLED_KEEP_CHANGES);
162 bool ProxyOverriddenBubbleDelegate::ShouldShowExtensionList() const {
163 return false;
166 bool ProxyOverriddenBubbleDelegate::ShouldHighlightExtensions() const {
167 return true;
170 void ProxyOverriddenBubbleDelegate::RestrictToSingleExtension(
171 const std::string& extension_id) {
172 extension_id_ = extension_id;
175 void ProxyOverriddenBubbleDelegate::LogExtensionCount(size_t count) {
176 UMA_HISTOGRAM_COUNTS_100("ProxyOverriddenBubble.ExtensionCount", count);
179 void ProxyOverriddenBubbleDelegate::LogAction(
180 ExtensionMessageBubbleController::BubbleAction action) {
181 UMA_HISTOGRAM_ENUMERATION("ProxyOverriddenBubble.UserSelection",
182 action,
183 ExtensionMessageBubbleController::ACTION_BOUNDARY);
186 } // namespace
188 ////////////////////////////////////////////////////////////////////////////////
189 // ProxyOverriddenBubbleController
191 ProxyOverriddenBubbleController::ProxyOverriddenBubbleController(
192 Profile* profile)
193 : ExtensionMessageBubbleController(
194 new ProxyOverriddenBubbleDelegate(
195 ExtensionSystem::Get(profile)->extension_service(),
196 profile),
197 profile),
198 profile_(profile) {}
200 ProxyOverriddenBubbleController::~ProxyOverriddenBubbleController() {}
202 bool ProxyOverriddenBubbleController::ShouldShow(
203 const std::string& extension_id) {
204 if (!delegate()->ShouldIncludeExtension(extension_id))
205 return false;
207 delegate()->RestrictToSingleExtension(extension_id);
208 return true;
211 bool ProxyOverriddenBubbleController::CloseOnDeactivate() {
212 return false;
215 } // namespace extensions