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

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: Address reviewer comments 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
41 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to 43 // 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 44 // 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 45 // UX to fully spec all the the behaviors of download items and truncations
44 // rules so all platforms can get inline in the future. 46 // rules so all platforms can get inline in the future.
45 const int kTextWidth = 140; // Pixels 47 const int kTextWidth = 140; // Pixels
46 48
47 // The maximum width in pixels for the file name tooltip. 49 // The maximum width in pixels for the file name tooltip.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 state_ = kNormal; 112 state_ = kNormal;
111 creationTime_ = base::Time::Now(); 113 creationTime_ = base::Time::Now();
112 font_list_.reset(new gfx::FontList( 114 font_list_.reset(new gfx::FontList(
113 ui::ResourceBundle::GetSharedInstance().GetFontList( 115 ui::ResourceBundle::GetSharedInstance().GetFontList(
114 ui::ResourceBundle::BaseFont))); 116 ui::ResourceBundle::BaseFont)));
115 } 117 }
116 return self; 118 return self;
117 } 119 }
118 120
119 - (void)dealloc { 121 - (void)dealloc {
122 if (sampling_event_.get())
123 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore);
120 [[NSNotificationCenter defaultCenter] removeObserver:self]; 124 [[NSNotificationCenter defaultCenter] removeObserver:self];
121 [progressView_ setController:nil]; 125 [progressView_ setController:nil];
122 [[self view] removeFromSuperview]; 126 [[self view] removeFromSuperview];
123 [super dealloc]; 127 [super dealloc];
124 } 128 }
125 129
126 - (void)awakeFromNib { 130 - (void)awakeFromNib {
127 [progressView_ setController:self]; 131 [progressView_ setController:self];
128 132
129 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = 133 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker =
130 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; 134 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease];
131 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; 135 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]];
132 136
133 [self setStateFromDownload:bridge_->download_model()]; 137 [self setStateFromDownload:bridge_->download_model()];
134 138
135 bridge_->LoadIcon(); 139 bridge_->LoadIcon();
136 [self updateToolTip]; 140 [self updateToolTip];
137 } 141 }
138 142
139 - (void)showDangerousWarning:(DownloadItemModel*)downloadModel { 143 - (void)showDangerousWarning:(DownloadItemModel*)downloadModel {
140 // The transition from safe -> dangerous should only happen once. The code 144 // 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. 145 // assumes that the danger type of the download doesn't change once it's set.
142 if ([self isDangerousMode]) 146 if ([self isDangerousMode])
143 return; 147 return;
144 148
145 [self setState:kDangerous]; 149 [self setState:kDangerous];
146 150
151 // ExperienceSampling: Dangerous or malicious download warning is being shown
152 // to the user, so we start a new SamplingEvent and track it.
153 std::string event_name =
154 downloadModel->MightBeMalicious()
155 ? ExperienceSamplingEvent::kEventNameMaliciousDownload
msw 2014/08/14 01:48:33 Wow, is this what git cl format does? I'm surprise
Chris Thompson 2014/08/14 15:43:44 Yep. The line is just long enough to make any othe
156 : ExperienceSamplingEvent::kEventNameDangerousDownload;
157 sampling_event_.reset(new ExperienceSamplingEvent(
158 event_name,
159 downloadModel->download()->GetURL(),
160 downloadModel->download()->GetReferrerUrl(),
161 downloadModel->download()->GetBrowserContext()));
162
147 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 163 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
148 NSImage* alertIcon; 164 NSImage* alertIcon;
149 165
150 NSString* dangerousWarning = base::SysUTF16ToNSString( 166 NSString* dangerousWarning = base::SysUTF16ToNSString(
151 downloadModel->GetWarningText(*font_list_, kTextWidth)); 167 downloadModel->GetWarningText(*font_list_, kTextWidth));
152 DCHECK(dangerousWarning); 168 DCHECK(dangerousWarning);
153 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; 169 [dangerousDownloadLabel_ setStringValue:dangerousWarning];
154 CGFloat labelWidthChange = 170 CGFloat labelWidthChange =
155 [GTMUILocalizerAndLayoutTweaker 171 [GTMUILocalizerAndLayoutTweaker
156 sizeToFitFixedHeightTextField:dangerousDownloadLabel_ 172 sizeToFitFixedHeightTextField:dangerousDownloadLabel_
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 329
314 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); 330 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT);
315 [dangerousDownloadLabel_ setTextColor:color]; 331 [dangerousDownloadLabel_ setTextColor:color];
316 } 332 }
317 333
318 - (IBAction)saveDownload:(id)sender { 334 - (IBAction)saveDownload:(id)sender {
319 // The user has confirmed a dangerous download. We record how quickly the 335 // The user has confirmed a dangerous download. We record how quickly the
320 // user did this to detect whether we're being clickjacked. 336 // user did this to detect whether we're being clickjacked.
321 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 337 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
322 base::Time::Now() - creationTime_); 338 base::Time::Now() - creationTime_);
339 // ExperienceSampling: User chose to proceed with dangerous download.
340 if (sampling_event_.get()) {
341 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
342 sampling_event_.reset(NULL);
343 }
323 // This will change the state and notify us. 344 // This will change the state and notify us.
324 bridge_->download_model()->download()->ValidateDangerousDownload(); 345 bridge_->download_model()->download()->ValidateDangerousDownload();
325 } 346 }
326 347
327 - (IBAction)discardDownload:(id)sender { 348 - (IBAction)discardDownload:(id)sender {
328 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 349 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
329 base::Time::Now() - creationTime_); 350 base::Time::Now() - creationTime_);
330 DownloadItem* download = bridge_->download_model()->download(); 351 DownloadItem* download = bridge_->download_model()->download();
331 download->Remove(); 352 download->Remove();
332 // WARNING: we are deleted at this point. Don't access 'this'. 353 // WARNING: we are deleted at this point. Don't access 'this'.
333 } 354 }
334 355
335 - (IBAction)dismissMaliciousDownload:(id)sender { 356 - (IBAction)dismissMaliciousDownload:(id)sender {
357 // ExperienceSampling: User dismissed the dangerous download.
358 if (sampling_event_.get()) {
359 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
360 sampling_event_.reset(NULL);
361 }
336 [self remove]; 362 [self remove];
337 // WARNING: we are deleted at this point. 363 // WARNING: we are deleted at this point.
338 } 364 }
339 365
340 - (IBAction)showContextMenu:(id)sender { 366 - (IBAction)showContextMenu:(id)sender {
341 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( 367 base::scoped_nsobject<DownloadShelfContextMenuController> menuController(
342 [[DownloadShelfContextMenuController alloc] 368 [[DownloadShelfContextMenuController alloc]
343 initWithItemController:self 369 initWithItemController:self
344 withDelegate:nil]); 370 withDelegate:nil]);
345 [NSMenu popUpContextMenu:[menuController menu] 371 [NSMenu popUpContextMenu:[menuController menu]
346 withEvent:[NSApp currentEvent] 372 withEvent:[NSApp currentEvent]
347 forView:[self view]]; 373 forView:[self view]];
348 } 374 }
349 375
350 @end 376 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698