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 (mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE) | |
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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 | 1128 |
1121 void DownloadItemView::ClearWarningDialog() { | 1129 void DownloadItemView::ClearWarningDialog() { |
1122 DCHECK(download()->GetDangerType() == | 1130 DCHECK(download()->GetDangerType() == |
1123 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); | 1131 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); |
1124 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); | 1132 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); |
1125 | 1133 |
1126 mode_ = NORMAL_MODE; | 1134 mode_ = NORMAL_MODE; |
1127 body_state_ = NORMAL; | 1135 body_state_ = NORMAL; |
1128 drop_down_state_ = NORMAL; | 1136 drop_down_state_ = NORMAL; |
1129 | 1137 |
1138 // ExperienceSampling: User proceeded through the warning. | |
1139 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); | |
msw
2014/08/14 01:48:33
Can the user explicitly deny in Views like Cocoa's
Chris Thompson
2014/08/14 15:43:44
The dismiss button is handled in DownloadItemView:
Chris Thompson
2014/08/14 17:19:16
I've also reworked the instrumentation here a litt
msw
2014/08/14 17:56:44
Cool, the the latest patch set looks more complete
| |
1140 | |
1130 // Remove the views used by the warning dialog. | 1141 // Remove the views used by the warning dialog. |
1131 if (save_button_) { | 1142 if (save_button_) { |
1132 RemoveChildView(save_button_); | 1143 RemoveChildView(save_button_); |
1133 delete save_button_; | 1144 delete save_button_; |
1134 save_button_ = NULL; | 1145 save_button_ = NULL; |
1135 } | 1146 } |
1136 RemoveChildView(discard_button_); | 1147 RemoveChildView(discard_button_); |
1137 delete discard_button_; | 1148 delete discard_button_; |
1138 discard_button_ = NULL; | 1149 discard_button_ = NULL; |
1139 RemoveChildView(dangerous_download_label_); | 1150 RemoveChildView(dangerous_download_label_); |
(...skipping 23 matching lines...) Expand all Loading... | |
1163 content::DownloadDangerType danger_type = download()->GetDangerType(); | 1174 content::DownloadDangerType danger_type = download()->GetDangerType(); |
1164 RecordDangerousDownloadWarningShown(danger_type); | 1175 RecordDangerousDownloadWarningShown(danger_type); |
1165 #if defined(FULL_SAFE_BROWSING) | 1176 #if defined(FULL_SAFE_BROWSING) |
1166 if (model_.ShouldAllowDownloadFeedback()) { | 1177 if (model_.ShouldAllowDownloadFeedback()) { |
1167 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( | 1178 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( |
1168 danger_type); | 1179 danger_type); |
1169 } | 1180 } |
1170 #endif | 1181 #endif |
1171 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; | 1182 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; |
1172 | 1183 |
1184 // ExperienceSampling: Dangerous or malicious download warning is being shown | |
1185 // to the user, so we start a new SamplingEvent and track it. | |
1186 std::string event_name = | |
1187 model_.MightBeMalicious() | |
1188 ? ExperienceSamplingEvent::kEventNameMaliciousDownload | |
1189 : ExperienceSamplingEvent::kEventNameDangerousDownload; | |
1190 sampling_event_.reset( | |
1191 new ExperienceSamplingEvent(event_name, | |
1192 download()->GetURL(), | |
1193 download()->GetReferrerUrl(), | |
1194 download()->GetBrowserContext())); | |
1195 | |
1173 body_state_ = NORMAL; | 1196 body_state_ = NORMAL; |
1174 drop_down_state_ = NORMAL; | 1197 drop_down_state_ = NORMAL; |
1175 if (mode_ == DANGEROUS_MODE) { | 1198 if (mode_ == DANGEROUS_MODE) { |
1176 save_button_ = new views::LabelButton( | 1199 save_button_ = new views::LabelButton( |
1177 this, model_.GetWarningConfirmButtonText()); | 1200 this, model_.GetWarningConfirmButtonText()); |
1178 save_button_->SetStyle(views::Button::STYLE_BUTTON); | 1201 save_button_->SetStyle(views::Button::STYLE_BUTTON); |
1179 AddChildView(save_button_); | 1202 AddChildView(save_button_); |
1180 } | 1203 } |
1181 int discard_button_message = model_.IsMalicious() ? | 1204 int discard_button_message = model_.IsMalicious() ? |
1182 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; | 1205 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, | 1379 void DownloadItemView::AnimateStateTransition(State from, State to, |
1357 gfx::SlideAnimation* animation) { | 1380 gfx::SlideAnimation* animation) { |
1358 if (from == NORMAL && to == HOT) { | 1381 if (from == NORMAL && to == HOT) { |
1359 animation->Show(); | 1382 animation->Show(); |
1360 } else if (from == HOT && to == NORMAL) { | 1383 } else if (from == HOT && to == NORMAL) { |
1361 animation->Hide(); | 1384 animation->Hide(); |
1362 } else if (from != to) { | 1385 } else if (from != to) { |
1363 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1386 animation->Reset((to == HOT) ? 1.0 : 0.0); |
1364 } | 1387 } |
1365 } | 1388 } |
OLD | NEW |