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/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 22 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
23 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
24 #include "chrome/browser/download/download_stats.h" | 24 #include "chrome/browser/download/download_stats.h" |
25 #include "chrome/browser/download/drag_download_item.h" | 25 #include "chrome/browser/download/drag_download_item.h" |
| 26 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 28 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
28 #include "chrome/browser/safe_browsing/download_protection_service.h" | 29 #include "chrome/browser/safe_browsing/download_protection_service.h" |
29 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
30 #include "chrome/browser/themes/theme_properties.h" | 31 #include "chrome/browser/themes/theme_properties.h" |
31 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" | 32 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" |
32 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" | 33 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" |
33 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 34 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
34 #include "chrome/browser/ui/views/frame/browser_view.h" | 35 #include "chrome/browser/ui/views/frame/browser_view.h" |
35 #include "content/public/browser/download_danger_type.h" | 36 #include "content/public/browser/download_danger_type.h" |
(...skipping 11 matching lines...) Expand all Loading... |
47 #include "ui/gfx/image/image.h" | 48 #include "ui/gfx/image/image.h" |
48 #include "ui/gfx/text_elider.h" | 49 #include "ui/gfx/text_elider.h" |
49 #include "ui/gfx/text_utils.h" | 50 #include "ui/gfx/text_utils.h" |
50 #include "ui/views/controls/button/label_button.h" | 51 #include "ui/views/controls/button/label_button.h" |
51 #include "ui/views/controls/label.h" | 52 #include "ui/views/controls/label.h" |
52 #include "ui/views/mouse_constants.h" | 53 #include "ui/views/mouse_constants.h" |
53 #include "ui/views/widget/root_view.h" | 54 #include "ui/views/widget/root_view.h" |
54 #include "ui/views/widget/widget.h" | 55 #include "ui/views/widget/widget.h" |
55 | 56 |
56 using content::DownloadItem; | 57 using content::DownloadItem; |
| 58 using extensions::ExperienceSamplingEvent; |
57 | 59 |
58 // TODO(paulg): These may need to be adjusted when download progress | 60 // TODO(paulg): These may need to be adjusted when download progress |
59 // animation is added, and also possibly to take into account | 61 // animation is added, and also possibly to take into account |
60 // different screen resolutions. | 62 // different screen resolutions. |
61 static const int kTextWidth = 140; // Pixels | 63 static const int kTextWidth = 140; // Pixels |
62 static const int kDangerousTextWidth = 200; // Pixels | 64 static const int kDangerousTextWidth = 200; // Pixels |
63 static const int kVerticalPadding = 3; // Pixels | 65 static const int kVerticalPadding = 3; // Pixels |
64 static const int kVerticalTextPadding = 2; // Pixels | 66 static const int kVerticalTextPadding = 2; // Pixels |
65 static const int kTooltipMaxWidth = 800; // Pixels | 67 static const int kTooltipMaxWidth = 800; // Pixels |
66 | 68 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 225 |
224 SetAccessibilityFocusable(true); | 226 SetAccessibilityFocusable(true); |
225 | 227 |
226 OnDownloadUpdated(download()); | 228 OnDownloadUpdated(download()); |
227 UpdateDropDownButtonPosition(); | 229 UpdateDropDownButtonPosition(); |
228 } | 230 } |
229 | 231 |
230 DownloadItemView::~DownloadItemView() { | 232 DownloadItemView::~DownloadItemView() { |
231 StopDownloadProgress(); | 233 StopDownloadProgress(); |
232 download()->RemoveObserver(this); | 234 download()->RemoveObserver(this); |
| 235 |
| 236 // ExperienceSampling: If the user took no action to remove the warning |
| 237 // before it disappeared, then the user effectively dismissed the download |
| 238 // without keeping it. |
| 239 if (sampling_event_.get()) |
| 240 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); |
233 } | 241 } |
234 | 242 |
235 // Progress animation handlers. | 243 // Progress animation handlers. |
236 | 244 |
237 void DownloadItemView::UpdateDownloadProgress() { | 245 void DownloadItemView::UpdateDownloadProgress() { |
238 progress_angle_ = | 246 progress_angle_ = |
239 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) % | 247 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) % |
240 DownloadShelf::kMaxDegrees; | 248 DownloadShelf::kMaxDegrees; |
241 SchedulePaint(); | 249 SchedulePaint(); |
242 } | 250 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 void DownloadItemView::ButtonPressed(views::Button* sender, | 551 void DownloadItemView::ButtonPressed(views::Button* sender, |
544 const ui::Event& event) { | 552 const ui::Event& event) { |
545 base::TimeDelta warning_duration; | 553 base::TimeDelta warning_duration; |
546 if (!time_download_warning_shown_.is_null()) | 554 if (!time_download_warning_shown_.is_null()) |
547 warning_duration = base::Time::Now() - time_download_warning_shown_; | 555 warning_duration = base::Time::Now() - time_download_warning_shown_; |
548 | 556 |
549 if (save_button_ && sender == save_button_) { | 557 if (save_button_ && sender == save_button_) { |
550 // The user has confirmed a dangerous download. We'd record how quickly the | 558 // The user has confirmed a dangerous download. We'd record how quickly the |
551 // user did this to detect whether we're being clickjacked. | 559 // user did this to detect whether we're being clickjacked. |
552 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration); | 560 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration); |
| 561 // ExperienceSampling: User chose to proceed with a dangerous download. |
| 562 if (sampling_event_.get()) { |
| 563 sampling_event_->CreateUserDecisionEvent( |
| 564 ExperienceSamplingEvent::kProceed); |
| 565 sampling_event_.reset(NULL); |
| 566 } |
553 // This will change the state and notify us. | 567 // This will change the state and notify us. |
554 download()->ValidateDangerousDownload(); | 568 download()->ValidateDangerousDownload(); |
555 return; | 569 return; |
556 } | 570 } |
557 | 571 |
558 // WARNING: all end states after this point delete |this|. | 572 // WARNING: all end states after this point delete |this|. |
559 DCHECK_EQ(discard_button_, sender); | 573 DCHECK_EQ(discard_button_, sender); |
560 if (model_.IsMalicious()) { | 574 if (model_.IsMalicious()) { |
561 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); | 575 UMA_HISTOGRAM_LONG_TIMES("clickjacking.dismiss_download", warning_duration); |
| 576 // ExperienceSampling: User chose to dismiss the dangerous download. |
| 577 if (sampling_event_.get()) { |
| 578 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
| 579 sampling_event_.reset(NULL); |
| 580 } |
562 shelf_->RemoveDownloadView(this); | 581 shelf_->RemoveDownloadView(this); |
563 return; | 582 return; |
564 } | 583 } |
565 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 584 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
566 if (model_.ShouldAllowDownloadFeedback() && | 585 if (model_.ShouldAllowDownloadFeedback() && |
567 !shelf_->browser()->profile()->IsOffTheRecord()) { | 586 !shelf_->browser()->profile()->IsOffTheRecord()) { |
568 if (!shelf_->browser()->profile()->GetPrefs()->HasPrefPath( | 587 if (!shelf_->browser()->profile()->GetPrefs()->HasPrefPath( |
569 prefs::kSafeBrowsingExtendedReportingEnabled)) { | 588 prefs::kSafeBrowsingExtendedReportingEnabled)) { |
570 // Show dialog, because the dialog hasn't been shown before. | 589 // Show dialog, because the dialog hasn't been shown before. |
571 DownloadFeedbackDialogView::Show( | 590 DownloadFeedbackDialogView::Show( |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1139 |
1121 void DownloadItemView::ClearWarningDialog() { | 1140 void DownloadItemView::ClearWarningDialog() { |
1122 DCHECK(download()->GetDangerType() == | 1141 DCHECK(download()->GetDangerType() == |
1123 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); | 1142 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); |
1124 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); | 1143 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); |
1125 | 1144 |
1126 mode_ = NORMAL_MODE; | 1145 mode_ = NORMAL_MODE; |
1127 body_state_ = NORMAL; | 1146 body_state_ = NORMAL; |
1128 drop_down_state_ = NORMAL; | 1147 drop_down_state_ = NORMAL; |
1129 | 1148 |
| 1149 // ExperienceSampling: User proceeded through the warning. |
| 1150 if (sampling_event_.get()) { |
| 1151 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
| 1152 sampling_event_.reset(NULL); |
| 1153 } |
1130 // Remove the views used by the warning dialog. | 1154 // Remove the views used by the warning dialog. |
1131 if (save_button_) { | 1155 if (save_button_) { |
1132 RemoveChildView(save_button_); | 1156 RemoveChildView(save_button_); |
1133 delete save_button_; | 1157 delete save_button_; |
1134 save_button_ = NULL; | 1158 save_button_ = NULL; |
1135 } | 1159 } |
1136 RemoveChildView(discard_button_); | 1160 RemoveChildView(discard_button_); |
1137 delete discard_button_; | 1161 delete discard_button_; |
1138 discard_button_ = NULL; | 1162 discard_button_ = NULL; |
1139 RemoveChildView(dangerous_download_label_); | 1163 RemoveChildView(dangerous_download_label_); |
(...skipping 23 matching lines...) Expand all Loading... |
1163 content::DownloadDangerType danger_type = download()->GetDangerType(); | 1187 content::DownloadDangerType danger_type = download()->GetDangerType(); |
1164 RecordDangerousDownloadWarningShown(danger_type); | 1188 RecordDangerousDownloadWarningShown(danger_type); |
1165 #if defined(FULL_SAFE_BROWSING) | 1189 #if defined(FULL_SAFE_BROWSING) |
1166 if (model_.ShouldAllowDownloadFeedback()) { | 1190 if (model_.ShouldAllowDownloadFeedback()) { |
1167 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( | 1191 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( |
1168 danger_type); | 1192 danger_type); |
1169 } | 1193 } |
1170 #endif | 1194 #endif |
1171 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; | 1195 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; |
1172 | 1196 |
| 1197 // ExperienceSampling: Dangerous or malicious download warning is being shown |
| 1198 // to the user, so we start a new SamplingEvent and track it. |
| 1199 std::string event_name = model_.MightBeMalicious() |
| 1200 ? ExperienceSamplingEvent::kMaliciousDownload |
| 1201 : ExperienceSamplingEvent::kDangerousDownload; |
| 1202 sampling_event_.reset( |
| 1203 new ExperienceSamplingEvent(event_name, |
| 1204 download()->GetURL(), |
| 1205 download()->GetReferrerUrl(), |
| 1206 download()->GetBrowserContext())); |
| 1207 |
1173 body_state_ = NORMAL; | 1208 body_state_ = NORMAL; |
1174 drop_down_state_ = NORMAL; | 1209 drop_down_state_ = NORMAL; |
1175 if (mode_ == DANGEROUS_MODE) { | 1210 if (mode_ == DANGEROUS_MODE) { |
1176 save_button_ = new views::LabelButton( | 1211 save_button_ = new views::LabelButton( |
1177 this, model_.GetWarningConfirmButtonText()); | 1212 this, model_.GetWarningConfirmButtonText()); |
1178 save_button_->SetStyle(views::Button::STYLE_BUTTON); | 1213 save_button_->SetStyle(views::Button::STYLE_BUTTON); |
1179 AddChildView(save_button_); | 1214 AddChildView(save_button_); |
1180 } | 1215 } |
1181 int discard_button_message = model_.IsMalicious() ? | 1216 int discard_button_message = model_.IsMalicious() ? |
1182 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; | 1217 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 void DownloadItemView::AnimateStateTransition(State from, State to, | 1391 void DownloadItemView::AnimateStateTransition(State from, State to, |
1357 gfx::SlideAnimation* animation) { | 1392 gfx::SlideAnimation* animation) { |
1358 if (from == NORMAL && to == HOT) { | 1393 if (from == NORMAL && to == HOT) { |
1359 animation->Show(); | 1394 animation->Show(); |
1360 } else if (from == HOT && to == NORMAL) { | 1395 } else if (from == HOT && to == NORMAL) { |
1361 animation->Hide(); | 1396 animation->Hide(); |
1362 } else if (from != to) { | 1397 } else if (from != to) { |
1363 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1398 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1364 } | 1399 } |
1365 } | 1400 } |
OLD | NEW |