Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 8757007: Implement additional UI changes for dangerous download warnings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add DCHECKs Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/download/download_item_view.h" 5 #include "chrome/browser/ui/views/download/download_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 DownloadItemView::DownloadItemView(DownloadItem* download, 85 DownloadItemView::DownloadItemView(DownloadItem* download,
86 DownloadShelfView* parent, 86 DownloadShelfView* parent,
87 BaseDownloadItemModel* model) 87 BaseDownloadItemModel* model)
88 : warning_icon_(NULL), 88 : warning_icon_(NULL),
89 download_(download), 89 download_(download),
90 parent_(parent), 90 parent_(parent),
91 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), 91 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)),
92 body_state_(NORMAL), 92 body_state_(NORMAL),
93 drop_down_state_(NORMAL), 93 drop_down_state_(NORMAL),
94 mode_(NORMAL_MODE),
94 progress_angle_(download_util::kStartAngleDegrees), 95 progress_angle_(download_util::kStartAngleDegrees),
95 drop_down_pressed_(false), 96 drop_down_pressed_(false),
96 dragging_(false), 97 dragging_(false),
97 starting_drag_(false), 98 starting_drag_(false),
98 model_(model), 99 model_(model),
99 save_button_(NULL), 100 save_button_(NULL),
100 discard_button_(NULL), 101 discard_button_(NULL),
101 dangerous_download_label_(NULL), 102 dangerous_download_label_(NULL),
102 dangerous_download_label_sized_(false), 103 dangerous_download_label_sized_(false),
103 disabled_while_opening_(false), 104 disabled_while_opening_(false),
104 creation_time_(base::Time::Now()), 105 creation_time_(base::Time::Now()),
105 ALLOW_THIS_IN_INITIALIZER_LIST(reenable_method_factory_(this)) { 106 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
106 DCHECK(download_); 107 DCHECK(download_);
107 download_->AddObserver(this); 108 download_->AddObserver(this);
108 109
109 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 110 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
110 111
111 BodyImageSet normal_body_image_set = { 112 BodyImageSet normal_body_image_set = {
112 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), 113 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP),
113 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), 114 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE),
114 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), 115 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM),
115 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), 116 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), 175 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM),
175 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), 176 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP),
176 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE), 177 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE),
177 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM), 178 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM),
178 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), 179 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD),
179 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), 180 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD),
180 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD) 181 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD)
181 }; 182 };
182 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; 183 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set;
183 184
185 BodyImageSet malicious_mode_body_image_set = {
186 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP),
187 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE),
188 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM),
189 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP),
190 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE),
191 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM),
192 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP),
193 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE),
194 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM)
195 };
196 malicious_mode_body_image_set_ = malicious_mode_body_image_set;
dmazzoni 2011/12/01 19:49:22 Can you just say malicious_mode_body_image_set_ =
asanka 2011/12/02 00:05:04 Done. I think you meant normal_body_image_set. C
197
184 LoadIcon(); 198 LoadIcon();
185 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); 199 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName();
186 200
187 font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); 201 font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
188 box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() + 202 box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() +
189 kVerticalTextPadding + font_.GetHeight(), 203 kVerticalTextPadding + font_.GetHeight(),
190 2 * kVerticalPadding + 204 2 * kVerticalPadding +
191 normal_body_image_set_.top_left->height() + 205 normal_body_image_set_.top_left->height() +
192 normal_body_image_set_.bottom_left->height()); 206 normal_body_image_set_.bottom_left->height());
193 207
194 if (download_util::kSmallProgressIconSize > box_height_) 208 if (download_util::kSmallProgressIconSize > box_height_)
195 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; 209 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2;
196 else 210 else
197 box_y_ = kVerticalPadding; 211 box_y_ = kVerticalPadding;
198 212
199 gfx::Size size = GetPreferredSize();
200 if (base::i18n::IsRTL()) {
201 // Drop down button is glued to the left of the download shelf.
202 drop_down_x_left_ = 0;
203 drop_down_x_right_ = normal_drop_down_image_set_.top->width();
204 } else {
205 // Drop down button is glued to the right of the download shelf.
206 drop_down_x_left_ =
207 size.width() - normal_drop_down_image_set_.top->width();
208 drop_down_x_right_ = size.width();
209 }
210
211 body_hover_animation_.reset(new ui::SlideAnimation(this)); 213 body_hover_animation_.reset(new ui::SlideAnimation(this));
212 drop_hover_animation_.reset(new ui::SlideAnimation(this)); 214 drop_hover_animation_.reset(new ui::SlideAnimation(this));
213 215
216 UpdateDropDownButtonPosition();
217
214 if (download->GetSafetyState() == DownloadItem::DANGEROUS) 218 if (download->GetSafetyState() == DownloadItem::DANGEROUS)
215 EnterDangerousMode(); 219 ShowWarningDialog();
216 220
217 UpdateAccessibleName(); 221 UpdateAccessibleName();
218 set_accessibility_focusable(true); 222 set_accessibility_focusable(true);
219 223
220 // Set up our animation. 224 // Set up our animation.
221 StartDownloadProgress(); 225 StartDownloadProgress();
222 } 226 }
223 227
224 DownloadItemView::~DownloadItemView() { 228 DownloadItemView::~DownloadItemView() {
225 if (context_menu_.get())
226 context_menu_->Stop();
dmazzoni 2011/12/01 19:49:22 Why are you deleting this? Was it wrong or is it n
asanka 2011/12/02 00:05:04 It was used as a signal that DownloadItemView (and
227 icon_consumer_.CancelAllRequests(); 229 icon_consumer_.CancelAllRequests();
228 StopDownloadProgress(); 230 StopDownloadProgress();
229 download_->RemoveObserver(this); 231 download_->RemoveObserver(this);
230 } 232 }
231 233
232 // Progress animation handlers. 234 // Progress animation handlers.
233 235
234 void DownloadItemView::UpdateDownloadProgress() { 236 void DownloadItemView::UpdateDownloadProgress() {
235 progress_angle_ = (progress_angle_ + 237 progress_angle_ = (progress_angle_ +
236 download_util::kUnknownIncrementDegrees) % 238 download_util::kUnknownIncrementDegrees) %
(...skipping 19 matching lines...) Expand all
256 parent()->SchedulePaint(); 258 parent()->SchedulePaint();
257 } 259 }
258 260
259 // DownloadObserver interface. 261 // DownloadObserver interface.
260 262
261 // Update the progress graphic on the icon and our text status label 263 // Update the progress graphic on the icon and our text status label
262 // to reflect our current bytes downloaded, time remaining. 264 // to reflect our current bytes downloaded, time remaining.
263 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { 265 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) {
264 DCHECK(download == download_); 266 DCHECK(download == download_);
265 267
266 if (body_state_ == DANGEROUS && 268 if (IsShowingWarningDialog() &&
267 download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { 269 download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) {
268 // We have been approved. 270 // We have been approved.
269 ClearDangerousMode(); 271 ClearWarningDialog();
270 } else if (body_state_ != DANGEROUS && 272 } else if (!IsShowingWarningDialog() &&
271 download->GetSafetyState() == DownloadItem::DANGEROUS) { 273 download->GetSafetyState() == DownloadItem::DANGEROUS) {
272 EnterDangerousMode(); 274 ShowWarningDialog();
273 // Force the shelf to layout again as our size has changed. 275 // Force the shelf to layout again as our size has changed.
274 parent_->Layout(); 276 parent_->Layout();
275 SchedulePaint(); 277 SchedulePaint();
276 } else { 278 } else {
277 string16 status_text = model_->GetStatusText(); 279 string16 status_text = model_->GetStatusText();
278 switch (download_->GetState()) { 280 switch (download_->GetState()) {
279 case DownloadItem::IN_PROGRESS: 281 case DownloadItem::IN_PROGRESS:
280 download_->IsPaused() ? 282 download_->IsPaused() ?
281 StopDownloadProgress() : StartDownloadProgress(); 283 StopDownloadProgress() : StartDownloadProgress();
282 LoadIconIfItemPathChanged(); 284 LoadIconIfItemPathChanged();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // for painting. 324 // for painting.
323 parent()->SchedulePaint(); 325 parent()->SchedulePaint();
324 } 326 }
325 327
326 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { 328 void DownloadItemView::OnDownloadOpened(DownloadItem* download) {
327 disabled_while_opening_ = true; 329 disabled_while_opening_ = true;
328 SetEnabled(false); 330 SetEnabled(false);
329 MessageLoop::current()->PostDelayedTask( 331 MessageLoop::current()->PostDelayedTask(
330 FROM_HERE, 332 FROM_HERE,
331 base::Bind(&DownloadItemView::Reenable, 333 base::Bind(&DownloadItemView::Reenable,
332 reenable_method_factory_.GetWeakPtr()), 334 weak_ptr_factory_.GetWeakPtr()),
333 kDisabledOnOpenDuration); 335 kDisabledOnOpenDuration);
334 336
335 // Notify our parent. 337 // Notify our parent.
336 parent_->OpenedDownload(this); 338 parent_->OpenedDownload(this);
337 } 339 }
338 340
339 // View overrides 341 // View overrides
340 342
341 // In dangerous mode we have to layout our buttons. 343 // In dangerous mode we have to layout our buttons.
342 void DownloadItemView::Layout() { 344 void DownloadItemView::Layout() {
343 if (IsDangerousMode()) { 345 if (IsShowingWarningDialog()) {
346 BodyImageSet* body_image_set =
347 (mode_ == DANGEROUS_MODE) ? &dangerous_mode_body_image_set_ :
348 &malicious_mode_body_image_set_;
344 dangerous_download_label_->SetEnabledColor( 349 dangerous_download_label_->SetEnabledColor(
345 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); 350 GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT));
346 351
347 int x = kLeftPadding + dangerous_mode_body_image_set_.top_left->width() + 352 int x = kLeftPadding + body_image_set->top_left->width() +
348 warning_icon_->width() + kLabelPadding; 353 warning_icon_->width() + kLabelPadding;
349 int y = (height() - dangerous_download_label_->height()) / 2; 354 int y = (height() - dangerous_download_label_->height()) / 2;
350 dangerous_download_label_->SetBounds(x, y, 355 dangerous_download_label_->SetBounds(x, y,
351 dangerous_download_label_->width(), 356 dangerous_download_label_->width(),
352 dangerous_download_label_->height()); 357 dangerous_download_label_->height());
353 gfx::Size button_size = GetButtonSize(); 358 gfx::Size button_size = GetButtonSize();
354 x += dangerous_download_label_->width() + kLabelPadding; 359 x += dangerous_download_label_->width() + kLabelPadding;
355 y = (height() - button_size.height()) / 2; 360 y = (height() - button_size.height()) / 2;
356 save_button_->SetBounds(x, y, button_size.width(), button_size.height()); 361 if (save_button_) {
357 x += button_size.width() + kButtonPadding; 362 save_button_->SetBounds(x, y, button_size.width(), button_size.height());
363 x += button_size.width() + kButtonPadding;
364 }
358 discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); 365 discard_button_->SetBounds(x, y, button_size.width(), button_size.height());
359 } 366 }
360 } 367 }
361 368
362 gfx::Size DownloadItemView::GetPreferredSize() { 369 gfx::Size DownloadItemView::GetPreferredSize() {
363 int width, height; 370 int width, height;
364 371
365 // First, we set the height to the height of two rows or text plus margins. 372 // First, we set the height to the height of two rows or text plus margins.
366 height = 2 * kVerticalPadding + 2 * font_.GetHeight() + kVerticalTextPadding; 373 height = 2 * kVerticalPadding + 2 * font_.GetHeight() + kVerticalTextPadding;
367 // Then we increase the size if the progress icon doesn't fit. 374 // Then we increase the size if the progress icon doesn't fit.
368 height = std::max<int>(height, download_util::kSmallProgressIconSize); 375 height = std::max<int>(height, download_util::kSmallProgressIconSize);
369 376
370 if (IsDangerousMode()) { 377 if (IsShowingWarningDialog()) {
371 width = kLeftPadding + dangerous_mode_body_image_set_.top_left->width(); 378 BodyImageSet* body_image_set =
379 (mode_ == DANGEROUS_MODE) ? &dangerous_mode_body_image_set_ :
380 &malicious_mode_body_image_set_;
381 width = kLeftPadding + body_image_set->top_left->width();
372 width += warning_icon_->width() + kLabelPadding; 382 width += warning_icon_->width() + kLabelPadding;
373 width += dangerous_download_label_->width() + kLabelPadding; 383 width += dangerous_download_label_->width() + kLabelPadding;
374 gfx::Size button_size = GetButtonSize(); 384 gfx::Size button_size = GetButtonSize();
375 // Make sure the button fits. 385 // Make sure the button fits.
376 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); 386 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height());
377 // Then we make sure the warning icon fits. 387 // Then we make sure the warning icon fits.
378 height = std::max<int>(height, 2 * kVerticalPadding + 388 height = std::max<int>(height, 2 * kVerticalPadding +
379 warning_icon_->height()); 389 warning_icon_->height());
380 width += button_size.width() * 2 + kButtonPadding; 390 if (mode_ == DANGEROUS_MODE)
dmazzoni 2011/12/01 19:49:22 How about making this based on whether save_button
asanka 2011/12/02 00:05:04 Done.
381 width += dangerous_mode_body_image_set_.top_right->width(); 391 width += button_size.width() + kButtonPadding;
392 width += button_size.width();
393 width += body_image_set->top_right->width();
394 if (mode_ == MALICIOUS_MODE)
395 width += normal_drop_down_image_set_.top->width();
382 } else { 396 } else {
383 width = kLeftPadding + normal_body_image_set_.top_left->width(); 397 width = kLeftPadding + normal_body_image_set_.top_left->width();
384 width += download_util::kSmallProgressIconSize; 398 width += download_util::kSmallProgressIconSize;
385 width += kTextWidth; 399 width += kTextWidth;
386 width += normal_body_image_set_.top_right->width(); 400 width += normal_body_image_set_.top_right->width();
387 width += normal_drop_down_image_set_.top->width(); 401 width += normal_drop_down_image_set_.top->width();
388 } 402 }
389 return gfx::Size(width, height); 403 return gfx::Size(width, height);
390 } 404 }
391 405
392 // Handle a mouse click and open the context menu if the mouse is 406 // Handle a mouse click and open the context menu if the mouse is
393 // over the drop-down region. 407 // over the drop-down region.
394 bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) { 408 bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) {
395 // Mouse should not activate us in dangerous mode. 409 // Mouse should not activate us in dangerous mode.
396 if (IsDangerousMode()) 410 if (mode_ == DANGEROUS_MODE)
397 return true; 411 return true;
398 412
399 // Stop any completion animation. 413 // Stop any completion animation.
400 if (complete_animation_.get() && complete_animation_->is_animating()) 414 if (complete_animation_.get() && complete_animation_->is_animating())
401 complete_animation_->End(); 415 complete_animation_->End();
402 416
403 if (event.IsOnlyLeftMouseButton()) { 417 if (event.IsOnlyLeftMouseButton()) {
404 if (InDropDownButtonXCoordinateRange(event.x())) { 418 if (InDropDownButtonXCoordinateRange(event.x())) {
405 drop_down_pressed_ = true; 419 drop_down_pressed_ = true;
406 SetState(NORMAL, PUSHED); 420 SetState(NORMAL, PUSHED);
407 // We are setting is_mouse_gesture to false when calling ShowContextMenu 421 // We are setting is_mouse_gesture to false when calling ShowContextMenu
408 // so that the positioning of the context menu will be similar to a 422 // so that the positioning of the context menu will be similar to a
409 // keyboard invocation. I.e. we want the menu to always be positioned 423 // keyboard invocation. I.e. we want the menu to always be positioned
410 // next to the drop down button instead of the next to the pointer. 424 // next to the drop down button instead of the next to the pointer.
411 ShowContextMenu(event.location(), false); 425 ShowContextMenu(event.location(), false);
412 } else { 426 } else if (!IsShowingWarningDialog()) {
413 SetState(PUSHED, NORMAL); 427 SetState(PUSHED, NORMAL);
414 } 428 }
415 } 429 }
416 return true; 430 return true;
417 } 431 }
418 432
419 // Handle drag (file copy) operations. 433 // Handle drag (file copy) operations.
420 bool DownloadItemView::OnMouseDragged(const views::MouseEvent& event) { 434 bool DownloadItemView::OnMouseDragged(const views::MouseEvent& event) {
421 // Mouse should not activate us in dangerous mode. 435 // Mouse should not activate us in dangerous mode.
422 if (IsDangerousMode()) 436 if (IsShowingWarningDialog())
423 return true; 437 return true;
424 438
425 if (!starting_drag_) { 439 if (!starting_drag_) {
426 starting_drag_ = true; 440 starting_drag_ = true;
427 drag_start_point_ = event.location(); 441 drag_start_point_ = event.location();
428 } 442 }
429 if (dragging_) { 443 if (dragging_) {
430 if (download_->IsComplete()) { 444 if (download_->IsComplete()) {
431 IconManager* im = g_browser_process->icon_manager(); 445 IconManager* im = g_browser_process->icon_manager();
432 gfx::Image* icon = im->LookupIcon(download_->GetUserVerifiedFilePath(), 446 gfx::Image* icon = im->LookupIcon(download_->GetUserVerifiedFilePath(),
433 IconLoader::SMALL); 447 IconLoader::SMALL);
434 if (icon) { 448 if (icon) {
435 views::Widget* widget = GetWidget(); 449 views::Widget* widget = GetWidget();
436 download_util::DragDownload(download_, icon, 450 download_util::DragDownload(download_, icon,
437 widget ? widget->GetNativeView() : NULL); 451 widget ? widget->GetNativeView() : NULL);
438 } 452 }
439 } 453 }
440 } else if (ExceededDragThreshold( 454 } else if (ExceededDragThreshold(
441 event.location().x() - drag_start_point_.x(), 455 event.location().x() - drag_start_point_.x(),
442 event.location().y() - drag_start_point_.y())) { 456 event.location().y() - drag_start_point_.y())) {
443 dragging_ = true; 457 dragging_ = true;
444 } 458 }
445 return true; 459 return true;
446 } 460 }
447 461
448 void DownloadItemView::OnMouseReleased(const views::MouseEvent& event) { 462 void DownloadItemView::OnMouseReleased(const views::MouseEvent& event) {
449 // Mouse should not activate us in dangerous mode. 463 // Mouse should not activate us in dangerous mode.
450 if (IsDangerousMode()) 464 if (mode_ == DANGEROUS_MODE)
451 return; 465 return;
452 466
453 if (event.IsOnlyLeftMouseButton() && 467 if (event.IsOnlyLeftMouseButton() &&
454 !InDropDownButtonXCoordinateRange(event.x())) { 468 !InDropDownButtonXCoordinateRange(event.x()) &&
469 !IsShowingWarningDialog()) {
455 OpenDownload(); 470 OpenDownload();
456 } 471 }
457 472
458 SetState(NORMAL, NORMAL); 473 SetState(NORMAL, NORMAL);
459 } 474 }
460 475
461 void DownloadItemView::OnMouseCaptureLost() { 476 void DownloadItemView::OnMouseCaptureLost() {
462 // Mouse should not activate us in dangerous mode. 477 // Mouse should not activate us in dangerous mode.
463 if (IsDangerousMode()) 478 if (mode_ == DANGEROUS_MODE)
464 return; 479 return;
465 480
466 if (dragging_) { 481 if (dragging_) {
467 // Starting a drag results in a MouseCaptureLost. 482 // Starting a drag results in a MouseCaptureLost.
468 dragging_ = false; 483 dragging_ = false;
469 starting_drag_ = false; 484 starting_drag_ = false;
470 } else { 485 } else {
471 SetState(NORMAL, NORMAL); 486 SetState(NORMAL, NORMAL);
472 } 487 }
473 } 488 }
474 489
475 void DownloadItemView::OnMouseMoved(const views::MouseEvent& event) { 490 void DownloadItemView::OnMouseMoved(const views::MouseEvent& event) {
476 // Mouse should not activate us in dangerous mode. 491 // Mouse should not activate us in dangerous mode.
477 if (IsDangerousMode()) 492 if (mode_ == DANGEROUS_MODE)
478 return; 493 return;
479 494
480 bool on_body = !InDropDownButtonXCoordinateRange(event.x()); 495 bool on_body = !InDropDownButtonXCoordinateRange(event.x());
481 SetState(on_body ? HOT : NORMAL, on_body ? NORMAL : HOT); 496 SetState(on_body ? HOT : NORMAL, on_body ? NORMAL : HOT);
482 if (on_body) { 497 if (on_body) {
483 body_hover_animation_->Show(); 498 if (!IsShowingWarningDialog())
Randy Smith (Not in Mondays) 2011/12/01 19:50:46 How can we be in dangerous mode and not showing a
asanka 2011/12/02 00:05:04 We get here when we aren't showing a warning dialo
499 body_hover_animation_->Show();
484 drop_hover_animation_->Hide(); 500 drop_hover_animation_->Hide();
485 } else { 501 } else {
486 body_hover_animation_->Hide(); 502 if (!IsShowingWarningDialog())
503 body_hover_animation_->Hide();
487 drop_hover_animation_->Show(); 504 drop_hover_animation_->Show();
488 } 505 }
489 } 506 }
490 507
491 void DownloadItemView::OnMouseExited(const views::MouseEvent& event) { 508 void DownloadItemView::OnMouseExited(const views::MouseEvent& event) {
492 // Mouse should not activate us in dangerous mode. 509 // Mouse should not activate us in dangerous mode.
493 if (IsDangerousMode()) 510 if (mode_ == DANGEROUS_MODE)
494 return; 511 return;
495 512
496 SetState(NORMAL, drop_down_pressed_ ? PUSHED : NORMAL); 513 SetState(NORMAL, drop_down_pressed_ ? PUSHED : NORMAL);
497 body_hover_animation_->Hide(); 514 if (!IsShowingWarningDialog())
515 body_hover_animation_->Hide();
498 drop_hover_animation_->Hide(); 516 drop_hover_animation_->Hide();
499 } 517 }
500 518
501 bool DownloadItemView::OnKeyPressed(const views::KeyEvent& event) { 519 bool DownloadItemView::OnKeyPressed(const views::KeyEvent& event) {
502 // Key press should not activate us in dangerous mode. 520 // Key press should not activate us in dangerous mode.
503 if (IsDangerousMode()) 521 if (IsShowingWarningDialog())
504 return true; 522 return true;
505 523
506 if (event.key_code() == ui::VKEY_SPACE || 524 if (event.key_code() == ui::VKEY_SPACE ||
507 event.key_code() == ui::VKEY_RETURN) { 525 event.key_code() == ui::VKEY_RETURN) {
508 OpenDownload(); 526 OpenDownload();
509 return true; 527 return true;
510 } 528 }
511 return false; 529 return false;
512 } 530 }
513 531
(...skipping 23 matching lines...) Expand all
537 SetMouseHandler(NULL); 555 SetMouseHandler(NULL);
538 556
539 // If |is_mouse_gesture| is false, |p| is ignored. The menu is shown aligned 557 // If |is_mouse_gesture| is false, |p| is ignored. The menu is shown aligned
540 // to drop down arrow button. 558 // to drop down arrow button.
541 if (!is_mouse_gesture) { 559 if (!is_mouse_gesture) {
542 drop_down_pressed_ = true; 560 drop_down_pressed_ = true;
543 SetState(NORMAL, PUSHED); 561 SetState(NORMAL, PUSHED);
544 point.SetPoint(drop_down_x_left_, box_y_); 562 point.SetPoint(drop_down_x_left_, box_y_);
545 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); 563 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_);
546 } 564 }
547 565 // Post a task to release the button. When we call the Run method on the menu
566 // below, it runs an inner message loop that might cause us to be deleted.
567 // Posting a task with a WeakPtr lets us safely handle the button release.
568 MessageLoop::current()->PostNonNestableTask(
569 FROM_HERE,
570 base::Bind(&DownloadItemView::ReleaseDropDown,
571 weak_ptr_factory_.GetWeakPtr()));
548 views::View::ConvertPointToScreen(this, &point); 572 views::View::ConvertPointToScreen(this, &point);
549 573
550 if (!context_menu_.get()) 574 if (!context_menu_.get())
551 context_menu_.reset(new DownloadShelfContextMenuView(model_.get())); 575 context_menu_.reset(new DownloadShelfContextMenuView(model_.get()));
552 // When we call the Run method on the menu, it runs an inner message loop 576 context_menu_->Run(GetWidget()->GetTopLevelWidget(),
553 // that might causes us to be deleted. 577 gfx::Rect(point, size));
554 if (context_menu_->Run(GetWidget()->GetTopLevelWidget(), 578 // We could be deleted now.
555 gfx::Rect(point, size)))
556 return; // We have been deleted! Don't access 'this'.
557
558 // If the menu action was to remove the download, this view will also be
559 // invalid so we must not access 'this' in this case.
560 if (context_menu_->download_item()) {
561 drop_down_pressed_ = false;
562 // Showing the menu blocks. Here we revert the state.
563 SetState(NORMAL, NORMAL);
564 }
565 } 579 }
566 580
567 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { 581 void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) {
568 state->name = accessible_name_; 582 state->name = accessible_name_;
569 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 583 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
570 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { 584 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) {
571 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; 585 state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE;
572 } else { 586 } else {
573 state->state = ui::AccessibilityTypes::STATE_HASPOPUP; 587 state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
574 } 588 }
575 } 589 }
576 590
577 void DownloadItemView::ButtonPressed( 591 void DownloadItemView::ButtonPressed(
578 views::Button* sender, const views::Event& event) { 592 views::Button* sender, const views::Event& event) {
579 if (sender == discard_button_) { 593 if (sender == discard_button_) {
580 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 594 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
581 base::Time::Now() - creation_time_); 595 base::Time::Now() - creation_time_);
582 if (download_->IsPartialDownload()) 596 if (download_->IsPartialDownload())
583 download_->Cancel(true); 597 download_->Cancel(true);
584 download_->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 598 download_->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
585 // WARNING: we are deleted at this point. Don't access 'this'. 599 // WARNING: we are deleted at this point. Don't access 'this'.
586 } else if (sender == save_button_) { 600 } else if (save_button_ && sender == save_button_) {
587 // The user has confirmed a dangerous download. We'd record how quickly the 601 // The user has confirmed a dangerous download. We'd record how quickly the
588 // user did this to detect whether we're being clickjacked. 602 // user did this to detect whether we're being clickjacked.
589 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 603 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
590 base::Time::Now() - creation_time_); 604 base::Time::Now() - creation_time_);
591 // This will change the state and notify us. 605 // This will change the state and notify us.
592 download_->DangerousDownloadValidated(); 606 download_->DangerousDownloadValidated();
593 } 607 }
594 } 608 }
595 609
596 void DownloadItemView::AnimationProgressed(const ui::Animation* animation) { 610 void DownloadItemView::AnimationProgressed(const ui::Animation* animation) {
597 // We don't care if what animation (body button/drop button/complete), 611 // We don't care if what animation (body button/drop button/complete),
598 // is calling back, as they all have to go through the same paint call. 612 // is calling back, as they all have to go through the same paint call.
599 SchedulePaint(); 613 SchedulePaint();
600 } 614 }
601 615
602 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { 616 void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
dmazzoni 2011/12/01 19:49:22 This logic is getting a little more confusing to f
asanka 2011/12/02 00:05:04 I added a comment before OnPaint() that gives an o
603 BodyImageSet* body_image_set = NULL; 617 BodyImageSet* body_image_set = NULL;
604 switch (body_state_) { 618 switch (mode_) {
605 case NORMAL: 619 case NORMAL_MODE:
606 case HOT: 620 if (body_state_ == PUSHED)
607 body_image_set = &normal_body_image_set_; 621 body_image_set = &pushed_body_image_set_;
622 else // NORMAL or HOT
623 body_image_set = &normal_body_image_set_;
608 break; 624 break;
609 case PUSHED: 625 case DANGEROUS_MODE:
610 body_image_set = &pushed_body_image_set_;
611 break;
612 case DANGEROUS:
613 body_image_set = &dangerous_mode_body_image_set_; 626 body_image_set = &dangerous_mode_body_image_set_;
614 break; 627 break;
615 default: 628 case MALICIOUS_MODE:
616 NOTREACHED(); 629 body_image_set = &malicious_mode_body_image_set_;
617 }
618 DropDownImageSet* drop_down_image_set = NULL;
619 switch (drop_down_state_) {
620 case NORMAL:
621 case HOT:
622 drop_down_image_set = &normal_drop_down_image_set_;
623 break;
624 case PUSHED:
625 drop_down_image_set = &pushed_drop_down_image_set_;
626 break;
627 case DANGEROUS:
628 drop_down_image_set = NULL; // No drop-down in dangerous mode.
dmazzoni 2011/12/01 19:49:22 Please preserve this comment somewhere.
asanka 2011/12/02 00:05:04 Done.
629 break; 630 break;
630 default: 631 default:
631 NOTREACHED(); 632 NOTREACHED();
632 } 633 }
633 634
635 DropDownImageSet* drop_down_image_set = NULL;
636 if (mode_ == NORMAL_MODE || mode_ == MALICIOUS_MODE) {
637 switch (drop_down_state_) {
638 case NORMAL:
639 case HOT:
640 drop_down_image_set = &normal_drop_down_image_set_;
641 break;
642 case PUSHED:
643 drop_down_image_set = &pushed_drop_down_image_set_;
644 break;
645 default:
646 NOTREACHED();
647 }
648 }
649
634 int center_width = width() - kLeftPadding - 650 int center_width = width() - kLeftPadding -
635 body_image_set->left->width() - 651 body_image_set->left->width() -
636 body_image_set->right->width() - 652 body_image_set->right->width() -
637 (drop_down_image_set ? 653 (drop_down_image_set ?
638 normal_drop_down_image_set_.center->width() : 654 normal_drop_down_image_set_.center->width() :
639 0); 655 0);
640 656
641 // May be caused by animation. 657 // May be caused by animation.
642 if (center_width <= 0) 658 if (center_width <= 0)
643 return; 659 return;
644 660
645 // Draw status before button image to effectively lighten text. 661 // Draw status before button image to effectively lighten text.
646 if (!IsDangerousMode()) { 662 if (!IsShowingWarningDialog()) {
647 if (!status_text_.empty()) { 663 if (!status_text_.empty()) {
648 int mirrored_x = GetMirroredXWithWidthInView( 664 int mirrored_x = GetMirroredXWithWidthInView(
649 download_util::kSmallProgressIconSize, kTextWidth); 665 download_util::kSmallProgressIconSize, kTextWidth);
650 // Add font_.height() to compensate for title, which is drawn later. 666 // Add font_.height() to compensate for title, which is drawn later.
651 int y = box_y_ + kVerticalPadding + font_.GetHeight() + 667 int y = box_y_ + kVerticalPadding + font_.GetHeight() +
652 kVerticalTextPadding; 668 kVerticalTextPadding;
653 SkColor file_name_color = GetThemeProvider()->GetColor( 669 SkColor file_name_color = GetThemeProvider()->GetColor(
654 ThemeService::COLOR_BOOKMARK_TEXT); 670 ThemeService::COLOR_BOOKMARK_TEXT);
655 // If text is light-on-dark, lightening it alone will do nothing. 671 // If text is light-on-dark, lightening it alone will do nothing.
656 // Therefore we mute luminance a wee bit before drawing in this case. 672 // Therefore we mute luminance a wee bit before drawing in this case.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 body_image_set->top, body_image_set->center, 705 body_image_set->top, body_image_set->center,
690 body_image_set->bottom, 706 body_image_set->bottom,
691 x, box_y_, box_height_, center_width); 707 x, box_y_, box_height_, center_width);
692 x += center_width; 708 x += center_width;
693 PaintBitmaps(canvas, 709 PaintBitmaps(canvas,
694 body_image_set->top_right, body_image_set->right, 710 body_image_set->top_right, body_image_set->right,
695 body_image_set->bottom_right, 711 body_image_set->bottom_right,
696 x, box_y_, box_height_, body_image_set->top_right->width()); 712 x, box_y_, box_height_, body_image_set->top_right->width());
697 713
698 // Overlay our body hot state. 714 // Overlay our body hot state.
699 if (body_hover_animation_->GetCurrentValue() > 0) { 715 if (!IsShowingWarningDialog() &&
716 body_hover_animation_->GetCurrentValue() > 0) {
700 canvas->SaveLayerAlpha( 717 canvas->SaveLayerAlpha(
701 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255)); 718 static_cast<int>(body_hover_animation_->GetCurrentValue() * 255));
702 canvas->GetSkCanvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); 719 canvas->GetSkCanvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
703 720
704 int x = kLeftPadding; 721 int x = kLeftPadding;
705 PaintBitmaps(canvas, 722 PaintBitmaps(canvas,
706 hot_body_image_set_.top_left, hot_body_image_set_.left, 723 hot_body_image_set_.top_left, hot_body_image_set_.left,
707 hot_body_image_set_.bottom_left, 724 hot_body_image_set_.bottom_left,
708 x, box_y_, box_height_, hot_body_image_set_.top_left->width()); 725 x, box_y_, box_height_, hot_body_image_set_.top_left->width());
709 x += body_image_set->top_left->width(); 726 x += body_image_set->top_left->width();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 763 }
747 764
748 // Restore the canvas to avoid file name etc. text are drawn flipped. 765 // Restore the canvas to avoid file name etc. text are drawn flipped.
749 // Consequently, the x-axis of following canvas->DrawXXX() method should be 766 // Consequently, the x-axis of following canvas->DrawXXX() method should be
750 // mirrored so the text and images are down in the right positions. 767 // mirrored so the text and images are down in the right positions.
751 canvas->Restore(); 768 canvas->Restore();
752 769
753 // Print the text, left aligned and always print the file extension. 770 // Print the text, left aligned and always print the file extension.
754 // Last value of x was the end of the right image, just before the button. 771 // Last value of x was the end of the right image, just before the button.
755 // Note that in dangerous mode we use a label (as the text is multi-line). 772 // Note that in dangerous mode we use a label (as the text is multi-line).
756 if (!IsDangerousMode()) { 773 if (!IsShowingWarningDialog()) {
757 string16 filename; 774 string16 filename;
758 if (!disabled_while_opening_) { 775 if (!disabled_while_opening_) {
759 filename = ui::ElideFilename(download_->GetFileNameToReportUser(), 776 filename = ui::ElideFilename(download_->GetFileNameToReportUser(),
760 font_, kTextWidth); 777 font_, kTextWidth);
761 } else { 778 } else {
762 // First, Calculate the download status opening string width. 779 // First, Calculate the download status opening string width.
763 string16 status_string = 780 string16 status_string =
764 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16()); 781 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, string16());
765 int status_string_width = font_.GetStringWidth(status_string); 782 int status_string_width = font_.GetStringWidth(status_string);
766 // Then, elide the file name. 783 // Then, elide the file name.
(...skipping 18 matching lines...) Expand all
785 IsEnabled() ? file_name_color : 802 IsEnabled() ? file_name_color :
786 kFileNameDisabledColor, 803 kFileNameDisabledColor,
787 mirrored_x, y, kTextWidth, font_.GetHeight()); 804 mirrored_x, y, kTextWidth, font_.GetHeight());
788 } 805 }
789 806
790 // Load the icon. 807 // Load the icon.
791 IconManager* im = g_browser_process->icon_manager(); 808 IconManager* im = g_browser_process->icon_manager();
792 gfx::Image* image = im->LookupIcon(download_->GetUserVerifiedFilePath(), 809 gfx::Image* image = im->LookupIcon(download_->GetUserVerifiedFilePath(),
793 IconLoader::SMALL); 810 IconLoader::SMALL);
794 const SkBitmap* icon = NULL; 811 const SkBitmap* icon = NULL;
795 if (IsDangerousMode()) 812 if (IsShowingWarningDialog())
796 icon = warning_icon_; 813 icon = warning_icon_;
797 else if (image) 814 else if (image)
798 icon = *image; 815 icon = *image;
799 816
800 // We count on the fact that the icon manager will cache the icons and if one 817 // We count on the fact that the icon manager will cache the icons and if one
801 // is available, it will be cached here. We *don't* want to request the icon 818 // is available, it will be cached here. We *don't* want to request the icon
802 // to be loaded here, since this will also get called if the icon can't be 819 // to be loaded here, since this will also get called if the icon can't be
803 // loaded, in which case LookupIcon will always be NULL. The loading will be 820 // loaded, in which case LookupIcon will always be NULL. The loading will be
804 // triggered only when we think the status might change. 821 // triggered only when we think the status might change.
805 if (icon) { 822 if (icon) {
806 if (!IsDangerousMode()) { 823 if (!IsShowingWarningDialog()) {
807 if (download_->IsInProgress()) { 824 if (download_->IsInProgress()) {
808 download_util::PaintDownloadProgress(canvas, this, 0, 0, 825 download_util::PaintDownloadProgress(canvas, this, 0, 0,
809 progress_angle_, 826 progress_angle_,
810 download_->PercentComplete(), 827 download_->PercentComplete(),
811 download_util::SMALL); 828 download_util::SMALL);
812 } else if (download_->IsComplete() && 829 } else if (download_->IsComplete() &&
813 complete_animation_.get() && 830 complete_animation_.get() &&
814 complete_animation_->is_animating()) { 831 complete_animation_->is_animating()) {
815 if (download_->IsInterrupted()) { 832 if (download_->IsInterrupted()) {
816 download_util::PaintDownloadInterrupted(canvas, this, 0, 0, 833 download_util::PaintDownloadInterrupted(canvas, this, 0, 0,
817 complete_animation_->GetCurrentValue(), 834 complete_animation_->GetCurrentValue(),
818 download_util::SMALL); 835 download_util::SMALL);
819 } else { 836 } else {
820 download_util::PaintDownloadComplete(canvas, this, 0, 0, 837 download_util::PaintDownloadComplete(canvas, this, 0, 0,
821 complete_animation_->GetCurrentValue(), 838 complete_animation_->GetCurrentValue(),
822 download_util::SMALL); 839 download_util::SMALL);
823 } 840 }
824 } 841 }
825 } 842 }
826 843
827 // Draw the icon image. 844 // Draw the icon image.
828 int icon_x, icon_y; 845 int icon_x, icon_y;
829 846
830 if (IsDangerousMode()) { 847 if (IsShowingWarningDialog()) {
831 icon_x = kLeftPadding + body_image_set->top_left->width(); 848 icon_x = kLeftPadding + body_image_set->top_left->width();
832 icon_y = (height() - icon->height()) / 2; 849 icon_y = (height() - icon->height()) / 2;
833 } else { 850 } else {
834 icon_x = download_util::kSmallProgressIconOffset; 851 icon_x = download_util::kSmallProgressIconOffset;
835 icon_y = download_util::kSmallProgressIconOffset; 852 icon_y = download_util::kSmallProgressIconOffset;
836 } 853 }
837 icon_x = GetMirroredXWithWidthInView(icon_x, icon->width()); 854 icon_x = GetMirroredXWithWidthInView(icon_x, icon->width());
838 if (IsEnabled()) { 855 if (IsEnabled()) {
839 canvas->DrawBitmapInt(*icon, icon_x, icon_y); 856 canvas->DrawBitmapInt(*icon, icon_x, icon_y);
840 } else { 857 } else {
841 // Use an alpha to make the image look disabled. 858 // Use an alpha to make the image look disabled.
842 SkPaint paint; 859 SkPaint paint;
843 paint.setAlpha(120); 860 paint.setAlpha(120);
844 canvas->DrawBitmapInt(*icon, icon_x, icon_y, paint); 861 canvas->DrawBitmapInt(*icon, icon_x, icon_y, paint);
845 } 862 }
846 } 863 }
847 } 864 }
848 865
849 void DownloadItemView::OpenDownload() { 866 void DownloadItemView::OpenDownload() {
867 DCHECK(!IsShowingWarningDialog());
850 // We're interested in how long it takes users to open downloads. If they 868 // We're interested in how long it takes users to open downloads. If they
851 // open downloads super quickly, we should be concerned about clickjacking. 869 // open downloads super quickly, we should be concerned about clickjacking.
852 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", 870 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
853 base::Time::Now() - creation_time_); 871 base::Time::Now() - creation_time_);
854 download_->OpenDownload(); 872 download_->OpenDownload();
855 UpdateAccessibleName(); 873 UpdateAccessibleName();
856 } 874 }
857 875
858 void DownloadItemView::LoadIcon() { 876 void DownloadItemView::LoadIcon() {
859 IconManager* im = g_browser_process->icon_manager(); 877 IconManager* im = g_browser_process->icon_manager();
(...skipping 30 matching lines...) Expand all
890 0, 0, center_bitmap->width(), center_bitmap->height(), 908 0, 0, center_bitmap->width(), center_bitmap->height(),
891 x, y, width, middle_height, false); 909 x, y, width, middle_height, false);
892 y += middle_height; 910 y += middle_height;
893 // Draw the bottom. 911 // Draw the bottom.
894 canvas->DrawBitmapInt(*bottom_bitmap, 912 canvas->DrawBitmapInt(*bottom_bitmap,
895 0, 0, bottom_bitmap->width(), bottom_bitmap->height(), 913 0, 0, bottom_bitmap->width(), bottom_bitmap->height(),
896 x, y, width, bottom_bitmap->height(), false); 914 x, y, width, bottom_bitmap->height(), false);
897 } 915 }
898 916
899 void DownloadItemView::SetState(State body_state, State drop_down_state) { 917 void DownloadItemView::SetState(State body_state, State drop_down_state) {
900 if (body_state_ == body_state && drop_down_state_ == drop_down_state) 918 if ((IsShowingWarningDialog() || body_state_ == body_state) &&
dmazzoni 2011/12/01 19:49:22 I don't understand why IsShowingWarningDialog() is
asanka 2011/12/02 00:05:04 If we are showing the warning dialog, we don't cha
919 drop_down_state_ == drop_down_state)
901 return; 920 return;
921 // We shouldn't be calling SetState if we are in DANGEROUS_MODE.
922 DCHECK(mode_ != DANGEROUS_MODE);
902 923
903 body_state_ = body_state; 924 // If we are showing a warning dialog, we don't change body state, unless
925 // through ClearWarningDialog().
926 if (!IsShowingWarningDialog()) {
927 body_state_ = body_state;
928 } else {
929 DCHECK(body_state_ == NORMAL);
930 }
904 drop_down_state_ = drop_down_state; 931 drop_down_state_ = drop_down_state;
905 SchedulePaint(); 932 SchedulePaint();
906 } 933 }
907 934
908 void DownloadItemView::ClearDangerousMode() { 935 void DownloadItemView::ClearWarningDialog() {
909 DCHECK(download_->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED && 936 DCHECK(download_->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED &&
910 body_state_ == DANGEROUS && drop_down_state_ == DANGEROUS); 937 (mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE));
911 938
939 mode_ = NORMAL_MODE;
912 body_state_ = NORMAL; 940 body_state_ = NORMAL;
913 drop_down_state_ = NORMAL; 941 drop_down_state_ = NORMAL;
914 942
915 // Remove the views used by the dangerous mode. 943 // Remove the views used by the warning dialog.
916 RemoveChildView(save_button_); 944 if (save_button_) {
917 delete save_button_; 945 RemoveChildView(save_button_);
918 save_button_ = NULL; 946 delete save_button_;
947 save_button_ = NULL;
948 }
919 RemoveChildView(discard_button_); 949 RemoveChildView(discard_button_);
920 delete discard_button_; 950 delete discard_button_;
921 discard_button_ = NULL; 951 discard_button_ = NULL;
922 RemoveChildView(dangerous_download_label_); 952 RemoveChildView(dangerous_download_label_);
923 delete dangerous_download_label_; 953 delete dangerous_download_label_;
924 dangerous_download_label_ = NULL; 954 dangerous_download_label_ = NULL;
925 dangerous_download_label_sized_ = false; 955 dangerous_download_label_sized_ = false;
956 cached_button_size_.SetSize(0,0);
926 957
927 // Set the accessible name back to the status and filename instead of the 958 // Set the accessible name back to the status and filename instead of the
928 // download warning. 959 // download warning.
929 UpdateAccessibleName(); 960 UpdateAccessibleName();
961 UpdateDropDownButtonPosition();
930 962
931 // We need to load the icon now that the download_ has the real path. 963 // We need to load the icon now that the download_ has the real path.
932 LoadIcon(); 964 LoadIcon();
933 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); 965 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName();
934 966
935 // Force the shelf to layout again as our size has changed. 967 // Force the shelf to layout again as our size has changed.
936 parent_->Layout(); 968 parent_->Layout();
937 parent_->SchedulePaint(); 969 parent_->SchedulePaint();
938 } 970 }
939 971
940 void DownloadItemView::EnterDangerousMode() { 972 void DownloadItemView::ShowWarningDialog() {
941 DCHECK(body_state_ != DANGEROUS && drop_down_state_ != DANGEROUS); 973 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE);
974 if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_URL ||
975 download_->GetDangerType() == DownloadStateInfo::DANGEROUS_CONTENT) {
976 mode_ = MALICIOUS_MODE;
977 } else {
978 DCHECK(download_->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE);
979 mode_ = DANGEROUS_MODE;
980 }
981 body_state_ = NORMAL;
982 drop_down_state_ = NORMAL;
942 tooltip_text_.clear(); 983 tooltip_text_.clear();
943 body_state_ = DANGEROUS; 984 if (mode_ == DANGEROUS_MODE) {
944 drop_down_state_ = DANGEROUS; 985 save_button_ = new views::NativeTextButton(this,
945 save_button_ = new views::NativeTextButton(this, 986 l10n_util::GetStringUTF16(
946 l10n_util::GetStringUTF16( 987 ChromeDownloadManagerDelegate::IsExtensionDownload(download_) ?
947 ChromeDownloadManagerDelegate::IsExtensionDownload(download_) ? 988 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD));
948 IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); 989 save_button_->set_ignore_minimum_size(true);
949 save_button_->set_ignore_minimum_size(true); 990 AddChildView(save_button_);
991 }
950 discard_button_ = new views::NativeTextButton( 992 discard_button_ = new views::NativeTextButton(
951 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); 993 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD));
952 discard_button_->set_ignore_minimum_size(true); 994 discard_button_->set_ignore_minimum_size(true);
953 AddChildView(save_button_);
954 AddChildView(discard_button_); 995 AddChildView(discard_button_);
955 996
956 // Ensure the file name is not too long. 997 // Ensure the file name is not too long.
957 998
958 // Extract the file extension (if any). 999 // Extract the file extension (if any).
959 FilePath filename(download_->GetTargetName()); 1000 FilePath filename(download_->GetTargetName());
960 #if defined(OS_POSIX) 1001 #if defined(OS_POSIX)
961 string16 extension = WideToUTF16(base::SysNativeMBToWide( 1002 string16 extension = WideToUTF16(base::SysNativeMBToWide(
962 filename.Extension())); 1003 filename.Extension()));
963 #else 1004 #else
(...skipping 11 matching lines...) Expand all
975 #endif 1016 #endif
976 1017
977 // Elide giant extensions (this shouldn't currently be hit, but might 1018 // Elide giant extensions (this shouldn't currently be hit, but might
978 // in future, should we ever notice unsafe giant extensions). 1019 // in future, should we ever notice unsafe giant extensions).
979 if (extension.length() > kFileNameMaxLength / 2) 1020 if (extension.length() > kFileNameMaxLength / 2)
980 ui::ElideString(extension, kFileNameMaxLength / 2, &extension); 1021 ui::ElideString(extension, kFileNameMaxLength / 2, &extension);
981 1022
982 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1023 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
983 // The dangerous download label text and icon are different 1024 // The dangerous download label text and icon are different
984 // under different cases. 1025 // under different cases.
985 if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_URL || 1026 if (mode_ == MALICIOUS_MODE) {
986 download_->GetDangerType() == DownloadStateInfo::DANGEROUS_CONTENT) {
987 warning_icon_ = rb.GetBitmapNamed(IDR_SAFEBROWSING_WARNING); 1027 warning_icon_ = rb.GetBitmapNamed(IDR_SAFEBROWSING_WARNING);
988 } else { 1028 } else {
989 DCHECK(download_->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE); 1029 DCHECK(download_->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE);
1030 // The download file has dangerous file type (e.g.: an executable).
990 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); 1031 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING);
991 } 1032 }
992 string16 dangerous_label; 1033 string16 dangerous_label;
993 if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_URL) { 1034 if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_URL) {
994 // Safebrowsing shows the download URL or content leads to malicious file. 1035 // Safebrowsing shows the download URL or content leads to malicious file.
995 dangerous_label = l10n_util::GetStringUTF16( 1036 dangerous_label = l10n_util::GetStringUTF16(
996 IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); 1037 IDS_PROMPT_MALICIOUS_DOWNLOAD_URL);
997 } else if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE && 1038 } else if (download_->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE &&
998 ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) { 1039 ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
999 dangerous_label = 1040 dangerous_label =
(...skipping 15 matching lines...) Expand all
1015 filename); 1056 filename);
1016 } 1057 }
1017 1058
1018 dangerous_download_label_ = new views::Label(dangerous_label); 1059 dangerous_download_label_ = new views::Label(dangerous_label);
1019 dangerous_download_label_->SetMultiLine(true); 1060 dangerous_download_label_->SetMultiLine(true);
1020 dangerous_download_label_->SetHorizontalAlignment( 1061 dangerous_download_label_->SetHorizontalAlignment(
1021 views::Label::ALIGN_LEFT); 1062 views::Label::ALIGN_LEFT);
1022 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); 1063 dangerous_download_label_->SetAutoColorReadabilityEnabled(false);
1023 AddChildView(dangerous_download_label_); 1064 AddChildView(dangerous_download_label_);
1024 SizeLabelToMinWidth(); 1065 SizeLabelToMinWidth();
1066 UpdateDropDownButtonPosition();
1025 } 1067 }
1026 1068
1027 gfx::Size DownloadItemView::GetButtonSize() { 1069 gfx::Size DownloadItemView::GetButtonSize() {
1028 DCHECK(save_button_ && discard_button_); 1070 DCHECK(discard_button_ && (mode_ == MALICIOUS_MODE || save_button_));
1029 gfx::Size size; 1071 gfx::Size size;
1030 1072
1031 // We cache the size when successfully retrieved, not for performance reasons 1073 // We cache the size when successfully retrieved, not for performance reasons
1032 // but because if this DownloadItemView is being animated while the tab is 1074 // but because if this DownloadItemView is being animated while the tab is
1033 // not showing, the native buttons are not parented and their preferred size 1075 // not showing, the native buttons are not parented and their preferred size
1034 // is 0, messing-up the layout. 1076 // is 0, messing-up the layout.
1035 if (cached_button_size_.width() != 0) 1077 if (cached_button_size_.width() != 0)
1036 return cached_button_size_; 1078 return cached_button_size_;
1037 1079
1038 size = save_button_->GetMinimumSize(); 1080 if (save_button_)
1081 size = save_button_->GetMinimumSize();
1039 gfx::Size discard_size = discard_button_->GetMinimumSize(); 1082 gfx::Size discard_size = discard_button_->GetMinimumSize();
1040 1083
1041 size.SetSize(std::max(size.width(), discard_size.width()), 1084 size.SetSize(std::max(size.width(), discard_size.width()),
1042 std::max(size.height(), discard_size.height())); 1085 std::max(size.height(), discard_size.height()));
1043 1086
1044 if (size.width() != 0) 1087 if (size.width() != 0)
1045 cached_button_size_ = size; 1088 cached_button_size_ = size;
1046 1089
1047 return size; 1090 return size;
1048 } 1091 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 1154
1112 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); 1155 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height());
1113 dangerous_download_label_sized_ = true; 1156 dangerous_download_label_sized_ = true;
1114 } 1157 }
1115 1158
1116 void DownloadItemView::Reenable() { 1159 void DownloadItemView::Reenable() {
1117 disabled_while_opening_ = false; 1160 disabled_while_opening_ = false;
1118 SetEnabled(true); // Triggers a repaint. 1161 SetEnabled(true); // Triggers a repaint.
1119 } 1162 }
1120 1163
1164 void DownloadItemView::ReleaseDropDown() {
1165 drop_down_pressed_ = false;
1166 SetState(NORMAL, NORMAL);
1167 }
1168
1121 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { 1169 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) {
1122 if (x > drop_down_x_left_ && x < drop_down_x_right_) 1170 if (x > drop_down_x_left_ && x < drop_down_x_right_)
1123 return true; 1171 return true;
1124 return false; 1172 return false;
1125 } 1173 }
1126 1174
1127 void DownloadItemView::UpdateAccessibleName() { 1175 void DownloadItemView::UpdateAccessibleName() {
1128 string16 new_name; 1176 string16 new_name;
1129 if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { 1177 if (IsShowingWarningDialog()) {
1130 new_name = dangerous_download_label_->GetText(); 1178 new_name = dangerous_download_label_->GetText();
dmazzoni 2011/12/01 19:49:22 Does this need to be updated for dangerous vs mali
asanka 2011/12/02 00:05:04 For both cases, the accessible text is going to be
1131 } else { 1179 } else {
1132 new_name = status_text_ + char16(' ') + 1180 new_name = status_text_ + char16(' ') +
1133 download_->GetFileNameToReportUser().LossyDisplayName(); 1181 download_->GetFileNameToReportUser().LossyDisplayName();
1134 } 1182 }
1135 1183
1136 // If the name has changed, notify assistive technology that the name 1184 // If the name has changed, notify assistive technology that the name
1137 // has changed so they can announce it immediately. 1185 // has changed so they can announce it immediately.
1138 if (new_name != accessible_name_) { 1186 if (new_name != accessible_name_) {
1139 accessible_name_ = new_name; 1187 accessible_name_ = new_name;
1140 if (GetWidget()) { 1188 if (GetWidget()) {
1141 GetWidget()->NotifyAccessibilityEvent( 1189 GetWidget()->NotifyAccessibilityEvent(
1142 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); 1190 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true);
1143 } 1191 }
1144 } 1192 }
1145 } 1193 }
1194
1195 void DownloadItemView::UpdateDropDownButtonPosition() {
1196 gfx::Size size = GetPreferredSize();
1197 if (base::i18n::IsRTL()) {
1198 // Drop down button is glued to the left of the download shelf.
1199 drop_down_x_left_ = 0;
1200 drop_down_x_right_ = normal_drop_down_image_set_.top->width();
1201 } else {
1202 // Drop down button is glued to the right of the download shelf.
1203 drop_down_x_left_ =
1204 size.width() - normal_drop_down_image_set_.top->width();
1205 drop_down_x_right_ = size.width();
1206 }
1207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698