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 #include "ui/base/win/shell.h" | 5 #include "ui/base/win/shell.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <shlobj.h> // Must be before propkey. | 8 #include <shlobj.h> // Must be before propkey. |
9 #include <propkey.h> | 9 #include <propkey.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 bool PreventWindowFromPinning(HWND hwnd) { | 99 bool PreventWindowFromPinning(HWND hwnd) { |
100 DCHECK(hwnd); | 100 DCHECK(hwnd); |
101 | 101 |
102 // This functionality is only available on Win7+. | 102 // This functionality is only available on Win7+. |
103 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 103 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
104 return false; | 104 return false; |
105 | 105 |
106 base::win::ScopedComPtr<IPropertyStore> pps; | 106 base::win::ScopedComPtr<IPropertyStore> pps; |
107 if (FAILED(SHGetPropertyStoreForWindow(hwnd, | 107 if (FAILED( |
108 IID_PPV_ARGS(pps.Receive())))) | 108 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) |
109 return false; | 109 return false; |
110 | 110 |
111 return base::win::SetBooleanValueForPropertyStore( | 111 return base::win::SetBooleanValueForPropertyStore( |
112 pps.Get(), PKEY_AppUserModel_PreventPinning, true); | 112 pps.Get(), PKEY_AppUserModel_PreventPinning, true); |
113 } | 113 } |
114 | 114 |
115 // TODO(calamity): investigate moving this out of the UI thread as COM | 115 // TODO(calamity): investigate moving this out of the UI thread as COM |
116 // operations may spawn nested run loops which can cause issues. | 116 // operations may spawn nested run loops which can cause issues. |
117 void SetAppDetailsForWindow(const base::string16& app_id, | 117 void SetAppDetailsForWindow(const base::string16& app_id, |
118 const base::FilePath& app_icon_path, | 118 const base::FilePath& app_icon_path, |
119 int app_icon_index, | 119 int app_icon_index, |
120 const base::string16& relaunch_command, | 120 const base::string16& relaunch_command, |
121 const base::string16& relaunch_display_name, | 121 const base::string16& relaunch_display_name, |
122 HWND hwnd) { | 122 HWND hwnd) { |
123 DCHECK(hwnd); | 123 DCHECK(hwnd); |
124 | 124 |
125 // This functionality is only available on Win7+. | 125 // This functionality is only available on Win7+. |
126 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 126 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
127 return; | 127 return; |
128 | 128 |
129 base::win::ScopedComPtr<IPropertyStore> pps; | 129 base::win::ScopedComPtr<IPropertyStore> pps; |
130 if (FAILED(SHGetPropertyStoreForWindow(hwnd, | 130 if (FAILED( |
131 IID_PPV_ARGS(pps.Receive())))) | 131 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) |
132 return; | 132 return; |
133 | 133 |
134 if (!app_id.empty()) | 134 if (!app_id.empty()) |
135 base::win::SetAppIdForPropertyStore(pps.Get(), app_id.c_str()); | 135 base::win::SetAppIdForPropertyStore(pps.Get(), app_id.c_str()); |
136 if (!app_icon_path.empty()) { | 136 if (!app_icon_path.empty()) { |
137 // Always add the icon index explicitly to prevent bad interaction with the | 137 // Always add the icon index explicitly to prevent bad interaction with the |
138 // index notation when file path has commas. | 138 // index notation when file path has commas. |
139 base::win::SetStringValueForPropertyStore( | 139 base::win::SetStringValueForPropertyStore( |
140 pps.Get(), PKEY_AppUserModel_RelaunchIconResource, | 140 pps.Get(), PKEY_AppUserModel_RelaunchIconResource, |
141 base::StringPrintf(L"%ls,%d", app_icon_path.value().c_str(), | 141 base::StringPrintf(L"%ls,%d", app_icon_path.value().c_str(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 174 } |
175 | 175 |
176 void ClearWindowPropertyStore(HWND hwnd) { | 176 void ClearWindowPropertyStore(HWND hwnd) { |
177 DCHECK(hwnd); | 177 DCHECK(hwnd); |
178 | 178 |
179 // This functionality is only available on Win7+. | 179 // This functionality is only available on Win7+. |
180 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 180 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
181 return; | 181 return; |
182 | 182 |
183 base::win::ScopedComPtr<IPropertyStore> pps; | 183 base::win::ScopedComPtr<IPropertyStore> pps; |
184 if (FAILED(SHGetPropertyStoreForWindow(hwnd, | 184 if (FAILED( |
185 IID_PPV_ARGS(pps.Receive())))) | 185 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) |
186 return; | 186 return; |
187 | 187 |
188 DWORD property_count; | 188 DWORD property_count; |
189 if (FAILED(pps->GetCount(&property_count))) | 189 if (FAILED(pps->GetCount(&property_count))) |
190 return; | 190 return; |
191 | 191 |
192 PROPVARIANT empty_property_variant = {}; | 192 PROPVARIANT empty_property_variant = {}; |
193 for (DWORD i = 0; i < property_count; i++) { | 193 for (DWORD i = 0; i < property_count; i++) { |
194 PROPERTYKEY key; | 194 PROPERTYKEY key; |
195 if (SUCCEEDED(pps->GetAt(i, &key))) | 195 if (SUCCEEDED(pps->GetAt(i, &key))) |
(...skipping 16 matching lines...) Expand all Loading... |
212 // at the same feature level. See bug 426573. | 212 // at the same feature level. See bug 426573. |
213 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 213 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
214 return false; | 214 return false; |
215 // If composition is not enabled, we behave like on XP. | 215 // If composition is not enabled, we behave like on XP. |
216 BOOL enabled = FALSE; | 216 BOOL enabled = FALSE; |
217 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled; | 217 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled; |
218 } | 218 } |
219 | 219 |
220 } // namespace win | 220 } // namespace win |
221 } // namespace ui | 221 } // namespace ui |
OLD | NEW |