Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/download/download_file_picker.h" | 22 #include "chrome/browser/download/download_file_picker.h" |
| 23 #include "chrome/browser/download/download_history.h" | 23 #include "chrome/browser/download/download_history.h" |
| 24 #include "chrome/browser/download/download_path_reservation_tracker.h" | 24 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 25 #include "chrome/browser/download/download_prefs.h" | 25 #include "chrome/browser/download/download_prefs.h" |
| 26 #include "chrome/browser/download/download_status_updater.h" | 26 #include "chrome/browser/download/download_status_updater.h" |
| 27 #include "chrome/browser/download/download_util.h" | 27 #include "chrome/browser/download/download_util.h" |
| 28 #include "chrome/browser/download/save_package_file_picker.h" | 28 #include "chrome/browser/download/save_package_file_picker.h" |
| 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 30 #include "chrome/browser/extensions/crx_installer.h" | 30 #include "chrome/browser/extensions/crx_installer.h" |
| 31 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
| 32 #include "chrome/browser/intents/web_intents_util.h" | |
| 32 #include "chrome/browser/prefs/pref_service.h" | 33 #include "chrome/browser/prefs/pref_service.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 35 #include "chrome/browser/ui/browser_tabstrip.h" | 36 #include "chrome/browser/ui/browser_tabstrip.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/extensions/extension_switch_utils.h" | 38 #include "chrome/common/extensions/extension_switch_utils.h" |
| 38 #include "chrome/common/extensions/user_script.h" | 39 #include "chrome/common/extensions/user_script.h" |
| 39 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 40 #include "content/public/browser/download_item.h" | 41 #include "content/public/browser/download_item.h" |
| 41 #include "content/public/browser/download_manager.h" | 42 #include "content/public/browser/download_manager.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 OpenWithWebIntent(item); | 383 OpenWithWebIntent(item); |
| 383 item->DelayedDownloadOpened(true /* did_open */); | 384 item->DelayedDownloadOpened(true /* did_open */); |
| 384 return false; | 385 return false; |
| 385 } | 386 } |
| 386 | 387 |
| 387 return true; | 388 return true; |
| 388 } | 389 } |
| 389 | 390 |
| 390 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( | 391 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( |
| 391 const DownloadItem* item) { | 392 const DownloadItem* item) { |
| 392 if (!item->GetWebContents() || !item->GetWebContents()->GetDelegate()) | 393 if ((item->GetWebContents() && !item->GetWebContents()->GetDelegate()) && |
| 394 !web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_)) { | |
| 393 return false; | 395 return false; |
| 396 } | |
| 394 if (!item->GetForcedFilePath().empty()) | 397 if (!item->GetForcedFilePath().empty()) |
| 395 return false; | 398 return false; |
| 396 | 399 |
| 397 std::string mime_type = item->GetMimeType(); | 400 std::string mime_type = item->GetMimeType(); |
| 398 if (mime_type == "application/rss+xml" || | 401 if (mime_type == "application/rss+xml" || |
| 399 mime_type == "application/atom+xml") { | 402 mime_type == "application/atom+xml") { |
| 400 return true; | 403 return true; |
| 401 } | 404 } |
| 402 | 405 |
| 403 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 | 456 |
| 454 // Pass the downloaded filename to the service app as the name hint. | 457 // Pass the downloaded filename to the service app as the name hint. |
| 455 intent_data.extra_data.insert( | 458 intent_data.extra_data.insert( |
| 456 make_pair(ASCIIToUTF16("filename"), | 459 make_pair(ASCIIToUTF16("filename"), |
| 457 item->GetFileNameToReportUser().LossyDisplayName())); | 460 item->GetFileNameToReportUser().LossyDisplayName())); |
| 458 | 461 |
| 459 content::WebIntentsDispatcher* dispatcher = | 462 content::WebIntentsDispatcher* dispatcher = |
| 460 content::WebIntentsDispatcher::Create(intent_data); | 463 content::WebIntentsDispatcher::Create(intent_data); |
| 461 dispatcher->RegisterReplyNotification( | 464 dispatcher->RegisterReplyNotification( |
| 462 base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath())); | 465 base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath())); |
| 463 // TODO(gbillock): try to get this to be able to delegate to the Browser | 466 |
| 464 // object directly, passing a NULL WebContents? | 467 content::WebContentsDelegate* delegate = NULL; |
| 465 item->GetWebContents()->GetDelegate()->WebIntentDispatch( | 468 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) { |
| 466 item->GetWebContents(), dispatcher); | 469 delegate = item->GetWebContents()->GetDelegate(); |
| 470 } else { | |
| 471 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery( | |
| 472 profile_); | |
| 473 } | |
| 474 if (delegate) | |
| 475 delegate->WebIntentDispatch(NULL, dispatcher); | |
|
Randy Smith (Not in Mondays)
2012/09/10 15:43:35
DCHECK opportunity here? Should we ever end up he
| |
| 467 } | 476 } |
| 468 | 477 |
| 469 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 478 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
| 470 #if defined(ENABLE_SAFE_BROWSING) | 479 #if defined(ENABLE_SAFE_BROWSING) |
| 471 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 480 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 472 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 481 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
| 473 #else | 482 #else |
| 474 return false; | 483 return false; |
| 475 #endif | 484 #endif |
| 476 } | 485 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 // where an extension is installed, not when one is downloaded with | 735 // where an extension is installed, not when one is downloaded with |
| 727 // "save as...". | 736 // "save as...". |
| 728 // 2) Filetypes marked "always open." If the user just wants this file | 737 // 2) Filetypes marked "always open." If the user just wants this file |
| 729 // opened, don't bother asking where to keep it. | 738 // opened, don't bother asking where to keep it. |
| 730 if (!download_crx_util::IsExtensionDownload(*download) && | 739 if (!download_crx_util::IsExtensionDownload(*download) && |
| 731 !ShouldOpenFileBasedOnExtension(generated_name)) | 740 !ShouldOpenFileBasedOnExtension(generated_name)) |
| 732 should_prompt = true; | 741 should_prompt = true; |
| 733 } | 742 } |
| 734 if (download_prefs_->IsDownloadPathManaged()) | 743 if (download_prefs_->IsDownloadPathManaged()) |
| 735 should_prompt = false; | 744 should_prompt = false; |
| 745 if (ShouldOpenWithWebIntents(download)) | |
| 746 should_prompt = false; | |
| 736 | 747 |
| 737 // Determine the proper path for a download, by either one of the following: | 748 // Determine the proper path for a download, by either one of the following: |
| 738 // 1) using the default download directory. | 749 // 1) using the default download directory. |
| 739 // 2) prompting the user. | 750 // 2) prompting the user. |
| 740 FilePath target_directory; | 751 FilePath target_directory; |
| 741 if (should_prompt && !last_download_path_.empty()) | 752 if (should_prompt && !last_download_path_.empty()) |
| 742 target_directory = last_download_path_; | 753 target_directory = last_download_path_; |
| 743 else | 754 else |
| 744 target_directory = download_prefs_->DownloadPath(); | 755 target_directory = download_prefs_->DownloadPath(); |
| 745 suggested_path = target_directory.Append(generated_name); | 756 suggested_path = target_directory.Append(generated_name); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 int32 download_id, int64 db_handle) { | 899 int32 download_id, int64 db_handle) { |
| 889 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 900 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 890 // call this function with an invalid |db_handle|. For instance, this can | 901 // call this function with an invalid |db_handle|. For instance, this can |
| 891 // happen when the history database is offline. We cannot have multiple | 902 // happen when the history database is offline. We cannot have multiple |
| 892 // DownloadItems with the same invalid db_handle, so we need to assign a | 903 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 893 // unique |db_handle| here. | 904 // unique |db_handle| here. |
| 894 if (db_handle == DownloadItem::kUninitializedHandle) | 905 if (db_handle == DownloadItem::kUninitializedHandle) |
| 895 db_handle = download_history_->GetNextFakeDbHandle(); | 906 db_handle = download_history_->GetNextFakeDbHandle(); |
| 896 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 907 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 897 } | 908 } |
| OLD | NEW |