| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Download utility implementation | 5 // Download utility implementation |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/download/download_extensions.h" | 28 #include "chrome/browser/download/download_extensions.h" |
| 29 #include "chrome/browser/download/download_item.h" | 29 #include "chrome/browser/download/download_item.h" |
| 30 #include "chrome/browser/download/download_item_model.h" | 30 #include "chrome/browser/download/download_item_model.h" |
| 31 #include "chrome/browser/download/download_manager.h" | 31 #include "chrome/browser/download/download_manager.h" |
| 32 #include "chrome/browser/extensions/crx_installer.h" | 32 #include "chrome/browser/extensions/crx_installer.h" |
| 33 #include "chrome/browser/extensions/extension_install_ui.h" | 33 #include "chrome/browser/extensions/extension_install_ui.h" |
| 34 #include "chrome/browser/extensions/extension_service.h" | 34 #include "chrome/browser/extensions/extension_service.h" |
| 35 #include "chrome/browser/history/download_create_info.h" | 35 #include "chrome/browser/history/download_create_info.h" |
| 36 #include "chrome/browser/net/chrome_url_request_context.h" | 36 #include "chrome/browser/net/chrome_url_request_context.h" |
| 37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/renderer_host/render_view_host.h" |
| 38 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 39 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 39 #include "chrome/browser/tab_contents/tab_contents.h" | 40 #include "chrome/browser/tab_contents/tab_contents.h" |
| 40 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
| 41 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 42 #include "chrome/common/notification_service.h" | 43 #include "chrome/common/notification_service.h" |
| 43 #include "chrome/common/time_format.h" | 44 #include "chrome/common/time_format.h" |
| 44 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 45 #include "grit/locale_settings.h" | 46 #include "grit/locale_settings.h" |
| 46 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
| 47 #include "net/base/mime_util.h" | 48 #include "net/base/mime_util.h" |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 Browser* browser = *browser_iterator; | 681 Browser* browser = *browser_iterator; |
| 681 BrowserWindow* window = browser->window(); | 682 BrowserWindow* window = browser->window(); |
| 682 if (!window) | 683 if (!window) |
| 683 continue; | 684 continue; |
| 684 HWND frame = window->GetNativeHandle(); | 685 HWND frame = window->GetNativeHandle(); |
| 685 if (download_count == 0 || progress == 1.0f) | 686 if (download_count == 0 || progress == 1.0f) |
| 686 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); | 687 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); |
| 687 else if (!progress_known) | 688 else if (!progress_known) |
| 688 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); | 689 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); |
| 689 else | 690 else |
| 690 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); | 691 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100); |
| 691 } | 692 } |
| 692 #endif | 693 #endif |
| 693 } | 694 } |
| 694 #endif | 695 #endif |
| 695 | 696 |
| 696 // Appends the passed the number between parenthesis the path before the | 697 // Appends the passed the number between parenthesis the path before the |
| 697 // extension. | 698 // extension. |
| 698 void AppendNumberToPath(FilePath* path, int number) { | 699 void AppendNumberToPath(FilePath* path, int number) { |
| 699 *path = path->InsertBeforeExtensionASCII(StringPrintf(" (%d)", number)); | 700 *path = path->InsertBeforeExtensionASCII(StringPrintf(" (%d)", number)); |
| 700 } | 701 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 context); | 743 context); |
| 743 } | 744 } |
| 744 | 745 |
| 745 void CancelDownloadRequest(ResourceDispatcherHost* rdh, | 746 void CancelDownloadRequest(ResourceDispatcherHost* rdh, |
| 746 int render_process_id, | 747 int render_process_id, |
| 747 int request_id) { | 748 int request_id) { |
| 748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 749 rdh->CancelRequest(render_process_id, request_id, false); | 750 rdh->CancelRequest(render_process_id, request_id, false); |
| 750 } | 751 } |
| 751 | 752 |
| 753 void NotifyDownloadInitiated(int render_process_id, int render_view_id) { |
| 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 755 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, |
| 756 render_view_id); |
| 757 if (!rvh) |
| 758 return; |
| 759 |
| 760 NotificationService::current()->Notify(NotificationType::DOWNLOAD_INITIATED, |
| 761 Source<RenderViewHost>(rvh), |
| 762 NotificationService::NoDetails()); |
| 763 } |
| 764 |
| 752 int GetUniquePathNumberWithCrDownload(const FilePath& path) { | 765 int GetUniquePathNumberWithCrDownload(const FilePath& path) { |
| 753 if (!file_util::PathExists(path) && | 766 if (!file_util::PathExists(path) && |
| 754 !file_util::PathExists(GetCrDownloadPath(path))) | 767 !file_util::PathExists(GetCrDownloadPath(path))) |
| 755 return 0; | 768 return 0; |
| 756 | 769 |
| 757 FilePath new_path; | 770 FilePath new_path; |
| 758 for (int count = 1; count <= kMaxUniqueFiles; ++count) { | 771 for (int count = 1; count <= kMaxUniqueFiles; ++count) { |
| 759 new_path = FilePath(path); | 772 new_path = FilePath(path); |
| 760 AppendNumberToPath(&new_path, count); | 773 AppendNumberToPath(&new_path, count); |
| 761 | 774 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 826 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
| 814 // Extensions that are not from the gallery are considered dangerous. | 827 // Extensions that are not from the gallery are considered dangerous. |
| 815 ret = true; | 828 ret = true; |
| 816 } | 829 } |
| 817 } | 830 } |
| 818 | 831 |
| 819 return ret; | 832 return ret; |
| 820 } | 833 } |
| 821 | 834 |
| 822 } // namespace download_util | 835 } // namespace download_util |
| OLD | NEW |