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

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

Issue 15881012: Implement safebrowsing download feedback service, enabled for dev & canary only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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/string_util.h" 16 #include "base/string_util.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 const gfx::Point& point) { 518 const gfx::Point& point) {
516 // |point| is in screen coordinates. So convert it to local coordinates first. 519 // |point| is in screen coordinates. So convert it to local coordinates first.
517 gfx::Point local_point = point; 520 gfx::Point local_point = point;
518 ConvertPointFromScreen(this, &local_point); 521 ConvertPointFromScreen(this, &local_point);
519 ShowContextMenuImpl(local_point, true); 522 ShowContextMenuImpl(local_point, true);
520 } 523 }
521 524
522 void DownloadItemView::ButtonPressed( 525 void DownloadItemView::ButtonPressed(
523 views::Button* sender, const ui::Event& event) { 526 views::Button* sender, const ui::Event& event) {
524 if (sender == discard_button_) { 527 if (sender == discard_button_) {
528 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback())
529 return;
525 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 530 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
526 base::Time::Now() - creation_time_); 531 base::Time::Now() - creation_time_);
527 download()->Remove(); 532 download()->Remove();
528 // WARNING: we are deleted at this point. Don't access 'this'. 533 // WARNING: we are deleted at this point. Don't access 'this'.
529 } else if (save_button_ && sender == save_button_) { 534 } else if (save_button_ && sender == save_button_) {
530 // The user has confirmed a dangerous download. We'd record how quickly the 535 // The user has confirmed a dangerous download. We'd record how quickly the
531 // user did this to detect whether we're being clickjacked. 536 // user did this to detect whether we're being clickjacked.
532 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 537 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
533 base::Time::Now() - creation_time_); 538 base::Time::Now() - creation_time_);
534 // This will change the state and notify us. 539 // This will change the state and notify us.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 void DownloadItemView::OpenDownload() { 837 void DownloadItemView::OpenDownload() {
833 DCHECK(!IsShowingWarningDialog()); 838 DCHECK(!IsShowingWarningDialog());
834 // We're interested in how long it takes users to open downloads. If they 839 // We're interested in how long it takes users to open downloads. If they
835 // open downloads super quickly, we should be concerned about clickjacking. 840 // open downloads super quickly, we should be concerned about clickjacking.
836 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", 841 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
837 base::Time::Now() - creation_time_); 842 base::Time::Now() - creation_time_);
838 download()->OpenDownload(); 843 download()->OpenDownload();
839 UpdateAccessibleName(); 844 UpdateAccessibleName();
840 } 845 }
841 846
847 bool DownloadItemView::BeginDownloadFeedback() {
848 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
849 if (!sb_service)
850 return false;
851 safe_browsing::DownloadProtectionService* download_protection_service =
852 sb_service->download_protection_service();
853 if (!download_protection_service)
854 return false;
855 UMA_HISTOGRAM_LONG_TIMES("clickjacking.report_and_discard_download",
856 base::Time::Now() - creation_time_);
857 download_protection_service->feedback_service()->BeginFeedbackForDownload(
858 download());
859 // WARNING: we are deleted at this point. Don't access 'this'.
860 return true;
noelutz 2013/06/12 02:49:47 I didn't know that worked ;).
861 }
862
842 void DownloadItemView::LoadIcon() { 863 void DownloadItemView::LoadIcon() {
843 IconManager* im = g_browser_process->icon_manager(); 864 IconManager* im = g_browser_process->icon_manager();
844 last_download_item_path_ = download()->GetTargetFilePath(); 865 last_download_item_path_ = download()->GetTargetFilePath();
845 im->LoadIcon(last_download_item_path_, 866 im->LoadIcon(last_download_item_path_,
846 IconLoader::SMALL, 867 IconLoader::SMALL,
847 base::Bind(&DownloadItemView::OnExtractIconComplete, 868 base::Bind(&DownloadItemView::OnExtractIconComplete,
848 base::Unretained(this)), 869 base::Unretained(this)),
849 &cancelable_task_tracker_); 870 &cancelable_task_tracker_);
850 } 871 }
851 872
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 mode_ = ((model_.IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE); 1060 mode_ = ((model_.IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE);
1040 1061
1041 body_state_ = NORMAL; 1062 body_state_ = NORMAL;
1042 drop_down_state_ = NORMAL; 1063 drop_down_state_ = NORMAL;
1043 if (mode_ == DANGEROUS_MODE) { 1064 if (mode_ == DANGEROUS_MODE) {
1044 save_button_ = new views::LabelButton( 1065 save_button_ = new views::LabelButton(
1045 this, model_.GetWarningConfirmButtonText()); 1066 this, model_.GetWarningConfirmButtonText());
1046 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 1067 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
1047 AddChildView(save_button_); 1068 AddChildView(save_button_);
1048 } 1069 }
1049 discard_button_ = new views::LabelButton( 1070 if (model_.ShouldAllowDownloadFeedback()) {
1050 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); 1071 safe_browsing::DownloadFeedbackService::RecordFeedbackButtonShown(
1072 download()->GetDangerType());
1073 discard_button_ = new views::LabelButton(
1074 this, l10n_util::GetStringUTF16(IDS_REPORT_AND_DISCARD_DOWNLOAD));
1075 } else {
1076 discard_button_ = new views::LabelButton(
1077 this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD));
1078 }
1051 discard_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 1079 discard_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
1052 AddChildView(discard_button_); 1080 AddChildView(discard_button_);
1053 1081
1054 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1082 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1055 // The dangerous download label text and icon are different under 1083 // The dangerous download label text and icon are different under
1056 // different cases. 1084 // different cases.
1057 if (mode_ == MALICIOUS_MODE) { 1085 if (mode_ == MALICIOUS_MODE) {
1058 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING); 1086 warning_icon_ = rb.GetImageSkiaNamed(IDR_SAFEBROWSING_WARNING);
1059 } else { 1087 } else {
1060 // The download file has dangerous file type (e.g.: an executable). 1088 // The download file has dangerous file type (e.g.: an executable).
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 void DownloadItemView::AnimateStateTransition(State from, State to, 1238 void DownloadItemView::AnimateStateTransition(State from, State to,
1211 ui::SlideAnimation* animation) { 1239 ui::SlideAnimation* animation) {
1212 if (from == NORMAL && to == HOT) { 1240 if (from == NORMAL && to == HOT) {
1213 animation->Show(); 1241 animation->Show();
1214 } else if (from == HOT && to == NORMAL) { 1242 } else if (from == HOT && to == NORMAL) {
1215 animation->Hide(); 1243 animation->Hide();
1216 } else if (from != to) { 1244 } else if (from != to) {
1217 animation->Reset((to == HOT) ? 1.0 : 0.0); 1245 animation->Reset((to == HOT) ? 1.0 : 0.0);
1218 } 1246 }
1219 } 1247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698