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