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 "base/win/shortcut.h" | 5 #include "base/win/shortcut.h" |
6 | 6 |
| 7 #include <objbase.h> |
7 #include <shellapi.h> | 8 #include <shellapi.h> |
8 #include <shlobj.h> | 9 #include <shlobj.h> |
9 #include <propkey.h> | 10 #include <propkey.h> |
10 | 11 |
11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
13 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
14 #include "base/win/scoped_propvariant.h" | 15 #include "base/win/scoped_propvariant.h" |
15 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
16 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 namespace win { | 20 namespace win { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Initializes |i_shell_link| and |i_persist_file| (releasing them first if they | 24 // Initializes |i_shell_link| and |i_persist_file| (releasing them first if they |
24 // are already initialized). | 25 // are already initialized). |
25 // If |shortcut| is not NULL, loads |shortcut| into |i_persist_file|. | 26 // If |shortcut| is not NULL, loads |shortcut| into |i_persist_file|. |
26 // If any of the above steps fail, both |i_shell_link| and |i_persist_file| will | 27 // If any of the above steps fail, both |i_shell_link| and |i_persist_file| will |
27 // be released. | 28 // be released. |
28 void InitializeShortcutInterfaces( | 29 void InitializeShortcutInterfaces( |
29 const wchar_t* shortcut, | 30 const wchar_t* shortcut, |
30 ScopedComPtr<IShellLink>* i_shell_link, | 31 ScopedComPtr<IShellLink>* i_shell_link, |
31 ScopedComPtr<IPersistFile>* i_persist_file) { | 32 ScopedComPtr<IPersistFile>* i_persist_file) { |
32 i_shell_link->Reset(); | 33 i_shell_link->Reset(); |
33 i_persist_file->Reset(); | 34 i_persist_file->Reset(); |
34 if (FAILED(i_shell_link->CreateInstance(CLSID_ShellLink, NULL, | 35 if (FAILED(::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, |
35 CLSCTX_INPROC_SERVER)) || | 36 IID_PPV_ARGS(i_shell_link->GetAddressOf()))) || |
36 FAILED(i_shell_link->CopyTo(i_persist_file->GetAddressOf())) || | 37 FAILED(i_shell_link->CopyTo(i_persist_file->GetAddressOf())) || |
37 (shortcut && FAILED((*i_persist_file)->Load(shortcut, STGM_READWRITE)))) { | 38 (shortcut && FAILED((*i_persist_file)->Load(shortcut, STGM_READWRITE)))) { |
38 i_shell_link->Reset(); | 39 i_shell_link->Reset(); |
39 i_persist_file->Reset(); | 40 i_persist_file->Reset(); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 ShortcutProperties::ShortcutProperties() | 46 ShortcutProperties::ShortcutProperties() |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ShortcutProperties* properties) { | 191 ShortcutProperties* properties) { |
191 DCHECK(options && properties); | 192 DCHECK(options && properties); |
192 base::ThreadRestrictions::AssertIOAllowed(); | 193 base::ThreadRestrictions::AssertIOAllowed(); |
193 | 194 |
194 if (options & ~ShortcutProperties::PROPERTIES_ALL) | 195 if (options & ~ShortcutProperties::PROPERTIES_ALL) |
195 NOTREACHED() << "Unhandled property is used."; | 196 NOTREACHED() << "Unhandled property is used."; |
196 | 197 |
197 ScopedComPtr<IShellLink> i_shell_link; | 198 ScopedComPtr<IShellLink> i_shell_link; |
198 | 199 |
199 // Get pointer to the IShellLink interface. | 200 // Get pointer to the IShellLink interface. |
200 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, | 201 if (FAILED(::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, |
201 CLSCTX_INPROC_SERVER))) { | 202 IID_PPV_ARGS(&i_shell_link)))) { |
202 return false; | 203 return false; |
203 } | 204 } |
204 | 205 |
205 ScopedComPtr<IPersistFile> persist; | 206 ScopedComPtr<IPersistFile> persist; |
206 // Query IShellLink for the IPersistFile interface. | 207 // Query IShellLink for the IPersistFile interface. |
207 if (FAILED(i_shell_link.CopyTo(persist.GetAddressOf()))) | 208 if (FAILED(i_shell_link.CopyTo(persist.GetAddressOf()))) |
208 return false; | 209 return false; |
209 | 210 |
210 // Load the shell link. | 211 // Load the shell link. |
211 if (FAILED(persist->Load(shortcut_path.value().c_str(), STGM_READ))) | 212 if (FAILED(persist->Load(shortcut_path.value().c_str(), STGM_READ))) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 if (GetVersion() < VERSION_WIN7) | 341 if (GetVersion() < VERSION_WIN7) |
341 return false; | 342 return false; |
342 | 343 |
343 intptr_t result = reinterpret_cast<intptr_t>(ShellExecute( | 344 intptr_t result = reinterpret_cast<intptr_t>(ShellExecute( |
344 NULL, L"taskbarunpin", shortcut.value().c_str(), NULL, NULL, 0)); | 345 NULL, L"taskbarunpin", shortcut.value().c_str(), NULL, NULL, 0)); |
345 return result > 32; | 346 return result > 32; |
346 } | 347 } |
347 | 348 |
348 } // namespace win | 349 } // namespace win |
349 } // namespace base | 350 } // namespace base |
OLD | NEW |