| 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 "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 22 #include "chrome/browser/download/download_item_model.h" | 22 #include "chrome/browser/download/download_item_model.h" |
| 23 #include "chrome/browser/download/download_util.h" | 23 #include "chrome/browser/download/download_util.h" |
| 24 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 25 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 24 #include "chrome/browser/themes/theme_properties.h" | 27 #include "chrome/browser/themes/theme_properties.h" |
| 25 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" | 28 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" |
| 26 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 29 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
| 27 #include "content/public/browser/download_danger_type.h" | 30 #include "content/public/browser/download_danger_type.h" |
| 28 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 29 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 30 #include "third_party/icu/public/common/unicode/uchar.h" | 33 #include "third_party/icu/public/common/unicode/uchar.h" |
| 31 #include "ui/base/accessibility/accessible_view_state.h" | 34 #include "ui/base/accessibility/accessible_view_state.h" |
| 32 #include "ui/base/animation/slide_animation.h" | 35 #include "ui/base/animation/slide_animation.h" |
| 33 #include "ui/base/events/event.h" | 36 #include "ui/base/events/event.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 const gfx::Point& point) { | 520 const gfx::Point& point) { |
| 518 // |point| is in screen coordinates. So convert it to local coordinates first. | 521 // |point| is in screen coordinates. So convert it to local coordinates first. |
| 519 gfx::Point local_point = point; | 522 gfx::Point local_point = point; |
| 520 ConvertPointFromScreen(this, &local_point); | 523 ConvertPointFromScreen(this, &local_point); |
| 521 ShowContextMenuImpl(local_point, true); | 524 ShowContextMenuImpl(local_point, true); |
| 522 } | 525 } |
| 523 | 526 |
| 524 void DownloadItemView::ButtonPressed( | 527 void DownloadItemView::ButtonPressed( |
| 525 views::Button* sender, const ui::Event& event) { | 528 views::Button* sender, const ui::Event& event) { |
| 526 if (sender == discard_button_) { | 529 if (sender == discard_button_) { |
| 530 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback()) |
| 531 return; |
| 527 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 532 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 528 base::Time::Now() - creation_time_); | 533 base::Time::Now() - creation_time_); |
| 529 download()->Remove(); | 534 download()->Remove(); |
| 530 // WARNING: we are deleted at this point. Don't access 'this'. | 535 // WARNING: we are deleted at this point. Don't access 'this'. |
| 531 } else if (save_button_ && sender == save_button_) { | 536 } else if (save_button_ && sender == save_button_) { |
| 532 // The user has confirmed a dangerous download. We'd record how quickly the | 537 // The user has confirmed a dangerous download. We'd record how quickly the |
| 533 // user did this to detect whether we're being clickjacked. | 538 // user did this to detect whether we're being clickjacked. |
| 534 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 539 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
| 535 base::Time::Now() - creation_time_); | 540 base::Time::Now() - creation_time_); |
| 536 // This will change the state and notify us. | 541 // This will change the state and notify us. |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 void DownloadItemView::OpenDownload() { | 840 void DownloadItemView::OpenDownload() { |
| 836 DCHECK(!IsShowingWarningDialog()); | 841 DCHECK(!IsShowingWarningDialog()); |
| 837 // We're interested in how long it takes users to open downloads. If they | 842 // We're interested in how long it takes users to open downloads. If they |
| 838 // open downloads super quickly, we should be concerned about clickjacking. | 843 // open downloads super quickly, we should be concerned about clickjacking. |
| 839 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 844 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
| 840 base::Time::Now() - creation_time_); | 845 base::Time::Now() - creation_time_); |
| 841 download()->OpenDownload(); | 846 download()->OpenDownload(); |
| 842 UpdateAccessibleName(); | 847 UpdateAccessibleName(); |
| 843 } | 848 } |
| 844 | 849 |
| 850 bool DownloadItemView::BeginDownloadFeedback() { |
| 851 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| 852 if (!sb_service) |
| 853 return false; |
| 854 safe_browsing::DownloadProtectionService* download_protection_service = |
| 855 sb_service->download_protection_service(); |
| 856 if (!download_protection_service) |
| 857 return false; |
| 858 UMA_HISTOGRAM_LONG_TIMES("clickjacking.report_and_discard_download", |
| 859 base::Time::Now() - creation_time_); |
| 860 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
| 861 download()); |
| 862 // WARNING: we are deleted at this point. Don't access 'this'. |
| 863 return true; |
| 864 } |
| 865 |
| 845 void DownloadItemView::LoadIcon() { | 866 void DownloadItemView::LoadIcon() { |
| 846 IconManager* im = g_browser_process->icon_manager(); | 867 IconManager* im = g_browser_process->icon_manager(); |
| 847 last_download_item_path_ = download()->GetTargetFilePath(); | 868 last_download_item_path_ = download()->GetTargetFilePath(); |
| 848 im->LoadIcon(last_download_item_path_, | 869 im->LoadIcon(last_download_item_path_, |
| 849 IconLoader::SMALL, | 870 IconLoader::SMALL, |
| 850 base::Bind(&DownloadItemView::OnExtractIconComplete, | 871 base::Bind(&DownloadItemView::OnExtractIconComplete, |
| 851 base::Unretained(this)), | 872 base::Unretained(this)), |
| 852 &cancelable_task_tracker_); | 873 &cancelable_task_tracker_); |
| 853 } | 874 } |
| 854 | 875 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 mode_ = ((model_.IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); | 1063 mode_ = ((model_.IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); |
| 1043 | 1064 |
| 1044 body_state_ = NORMAL; | 1065 body_state_ = NORMAL; |
| 1045 drop_down_state_ = NORMAL; | 1066 drop_down_state_ = NORMAL; |
| 1046 if (mode_ == DANGEROUS_MODE) { | 1067 if (mode_ == DANGEROUS_MODE) { |
| 1047 save_button_ = new views::LabelButton( | 1068 save_button_ = new views::LabelButton( |
| 1048 this, model_.GetWarningConfirmButtonText()); | 1069 this, model_.GetWarningConfirmButtonText()); |
| 1049 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 1070 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 1050 AddChildView(save_button_); | 1071 AddChildView(save_button_); |
| 1051 } | 1072 } |
| 1052 discard_button_ = new views::LabelButton( | 1073 if (model_.ShouldAllowDownloadFeedback()) { |
| 1053 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); | 1074 safe_browsing::DownloadFeedbackService::RecordFeedbackButtonShown( |
| 1075 download()->GetDangerType()); |
| 1076 discard_button_ = new views::LabelButton( |
| 1077 this, l10n_util::GetStringUTF16(IDS_REPORT_AND_DISCARD_DOWNLOAD)); |
| 1078 } else { |
| 1079 discard_button_ = new views::LabelButton( |
| 1080 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); |
| 1081 } |
| 1054 discard_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 1082 discard_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 1055 AddChildView(discard_button_); | 1083 AddChildView(discard_button_); |
| 1056 | 1084 |
| 1057 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1085 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1058 // The dangerous download label text and icon are different under | 1086 // The dangerous download label text and icon are different under |
| 1059 // different cases. | 1087 // different cases. |
| 1060 if (mode_ == MALICIOUS_MODE) { | 1088 if (mode_ == MALICIOUS_MODE) { |
| 1061 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING); | 1089 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING); |
| 1062 } else { | 1090 } else { |
| 1063 // The download file has dangerous file type (e.g.: an executable). | 1091 // The download file has dangerous file type (e.g.: an executable). |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 void DownloadItemView::AnimateStateTransition(State from, State to, | 1241 void DownloadItemView::AnimateStateTransition(State from, State to, |
| 1214 ui::SlideAnimation* animation) { | 1242 ui::SlideAnimation* animation) { |
| 1215 if (from == NORMAL && to == HOT) { | 1243 if (from == NORMAL && to == HOT) { |
| 1216 animation->Show(); | 1244 animation->Show(); |
| 1217 } else if (from == HOT && to == NORMAL) { | 1245 } else if (from == HOT && to == NORMAL) { |
| 1218 animation->Hide(); | 1246 animation->Hide(); |
| 1219 } else if (from != to) { | 1247 } else if (from != to) { |
| 1220 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1248 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1221 } | 1249 } |
| 1222 } | 1250 } |
| OLD | NEW |