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

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

Issue 10827207: Mountain Lion: use the system download progress. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final? Created 8 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/download/download_status_updater.h"
6
7 #include <string>
8 #include <shobjidl.h>
9
10 #include "base/logging.h"
11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h"
13 #include "base/win/metro.h"
14 #include "base/win/scoped_comptr.h"
15 #include "base/win/windows_version.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "googleurl/src/gurl.h"
20 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h"
22
23 // This code doesn't compile with Aura on. TODO(avi): hook it up so that
24 // win_aura can do platform integration.
25 #if !defined(USE_AURA)
26
27 namespace {
28
29 const char kDownloadNotificationPrefix[] = "DownloadNotification";
30 int g_next_notification_id = 0;
31
32 void UpdateTaskbarProgressBar(int download_count,
33 bool progress_known,
34 float progress) {
35 // Taskbar progress bar is only supported on Win7.
36 if (base::win::GetVersion() < base::win::VERSION_WIN7)
37 return;
38
39 base::win::ScopedComPtr<ITaskbarList3> taskbar;
40 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
41 CLSCTX_INPROC_SERVER);
42 if (FAILED(result)) {
43 VLOG(1) << "Failed creating a TaskbarList object: " << result;
44 return;
45 }
46
47 result = taskbar->HrInit();
48 if (FAILED(result)) {
49 LOG(ERROR) << "Failed initializing an ITaskbarList3 interface.";
50 return;
51 }
52
53 // Iterate through all the browser windows, and draw the progress bar.
54 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
55 browser_iterator != BrowserList::end(); browser_iterator++) {
56 Browser* browser = *browser_iterator;
57 BrowserWindow* window = browser->window();
58 if (!window)
59 continue;
60 HWND frame = window->GetNativeWindow();
61 if (download_count == 0 || progress == 1.0f)
62 taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
63 else if (!progress_known)
64 taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
65 else
66 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100);
67 }
68 }
69
70 } // namespace
71
72 void DownloadStatusUpdater::UpdateAppIconDownloadProgress(
73 content::DownloadItem* download) {
74
75 // Always update overall progress.
76
77 float progress = 0;
78 int download_count = 0;
79 bool progress_known = GetProgress(&progress, &download_count);
80 UpdateTaskbarProgressBar(download_count, progress_known, progress);
81
82 // Fire notifications when downloads complete.
83
84 if (!base::win::IsMetroProcess())
85 return;
86
87 if (download->GetState() != content::DownloadItem::COMPLETE)
88 return;
89
90 if (download->GetOpenWhenComplete() ||
91 download->ShouldOpenFileBasedOnExtension() ||
92 download->IsTemporary() ||
93 download->GetAutoOpened())
94 return;
95
96 // In Windows 8 metro mode display a metro style notification which
97 // informs the user that the download is complete.
98 HMODULE metro = base::win::GetMetroModule();
99 base::win::MetroNotification display_notification =
100 reinterpret_cast<base::win::MetroNotification>(
101 ::GetProcAddress(metro, "DisplayNotification"));
102 DCHECK(display_notification);
103 if (display_notification) {
104 string16 title = l10n_util::GetStringUTF16(
105 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION_TITLE);
106 string16 body = l10n_util::GetStringUTF16(
107 IDS_METRO_DOWNLOAD_COMPLETE_NOTIFICATION);
108
109 // Dummy notification id. Every metro style notification needs a
110 // unique notification id.
111 std::string notification_id = kDownloadNotificationPrefix;
112 notification_id += base::IntToString(g_next_notification_id++);
113
114 display_notification(download->GetURL().spec().c_str(),
115 "",
116 title.c_str(),
117 body.c_str(),
118 L"",
119 notification_id.c_str());
120 }
121 }
122
123 #endif // !USE_AURA
OLDNEW
« no previous file with comments | « chrome/browser/download/download_status_updater_unittest.cc ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698