| 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_contents_delegate.h" | 52 #include "content/public/browser/web_contents_delegate.h" |
| 53 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 54 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 | 56 |
| 57 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 58 #include "chrome/browser/chromeos/drive/download_handler.h" | 58 #include "chrome/browser/chromeos/drive/download_handler.h" |
| 59 #include "chrome/browser/chromeos/drive/file_system_util.h" | 59 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 60 #include "chrome/browser/download/download_file_picker_chromeos.h" | 60 #include "chrome/browser/download/download_file_picker_chromeos.h" |
| 61 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | |
| 62 #endif | 61 #endif |
| 63 | 62 |
| 64 using content::BrowserContext; | |
| 65 using content::BrowserThread; | 63 using content::BrowserThread; |
| 66 using content::DownloadId; | 64 using content::DownloadId; |
| 67 using content::DownloadItem; | 65 using content::DownloadItem; |
| 68 using content::DownloadManager; | 66 using content::DownloadManager; |
| 69 using content::WebContents; | 67 using content::WebContents; |
| 70 using safe_browsing::DownloadProtectionService; | 68 using safe_browsing::DownloadProtectionService; |
| 71 | 69 |
| 72 namespace { | 70 namespace { |
| 73 | 71 |
| 74 // String pointer used for identifying safebrowing data associated with | 72 // String pointer used for identifying safebrowing data associated with |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 drive::DownloadHandler::GetForProfile(profile); | 174 drive::DownloadHandler::GetForProfile(profile); |
| 177 if (drive_download_handler && | 175 if (drive_download_handler && |
| 178 drive_download_handler->IsDriveDownload(download)) | 176 drive_download_handler->IsDriveDownload(download)) |
| 179 return drive_download_handler->GetTargetPath(download); | 177 return drive_download_handler->GetTargetPath(download); |
| 180 #endif | 178 #endif |
| 181 return download->GetFullPath(); | 179 return download->GetFullPath(); |
| 182 } | 180 } |
| 183 | 181 |
| 184 } // namespace | 182 } // namespace |
| 185 | 183 |
| 186 // static | |
| 187 void ChromeDownloadManagerDelegate::RegisterUserPrefs( | |
| 188 PrefRegistrySyncable* registry) { | |
| 189 const base::FilePath& default_download_path = | |
| 190 download_util::GetDefaultDownloadDirectory(); | |
| 191 registry->RegisterFilePathPref(prefs::kSaveFileDefaultDirectory, | |
| 192 default_download_path, | |
| 193 PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 194 } | |
| 195 | |
| 196 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 184 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| 197 : profile_(profile), | 185 : profile_(profile), |
| 198 next_download_id_(0), | 186 next_download_id_(0), |
| 199 download_prefs_(new DownloadPrefs(profile)) { | 187 download_prefs_(new DownloadPrefs(profile)) { |
| 200 } | 188 } |
| 201 | 189 |
| 202 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 190 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| 203 } | 191 } |
| 204 | 192 |
| 205 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 193 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| 206 download_manager_ = dm; | 194 download_manager_ = dm; |
| 207 } | 195 } |
| 208 | 196 |
| 209 void ChromeDownloadManagerDelegate::Shutdown() { | 197 void ChromeDownloadManagerDelegate::Shutdown() { |
| 210 download_prefs_.reset(); | 198 download_prefs_.reset(); |
| 211 } | 199 } |
| 212 | 200 |
| 213 DownloadId ChromeDownloadManagerDelegate::GetNextId() { | 201 DownloadId ChromeDownloadManagerDelegate::GetNextId() { |
| 214 if (!profile_->IsOffTheRecord()) | 202 if (!profile_->IsOffTheRecord()) |
| 215 return DownloadId(this, next_download_id_++); | 203 return DownloadId(this, next_download_id_++); |
| 216 | 204 |
| 217 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())-> | 205 return content::BrowserContext::GetDownloadManager( |
| 218 GetDelegate()->GetNextId(); | 206 profile_->GetOriginalProfile())->GetDelegate()->GetNextId(); |
| 219 } | 207 } |
| 220 | 208 |
| 221 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( | 209 bool ChromeDownloadManagerDelegate::DetermineDownloadTarget( |
| 222 DownloadItem* download, | 210 DownloadItem* download, |
| 223 const content::DownloadTargetCallback& callback) { | 211 const content::DownloadTargetCallback& callback) { |
| 224 #if defined(FULL_SAFE_BROWSING) | 212 #if defined(FULL_SAFE_BROWSING) |
| 225 DownloadProtectionService* service = GetDownloadProtectionService(); | 213 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 226 if (service) { | 214 if (service) { |
| 227 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 215 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " |
| 228 << download->DebugString(false); | 216 << download->DebugString(false); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 349 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
| 362 #if defined(FULL_SAFE_BROWSING) | 350 #if defined(FULL_SAFE_BROWSING) |
| 363 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 351 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 364 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 352 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
| 365 #else | 353 #else |
| 366 return false; | 354 return false; |
| 367 #endif | 355 #endif |
| 368 } | 356 } |
| 369 | 357 |
| 370 void ChromeDownloadManagerDelegate::GetSaveDir( | 358 void ChromeDownloadManagerDelegate::GetSaveDir( |
| 371 BrowserContext* browser_context, | 359 content::BrowserContext* browser_context, |
| 372 base::FilePath* website_save_dir, | 360 base::FilePath* website_save_dir, |
| 373 base::FilePath* download_save_dir, | 361 base::FilePath* download_save_dir, |
| 374 bool* skip_dir_check) { | 362 bool* skip_dir_check) { |
| 375 Profile* profile = Profile::FromBrowserContext(browser_context); | 363 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 376 PrefService* prefs = profile->GetPrefs(); | 364 PrefService* prefs = profile->GetPrefs(); |
| 377 | 365 |
| 378 // Check whether the preference for the preferred directory for | |
| 379 // saving file has been explicitly set. If not, and the preference | |
| 380 // for the default download directory has been set, initialize it | |
| 381 // with the latter. Note that the defaults for both are the same. | |
| 382 const PrefService::Preference* download_default_directory = | |
| 383 prefs->FindPreference(prefs::kDownloadDefaultDirectory); | |
| 384 if (!download_default_directory->IsDefaultValue() && | |
| 385 prefs->FindPreference( | |
| 386 prefs::kSaveFileDefaultDirectory)->IsDefaultValue()) { | |
| 387 prefs->Set(prefs::kSaveFileDefaultDirectory, | |
| 388 *(download_default_directory->GetValue())); | |
| 389 } | |
| 390 | |
| 391 // Get the directory from preference. | 366 // Get the directory from preference. |
| 392 *website_save_dir = prefs->GetFilePath(prefs::kSaveFileDefaultDirectory); | 367 *website_save_dir = download_prefs_->SaveFilePath(); |
| 393 DCHECK(!website_save_dir->empty()); | 368 DCHECK(!website_save_dir->empty()); |
| 394 | 369 |
| 395 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); | 370 *download_save_dir = prefs->GetFilePath(prefs::kDownloadDefaultDirectory); |
| 396 | 371 |
| 397 *skip_dir_check = false; | 372 *skip_dir_check = false; |
| 398 #if defined(OS_CHROMEOS) | 373 #if defined(OS_CHROMEOS) |
| 399 *skip_dir_check = drive::util::IsUnderDriveMountPoint(*website_save_dir); | 374 *skip_dir_check = drive::util::IsUnderDriveMountPoint(*website_save_dir); |
| 400 #endif | 375 #endif |
| 401 } | 376 } |
| 402 | 377 |
| 403 void ChromeDownloadManagerDelegate::ChooseSavePath( | 378 void ChromeDownloadManagerDelegate::ChooseSavePath( |
| 404 WebContents* web_contents, | 379 WebContents* web_contents, |
| 405 const base::FilePath& suggested_path, | 380 const base::FilePath& suggested_path, |
| 406 const base::FilePath::StringType& default_extension, | 381 const base::FilePath::StringType& default_extension, |
| 407 bool can_save_as_complete, | 382 bool can_save_as_complete, |
| 408 const content::SavePackagePathPickedCallback& callback) { | 383 const content::SavePackagePathPickedCallback& callback) { |
| 409 // Deletes itself. | 384 // Deletes itself. |
| 410 #if defined(OS_CHROMEOS) | |
| 411 new SavePackageFilePickerChromeOS( | |
| 412 web_contents, | |
| 413 suggested_path, | |
| 414 can_save_as_complete, | |
| 415 callback); | |
| 416 #else | |
| 417 new SavePackageFilePicker( | 385 new SavePackageFilePicker( |
| 418 web_contents, | 386 web_contents, |
| 419 suggested_path, | 387 suggested_path, |
| 420 default_extension, | 388 default_extension, |
| 421 can_save_as_complete, | 389 can_save_as_complete, |
| 422 download_prefs_.get(), | 390 download_prefs_.get(), |
| 423 callback); | 391 callback); |
| 424 #endif | |
| 425 } | 392 } |
| 426 | 393 |
| 427 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { | 394 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { |
| 428 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); | 395 platform_util::OpenItem(GetPlatformDownloadPath(profile_, download)); |
| 429 } | 396 } |
| 430 | 397 |
| 431 void ChromeDownloadManagerDelegate::ShowDownloadInShell( | 398 void ChromeDownloadManagerDelegate::ShowDownloadInShell( |
| 432 DownloadItem* download) { | 399 DownloadItem* download) { |
| 433 platform_util::ShowItemInFolder(GetPlatformDownloadPath(profile_, download)); | 400 platform_util::ShowItemInFolder(GetPlatformDownloadPath(profile_, download)); |
| 434 } | 401 } |
| 435 | 402 |
| 436 void ChromeDownloadManagerDelegate::CheckForFileExistence( | 403 void ChromeDownloadManagerDelegate::CheckForFileExistence( |
| 437 DownloadItem* download, | 404 DownloadItem* download, |
| 438 const content::CheckForFileExistenceCallback& callback) { | 405 const content::CheckForFileExistenceCallback& callback) { |
| 439 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
| 440 drive::DownloadHandler* drive_download_handler = | 407 drive::DownloadHandler* drive_download_handler = |
| 441 drive::DownloadHandler::GetForProfile(profile_); | 408 drive::DownloadHandler::GetForProfile(profile_); |
| 442 if (drive_download_handler && | 409 if (drive_download_handler && |
| 443 drive_download_handler->IsDriveDownload(download)) { | 410 drive_download_handler->IsDriveDownload(download)) { |
| 444 drive_download_handler->CheckForFileExistence(download, callback); | 411 drive_download_handler->CheckForFileExistence(download, callback); |
| 445 return; | 412 return; |
| 446 } | 413 } |
| 447 #endif | 414 #endif |
| 448 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::FILE, FROM_HERE, | 415 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::FILE, FROM_HERE, |
| 449 base::Bind(&file_util::PathExists, | 416 base::Bind(&file_util::PathExists, |
| 450 download->GetFullPath()), | 417 download->GetFullPath()), |
| 451 callback); | 418 callback); |
| 452 } | 419 } |
| 453 | 420 |
| 454 void ChromeDownloadManagerDelegate::ClearLastDownloadPath() { | |
| 455 last_download_path_.clear(); | |
| 456 } | |
| 457 | |
| 458 DownloadProtectionService* | 421 DownloadProtectionService* |
| 459 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { | 422 ChromeDownloadManagerDelegate::GetDownloadProtectionService() { |
| 460 #if defined(FULL_SAFE_BROWSING) | 423 #if defined(FULL_SAFE_BROWSING) |
| 461 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 424 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
| 462 if (sb_service && sb_service->download_protection_service() && | 425 if (sb_service && sb_service->download_protection_service() && |
| 463 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 426 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| 464 return sb_service->download_protection_service(); | 427 return sb_service->download_protection_service(); |
| 465 } | 428 } |
| 466 #endif | 429 #endif |
| 467 return NULL; | 430 return NULL; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 ChromeDownloadManagerDelegate::ContinueFilenameDeterminationInfo:: | 591 ChromeDownloadManagerDelegate::ContinueFilenameDeterminationInfo:: |
| 629 ~ContinueFilenameDeterminationInfo() {} | 592 ~ContinueFilenameDeterminationInfo() {} |
| 630 | 593 |
| 631 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 594 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| 632 int32 download_id, | 595 int32 download_id, |
| 633 const content::DownloadTargetCallback& callback, | 596 const content::DownloadTargetCallback& callback, |
| 634 content::DownloadDangerType danger_type, | 597 content::DownloadDangerType danger_type, |
| 635 bool visited_referrer_before) { | 598 bool visited_referrer_before) { |
| 636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 637 | 600 |
| 638 DownloadItem* download = | 601 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 639 download_manager_->GetDownload(download_id); | |
| 640 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 602 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 641 return; | 603 return; |
| 642 | 604 |
| 643 bool should_prompt = (download->GetTargetDisposition() == | 605 bool should_prompt = (download->GetTargetDisposition() == |
| 644 DownloadItem::TARGET_DISPOSITION_PROMPT); | 606 DownloadItem::TARGET_DISPOSITION_PROMPT); |
| 645 bool is_forced_path = !download->GetForcedFilePath().empty(); | 607 bool is_forced_path = !download->GetForcedFilePath().empty(); |
| 646 base::FilePath generated_name; | 608 base::FilePath generated_name; |
| 647 base::FilePath suggested_path; | 609 base::FilePath suggested_path; |
| 648 | 610 |
| 649 // Check whether this download is for an extension install or not. | 611 // Check whether this download is for an extension install or not. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 667 if (!download_crx_util::IsExtensionDownload(*download) && | 629 if (!download_crx_util::IsExtensionDownload(*download) && |
| 668 !ShouldOpenFileBasedOnExtension(generated_name)) | 630 !ShouldOpenFileBasedOnExtension(generated_name)) |
| 669 should_prompt = true; | 631 should_prompt = true; |
| 670 } | 632 } |
| 671 if (download_prefs_->IsDownloadPathManaged()) | 633 if (download_prefs_->IsDownloadPathManaged()) |
| 672 should_prompt = false; | 634 should_prompt = false; |
| 673 | 635 |
| 674 // Determine the proper path for a download, by either one of the following: | 636 // Determine the proper path for a download, by either one of the following: |
| 675 // 1) using the default download directory. | 637 // 1) using the default download directory. |
| 676 // 2) prompting the user. | 638 // 2) prompting the user. |
| 677 base::FilePath target_directory; | 639 base::FilePath target_directory = should_prompt ? |
| 678 if (should_prompt && !last_download_path_.empty()) | 640 download_prefs_->SaveFilePath() : download_prefs_->DownloadPath(); |
| 679 target_directory = last_download_path_; | |
| 680 else | |
| 681 target_directory = download_prefs_->DownloadPath(); | |
| 682 suggested_path = target_directory.Append(generated_name); | 641 suggested_path = target_directory.Append(generated_name); |
| 683 } else { | 642 } else { |
| 684 DCHECK(!should_prompt); | 643 DCHECK(!should_prompt); |
| 685 suggested_path = download->GetForcedFilePath(); | 644 suggested_path = download->GetForcedFilePath(); |
| 686 } | 645 } |
| 687 | 646 |
| 688 ContinueFilenameDeterminationInfo continue_info; | 647 ContinueFilenameDeterminationInfo continue_info; |
| 689 continue_info.download_id = download_id; | 648 continue_info.download_id = download_id; |
| 690 continue_info.callback = callback; | 649 continue_info.callback = callback; |
| 691 continue_info.danger_type = danger_type; | 650 continue_info.danger_type = danger_type; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 716 download, generated_name, filename_determined, overriding); | 675 download, generated_name, filename_determined, overriding); |
| 717 } | 676 } |
| 718 #endif | 677 #endif |
| 719 } | 678 } |
| 720 | 679 |
| 721 void ChromeDownloadManagerDelegate::OnExtensionOverridingFilename( | 680 void ChromeDownloadManagerDelegate::OnExtensionOverridingFilename( |
| 722 const ContinueFilenameDeterminationInfo& continue_info, | 681 const ContinueFilenameDeterminationInfo& continue_info, |
| 723 const base::FilePath& changed_filename, | 682 const base::FilePath& changed_filename, |
| 724 DownloadPathReservationTracker::FilenameConflictAction conflict_action) { | 683 DownloadPathReservationTracker::FilenameConflictAction conflict_action) { |
| 725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 726 DownloadItem* download = | 685 DownloadItem* download = download_manager_->GetDownload( |
| 727 download_manager_->GetDownload(continue_info.download_id); | 686 continue_info.download_id); |
| 728 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 687 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 729 return; | 688 return; |
| 730 | 689 |
| 731 // If an extension overrides the filename, then the target directory will be | 690 // If an extension overrides the filename, then the target directory will be |
| 732 // forced to download_prefs_->DownloadPath() since extensions cannot place | 691 // forced to download_prefs_->DownloadPath() since extensions cannot place |
| 733 // downloaded files anywhere except there. This prevents subdirectories from | 692 // downloaded files anywhere except there. This prevents subdirectories from |
| 734 // accumulating: if an extension is allowed to say that a file should go in | 693 // accumulating: if an extension is allowed to say that a file should go in |
| 735 // last_download_path/music/foo.mp3, then last_download_path will accumulate | 694 // last_download_path/music/foo.mp3, then last_download_path will accumulate |
| 736 // the subdirectory /music/ so that the next download may end up in | 695 // the subdirectory /music/ so that the next download may end up in |
| 737 // Downloads/music/music/music/bar.mp3. | 696 // Downloads/music/music/music/bar.mp3. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 748 void ChromeDownloadManagerDelegate::ContinueDeterminingFilename( | 707 void ChromeDownloadManagerDelegate::ContinueDeterminingFilename( |
| 749 const ContinueFilenameDeterminationInfo& continue_info, | 708 const ContinueFilenameDeterminationInfo& continue_info, |
| 750 const base::FilePath& suggested_path, | 709 const base::FilePath& suggested_path, |
| 751 DownloadPathReservationTracker::FilenameConflictAction conflict_action) { | 710 DownloadPathReservationTracker::FilenameConflictAction conflict_action) { |
| 752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 753 int32 download_id = continue_info.download_id; | 712 int32 download_id = continue_info.download_id; |
| 754 const content::DownloadTargetCallback& callback = continue_info.callback; | 713 const content::DownloadTargetCallback& callback = continue_info.callback; |
| 755 content::DownloadDangerType danger_type = continue_info.danger_type; | 714 content::DownloadDangerType danger_type = continue_info.danger_type; |
| 756 bool visited_referrer_before = continue_info.visited_referrer_before; | 715 bool visited_referrer_before = continue_info.visited_referrer_before; |
| 757 bool should_prompt = continue_info.should_prompt; | 716 bool should_prompt = continue_info.should_prompt; |
| 758 DownloadItem* download = | 717 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 759 download_manager_->GetDownload(download_id); | |
| 760 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 718 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 761 return; | 719 return; |
| 762 | 720 |
| 763 // If the download hasn't already been marked dangerous (could be | 721 // If the download hasn't already been marked dangerous (could be |
| 764 // DANGEROUS_URL), check if it is a dangerous file. | 722 // DANGEROUS_URL), check if it is a dangerous file. |
| 765 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 723 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| 766 if (!should_prompt && | 724 if (!should_prompt && |
| 767 download->GetForcedFilePath().empty() && | 725 download->GetForcedFilePath().empty() && |
| 768 IsDangerousFile(*download, suggested_path, visited_referrer_before)) { | 726 IsDangerousFile(*download, suggested_path, visited_referrer_before)) { |
| 769 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 727 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 #if defined (OS_CHROMEOS) | 769 #if defined (OS_CHROMEOS) |
| 812 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. | 770 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. |
| 813 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback( | 771 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback( |
| 814 int32 download_id, | 772 int32 download_id, |
| 815 const content::DownloadTargetCallback& callback, | 773 const content::DownloadTargetCallback& callback, |
| 816 bool should_prompt, | 774 bool should_prompt, |
| 817 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 775 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 818 content::DownloadDangerType danger_type, | 776 content::DownloadDangerType danger_type, |
| 819 const base::FilePath& suggested_path) { | 777 const base::FilePath& suggested_path) { |
| 820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 821 DownloadItem* download = | 779 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 822 download_manager_->GetDownload(download_id); | |
| 823 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 780 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 824 return; | 781 return; |
| 825 | 782 |
| 826 if (suggested_path.empty()) { | 783 if (suggested_path.empty()) { |
| 827 // Substitution failed. | 784 // Substitution failed. |
| 828 callback.Run(base::FilePath(), | 785 callback.Run(base::FilePath(), |
| 829 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 786 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 830 danger_type, | 787 danger_type, |
| 831 base::FilePath()); | 788 base::FilePath()); |
| 832 return; | 789 return; |
| 833 } | 790 } |
| 834 | 791 |
| 835 GetReservedPath( | 792 GetReservedPath( |
| 836 *download, suggested_path, download_prefs_->DownloadPath(), | 793 *download, suggested_path, download_prefs_->DownloadPath(), |
| 837 conflict_action, | 794 conflict_action, |
| 838 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 795 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
| 839 this, download->GetId(), callback, should_prompt, | 796 this, download->GetId(), callback, should_prompt, |
| 840 danger_type)); | 797 danger_type)); |
| 841 } | 798 } |
| 842 #endif | 799 #endif |
| 843 | 800 |
| 844 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( | 801 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( |
| 845 int32 download_id, | 802 int32 download_id, |
| 846 const content::DownloadTargetCallback& callback, | 803 const content::DownloadTargetCallback& callback, |
| 847 bool should_prompt, | 804 bool should_prompt, |
| 848 content::DownloadDangerType danger_type, | 805 content::DownloadDangerType danger_type, |
| 849 const base::FilePath& reserved_path, | 806 const base::FilePath& reserved_path, |
| 850 bool reserved_path_verified) { | 807 bool reserved_path_verified) { |
| 851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 852 DownloadItem* download = | 809 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 853 download_manager_->GetDownload(download_id); | |
| 854 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 810 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 855 return; | 811 return; |
| 856 if (should_prompt || !reserved_path_verified) { | 812 if (should_prompt || !reserved_path_verified) { |
| 857 // If the target path could not be verified then the path was non-existant, | 813 // If the target path could not be verified then the path was non-existant, |
| 858 // non writeable or could not be uniquified. Prompt the user. | 814 // non writeable or could not be uniquified. Prompt the user. |
| 859 ChooseDownloadPath( | 815 ChooseDownloadPath( |
| 860 download, reserved_path, | 816 download, reserved_path, |
| 861 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, | 817 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, |
| 862 this, download_id, callback, | 818 this, download_id, callback, |
| 863 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); | 819 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); |
| 864 } else { | 820 } else { |
| 865 OnTargetPathDetermined(download_id, callback, | 821 OnTargetPathDetermined(download_id, callback, |
| 866 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 822 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 867 danger_type, reserved_path); | 823 danger_type, reserved_path); |
| 868 } | 824 } |
| 869 } | 825 } |
| 870 | 826 |
| 871 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( | 827 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( |
| 872 int32 download_id, | 828 int32 download_id, |
| 873 const content::DownloadTargetCallback& callback, | 829 const content::DownloadTargetCallback& callback, |
| 874 DownloadItem::TargetDisposition disposition, | 830 DownloadItem::TargetDisposition disposition, |
| 875 content::DownloadDangerType danger_type, | 831 content::DownloadDangerType danger_type, |
| 876 const base::FilePath& target_path) { | 832 const base::FilePath& target_path) { |
| 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 878 base::FilePath intermediate_path; | 834 base::FilePath intermediate_path; |
| 879 DownloadItem* download = | 835 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 880 download_manager_->GetDownload(download_id); | |
| 881 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) | 836 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS)) |
| 882 return; | 837 return; |
| 883 | 838 |
| 884 // If |target_path| is empty, then that means that the user wants to cancel | 839 // If |target_path| is empty, then that means that the user wants to cancel |
| 885 // the download. | 840 // the download. |
| 886 if (!target_path.empty()) { | 841 if (!target_path.empty()) { |
| 887 intermediate_path = GetIntermediatePath( | 842 intermediate_path = GetIntermediatePath( |
| 888 target_path, danger_type, !download->GetForcedFilePath().empty()); | 843 target_path, danger_type, !download->GetForcedFilePath().empty()); |
| 889 | 844 if (!profile_->IsOffTheRecord()) { |
| 890 // Retain the last directory. Exclude temporary downloads since the path | 845 base::FilePath target_dir = target_path.DirName(); |
| 891 // likely points at the location of a temporary file. | 846 #if defined(OS_CHROMEOS) |
| 892 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | 847 drive::DownloadHandler* drive_handler = |
| 893 // directory to persist. Or perhaps, if the Drive path | 848 drive::DownloadHandler::GetForProfile(profile_); |
| 894 // substitution logic is moved here, then we would have a | 849 if (drive_handler->IsDriveDownload(download)) { |
| 895 // persistable path after the DownloadFilePicker is done. | 850 target_dir = drive_handler->GetTargetPath(download); |
| 896 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | 851 } |
| 897 !download->IsTemporary()) | 852 #endif |
| 898 last_download_path_ = target_path.DirName(); | 853 download_prefs_->SetSaveFilePath(target_dir); |
| 854 } |
| 899 } | 855 } |
| 900 callback.Run(target_path, disposition, danger_type, intermediate_path); | 856 callback.Run(target_path, disposition, danger_type, intermediate_path); |
| 901 } | 857 } |
| OLD | NEW |