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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/supports_user_data.h" | |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 22 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
22 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
23 #include "chrome/browser/download/download_stats.h" | 24 #include "chrome/browser/download/download_stats.h" |
24 #include "chrome/browser/download/drag_download_item.h" | 25 #include "chrome/browser/download/drag_download_item.h" |
26 #include "chrome/browser/prefs/pref_service_syncable.h" | |
25 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 27 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
26 #include "chrome/browser/safe_browsing/download_protection_service.h" | 28 #include "chrome/browser/safe_browsing/download_protection_service.h" |
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 29 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
28 #include "chrome/browser/themes/theme_properties.h" | 30 #include "chrome/browser/themes/theme_properties.h" |
31 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" | |
29 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" | 32 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" |
30 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 33 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
31 #include "content/public/browser/download_danger_type.h" | 34 #include "content/public/browser/download_danger_type.h" |
32 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
33 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
34 #include "third_party/icu/source/common/unicode/uchar.h" | 37 #include "third_party/icu/source/common/unicode/uchar.h" |
35 #include "ui/base/accessibility/accessible_view_state.h" | 38 #include "ui/base/accessibility/accessible_view_state.h" |
36 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
38 #include "ui/base/theme_provider.h" | 41 #include "ui/base/theme_provider.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 // downloaded item. | 84 // downloaded item. |
82 static const int kDisabledOnOpenDuration = 3000; | 85 static const int kDisabledOnOpenDuration = 3000; |
83 | 86 |
84 // Darken light-on-dark download status text by 20% before drawing, thus | 87 // Darken light-on-dark download status text by 20% before drawing, thus |
85 // creating a "muted" version of title text for both dark-on-light and | 88 // creating a "muted" version of title text for both dark-on-light and |
86 // light-on-dark themes. | 89 // light-on-dark themes. |
87 static const double kDownloadItemLuminanceMod = 0.8; | 90 static const double kDownloadItemLuminanceMod = 0.8; |
88 | 91 |
89 using content::DownloadItem; | 92 using content::DownloadItem; |
90 | 93 |
94 const char kDialogStatusKey[] = "DownloadItemView DialogStatusKey"; | |
mattm
2014/02/06 03:13:10
The key doesn't actually need to be a string, you
felt
2014/02/06 03:33:19
Done.
| |
95 | |
96 class DialogStatusData : public base::SupportsUserData::Data { | |
97 public: | |
98 DialogStatusData() : currently_shown_(false) { } | |
mattm
2014/02/06 03:13:10
should have a virtual destructor
felt
2014/02/06 03:33:19
Done.
| |
99 bool currently_shown_; | |
mattm
2014/02/06 03:13:10
style nit:Should be private with accessors, unless
felt
2014/02/06 03:33:19
Done.
| |
100 }; | |
101 | |
91 DownloadItemView::DownloadItemView(DownloadItem* download_item, | 102 DownloadItemView::DownloadItemView(DownloadItem* download_item, |
92 DownloadShelfView* parent) | 103 DownloadShelfView* parent) |
93 : warning_icon_(NULL), | 104 : warning_icon_(NULL), |
94 shelf_(parent), | 105 shelf_(parent), |
95 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 106 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
96 body_state_(NORMAL), | 107 body_state_(NORMAL), |
97 drop_down_state_(NORMAL), | 108 drop_down_state_(NORMAL), |
98 mode_(NORMAL_MODE), | 109 mode_(NORMAL_MODE), |
99 progress_angle_(DownloadShelf::kStartAngleDegrees), | 110 progress_angle_(DownloadShelf::kStartAngleDegrees), |
100 drop_down_pressed_(false), | 111 drop_down_pressed_(false), |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 return; | 554 return; |
544 } | 555 } |
545 | 556 |
546 // WARNING: all end states after this point delete |this|. | 557 // WARNING: all end states after this point delete |this|. |
547 DCHECK_EQ(discard_button_, sender); | 558 DCHECK_EQ(discard_button_, sender); |
548 if (model_.IsMalicious()) { | 559 if (model_.IsMalicious()) { |
549 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); | 560 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); |
550 shelf_->RemoveDownloadView(this); | 561 shelf_->RemoveDownloadView(this); |
551 return; | 562 return; |
552 } | 563 } |
553 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback()) | 564 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
565 if (model_.ShouldAllowDownloadFeedback()) { | |
566 DownloadFeedbackDialogView::DownloadReportingStatus pref_value = | |
567 static_cast<DownloadFeedbackDialogView::DownloadReportingStatus>( | |
568 shelf_->browser()->profile()->GetPrefs()->GetInteger( | |
569 prefs::kSafeBrowsingDownloadReportingEnabled)); | |
570 DialogStatusData* data = static_cast<DialogStatusData*>( | |
571 shelf_->browser()->profile()->GetUserData(kDialogStatusKey)); | |
572 switch (pref_value) { | |
573 case DownloadFeedbackDialogView::kDialogNotYetShown: | |
574 // Need to check if the dialog is already displayed for this profile. | |
575 // If it is, default to discarding the file and don't generate a second | |
576 // instance of the dialog. | |
577 if (data == NULL) { | |
578 data = new DialogStatusData(); | |
579 shelf_->browser()->profile()->SetUserData(kDialogStatusKey, data); | |
580 } | |
581 if (data->currently_shown_ == false) { | |
582 data->currently_shown_ = true; | |
583 DownloadFeedbackDialogView::Show( | |
584 shelf_->get_parent()->GetNativeWindow(), | |
585 shelf_->browser()->profile(), | |
586 base::Bind( | |
587 &DownloadItemView::PossiblySubmitDownloadToFeedbackService, | |
588 weak_ptr_factory_.GetWeakPtr())); | |
589 } else { | |
590 PossiblySubmitDownloadToFeedbackService( | |
591 DownloadFeedbackDialogView::kDownloadReportingDisabled); | |
592 } | |
593 break; | |
594 | |
595 case DownloadFeedbackDialogView::kDownloadReportingEnabled: | |
596 case DownloadFeedbackDialogView::kDownloadReportingDisabled: | |
597 PossiblySubmitDownloadToFeedbackService(pref_value); | |
598 break; | |
599 | |
600 case DownloadFeedbackDialogView::kMaxValue: | |
601 NOTREACHED(); | |
602 } | |
554 return; | 603 return; |
555 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 604 } |
556 download()->Remove(); | 605 download()->Remove(); |
557 } | 606 } |
558 | 607 |
559 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 608 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
560 // We don't care if what animation (body button/drop button/complete), | 609 // We don't care if what animation (body button/drop button/complete), |
561 // is calling back, as they all have to go through the same paint call. | 610 // is calling back, as they all have to go through the same paint call. |
562 SchedulePaint(); | 611 SchedulePaint(); |
563 } | 612 } |
564 | 613 |
565 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { | 614 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
883 void DownloadItemView::OpenDownload() { | 932 void DownloadItemView::OpenDownload() { |
884 DCHECK(!IsShowingWarningDialog()); | 933 DCHECK(!IsShowingWarningDialog()); |
885 // We're interested in how long it takes users to open downloads. If they | 934 // We're interested in how long it takes users to open downloads. If they |
886 // open downloads super quickly, we should be concerned about clickjacking. | 935 // open downloads super quickly, we should be concerned about clickjacking. |
887 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 936 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
888 base::Time::Now() - creation_time_); | 937 base::Time::Now() - creation_time_); |
889 download()->OpenDownload(); | 938 download()->OpenDownload(); |
890 UpdateAccessibleName(); | 939 UpdateAccessibleName(); |
891 } | 940 } |
892 | 941 |
893 bool DownloadItemView::BeginDownloadFeedback() { | 942 bool DownloadItemView::SubmitDownloadToFeedbackService() { |
894 #if defined(FULL_SAFE_BROWSING) | 943 #if defined(FULL_SAFE_BROWSING) |
895 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 944 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
896 if (!sb_service) | 945 if (!sb_service) |
897 return false; | 946 return false; |
898 safe_browsing::DownloadProtectionService* download_protection_service = | 947 safe_browsing::DownloadProtectionService* download_protection_service = |
899 sb_service->download_protection_service(); | 948 sb_service->download_protection_service(); |
900 if (!download_protection_service) | 949 if (!download_protection_service) |
901 return false; | 950 return false; |
902 base::TimeDelta warning_duration = base::TimeDelta(); | |
903 if (!time_download_warning_shown_.is_null()) | |
904 warning_duration = base::Time::Now() - time_download_warning_shown_; | |
905 UMA_HISTOGRAM_LONG_TIMES("clickjacking.report_and_discard_download", | |
906 warning_duration); | |
907 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 951 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
908 download()); | 952 download()); |
909 // WARNING: we are deleted at this point. Don't access 'this'. | 953 // WARNING: we are deleted at this point. Don't access 'this'. |
910 return true; | 954 return true; |
911 #else | 955 #else |
912 NOTREACHED(); | 956 NOTREACHED(); |
913 return false; | 957 return false; |
914 #endif | 958 #endif |
915 } | 959 } |
916 | 960 |
961 void DownloadItemView::PossiblySubmitDownloadToFeedbackService( | |
962 DownloadFeedbackDialogView::DownloadReportingStatus status) { | |
963 DialogStatusData* data = static_cast<DialogStatusData*>( | |
964 shelf_->browser()->profile()->GetUserData(kDialogStatusKey)); | |
965 DCHECK(data); | |
966 data->currently_shown_ = false; | |
967 | |
968 if (status != DownloadFeedbackDialogView::kDownloadReportingEnabled || | |
969 !SubmitDownloadToFeedbackService()) { | |
970 download()->Remove(); | |
971 } | |
972 // WARNING: 'this' is deleted at this point. Don't access 'this'. | |
973 } | |
974 | |
917 void DownloadItemView::LoadIcon() { | 975 void DownloadItemView::LoadIcon() { |
918 IconManager* im = g_browser_process->icon_manager(); | 976 IconManager* im = g_browser_process->icon_manager(); |
919 last_download_item_path_ = download()->GetTargetFilePath(); | 977 last_download_item_path_ = download()->GetTargetFilePath(); |
920 im->LoadIcon(last_download_item_path_, | 978 im->LoadIcon(last_download_item_path_, |
921 IconLoader::SMALL, | 979 IconLoader::SMALL, |
922 base::Bind(&DownloadItemView::OnExtractIconComplete, | 980 base::Bind(&DownloadItemView::OnExtractIconComplete, |
923 base::Unretained(this)), | 981 base::Unretained(this)), |
924 &cancelable_task_tracker_); | 982 &cancelable_task_tracker_); |
925 } | 983 } |
926 | 984 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 body_state_ = NORMAL; | 1192 body_state_ = NORMAL; |
1135 drop_down_state_ = NORMAL; | 1193 drop_down_state_ = NORMAL; |
1136 if (mode_ == DANGEROUS_MODE) { | 1194 if (mode_ == DANGEROUS_MODE) { |
1137 save_button_ = new views::LabelButton( | 1195 save_button_ = new views::LabelButton( |
1138 this, model_.GetWarningConfirmButtonText()); | 1196 this, model_.GetWarningConfirmButtonText()); |
1139 save_button_->SetStyle(views::Button::STYLE_BUTTON); | 1197 save_button_->SetStyle(views::Button::STYLE_BUTTON); |
1140 AddChildView(save_button_); | 1198 AddChildView(save_button_); |
1141 } | 1199 } |
1142 int discard_button_message = model_.IsMalicious() ? | 1200 int discard_button_message = model_.IsMalicious() ? |
1143 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; | 1201 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; |
1144 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback()) | |
1145 discard_button_message = IDS_REPORT_AND_DISCARD_DOWNLOAD; | |
1146 discard_button_ = new views::LabelButton( | 1202 discard_button_ = new views::LabelButton( |
1147 this, l10n_util::GetStringUTF16(discard_button_message)); | 1203 this, l10n_util::GetStringUTF16(discard_button_message)); |
1148 discard_button_->SetStyle(views::Button::STYLE_BUTTON); | 1204 discard_button_->SetStyle(views::Button::STYLE_BUTTON); |
1149 AddChildView(discard_button_); | 1205 AddChildView(discard_button_); |
1150 | 1206 |
1151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1207 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1152 switch (danger_type) { | 1208 switch (danger_type) { |
1153 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 1209 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
1154 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 1210 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
1155 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 1211 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 void DownloadItemView::AnimateStateTransition(State from, State to, | 1375 void DownloadItemView::AnimateStateTransition(State from, State to, |
1320 gfx::SlideAnimation* animation) { | 1376 gfx::SlideAnimation* animation) { |
1321 if (from == NORMAL && to == HOT) { | 1377 if (from == NORMAL && to == HOT) { |
1322 animation->Show(); | 1378 animation->Show(); |
1323 } else if (from == HOT && to == NORMAL) { | 1379 } else if (from == HOT && to == NORMAL) { |
1324 animation->Hide(); | 1380 animation->Hide(); |
1325 } else if (from != to) { | 1381 } else if (from != to) { |
1326 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1382 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1327 } | 1383 } |
1328 } | 1384 } |
OLD | NEW |