OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <pstore.h> | 9 #include <pstore.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // We have been called from the unit tests. Don't import real passwords. | 256 // We have been called from the unit tests. Don't import real passwords. |
257 return; | 257 return; |
258 } | 258 } |
259 | 259 |
260 const wchar_t kStorage2Path[] = | 260 const wchar_t kStorage2Path[] = |
261 L"Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2"; | 261 L"Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2"; |
262 | 262 |
263 base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ); | 263 base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ); |
264 base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER, | 264 base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER, |
265 kStorage2Path); | 265 kStorage2Path); |
| 266 IE7PasswordInfo password_info; |
266 while (reg_iterator.Valid() && !cancelled()) { | 267 while (reg_iterator.Valid() && !cancelled()) { |
267 // Get the size of the encrypted data. | 268 // Get the size of the encrypted data. |
268 DWORD value_len = 0; | 269 DWORD value_len = 0; |
269 if (key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL) && | 270 key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL); |
270 value_len) { | 271 if (value_len) { |
271 // Query the encrypted data. | 272 // Query the encrypted data. |
272 std::vector<unsigned char> value; | 273 password_info.encrypted_data.resize(value_len); |
273 value.resize(value_len); | 274 if (key.ReadValue(reg_iterator.Name(), |
274 if (key.ReadValue(reg_iterator.Name(), &value.front(), &value_len, | 275 &password_info.encrypted_data.front(), |
275 NULL)) { | 276 &value_len, NULL) == ERROR_SUCCESS) { |
276 IE7PasswordInfo password_info; | |
277 password_info.url_hash = reg_iterator.Name(); | 277 password_info.url_hash = reg_iterator.Name(); |
278 password_info.encrypted_data = value; | |
279 password_info.date_created = Time::Now(); | 278 password_info.date_created = Time::Now(); |
280 | 279 |
281 bridge_->AddIE7PasswordInfo(password_info); | 280 bridge_->AddIE7PasswordInfo(password_info); |
282 } | 281 } |
283 } | 282 } |
284 | 283 |
285 ++reg_iterator; | 284 ++reg_iterator; |
286 } | 285 } |
287 } | 286 } |
288 | 287 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 std::map<std::string, TemplateURL*> search_engines_map; | 358 std::map<std::string, TemplateURL*> search_engines_map; |
360 key.ReadValue(L"DefaultScope", &default_search_engine_name); | 359 key.ReadValue(L"DefaultScope", &default_search_engine_name); |
361 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, | 360 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, |
362 kSearchScopePath); | 361 kSearchScopePath); |
363 while (key_iterator.Valid()) { | 362 while (key_iterator.Valid()) { |
364 std::wstring sub_key_name = kSearchScopePath; | 363 std::wstring sub_key_name = kSearchScopePath; |
365 sub_key_name.append(L"\\").append(key_iterator.Name()); | 364 sub_key_name.append(L"\\").append(key_iterator.Name()); |
366 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), | 365 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), |
367 KEY_READ); | 366 KEY_READ); |
368 std::wstring wide_url; | 367 std::wstring wide_url; |
369 if (!sub_key.ReadValue(L"URL", &wide_url) || wide_url.empty()) { | 368 if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) || |
| 369 wide_url.empty()) { |
370 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); | 370 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); |
371 ++key_iterator; | 371 ++key_iterator; |
372 continue; | 372 continue; |
373 } | 373 } |
374 // For the name, we try the default value first (as Live Search uses a | 374 // For the name, we try the default value first (as Live Search uses a |
375 // non displayable name in DisplayName, and the readable name under the | 375 // non displayable name in DisplayName, and the readable name under the |
376 // default value). | 376 // default value). |
377 std::wstring name; | 377 std::wstring name; |
378 if (!sub_key.ReadValue(NULL, &name) || name.empty()) { | 378 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) { |
379 // Try the displayable name. | 379 // Try the displayable name. |
380 if (!sub_key.ReadValue(L"DisplayName", &name) || name.empty()) { | 380 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) || |
| 381 name.empty()) { |
381 VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); | 382 VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); |
382 ++key_iterator; | 383 ++key_iterator; |
383 continue; | 384 continue; |
384 } | 385 } |
385 } | 386 } |
386 | 387 |
387 std::string url(WideToUTF8(wide_url)); | 388 std::string url(WideToUTF8(wide_url)); |
388 std::map<std::string, TemplateURL*>::iterator t_iter = | 389 std::map<std::string, TemplateURL*>::iterator t_iter = |
389 search_engines_map.find(url); | 390 search_engines_map.find(url); |
390 TemplateURL* template_url = | 391 TemplateURL* template_url = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 427 } |
427 | 428 |
428 void IEImporter::ImportHomepage() { | 429 void IEImporter::ImportHomepage() { |
429 const wchar_t kIESettingsMain[] = | 430 const wchar_t kIESettingsMain[] = |
430 L"Software\\Microsoft\\Internet Explorer\\Main"; | 431 L"Software\\Microsoft\\Internet Explorer\\Main"; |
431 const wchar_t kIEHomepage[] = L"Start Page"; | 432 const wchar_t kIEHomepage[] = L"Start Page"; |
432 const wchar_t kIEDefaultHomepage[] = L"Default_Page_URL"; | 433 const wchar_t kIEDefaultHomepage[] = L"Default_Page_URL"; |
433 | 434 |
434 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); | 435 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); |
435 std::wstring homepage_url; | 436 std::wstring homepage_url; |
436 if (!key.ReadValue(kIEHomepage, &homepage_url) || homepage_url.empty()) | 437 if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS || |
| 438 homepage_url.empty()) |
437 return; | 439 return; |
438 | 440 |
439 GURL homepage = GURL(homepage_url); | 441 GURL homepage = GURL(homepage_url); |
440 if (!homepage.is_valid()) | 442 if (!homepage.is_valid()) |
441 return; | 443 return; |
442 | 444 |
443 // Check to see if this is the default website and skip import. | 445 // Check to see if this is the default website and skip import. |
444 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); | 446 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); |
445 std::wstring default_homepage_url; | 447 std::wstring default_homepage_url; |
446 if (keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url) && | 448 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); |
447 !default_homepage_url.empty()) { | 449 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { |
448 if (homepage.spec() == GURL(default_homepage_url).spec()) | 450 if (homepage.spec() == GURL(default_homepage_url).spec()) |
449 return; | 451 return; |
450 } | 452 } |
451 | 453 |
452 bridge_->AddHomePage(homepage); | 454 bridge_->AddHomePage(homepage); |
453 } | 455 } |
454 | 456 |
455 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { | 457 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { |
456 if (!source_path_.empty()) { | 458 if (!source_path_.empty()) { |
457 // Source path exists during testing. | 459 // Source path exists during testing. |
(...skipping 12 matching lines...) Expand all Loading... |
470 | 472 |
471 // There is a Links folder under Favorites folder in Windows Vista, but it | 473 // There is a Links folder under Favorites folder in Windows Vista, but it |
472 // is not recording in Vista's registry. So in Vista, we assume the Links | 474 // is not recording in Vista's registry. So in Vista, we assume the Links |
473 // folder is under Favorites folder since it looks like there is not name | 475 // folder is under Favorites folder since it looks like there is not name |
474 // different in every language version of Windows Vista. | 476 // different in every language version of Windows Vista. |
475 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 477 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
476 // The Link folder name is stored in the registry. | 478 // The Link folder name is stored in the registry. |
477 DWORD buffer_length = sizeof(buffer); | 479 DWORD buffer_length = sizeof(buffer); |
478 base::win::RegKey reg_key(HKEY_CURRENT_USER, | 480 base::win::RegKey reg_key(HKEY_CURRENT_USER, |
479 L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ); | 481 L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ); |
480 if (!reg_key.ReadValue(L"LinksFolderName", buffer, &buffer_length, NULL)) | 482 if (reg_key.ReadValue(L"LinksFolderName", buffer, |
| 483 &buffer_length, NULL) != ERROR_SUCCESS) |
481 return false; | 484 return false; |
482 info->links_folder = buffer; | 485 info->links_folder = buffer; |
483 } else { | 486 } else { |
484 info->links_folder = L"Links"; | 487 info->links_folder = L"Links"; |
485 } | 488 } |
486 | 489 |
487 return true; | 490 return true; |
488 } | 491 } |
489 | 492 |
490 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, | 493 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 return std::wstring(url); | 583 return std::wstring(url); |
581 } | 584 } |
582 | 585 |
583 int IEImporter::CurrentIEVersion() const { | 586 int IEImporter::CurrentIEVersion() const { |
584 static int version = -1; | 587 static int version = -1; |
585 if (version < 0) { | 588 if (version < 0) { |
586 wchar_t buffer[128]; | 589 wchar_t buffer[128]; |
587 DWORD buffer_length = sizeof(buffer); | 590 DWORD buffer_length = sizeof(buffer); |
588 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, | 591 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, |
589 L"Software\\Microsoft\\Internet Explorer", KEY_READ); | 592 L"Software\\Microsoft\\Internet Explorer", KEY_READ); |
590 bool result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 593 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
591 version = (result ? _wtoi(buffer) : 0); | 594 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
592 } | 595 } |
593 return version; | 596 return version; |
594 } | 597 } |
OLD | NEW |