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; |
| 431 |
| 432 if (edge_import_mode_) { |
| 433 // When using for Edge imports we only support Favorites. |
| 434 DCHECK_EQ(items, importer::FAVORITES); |
| 435 // As coming from untrusted source ensure items is correct. |
| 436 items = importer::FAVORITES; |
| 437 } |
430 source_path_ = source_profile.source_path; | 438 source_path_ = source_profile.source_path; |
431 | 439 |
432 bridge_->NotifyStarted(); | 440 bridge_->NotifyStarted(); |
433 | 441 |
434 if ((items & importer::HOME_PAGE) && !cancelled()) { | 442 if ((items & importer::HOME_PAGE) && !cancelled()) { |
435 bridge_->NotifyItemStarted(importer::HOME_PAGE); | 443 bridge_->NotifyItemStarted(importer::HOME_PAGE); |
436 ImportHomepage(); // Doesn't have a UI item. | 444 ImportHomepage(); // Doesn't have a UI item. |
437 bridge_->NotifyItemEnded(importer::HOME_PAGE); | 445 bridge_->NotifyItemEnded(importer::HOME_PAGE); |
438 } | 446 } |
439 // The order here is important! | 447 // The order here is important! |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 FavoritesInfo info; | 479 FavoritesInfo info; |
472 if (!GetFavoritesInfo(&info)) | 480 if (!GetFavoritesInfo(&info)) |
473 return; | 481 return; |
474 | 482 |
475 BookmarkVector bookmarks; | 483 BookmarkVector bookmarks; |
476 favicon_base::FaviconUsageDataList favicons; | 484 favicon_base::FaviconUsageDataList favicons; |
477 ParseFavoritesFolder(info, &bookmarks, &favicons); | 485 ParseFavoritesFolder(info, &bookmarks, &favicons); |
478 | 486 |
479 if (!bookmarks.empty() && !cancelled()) { | 487 if (!bookmarks.empty() && !cancelled()) { |
480 const base::string16& first_folder_name = | 488 const base::string16& first_folder_name = |
481 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); | 489 edge_import_mode_ |
| 490 ? l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_EDGE) |
| 491 : l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); |
| 492 |
482 bridge_->AddBookmarks(bookmarks, first_folder_name); | 493 bridge_->AddBookmarks(bookmarks, first_folder_name); |
483 } | 494 } |
484 if (!favicons.empty() && !cancelled()) | 495 if (!favicons.empty() && !cancelled()) |
485 bridge_->SetFavicons(favicons); | 496 bridge_->SetFavicons(favicons); |
486 } | 497 } |
487 | 498 |
488 void IEImporter::ImportHistory() { | 499 void IEImporter::ImportHistory() { |
489 const std::string kSchemes[] = {url::kHttpScheme, | 500 const std::string kSchemes[] = {url::kHttpScheme, |
490 url::kHttpsScheme, | 501 url::kHttpsScheme, |
491 url::kFtpScheme, | 502 url::kFtpScheme, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); | 786 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); |
776 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { | 787 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { |
777 if (homepage.spec() == GURL(default_homepage_url).spec()) | 788 if (homepage.spec() == GURL(default_homepage_url).spec()) |
778 return; | 789 return; |
779 } | 790 } |
780 bridge_->AddHomePage(homepage); | 791 bridge_->AddHomePage(homepage); |
781 } | 792 } |
782 | 793 |
783 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo* info) { | 794 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo* info) { |
784 if (!source_path_.empty()) { | 795 if (!source_path_.empty()) { |
785 // Source path exists during testing. | 796 // Source path exists during testing as well as when importing from Edge. |
786 info->path = source_path_; | 797 info->path = source_path_; |
787 info->path = info->path.AppendASCII("Favorites"); | 798 info->path = info->path.AppendASCII("Favorites"); |
788 info->links_folder = L"Links"; | 799 info->links_folder = L"Links"; |
789 return true; | 800 return true; |
790 } | 801 } |
791 | 802 |
792 // IE stores the favorites in the Favorites under user profile's folder. | 803 // IE stores the favorites in the Favorites under user profile's folder. |
793 wchar_t buffer[MAX_PATH]; | 804 wchar_t buffer[MAX_PATH]; |
794 if (FAILED(SHGetFolderPath(NULL, CSIDL_FAVORITES, NULL, | 805 if (FAILED(SHGetFolderPath(NULL, CSIDL_FAVORITES, NULL, |
795 SHGFP_TYPE_CURRENT, buffer))) | 806 SHGFP_TYPE_CURRENT, buffer))) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 relative_path.GetComponents(&entry.path); | 892 relative_path.GetComponents(&entry.path); |
882 | 893 |
883 // Add the bookmark. | 894 // Add the bookmark. |
884 if (!entry.path.empty() && entry.path[0] == info.links_folder) { | 895 if (!entry.path.empty() && entry.path[0] == info.links_folder) { |
885 // Bookmarks in the Link folder should be imported to the toolbar. | 896 // Bookmarks in the Link folder should be imported to the toolbar. |
886 entry.in_toolbar = true; | 897 entry.in_toolbar = true; |
887 } | 898 } |
888 bookmarks->push_back(entry); | 899 bookmarks->push_back(entry); |
889 } | 900 } |
890 | 901 |
891 // Reflect the menu order in IE. | 902 if (!edge_import_mode_) { |
892 SortBookmarksInIEOrder(this, bookmarks); | 903 // Reflect the menu order in IE. |
| 904 SortBookmarksInIEOrder(this, bookmarks); |
| 905 } |
893 | 906 |
894 // Record favicon data. | 907 // Record favicon data. |
895 for (FaviconMap::iterator iter = favicon_map.begin(); | 908 for (FaviconMap::iterator iter = favicon_map.begin(); |
896 iter != favicon_map.end(); ++iter) | 909 iter != favicon_map.end(); ++iter) |
897 favicons->push_back(iter->second); | 910 favicons->push_back(iter->second); |
898 } | 911 } |
899 | 912 |
900 int IEImporter::CurrentIEVersion() const { | 913 int IEImporter::CurrentIEVersion() const { |
901 static int version = -1; | 914 static int version = -1; |
902 if (version < 0) { | 915 if (version < 0) { |
903 wchar_t buffer[128]; | 916 wchar_t buffer[128]; |
904 DWORD buffer_length = sizeof(buffer); | 917 DWORD buffer_length = sizeof(buffer); |
905 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 918 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
906 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 919 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
907 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 920 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
908 } | 921 } |
909 return version; | 922 return version; |
910 } | 923 } |
OLD | NEW |