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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 OpenWithWebIntent(item); | 363 OpenWithWebIntent(item); |
363 item->DelayedDownloadOpened(true /* did_open */); | 364 item->DelayedDownloadOpened(true /* did_open */); |
364 return false; | 365 return false; |
365 } | 366 } |
366 | 367 |
367 return true; | 368 return true; |
368 } | 369 } |
369 | 370 |
370 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( | 371 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( |
371 const DownloadItem* item) { | 372 const DownloadItem* item) { |
372 if (!item->GetWebContents() || !item->GetWebContents()->GetDelegate()) | 373 if (web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_) == NULL) |
benjhayden
2012/08/28 19:13:06
if (!web_intents::...(...)) instead of explicit co
Greg Billock
2012/09/07 18:52:34
Done.
| |
373 return false; | 374 return false; |
374 | 375 |
375 std::string mime_type = item->GetMimeType(); | 376 std::string mime_type = item->GetMimeType(); |
376 if (mime_type == "application/rss+xml" || | 377 if (mime_type == "application/rss+xml" || |
377 mime_type == "application/atom+xml") { | 378 mime_type == "application/atom+xml") { |
378 return true; | 379 return true; |
379 } | 380 } |
380 | 381 |
381 #if defined(OS_CHROMEOS) | 382 #if defined(OS_CHROMEOS) |
382 if (mime_type == "application/msword" || | 383 if (mime_type == "application/msword" || |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 intent_data.extra_data.insert(make_pair( | 430 intent_data.extra_data.insert(make_pair( |
430 ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec()))); | 431 ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec()))); |
431 | 432 |
432 // Pass the downloaded filename to the service app as the name hint. | 433 // Pass the downloaded filename to the service app as the name hint. |
433 intent_data.extra_data.insert( | 434 intent_data.extra_data.insert( |
434 make_pair(ASCIIToUTF16("filename"), | 435 make_pair(ASCIIToUTF16("filename"), |
435 item->GetFileNameToReportUser().LossyDisplayName())); | 436 item->GetFileNameToReportUser().LossyDisplayName())); |
436 | 437 |
437 content::WebIntentsDispatcher* dispatcher = | 438 content::WebIntentsDispatcher* dispatcher = |
438 content::WebIntentsDispatcher::Create(intent_data); | 439 content::WebIntentsDispatcher::Create(intent_data); |
439 // TODO(gbillock): try to get this to be able to delegate to the Browser | 440 |
440 // object directly, passing a NULL WebContents? | 441 content::WebContentsDelegate* delegate = NULL; |
441 item->GetWebContents()->GetDelegate()->WebIntentDispatch( | 442 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) { |
442 item->GetWebContents(), dispatcher); | 443 delegate = item->GetWebContents()->GetDelegate(); |
444 } else { | |
445 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery( | |
446 profile_); | |
447 } | |
448 if (delegate) | |
449 delegate->WebIntentDispatch(NULL, dispatcher); | |
443 } | 450 } |
444 | 451 |
445 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 452 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
446 #if defined(ENABLE_SAFE_BROWSING) | 453 #if defined(ENABLE_SAFE_BROWSING) |
447 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 454 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
448 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 455 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
449 #else | 456 #else |
450 return false; | 457 return false; |
451 #endif | 458 #endif |
452 } | 459 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 // where an extension is installed, not when one is downloaded with | 709 // where an extension is installed, not when one is downloaded with |
703 // "save as...". | 710 // "save as...". |
704 // 2) Filetypes marked "always open." If the user just wants this file | 711 // 2) Filetypes marked "always open." If the user just wants this file |
705 // opened, don't bother asking where to keep it. | 712 // opened, don't bother asking where to keep it. |
706 if (!download_crx_util::IsExtensionDownload(*download) && | 713 if (!download_crx_util::IsExtensionDownload(*download) && |
707 !ShouldOpenFileBasedOnExtension(generated_name)) | 714 !ShouldOpenFileBasedOnExtension(generated_name)) |
708 should_prompt = true; | 715 should_prompt = true; |
709 } | 716 } |
710 if (download_prefs_->IsDownloadPathManaged()) | 717 if (download_prefs_->IsDownloadPathManaged()) |
711 should_prompt = false; | 718 should_prompt = false; |
719 if (ShouldOpenWithWebIntents(download)) | |
720 should_prompt = false; | |
712 | 721 |
713 // Determine the proper path for a download, by either one of the following: | 722 // Determine the proper path for a download, by either one of the following: |
714 // 1) using the default download directory. | 723 // 1) using the default download directory. |
715 // 2) prompting the user. | 724 // 2) prompting the user. |
716 FilePath target_directory; | 725 FilePath target_directory; |
717 if (should_prompt && !last_download_path_.empty()) | 726 if (should_prompt && !last_download_path_.empty()) |
718 target_directory = last_download_path_; | 727 target_directory = last_download_path_; |
719 else | 728 else |
720 target_directory = download_prefs_->DownloadPath(); | 729 target_directory = download_prefs_->DownloadPath(); |
721 suggested_path = target_directory.Append(generated_name); | 730 suggested_path = target_directory.Append(generated_name); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 int32 download_id, int64 db_handle) { | 865 int32 download_id, int64 db_handle) { |
857 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 866 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
858 // call this function with an invalid |db_handle|. For instance, this can | 867 // call this function with an invalid |db_handle|. For instance, this can |
859 // happen when the history database is offline. We cannot have multiple | 868 // happen when the history database is offline. We cannot have multiple |
860 // DownloadItems with the same invalid db_handle, so we need to assign a | 869 // DownloadItems with the same invalid db_handle, so we need to assign a |
861 // unique |db_handle| here. | 870 // unique |db_handle| here. |
862 if (db_handle == DownloadItem::kUninitializedHandle) | 871 if (db_handle == DownloadItem::kUninitializedHandle) |
863 db_handle = download_history_->GetNextFakeDbHandle(); | 872 db_handle = download_history_->GetNextFakeDbHandle(); |
864 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 873 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
865 } | 874 } |
OLD | NEW |