OLD | NEW |
---|---|
(Empty) | |
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/extension_message_bubble_controller.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/metrics/histogram.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/extensions/extension_message_bubble.h" | |
11 #include "chrome/browser/extensions/extension_prefs.h" | |
12 #include "chrome/browser/extensions/extension_service.h" | |
13 #include "chrome/browser/ui/browser.h" | |
14 #include "chrome/browser/ui/browser_finder.h" | |
15 #include "chrome/common/url_constants.h" | |
16 #include "content/public/browser/user_metrics.h" | |
17 #include "grit/chromium_strings.h" | |
18 #include "grit/generated_resources.h" | |
19 #include "ui/base/l10n/l10n_util.h" | |
20 | |
21 namespace extensions { | |
22 | |
23 //////////////////////////////////////////////////////////////////////////////// | |
24 // ExtensionMessageBubbleController | |
25 | |
26 ExtensionMessageBubbleController::ExtensionMessageBubbleController( | |
27 Delegate* delegate, Profile* profile) | |
28 : service_(extensions::ExtensionSystem::Get(profile)->extension_service()), | |
29 profile_(profile), | |
30 user_action_(ACTION_BOUNDARY), | |
31 delegate_(delegate), | |
32 initialized_(false), | |
33 has_notified_(false) { | |
34 } | |
35 | |
36 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() { | |
37 } | |
38 | |
39 bool ExtensionMessageBubbleController::ShouldShow() { | |
40 if (has_notified_) | |
41 return false; | |
42 if (!initialized_) | |
43 FetchExtensionList(); | |
44 | |
45 has_notified_ = true; | |
46 return !extension_list_.empty(); | |
47 } | |
48 | |
49 std::vector<string16> | |
50 ExtensionMessageBubbleController::GetExtensionList() { | |
51 if (!initialized_) | |
52 FetchExtensionList(); | |
53 if (extension_list_.empty()) | |
54 return std::vector<string16>(); | |
55 | |
56 std::vector<string16> return_value; | |
57 for (ExtensionIdList::const_iterator it = extension_list_.begin(); | |
58 it != extension_list_.end(); ++it) { | |
59 const Extension* extension = service_->GetInstalledExtension(*it); | |
60 if (extension) { | |
61 return_value.push_back(UTF8ToUTF16(extension->name())); | |
62 } else { | |
63 return_value.push_back( | |
64 ASCIIToUTF16(std::string("(unknown name) ") + *it)); | |
65 // TODO(finnur): Add this as a string to the grd, for next milestone. | |
66 } | |
67 } | |
68 return return_value; | |
69 } | |
70 | |
71 void ExtensionMessageBubbleController::Show(ExtensionMessageBubble* bubble) { | |
72 // Wire up all the callbacks, to get notified what actions the user took. | |
73 base::Closure dismiss_button_callback = | |
74 base::Bind(&ExtensionMessageBubbleController::OnBubbleDismiss, | |
75 base::Unretained(this)); | |
76 base::Closure action_button_callback = | |
77 base::Bind(&ExtensionMessageBubbleController::OnBubbleAction, | |
78 base::Unretained(this)); | |
79 base::Closure link_callback = | |
80 base::Bind(&ExtensionMessageBubbleController::OnLinkClicked, | |
81 base::Unretained(this)); | |
82 bubble->OnActionButtonClicked(action_button_callback); | |
83 bubble->OnDismissButtonClicked(dismiss_button_callback); | |
84 bubble->OnLinkClicked(link_callback); | |
85 | |
86 bubble->Show(); | |
87 } | |
88 | |
89 void ExtensionMessageBubbleController::OnBubbleAction() { | |
90 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
91 user_action_ = ACTION_EXECUTE; | |
92 | |
93 delegate_->LogAction(ACTION_EXECUTE); | |
94 delegate_->PerformAction(extension_list_); | |
not at google - send to devlin
2013/12/12 18:21:38
see comment below about GetOrCreateExtensionList()
Finnur
2013/12/12 20:25:12
Done.
| |
95 AcknowledgeExtensions(); | |
96 } | |
97 | |
98 void ExtensionMessageBubbleController::OnBubbleDismiss() { | |
99 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
100 user_action_ = ACTION_DISMISS; | |
101 | |
102 delegate_->LogAction(ACTION_DISMISS); | |
103 AcknowledgeExtensions(); | |
104 } | |
105 | |
106 void ExtensionMessageBubbleController::OnLinkClicked() { | |
107 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
108 user_action_ = ACTION_LEARN_MORE; | |
109 | |
110 delegate_->LogAction(ACTION_LEARN_MORE); | |
111 Browser* browser = | |
112 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | |
113 if (browser) { | |
114 browser->OpenURL( | |
115 content::OpenURLParams(delegate_->GetLearnMoreUrl(), | |
116 content::Referrer(), | |
117 NEW_FOREGROUND_TAB, | |
118 content::PAGE_TRANSITION_LINK, | |
119 false)); | |
120 } | |
121 AcknowledgeExtensions(); | |
122 } | |
123 | |
124 void ExtensionMessageBubbleController::AcknowledgeExtensions() { | |
125 for (ExtensionIdList::const_iterator it = extension_list_.begin(); | |
not at google - send to devlin
2013/12/12 18:21:38
and here?
Finnur
2013/12/12 20:25:12
Done.
| |
126 it != extension_list_.end(); ++it) | |
127 delegate_->AcknowledgeExtension(*it, user_action_); | |
128 } | |
129 | |
130 void ExtensionMessageBubbleController::FetchExtensionList() { | |
not at google - send to devlin
2013/12/12 18:21:38
if this were GetOrCreateExtensionList() which retu
Finnur
2013/12/12 20:25:12
Done.
| |
131 DCHECK(!initialized_); | |
132 | |
133 scoped_ptr<const ExtensionSet> extension_set( | |
134 service_->GenerateInstalledExtensionsSet()); | |
135 for (ExtensionSet::const_iterator it = extension_set->begin(); | |
136 it != extension_set->end(); ++it) { | |
137 std::string id = (*it)->id(); | |
138 if (!delegate_->ShouldIncludeExtension(id)) | |
139 continue; | |
140 extension_list_.push_back(id); | |
141 } | |
142 | |
143 delegate_->LogExtensionCount(extension_list_.size()); | |
144 initialized_ = true; | |
145 } | |
146 | |
147 } // namespace extensions | |
OLD | NEW |