| 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/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 download_(download), | 78 download_(download), |
| 74 show_context_(show_context), | 79 show_context_(show_context), |
| 75 done_(done) { | 80 done_(done) { |
| 76 DCHECK(!done_.is_null()); | 81 DCHECK(!done_.is_null()); |
| 77 download_->AddObserver(this); | 82 download_->AddObserver(this); |
| 78 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); | 83 RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); |
| 79 | 84 |
| 80 // ExperienceSampling: A malicious download warning is being shown to the | 85 // ExperienceSampling: A malicious download warning is being shown to the |
| 81 // user, so we start a new SamplingEvent and track it. | 86 // user, so we start a new SamplingEvent and track it. |
| 82 sampling_event_.reset(new ExperienceSamplingEvent( | 87 sampling_event_.reset(new ExperienceSamplingEvent( |
| 83 ExperienceSamplingEvent::kDownloadDangerPrompt, | 88 ExperienceSamplingEvent::kDownloadDangerPrompt, download->GetURL(), |
| 84 download->GetURL(), | 89 download->GetReferrerUrl(), download->GetBrowserContext())); |
| 85 download->GetReferrerUrl(), | |
| 86 download->GetBrowserContext())); | |
| 87 } | 90 } |
| 88 | 91 |
| 89 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { | 92 DownloadDangerPromptImpl::~DownloadDangerPromptImpl() { |
| 90 // |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 |
| 91 // 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. |
| 92 RunDone(DISMISS); | 95 RunDone(DISMISS); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { | 98 void DownloadDangerPromptImpl::InvokeActionForTesting(Action action) { |
| 96 switch (action) { | 99 switch (action) { |
| 97 case ACCEPT: Accept(); break; | 100 case ACCEPT: |
| 98 case CANCEL: Cancel(); break; | 101 Accept(); |
| 102 break; |
| 103 case CANCEL: |
| 104 Cancel(); |
| 105 break; |
| 99 case DISMISS: | 106 case DISMISS: |
| 100 RunDone(DISMISS); | 107 RunDone(DISMISS); |
| 101 Cancel(); | 108 Cancel(); |
| 102 break; | 109 break; |
| 103 } | 110 } |
| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 133 } | 140 } |
| 134 | 141 |
| 135 base::string16 DownloadDangerPromptImpl::GetDialogMessage() { | 142 base::string16 DownloadDangerPromptImpl::GetDialogMessage() { |
| 136 if (show_context_) { | 143 if (show_context_) { |
| 137 switch (download_->GetDangerType()) { | 144 switch (download_->GetDangerType()) { |
| 138 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { | 145 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { |
| 139 return l10n_util::GetStringFUTF16( | 146 return l10n_util::GetStringFUTF16( |
| 140 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 147 IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 141 download_->GetFileNameToReportUser().LossyDisplayName()); | 148 download_->GetFileNameToReportUser().LossyDisplayName()); |
| 142 } | 149 } |
| 143 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through | 150 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: // Fall through |
| 144 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 151 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 145 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 152 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
| 146 return l10n_util::GetStringFUTF16( | 153 return l10n_util::GetStringFUTF16( |
| 147 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | 154 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
| 148 download_->GetFileNameToReportUser().LossyDisplayName()); | 155 download_->GetFileNameToReportUser().LossyDisplayName()); |
| 149 } | 156 } |
| 150 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { | 157 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { |
| 151 return l10n_util::GetStringFUTF16( | 158 return l10n_util::GetStringFUTF16( |
| 152 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 159 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
| 153 download_->GetFileNameToReportUser().LossyDisplayName()); | 160 download_->GetFileNameToReportUser().LossyDisplayName()); |
| 154 } | 161 } |
| 155 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: { | 162 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: { |
| 156 return l10n_util::GetStringFUTF16( | 163 return l10n_util::GetStringFUTF16( |
| 157 IDS_PROMPT_DOWNLOAD_CHANGES_SETTINGS, | 164 IDS_PROMPT_DOWNLOAD_CHANGES_SETTINGS, |
| 158 download_->GetFileNameToReportUser().LossyDisplayName()); | 165 download_->GetFileNameToReportUser().LossyDisplayName()); |
| 159 } | 166 } |
| 160 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 167 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 161 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 168 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| 162 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 169 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
| 163 case content::DOWNLOAD_DANGER_TYPE_MAX: { | 170 case content::DOWNLOAD_DANGER_TYPE_MAX: { |
| 164 break; | 171 break; |
| 165 } | 172 } |
| 166 } | 173 } |
| 167 } else { | 174 } else { |
| 168 switch (download_->GetDangerType()) { | 175 switch (download_->GetDangerType()) { |
| 169 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 176 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 170 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 177 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 171 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { | 178 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: { |
| 172 return l10n_util::GetStringUTF16( | 179 return l10n_util::GetStringUTF16( |
| 173 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD) + | 180 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_LEAD) + |
| 174 base::ASCIIToUTF16("\n\n") + | 181 base::ASCIIToUTF16("\n\n") + |
| 175 l10n_util::GetStringUTF16( | 182 l10n_util::GetStringUTF16( |
| 176 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_BODY); | 183 IDS_PROMPT_CONFIRM_KEEP_MALICIOUS_DOWNLOAD_BODY); |
| 177 } | 184 } |
| 178 default: { | 185 default: { |
| 179 return l10n_util::GetStringUTF16( | 186 return l10n_util::GetStringUTF16( |
| 180 IDS_PROMPT_CONFIRM_KEEP_DANGEROUS_DOWNLOAD); | 187 IDS_PROMPT_CONFIRM_KEEP_DANGEROUS_DOWNLOAD); |
| 181 } | 188 } |
| 182 } | 189 } |
| 183 } | 190 } |
| 184 NOTREACHED(); | 191 NOTREACHED(); |
| 185 return base::string16(); | 192 return base::string16(); |
| 186 } | 193 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 !download_->GetBrowserContext()->IsOffTheRecord()) { |
| 252 SendSafeBrowsingDownloadRecoveryReport( |
| 253 action == DownloadDangerPrompt::ACCEPT, download_->GetURL()); |
| 254 } |
| 243 download_->RemoveObserver(this); | 255 download_->RemoveObserver(this); |
| 244 download_ = NULL; | 256 download_ = NULL; |
| 245 } | 257 } |
| 246 if (!done.is_null()) | 258 if (!done.is_null()) |
| 247 done.Run(action); | 259 done.Run(action); |
| 248 } | 260 } |
| 249 | 261 |
| 250 } // namespace | 262 } // namespace |
| 251 | 263 |
| 252 #if !defined(USE_AURA) | 264 #if !defined(USE_AURA) |
| 253 // static | 265 // static |
| 254 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 266 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
| 255 content::DownloadItem* item, | 267 content::DownloadItem* item, |
| 256 content::WebContents* web_contents, | 268 content::WebContents* web_contents, |
| 257 bool show_context, | 269 bool show_context, |
| 258 const OnDone& done) { | 270 const OnDone& done) { |
| 259 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( | 271 DownloadDangerPromptImpl* prompt = |
| 260 item, web_contents, show_context, done); | 272 new DownloadDangerPromptImpl(item, web_contents, show_context, done); |
| 261 // |prompt| will be deleted when the dialog is done. | 273 // |prompt| will be deleted when the dialog is done. |
| 262 TabModalConfirmDialog::Create(prompt, web_contents); | 274 TabModalConfirmDialog::Create(prompt, web_contents); |
| 263 return prompt; | 275 return prompt; |
| 264 } | 276 } |
| 265 #endif | 277 #endif |
| 278 |
| 279 void DownloadDangerPrompt::SendSafeBrowsingDownloadRecoveryReport( |
| 280 bool did_proceed, |
| 281 const GURL& url) { |
| 282 safe_browsing::SafeBrowsingService* sb_service = |
| 283 g_browser_process->safe_browsing_service(); |
| 284 ClientSafeBrowsingReportRequest report; |
| 285 report.set_type(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 } |
| OLD | NEW |