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_item_model.h" | 5 #include "chrome/browser/download/download_item_model.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 tooltip += ui::ElideText(InterruptReasonStatusMessage(reason), | 294 tooltip += ui::ElideText(InterruptReasonStatusMessage(reason), |
295 font, max_width, ui::ELIDE_AT_END); | 295 font, max_width, ui::ELIDE_AT_END); |
296 } | 296 } |
297 return tooltip; | 297 return tooltip; |
298 } | 298 } |
299 | 299 |
300 string16 DownloadItemModel::GetWarningText(const gfx::Font& font, | 300 string16 DownloadItemModel::GetWarningText(const gfx::Font& font, |
301 int base_width) const { | 301 int base_width) const { |
302 // Should only be called if IsDangerous(). | 302 // Should only be called if IsDangerous(). |
303 DCHECK(IsDangerous()); | 303 DCHECK(IsDangerous()); |
| 304 string16 elided_filename = |
| 305 ui::ElideFilename(download_->GetFileNameToReportUser(), font, base_width); |
304 switch (download_->GetDangerType()) { | 306 switch (download_->GetDangerType()) { |
305 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 307 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
306 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | 308 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); |
307 | 309 |
308 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | 310 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
309 if (download_crx_util::IsExtensionDownload(*download_)) { | 311 if (download_crx_util::IsExtensionDownload(*download_)) { |
310 return l10n_util::GetStringUTF16( | 312 return l10n_util::GetStringUTF16( |
311 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); | 313 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); |
312 } else { | 314 } else { |
313 return l10n_util::GetStringFUTF16( | 315 return l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
314 IDS_PROMPT_DANGEROUS_DOWNLOAD, | 316 elided_filename); |
315 ui::ElideFilename(download_->GetFileNameToReportUser(), | |
316 font, base_width)); | |
317 } | 317 } |
318 | 318 |
319 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 319 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
320 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 320 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
321 return l10n_util::GetStringFUTF16( | 321 return l10n_util::GetStringFUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
322 IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | 322 elided_filename); |
323 ui::ElideFilename(download_->GetFileNameToReportUser(), | |
324 font, base_width)); | |
325 | 323 |
326 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 324 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 325 return l10n_util::GetStringFUTF16(IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
| 326 elided_filename); |
| 327 |
| 328 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
327 return l10n_util::GetStringFUTF16( | 329 return l10n_util::GetStringFUTF16( |
328 IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 330 IDS_PROMPT_POTENTIALLY_UNWANTED_DOWNLOAD, elided_filename); |
329 ui::ElideFilename(download_->GetFileNameToReportUser(), | |
330 font, base_width)); | |
331 | 331 |
332 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 332 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
333 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 333 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
334 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 334 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
335 case content::DOWNLOAD_DANGER_TYPE_MAX: | 335 case content::DOWNLOAD_DANGER_TYPE_MAX: |
336 NOTREACHED(); | 336 break; |
337 } | 337 } |
| 338 NOTREACHED(); |
338 return string16(); | 339 return string16(); |
339 } | 340 } |
340 | 341 |
341 string16 DownloadItemModel::GetWarningConfirmButtonText() const { | 342 string16 DownloadItemModel::GetWarningConfirmButtonText() const { |
342 // Should only be called if IsDangerous() | 343 // Should only be called if IsDangerous() |
343 DCHECK(IsDangerous()); | 344 DCHECK(IsDangerous()); |
344 if (download_->GetDangerType() == | 345 if (download_->GetDangerType() == |
345 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && | 346 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && |
346 download_crx_util::IsExtensionDownload(*download_)) { | 347 download_crx_util::IsExtensionDownload(*download_)) { |
347 return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD); | 348 return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD); |
(...skipping 23 matching lines...) Expand all Loading... |
371 } | 372 } |
372 | 373 |
373 bool DownloadItemModel::IsMalicious() const { | 374 bool DownloadItemModel::IsMalicious() const { |
374 if (!IsDangerous()) | 375 if (!IsDangerous()) |
375 return false; | 376 return false; |
376 switch (download_->GetDangerType()) { | 377 switch (download_->GetDangerType()) { |
377 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 378 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
378 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 379 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
379 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 380 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
380 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 381 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 382 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
381 return true; | 383 return true; |
382 | 384 |
383 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 385 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
384 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 386 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
385 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 387 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
386 case content::DOWNLOAD_DANGER_TYPE_MAX: | 388 case content::DOWNLOAD_DANGER_TYPE_MAX: |
387 // We shouldn't get any of these due to the IsDangerous() test above. | 389 // We shouldn't get any of these due to the IsDangerous() test above. |
388 NOTREACHED(); | 390 NOTREACHED(); |
389 // Fallthrough. | 391 // Fallthrough. |
390 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | 392 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 530 } |
529 | 531 |
530 // In progress download with no known time left and non-zero completed bytes: | 532 // In progress download with no known time left and non-zero completed bytes: |
531 // "100/120 MB" or "100 MB" | 533 // "100/120 MB" or "100 MB" |
532 if (GetCompletedBytes() > 0) | 534 if (GetCompletedBytes() > 0) |
533 return size_ratio; | 535 return size_ratio; |
534 | 536 |
535 // Instead of displaying "0 B" we say "Starting..." | 537 // Instead of displaying "0 B" we say "Starting..." |
536 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); | 538 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); |
537 } | 539 } |
OLD | NEW |