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 #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 Loading... | |
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::kDeny); | |
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 = downloadModel->MightBeMalcious() ? | |
felt
2014/08/11 21:57:27
MightBeMalicious()
Chris Thompson
2014/08/11 22:00:50
Done.
| |
154 kEventNameMalicious | |
155 : kEventNameDangerous; | |
156 sampling_event_.reset(new ExperienceSamplingEvent( | |
157 event_name, | |
158 downloadModel->download()->GetURL(), | |
159 downloadModel->download()->GetReferrerUrl(), | |
160 downloadModel->download()->GetBrowserContext())); | |
161 | |
147 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 162 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
148 NSImage* alertIcon; | 163 NSImage* alertIcon; |
149 | 164 |
150 NSString* dangerousWarning = base::SysUTF16ToNSString( | 165 NSString* dangerousWarning = base::SysUTF16ToNSString( |
151 downloadModel->GetWarningText(*font_list_, kTextWidth)); | 166 downloadModel->GetWarningText(*font_list_, kTextWidth)); |
152 DCHECK(dangerousWarning); | 167 DCHECK(dangerousWarning); |
153 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; | 168 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; |
154 CGFloat labelWidthChange = | 169 CGFloat labelWidthChange = |
155 [GTMUILocalizerAndLayoutTweaker | 170 [GTMUILocalizerAndLayoutTweaker |
156 sizeToFitFixedHeightTextField:dangerousDownloadLabel_ | 171 sizeToFitFixedHeightTextField:dangerousDownloadLabel_ |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 | 328 |
314 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); | 329 NSColor* color = themeProvider->GetNSColor(ThemeProperties::COLOR_TAB_TEXT); |
315 [dangerousDownloadLabel_ setTextColor:color]; | 330 [dangerousDownloadLabel_ setTextColor:color]; |
316 } | 331 } |
317 | 332 |
318 - (IBAction)saveDownload:(id)sender { | 333 - (IBAction)saveDownload:(id)sender { |
319 // The user has confirmed a dangerous download. We record how quickly the | 334 // The user has confirmed a dangerous download. We record how quickly the |
320 // user did this to detect whether we're being clickjacked. | 335 // user did this to detect whether we're being clickjacked. |
321 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 336 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
322 base::Time::Now() - creationTime_); | 337 base::Time::Now() - creationTime_); |
338 // ExperienceSampling: User chose to proceed with dangerous download. | |
339 if (sampling_event_.get()) { | |
340 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); | |
341 sampling_event_.reset(NULL); | |
342 } | |
323 // This will change the state and notify us. | 343 // This will change the state and notify us. |
324 bridge_->download_model()->download()->ValidateDangerousDownload(); | 344 bridge_->download_model()->download()->ValidateDangerousDownload(); |
325 } | 345 } |
326 | 346 |
327 - (IBAction)discardDownload:(id)sender { | 347 - (IBAction)discardDownload:(id)sender { |
328 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 348 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
329 base::Time::Now() - creationTime_); | 349 base::Time::Now() - creationTime_); |
330 DownloadItem* download = bridge_->download_model()->download(); | 350 DownloadItem* download = bridge_->download_model()->download(); |
331 download->Remove(); | 351 download->Remove(); |
332 // WARNING: we are deleted at this point. Don't access 'this'. | 352 // WARNING: we are deleted at this point. Don't access 'this'. |
333 } | 353 } |
334 | 354 |
335 - (IBAction)dismissMaliciousDownload:(id)sender { | 355 - (IBAction)dismissMaliciousDownload:(id)sender { |
356 // ExperienceSampling: User dismissed the dangerous download. | |
357 if (sampling_event_.get()) { | |
358 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | |
359 sampling_event_.reset(NULL); | |
360 } | |
336 [self remove]; | 361 [self remove]; |
337 // WARNING: we are deleted at this point. | 362 // WARNING: we are deleted at this point. |
338 } | 363 } |
339 | 364 |
340 - (IBAction)showContextMenu:(id)sender { | 365 - (IBAction)showContextMenu:(id)sender { |
341 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( | 366 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( |
342 [[DownloadShelfContextMenuController alloc] | 367 [[DownloadShelfContextMenuController alloc] |
343 initWithItemController:self | 368 initWithItemController:self |
344 withDelegate:nil]); | 369 withDelegate:nil]); |
345 [NSMenu popUpContextMenu:[menuController menu] | 370 [NSMenu popUpContextMenu:[menuController menu] |
346 withEvent:[NSApp currentEvent] | 371 withEvent:[NSApp currentEvent] |
347 forView:[self view]]; | 372 forView:[self view]]; |
348 } | 373 } |
349 | 374 |
350 @end | 375 @end |
OLD | NEW |