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

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

Issue 3127008: Preliminary work on resuming downloads whose connections have expired.
Patch Set: Waiting to send download automation error message until after other downloads are canceled. Created 10 years, 3 months 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/download_item_view.h" 5 #include "chrome/browser/views/download_item_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 static const int kButtonPadding = 5; // Pixels. 55 static const int kButtonPadding = 5; // Pixels.
56 56
57 // The space on the left and right side of the dangerous download label. 57 // The space on the left and right side of the dangerous download label.
58 static const int kLabelPadding = 4; // Pixels. 58 static const int kLabelPadding = 4; // Pixels.
59 59
60 static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212); 60 static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212);
61 61
62 // How long the 'download complete' animation should last for. 62 // How long the 'download complete' animation should last for.
63 static const int kCompleteAnimationDurationMs = 2500; 63 static const int kCompleteAnimationDurationMs = 2500;
64 64
65 // How long the 'download interrupted' animation should last for.
66 static const int kInterruptedAnimationDurationMs = 2500;
67
65 // How long we keep the item disabled after the user clicked it to open the 68 // How long we keep the item disabled after the user clicked it to open the
66 // downloaded item. 69 // downloaded item.
67 static const int kDisabledOnOpenDuration = 3000; 70 static const int kDisabledOnOpenDuration = 3000;
68 71
69 // Darken light-on-dark download status text by 20% before drawing, thus 72 // Darken light-on-dark download status text by 20% before drawing, thus
70 // creating a "muted" version of title text for both dark-on-light and 73 // creating a "muted" version of title text for both dark-on-light and
71 // light-on-dark themes. 74 // light-on-dark themes.
72 static const double kDownloadItemLuminanceMod = 0.8; 75 static const double kDownloadItemLuminanceMod = 0.8;
73 76
74 // DownloadShelfContextMenuWin ------------------------------------------------- 77 // DownloadShelfContextMenuWin -------------------------------------------------
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) { 348 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) {
346 // We have been approved. 349 // We have been approved.
347 ClearDangerousMode(); 350 ClearDangerousMode();
348 } 351 }
349 352
350 std::wstring status_text = model_->GetStatusText(); 353 std::wstring status_text = model_->GetStatusText();
351 switch (download_->state()) { 354 switch (download_->state()) {
352 case DownloadItem::IN_PROGRESS: 355 case DownloadItem::IN_PROGRESS:
353 download_->is_paused() ? StopDownloadProgress() : StartDownloadProgress(); 356 download_->is_paused() ? StopDownloadProgress() : StartDownloadProgress();
354 break; 357 break;
358 case DownloadItem::INTERRUPTED:
359 StopDownloadProgress();
360 interrupted_animation_.reset(new SlideAnimation(this));
361 interrupted_animation_->SetSlideDuration(kInterruptedAnimationDurationMs);
362 interrupted_animation_->SetTweenType(Tween::LINEAR);
363 interrupted_animation_->Show();
364 if (status_text.empty())
365 show_status_text_ = false;
366 SchedulePaint();
367 LoadIcon();
368 break;
355 case DownloadItem::COMPLETE: 369 case DownloadItem::COMPLETE:
356 if (download_->auto_opened()) { 370 if (download_->auto_opened()) {
357 parent_->RemoveDownloadView(this); // This will delete us! 371 parent_->RemoveDownloadView(this); // This will delete us!
358 return; 372 return;
359 } 373 }
360 StopDownloadProgress(); 374 StopDownloadProgress();
361 complete_animation_.reset(new SlideAnimation(this)); 375 complete_animation_.reset(new SlideAnimation(this));
362 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); 376 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
363 complete_animation_->SetTweenType(Tween::LINEAR); 377 complete_animation_->SetTweenType(Tween::LINEAR);
364 complete_animation_->Show(); 378 complete_animation_->Show();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 x += button_size.width() + kButtonPadding; 433 x += button_size.width() + kButtonPadding;
420 discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); 434 discard_button_->SetBounds(x, y, button_size.width(), button_size.height());
421 } 435 }
422 } 436 }
423 437
424 void DownloadItemView::ButtonPressed( 438 void DownloadItemView::ButtonPressed(
425 views::Button* sender, const views::Event& event) { 439 views::Button* sender, const views::Event& event) {
426 if (sender == discard_button_) { 440 if (sender == discard_button_) {
427 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 441 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
428 base::Time::Now() - creation_time_); 442 base::Time::Now() - creation_time_);
429 if (download_->state() == DownloadItem::IN_PROGRESS) 443 if (download_->IsPartialDownload())
430 download_->Cancel(true); 444 download_->Cancel(true);
431 download_->Remove(true); 445 download_->Remove(true);
432 // WARNING: we are deleted at this point. Don't access 'this'. 446 // WARNING: we are deleted at this point. Don't access 'this'.
433 } else if (sender == save_button_) { 447 } else if (sender == save_button_) {
434 // The user has confirmed a dangerous download. We'd record how quickly the 448 // The user has confirmed a dangerous download. We'd record how quickly the
435 // user did this to detect whether we're being clickjacked. 449 // user did this to detect whether we're being clickjacked.
436 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 450 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
437 base::Time::Now() - creation_time_); 451 base::Time::Now() - creation_time_);
438 // This will change the state and notify us. 452 // This will change the state and notify us.
439 download_->DangerousDownloadValidated(); 453 download_->DangerousDownloadValidated();
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 download_util::PaintDownloadProgress(canvas, this, 0, 0, 660 download_util::PaintDownloadProgress(canvas, this, 0, 0,
647 progress_angle_, 661 progress_angle_,
648 download_->PercentComplete(), 662 download_->PercentComplete(),
649 download_util::SMALL); 663 download_util::SMALL);
650 } else if (download_->state() == DownloadItem::COMPLETE && 664 } else if (download_->state() == DownloadItem::COMPLETE &&
651 complete_animation_.get() && 665 complete_animation_.get() &&
652 complete_animation_->is_animating()) { 666 complete_animation_->is_animating()) {
653 download_util::PaintDownloadComplete(canvas, this, 0, 0, 667 download_util::PaintDownloadComplete(canvas, this, 0, 0,
654 complete_animation_->GetCurrentValue(), 668 complete_animation_->GetCurrentValue(),
655 download_util::SMALL); 669 download_util::SMALL);
670 } else if ((download_->state() == DownloadItem::INTERRUPTED) &&
671 interrupted_animation_.get() &&
672 interrupted_animation_->is_animating()) {
673 download_util::PaintDownloadInterrupted(canvas, this, 0, 0,
674 interrupted_animation_->GetCurrentValue(),
675 download_util::SMALL);
656 } 676 }
657 } 677 }
658 678
659 // Draw the icon image. 679 // Draw the icon image.
660 int mirrored_x = MirroredXWithWidthInsideView( 680 int mirrored_x = MirroredXWithWidthInsideView(
661 download_util::kSmallProgressIconOffset, icon->width()); 681 download_util::kSmallProgressIconOffset, icon->width());
662 if (IsEnabled()) { 682 if (IsEnabled()) {
663 canvas->DrawBitmapInt(*icon, mirrored_x, 683 canvas->DrawBitmapInt(*icon, mirrored_x,
664 download_util::kSmallProgressIconOffset); 684 download_util::kSmallProgressIconOffset);
665 } else { 685 } else {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // Display the context menu for this item. 793 // Display the context menu for this item.
774 bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) { 794 bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) {
775 // Mouse should not activate us in dangerous mode. 795 // Mouse should not activate us in dangerous mode.
776 if (IsDangerousMode()) 796 if (IsDangerousMode())
777 return true; 797 return true;
778 798
779 // Stop any completion animation. 799 // Stop any completion animation.
780 if (complete_animation_.get() && complete_animation_->is_animating()) 800 if (complete_animation_.get() && complete_animation_->is_animating())
781 complete_animation_->End(); 801 complete_animation_->End();
782 802
803 // Stop any 'interrupted' animation.
804 if (interrupted_animation_.get() && interrupted_animation_->is_animating())
805 interrupted_animation_->End();
806
783 if (event.IsOnlyLeftMouseButton()) { 807 if (event.IsOnlyLeftMouseButton()) {
784 gfx::Point point(event.location()); 808 gfx::Point point(event.location());
785 if (!InDropDownButtonXCoordinateRange(event.x())) { 809 if (!InDropDownButtonXCoordinateRange(event.x())) {
786 SetState(PUSHED, NORMAL); 810 SetState(PUSHED, NORMAL);
787 return true; 811 return true;
788 } 812 }
789 813
790 drop_down_pressed_ = true; 814 drop_down_pressed_ = true;
791 SetState(NORMAL, PUSHED); 815 SetState(NORMAL, PUSHED);
792 816
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 void DownloadItemView::Reenable() { 1028 void DownloadItemView::Reenable() {
1005 disabled_while_opening_ = false; 1029 disabled_while_opening_ = false;
1006 SetEnabled(true); // Triggers a repaint. 1030 SetEnabled(true); // Triggers a repaint.
1007 } 1031 }
1008 1032
1009 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) { 1033 bool DownloadItemView::InDropDownButtonXCoordinateRange(int x) {
1010 if (x > drop_down_x_left_ && x < drop_down_x_right_) 1034 if (x > drop_down_x_left_ && x < drop_down_x_right_)
1011 return true; 1035 return true;
1012 return false; 1036 return false;
1013 } 1037 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698