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 "chrome/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.h" |
6 | 6 |
| 7 #include <objbase.h> |
7 #include <ole2.h> | 8 #include <ole2.h> |
8 #include <intshcut.h> | 9 #include <intshcut.h> |
9 #include <shlobj.h> | 10 #include <shlobj.h> |
10 #include <stddef.h> | 11 #include <stddef.h> |
11 #include <urlhist.h> | 12 #include <urlhist.h> |
12 #include <wininet.h> | 13 #include <wininet.h> |
13 | 14 |
14 #include <algorithm> | 15 #include <algorithm> |
15 #include <map> | 16 #include <map> |
16 #include <string> | 17 #include <string> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // representing it. | 290 // representing it. |
290 bool LoadInternetShortcut( | 291 bool LoadInternetShortcut( |
291 const base::string16& file, | 292 const base::string16& file, |
292 base::win::ScopedComPtr<IUniformResourceLocator>* shortcut) { | 293 base::win::ScopedComPtr<IUniformResourceLocator>* shortcut) { |
293 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; | 294 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; |
294 if (FAILED(url_locator.CreateInstance(CLSID_InternetShortcut, NULL, | 295 if (FAILED(url_locator.CreateInstance(CLSID_InternetShortcut, NULL, |
295 CLSCTX_INPROC_SERVER))) | 296 CLSCTX_INPROC_SERVER))) |
296 return false; | 297 return false; |
297 | 298 |
298 base::win::ScopedComPtr<IPersistFile> persist_file; | 299 base::win::ScopedComPtr<IPersistFile> persist_file; |
299 if (FAILED(persist_file.QueryFrom(url_locator.Get()))) | 300 if (FAILED(url_locator.CopyTo(persist_file.GetAddressOf()))) |
300 return false; | 301 return false; |
301 | 302 |
302 // Loads the Internet Shortcut from persistent storage. | 303 // Loads the Internet Shortcut from persistent storage. |
303 if (FAILED(persist_file->Load(file.c_str(), STGM_READ))) | 304 if (FAILED(persist_file->Load(file.c_str(), STGM_READ))) |
304 return false; | 305 return false; |
305 | 306 |
306 std::swap(url_locator, *shortcut); | 307 std::swap(url_locator, *shortcut); |
307 return true; | 308 return true; |
308 } | 309 } |
309 | 310 |
310 // Reads the URL stored in the internet shortcut. | 311 // Reads the URL stored in the internet shortcut. |
311 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 312 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
312 base::win::ScopedCoMem<wchar_t> url; | 313 base::win::ScopedCoMem<wchar_t> url; |
313 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. | 314 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. |
314 return (FAILED(url_locator->GetURL(&url)) || !url) ? | 315 return (FAILED(url_locator->GetURL(&url)) || !url) ? |
315 GURL() : GURL(url.get()); | 316 GURL() : GURL(url.get()); |
316 } | 317 } |
317 | 318 |
318 // Reads the URL of the favicon of the internet shortcut. | 319 // Reads the URL of the favicon of the internet shortcut. |
319 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 320 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
320 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; | 321 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; |
321 if (FAILED(property_set_storage.QueryFrom(url_locator))) | 322 if (FAILED(url_locator->QueryInterface(IID_PPV_ARGS(&property_set_storage)))) |
322 return GURL(); | 323 return GURL(); |
323 | 324 |
324 base::win::ScopedComPtr<IPropertyStorage> property_storage; | 325 base::win::ScopedComPtr<IPropertyStorage> property_storage; |
325 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, | 326 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, |
326 property_storage.GetAddressOf()))) { | 327 property_storage.GetAddressOf()))) { |
327 return GURL(); | 328 return GURL(); |
328 } | 329 } |
329 | 330 |
330 PROPSPEC properties[] = {{PRSPEC_PROPID, {PID_IS_ICONFILE}}}; | 331 PROPSPEC properties[] = {{PRSPEC_PROPID, {PID_IS_ICONFILE}}}; |
331 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code | 332 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 static int version = -1; | 912 static int version = -1; |
912 if (version < 0) { | 913 if (version < 0) { |
913 wchar_t buffer[128]; | 914 wchar_t buffer[128]; |
914 DWORD buffer_length = sizeof(buffer); | 915 DWORD buffer_length = sizeof(buffer); |
915 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 916 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
916 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 917 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
917 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 918 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
918 } | 919 } |
919 return version; | 920 return version; |
920 } | 921 } |
OLD | NEW |