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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_item_controller.mm

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 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" 5 #import "chrome/browser/ui/cocoa/download/download_item_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/download/chrome_download_manager_delegate.h" 14 #include "chrome/browser/download/chrome_download_manager_delegate.h"
15 #include "chrome/browser/download/download_item_model.h" 15 #include "chrome/browser/download/download_item_model.h"
16 #include "chrome/browser/download/download_shelf_context_menu.h" 16 #include "chrome/browser/download/download_shelf_context_menu.h"
17 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
17 #import "chrome/browser/themes/theme_properties.h" 18 #import "chrome/browser/themes/theme_properties.h"
18 #import "chrome/browser/themes/theme_service.h" 19 #import "chrome/browser/themes/theme_service.h"
19 #import "chrome/browser/ui/cocoa/download/download_item_button.h" 20 #import "chrome/browser/ui/cocoa/download/download_item_button.h"
20 #import "chrome/browser/ui/cocoa/download/download_item_cell.h" 21 #import "chrome/browser/ui/cocoa/download/download_item_cell.h"
21 #include "chrome/browser/ui/cocoa/download/download_item_mac.h" 22 #include "chrome/browser/ui/cocoa/download/download_item_mac.h"
22 #import "chrome/browser/ui/cocoa/download/download_shelf_context_menu_controller .h" 23 #import "chrome/browser/ui/cocoa/download/download_shelf_context_menu_controller .h"
23 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 24 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
24 #import "chrome/browser/ui/cocoa/themed_window.h" 25 #import "chrome/browser/ui/cocoa/themed_window.h"
25 #import "chrome/browser/ui/cocoa/ui_localizer.h" 26 #import "chrome/browser/ui/cocoa/ui_localizer.h"
26 #include "content/public/browser/download_item.h" 27 #include "content/public/browser/download_item.h"
27 #include "content/public/browser/page_navigator.h" 28 #include "content/public/browser/page_navigator.h"
28 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
29 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
30 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT weaker.h" 31 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT weaker.h"
31 #include "ui/base/l10n/l10n_util_mac.h" 32 #include "ui/base/l10n/l10n_util_mac.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/text_elider.h" 34 #include "ui/gfx/text_elider.h"
34 #include "ui/gfx/font.h" 35 #include "ui/gfx/font.h"
35 #include "ui/gfx/image/image.h" 36 #include "ui/gfx/image/image.h"
36 37
37 using content::DownloadItem; 38 using content::DownloadItem;
39 using extensions::ExperienceSamplingEvent;
38 40
39 namespace { 41 namespace {
40 42
43 // Constants for Experience Sampling.
44 const char kEventNameMalicious[] = "download_warning_malicious";
45 const char kEventNameDangerous[] = "download_warning_dangerous";
46
41 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to 47 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to
42 // control the min size on the dangerous download text. TVL sent a query off to 48 // control the min size on the dangerous download text. TVL sent a query off to
43 // UX to fully spec all the the behaviors of download items and truncations 49 // UX to fully spec all the the behaviors of download items and truncations
44 // rules so all platforms can get inline in the future. 50 // rules so all platforms can get inline in the future.
45 const int kTextWidth = 140; // Pixels 51 const int kTextWidth = 140; // Pixels
46 52
47 // The maximum width in pixels for the file name tooltip. 53 // The maximum width in pixels for the file name tooltip.
48 const int kToolTipMaxWidth = 900; 54 const int kToolTipMaxWidth = 900;
49 55
50 56
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 state_ = kNormal; 116 state_ = kNormal;
111 creationTime_ = base::Time::Now(); 117 creationTime_ = base::Time::Now();
112 font_list_.reset(new gfx::FontList( 118 font_list_.reset(new gfx::FontList(
113 ui::ResourceBundle::GetSharedInstance().GetFontList( 119 ui::ResourceBundle::GetSharedInstance().GetFontList(
114 ui::ResourceBundle::BaseFont))); 120 ui::ResourceBundle::BaseFont)));
115 } 121 }
116 return self; 122 return self;
117 } 123 }
118 124
119 - (void)dealloc { 125 - (void)dealloc {
126 if (sampling_event_.get())
127 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
120 [[NSNotificationCenter defaultCenter] removeObserver:self]; 128 [[NSNotificationCenter defaultCenter] removeObserver:self];
121 [progressView_ setController:nil]; 129 [progressView_ setController:nil];
122 [[self view] removeFromSuperview]; 130 [[self view] removeFromSuperview];
123 [super dealloc]; 131 [super dealloc];
124 } 132 }
125 133
126 - (void)awakeFromNib { 134 - (void)awakeFromNib {
127 [progressView_ setController:self]; 135 [progressView_ setController:self];
128 136
129 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = 137 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker =
130 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; 138 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease];
131 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; 139 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]];
132 140
133 [self setStateFromDownload:bridge_->download_model()]; 141 [self setStateFromDownload:bridge_->download_model()];
134 142
135 bridge_->LoadIcon(); 143 bridge_->LoadIcon();
136 [self updateToolTip]; 144 [self updateToolTip];
137 } 145 }
138 146
139 - (void)showDangerousWarning:(DownloadItemModel*)downloadModel { 147 - (void)showDangerousWarning:(DownloadItemModel*)downloadModel {
140 // The transition from safe -> dangerous should only happen once. The code 148 // The transition from safe -> dangerous should only happen once. The code
141 // assumes that the danger type of the download doesn't change once it's set. 149 // assumes that the danger type of the download doesn't change once it's set.
142 if ([self isDangerousMode]) 150 if ([self isDangerousMode])
143 return; 151 return;
144 152
145 [self setState:kDangerous]; 153 [self setState:kDangerous];
146 154
155 // ExperienceSampling: Dangerous or malicious download warning is being shown
156 // to the user, so we start a new SamplingEvent and track it.
157 std::string event_name = downloadModel->MightBeMalicious() ?
158 kEventNameMalicious
159 : kEventNameDangerous;
160 sampling_event_.reset(new ExperienceSamplingEvent(
161 event_name,
162 downloadModel->download()->GetURL(),
163 downloadModel->download()->GetReferrerUrl(),
164 downloadModel->download()->GetBrowserContext()));
165
147 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 166 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
148 NSImage* alertIcon; 167 NSImage* alertIcon;
149 168
150 NSString* dangerousWarning = base::SysUTF16ToNSString( 169 NSString* dangerousWarning = base::SysUTF16ToNSString(
151 downloadModel->GetWarningText(*font_list_, kTextWidth)); 170 downloadModel->GetWarningText(*font_list_, kTextWidth));
152 DCHECK(dangerousWarning); 171 DCHECK(dangerousWarning);
153 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; 172 [dangerousDownloadLabel_ setStringValue:dangerousWarning];
154 CGFloat labelWidthChange = 173 CGFloat labelWidthChange =
155 [GTMUILocalizerAndLayoutTweaker 174 [GTMUILocalizerAndLayoutTweaker
156 sizeToFitFixedHeightTextField:dangerousDownloadLabel_ 175 sizeToFitFixedHeightTextField:dangerousDownloadLabel_
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 332
314 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); 333 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT);
315 [dangerousDownloadLabel_ setTextColor:color]; 334 [dangerousDownloadLabel_ setTextColor:color];
316 } 335 }
317 336
318 - (IBAction)saveDownload:(id)sender { 337 - (IBAction)saveDownload:(id)sender {
319 // The user has confirmed a dangerous download. We record how quickly the 338 // The user has confirmed a dangerous download. We record how quickly the
320 // user did this to detect whether we're being clickjacked. 339 // user did this to detect whether we're being clickjacked.
321 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 340 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
322 base::Time::Now() - creationTime_); 341 base::Time::Now() - creationTime_);
342 // ExperienceSampling: User chose to proceed with dangerous download.
343 if (sampling_event_.get()) {
344 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
345 sampling_event_.reset(NULL);
346 }
323 // This will change the state and notify us. 347 // This will change the state and notify us.
324 bridge_->download_model()->download()->ValidateDangerousDownload(); 348 bridge_->download_model()->download()->ValidateDangerousDownload();
325 } 349 }
326 350
327 - (IBAction)discardDownload:(id)sender { 351 - (IBAction)discardDownload:(id)sender {
328 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 352 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
329 base::Time::Now() - creationTime_); 353 base::Time::Now() - creationTime_);
330 DownloadItem* download = bridge_->download_model()->download(); 354 DownloadItem* download = bridge_->download_model()->download();
331 download->Remove(); 355 download->Remove();
332 // WARNING: we are deleted at this point. Don't access 'this'. 356 // WARNING: we are deleted at this point. Don't access 'this'.
333 } 357 }
334 358
335 - (IBAction)dismissMaliciousDownload:(id)sender { 359 - (IBAction)dismissMaliciousDownload:(id)sender {
360 // ExperienceSampling: User dismissed the dangerous download.
361 if (sampling_event_.get()) {
362 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
363 sampling_event_.reset(NULL);
364 }
336 [self remove]; 365 [self remove];
337 // WARNING: we are deleted at this point. 366 // WARNING: we are deleted at this point.
338 } 367 }
339 368
340 - (IBAction)showContextMenu:(id)sender { 369 - (IBAction)showContextMenu:(id)sender {
341 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( 370 base::scoped_nsobject<DownloadShelfContextMenuController> menuController(
342 [[DownloadShelfContextMenuController alloc] 371 [[DownloadShelfContextMenuController alloc]
343 initWithItemController:self 372 initWithItemController:self
344 withDelegate:nil]); 373 withDelegate:nil]);
345 [NSMenu popUpContextMenu:[menuController menu] 374 [NSMenu popUpContextMenu:[menuController menu]
346 withEvent:[NSApp currentEvent] 375 withEvent:[NSApp currentEvent]
347 forView:[self view]]; 376 forView:[self view]];
348 } 377 }
349 378
350 @end 379 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698