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

Side by Side Diff: chrome/browser/download/download_danger_prompt.cc

Issue 1436273002: Send safe browsing ThreatDetails to track download CTR when user tries to recover blocked downloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 1 month 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 #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/browser_process.h"
9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" 11 #include "chrome/browser/download/chrome_download_manager_delegate.h"
11 #include "chrome/browser/download/download_stats.h" 12 #include "chrome/browser/download/download_stats.h"
12 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 13 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
14 #include "chrome/browser/safe_browsing/ping_manager.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 16 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
14 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 17 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
18 #include "chrome/common/safe_browsing/csd.pb.h"
15 #include "chrome/grit/chromium_strings.h" 19 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/download_danger_type.h" 21 #include "content/public/browser/download_danger_type.h"
18 #include "content/public/browser/download_item.h" 22 #include "content/public/browser/download_item.h"
19 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
20 24
21 using extensions::ExperienceSamplingEvent; 25 using extensions::ExperienceSamplingEvent;
26 using safe_browsing::ClientSafeBrowsingReportRequest;
22 27
23 namespace { 28 namespace {
24 29
25 // TODO(wittman): Create a native web contents modal dialog implementation of 30 // TODO(wittman): Create a native web contents modal dialog implementation of
26 // this dialog for non-Views platforms, to support bold formatting of the 31 // this dialog for non-Views platforms, to support bold formatting of the
27 // message lead. 32 // message lead.
28 33
29 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. 34 // Implements DownloadDangerPrompt using a TabModalConfirmDialog.
30 class DownloadDangerPromptImpl : public DownloadDangerPrompt, 35 class DownloadDangerPromptImpl : public DownloadDangerPrompt,
31 public content::DownloadItem::Observer, 36 public content::DownloadItem::Observer,
32 public TabModalConfirmDialogDelegate { 37 public TabModalConfirmDialogDelegate {
33 public: 38 public:
34 DownloadDangerPromptImpl(content::DownloadItem* item, 39 DownloadDangerPromptImpl(content::DownloadItem* item,
35 content::WebContents* web_contents, 40 content::WebContents* web_contents,
36 bool show_context, 41 bool show_context,
37 const OnDone& done); 42 const OnDone& done);
38 ~DownloadDangerPromptImpl() override; 43 ~DownloadDangerPromptImpl() override;
39 44
40 // DownloadDangerPrompt: 45 // DownloadDangerPrompt:
41 void InvokeActionForTesting(Action action) override; 46 std::string InvokeActionForTesting(Action action, const GURL& url) override;
42 47
43 private: 48 private:
44 // content::DownloadItem::Observer: 49 // content::DownloadItem::Observer:
45 void OnDownloadUpdated(content::DownloadItem* download) override; 50 void OnDownloadUpdated(content::DownloadItem* download) override;
46 51
47 // TabModalConfirmDialogDelegate: 52 // TabModalConfirmDialogDelegate:
48 base::string16 GetTitle() override; 53 base::string16 GetTitle() override;
49 base::string16 GetDialogMessage() override; 54 base::string16 GetDialogMessage() override;
50 base::string16 GetAcceptButtonTitle() override; 55 base::string16 GetAcceptButtonTitle() override;
51 base::string16 GetCancelButtonTitle() override; 56 base::string16 GetCancelButtonTitle() override;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 download->GetReferrerUrl(), 90 download->GetReferrerUrl(),
86 download->GetBrowserContext())); 91 download->GetBrowserContext()));
87 } 92 }
88 93
89 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { 94 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() {
90 // |this| might be deleted without invoking any callbacks. E.g. pressing Esc 95 // |this| might be deleted without invoking any callbacks. E.g. pressing Esc
91 // on GTK or if the user navigates away from the page showing the prompt. 96 // on GTK or if the user navigates away from the page showing the prompt.
92 RunDone(DISMISS); 97 RunDone(DISMISS);
93 } 98 }
94 99
95 void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { 100 std::string DownloadDangerPromptImpl::InvokeActionForTesting(
101 Action action, const GURL& url) {
96 switch (action) { 102 switch (action) {
97 case ACCEPT: Accept(); break; 103 case ACCEPT: Accept(); break;
98 case CANCEL: Cancel(); break; 104 case CANCEL: Cancel(); break;
99 case DISMISS: 105 case DISMISS:
100 RunDone(DISMISS); 106 RunDone(DISMISS);
101 Cancel(); 107 Cancel();
102 break; 108 break;
103 } 109 }
110 return CreateSafeBrowsingDownloadRecoveryReport(action == ACCEPT, url);
104 } 111 }
105 112
106 void DownloadDangerPromptImpl::OnDownloadUpdated( 113 void DownloadDangerPromptImpl::OnDownloadUpdated(
107 content::DownloadItem* download) { 114 content::DownloadItem* download) {
108 // If the download is nolonger dangerous (accepted externally) or the download 115 // If the download is nolonger dangerous (accepted externally) or the download
109 // is in a terminal state, then the download danger prompt is no longer 116 // is in a terminal state, then the download danger prompt is no longer
110 // necessary. 117 // necessary.
111 if (!download->IsDangerous() || download->IsDone()) { 118 if (!download->IsDangerous() || download->IsDone()) {
112 RunDone(DISMISS); 119 RunDone(DISMISS);
113 Cancel(); 120 Cancel();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 RunDone(DISMISS); 240 RunDone(DISMISS);
234 } 241 }
235 242
236 void DownloadDangerPromptImpl::RunDone(Action action) { 243 void DownloadDangerPromptImpl::RunDone(Action action) {
237 // Invoking the callback can cause the download item state to change or cause 244 // Invoking the callback can cause the download item state to change or cause
238 // the constrained window to close, and |callback| refers to a member 245 // the constrained window to close, and |callback| refers to a member
239 // variable. 246 // variable.
240 OnDone done = done_; 247 OnDone done = done_;
241 done_.Reset(); 248 done_.Reset();
242 if (download_ != NULL) { 249 if (download_ != NULL) {
250 if (!download_->GetURL().is_empty()) {
251 std::string report = CreateSafeBrowsingDownloadRecoveryReport(
252 action == DownloadDangerPrompt::ACCEPT, download_->GetURL());
253 if (!report.empty())
254 SendSerializedReport(report);
255 }
243 download_->RemoveObserver(this); 256 download_->RemoveObserver(this);
244 download_ = NULL; 257 download_ = NULL;
245 } 258 }
246 if (!done.is_null()) 259 if (!done.is_null())
247 done.Run(action); 260 done.Run(action);
248 } 261 }
249 262
250 } // namespace 263 } // namespace
251 264
252 #if !defined(USE_AURA) 265 #if !defined(USE_AURA)
253 // static 266 // static
254 DownloadDangerPrompt* DownloadDangerPrompt::Create( 267 DownloadDangerPrompt* DownloadDangerPrompt::Create(
255 content::DownloadItem* item, 268 content::DownloadItem* item,
256 content::WebContents* web_contents, 269 content::WebContents* web_contents,
257 bool show_context, 270 bool show_context,
258 const OnDone& done) { 271 const OnDone& done) {
259 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( 272 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl(
260 item, web_contents, show_context, done); 273 item, web_contents, show_context, done);
261 // |prompt| will be deleted when the dialog is done. 274 // |prompt| will be deleted when the dialog is done.
262 TabModalConfirmDialog::Create(prompt, web_contents); 275 TabModalConfirmDialog::Create(prompt, web_contents);
263 return prompt; 276 return prompt;
264 } 277 }
265 #endif 278 #endif
279
280 std::string DownloadDangerPrompt::CreateSafeBrowsingDownloadRecoveryReport(
281 bool did_proceed,
282 const GURL& url) {
283 ClientSafeBrowsingReportRequest report;
284 report.set_type(ClientSafeBrowsingReportRequest::MALICIOUS_DOWNLOAD_RECOVERY);
285 report.set_url(url.spec());
286 report.set_did_proceed(did_proceed);
287
288 std::string serialized_report;
289 if (!report.SerializeToString(&serialized_report)) {
290 DLOG(ERROR) << "Unable to serialize the threat report.";
291 return "";
292 }
293
294 return serialized_report;
295 }
296
297 void DownloadDangerPrompt::SendSerializedReport(
298 const std::string& serialized_report) {
299 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service();
300 if (sb_service) {
301 sb_service->SendDownloadRecoveryReport(serialized_report);
302 }
303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698