| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) || | 315 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) || |
| 316 output.get().vt != VT_LPWSTR) | 316 output.get().vt != VT_LPWSTR) |
| 317 return GURL(); | 317 return GURL(); |
| 318 return GURL(WideToUTF16(output.get().pwszVal)); | 318 return GURL(WideToUTF16(output.get().pwszVal)); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // Reads the favicon imaga data in an NTFS alternate data stream. This is where | 321 // Reads the favicon imaga data in an NTFS alternate data stream. This is where |
| 322 // IE7 and above store the data. | 322 // IE7 and above store the data. |
| 323 bool ReadFaviconDataFromInternetShortcut(const string16& file, | 323 bool ReadFaviconDataFromInternetShortcut(const string16& file, |
| 324 std::string* data) { | 324 std::string* data) { |
| 325 return file_util::ReadFileToString( | 325 return base::ReadFileToString( |
| 326 base::FilePath(file + kFaviconStreamName), data); | 326 base::FilePath(file + kFaviconStreamName), data); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Reads the favicon imaga data in the Internet cache. IE6 doesn't hold the data | 329 // Reads the favicon imaga data in the Internet cache. IE6 doesn't hold the data |
| 330 // explicitly, but it might be found in the cache. | 330 // explicitly, but it might be found in the cache. |
| 331 bool ReadFaviconDataFromCache(const GURL& favicon_url, std::string* data) { | 331 bool ReadFaviconDataFromCache(const GURL& favicon_url, std::string* data) { |
| 332 std::wstring url_wstring(UTF8ToWide(favicon_url.spec())); | 332 std::wstring url_wstring(UTF8ToWide(favicon_url.spec())); |
| 333 DWORD info_size = 0; | 333 DWORD info_size = 0; |
| 334 GetUrlCacheEntryInfoEx(url_wstring.c_str(), NULL, &info_size, NULL, NULL, | 334 GetUrlCacheEntryInfoEx(url_wstring.c_str(), NULL, &info_size, NULL, NULL, |
| 335 NULL, 0); | 335 NULL, 0); |
| 336 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) | 336 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) |
| 337 return false; | 337 return false; |
| 338 | 338 |
| 339 std::vector<char> buf(info_size); | 339 std::vector<char> buf(info_size); |
| 340 INTERNET_CACHE_ENTRY_INFO* cache = | 340 INTERNET_CACHE_ENTRY_INFO* cache = |
| 341 reinterpret_cast<INTERNET_CACHE_ENTRY_INFO*>(&buf[0]); | 341 reinterpret_cast<INTERNET_CACHE_ENTRY_INFO*>(&buf[0]); |
| 342 if (!GetUrlCacheEntryInfoEx(url_wstring.c_str(), cache, &info_size, NULL, | 342 if (!GetUrlCacheEntryInfoEx(url_wstring.c_str(), cache, &info_size, NULL, |
| 343 NULL, NULL, 0)) { | 343 NULL, NULL, 0)) { |
| 344 return false; | 344 return false; |
| 345 } | 345 } |
| 346 return file_util::ReadFileToString(base::FilePath(cache->lpszLocalFileName), | 346 return base::ReadFileToString(base::FilePath(cache->lpszLocalFileName), data); |
| 347 data); | |
| 348 } | 347 } |
| 349 | 348 |
| 350 // Reads the binary image data of favicon of an internet shortcut file |file|. | 349 // Reads the binary image data of favicon of an internet shortcut file |file|. |
| 351 // |favicon_url| read by ReadFaviconURLFromInternetShortcut is also needed to | 350 // |favicon_url| read by ReadFaviconURLFromInternetShortcut is also needed to |
| 352 // examine the IE cache. | 351 // examine the IE cache. |
| 353 bool ReadReencodedFaviconData(const string16& file, | 352 bool ReadReencodedFaviconData(const string16& file, |
| 354 const GURL& favicon_url, | 353 const GURL& favicon_url, |
| 355 std::vector<unsigned char>* data) { | 354 std::vector<unsigned char>* data) { |
| 356 std::string image_data; | 355 std::string image_data; |
| 357 if (!ReadFaviconDataFromInternetShortcut(file, &image_data) && | 356 if (!ReadFaviconDataFromInternetShortcut(file, &image_data) && |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 static int version = -1; | 873 static int version = -1; |
| 875 if (version < 0) { | 874 if (version < 0) { |
| 876 wchar_t buffer[128]; | 875 wchar_t buffer[128]; |
| 877 DWORD buffer_length = sizeof(buffer); | 876 DWORD buffer_length = sizeof(buffer); |
| 878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 877 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 878 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 879 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 881 } | 880 } |
| 882 return version; | 881 return version; |
| 883 } | 882 } |
| OLD | NEW |