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