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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 content::Source<extensions::CrxInstaller>(crx_installer.get())); | 368 content::Source<extensions::CrxInstaller>(crx_installer.get())); |
369 | 369 |
370 crx_installers_[crx_installer.get()] = callback; | 370 crx_installers_[crx_installer.get()] = callback; |
371 // The status text and percent complete indicator will change now | 371 // The status text and percent complete indicator will change now |
372 // that we are installing a CRX. Update observers so that they pick | 372 // that we are installing a CRX. Update observers so that they pick |
373 // up the change. | 373 // up the change. |
374 item->UpdateObservers(); | 374 item->UpdateObservers(); |
375 return false; | 375 return false; |
376 } | 376 } |
377 | 377 |
| 378 #if defined(ENABLE_WEB_INTENTS) |
378 if (ShouldOpenWithWebIntents(item)) { | 379 if (ShouldOpenWithWebIntents(item)) { |
379 OpenWithWebIntent(item); | 380 OpenWithWebIntent(item); |
380 callback.Run(true); | 381 callback.Run(true); |
381 return false; | 382 return false; |
382 } | 383 } |
| 384 #endif |
383 | 385 |
384 return true; | 386 return true; |
385 } | 387 } |
386 | 388 |
| 389 #if defined(ENABLE_WEB_INTENTS) |
387 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( | 390 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( |
388 const DownloadItem* item) { | 391 const DownloadItem* item) { |
389 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) | 392 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) |
390 return false; | 393 return false; |
391 | 394 |
392 if ((item->GetWebContents() && !item->GetWebContents()->GetDelegate()) && | 395 if ((item->GetWebContents() && !item->GetWebContents()->GetDelegate()) && |
393 !web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_)) { | 396 !web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_)) { |
394 return false; | 397 return false; |
395 } | 398 } |
396 if (!item->GetForcedFilePath().empty()) | 399 if (!item->GetForcedFilePath().empty()) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 #if !defined(OS_ANDROID) | 467 #if !defined(OS_ANDROID) |
465 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) { | 468 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) { |
466 delegate = item->GetWebContents()->GetDelegate(); | 469 delegate = item->GetWebContents()->GetDelegate(); |
467 } else { | 470 } else { |
468 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_); | 471 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_); |
469 } | 472 } |
470 #endif // !defined(OS_ANDROID) | 473 #endif // !defined(OS_ANDROID) |
471 DCHECK(delegate); | 474 DCHECK(delegate); |
472 delegate->WebIntentDispatch(NULL, dispatcher); | 475 delegate->WebIntentDispatch(NULL, dispatcher); |
473 } | 476 } |
| 477 #endif |
474 | 478 |
475 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 479 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
476 #if defined(FULL_SAFE_BROWSING) | 480 #if defined(FULL_SAFE_BROWSING) |
477 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 481 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
478 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 482 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
479 #else | 483 #else |
480 return false; | 484 return false; |
481 #endif | 485 #endif |
482 } | 486 } |
483 | 487 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 if (should_prompt && !last_download_path_.empty()) | 750 if (should_prompt && !last_download_path_.empty()) |
747 target_directory = last_download_path_; | 751 target_directory = last_download_path_; |
748 else | 752 else |
749 target_directory = download_prefs_->DownloadPath(); | 753 target_directory = download_prefs_->DownloadPath(); |
750 suggested_path = target_directory.Append(generated_name); | 754 suggested_path = target_directory.Append(generated_name); |
751 } else { | 755 } else { |
752 DCHECK(!should_prompt); | 756 DCHECK(!should_prompt); |
753 suggested_path = download->GetForcedFilePath(); | 757 suggested_path = download->GetForcedFilePath(); |
754 } | 758 } |
755 | 759 |
| 760 #if defined(ENABLE_WEB_INTENTS) |
756 // If we will open the file with a web intents dispatch, | 761 // If we will open the file with a web intents dispatch, |
757 // give it a name that will not allow the OS to open it using usual | 762 // give it a name that will not allow the OS to open it using usual |
758 // associated apps. | 763 // associated apps. |
759 if (ShouldOpenWithWebIntents(download)) { | 764 if (ShouldOpenWithWebIntents(download)) { |
760 download->SetDisplayName(suggested_path.BaseName()); | 765 download->SetDisplayName(suggested_path.BaseName()); |
761 suggested_path = suggested_path.AddExtension(kWebIntentsFileExtension); | 766 suggested_path = suggested_path.AddExtension(kWebIntentsFileExtension); |
762 } | 767 } |
| 768 #endif |
763 | 769 |
764 // If the download hasn't already been marked dangerous (could be | 770 // If the download hasn't already been marked dangerous (could be |
765 // DANGEROUS_URL), check if it is a dangerous file. | 771 // DANGEROUS_URL), check if it is a dangerous file. |
766 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 772 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
767 if (!should_prompt && !is_forced_path && | 773 if (!should_prompt && !is_forced_path && |
768 IsDangerousFile(*download, suggested_path, visited_referrer_before)) { | 774 IsDangerousFile(*download, suggested_path, visited_referrer_before)) { |
769 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 775 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
770 } | 776 } |
771 | 777 |
772 #if defined(FULL_SAFE_BROWSING) | 778 #if defined(FULL_SAFE_BROWSING) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | 900 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a |
895 // directory to persist. Or perhaps, if the Drive path | 901 // directory to persist. Or perhaps, if the Drive path |
896 // substitution logic is moved here, then we would have a | 902 // substitution logic is moved here, then we would have a |
897 // persistable path after the DownloadFilePicker is done. | 903 // persistable path after the DownloadFilePicker is done. |
898 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | 904 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && |
899 !download->IsTemporary()) | 905 !download->IsTemporary()) |
900 last_download_path_ = target_path.DirName(); | 906 last_download_path_ = target_path.DirName(); |
901 } | 907 } |
902 callback.Run(target_path, disposition, danger_type, intermediate_path); | 908 callback.Run(target_path, disposition, danger_type, intermediate_path); |
903 } | 909 } |
OLD | NEW |