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. | |
achuithb
2011/11/21 21:34:36
Does a NOTREACHED() make sense here? If we ever ge
asanka
2011/11/21 22:46:58
It did have a NOTREACHED(), but I removed it becau
| |
103 return ""; | |
104 } | |
105 } | |
106 | |
107 } // namespace | |
108 | |
86 namespace download_util { | 109 namespace download_util { |
87 | 110 |
88 // How many times to cycle the complete animation. This should be an odd number | 111 // How many times to cycle the complete animation. This should be an odd number |
89 // so that the animation ends faded out. | 112 // so that the animation ends faded out. |
90 static const int kCompleteAnimationCycles = 5; | 113 static const int kCompleteAnimationCycles = 5; |
91 | 114 |
92 // Download temporary file creation -------------------------------------------- | 115 // Download temporary file creation -------------------------------------------- |
93 | 116 |
94 class DefaultDownloadDirectory { | 117 class DefaultDownloadDirectory { |
95 public: | 118 public: |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 file_value->SetString("file_name", file_name); | 444 file_value->SetString("file_name", file_name); |
422 file_value->SetString("url", download->GetURL().spec()); | 445 file_value->SetString("url", download->GetURL().spec()); |
423 file_value->SetBoolean("otr", download->is_otr()); | 446 file_value->SetBoolean("otr", download->is_otr()); |
424 file_value->SetInteger("total", static_cast<int>(download->total_bytes())); | 447 file_value->SetInteger("total", static_cast<int>(download->total_bytes())); |
425 file_value->SetBoolean("file_externally_removed", | 448 file_value->SetBoolean("file_externally_removed", |
426 download->file_externally_removed()); | 449 download->file_externally_removed()); |
427 | 450 |
428 if (download->IsInProgress()) { | 451 if (download->IsInProgress()) { |
429 if (download->safety_state() == DownloadItem::DANGEROUS) { | 452 if (download->safety_state() == DownloadItem::DANGEROUS) { |
430 file_value->SetString("state", "DANGEROUS"); | 453 file_value->SetString("state", "DANGEROUS"); |
454 // These are the only danger states we expect to see (and the UI is | |
455 // equipped to handle): | |
431 DCHECK(download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE || | 456 DCHECK(download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE || |
432 download->GetDangerType() == DownloadStateInfo::DANGEROUS_URL); | 457 download->GetDangerType() == DownloadStateInfo::DANGEROUS_URL || |
458 download->GetDangerType() == DownloadStateInfo::DANGEROUS_CONTENT); | |
433 const char* danger_type_value = | 459 const char* danger_type_value = |
434 download->GetDangerType() == DownloadStateInfo::DANGEROUS_FILE ? | 460 GetDangerTypeString(download->GetDangerType()); |
435 "DANGEROUS_FILE" : "DANGEROUS_URL"; | |
436 file_value->SetString("danger_type", danger_type_value); | 461 file_value->SetString("danger_type", danger_type_value); |
437 } else if (download->is_paused()) { | 462 } else if (download->is_paused()) { |
438 file_value->SetString("state", "PAUSED"); | 463 file_value->SetString("state", "PAUSED"); |
439 } else { | 464 } else { |
440 file_value->SetString("state", "IN_PROGRESS"); | 465 file_value->SetString("state", "IN_PROGRESS"); |
441 } | 466 } |
442 | 467 |
443 file_value->SetString("progress_status_text", | 468 file_value->SetString("progress_status_text", |
444 GetProgressStatusText(download)); | 469 GetProgressStatusText(download)); |
445 | 470 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 return DownloadFile::GetUniquePathNumberWithSuffix( | 591 return DownloadFile::GetUniquePathNumberWithSuffix( |
567 path, FILE_PATH_LITERAL(".crdownload")); | 592 path, FILE_PATH_LITERAL(".crdownload")); |
568 } | 593 } |
569 | 594 |
570 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 595 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
571 return DownloadFile::AppendSuffixToPath( | 596 return DownloadFile::AppendSuffixToPath( |
572 suggested_path, FILE_PATH_LITERAL(".crdownload")); | 597 suggested_path, FILE_PATH_LITERAL(".crdownload")); |
573 } | 598 } |
574 | 599 |
575 } // namespace download_util | 600 } // namespace download_util |
OLD | NEW |