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

Side by Side Diff: chrome/browser/ui/views/status_icons/status_icon_win.cc

Issue 1406403007: Eliminate HICON leaks caused by creating icons from bitmap image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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
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/ui/views/status_icons/status_icon_win.h" 5 #include "chrome/browser/ui/views/status_icons/status_icon_win.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/win/windows_version.h" 8 #include "base/win/windows_version.h"
9 #include "chrome/browser/ui/views/status_icons/status_tray_win.h" 9 #include "chrome/browser/ui/views/status_icons/status_tray_win.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 void StatusIconWin::ResetIcon() { 77 void StatusIconWin::ResetIcon() {
78 NOTIFYICONDATA icon_data; 78 NOTIFYICONDATA icon_data;
79 InitIconData(&icon_data); 79 InitIconData(&icon_data);
80 // Delete any previously existing icon. 80 // Delete any previously existing icon.
81 Shell_NotifyIcon(NIM_DELETE, &icon_data); 81 Shell_NotifyIcon(NIM_DELETE, &icon_data);
82 InitIconData(&icon_data); 82 InitIconData(&icon_data);
83 icon_data.uFlags = NIF_MESSAGE; 83 icon_data.uFlags = NIF_MESSAGE;
84 icon_data.uCallbackMessage = message_id_; 84 icon_data.uCallbackMessage = message_id_;
85 icon_data.hIcon = icon_.Get(); 85 icon_data.hIcon = icon_.get();
86 // If we have an image, then set the NIF_ICON flag, which tells 86 // If we have an image, then set the NIF_ICON flag, which tells
87 // Shell_NotifyIcon() to set the image for the status icon it creates. 87 // Shell_NotifyIcon() to set the image for the status icon it creates.
88 if (icon_data.hIcon) 88 if (icon_data.hIcon)
89 icon_data.uFlags |= NIF_ICON; 89 icon_data.uFlags |= NIF_ICON;
90 // Re-add our icon. 90 // Re-add our icon.
91 BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data); 91 BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data);
92 if (!result) 92 if (!result)
93 LOG(WARNING) << "Unable to re-create status tray icon."; 93 LOG(WARNING) << "Unable to re-create status tray icon.";
94 } 94 }
95 95
96 void StatusIconWin::SetImage(const gfx::ImageSkia& image) { 96 void StatusIconWin::SetImage(const gfx::ImageSkia& image) {
97 // Create the icon. 97 // Create the icon.
98 NOTIFYICONDATA icon_data; 98 NOTIFYICONDATA icon_data;
99 InitIconData(&icon_data); 99 InitIconData(&icon_data);
100 icon_data.uFlags = NIF_ICON; 100 icon_data.uFlags = NIF_ICON;
101 icon_.Set(IconUtil::CreateHICONFromSkBitmap(*image.bitmap())); 101 icon_ = IconUtil::CreateHICONFromSkBitmap(*image.bitmap()).Pass();
102 icon_data.hIcon = icon_.Get(); 102 icon_data.hIcon = icon_.get();
103 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); 103 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
104 if (!result) 104 if (!result)
105 LOG(WARNING) << "Error setting status tray icon image"; 105 LOG(WARNING) << "Error setting status tray icon image";
106 } 106 }
107 107
108 void StatusIconWin::SetToolTip(const base::string16& tool_tip) { 108 void StatusIconWin::SetToolTip(const base::string16& tool_tip) {
109 // Create the icon. 109 // Create the icon.
110 NOTIFYICONDATA icon_data; 110 NOTIFYICONDATA icon_data;
111 InitIconData(&icon_data); 111 InitIconData(&icon_data);
112 icon_data.uFlags = NIF_TIP; 112 icon_data.uFlags = NIF_TIP;
(...skipping 11 matching lines...) Expand all
124 NOTIFYICONDATA icon_data; 124 NOTIFYICONDATA icon_data;
125 InitIconData(&icon_data); 125 InitIconData(&icon_data);
126 icon_data.uFlags = NIF_INFO; 126 icon_data.uFlags = NIF_INFO;
127 icon_data.dwInfoFlags = NIIF_INFO; 127 icon_data.dwInfoFlags = NIIF_INFO;
128 wcscpy_s(icon_data.szInfoTitle, title.c_str()); 128 wcscpy_s(icon_data.szInfoTitle, title.c_str());
129 wcscpy_s(icon_data.szInfo, contents.c_str()); 129 wcscpy_s(icon_data.szInfo, contents.c_str());
130 icon_data.uTimeout = 0; 130 icon_data.uTimeout = 0;
131 131
132 base::win::Version win_version = base::win::GetVersion(); 132 base::win::Version win_version = base::win::GetVersion();
133 if (!icon.isNull() && win_version != base::win::VERSION_PRE_XP) { 133 if (!icon.isNull() && win_version != base::win::VERSION_PRE_XP) {
134 balloon_icon_.Set(IconUtil::CreateHICONFromSkBitmap(*icon.bitmap())); 134 balloon_icon_ = IconUtil::CreateHICONFromSkBitmap(*icon.bitmap()).Pass();
135 if (win_version >= base::win::VERSION_VISTA) { 135 if (win_version >= base::win::VERSION_VISTA) {
136 icon_data.hBalloonIcon = balloon_icon_.Get(); 136 icon_data.hBalloonIcon = balloon_icon_.get();
137 icon_data.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; 137 icon_data.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON;
138 } else { 138 } else {
139 icon_data.hIcon = balloon_icon_.Get(); 139 icon_data.hIcon = balloon_icon_.get();
140 icon_data.uFlags |= NIF_ICON; 140 icon_data.uFlags |= NIF_ICON;
141 icon_data.dwInfoFlags = NIIF_USER; 141 icon_data.dwInfoFlags = NIIF_USER;
142 } 142 }
143 } 143 }
144 144
145 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); 145 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
146 if (!result) 146 if (!result)
147 LOG(WARNING) << "Unable to create status tray balloon."; 147 LOG(WARNING) << "Unable to create status tray balloon.";
148 } 148 }
149 149
(...skipping 17 matching lines...) Expand all
167 memset(icon_data, 0, sizeof(NOTIFYICONDATA)); 167 memset(icon_data, 0, sizeof(NOTIFYICONDATA));
168 icon_data->cbSize = sizeof(NOTIFYICONDATA); 168 icon_data->cbSize = sizeof(NOTIFYICONDATA);
169 } else { 169 } else {
170 memset(icon_data, 0, NOTIFYICONDATA_V3_SIZE); 170 memset(icon_data, 0, NOTIFYICONDATA_V3_SIZE);
171 icon_data->cbSize = NOTIFYICONDATA_V3_SIZE; 171 icon_data->cbSize = NOTIFYICONDATA_V3_SIZE;
172 } 172 }
173 173
174 icon_data->hWnd = window_; 174 icon_data->hWnd = window_;
175 icon_data->uID = icon_id_; 175 icon_data->uID = icon_id_;
176 } 176 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/panels/panel_frame_view.cc ('k') | chrome/browser/ui/views/tabs/window_finder_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698