Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / suspicious_extension_bubble_controller.cc
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/suspicious_extension_bubble_controller.h"
6
7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/extensions/extension_message_bubble.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/user_metrics.h"
18 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_system.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 base::LazyInstance<std::set<Profile*> > g_shown_for_profiles =
27   LAZY_INSTANCE_INITIALIZER;
28
29 ////////////////////////////////////////////////////////////////////////////////
30 // SuspiciousExtensionBubbleDelegate
31
32 SuspiciousExtensionBubbleDelegate::SuspiciousExtensionBubbleDelegate(
33     Profile* profile)
34     : profile_(profile) {}
35
36 SuspiciousExtensionBubbleDelegate::~SuspiciousExtensionBubbleDelegate() {
37 }
38
39 bool SuspiciousExtensionBubbleDelegate::ShouldIncludeExtension(
40       const std::string& extension_id) {
41   extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
42   if (!prefs->IsExtensionDisabled(extension_id))
43     return false;
44
45   int disble_reasons = prefs->GetDisableReasons(extension_id);
46   if (disble_reasons & extensions::Extension::DISABLE_NOT_VERIFIED)
47     return !prefs->HasWipeoutBeenAcknowledged(extension_id);
48
49   return false;
50 }
51
52 void SuspiciousExtensionBubbleDelegate::AcknowledgeExtension(
53     const std::string& extension_id,
54     ExtensionMessageBubbleController::BubbleAction user_action) {
55   extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
56   prefs->SetWipeoutAcknowledged(extension_id, true);
57 }
58
59 void SuspiciousExtensionBubbleDelegate::PerformAction(
60     const extensions::ExtensionIdList& list) {
61   // This bubble solicits no action from the user. Or as Nimoy would have it:
62   // "Well, my work here is done".
63 }
64
65 base::string16 SuspiciousExtensionBubbleDelegate::GetTitle() const {
66   return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_TITLE);
67 }
68
69 base::string16 SuspiciousExtensionBubbleDelegate::GetMessageBody() const {
70   return l10n_util::GetStringFUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BODY,
71       l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
72 }
73
74 base::string16 SuspiciousExtensionBubbleDelegate::GetOverflowText(
75     const base::string16& overflow_count) const {
76   return l10n_util::GetStringFUTF16(
77             IDS_EXTENSIONS_DISABLED_AND_N_MORE,
78             overflow_count);
79 }
80
81 base::string16
82 SuspiciousExtensionBubbleDelegate::GetLearnMoreLabel() const {
83   return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
84 }
85
86 GURL SuspiciousExtensionBubbleDelegate::GetLearnMoreUrl() const {
87   return GURL(chrome::kRemoveNonCWSExtensionURL);
88 }
89
90 base::string16
91 SuspiciousExtensionBubbleDelegate::GetActionButtonLabel() const {
92   return base::string16();
93 }
94
95 base::string16
96 SuspiciousExtensionBubbleDelegate::GetDismissButtonLabel() const {
97   return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNSUPPORTED_DISABLED_BUTTON);
98 }
99
100 bool
101 SuspiciousExtensionBubbleDelegate::ShouldShowExtensionList() const {
102   return true;
103 }
104
105 void SuspiciousExtensionBubbleDelegate::LogExtensionCount(
106     size_t count) {
107   UMA_HISTOGRAM_COUNTS_100(
108       "ExtensionWipeoutBubble.ExtensionWipeoutCount", count);
109 }
110
111 void SuspiciousExtensionBubbleDelegate::LogAction(
112     ExtensionMessageBubbleController::BubbleAction action) {
113   UMA_HISTOGRAM_ENUMERATION(
114       "ExtensionWipeoutBubble.UserSelection",
115       action, ExtensionMessageBubbleController::ACTION_BOUNDARY);
116 }
117
118 }  // namespace
119
120 namespace extensions {
121
122 ////////////////////////////////////////////////////////////////////////////////
123 // SuspiciousExtensionBubbleController
124
125 // static
126 void SuspiciousExtensionBubbleController::ClearProfileListForTesting() {
127   g_shown_for_profiles.Get().clear();
128 }
129
130 SuspiciousExtensionBubbleController::SuspiciousExtensionBubbleController(
131     Profile* profile)
132     : ExtensionMessageBubbleController(
133           new SuspiciousExtensionBubbleDelegate(profile),
134           profile),
135       profile_(profile) {}
136
137 SuspiciousExtensionBubbleController::~SuspiciousExtensionBubbleController() {
138 }
139
140 bool SuspiciousExtensionBubbleController::ShouldShow() {
141   return !g_shown_for_profiles.Get().count(profile_->GetOriginalProfile()) &&
142       !GetExtensionList().empty();
143 }
144
145 void SuspiciousExtensionBubbleController::Show(ExtensionMessageBubble* bubble) {
146   g_shown_for_profiles.Get().insert(profile_->GetOriginalProfile());
147   ExtensionMessageBubbleController::Show(bubble);
148 }
149
150 }  // namespace extensions