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 <ole2.h> | 7 #include <ole2.h> |
8 #include <intshcut.h> | 8 #include <intshcut.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #include <urlhist.h> | 10 #include <urlhist.h> |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 std::swap(url_locator, *shortcut); | 286 std::swap(url_locator, *shortcut); |
287 return true; | 287 return true; |
288 } | 288 } |
289 | 289 |
290 // Reads the URL stored in the internet shortcut. | 290 // Reads the URL stored in the internet shortcut. |
291 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 291 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
292 base::win::ScopedCoMem<wchar_t> url; | 292 base::win::ScopedCoMem<wchar_t> url; |
293 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. | 293 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. |
294 return (FAILED(url_locator->GetURL(&url)) || !url) ? | 294 return (FAILED(url_locator->GetURL(&url)) || !url) ? |
295 GURL() : GURL(base::WideToUTF16(url.get())); | 295 GURL() : GURL(url.get()); |
296 } | 296 } |
297 | 297 |
298 // Reads the URL of the favicon of the internet shortcut. | 298 // Reads the URL of the favicon of the internet shortcut. |
299 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 299 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
300 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; | 300 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; |
301 if (FAILED(property_set_storage.QueryFrom(url_locator))) | 301 if (FAILED(property_set_storage.QueryFrom(url_locator))) |
302 return GURL(); | 302 return GURL(); |
303 | 303 |
304 base::win::ScopedComPtr<IPropertyStorage> property_storage; | 304 base::win::ScopedComPtr<IPropertyStorage> property_storage; |
305 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, | 305 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, |
306 property_storage.Receive()))) { | 306 property_storage.Receive()))) { |
307 return GURL(); | 307 return GURL(); |
308 } | 308 } |
309 | 309 |
310 PROPSPEC properties[] = {{PRSPEC_PROPID, PID_IS_ICONFILE}}; | 310 PROPSPEC properties[] = {{PRSPEC_PROPID, PID_IS_ICONFILE}}; |
311 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code | 311 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code |
312 // only needs an array of size 1: a non-const pointer to |output| is | 312 // only needs an array of size 1: a non-const pointer to |output| is |
313 // equivalent. | 313 // equivalent. |
314 base::win::ScopedPropVariant output; | 314 base::win::ScopedPropVariant output; |
315 // ReadMultiple can return S_FALSE (FAILED(S_FALSE) is false) when the | 315 // ReadMultiple can return S_FALSE (FAILED(S_FALSE) is false) when the |
316 // property is not found, in which case output[0].vt is set to VT_EMPTY. | 316 // property is not found, in which case output[0].vt is set to VT_EMPTY. |
317 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) || | 317 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) || |
318 output.get().vt != VT_LPWSTR) | 318 output.get().vt != VT_LPWSTR) |
319 return GURL(); | 319 return GURL(); |
320 return GURL(base::WideToUTF16(output.get().pwszVal)); | 320 return GURL(output.get().pwszVal); |
321 } | 321 } |
322 | 322 |
323 // Reads the favicon imaga data in an NTFS alternate data stream. This is where | 323 // Reads the favicon imaga data in an NTFS alternate data stream. This is where |
324 // IE7 and above store the data. | 324 // IE7 and above store the data. |
325 bool ReadFaviconDataFromInternetShortcut(const base::string16& file, | 325 bool ReadFaviconDataFromInternetShortcut(const base::string16& file, |
326 std::string* data) { | 326 std::string* data) { |
327 return base::ReadFileToString( | 327 return base::ReadFileToString( |
328 base::FilePath(file + kFaviconStreamName), data); | 328 base::FilePath(file + kFaviconStreamName), data); |
329 } | 329 } |
330 | 330 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 static int version = -1; | 883 static int version = -1; |
884 if (version < 0) { | 884 if (version < 0) { |
885 wchar_t buffer[128]; | 885 wchar_t buffer[128]; |
886 DWORD buffer_length = sizeof(buffer); | 886 DWORD buffer_length = sizeof(buffer); |
887 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 887 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
888 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 888 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
889 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 889 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
890 } | 890 } |
891 return version; | 891 return version; |
892 } | 892 } |
OLD | NEW |