Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/download/download_status_updater_win.cc

Issue 243703003: Removes win8_util (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/download_status_updater.h" 5 #include "chrome/browser/download/download_status_updater.h"
6 6
7 #include <shobjidl.h> 7 #include <shobjidl.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/win/metro.h"
15 #include "base/win/scoped_comptr.h" 11 #include "base/win/scoped_comptr.h"
16 #include "base/win/windows_version.h" 12 #include "base/win/windows_version.h"
17 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_iterator.h" 14 #include "chrome/browser/ui/browser_iterator.h"
20 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/views/win/hwnd_util.h" 18 #include "ui/views/win/hwnd_util.h"
26 #include "url/gurl.h"
27 #include "win8/util/win8_util.h"
28 19
29 namespace { 20 namespace {
30 21
31 const char kDownloadNotificationPrefix[] = "DownloadNotification";
32 int g_next_notification_id = 0;
33
34 void UpdateTaskbarProgressBar(int download_count, 22 void UpdateTaskbarProgressBar(int download_count,
35 bool progress_known, 23 bool progress_known,
36 float progress) { 24 float progress) {
37 // Taskbar progress bar is only supported on Win7. 25 // Taskbar progress bar is only supported on Win7.
38 if (base::win::GetVersion() < base::win::VERSION_WIN7) 26 if (base::win::GetVersion() < base::win::VERSION_WIN7)
39 return; 27 return;
40 28
41 base::win::ScopedComPtr<ITaskbarList3> taskbar; 29 base::win::ScopedComPtr<ITaskbarList3> taskbar;
42 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, 30 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
43 CLSCTX_INPROC_SERVER); 31 CLSCTX_INPROC_SERVER);
(...skipping 17 matching lines...) Expand all
61 HWND frame = views::HWNDForNativeWindow(window->GetNativeWindow()); 49 HWND frame = views::HWNDForNativeWindow(window->GetNativeWindow());
62 if (download_count == 0 || progress == 1.0f) 50 if (download_count == 0 || progress == 1.0f)
63 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); 51 taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
64 else if (!progress_known) 52 else if (!progress_known)
65 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); 53 taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
66 else 54 else
67 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100); 55 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100);
68 } 56 }
69 } 57 }
70 58
71 void MetroDownloadNotificationClickedHandler(const wchar_t* download_path) {
72 // Metro chrome will invoke these handlers on the metro thread.
73 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
74
75 // Ensure that we invoke the function to display the downloaded item on the
76 // UI thread.
77 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
78 base::Bind(platform_util::ShowItemInFolder,
79 static_cast<Profile*>(NULL),
80 base::FilePath(download_path)));
81 }
82
83 } // namespace 59 } // namespace
84 60
85 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( 61 void DownloadStatusUpdater::UpdateAppIconDownloadProgress(
86 content::DownloadItem* download) { 62 content::DownloadItem* download) {
87 63
88 // Always update overall progress. 64 // Always update overall progress.
89 float progress = 0; 65 float progress = 0;
90 int download_count = 0; 66 int download_count = 0;
91 bool progress_known = GetProgress(&progress, &download_count); 67 bool progress_known = GetProgress(&progress, &download_count);
92 UpdateTaskbarProgressBar(download_count, progress_known, progress); 68 UpdateTaskbarProgressBar(download_count, progress_known, progress);
93
94 // Fire notifications when downloads complete.
95 if (!win8::IsSingleWindowMetroMode())
96 return;
97
98 if (download->GetState() != content::DownloadItem::COMPLETE)
99 return;
100
101 if (download->GetOpenWhenComplete() ||
102 download->ShouldOpenFileBasedOnExtension() ||
103 download->IsTemporary() ||
104 download->GetAutoOpened())
105 return;
106
107 // Don't display the Windows8 metro notifications for an incognito download.
108 if (download->GetBrowserContext() &&
109 download->GetBrowserContext()->IsOffTheRecord())
110 return;
111
112 // Don't display the Windows 8 metro notifications if we are in the
113 // foreground.
114 HWND foreground_window = ::GetForegroundWindow();
115 if (::IsWindow(foreground_window)) {
116 DWORD process_id = 0;
117 ::GetWindowThreadProcessId(foreground_window, &process_id);
118 if (process_id == ::GetCurrentProcessId())
119 return;
120 }
121
122 // In Windows 8 metro mode display a metro style notification which
123 // informs the user that the download is complete.
124 HMODULE metro = base::win::GetMetroModule();
125 base::win::MetroNotification display_notification =
126 reinterpret_cast<base::win::MetroNotification>(
127 ::GetProcAddress(metro, "DisplayNotification"));
128 DCHECK(display_notification);
129 if (display_notification) {
130 base::string16 title = l10n_util::GetStringUTF16(
131 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION_TITLE);
132 base::string16 body = l10n_util::GetStringUTF16(
133 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION);
134
135 // Dummy notification id. Every metro style notification needs a
136 // unique notification id.
137 std::string notification_id = kDownloadNotificationPrefix;
138 notification_id += base::IntToString(g_next_notification_id++);
139
140 display_notification(download->GetURL().spec().c_str(),
141 "",
142 title.c_str(),
143 body.c_str(),
144 L"",
145 notification_id.c_str(),
146 MetroDownloadNotificationClickedHandler,
147 download->GetTargetFilePath().value().c_str());
148 }
149 } 69 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698