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/download/download_danger_prompt.h" | 5 #include "chrome/browser/download/download_danger_prompt.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
11 #include "chrome/browser/download/download_stats.h" | 11 #include "chrome/browser/download/download_stats.h" |
| 12 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
12 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 13 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
13 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 14 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
14 #include "content/public/browser/download_danger_type.h" | 15 #include "content/public/browser/download_danger_type.h" |
15 #include "content/public/browser/download_item.h" | 16 #include "content/public/browser/download_item.h" |
16 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 | 20 |
| 21 using extensions::ExperienceSamplingEvent; |
| 22 |
20 namespace { | 23 namespace { |
21 | 24 |
22 // TODO(wittman): Create a native web contents modal dialog implementation of | 25 // TODO(wittman): Create a native web contents modal dialog implementation of |
23 // this dialog for non-Views platforms, to support bold formatting of the | 26 // this dialog for non-Views platforms, to support bold formatting of the |
24 // message lead. | 27 // message lead. |
25 | 28 |
26 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. | 29 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. |
27 class DownloadDangerPromptImpl : public DownloadDangerPrompt, | 30 class DownloadDangerPromptImpl : public DownloadDangerPrompt, |
28 public content::DownloadItem::Observer, | 31 public content::DownloadItem::Observer, |
29 public TabModalConfirmDialogDelegate { | 32 public TabModalConfirmDialogDelegate { |
(...skipping 19 matching lines...) Expand all Loading... |
49 virtual void OnAccepted() OVERRIDE; | 52 virtual void OnAccepted() OVERRIDE; |
50 virtual void OnCanceled() OVERRIDE; | 53 virtual void OnCanceled() OVERRIDE; |
51 virtual void OnClosed() OVERRIDE; | 54 virtual void OnClosed() OVERRIDE; |
52 | 55 |
53 void RunDone(Action action); | 56 void RunDone(Action action); |
54 | 57 |
55 content::DownloadItem* download_; | 58 content::DownloadItem* download_; |
56 bool show_context_; | 59 bool show_context_; |
57 OnDone done_; | 60 OnDone done_; |
58 | 61 |
| 62 scoped_ptr<ExperienceSamplingEvent> sampling_event_; |
| 63 |
59 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl); | 64 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl); |
60 }; | 65 }; |
61 | 66 |
62 DownloadDangerPromptImpl::DownloadDangerPromptImpl( | 67 DownloadDangerPromptImpl::DownloadDangerPromptImpl( |
63 content::DownloadItem* download, | 68 content::DownloadItem* download, |
64 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
65 bool show_context, | 70 bool show_context, |
66 const OnDone& done) | 71 const OnDone& done) |
67 : TabModalConfirmDialogDelegate(web_contents), | 72 : TabModalConfirmDialogDelegate(web_contents), |
68 download_(download), | 73 download_(download), |
69 show_context_(show_context), | 74 show_context_(show_context), |
70 done_(done) { | 75 done_(done) { |
71 DCHECK(!done_.is_null()); | 76 DCHECK(!done_.is_null()); |
72 download_->AddObserver(this); | 77 download_->AddObserver(this); |
73 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); | 78 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); |
| 79 |
| 80 // ExperienceSampling: A malicious download warning is being shown to the |
| 81 // user, so we start a new SamplingEvent and track it. |
| 82 sampling_event_.reset(new ExperienceSamplingEvent( |
| 83 ExperienceSamplingEvent::kDownloadDangerPrompt, |
| 84 download->GetURL(), |
| 85 download->GetReferrerUrl(), |
| 86 download->GetBrowserContext())); |
74 } | 87 } |
75 | 88 |
76 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { | 89 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { |
77 // |this| might be deleted without invoking any callbacks. E.g. pressing Esc | 90 // |this| might be deleted without invoking any callbacks. E.g. pressing Esc |
78 // on GTK or if the user navigates away from the page showing the prompt. | 91 // on GTK or if the user navigates away from the page showing the prompt. |
79 RunDone(DISMISS); | 92 RunDone(DISMISS); |
80 } | 93 } |
81 | 94 |
82 void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { | 95 void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { |
83 switch (action) { | 96 switch (action) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 209 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
197 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: { | 210 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: { |
198 return l10n_util::GetStringUTF16(IDS_CONFIRM_CANCEL_AGAIN_MALICIOUS); | 211 return l10n_util::GetStringUTF16(IDS_CONFIRM_CANCEL_AGAIN_MALICIOUS); |
199 } | 212 } |
200 default: | 213 default: |
201 return l10n_util::GetStringUTF16(IDS_CANCEL); | 214 return l10n_util::GetStringUTF16(IDS_CANCEL); |
202 } | 215 } |
203 } | 216 } |
204 | 217 |
205 void DownloadDangerPromptImpl::OnAccepted() { | 218 void DownloadDangerPromptImpl::OnAccepted() { |
| 219 // ExperienceSampling: User proceeded through the warning. |
| 220 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
206 RunDone(ACCEPT); | 221 RunDone(ACCEPT); |
207 } | 222 } |
208 | 223 |
209 void DownloadDangerPromptImpl::OnCanceled() { | 224 void DownloadDangerPromptImpl::OnCanceled() { |
| 225 // ExperienceSampling: User canceled the warning. |
| 226 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
210 RunDone(CANCEL); | 227 RunDone(CANCEL); |
211 } | 228 } |
212 | 229 |
213 void DownloadDangerPromptImpl::OnClosed() { | 230 void DownloadDangerPromptImpl::OnClosed() { |
| 231 // ExperienceSampling: User canceled the warning. |
| 232 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
214 RunDone(DISMISS); | 233 RunDone(DISMISS); |
215 } | 234 } |
216 | 235 |
217 void DownloadDangerPromptImpl::RunDone(Action action) { | 236 void DownloadDangerPromptImpl::RunDone(Action action) { |
218 // Invoking the callback can cause the download item state to change or cause | 237 // Invoking the callback can cause the download item state to change or cause |
219 // the constrained window to close, and |callback| refers to a member | 238 // the constrained window to close, and |callback| refers to a member |
220 // variable. | 239 // variable. |
221 OnDone done = done_; | 240 OnDone done = done_; |
222 done_.Reset(); | 241 done_.Reset(); |
223 if (download_ != NULL) { | 242 if (download_ != NULL) { |
(...skipping 13 matching lines...) Expand all Loading... |
237 content::WebContents* web_contents, | 256 content::WebContents* web_contents, |
238 bool show_context, | 257 bool show_context, |
239 const OnDone& done) { | 258 const OnDone& done) { |
240 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( | 259 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( |
241 item, web_contents, show_context, done); | 260 item, web_contents, show_context, done); |
242 // |prompt| will be deleted when the dialog is done. | 261 // |prompt| will be deleted when the dialog is done. |
243 TabModalConfirmDialog::Create(prompt, web_contents); | 262 TabModalConfirmDialog::Create(prompt, web_contents); |
244 return prompt; | 263 return prompt; |
245 } | 264 } |
246 #endif | 265 #endif |
OLD | NEW |