| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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" | |
| 8 #include "base/macros.h" | 7 #include "base/macros.h" |
| 9 #include "base/metrics/sparse_histogram.h" | |
| 10 #include "base/strings/stringprintf.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | |
| 13 #include "chrome/browser/chrome_notification_types.h" | |
| 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | |
| 15 #include "chrome/browser/download/download_stats.h" | 9 #include "chrome/browser/download/download_stats.h" |
| 16 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | 10 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
| 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 18 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 11 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
| 19 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 12 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 20 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 21 #include "chrome/common/safe_browsing/download_protection_util.h" | |
| 22 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 23 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 24 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/download_danger_type.h" | 16 #include "content/public/browser/download_danger_type.h" |
| 26 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
| 27 #include "grit/components_strings.h" | 18 #include "grit/components_strings.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "url/gurl.h" |
| 29 | 21 |
| 30 using extensions::ExperienceSamplingEvent; | 22 using extensions::ExperienceSamplingEvent; |
| 31 using safe_browsing::ClientDownloadResponse; | |
| 32 using safe_browsing::ClientSafeBrowsingReportRequest; | |
| 33 using safe_browsing::download_protection_util:: | |
| 34 GetSBClientDownloadExtensionValueForUMA; | |
| 35 | 23 |
| 36 namespace { | 24 namespace { |
| 37 | 25 |
| 38 const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; | |
| 39 | |
| 40 // TODO(wittman): Create a native web contents modal dialog implementation of | 26 // TODO(wittman): Create a native web contents modal dialog implementation of |
| 41 // this dialog for non-Views platforms, to support bold formatting of the | 27 // this dialog for non-Views platforms, to support bold formatting of the |
| 42 // message lead. | 28 // message lead. |
| 43 | 29 |
| 44 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. | 30 // Implements DownloadDangerPrompt using a TabModalConfirmDialog. |
| 45 class DownloadDangerPromptImpl : public DownloadDangerPrompt, | 31 class DownloadDangerPromptImpl : public DownloadDangerPrompt, |
| 46 public content::DownloadItem::Observer, | 32 public content::DownloadItem::Observer, |
| 47 public TabModalConfirmDialogDelegate { | 33 public TabModalConfirmDialogDelegate { |
| 48 public: | 34 public: |
| 49 DownloadDangerPromptImpl(content::DownloadItem* item, | 35 DownloadDangerPromptImpl(content::DownloadItem* item, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 !download_->GetBrowserContext()->IsOffTheRecord()) { | 249 !download_->GetBrowserContext()->IsOffTheRecord()) { |
| 264 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); | 250 SendSafeBrowsingDownloadRecoveryReport(accept, *download_); |
| 265 } | 251 } |
| 266 download_->RemoveObserver(this); | 252 download_->RemoveObserver(this); |
| 267 download_ = NULL; | 253 download_ = NULL; |
| 268 } | 254 } |
| 269 if (!done.is_null()) | 255 if (!done.is_null()) |
| 270 done.Run(action); | 256 done.Run(action); |
| 271 } | 257 } |
| 272 | 258 |
| 273 // Converts DownloadDangerType into their corresponding string. | |
| 274 const char* GetDangerTypeString( | |
| 275 const content::DownloadDangerType& danger_type) { | |
| 276 switch (danger_type) { | |
| 277 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | |
| 278 return "DangerousFile"; | |
| 279 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | |
| 280 return "DangerousURL"; | |
| 281 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | |
| 282 return "DangerousContent"; | |
| 283 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | |
| 284 return "DangerousHost"; | |
| 285 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | |
| 286 return "UncommonContent"; | |
| 287 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | |
| 288 return "PotentiallyUnwanted"; | |
| 289 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | |
| 290 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | |
| 291 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | |
| 292 case content::DOWNLOAD_DANGER_TYPE_MAX: | |
| 293 break; | |
| 294 } | |
| 295 NOTREACHED(); | |
| 296 return nullptr; | |
| 297 } | |
| 298 | |
| 299 } // namespace | 259 } // namespace |
| 300 | 260 |
| 301 #if !defined(USE_AURA) | |
| 302 // static | 261 // static |
| 303 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 262 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| 304 content::DownloadItem* item, | 263 content::DownloadItem* item, |
| 305 content::WebContents* web_contents, | 264 content::WebContents* web_contents, |
| 306 bool show_context, | 265 bool show_context, |
| 307 const OnDone& done) { | 266 const OnDone& done) { |
| 308 DownloadDangerPromptImpl* prompt = | 267 DownloadDangerPromptImpl* prompt = |
| 309 new DownloadDangerPromptImpl(item, web_contents, show_context, done); | 268 new DownloadDangerPromptImpl(item, web_contents, show_context, done); |
| 310 // |prompt| will be deleted when the dialog is done. | 269 // |prompt| will be deleted when the dialog is done. |
| 311 TabModalConfirmDialog::Create(prompt, web_contents); | 270 TabModalConfirmDialog::Create(prompt, web_contents); |
| 312 return prompt; | 271 return prompt; |
| 313 } | 272 } |
| 314 #endif | |
| 315 | |
| 316 void DownloadDangerPrompt::SendSafeBrowsingDownloadRecoveryReport( | |
| 317 bool did_proceed, | |
| 318 const content::DownloadItem& download) { | |
| 319 safe_browsing::SafeBrowsingService* sb_service = | |
| 320 g_browser_process->safe_browsing_service(); | |
| 321 ClientSafeBrowsingReportRequest report; | |
| 322 report.set_type(ClientSafeBrowsingReportRequest::DANGEROUS_DOWNLOAD_RECOVERY); | |
| 323 switch (download.GetDangerType()) { | |
| 324 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | |
| 325 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | |
| 326 report.set_download_verdict(ClientDownloadResponse::DANGEROUS); | |
| 327 break; | |
| 328 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | |
| 329 report.set_download_verdict(ClientDownloadResponse::UNCOMMON); | |
| 330 break; | |
| 331 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | |
| 332 report.set_download_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | |
| 333 break; | |
| 334 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | |
| 335 report.set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); | |
| 336 break; | |
| 337 default: | |
| 338 break; | |
| 339 } | |
| 340 report.set_url(download.GetURL().spec()); | |
| 341 report.set_did_proceed(did_proceed); | |
| 342 | |
| 343 std::string serialized_report; | |
| 344 if (report.SerializeToString(&serialized_report)) | |
| 345 sb_service->SendSerializedDownloadReport(serialized_report); | |
| 346 else | |
| 347 DLOG(ERROR) << "Unable to serialize the threat report."; | |
| 348 } | |
| 349 | |
| 350 void DownloadDangerPrompt::RecordDownloadDangerPrompt( | |
| 351 bool did_proceed, | |
| 352 const content::DownloadItem& download) { | |
| 353 int dangerous_file_type = | |
| 354 GetSBClientDownloadExtensionValueForUMA(download.GetTargetFilePath()); | |
| 355 content::DownloadDangerType danger_type = download.GetDangerType(); | |
| 356 | |
| 357 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
| 358 base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, | |
| 359 GetDangerTypeString(danger_type)), | |
| 360 dangerous_file_type); | |
| 361 if (did_proceed) { | |
| 362 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
| 363 base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, | |
| 364 GetDangerTypeString(danger_type)), | |
| 365 dangerous_file_type); | |
| 366 } | |
| 367 } | |
| OLD | NEW |