OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const CompletionCallback& callback) | 88 const CompletionCallback& callback) |
89 : next_state_(STATE_GENERATE_TARGET_PATH), | 89 : next_state_(STATE_GENERATE_TARGET_PATH), |
90 should_prompt_(false), | 90 should_prompt_(false), |
91 should_notify_extensions_(false), | 91 should_notify_extensions_(false), |
92 create_target_directory_(false), | 92 create_target_directory_(false), |
93 conflict_action_(DownloadPathReservationTracker::OVERWRITE), | 93 conflict_action_(DownloadPathReservationTracker::OVERWRITE), |
94 danger_type_(download->GetDangerType()), | 94 danger_type_(download->GetDangerType()), |
95 is_dangerous_file_(false), | 95 is_dangerous_file_(false), |
96 virtual_path_(initial_virtual_path), | 96 virtual_path_(initial_virtual_path), |
97 is_filetype_handled_safely_(false), | 97 is_filetype_handled_safely_(false), |
| 98 hide_file_extension_(false), |
98 download_(download), | 99 download_(download), |
99 is_resumption_(download_->GetLastReason() != | 100 is_resumption_(download_->GetLastReason() != |
100 content::DOWNLOAD_INTERRUPT_REASON_NONE && | 101 content::DOWNLOAD_INTERRUPT_REASON_NONE && |
101 !initial_virtual_path.empty()), | 102 !initial_virtual_path.empty()), |
102 download_prefs_(download_prefs), | 103 download_prefs_(download_prefs), |
103 delegate_(delegate), | 104 delegate_(delegate), |
104 completion_callback_(callback), | 105 completion_callback_(callback), |
105 weak_ptr_factory_(this) { | 106 weak_ptr_factory_(this) { |
106 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
107 DCHECK(download_); | 108 DCHECK(download_); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 download_, | 329 download_, |
329 virtual_path_, | 330 virtual_path_, |
330 base::Bind(&DownloadTargetDeterminer::PromptUserForDownloadPathDone, | 331 base::Bind(&DownloadTargetDeterminer::PromptUserForDownloadPathDone, |
331 weak_ptr_factory_.GetWeakPtr())); | 332 weak_ptr_factory_.GetWeakPtr())); |
332 return QUIT_DOLOOP; | 333 return QUIT_DOLOOP; |
333 } | 334 } |
334 return CONTINUE; | 335 return CONTINUE; |
335 } | 336 } |
336 | 337 |
337 void DownloadTargetDeterminer::PromptUserForDownloadPathDone( | 338 void DownloadTargetDeterminer::PromptUserForDownloadPathDone( |
338 const base::FilePath& virtual_path) { | 339 const base::FilePath& virtual_path, bool hide_file_extension) { |
339 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 340 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
340 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe(); | 341 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe(); |
341 if (virtual_path.empty()) { | 342 if (virtual_path.empty()) { |
342 CancelOnFailureAndDeleteSelf(); | 343 CancelOnFailureAndDeleteSelf(); |
343 return; | 344 return; |
344 } | 345 } |
345 DCHECK_EQ(STATE_DETERMINE_LOCAL_PATH, next_state_); | 346 DCHECK_EQ(STATE_DETERMINE_LOCAL_PATH, next_state_); |
346 | 347 |
347 virtual_path_ = virtual_path; | 348 virtual_path_ = virtual_path; |
348 download_prefs_->SetSaveFilePath(virtual_path_.DirName()); | 349 download_prefs_->SetSaveFilePath(virtual_path_.DirName()); |
| 350 hide_file_extension_ = hide_file_extension; |
349 DoLoop(); | 351 DoLoop(); |
350 } | 352 } |
351 | 353 |
352 DownloadTargetDeterminer::Result | 354 DownloadTargetDeterminer::Result |
353 DownloadTargetDeterminer::DoDetermineLocalPath() { | 355 DownloadTargetDeterminer::DoDetermineLocalPath() { |
354 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 356 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
355 DCHECK(!virtual_path_.empty()); | 357 DCHECK(!virtual_path_.empty()); |
356 DCHECK(local_path_.empty()); | 358 DCHECK(local_path_.empty()); |
357 | 359 |
358 next_state_ = STATE_DETERMINE_MIME_TYPE; | 360 next_state_ = STATE_DETERMINE_MIME_TYPE; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 target_info->target_path = local_path_; | 730 target_info->target_path = local_path_; |
729 target_info->target_disposition = | 731 target_info->target_disposition = |
730 (HasPromptedForPath() || should_prompt_ | 732 (HasPromptedForPath() || should_prompt_ |
731 ? DownloadItem::TARGET_DISPOSITION_PROMPT | 733 ? DownloadItem::TARGET_DISPOSITION_PROMPT |
732 : DownloadItem::TARGET_DISPOSITION_OVERWRITE); | 734 : DownloadItem::TARGET_DISPOSITION_OVERWRITE); |
733 target_info->danger_type = danger_type_; | 735 target_info->danger_type = danger_type_; |
734 target_info->is_dangerous_file = is_dangerous_file_; | 736 target_info->is_dangerous_file = is_dangerous_file_; |
735 target_info->intermediate_path = intermediate_path_; | 737 target_info->intermediate_path = intermediate_path_; |
736 target_info->mime_type = mime_type_; | 738 target_info->mime_type = mime_type_; |
737 target_info->is_filetype_handled_safely = is_filetype_handled_safely_; | 739 target_info->is_filetype_handled_safely = is_filetype_handled_safely_; |
| 740 target_info->hide_file_extension = hide_file_extension_; |
738 | 741 |
739 base::ThreadTaskRunnerHandle::Get()->PostTask( | 742 base::ThreadTaskRunnerHandle::Get()->PostTask( |
740 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info))); | 743 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info))); |
741 completion_callback_.Reset(); | 744 completion_callback_.Reset(); |
742 delete this; | 745 delete this; |
743 } | 746 } |
744 | 747 |
745 void DownloadTargetDeterminer::CancelOnFailureAndDeleteSelf() { | 748 void DownloadTargetDeterminer::CancelOnFailureAndDeleteSelf() { |
746 // Path substitution failed. | 749 // Path substitution failed. |
747 virtual_path_.clear(); | 750 virtual_path_.clear(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 const base::FilePath& suggested_path) { | 898 const base::FilePath& suggested_path) { |
896 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 899 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
897 } | 900 } |
898 | 901 |
899 #if defined(OS_WIN) | 902 #if defined(OS_WIN) |
900 // static | 903 // static |
901 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 904 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
902 return g_is_adobe_reader_up_to_date_; | 905 return g_is_adobe_reader_up_to_date_; |
903 } | 906 } |
904 #endif | 907 #endif |
OLD | NEW |