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

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: scoped_refptr Created 5 years 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/safe_browsing_service.h"
13 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 15 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
14 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 16 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
17 #include "chrome/common/safe_browsing/csd.pb.h"
15 #include "chrome/grit/chromium_strings.h" 18 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "content/public/browser/browser_context.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,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 RunDone(DISMISS); 238 RunDone(DISMISS);
234 } 239 }
235 240
236 void DownloadDangerPromptImpl::RunDone(Action action) { 241 void DownloadDangerPromptImpl::RunDone(Action action) {
237 // Invoking the callback can cause the download item state to change or cause 242 // 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 243 // the constrained window to close, and |callback| refers to a member
239 // variable. 244 // variable.
240 OnDone done = done_; 245 OnDone done = done_;
241 done_.Reset(); 246 done_.Reset();
242 if (download_ != NULL) { 247 if (download_ != NULL) {
248 if (!download_->GetURL().is_empty() &&
249 !download_->GetBrowserContext()->IsOffTheRecord()) {
250 SendSafeBrowsingDownloadRecoveryReport(
251 action == DownloadDangerPrompt::ACCEPT, download_->GetURL());
252 }
243 download_->RemoveObserver(this); 253 download_->RemoveObserver(this);
244 download_ = NULL; 254 download_ = NULL;
245 } 255 }
246 if (!done.is_null()) 256 if (!done.is_null())
247 done.Run(action); 257 done.Run(action);
248 } 258 }
249 259
250 } // namespace 260 } // namespace
251 261
252 #if !defined(USE_AURA) 262 #if !defined(USE_AURA)
253 // static 263 // static
254 DownloadDangerPrompt* DownloadDangerPrompt::Create( 264 DownloadDangerPrompt* DownloadDangerPrompt::Create(
255 content::DownloadItem* item, 265 content::DownloadItem* item,
256 content::WebContents* web_contents, 266 content::WebContents* web_contents,
257 bool show_context, 267 bool show_context,
258 const OnDone& done) { 268 const OnDone& done) {
259 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( 269 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl(
260 item, web_contents, show_context, done); 270 item, web_contents, show_context, done);
261 // |prompt| will be deleted when the dialog is done. 271 // |prompt| will be deleted when the dialog is done.
262 TabModalConfirmDialog::Create(prompt, web_contents); 272 TabModalConfirmDialog::Create(prompt, web_contents);
263 return prompt; 273 return prompt;
264 } 274 }
265 #endif 275 #endif
276
277 void DownloadDangerPrompt::SendSafeBrowsingDownloadRecoveryReport(
278 bool did_proceed,
279 const GURL& url) {
280 safe_browsing::SafeBrowsingService* sb_service =
281 g_browser_process->safe_browsing_service();
282 if (sb_service) {
Lei Zhang 2015/11/24 18:55:27 This should be always true, right?
Jialiu Lin 2015/11/25 23:43:20 Yes, you're right. This check is not necessary. Th
283 ClientSafeBrowsingReportRequest report;
284 report.set_type(
285 ClientSafeBrowsingReportRequest::MALICIOUS_DOWNLOAD_RECOVERY);
286 report.set_url(url.spec());
287 report.set_did_proceed(did_proceed);
288
289 std::string serialized_report;
290 if (report.SerializeToString(&serialized_report))
291 sb_service->SendDownloadRecoveryReport(serialized_report);
292 else
293 DLOG(ERROR) << "Unable to serialize the threat report.";
294 }
295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698