OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" | |
11 #include "chrome/browser/extensions/extension_action_manager.h" | |
10 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 15 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/views/frame/browser_view.h" | |
19 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | |
20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | |
16 #include "grit/locale_settings.h" | 21 #include "grit/locale_settings.h" |
17 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
18 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/views/controls/button/label_button.h" | 24 #include "ui/views/controls/button/label_button.h" |
20 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
21 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
22 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
28 #include "ui/views/view.h" | |
23 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
24 | 30 |
25 namespace { | 31 namespace { |
26 | 32 |
27 // Layout constants. | 33 // Layout constants. |
28 const int kExtensionListPadding = 10; | 34 const int kExtensionListPadding = 10; |
29 const int kInsetBottomRight = 13; | 35 const int kInsetBottomRight = 13; |
30 const int kInsetLeft = 14; | 36 const int kInsetLeft = 14; |
31 const int kInsetTop = 9; | 37 const int kInsetTop = 9; |
32 const int kHeadlineMessagePadding = 4; | 38 const int kHeadlineMessagePadding = 4; |
33 const int kHeadlineRowPadding = 10; | 39 const int kHeadlineRowPadding = 10; |
34 const int kMessageBubblePadding = 11; | 40 const int kMessageBubblePadding = 11; |
35 | 41 |
36 // How many extensions to show in the bubble (max). | 42 // How many extensions to show in the bubble (max). |
37 const size_t kMaxExtensionsToShow = 7; | 43 const size_t kMaxExtensionsToShow = 7; |
38 | 44 |
39 // How long to wait until showing the bubble (in seconds). | 45 // How long to wait until showing the bubble (in seconds). |
40 const int kBubbleAppearanceWaitTime = 5; | 46 const int kBubbleAppearanceWaitTime = 5; |
41 | 47 |
42 } // namespace | 48 } // namespace |
43 | 49 |
44 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
45 // SuspiciousExtensionBubbleView | 51 // ExtensionMessageBubbleView |
46 | 52 |
47 namespace extensions { | 53 namespace extensions { |
48 | 54 |
49 SuspiciousExtensionBubbleView::SuspiciousExtensionBubbleView( | 55 ExtensionMessageBubbleView::ExtensionMessageBubbleView( |
50 views::View* anchor_view, | 56 views::View* anchor_view, |
51 SuspiciousExtensionBubbleController* controller) | 57 ExtensionMessageBubbleController::Delegate* delegate) |
52 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 58 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
53 weak_factory_(this), | 59 weak_factory_(this), |
54 controller_(controller), | 60 delegate_(delegate), |
55 headline_(NULL), | 61 headline_(NULL), |
56 learn_more_(NULL), | 62 learn_more_(NULL), |
57 dismiss_button_(NULL), | 63 dismiss_button_(NULL), |
58 link_clicked_(false) { | 64 link_clicked_(false), |
65 action_taken_(false) { | |
59 DCHECK(anchor_view->GetWidget()); | 66 DCHECK(anchor_view->GetWidget()); |
60 set_close_on_deactivate(false); | 67 set_close_on_deactivate(false); |
61 set_move_with_anchor(true); | 68 set_move_with_anchor(true); |
62 set_close_on_esc(true); | 69 set_close_on_esc(true); |
63 | 70 |
64 // Compensate for built-in vertical padding in the anchor view's image. | 71 // Compensate for built-in vertical padding in the anchor view's image. |
65 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 72 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
66 } | 73 } |
67 | 74 |
68 // static | 75 // static |
69 void SuspiciousExtensionBubbleView::MaybeShow( | 76 void ExtensionMessageBubbleView::MaybeShow( |
not at google - send to devlin
2013/12/12 18:21:38
This MaybeShow code doesn't really belong here.
E
Finnur
2013/12/12 20:25:12
This logic doesn't belong in either place really,
not at google - send to devlin
2013/12/12 21:17:19
Only the toolbar view knows that the "suspicious b
Finnur
2013/12/13 21:29:48
I thought about that, but this gets messy as you a
| |
70 Browser* browser, | 77 Browser* browser, |
71 views::View* anchor_view) { | 78 views::View* anchor_view) { |
72 SuspiciousExtensionBubbleController* controller = | 79 // The list of suspicious extensions takes priority over the dev mode bubble, |
80 // since that needs to be shown as soon as we disable something. The dev mode | |
81 // bubble is not as time sensitive so we'll catch the dev mode extensions on | |
82 // the next startup. That way, we're not too spammy with the bubbles. | |
not at google - send to devlin
2013/12/12 18:21:38
it's not next startup, it's next time this method
Finnur
2013/12/12 20:25:12
Yeah, it is next startup/next window. Updated comm
| |
83 SuspiciousExtensionBubbleController* suspicious_extensions = | |
73 extensions::SuspiciousExtensionBubbleController::Get( | 84 extensions::SuspiciousExtensionBubbleController::Get( |
74 browser->profile()); | 85 browser->profile()); |
75 if (controller->HasSuspiciousExtensions()) { | 86 if (suspicious_extensions->ShouldShow()) { |
76 SuspiciousExtensionBubbleView* bubble_delegate = | 87 ExtensionMessageBubbleView* bubble_delegate = |
77 new SuspiciousExtensionBubbleView(anchor_view, controller); | 88 new ExtensionMessageBubbleView(anchor_view, suspicious_extensions); |
78 views::BubbleDelegateView::CreateBubble(bubble_delegate); | 89 views::BubbleDelegateView::CreateBubble(bubble_delegate); |
79 controller->Show(bubble_delegate); | 90 suspicious_extensions->Show(bubble_delegate); |
91 return; | |
92 } | |
93 | |
94 DevModeBubbleController* dev_mode_extensions = | |
95 extensions::DevModeBubbleController::Get( | |
96 browser->profile()); | |
97 if (dev_mode_extensions->ShouldShow()) { | |
98 // Find an extension browser action view to anchor against in the toolbar. | |
99 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | |
100 views::View* reference_view = NULL; | |
101 BrowserActionsContainer* container = | |
102 browser_view->GetToolbarView()->browser_actions(); | |
not at google - send to devlin
2013/12/12 18:21:38
see comment above; you could at least pass the too
Finnur
2013/12/12 20:25:12
Added toolbar_view param.
| |
103 if (container->animating()) | |
104 return; | |
105 | |
106 ExtensionService* service = extensions::ExtensionSystem::Get( | |
107 browser->profile())->extension_service(); | |
108 extensions::ExtensionActionManager* extension_action_manager = | |
109 extensions::ExtensionActionManager::Get(browser->profile()); | |
110 | |
111 const ExtensionIdList extension_list = | |
112 dev_mode_extensions->extension_id_list(); | |
not at google - send to devlin
2013/12/12 18:21:38
can you make dev_mode_extensions return an Extensi
Finnur
2013/12/12 20:25:12
Same argument applies here as with ShouldShowExten
not at google - send to devlin
2013/12/12 21:17:19
Makes sense. You could include the Extension::Stat
Finnur
2013/12/13 21:29:48
GetExtensionList returns names, not IDs. Changed i
| |
113 for (size_t i = 0; i < extension_list.size(); ++i) { | |
114 const Extension* extension = | |
115 service->GetExtensionById(extension_list[i], false); | |
116 if (!extension) | |
117 continue; | |
118 reference_view = container->GetBrowserActionView( | |
119 extension_action_manager->GetBrowserAction(*extension)); | |
120 if (reference_view && reference_view->visible()) | |
121 break; // Found a good candidate. | |
122 } | |
123 if (reference_view) { | |
124 // If we have a view, it means we found a browser action and we want to | |
125 // point to the chevron, not the hotdog menu. | |
126 if (!reference_view->visible()) | |
127 reference_view = container->chevron(); // It's hidden, use the chevron. | |
128 } | |
129 if (reference_view && reference_view->visible()) | |
130 anchor_view = reference_view; // Catch-all is the hotdog menu. | |
131 | |
132 // Show the bubble. | |
133 ExtensionMessageBubbleView* bubble_delegate = | |
134 new ExtensionMessageBubbleView(anchor_view, dev_mode_extensions); | |
135 views::BubbleDelegateView::CreateBubble(bubble_delegate); | |
136 dev_mode_extensions->Show(bubble_delegate); | |
80 } | 137 } |
81 } | 138 } |
82 | 139 |
83 void SuspiciousExtensionBubbleView::OnButtonClicked( | 140 void ExtensionMessageBubbleView::OnActionButtonClicked( |
84 const base::Closure& callback) { | 141 const base::Closure& callback) { |
85 button_callback_ = callback; | 142 action_callback_ = callback; |
86 } | 143 } |
87 | 144 |
88 void SuspiciousExtensionBubbleView::OnLinkClicked( | 145 void ExtensionMessageBubbleView::OnDismissButtonClicked( |
146 const base::Closure& callback) { | |
147 dismiss_callback_ = callback; | |
148 } | |
149 | |
150 void ExtensionMessageBubbleView::OnLinkClicked( | |
89 const base::Closure& callback) { | 151 const base::Closure& callback) { |
90 link_callback_ = callback; | 152 link_callback_ = callback; |
91 } | 153 } |
92 | 154 |
93 void SuspiciousExtensionBubbleView::Show() { | 155 void ExtensionMessageBubbleView::Show() { |
94 // Not showing the bubble right away (during startup) has a few benefits: | 156 // Not showing the bubble right away (during startup) has a few benefits: |
95 // We don't have to worry about focus being lost due to the Omnibox (or to | 157 // We don't have to worry about focus being lost due to the Omnibox (or to |
96 // other things that want focus at startup). This allows Esc to work to close | 158 // other things that want focus at startup). This allows Esc to work to close |
97 // the bubble and also solves the keyboard accessibility problem that comes | 159 // the bubble and also solves the keyboard accessibility problem that comes |
98 // with focus being lost (we don't have a good generic mechanism of injecting | 160 // with focus being lost (we don't have a good generic mechanism of injecting |
99 // bubbles into the focus cycle). Another benefit of delaying the show is | 161 // bubbles into the focus cycle). Another benefit of delaying the show is |
100 // that fade-in works (the fade-in isn't apparent if the the bubble appears at | 162 // that fade-in works (the fade-in isn't apparent if the the bubble appears at |
101 // startup). | 163 // startup). |
102 base::MessageLoop::current()->PostDelayedTask( | 164 base::MessageLoop::current()->PostDelayedTask( |
103 FROM_HERE, | 165 FROM_HERE, |
104 base::Bind(&SuspiciousExtensionBubbleView::ShowBubble, | 166 base::Bind(&ExtensionMessageBubbleView::ShowBubble, |
105 weak_factory_.GetWeakPtr()), | 167 weak_factory_.GetWeakPtr()), |
106 base::TimeDelta::FromSeconds(kBubbleAppearanceWaitTime)); | 168 base::TimeDelta::FromSeconds(kBubbleAppearanceWaitTime)); |
107 } | 169 } |
108 | 170 |
109 void SuspiciousExtensionBubbleView::OnWidgetDestroying(views::Widget* widget) { | 171 void ExtensionMessageBubbleView::OnWidgetDestroying(views::Widget* widget) { |
110 // To catch Esc, we monitor destroy message. Unless the link has been clicked, | 172 // To catch Esc, we monitor destroy message. Unless the link has been clicked, |
111 // we assume Dismiss was the action taken. | 173 // we assume Dismiss was the action taken. |
112 if (!link_clicked_) | 174 if (!link_clicked_ && !action_taken_) |
113 button_callback_.Run(); | 175 dismiss_callback_.Run(); |
114 } | 176 } |
115 | 177 |
116 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
117 // SuspiciousExtensionBubbleView - private. | 179 // ExtensionMessageBubbleView - private. |
118 | 180 |
119 SuspiciousExtensionBubbleView::~SuspiciousExtensionBubbleView() { | 181 ExtensionMessageBubbleView::~ExtensionMessageBubbleView() { |
120 } | 182 } |
121 | 183 |
122 void SuspiciousExtensionBubbleView::ShowBubble() { | 184 void ExtensionMessageBubbleView::ShowBubble() { |
123 StartFade(true); | 185 StartFade(true); |
124 } | 186 } |
125 | 187 |
126 void SuspiciousExtensionBubbleView::Init() { | 188 void ExtensionMessageBubbleView::Init() { |
127 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 189 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
128 | 190 |
129 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 191 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
130 layout->SetInsets(kInsetTop, kInsetLeft, | 192 layout->SetInsets(kInsetTop, kInsetLeft, |
131 kInsetBottomRight, kInsetBottomRight); | 193 kInsetBottomRight, kInsetBottomRight); |
132 SetLayoutManager(layout); | 194 SetLayoutManager(layout); |
133 | 195 |
134 const int headline_column_set_id = 0; | 196 const int headline_column_set_id = 0; |
135 views::ColumnSet* top_columns = layout->AddColumnSet(headline_column_set_id); | 197 views::ColumnSet* top_columns = layout->AddColumnSet(headline_column_set_id); |
136 top_columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 198 top_columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
137 0, views::GridLayout::USE_PREF, 0, 0); | 199 0, views::GridLayout::USE_PREF, 0, 0); |
138 top_columns->AddPaddingColumn(1, 0); | 200 top_columns->AddPaddingColumn(1, 0); |
139 layout->StartRow(0, headline_column_set_id); | 201 layout->StartRow(0, headline_column_set_id); |
140 | 202 |
141 headline_ = new views::Label(); | 203 headline_ = new views::Label(); |
142 headline_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 204 headline_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
143 headline_->SetText(controller_->GetTitle()); | 205 headline_->SetText(delegate_->GetTitle()); |
144 layout->AddView(headline_); | 206 layout->AddView(headline_); |
145 | 207 |
146 layout->AddPaddingRow(0, kHeadlineRowPadding); | 208 layout->AddPaddingRow(0, kHeadlineRowPadding); |
147 | 209 |
148 const int text_column_set_id = 1; | 210 const int text_column_set_id = 1; |
149 views::ColumnSet* upper_columns = layout->AddColumnSet(text_column_set_id); | 211 views::ColumnSet* upper_columns = layout->AddColumnSet(text_column_set_id); |
150 upper_columns->AddColumn( | 212 upper_columns->AddColumn( |
151 views::GridLayout::LEADING, views::GridLayout::LEADING, | 213 views::GridLayout::LEADING, views::GridLayout::LEADING, |
152 0, views::GridLayout::USE_PREF, 0, 0); | 214 0, views::GridLayout::USE_PREF, 0, 0); |
153 layout->StartRow(0, text_column_set_id); | 215 layout->StartRow(0, text_column_set_id); |
154 | 216 |
155 views::Label* message = new views::Label(); | 217 views::Label* message = new views::Label(); |
156 message->SetMultiLine(true); | 218 message->SetMultiLine(true); |
157 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 219 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
158 message->SetText(controller_->GetMessageBody()); | 220 message->SetText(delegate_->GetMessageBody()); |
159 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( | 221 message->SizeToFit(views::Widget::GetLocalizedContentsWidth( |
160 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS)); | 222 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS)); |
161 layout->AddView(message); | 223 layout->AddView(message); |
162 | 224 |
163 const int extension_list_column_set_id = 2; | 225 if (delegate_->ShouldShowExtensionList()) { |
164 views::ColumnSet* middle_columns = | 226 const int extension_list_column_set_id = 2; |
165 layout->AddColumnSet(extension_list_column_set_id); | 227 views::ColumnSet* middle_columns = |
166 middle_columns->AddPaddingColumn(0, kExtensionListPadding); | 228 layout->AddColumnSet(extension_list_column_set_id); |
167 middle_columns->AddColumn( | 229 middle_columns->AddPaddingColumn(0, kExtensionListPadding); |
168 views::GridLayout::LEADING, views::GridLayout::CENTER, | 230 middle_columns->AddColumn( |
169 0, views::GridLayout::USE_PREF, 0, 0); | 231 views::GridLayout::LEADING, views::GridLayout::CENTER, |
232 0, views::GridLayout::USE_PREF, 0, 0); | |
170 | 233 |
171 layout->StartRowWithPadding(0, extension_list_column_set_id, | 234 layout->StartRowWithPadding(0, extension_list_column_set_id, |
172 0, kHeadlineMessagePadding); | 235 0, kHeadlineMessagePadding); |
173 views::Label* extensions = new views::Label(); | 236 views::Label* extensions = new views::Label(); |
174 extensions->SetMultiLine(true); | 237 extensions->SetMultiLine(true); |
175 extensions->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 238 extensions->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
176 | 239 |
177 std::vector<string16> extension_list; | 240 std::vector<string16> extension_list; |
178 char16 bullet_point = 0x2022; | 241 char16 bullet_point = 0x2022; |
179 | 242 |
180 std::vector<string16> suspicious = controller_->GetSuspiciousExtensionNames(); | 243 std::vector<string16> suspicious = delegate_->GetExtensions(); |
not at google - send to devlin
2013/12/12 18:21:38
use controller->GetExtensionList() here?
oh, you
| |
181 size_t i = 0; | 244 size_t i = 0; |
182 for (; i < suspicious.size() && i < kMaxExtensionsToShow; ++i) { | 245 for (; i < suspicious.size() && i < kMaxExtensionsToShow; ++i) { |
183 // Add each extension with bullet point. | 246 // Add each extension with bullet point. |
184 extension_list.push_back(bullet_point + ASCIIToUTF16(" ") + suspicious[i]); | 247 extension_list.push_back( |
248 bullet_point + ASCIIToUTF16(" ") + suspicious[i]); | |
249 } | |
250 | |
251 if (i > kMaxExtensionsToShow) { | |
252 string16 difference = base::IntToString16(i - kMaxExtensionsToShow); | |
253 extension_list.push_back(bullet_point + ASCIIToUTF16(" ") + | |
254 delegate_->GetOverflowText(difference)); | |
255 } | |
256 | |
257 extensions->SetText(JoinString(extension_list, ASCIIToUTF16("\n"))); | |
258 extensions->SizeToFit(views::Widget::GetLocalizedContentsWidth( | |
259 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS)); | |
260 layout->AddView(extensions); | |
185 } | 261 } |
186 | 262 |
187 if (i > kMaxExtensionsToShow) { | 263 string16 action_button = delegate_->GetActionButtonLabel(); |
188 base::string16 difference = base::IntToString16(i - kMaxExtensionsToShow); | |
189 extension_list.push_back(bullet_point + ASCIIToUTF16(" ") + | |
190 controller_->GetOverflowText(difference)); | |
191 } | |
192 | |
193 extensions->SetText(JoinString(extension_list, ASCIIToUTF16("\n"))); | |
194 extensions->SizeToFit(views::Widget::GetLocalizedContentsWidth( | |
195 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS)); | |
196 layout->AddView(extensions); | |
197 | 264 |
198 const int action_row_column_set_id = 3; | 265 const int action_row_column_set_id = 3; |
199 views::ColumnSet* bottom_columns = | 266 views::ColumnSet* bottom_columns = |
200 layout->AddColumnSet(action_row_column_set_id); | 267 layout->AddColumnSet(action_row_column_set_id); |
201 bottom_columns->AddColumn(views::GridLayout::LEADING, | 268 bottom_columns->AddColumn(views::GridLayout::LEADING, |
202 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 269 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); |
203 bottom_columns->AddPaddingColumn(1, 0); | 270 bottom_columns->AddPaddingColumn(1, 0); |
204 bottom_columns->AddColumn(views::GridLayout::TRAILING, | 271 bottom_columns->AddColumn(views::GridLayout::TRAILING, |
205 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 272 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); |
273 if (!action_button.empty()) { | |
274 bottom_columns->AddColumn(views::GridLayout::TRAILING, | |
275 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | |
276 } | |
206 layout->StartRowWithPadding(0, action_row_column_set_id, | 277 layout->StartRowWithPadding(0, action_row_column_set_id, |
207 0, kMessageBubblePadding); | 278 0, kMessageBubblePadding); |
208 | 279 |
209 learn_more_ = new views::Link(controller_->GetLearnMoreLabel()); | 280 learn_more_ = new views::Link(delegate_->GetLearnMoreLabel()); |
210 learn_more_->set_listener(this); | 281 learn_more_->set_listener(this); |
211 layout->AddView(learn_more_); | 282 layout->AddView(learn_more_); |
212 | 283 |
284 if (!action_button.empty()) { | |
285 action_button_ = new views::LabelButton(this, action_button.c_str()); | |
286 action_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | |
287 layout->AddView(action_button_); | |
288 } | |
289 | |
213 dismiss_button_ = new views::LabelButton(this, | 290 dismiss_button_ = new views::LabelButton(this, |
214 controller_->GetDismissButtonLabel()); | 291 delegate_->GetDismissButtonLabel()); |
215 dismiss_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 292 dismiss_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
216 layout->AddView(dismiss_button_); | 293 layout->AddView(dismiss_button_); |
217 } | 294 } |
218 | 295 |
219 void SuspiciousExtensionBubbleView::ButtonPressed(views::Button* sender, | 296 void ExtensionMessageBubbleView::ButtonPressed(views::Button* sender, |
220 const ui::Event& event) { | 297 const ui::Event& event) { |
221 DCHECK_EQ(dismiss_button_, sender); | 298 if (sender == action_button_) { |
299 action_taken_ = true; | |
300 action_callback_.Run(); | |
301 } else { | |
302 DCHECK_EQ(dismiss_button_, sender); | |
303 } | |
222 GetWidget()->Close(); | 304 GetWidget()->Close(); |
223 } | 305 } |
224 | 306 |
225 void SuspiciousExtensionBubbleView::LinkClicked(views::Link* source, | 307 void ExtensionMessageBubbleView::LinkClicked(views::Link* source, |
226 int event_flags) { | 308 int event_flags) { |
227 DCHECK_EQ(learn_more_, source); | 309 DCHECK_EQ(learn_more_, source); |
228 link_clicked_ = true; | 310 link_clicked_ = true; |
229 link_callback_.Run(); | 311 link_callback_.Run(); |
230 GetWidget()->Close(); | 312 GetWidget()->Close(); |
231 } | 313 } |
232 | 314 |
233 void SuspiciousExtensionBubbleView::GetAccessibleState( | 315 void ExtensionMessageBubbleView::GetAccessibleState( |
234 ui::AccessibleViewState* state) { | 316 ui::AccessibleViewState* state) { |
235 state->role = ui::AccessibilityTypes::ROLE_ALERT; | 317 state->role = ui::AccessibilityTypes::ROLE_ALERT; |
236 } | 318 } |
237 | 319 |
238 void SuspiciousExtensionBubbleView::ViewHierarchyChanged( | 320 void ExtensionMessageBubbleView::ViewHierarchyChanged( |
239 const ViewHierarchyChangedDetails& details) { | 321 const ViewHierarchyChangedDetails& details) { |
240 if (details.is_add && details.child == this) | 322 if (details.is_add && details.child == this) |
241 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); | 323 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); |
242 } | 324 } |
243 | 325 |
244 } // namespace extensions | 326 } // namespace extensions |
OLD | NEW |