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