Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "base/win/registry.h" | 26 #include "base/win/registry.h" |
| 27 #include "base/win/scoped_co_mem.h" | 27 #include "base/win/scoped_co_mem.h" |
| 28 #include "base/win/scoped_comptr.h" | 28 #include "base/win/scoped_comptr.h" |
| 29 #include "base/win/scoped_handle.h" | 29 #include "base/win/scoped_handle.h" |
| 30 #include "base/win/scoped_propvariant.h" | 30 #include "base/win/scoped_propvariant.h" |
| 31 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
| 32 #include "chrome/common/importer/edge_importer_utils_win.h" | |
| 32 #include "chrome/common/importer/ie_importer_utils_win.h" | 33 #include "chrome/common/importer/ie_importer_utils_win.h" |
| 33 #include "chrome/common/importer/imported_bookmark_entry.h" | 34 #include "chrome/common/importer/imported_bookmark_entry.h" |
| 34 #include "chrome/common/importer/importer_bridge.h" | 35 #include "chrome/common/importer/importer_bridge.h" |
| 35 #include "chrome/common/importer/importer_data_types.h" | 36 #include "chrome/common/importer/importer_data_types.h" |
| 36 #include "chrome/common/importer/importer_url_row.h" | 37 #include "chrome/common/importer/importer_url_row.h" |
| 37 #include "chrome/common/importer/pstore_declarations.h" | 38 #include "chrome/common/importer/pstore_declarations.h" |
| 38 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
| 39 #include "chrome/utility/importer/favicon_reencode.h" | 40 #include "chrome/utility/importer/favicon_reencode.h" |
| 40 #include "components/autofill/core/common/password_form.h" | 41 #include "components/autofill/core/common/password_form.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 const GUID IEImporter::kPStoreAutocompleteGUID = { | 414 const GUID IEImporter::kPStoreAutocompleteGUID = { |
| 414 0xe161255a, 0x37c3, 0x11d2, | 415 0xe161255a, 0x37c3, 0x11d2, |
| 415 { 0xbc, 0xaa, 0x00, 0xc0, 0x4f, 0xd9, 0x29, 0xdb } | 416 { 0xbc, 0xaa, 0x00, 0xc0, 0x4f, 0xd9, 0x29, 0xdb } |
| 416 }; | 417 }; |
| 417 // {A79029D6-753E-4e27-B807-3D46AB1545DF} | 418 // {A79029D6-753E-4e27-B807-3D46AB1545DF} |
| 418 const GUID IEImporter::kUnittestGUID = { | 419 const GUID IEImporter::kUnittestGUID = { |
| 419 0xa79029d6, 0x753e, 0x4e27, | 420 0xa79029d6, 0x753e, 0x4e27, |
| 420 { 0xb8, 0x7, 0x3d, 0x46, 0xab, 0x15, 0x45, 0xdf } | 421 { 0xb8, 0x7, 0x3d, 0x46, 0xab, 0x15, 0x45, 0xdf } |
| 421 }; | 422 }; |
| 422 | 423 |
| 423 IEImporter::IEImporter() { | 424 IEImporter::IEImporter() : edge_import_mode_(false) {} |
| 424 } | |
| 425 | 425 |
| 426 void IEImporter::StartImport(const importer::SourceProfile& source_profile, | 426 void IEImporter::StartImport(const importer::SourceProfile& source_profile, |
| 427 uint16 items, | 427 uint16 items, |
| 428 ImporterBridge* bridge) { | 428 ImporterBridge* bridge) { |
| 429 edge_import_mode_ = source_profile.importer_type == importer::TYPE_EDGE; | |
| 429 bridge_ = bridge; | 430 bridge_ = bridge; |
| 430 source_path_ = source_profile.source_path; | 431 |
| 432 if (edge_import_mode_) { | |
| 433 // When using for Edge imports we only support Favorites. | |
| 434 DCHECK(items == importer::FAVORITES); | |
|
Ilya Sherman
2015/11/26 02:04:45
nit: DCHECK_EQ
forshaw
2015/11/30 12:57:59
Acknowledged.
| |
| 435 // As coming from untrusted source ensure items is correct. | |
| 436 items = importer::FAVORITES; | |
| 437 source_path_ = importer::GetEdgeDataFilePath(); | |
|
Ilya Sherman
2015/11/26 02:04:45
Why isn't this just set on the SourceProfiler?
forshaw
2015/11/30 12:57:59
Moved this to being initialized in importer_list.
| |
| 438 } | |
| 439 if (!source_profile.source_path.empty()) | |
| 440 source_path_ = source_profile.source_path; | |
| 431 | 441 |
| 432 bridge_->NotifyStarted(); | 442 bridge_->NotifyStarted(); |
| 433 | 443 |
| 434 if ((items & importer::HOME_PAGE) && !cancelled()) { | 444 if ((items & importer::HOME_PAGE) && !cancelled()) { |
| 435 bridge_->NotifyItemStarted(importer::HOME_PAGE); | 445 bridge_->NotifyItemStarted(importer::HOME_PAGE); |
| 436 ImportHomepage(); // Doesn't have a UI item. | 446 ImportHomepage(); // Doesn't have a UI item. |
| 437 bridge_->NotifyItemEnded(importer::HOME_PAGE); | 447 bridge_->NotifyItemEnded(importer::HOME_PAGE); |
| 438 } | 448 } |
| 439 // The order here is important! | 449 // The order here is important! |
| 440 if ((items & importer::HISTORY) && !cancelled()) { | 450 if ((items & importer::HISTORY) && !cancelled()) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 471 FavoritesInfo info; | 481 FavoritesInfo info; |
| 472 if (!GetFavoritesInfo(&info)) | 482 if (!GetFavoritesInfo(&info)) |
| 473 return; | 483 return; |
| 474 | 484 |
| 475 BookmarkVector bookmarks; | 485 BookmarkVector bookmarks; |
| 476 favicon_base::FaviconUsageDataList favicons; | 486 favicon_base::FaviconUsageDataList favicons; |
| 477 ParseFavoritesFolder(info, &bookmarks, &favicons); | 487 ParseFavoritesFolder(info, &bookmarks, &favicons); |
| 478 | 488 |
| 479 if (!bookmarks.empty() && !cancelled()) { | 489 if (!bookmarks.empty() && !cancelled()) { |
| 480 const base::string16& first_folder_name = | 490 const base::string16& first_folder_name = |
| 481 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); | 491 edge_import_mode_ |
| 492 ? l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_EDGE) | |
| 493 : l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); | |
| 494 | |
| 482 bridge_->AddBookmarks(bookmarks, first_folder_name); | 495 bridge_->AddBookmarks(bookmarks, first_folder_name); |
| 483 } | 496 } |
| 484 if (!favicons.empty() && !cancelled()) | 497 if (!favicons.empty() && !cancelled()) |
| 485 bridge_->SetFavicons(favicons); | 498 bridge_->SetFavicons(favicons); |
| 486 } | 499 } |
| 487 | 500 |
| 488 void IEImporter::ImportHistory() { | 501 void IEImporter::ImportHistory() { |
| 489 const std::string kSchemes[] = {url::kHttpScheme, | 502 const std::string kSchemes[] = {url::kHttpScheme, |
| 490 url::kHttpsScheme, | 503 url::kHttpsScheme, |
| 491 url::kFtpScheme, | 504 url::kFtpScheme, |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); | 788 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); |
| 776 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { | 789 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { |
| 777 if (homepage.spec() == GURL(default_homepage_url).spec()) | 790 if (homepage.spec() == GURL(default_homepage_url).spec()) |
| 778 return; | 791 return; |
| 779 } | 792 } |
| 780 bridge_->AddHomePage(homepage); | 793 bridge_->AddHomePage(homepage); |
| 781 } | 794 } |
| 782 | 795 |
| 783 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo* info) { | 796 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo* info) { |
| 784 if (!source_path_.empty()) { | 797 if (!source_path_.empty()) { |
| 785 // Source path exists during testing. | 798 // Source path exists during testing as well as importing from Edge. |
|
Ilya Sherman
2015/11/26 02:04:45
nit: "as well as importing" -> "as well as when im
forshaw
2015/11/30 12:57:59
Acknowledged.
| |
| 786 info->path = source_path_; | 799 info->path = source_path_; |
| 787 info->path = info->path.AppendASCII("Favorites"); | 800 info->path = info->path.AppendASCII("Favorites"); |
| 788 info->links_folder = L"Links"; | 801 info->links_folder = L"Links"; |
| 789 return true; | 802 return true; |
| 790 } | 803 } |
| 791 | 804 |
| 792 // IE stores the favorites in the Favorites under user profile's folder. | 805 // IE stores the favorites in the Favorites under user profile's folder. |
| 793 wchar_t buffer[MAX_PATH]; | 806 wchar_t buffer[MAX_PATH]; |
| 794 if (FAILED(SHGetFolderPath(NULL, CSIDL_FAVORITES, NULL, | 807 if (FAILED(SHGetFolderPath(NULL, CSIDL_FAVORITES, NULL, |
| 795 SHGFP_TYPE_CURRENT, buffer))) | 808 SHGFP_TYPE_CURRENT, buffer))) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 relative_path.GetComponents(&entry.path); | 894 relative_path.GetComponents(&entry.path); |
| 882 | 895 |
| 883 // Add the bookmark. | 896 // Add the bookmark. |
| 884 if (!entry.path.empty() && entry.path[0] == info.links_folder) { | 897 if (!entry.path.empty() && entry.path[0] == info.links_folder) { |
| 885 // Bookmarks in the Link folder should be imported to the toolbar. | 898 // Bookmarks in the Link folder should be imported to the toolbar. |
| 886 entry.in_toolbar = true; | 899 entry.in_toolbar = true; |
| 887 } | 900 } |
| 888 bookmarks->push_back(entry); | 901 bookmarks->push_back(entry); |
| 889 } | 902 } |
| 890 | 903 |
| 891 // Reflect the menu order in IE. | 904 if (!edge_import_mode_) { |
| 892 SortBookmarksInIEOrder(this, bookmarks); | 905 // Reflect the menu order in IE. |
| 906 SortBookmarksInIEOrder(this, bookmarks); | |
| 907 } | |
| 893 | 908 |
| 894 // Record favicon data. | 909 // Record favicon data. |
| 895 for (FaviconMap::iterator iter = favicon_map.begin(); | 910 for (FaviconMap::iterator iter = favicon_map.begin(); |
| 896 iter != favicon_map.end(); ++iter) | 911 iter != favicon_map.end(); ++iter) |
| 897 favicons->push_back(iter->second); | 912 favicons->push_back(iter->second); |
| 898 } | 913 } |
| 899 | 914 |
| 900 int IEImporter::CurrentIEVersion() const { | 915 int IEImporter::CurrentIEVersion() const { |
| 901 static int version = -1; | 916 static int version = -1; |
| 902 if (version < 0) { | 917 if (version < 0) { |
| 903 wchar_t buffer[128]; | 918 wchar_t buffer[128]; |
| 904 DWORD buffer_length = sizeof(buffer); | 919 DWORD buffer_length = sizeof(buffer); |
| 905 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 920 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 906 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 921 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 907 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 922 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 908 } | 923 } |
| 909 return version; | 924 return version; |
| 910 } | 925 } |
| OLD | NEW |