| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_tray_state_changer_win.h" | 5 #include "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 bool StatusTrayStateChangerWin::CreateTrayNotify() { | 125 bool StatusTrayStateChangerWin::CreateTrayNotify() { |
| 126 DCHECK(CalledOnValidThread()); | 126 DCHECK(CalledOnValidThread()); |
| 127 | 127 |
| 128 tray_notify_.Reset(); // Reset so this method can be called more than once. | 128 tray_notify_.Reset(); // Reset so this method can be called more than once. |
| 129 | 129 |
| 130 HRESULT hr = tray_notify_.CreateInstance(CLSID_TrayNotify); | 130 HRESULT hr = tray_notify_.CreateInstance(CLSID_TrayNotify); |
| 131 if (FAILED(hr)) | 131 if (FAILED(hr)) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; | 134 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; |
| 135 hr = tray_notify_win8.QueryFrom(tray_notify_.Get()); | 135 hr = tray_notify_.CopyTo(tray_notify_win8.GetAddressOf()); |
| 136 if (SUCCEEDED(hr)) { | 136 if (SUCCEEDED(hr)) { |
| 137 interface_version_ = INTERFACE_VERSION_WIN8; | 137 interface_version_ = INTERFACE_VERSION_WIN8; |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 base::win::ScopedComPtr<ITrayNotify> tray_notify_legacy; | 141 base::win::ScopedComPtr<ITrayNotify> tray_notify_legacy; |
| 142 hr = tray_notify_legacy.QueryFrom(tray_notify_.Get()); | 142 hr = tray_notify_.CopyTo(tray_notify_legacy.GetAddressOf()); |
| 143 if (SUCCEEDED(hr)) { | 143 if (SUCCEEDED(hr)) { |
| 144 interface_version_ = INTERFACE_VERSION_LEGACY; | 144 interface_version_ = INTERFACE_VERSION_LEGACY; |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 std::unique_ptr<NOTIFYITEM> StatusTrayStateChangerWin::RegisterCallback() { | 151 std::unique_ptr<NOTIFYITEM> StatusTrayStateChangerWin::RegisterCallback() { |
| 152 // |notify_item_| is used to store the result of the callback from | 152 // |notify_item_| is used to store the result of the callback from |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 break; | 167 break; |
| 168 default: | 168 default: |
| 169 NOTREACHED(); | 169 NOTREACHED(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 return std::move(notify_item_); | 172 return std::move(notify_item_); |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { | 175 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { |
| 176 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; | 176 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; |
| 177 HRESULT hr = tray_notify_win8.QueryFrom(tray_notify_.Get()); | 177 HRESULT hr = tray_notify_.CopyTo(tray_notify_win8.GetAddressOf()); |
| 178 if (FAILED(hr)) | 178 if (FAILED(hr)) |
| 179 return false; | 179 return false; |
| 180 | 180 |
| 181 // The following two lines cause Windows Explorer to call us back with all the | 181 // The following two lines cause Windows Explorer to call us back with all the |
| 182 // existing tray icons and their preference. It would also presumably notify | 182 // existing tray icons and their preference. It would also presumably notify |
| 183 // us if changes were made in realtime while we registered as a callback, but | 183 // us if changes were made in realtime while we registered as a callback, but |
| 184 // we just want to modify our own entry so we immediately unregister. | 184 // we just want to modify our own entry so we immediately unregister. |
| 185 unsigned long callback_id = 0; | 185 unsigned long callback_id = 0; |
| 186 hr = tray_notify_win8->RegisterCallback(this, &callback_id); | 186 hr = tray_notify_win8->RegisterCallback(this, &callback_id); |
| 187 tray_notify_win8->UnregisterCallback(&callback_id); | 187 tray_notify_win8->UnregisterCallback(&callback_id); |
| 188 if (FAILED(hr)) { | 188 if (FAILED(hr)) { |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| 191 | 191 |
| 192 return true; | 192 return true; |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool StatusTrayStateChangerWin::RegisterCallbackLegacy() { | 195 bool StatusTrayStateChangerWin::RegisterCallbackLegacy() { |
| 196 base::win::ScopedComPtr<ITrayNotify> tray_notify; | 196 base::win::ScopedComPtr<ITrayNotify> tray_notify; |
| 197 HRESULT hr = tray_notify.QueryFrom(tray_notify_.Get()); | 197 HRESULT hr = tray_notify_.CopyTo(tray_notify.GetAddressOf()); |
| 198 if (FAILED(hr)) { | 198 if (FAILED(hr)) { |
| 199 return false; | 199 return false; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // The following two lines cause Windows Explorer to call us back with all the | 202 // The following two lines cause Windows Explorer to call us back with all the |
| 203 // existing tray icons and their preference. It would also presumably notify | 203 // existing tray icons and their preference. It would also presumably notify |
| 204 // us if changes were made in realtime while we registered as a callback. In | 204 // us if changes were made in realtime while we registered as a callback. In |
| 205 // this version of the API, there can be only one registered callback so it is | 205 // this version of the API, there can be only one registered callback so it is |
| 206 // better to unregister as soon as possible. | 206 // better to unregister as soon as possible. |
| 207 // TODO(dewittj): Try to notice if the notification area icon customization | 207 // TODO(dewittj): Try to notice if the notification area icon customization |
| 208 // window is open and postpone this call until the user closes it; | 208 // window is open and postpone this call until the user closes it; |
| 209 // registering the callback while the window is open can cause stale data to | 209 // registering the callback while the window is open can cause stale data to |
| 210 // be displayed to the user. | 210 // be displayed to the user. |
| 211 hr = tray_notify->RegisterCallback(this); | 211 hr = tray_notify->RegisterCallback(this); |
| 212 tray_notify->RegisterCallback(NULL); | 212 tray_notify->RegisterCallback(NULL); |
| 213 if (FAILED(hr)) { | 213 if (FAILED(hr)) { |
| 214 return false; | 214 return false; |
| 215 } | 215 } |
| 216 | 216 |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| 219 | 219 |
| 220 void StatusTrayStateChangerWin::SendNotifyItemUpdate( | 220 void StatusTrayStateChangerWin::SendNotifyItemUpdate( |
| 221 std::unique_ptr<NOTIFYITEM> notify_item) { | 221 std::unique_ptr<NOTIFYITEM> notify_item) { |
| 222 if (interface_version_ == INTERFACE_VERSION_LEGACY) { | 222 if (interface_version_ == INTERFACE_VERSION_LEGACY) { |
| 223 base::win::ScopedComPtr<ITrayNotify> tray_notify; | 223 base::win::ScopedComPtr<ITrayNotify> tray_notify; |
| 224 HRESULT hr = tray_notify.QueryFrom(tray_notify_.Get()); | 224 HRESULT hr = tray_notify_.CopyTo(tray_notify.GetAddressOf()); |
| 225 if (SUCCEEDED(hr)) | 225 if (SUCCEEDED(hr)) |
| 226 tray_notify->SetPreference(notify_item.get()); | 226 tray_notify->SetPreference(notify_item.get()); |
| 227 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { | 227 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { |
| 228 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; | 228 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; |
| 229 HRESULT hr = tray_notify.QueryFrom(tray_notify_.Get()); | 229 HRESULT hr = tray_notify_.CopyTo(tray_notify.GetAddressOf()); |
| 230 if (SUCCEEDED(hr)) | 230 if (SUCCEEDED(hr)) |
| 231 tray_notify->SetPreference(notify_item.get()); | 231 tray_notify->SetPreference(notify_item.get()); |
| 232 } | 232 } |
| 233 } | 233 } |
| OLD | NEW |