| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 FavoritesInfo info; | 130 FavoritesInfo info; |
| 131 if (!GetFavoritesInfo(&info)) | 131 if (!GetFavoritesInfo(&info)) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 BookmarkVector bookmarks; | 134 BookmarkVector bookmarks; |
| 135 ParseFavoritesFolder(info, &bookmarks); | 135 ParseFavoritesFolder(info, &bookmarks); |
| 136 | 136 |
| 137 if (!bookmarks.empty() && !cancelled()) { | 137 if (!bookmarks.empty() && !cancelled()) { |
| 138 const string16& first_folder_name = | 138 const string16& first_folder_name = |
| 139 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); | 139 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); |
| 140 int options = 0; | 140 bridge_->AddBookmarks(bookmarks, first_folder_name); |
| 141 if (import_to_bookmark_bar()) | |
| 142 options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; | |
| 143 bridge_->AddBookmarks(bookmarks, first_folder_name, options); | |
| 144 } | 141 } |
| 145 } | 142 } |
| 146 | 143 |
| 147 void IEImporter::ImportHistory() { | 144 void IEImporter::ImportHistory() { |
| 148 const std::string kSchemes[] = {chrome::kHttpScheme, | 145 const std::string kSchemes[] = {chrome::kHttpScheme, |
| 149 chrome::kHttpsScheme, | 146 chrome::kHttpsScheme, |
| 150 chrome::kFtpScheme, | 147 chrome::kFtpScheme, |
| 151 chrome::kFileScheme}; | 148 chrome::kFileScheme}; |
| 152 int total_schemes = arraysize(kSchemes); | 149 int total_schemes = arraysize(kSchemes); |
| 153 | 150 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 info->links_folder = buffer; | 519 info->links_folder = buffer; |
| 523 } else { | 520 } else { |
| 524 info->links_folder = L"Links"; | 521 info->links_folder = L"Links"; |
| 525 } | 522 } |
| 526 | 523 |
| 527 return true; | 524 return true; |
| 528 } | 525 } |
| 529 | 526 |
| 530 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, | 527 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, |
| 531 BookmarkVector* bookmarks) { | 528 BookmarkVector* bookmarks) { |
| 532 std::wstring ie_folder = | |
| 533 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE)); | |
| 534 BookmarkVector toolbar_bookmarks; | 529 BookmarkVector toolbar_bookmarks; |
| 535 FilePath file; | 530 FilePath file; |
| 536 std::vector<FilePath::StringType> file_list; | 531 std::vector<FilePath::StringType> file_list; |
| 537 FilePath favorites_path(info.path); | 532 FilePath favorites_path(info.path); |
| 538 // Favorites path length. Make sure it doesn't include the trailing \. | 533 // Favorites path length. Make sure it doesn't include the trailing \. |
| 539 size_t favorites_path_len = | 534 size_t favorites_path_len = |
| 540 favorites_path.StripTrailingSeparators().value().size(); | 535 favorites_path.StripTrailingSeparators().value().size(); |
| 541 file_util::FileEnumerator file_enumerator( | 536 file_util::FileEnumerator file_enumerator( |
| 542 favorites_path, true, file_util::FileEnumerator::FILES); | 537 favorites_path, true, file_util::FileEnumerator::FILES); |
| 543 while (!(file = file_enumerator.Next()).value().empty() && !cancelled()) | 538 while (!(file = file_enumerator.Next()).value().empty() && !cancelled()) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 568 FilePath relative_path(relative_string); | 563 FilePath relative_path(relative_string); |
| 569 | 564 |
| 570 ProfileWriter::BookmarkEntry entry; | 565 ProfileWriter::BookmarkEntry entry; |
| 571 // Remove the dot, the file extension, and the directory path. | 566 // Remove the dot, the file extension, and the directory path. |
| 572 entry.title = shortcut.RemoveExtension().BaseName().value(); | 567 entry.title = shortcut.RemoveExtension().BaseName().value(); |
| 573 entry.url = url; | 568 entry.url = url; |
| 574 entry.creation_time = GetFileCreationTime(*it); | 569 entry.creation_time = GetFileCreationTime(*it); |
| 575 if (!relative_path.empty()) | 570 if (!relative_path.empty()) |
| 576 relative_path.GetComponents(&entry.path); | 571 relative_path.GetComponents(&entry.path); |
| 577 | 572 |
| 578 // Flatten the bookmarks in Link folder onto bookmark toolbar. Otherwise, | 573 // Add the bookmark. |
| 579 // put it into "Other bookmarks". | 574 if (!entry.path.empty() && entry.path[0] == info.links_folder) { |
| 580 if (import_to_bookmark_bar() && | 575 // Bookmarks in the Link folder should be imported to the toolbar. |
| 581 (!entry.path.empty() && entry.path[0] == info.links_folder)) { | |
| 582 entry.in_toolbar = true; | 576 entry.in_toolbar = true; |
| 583 entry.path.erase(entry.path.begin()); | |
| 584 toolbar_bookmarks.push_back(entry); | 577 toolbar_bookmarks.push_back(entry); |
| 585 } else { | 578 } else { |
| 586 // We put the bookmarks in a "Imported From IE" | |
| 587 // folder, so that we don't mess up the "Other bookmarks". | |
| 588 if (!import_to_bookmark_bar()) | |
| 589 entry.path.insert(entry.path.begin(), ie_folder); | |
| 590 bookmarks->push_back(entry); | 579 bookmarks->push_back(entry); |
| 591 } | 580 } |
| 592 } | 581 } |
| 593 bookmarks->insert(bookmarks->begin(), toolbar_bookmarks.begin(), | 582 bookmarks->insert(bookmarks->begin(), toolbar_bookmarks.begin(), |
| 594 toolbar_bookmarks.end()); | 583 toolbar_bookmarks.end()); |
| 595 } | 584 } |
| 596 | 585 |
| 597 int IEImporter::CurrentIEVersion() const { | 586 int IEImporter::CurrentIEVersion() const { |
| 598 static int version = -1; | 587 static int version = -1; |
| 599 if (version < 0) { | 588 if (version < 0) { |
| 600 wchar_t buffer[128]; | 589 wchar_t buffer[128]; |
| 601 DWORD buffer_length = sizeof(buffer); | 590 DWORD buffer_length = sizeof(buffer); |
| 602 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, | 591 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, |
| 603 L"Software\\Microsoft\\Internet Explorer", KEY_READ); | 592 L"Software\\Microsoft\\Internet Explorer", KEY_READ); |
| 604 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 593 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 605 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 594 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 606 } | 595 } |
| 607 return version; | 596 return version; |
| 608 } | 597 } |
| OLD | NEW |