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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
8 | 8 |
9 #include "chrome/browser/download/download_util.h" | 9 #include "chrome/browser/download/download_util.h" |
10 | 10 |
11 #include <cmath> | 11 #include <cmath> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
16 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/string16.h" | 20 #include "base/string16.h" |
21 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
22 #include "base/sys_string_conversions.h" | 22 #include "base/sys_string_conversions.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
25 #include "base/value_conversions.h" | 25 #include "base/value_conversions.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/browser/download/download_extensions.h" | 27 #include "chrome/browser/download/download_extensions.h" |
28 #include "chrome/browser/download/download_item_model.h" | 28 #include "chrome/browser/download/download_item_model.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/browser.h" | |
31 #include "chrome/browser/ui/browser_window.h" | |
32 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/time_format.h" | 32 #include "chrome/common/time_format.h" |
35 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/download_item.h" | 34 #include "content/public/browser/download_item.h" |
37 #include "content/public/browser/download_manager.h" | 35 #include "content/public/browser/download_manager.h" |
38 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
39 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
40 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
41 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
42 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
43 #include "net/base/mime_util.h" | 41 #include "net/base/mime_util.h" |
44 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
45 #include "skia/ext/image_operations.h" | 43 #include "skia/ext/image_operations.h" |
46 #include "third_party/skia/include/core/SkPath.h" | 44 #include "third_party/skia/include/core/SkPath.h" |
47 #include "third_party/skia/include/core/SkShader.h" | 45 #include "third_party/skia/include/core/SkShader.h" |
48 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
49 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
50 #include "ui/base/text/bytes_formatting.h" | 48 #include "ui/base/text/bytes_formatting.h" |
51 #include "ui/gfx/canvas.h" | 49 #include "ui/gfx/canvas.h" |
52 #include "ui/gfx/image/image.h" | 50 #include "ui/gfx/image/image.h" |
53 #include "ui/gfx/rect.h" | 51 #include "ui/gfx/rect.h" |
54 | 52 |
55 #if defined(OS_WIN) | |
56 #include <shobjidl.h> | |
57 | |
58 #include "base/win/windows_version.h" | |
59 #endif | |
60 | |
61 #if defined(TOOLKIT_VIEWS) | 53 #if defined(TOOLKIT_VIEWS) |
62 #include "ui/base/dragdrop/drag_drop_types.h" | 54 #include "ui/base/dragdrop/drag_drop_types.h" |
63 #include "ui/base/dragdrop/drag_utils.h" | 55 #include "ui/base/dragdrop/drag_utils.h" |
64 #include "ui/base/dragdrop/os_exchange_data.h" | 56 #include "ui/base/dragdrop/os_exchange_data.h" |
65 #include "ui/gfx/screen.h" | 57 #include "ui/gfx/screen.h" |
66 #include "ui/views/widget/widget.h" | 58 #include "ui/views/widget/widget.h" |
67 #endif | 59 #endif |
68 | 60 |
69 #if defined(TOOLKIT_GTK) | 61 #if defined(TOOLKIT_GTK) |
70 #include "chrome/browser/ui/gtk/custom_drag.h" | 62 #include "chrome/browser/ui/gtk/custom_drag.h" |
71 #include "chrome/browser/ui/gtk/unity_service.h" | |
72 #endif // defined(TOOLKIT_GTK) | 63 #endif // defined(TOOLKIT_GTK) |
73 | 64 |
74 #if defined(OS_WIN) && !defined(USE_AURA) | 65 #if defined(OS_WIN) && !defined(USE_AURA) |
75 #include "base/win/scoped_comptr.h" | |
76 #include "chrome/browser/ui/browser_list.h" | |
77 #include "ui/base/dragdrop/drag_source.h" | 66 #include "ui/base/dragdrop/drag_source.h" |
78 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 67 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
79 #endif | 68 #endif |
80 | 69 |
81 #if defined(USE_AURA) | 70 #if defined(USE_AURA) |
82 #include "ui/aura/client/drag_drop_client.h" | 71 #include "ui/aura/client/drag_drop_client.h" |
83 #include "ui/aura/root_window.h" | 72 #include "ui/aura/root_window.h" |
84 #include "ui/aura/window.h" | 73 #include "ui/aura/window.h" |
85 #endif | 74 #endif |
86 | 75 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 536 |
548 if (time_remaining.empty()) { | 537 if (time_remaining.empty()) { |
549 base::i18n::AdjustStringForLocaleDirection(&amount); | 538 base::i18n::AdjustStringForLocaleDirection(&amount); |
550 return l10n_util::GetStringFUTF16( | 539 return l10n_util::GetStringFUTF16( |
551 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); | 540 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); |
552 } | 541 } |
553 return l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, | 542 return l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, |
554 speed_text, amount, time_remaining); | 543 speed_text, amount, time_remaining); |
555 } | 544 } |
556 | 545 |
557 #if !defined(OS_MACOSX) | |
558 void UpdateAppIconDownloadProgress(int download_count, | |
559 bool progress_known, | |
560 float progress) { | |
561 #if defined(USE_AURA) | |
562 // TODO(davemoore) Implement once UX for download is decided <104742> | |
563 #elif defined(OS_WIN) | |
564 // Taskbar progress bar is only supported on Win7. | |
565 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
566 return; | |
567 | |
568 base::win::ScopedComPtr<ITaskbarList3> taskbar; | |
569 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, | |
570 CLSCTX_INPROC_SERVER); | |
571 if (FAILED(result)) { | |
572 VLOG(1) << "Failed creating a TaskbarList object: " << result; | |
573 return; | |
574 } | |
575 | |
576 result = taskbar->HrInit(); | |
577 if (FAILED(result)) { | |
578 LOG(ERROR) << "Failed initializing an ITaskbarList3 interface."; | |
579 return; | |
580 } | |
581 | |
582 // Iterate through all the browser windows, and draw the progress bar. | |
583 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); | |
584 browser_iterator != BrowserList::end(); browser_iterator++) { | |
585 Browser* browser = *browser_iterator; | |
586 BrowserWindow* window = browser->window(); | |
587 if (!window) | |
588 continue; | |
589 HWND frame = window->GetNativeWindow(); | |
590 if (download_count == 0 || progress == 1.0f) | |
591 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); | |
592 else if (!progress_known) | |
593 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); | |
594 else | |
595 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100); | |
596 } | |
597 #elif defined(TOOLKIT_GTK) | |
598 unity::SetDownloadCount(download_count); | |
599 unity::SetProgressFraction(progress); | |
600 #endif | |
601 } | |
602 #endif | |
603 | |
604 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 546 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
605 return FilePath(suggested_path.value() + FILE_PATH_LITERAL(".crdownload")); | 547 return FilePath(suggested_path.value() + FILE_PATH_LITERAL(".crdownload")); |
606 } | 548 } |
607 | 549 |
608 bool IsSavableURL(const GURL& url) { | 550 bool IsSavableURL(const GURL& url) { |
609 for (int i = 0; content::GetSavableSchemes()[i] != NULL; ++i) { | 551 for (int i = 0; content::GetSavableSchemes()[i] != NULL; ++i) { |
610 if (url.SchemeIs(content::GetSavableSchemes()[i])) { | 552 if (url.SchemeIs(content::GetSavableSchemes()[i])) { |
611 return true; | 553 return true; |
612 } | 554 } |
613 } | 555 } |
(...skipping 23 matching lines...) Expand all Loading... |
637 UMA_HISTOGRAM_ENUMERATION( | 579 UMA_HISTOGRAM_ENUMERATION( |
638 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); | 580 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); |
639 } | 581 } |
640 | 582 |
641 void RecordDownloadSource(ChromeDownloadSource source) { | 583 void RecordDownloadSource(ChromeDownloadSource source) { |
642 UMA_HISTOGRAM_ENUMERATION( | 584 UMA_HISTOGRAM_ENUMERATION( |
643 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); | 585 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); |
644 } | 586 } |
645 | 587 |
646 } // namespace download_util | 588 } // namespace download_util |
OLD | NEW |