Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/importer/ie_importer.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/importer/ie_importer.h" 5 #include "chrome/browser/importer/ie_importer.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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 std::swap(url_locator, *shortcut); 290 std::swap(url_locator, *shortcut);
291 return true; 291 return true;
292 } 292 }
293 293
294 // Reads the URL stored in the internet shortcut. 294 // Reads the URL stored in the internet shortcut.
295 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { 295 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) {
296 base::win::ScopedCoMem<wchar_t> url; 296 base::win::ScopedCoMem<wchar_t> url;
297 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. 297 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL.
298 return (FAILED(url_locator->GetURL(&url)) || !url) ? 298 return (FAILED(url_locator->GetURL(&url)) || !url) ?
299 GURL() : GURL(WideToUTF16(std::wstring(url))); 299 GURL() : GURL(base::WideToUTF16(std::wstring(url)));
300 } 300 }
301 301
302 // Reads the URL of the favicon of the internet shortcut. 302 // Reads the URL of the favicon of the internet shortcut.
303 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { 303 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) {
304 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; 304 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage;
305 if (FAILED(property_set_storage.QueryFrom(url_locator))) 305 if (FAILED(property_set_storage.QueryFrom(url_locator)))
306 return GURL(); 306 return GURL();
307 307
308 base::win::ScopedComPtr<IPropertyStorage> property_storage; 308 base::win::ScopedComPtr<IPropertyStorage> property_storage;
309 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, 309 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ,
310 property_storage.Receive()))) { 310 property_storage.Receive()))) {
311 return GURL(); 311 return GURL();
312 } 312 }
313 313
314 PROPSPEC properties[] = {{PRSPEC_PROPID, PID_IS_ICONFILE}}; 314 PROPSPEC properties[] = {{PRSPEC_PROPID, PID_IS_ICONFILE}};
315 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code 315 // ReadMultiple takes a non-const array of PROPVARIANTs, but since this code
316 // only needs an array of size 1: a non-const pointer to |output| is 316 // only needs an array of size 1: a non-const pointer to |output| is
317 // equivalent. 317 // equivalent.
318 base::win::ScopedPropVariant output; 318 base::win::ScopedPropVariant output;
319 // ReadMultiple can return S_FALSE (FAILED(S_FALSE) is false) when the 319 // ReadMultiple can return S_FALSE (FAILED(S_FALSE) is false) when the
320 // property is not found, in which case output[0].vt is set to VT_EMPTY. 320 // property is not found, in which case output[0].vt is set to VT_EMPTY.
321 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) || 321 if (FAILED(property_storage->ReadMultiple(1, properties, output.Receive())) ||
322 output.get().vt != VT_LPWSTR) 322 output.get().vt != VT_LPWSTR)
323 return GURL(); 323 return GURL();
324 return GURL(WideToUTF16(output.get().pwszVal)); 324 return GURL(base::WideToUTF16(output.get().pwszVal));
325 } 325 }
326 326
327 // Reads the favicon imaga data in an NTFS alternate data stream. This is where 327 // Reads the favicon imaga data in an NTFS alternate data stream. This is where
328 // IE7 and above store the data. 328 // IE7 and above store the data.
329 bool ReadFaviconDataFromInternetShortcut(const string16& file, 329 bool ReadFaviconDataFromInternetShortcut(const string16& file,
330 std::string* data) { 330 std::string* data) {
331 return file_util::ReadFileToString( 331 return file_util::ReadFileToString(
332 base::FilePath(file + kFaviconStreamName), data); 332 base::FilePath(file + kFaviconStreamName), data);
333 } 333 }
334 334
335 // Reads the favicon imaga data in the Internet cache. IE6 doesn't hold the data 335 // Reads the favicon imaga data in the Internet cache. IE6 doesn't hold the data
336 // explicitly, but it might be found in the cache. 336 // explicitly, but it might be found in the cache.
337 bool ReadFaviconDataFromCache(const GURL& favicon_url, std::string* data) { 337 bool ReadFaviconDataFromCache(const GURL& favicon_url, std::string* data) {
338 std::wstring url_wstring(UTF8ToWide(favicon_url.spec())); 338 std::wstring url_wstring(base::UTF8ToWide(favicon_url.spec()));
339 DWORD info_size = 0; 339 DWORD info_size = 0;
340 GetUrlCacheEntryInfoEx(url_wstring.c_str(), NULL, &info_size, NULL, NULL, 340 GetUrlCacheEntryInfoEx(url_wstring.c_str(), NULL, &info_size, NULL, NULL,
341 NULL, 0); 341 NULL, 0);
342 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) 342 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
343 return false; 343 return false;
344 344
345 std::vector<char> buf(info_size); 345 std::vector<char> buf(info_size);
346 INTERNET_CACHE_ENTRY_INFO* cache = 346 INTERNET_CACHE_ENTRY_INFO* cache =
347 reinterpret_cast<INTERNET_CACHE_ENTRY_INFO*>(&buf[0]); 347 reinterpret_cast<INTERNET_CACHE_ENTRY_INFO*>(&buf[0]);
348 if (!GetUrlCacheEntryInfoEx(url_wstring.c_str(), cache, &info_size, NULL, 348 if (!GetUrlCacheEntryInfoEx(url_wstring.c_str(), cache, &info_size, NULL,
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 string16 name; 704 string16 name;
705 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) { 705 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) {
706 // Try the displayable name. 706 // Try the displayable name.
707 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) || 707 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) ||
708 name.empty()) { 708 name.empty()) {
709 VLOG(1) << "No name for IE search engine at " << key_iter.Name(); 709 VLOG(1) << "No name for IE search engine at " << key_iter.Name();
710 continue; 710 continue;
711 } 711 }
712 } 712 }
713 713
714 std::string url(WideToUTF8(wide_url)); 714 std::string url(base::WideToUTF8(wide_url));
715 SearchEnginesMap::iterator t_iter = search_engines_map.find(url); 715 SearchEnginesMap::iterator t_iter = search_engines_map.find(url);
716 if (t_iter == search_engines_map.end()) { 716 if (t_iter == search_engines_map.end()) {
717 // First time we see that URL. 717 // First time we see that URL.
718 GURL gurl(url); 718 GURL gurl(url);
719 if (gurl.is_valid()) { 719 if (gurl.is_valid()) {
720 TemplateURLData data; 720 TemplateURLData data;
721 data.short_name = name; 721 data.short_name = name;
722 data.SetKeyword(TemplateURLService::GenerateKeyword(gurl)); 722 data.SetKeyword(TemplateURLService::GenerateKeyword(gurl));
723 data.SetURL(url); 723 data.SetURL(url);
724 data.show_in_default_list = true; 724 data.show_in_default_list = true;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 static int version = -1; 884 static int version = -1;
885 if (version < 0) { 885 if (version < 0) {
886 wchar_t buffer[128]; 886 wchar_t buffer[128];
887 DWORD buffer_length = sizeof(buffer); 887 DWORD buffer_length = sizeof(buffer);
888 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); 888 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ);
889 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); 889 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL);
890 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); 890 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0);
891 } 891 }
892 return version; 892 return version;
893 } 893 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.cc ('k') | chrome/browser/importer/importer_unittest_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698