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 has_notified_(false), | |
33 showing_bubble_(false) { | |
34 } | |
35 | |
36 ExtensionMessageBubbleController::~ExtensionMessageBubbleController() { | |
37 } | |
38 | |
39 bool ExtensionMessageBubbleController::HasExtensionList() { | |
not at google - send to devlin
2013/12/10 01:21:39
HasExtensionList is confusing given it's actually
Finnur
2013/12/11 23:12:18
Done.
| |
40 if (has_notified_) | |
41 return false; | |
42 | |
43 scoped_ptr<const ExtensionSet> extension_set( | |
44 service_->GenerateInstalledExtensionsSet()); | |
45 for (ExtensionSet::const_iterator it = extension_set->begin(); | |
46 it != extension_set->end(); ++it) { | |
47 std::string id = (*it)->id(); | |
48 if (!delegate_->ShouldIncludeExtension(id)) | |
49 continue; | |
50 extension_list_.push_back(id); | |
51 } | |
52 | |
53 delegate_->LogExtensionCount(extension_list_.size()); | |
54 | |
55 has_notified_ = true; | |
56 return !extension_list_.empty(); | |
not at google - send to devlin
2013/12/10 01:21:39
A lot of the behaviour in this class seems to rely
Finnur
2013/12/11 23:12:18
The class already has a GetExtensionList method, b
| |
57 } | |
58 | |
59 std::vector<string16> | |
60 ExtensionMessageBubbleController::GetExtensionList() const { | |
61 if (extension_list_.empty()) | |
62 return std::vector<string16>(); | |
63 | |
64 std::vector<string16> return_value; | |
65 for (ExtensionIdList::const_iterator it = extension_list_.begin(); | |
66 it != extension_list_.end(); ++it) { | |
67 const Extension* extension = service_->GetInstalledExtension(*it); | |
68 if (extension) { | |
69 return_value.push_back(UTF8ToUTF16(extension->name())); | |
70 } else { | |
71 return_value.push_back( | |
72 ASCIIToUTF16(std::string("(unknown name) ") + *it)); | |
73 // TODO(finnur): Add this as a string to the grd, for next milestone. | |
74 } | |
75 } | |
76 return return_value; | |
77 } | |
78 | |
79 void ExtensionMessageBubbleController::Show(ExtensionMessageBubble* bubble) { | |
80 // Wire up all the callbacks, to get notified what actions the user took. | |
81 base::Closure dismiss_button_callback = | |
82 base::Bind(&ExtensionMessageBubbleController::OnBubbleDismiss, | |
83 base::Unretained(this)); | |
84 base::Closure action_button_callback = | |
85 base::Bind(&ExtensionMessageBubbleController::OnBubbleAction, | |
86 base::Unretained(this)); | |
87 base::Closure link_callback = | |
88 base::Bind(&ExtensionMessageBubbleController::OnLinkClicked, | |
89 base::Unretained(this)); | |
90 bubble->OnActionButtonClicked(action_button_callback); | |
91 bubble->OnDismissButtonClicked(dismiss_button_callback); | |
92 bubble->OnLinkClicked(link_callback); | |
93 | |
94 showing_bubble_ = true; | |
95 bubble->Show(); | |
96 } | |
97 | |
98 void ExtensionMessageBubbleController::OnBubbleAction() { | |
99 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
100 user_action_ = ACTION_EXECUTE; | |
101 | |
102 delegate_->LogAction(ACTION_EXECUTE); | |
103 delegate_->PerformAction(extension_list_); | |
104 AcknowledgeExtensions(); | |
105 } | |
106 | |
107 void ExtensionMessageBubbleController::OnBubbleDismiss() { | |
108 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
109 user_action_ = ACTION_DISMISS; | |
110 | |
111 delegate_->LogAction(ACTION_DISMISS); | |
112 AcknowledgeExtensions(); | |
113 } | |
114 | |
115 void ExtensionMessageBubbleController::OnLinkClicked() { | |
116 DCHECK_EQ(ACTION_BOUNDARY, user_action_); | |
117 user_action_ = ACTION_LEARN_MORE; | |
118 | |
119 delegate_->LogAction(ACTION_LEARN_MORE); | |
120 Browser* browser = | |
121 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | |
122 if (browser) { | |
123 browser->OpenURL( | |
124 content::OpenURLParams(delegate_->GetLearnMoreUrl(), | |
125 content::Referrer(), | |
126 NEW_FOREGROUND_TAB, | |
127 content::PAGE_TRANSITION_LINK, | |
128 false)); | |
129 } | |
130 AcknowledgeExtensions(); | |
131 } | |
132 | |
133 void ExtensionMessageBubbleController::AcknowledgeExtensions() { | |
134 for (ExtensionIdList::const_iterator it = extension_list_.begin(); | |
135 it != extension_list_.end(); ++it) | |
136 delegate_->AcknowledgeExtension(*it, user_action_); | |
137 | |
138 showing_bubble_ = false; | |
139 } | |
140 | |
141 } // namespace extensions | |
OLD | NEW |