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

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

Issue 402293002: Experience sampling instrumentation for dangerous downloads warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sampling-api
Patch Set: Add missing constants to Cocoa version Created 6 years, 4 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/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
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 18 matching lines...) Expand all
85 87
86 // How long we keep the item disabled after the user clicked it to open the 88 // How long we keep the item disabled after the user clicked it to open the
87 // downloaded item. 89 // downloaded item.
88 static const int kDisabledOnOpenDuration = 3000; 90 static const int kDisabledOnOpenDuration = 3000;
89 91
90 // Darken light-on-dark download status text by 20% before drawing, thus 92 // Darken light-on-dark download status text by 20% before drawing, thus
91 // creating a "muted" version of title text for both dark-on-light and 93 // creating a "muted" version of title text for both dark-on-light and
92 // light-on-dark themes. 94 // light-on-dark themes.
93 static const double kDownloadItemLuminanceMod = 0.8; 95 static const double kDownloadItemLuminanceMod = 0.8;
94 96
97 // Constants for the Experience Sampling instrumentation.
98 const char kEventNameMalicious[] = "download_warning_malicious";
msw 2014/08/13 20:11:37 These string constants should be shared between Co
Chris Thompson 2014/08/13 21:18:00 Done. Moved these to experience_sampling.h.
99 const char kEventNameDangerous[] = "download_warning_dangerous";
100
95 namespace { 101 namespace {
96 102
97 // Callback for DownloadShelf paint functions to mirror the progress animation 103 // Callback for DownloadShelf paint functions to mirror the progress animation
98 // in RTL locales. 104 // in RTL locales.
99 void RTLMirrorXForView(views::View* containing_view, gfx::Rect* bounds) { 105 void RTLMirrorXForView(views::View* containing_view, gfx::Rect* bounds) {
100 bounds->set_x(containing_view->GetMirroredXForRect(*bounds)); 106 bounds->set_x(containing_view->GetMirroredXForRect(*bounds));
101 } 107 }
102 108
103 } // namespace 109 } // namespace
104 110
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 229
224 SetAccessibilityFocusable(true); 230 SetAccessibilityFocusable(true);
225 231
226 OnDownloadUpdated(download()); 232 OnDownloadUpdated(download());
227 UpdateDropDownButtonPosition(); 233 UpdateDropDownButtonPosition();
228 } 234 }
229 235
230 DownloadItemView::~DownloadItemView() { 236 DownloadItemView::~DownloadItemView() {
231 StopDownloadProgress(); 237 StopDownloadProgress();
232 download()->RemoveObserver(this); 238 download()->RemoveObserver(this);
239
240 // Experience Sampling: If the user took no action to remove the warning
msw 2014/08/13 20:11:37 What's the use for this info? Wouldn't allow/deny/
Chris Thompson 2014/08/13 21:18:00 Changed this to "ignore".
241 // before it disappeared, then the user effectively dismissed the download
242 // without keeping it.
243 if (mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE)
244 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
233 } 245 }
234 246
235 // Progress animation handlers. 247 // Progress animation handlers.
236 248
237 void DownloadItemView::UpdateDownloadProgress() { 249 void DownloadItemView::UpdateDownloadProgress() {
238 progress_angle_ = 250 progress_angle_ =
239 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) % 251 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) %
240 DownloadShelf::kMaxDegrees; 252 DownloadShelf::kMaxDegrees;
241 SchedulePaint(); 253 SchedulePaint();
242 } 254 }
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1132
1121 void DownloadItemView::ClearWarningDialog() { 1133 void DownloadItemView::ClearWarningDialog() {
1122 DCHECK(download()->GetDangerType() == 1134 DCHECK(download()->GetDangerType() ==
1123 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); 1135 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
1124 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); 1136 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE);
1125 1137
1126 mode_ = NORMAL_MODE; 1138 mode_ = NORMAL_MODE;
1127 body_state_ = NORMAL; 1139 body_state_ = NORMAL;
1128 drop_down_state_ = NORMAL; 1140 drop_down_state_ = NORMAL;
1129 1141
1142 // ExperienceSampling: User proceeded through the warning.
msw 2014/08/13 20:11:37 Use "Experience Sampling" or "ExperienceSampling"
Chris Thompson 2014/08/13 21:18:00 Done. s/Experience Sampling/ExperienceSampling/g
1143 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
1144
1130 // Remove the views used by the warning dialog. 1145 // Remove the views used by the warning dialog.
1131 if (save_button_) { 1146 if (save_button_) {
1132 RemoveChildView(save_button_); 1147 RemoveChildView(save_button_);
1133 delete save_button_; 1148 delete save_button_;
1134 save_button_ = NULL; 1149 save_button_ = NULL;
1135 } 1150 }
1136 RemoveChildView(discard_button_); 1151 RemoveChildView(discard_button_);
1137 delete discard_button_; 1152 delete discard_button_;
1138 discard_button_ = NULL; 1153 discard_button_ = NULL;
1139 RemoveChildView(dangerous_download_label_); 1154 RemoveChildView(dangerous_download_label_);
(...skipping 23 matching lines...) Expand all
1163 content::DownloadDangerType danger_type = download()->GetDangerType(); 1178 content::DownloadDangerType danger_type = download()->GetDangerType();
1164 RecordDangerousDownloadWarningShown(danger_type); 1179 RecordDangerousDownloadWarningShown(danger_type);
1165 #if defined(FULL_SAFE_BROWSING) 1180 #if defined(FULL_SAFE_BROWSING)
1166 if (model_.ShouldAllowDownloadFeedback()) { 1181 if (model_.ShouldAllowDownloadFeedback()) {
1167 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( 1182 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown(
1168 danger_type); 1183 danger_type);
1169 } 1184 }
1170 #endif 1185 #endif
1171 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; 1186 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE;
1172 1187
1188 // ExperienceSampling: Dangerous or malicious download warning is being shown
1189 // to the user, so we start a new SamplingEvent and track it.
1190 std::string event_name = model_.MightBeMalicious() ?
1191 kEventNameMalicious
1192 : kEventNameDangerous;
msw 2014/08/13 20:11:37 This formatting is incorrect, use "git cl format"
Chris Thompson 2014/08/13 21:18:00 Done. Missed this in an edit that shortened the li
1193 sampling_event_.reset(new ExperienceSamplingEvent(
msw 2014/08/13 20:11:37 Yikes, I really hope this has undergone security r
Chris Thompson 2014/08/13 21:18:00 Do you have particular concerns about this use of
msw 2014/08/14 01:48:33 No, my point was more about reporting url, referre
1194 event_name,
1195 download()->GetURL(),
1196 download()->GetReferrerUrl(),
1197 download()->GetBrowserContext()));
1198
1173 body_state_ = NORMAL; 1199 body_state_ = NORMAL;
1174 drop_down_state_ = NORMAL; 1200 drop_down_state_ = NORMAL;
1175 if (mode_ == DANGEROUS_MODE) { 1201 if (mode_ == DANGEROUS_MODE) {
1176 save_button_ = new views::LabelButton( 1202 save_button_ = new views::LabelButton(
1177 this, model_.GetWarningConfirmButtonText()); 1203 this, model_.GetWarningConfirmButtonText());
1178 save_button_->SetStyle(views::Button::STYLE_BUTTON); 1204 save_button_->SetStyle(views::Button::STYLE_BUTTON);
1179 AddChildView(save_button_); 1205 AddChildView(save_button_);
1180 } 1206 }
1181 int discard_button_message = model_.IsMalicious() ? 1207 int discard_button_message = model_.IsMalicious() ?
1182 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; 1208 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 void DownloadItemView::AnimateStateTransition(State from, State to, 1382 void DownloadItemView::AnimateStateTransition(State from, State to,
1357 gfx::SlideAnimation* animation) { 1383 gfx::SlideAnimation* animation) {
1358 if (from == NORMAL && to == HOT) { 1384 if (from == NORMAL && to == HOT) {
1359 animation->Show(); 1385 animation->Show();
1360 } else if (from == HOT && to == NORMAL) { 1386 } else if (from == HOT && to == NORMAL) {
1361 animation->Hide(); 1387 animation->Hide();
1362 } else if (from != to) { 1388 } else if (from != to) {
1363 animation->Reset((to == HOT) ? 1.0 : 0.0); 1389 animation->Reset((to == HOT) ? 1.0 : 0.0);
1364 } 1390 }
1365 } 1391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698