OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 #include "chrome/browser/ui/browser_list.h" | 76 #include "chrome/browser/ui/browser_list.h" |
77 #include "chrome/browser/ui/views/frame/browser_view.h" | 77 #include "chrome/browser/ui/views/frame/browser_view.h" |
78 #include "ui/base/dragdrop/drag_source.h" | 78 #include "ui/base/dragdrop/drag_source.h" |
79 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 79 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
80 #endif | 80 #endif |
81 | 81 |
82 // TODO(phajdan.jr): Find some standard location for this, maintaining | 82 // TODO(phajdan.jr): Find some standard location for this, maintaining |
83 // the same value on all platforms. | 83 // the same value on all platforms. |
84 static const double PI = 3.141592653589793; | 84 static const double PI = 3.141592653589793; |
85 | 85 |
| 86 namespace { |
| 87 |
| 88 // Returns a string constant to be used as the |danger_type| value in |
| 89 // CreateDownloadItemValue(). We only return strings for DANGEROUS_FILE, |
| 90 // DANGEROUS_URL and DANGEROUS_CONTENT because the |danger_type| value is only |
| 91 // defined if the value of |state| is |DANGEROUS|. |
| 92 const char* GetDangerTypeString(DownloadStateInfo::DangerType danger_type) { |
| 93 switch (danger_type) { |
| 94 case DownloadStateInfo::DANGEROUS_FILE: |
| 95 return "DANGEROUS_FILE"; |
| 96 case DownloadStateInfo::DANGEROUS_URL: |
| 97 return "DANGEROUS_URL"; |
| 98 case DownloadStateInfo::DANGEROUS_CONTENT: |
| 99 return "DANGEROUS_CONTENT"; |
| 100 default: |
| 101 // We shouldn't be returning a danger type string if it is |
| 102 // NOT_DANGEROUS or MAYBE_DANGEROUS_CONTENT. |
| 103 NOTREACHED(); |
| 104 return ""; |
| 105 } |
| 106 } |
| 107 |
| 108 } // namespace |
| 109 |
86 namespace download_util { | 110 namespace download_util { |
87 | 111 |
88 // How many times to cycle the complete animation. This should be an odd number | 112 // How many times to cycle the complete animation. This should be an odd number |
89 // so that the animation ends faded out. | 113 // so that the animation ends faded out. |
90 static const int kCompleteAnimationCycles = 5; | 114 static const int kCompleteAnimationCycles = 5; |
91 | 115 |
92 // Download temporary file creation -------------------------------------------- | 116 // Download temporary file creation -------------------------------------------- |
93 | 117 |
94 class DefaultDownloadDirectory { | 118 class DefaultDownloadDirectory { |
95 public: | 119 public: |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 file_value->SetString("file_name", file_name); | 445 file_value->SetString("file_name", file_name); |
422 file_value->SetString("url", download->GetURL().spec()); | 446 file_value->SetString("url", download->GetURL().spec()); |
423 file_value->SetBoolean("otr", download->is_otr()); | 447 file_value->SetBoolean("otr", download->is_otr()); |
424 file_value->SetInteger("total", static_cast<int>(download->total_bytes())); | 448 file_value->SetInteger("total", static_cast<int>(download->total_bytes())); |
425 file_value->SetBoolean("file_externally_removed", | 449 file_value->SetBoolean("file_externally_removed", |
426 download->file_externally_removed()); | 450 download->file_externally_removed()); |
427 | 451 |
428 if (download->IsInProgress()) { | 452 if (download->IsInProgress()) { |
429 if (download->safety_state() == DownloadItem::DANGEROUS) { | 453 if (download->safety_state() == DownloadItem::DANGEROUS) { |
430 file_value->SetString("state", "DANGEROUS"); | 454 file_value->SetString("state", "DANGEROUS"); |
| 455 // These are the only danger states we expect to see (and the UI is |
| 456 // equipped to handle): |
431 DCHECK(download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE || | 457 DCHECK(download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE || |
432 download->GetDangerType() == DownloadStateInfo::DANGEROUS_URL); | 458 download->GetDangerType() == DownloadStateInfo::DANGEROUS_URL || |
| 459 download->GetDangerType() == DownloadStateInfo::DANGEROUS_CONTENT); |
433 const char* danger_type_value = | 460 const char* danger_type_value = |
434 download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE ? | 461 GetDangerTypeString(download->GetDangerType()); |
435 "DANGEROUS_FILE" : "DANGEROUS_URL"; | |
436 file_value->SetString("danger_type", danger_type_value); | 462 file_value->SetString("danger_type", danger_type_value); |
437 } else if (download->is_paused()) { | 463 } else if (download->is_paused()) { |
438 file_value->SetString("state", "PAUSED"); | 464 file_value->SetString("state", "PAUSED"); |
439 } else { | 465 } else { |
440 file_value->SetString("state", "IN_PROGRESS"); | 466 file_value->SetString("state", "IN_PROGRESS"); |
441 } | 467 } |
442 | 468 |
443 file_value->SetString("progress_status_text", | 469 file_value->SetString("progress_status_text", |
444 GetProgressStatusText(download)); | 470 GetProgressStatusText(download)); |
445 | 471 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 return DownloadFile::GetUniquePathNumberWithSuffix( | 592 return DownloadFile::GetUniquePathNumberWithSuffix( |
567 path, FILE_PATH_LITERAL(".crdownload")); | 593 path, FILE_PATH_LITERAL(".crdownload")); |
568 } | 594 } |
569 | 595 |
570 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 596 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
571 return DownloadFile::AppendSuffixToPath( | 597 return DownloadFile::AppendSuffixToPath( |
572 suggested_path, FILE_PATH_LITERAL(".crdownload")); | 598 suggested_path, FILE_PATH_LITERAL(".crdownload")); |
573 } | 599 } |
574 | 600 |
575 } // namespace download_util | 601 } // namespace download_util |
OLD | NEW |