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 (!web_intents::IsWebIntentsEnabledForProfile(profile_)) |
393 return false; | 394 return false; |
| 395 |
| 396 if ((item->GetWebContents() && !item->GetWebContents()->GetDelegate()) && |
| 397 !web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_)) { |
| 398 return false; |
| 399 } |
394 if (!item->GetForcedFilePath().empty()) | 400 if (!item->GetForcedFilePath().empty()) |
395 return false; | 401 return false; |
| 402 if (item->GetTargetDisposition() == DownloadItem::TARGET_DISPOSITION_PROMPT) |
| 403 return false; |
396 | 404 |
397 std::string mime_type = item->GetMimeType(); | 405 std::string mime_type = item->GetMimeType(); |
398 if (mime_type == "application/rss+xml" || | 406 if (mime_type == "application/rss+xml" || |
399 mime_type == "application/atom+xml") { | 407 mime_type == "application/atom+xml") { |
400 return true; | 408 return true; |
401 } | 409 } |
402 | 410 |
403 #if defined(OS_CHROMEOS) | 411 #if defined(OS_CHROMEOS) |
404 if (mime_type == "application/msword" || | 412 if (mime_type == "application/msword" || |
405 mime_type == "application/vnd.ms-powerpoint" || | 413 mime_type == "application/vnd.ms-powerpoint" || |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 461 |
454 // Pass the downloaded filename to the service app as the name hint. | 462 // Pass the downloaded filename to the service app as the name hint. |
455 intent_data.extra_data.insert( | 463 intent_data.extra_data.insert( |
456 make_pair(ASCIIToUTF16("filename"), | 464 make_pair(ASCIIToUTF16("filename"), |
457 item->GetFileNameToReportUser().LossyDisplayName())); | 465 item->GetFileNameToReportUser().LossyDisplayName())); |
458 | 466 |
459 content::WebIntentsDispatcher* dispatcher = | 467 content::WebIntentsDispatcher* dispatcher = |
460 content::WebIntentsDispatcher::Create(intent_data); | 468 content::WebIntentsDispatcher::Create(intent_data); |
461 dispatcher->RegisterReplyNotification( | 469 dispatcher->RegisterReplyNotification( |
462 base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath())); | 470 base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath())); |
463 // TODO(gbillock): try to get this to be able to delegate to the Browser | 471 |
464 // object directly, passing a NULL WebContents? | 472 content::WebContentsDelegate* delegate = NULL; |
465 item->GetWebContents()->GetDelegate()->WebIntentDispatch( | 473 #if !defined(OS_ANDROID) |
466 item->GetWebContents(), dispatcher); | 474 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) { |
| 475 delegate = item->GetWebContents()->GetDelegate(); |
| 476 } else { |
| 477 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_); |
| 478 } |
| 479 #endif // !defined(OS_ANDROID) |
| 480 DCHECK(delegate); |
| 481 delegate->WebIntentDispatch(NULL, dispatcher); |
467 } | 482 } |
468 | 483 |
469 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 484 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
470 #if defined(ENABLE_SAFE_BROWSING) | 485 #if defined(ENABLE_SAFE_BROWSING) |
471 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 486 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
472 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 487 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
473 #else | 488 #else |
474 return false; | 489 return false; |
475 #endif | 490 #endif |
476 } | 491 } |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 int32 download_id, int64 db_handle) { | 903 int32 download_id, int64 db_handle) { |
889 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 904 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
890 // call this function with an invalid |db_handle|. For instance, this can | 905 // call this function with an invalid |db_handle|. For instance, this can |
891 // happen when the history database is offline. We cannot have multiple | 906 // 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 | 907 // DownloadItems with the same invalid db_handle, so we need to assign a |
893 // unique |db_handle| here. | 908 // unique |db_handle| here. |
894 if (db_handle == DownloadItem::kUninitializedHandle) | 909 if (db_handle == DownloadItem::kUninitializedHandle) |
895 db_handle = download_history_->GetNextFakeDbHandle(); | 910 db_handle = download_history_->GetNextFakeDbHandle(); |
896 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 911 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
897 } | 912 } |
OLD | NEW |