OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 Loading... |
84 // How long we keep the item disabled after the user clicked it to open the | 84 // How long we keep the item disabled after the user clicked it to open the |
85 // downloaded item. | 85 // downloaded item. |
86 static const int kDisabledOnOpenDuration = 3000; | 86 static const int kDisabledOnOpenDuration = 3000; |
87 | 87 |
88 // Darken light-on-dark download status text by 20% before drawing, thus | 88 // Darken light-on-dark download status text by 20% before drawing, thus |
89 // creating a "muted" version of title text for both dark-on-light and | 89 // creating a "muted" version of title text for both dark-on-light and |
90 // light-on-dark themes. | 90 // light-on-dark themes. |
91 static const double kDownloadItemLuminanceMod = 0.8; | 91 static const double kDownloadItemLuminanceMod = 0.8; |
92 | 92 |
93 using content::DownloadItem; | 93 using content::DownloadItem; |
| 94 using safe_browsing::DownloadFeedbackService; |
94 | 95 |
95 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 96 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
96 DownloadShelfView* parent) | 97 DownloadShelfView* parent) |
97 : warning_icon_(NULL), | 98 : warning_icon_(NULL), |
98 shelf_(parent), | 99 shelf_(parent), |
99 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 100 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
100 body_state_(NORMAL), | 101 body_state_(NORMAL), |
101 drop_down_state_(NORMAL), | 102 drop_down_state_(NORMAL), |
102 mode_(NORMAL_MODE), | 103 mode_(NORMAL_MODE), |
103 progress_angle_(DownloadShelf::kStartAngleDegrees), | 104 progress_angle_(DownloadShelf::kStartAngleDegrees), |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // WARNING: all end states after this point delete |this|. | 551 // WARNING: all end states after this point delete |this|. |
551 DCHECK_EQ(discard_button_, sender); | 552 DCHECK_EQ(discard_button_, sender); |
552 if (model_.IsMalicious()) { | 553 if (model_.IsMalicious()) { |
553 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); | 554 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); |
554 shelf_->RemoveDownloadView(this); | 555 shelf_->RemoveDownloadView(this); |
555 return; | 556 return; |
556 } | 557 } |
557 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 558 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
558 if (model_.ShouldAllowDownloadFeedback() && | 559 if (model_.ShouldAllowDownloadFeedback() && |
559 !shelf_->browser()->profile()->IsOffTheRecord()) { | 560 !shelf_->browser()->profile()->IsOffTheRecord()) { |
560 DownloadFeedbackDialogView::DownloadReportingStatus pref_value = | 561 DownloadFeedbackService::DownloadReportingStatus pref_value = |
561 static_cast<DownloadFeedbackDialogView::DownloadReportingStatus>( | 562 static_cast<DownloadFeedbackService::DownloadReportingStatus>( |
562 shelf_->browser()->profile()->GetPrefs()->GetInteger( | 563 shelf_->browser()->profile()->GetPrefs()->GetInteger( |
563 prefs::kSafeBrowsingDownloadReportingEnabled)); | 564 prefs::kSafeBrowsingDownloadReportingEnabled)); |
564 switch (pref_value) { | 565 switch (pref_value) { |
565 case DownloadFeedbackDialogView::kDialogNotYetShown: | 566 case DownloadFeedbackService::kDialogNotYetShown: |
566 DownloadFeedbackDialogView::Show( | 567 DownloadFeedbackDialogView::Show( |
567 shelf_->get_parent()->GetNativeWindow(), | 568 shelf_->get_parent()->GetNativeWindow(), |
568 shelf_->browser()->profile(), | 569 shelf_->browser()->profile(), |
569 base::Bind( | 570 base::Bind( |
570 &DownloadItemView::PossiblySubmitDownloadToFeedbackService, | 571 &DownloadItemView::PossiblySubmitDownloadToFeedbackService, |
571 weak_ptr_factory_.GetWeakPtr())); | 572 weak_ptr_factory_.GetWeakPtr())); |
572 break; | 573 break; |
573 | 574 |
574 case DownloadFeedbackDialogView::kDownloadReportingEnabled: | 575 case DownloadFeedbackService::kDownloadReportingEnabled: |
575 case DownloadFeedbackDialogView::kDownloadReportingDisabled: | 576 case DownloadFeedbackService::kDownloadReportingDisabled: |
576 PossiblySubmitDownloadToFeedbackService(pref_value); | 577 PossiblySubmitDownloadToFeedbackService(pref_value); |
577 break; | 578 break; |
578 | 579 |
579 case DownloadFeedbackDialogView::kMaxValue: | 580 case DownloadFeedbackService::kMaxValue: |
580 NOTREACHED(); | 581 NOTREACHED(); |
581 } | 582 } |
582 return; | 583 return; |
583 } | 584 } |
584 download()->Remove(); | 585 download()->Remove(); |
585 } | 586 } |
586 | 587 |
587 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 588 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
588 // We don't care if what animation (body button/drop button/complete), | 589 // We don't care if what animation (body button/drop button/complete), |
589 // is calling back, as they all have to go through the same paint call. | 590 // is calling back, as they all have to go through the same paint call. |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 download()); | 932 download()); |
932 // WARNING: we are deleted at this point. Don't access 'this'. | 933 // WARNING: we are deleted at this point. Don't access 'this'. |
933 return true; | 934 return true; |
934 #else | 935 #else |
935 NOTREACHED(); | 936 NOTREACHED(); |
936 return false; | 937 return false; |
937 #endif | 938 #endif |
938 } | 939 } |
939 | 940 |
940 void DownloadItemView::PossiblySubmitDownloadToFeedbackService( | 941 void DownloadItemView::PossiblySubmitDownloadToFeedbackService( |
941 DownloadFeedbackDialogView::DownloadReportingStatus status) { | 942 DownloadFeedbackService::DownloadReportingStatus status) { |
942 if (status != DownloadFeedbackDialogView::kDownloadReportingEnabled || | 943 if (status != DownloadFeedbackService::kDownloadReportingEnabled || |
943 !SubmitDownloadToFeedbackService()) { | 944 !SubmitDownloadToFeedbackService()) { |
944 download()->Remove(); | 945 download()->Remove(); |
945 } | 946 } |
946 // WARNING: 'this' is deleted at this point. Don't access 'this'. | 947 // WARNING: 'this' is deleted at this point. Don't access 'this'. |
947 } | 948 } |
948 | 949 |
949 void DownloadItemView::LoadIcon() { | 950 void DownloadItemView::LoadIcon() { |
950 IconManager* im = g_browser_process->icon_manager(); | 951 IconManager* im = g_browser_process->icon_manager(); |
951 last_download_item_path_ = download()->GetTargetFilePath(); | 952 last_download_item_path_ = download()->GetTargetFilePath(); |
952 im->LoadIcon(last_download_item_path_, | 953 im->LoadIcon(last_download_item_path_, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 | 1150 |
1150 TooltipTextChanged(); | 1151 TooltipTextChanged(); |
1151 } | 1152 } |
1152 | 1153 |
1153 void DownloadItemView::ShowWarningDialog() { | 1154 void DownloadItemView::ShowWarningDialog() { |
1154 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); | 1155 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); |
1155 time_download_warning_shown_ = base::Time::Now(); | 1156 time_download_warning_shown_ = base::Time::Now(); |
1156 content::DownloadDangerType danger_type = download()->GetDangerType(); | 1157 content::DownloadDangerType danger_type = download()->GetDangerType(); |
1157 RecordDangerousDownloadWarningShown(danger_type); | 1158 RecordDangerousDownloadWarningShown(danger_type); |
1158 #if defined(FULL_SAFE_BROWSING) | 1159 #if defined(FULL_SAFE_BROWSING) |
1159 if (model_.ShouldAllowDownloadFeedback()) { | 1160 if (model_.ShouldAllowDownloadFeedback()) |
1160 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( | 1161 DownloadFeedbackService::RecordEligibleDownloadShown(danger_type); |
1161 danger_type); | |
1162 } | |
1163 #endif | 1162 #endif |
1164 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; | 1163 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; |
1165 | 1164 |
1166 body_state_ = NORMAL; | 1165 body_state_ = NORMAL; |
1167 drop_down_state_ = NORMAL; | 1166 drop_down_state_ = NORMAL; |
1168 if (mode_ == DANGEROUS_MODE) { | 1167 if (mode_ == DANGEROUS_MODE) { |
1169 save_button_ = new views::LabelButton( | 1168 save_button_ = new views::LabelButton( |
1170 this, model_.GetWarningConfirmButtonText()); | 1169 this, model_.GetWarningConfirmButtonText()); |
1171 save_button_->SetStyle(views::Button::STYLE_BUTTON); | 1170 save_button_->SetStyle(views::Button::STYLE_BUTTON); |
1172 AddChildView(save_button_); | 1171 AddChildView(save_button_); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 void DownloadItemView::AnimateStateTransition(State from, State to, | 1348 void DownloadItemView::AnimateStateTransition(State from, State to, |
1350 gfx::SlideAnimation* animation) { | 1349 gfx::SlideAnimation* animation) { |
1351 if (from == NORMAL && to == HOT) { | 1350 if (from == NORMAL && to == HOT) { |
1352 animation->Show(); | 1351 animation->Show(); |
1353 } else if (from == HOT && to == NORMAL) { | 1352 } else if (from == HOT && to == NORMAL) { |
1354 animation->Hide(); | 1353 animation->Hide(); |
1355 } else if (from != to) { | 1354 } else if (from != to) { |
1356 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1355 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1357 } | 1356 } |
1358 } | 1357 } |
OLD | NEW |