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

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

Issue 147593002: Implement new dangerous download reporting dialog for UNCOMMON_DOWNLOAD, in Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: MODAL_TYPE_WINDOW Created 6 years, 10 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) 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_stats.h" 23 #include "chrome/browser/download/download_stats.h"
24 #include "chrome/browser/download/drag_download_item.h" 24 #include "chrome/browser/download/drag_download_item.h"
25 #include "chrome/browser/prefs/pref_service_syncable.h"
25 #include "chrome/browser/safe_browsing/download_feedback_service.h" 26 #include "chrome/browser/safe_browsing/download_feedback_service.h"
26 #include "chrome/browser/safe_browsing/download_protection_service.h" 27 #include "chrome/browser/safe_browsing/download_protection_service.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
28 #include "chrome/browser/themes/theme_properties.h" 29 #include "chrome/browser/themes/theme_properties.h"
30 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
29 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" 31 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
30 #include "chrome/browser/ui/views/download/download_shelf_view.h" 32 #include "chrome/browser/ui/views/download/download_shelf_view.h"
31 #include "content/public/browser/download_danger_type.h" 33 #include "content/public/browser/download_danger_type.h"
32 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
33 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
34 #include "third_party/icu/source/common/unicode/uchar.h" 36 #include "third_party/icu/source/common/unicode/uchar.h"
35 #include "ui/base/accessibility/accessible_view_state.h" 37 #include "ui/base/accessibility/accessible_view_state.h"
36 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
38 #include "ui/base/theme_provider.h" 40 #include "ui/base/theme_provider.h"
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 return; 545 return;
544 } 546 }
545 547
546 // WARNING: all end states after this point delete |this|. 548 // WARNING: all end states after this point delete |this|.
547 DCHECK_EQ(discard_button_, sender); 549 DCHECK_EQ(discard_button_, sender);
548 if (model_.IsMalicious()) { 550 if (model_.IsMalicious()) {
549 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); 551 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration);
550 shelf_->RemoveDownloadView(this); 552 shelf_->RemoveDownloadView(this);
551 return; 553 return;
552 } 554 }
553 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback()) 555 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration);
556 if (model_.ShouldAllowDownloadFeedback()) {
557 DownloadFeedbackDialogView::DownloadReportingStatus pref_value =
558 static_cast<DownloadFeedbackDialogView::DownloadReportingStatus>(
559 shelf_->browser()->profile()->GetPrefs()->GetInteger(
560 prefs::kSafeBrowsingDownloadReportingEnabled));
561 switch (pref_value) {
562 case DownloadFeedbackDialogView::kDialogNotYetShown:
563 DownloadFeedbackDialogView::Show(
564 shelf_->get_parent()->GetNativeWindow(),
565 shelf_->browser()->profile(),
566 base::Bind(
567 &DownloadItemView::PossiblySubmitDownloadToFeedbackService,
568 weak_ptr_factory_.GetWeakPtr()));
569 break;
570 case DownloadFeedbackDialogView::kDownloadReportingEnabled:
Peter Kasting 2014/02/05 19:47:08 Nit: I might put a newline above this line, as wel
felt 2014/02/05 19:57:26 Done.
571 case DownloadFeedbackDialogView::kDownloadReportingDisabled:
572 PossiblySubmitDownloadToFeedbackService(pref_value);
573 break;
574 case DownloadFeedbackDialogView::kMaxValue:
575 NOTREACHED();
576 }
554 return; 577 return;
555 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); 578 }
556 download()->Remove(); 579 download()->Remove();
557 } 580 }
558 581
559 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { 582 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) {
560 // We don't care if what animation (body button/drop button/complete), 583 // 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. 584 // is calling back, as they all have to go through the same paint call.
562 SchedulePaint(); 585 SchedulePaint();
563 } 586 }
564 587
565 void DownloadItemView::OnPaint(gfx::Canvas* canvas) { 588 void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 void DownloadItemView::OpenDownload() { 906 void DownloadItemView::OpenDownload() {
884 DCHECK(!IsShowingWarningDialog()); 907 DCHECK(!IsShowingWarningDialog());
885 // We're interested in how long it takes users to open downloads. If they 908 // 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. 909 // open downloads super quickly, we should be concerned about clickjacking.
887 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", 910 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
888 base::Time::Now() - creation_time_); 911 base::Time::Now() - creation_time_);
889 download()->OpenDownload(); 912 download()->OpenDownload();
890 UpdateAccessibleName(); 913 UpdateAccessibleName();
891 } 914 }
892 915
893 bool DownloadItemView::BeginDownloadFeedback() { 916 bool DownloadItemView::SubmitDownloadToFeedbackService() {
894 #if defined(FULL_SAFE_BROWSING) 917 #if defined(FULL_SAFE_BROWSING)
895 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); 918 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
896 if (!sb_service) 919 if (!sb_service)
897 return false; 920 return false;
898 safe_browsing::DownloadProtectionService* download_protection_service = 921 safe_browsing::DownloadProtectionService* download_protection_service =
899 sb_service->download_protection_service(); 922 sb_service->download_protection_service();
900 if (!download_protection_service) 923 if (!download_protection_service)
901 return false; 924 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( 925 download_protection_service->feedback_service()->BeginFeedbackForDownload(
908 download()); 926 download());
909 // WARNING: we are deleted at this point. Don't access 'this'. 927 // WARNING: we are deleted at this point. Don't access 'this'.
910 return true; 928 return true;
911 #else 929 #else
912 NOTREACHED(); 930 NOTREACHED();
913 return false; 931 return false;
914 #endif 932 #endif
915 } 933 }
916 934
935 void DownloadItemView::PossiblySubmitDownloadToFeedbackService(
936 DownloadFeedbackDialogView::DownloadReportingStatus status) {
937 if (status != DownloadFeedbackDialogView::kDownloadReportingEnabled ||
938 !SubmitDownloadToFeedbackService()) {
Peter Kasting 2014/02/05 19:47:08 Nit: {} optional
felt 2014/02/05 19:57:26 I like brackets when the condition is split across
939 download()->Remove();
940 }
941 // WARNING: 'this' is deleted at this point. Don't access 'this'.
942 }
943
917 void DownloadItemView::LoadIcon() { 944 void DownloadItemView::LoadIcon() {
918 IconManager* im = g_browser_process->icon_manager(); 945 IconManager* im = g_browser_process->icon_manager();
919 last_download_item_path_ = download()->GetTargetFilePath(); 946 last_download_item_path_ = download()->GetTargetFilePath();
920 im->LoadIcon(last_download_item_path_, 947 im->LoadIcon(last_download_item_path_,
921 IconLoader::SMALL, 948 IconLoader::SMALL,
922 base::Bind(&DownloadItemView::OnExtractIconComplete, 949 base::Bind(&DownloadItemView::OnExtractIconComplete,
923 base::Unretained(this)), 950 base::Unretained(this)),
924 &cancelable_task_tracker_); 951 &cancelable_task_tracker_);
925 } 952 }
926 953
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 body_state_ = NORMAL; 1161 body_state_ = NORMAL;
1135 drop_down_state_ = NORMAL; 1162 drop_down_state_ = NORMAL;
1136 if (mode_ == DANGEROUS_MODE) { 1163 if (mode_ == DANGEROUS_MODE) {
1137 save_button_ = new views::LabelButton( 1164 save_button_ = new views::LabelButton(
1138 this, model_.GetWarningConfirmButtonText()); 1165 this, model_.GetWarningConfirmButtonText());
1139 save_button_->SetStyle(views::Button::STYLE_BUTTON); 1166 save_button_->SetStyle(views::Button::STYLE_BUTTON);
1140 AddChildView(save_button_); 1167 AddChildView(save_button_);
1141 } 1168 }
1142 int discard_button_message = model_.IsMalicious() ? 1169 int discard_button_message = model_.IsMalicious() ?
1143 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; 1170 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( 1171 discard_button_ = new views::LabelButton(
1147 this, l10n_util::GetStringUTF16(discard_button_message)); 1172 this, l10n_util::GetStringUTF16(discard_button_message));
1148 discard_button_->SetStyle(views::Button::STYLE_BUTTON); 1173 discard_button_->SetStyle(views::Button::STYLE_BUTTON);
1149 AddChildView(discard_button_); 1174 AddChildView(discard_button_);
1150 1175
1151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1176 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1152 switch (danger_type) { 1177 switch (danger_type) {
1153 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: 1178 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
1154 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: 1179 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
1155 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: 1180 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT:
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 void DownloadItemView::AnimateStateTransition(State from, State to, 1344 void DownloadItemView::AnimateStateTransition(State from, State to,
1320 gfx::SlideAnimation* animation) { 1345 gfx::SlideAnimation* animation) {
1321 if (from == NORMAL && to == HOT) { 1346 if (from == NORMAL && to == HOT) {
1322 animation->Show(); 1347 animation->Show();
1323 } else if (from == HOT && to == NORMAL) { 1348 } else if (from == HOT && to == NORMAL) {
1324 animation->Hide(); 1349 animation->Hide();
1325 } else if (from != to) { 1350 } else if (from != to) {
1326 animation->Reset((to == HOT) ? 1.0 : 0.0); 1351 animation->Reset((to == HOT) ? 1.0 : 0.0);
1327 } 1352 }
1328 } 1353 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_item_view.h ('k') | chrome/browser/ui/views/download/download_shelf_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698