| 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/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 <shlobj.h> | 9 #include <shlobj.h> |
| 10 #include <urlhist.h> | 10 #include <urlhist.h> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 23 #include "base/time.h" | 23 #include "base/time.h" |
| 24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 25 #include "base/win/registry.h" | 25 #include "base/win/registry.h" |
| 26 #include "base/win/scoped_co_mem.h" | 26 #include "base/win/scoped_co_mem.h" |
| 27 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
| 28 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
| 29 #include "base/win/scoped_propvariant.h" | 29 #include "base/win/scoped_propvariant.h" |
| 30 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
| 31 #include "chrome/browser/bookmarks/imported_bookmark_entry.h" |
| 31 #include "chrome/browser/importer/importer_bridge.h" | 32 #include "chrome/browser/importer/importer_bridge.h" |
| 32 #include "chrome/browser/importer/importer_data_types.h" | 33 #include "chrome/browser/importer/importer_data_types.h" |
| 33 #include "chrome/browser/importer/importer_util.h" | 34 #include "chrome/browser/importer/importer_util.h" |
| 34 #include "chrome/browser/importer/pstore_declarations.h" | 35 #include "chrome/browser/importer/pstore_declarations.h" |
| 35 #include "chrome/browser/search_engines/template_url.h" | 36 #include "chrome/browser/search_engines/template_url.h" |
| 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 37 #include "chrome/browser/search_engines/template_url_service.h" | 38 #include "chrome/browser/search_engines/template_url_service.h" |
| 38 #include "chrome/common/time_format.h" | 39 #include "chrome/common/time_format.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "components/webdata/encryptor/ie7_password.h" | 41 #include "components/webdata/encryptor/ie7_password.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (id_cb == 0) | 111 if (id_cb == 0) |
| 111 break; | 112 break; |
| 112 head += id_cb; | 113 head += id_cb; |
| 113 } | 114 } |
| 114 return reinterpret_cast<LPCITEMIDLIST>(&blob[offset]); | 115 return reinterpret_cast<LPCITEMIDLIST>(&blob[offset]); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // Compares the two bookmarks in the order of IE's Favorites menu. | 118 // Compares the two bookmarks in the order of IE's Favorites menu. |
| 118 // Returns true if rhs should come later than lhs (lhs < rhs). | 119 // Returns true if rhs should come later than lhs (lhs < rhs). |
| 119 struct IEOrderBookmarkComparator { | 120 struct IEOrderBookmarkComparator { |
| 120 bool operator()(const ProfileWriter::BookmarkEntry& lhs, | 121 bool operator()(const ImportedBookmarkEntry& lhs, |
| 121 const ProfileWriter::BookmarkEntry& rhs) const { | 122 const ImportedBookmarkEntry& rhs) const { |
| 122 static const uint32 kNotSorted = 0xfffffffb; // IE uses this magic value. | 123 static const uint32 kNotSorted = 0xfffffffb; // IE uses this magic value. |
| 123 base::FilePath lhs_prefix; | 124 base::FilePath lhs_prefix; |
| 124 base::FilePath rhs_prefix; | 125 base::FilePath rhs_prefix; |
| 125 for (size_t i = 0; i <= lhs.path.size() && i <= rhs.path.size(); ++i) { | 126 for (size_t i = 0; i <= lhs.path.size() && i <= rhs.path.size(); ++i) { |
| 126 const base::FilePath::StringType lhs_i = | 127 const base::FilePath::StringType lhs_i = |
| 127 (i < lhs.path.size() ? lhs.path[i] : lhs.title + L".url"); | 128 (i < lhs.path.size() ? lhs.path[i] : lhs.title + L".url"); |
| 128 const base::FilePath::StringType rhs_i = | 129 const base::FilePath::StringType rhs_i = |
| 129 (i < rhs.path.size() ? rhs.path[i] : rhs.title + L".url"); | 130 (i < rhs.path.size() ? rhs.path[i] : rhs.title + L".url"); |
| 130 lhs_prefix = lhs_prefix.Append(lhs_i); | 131 lhs_prefix = lhs_prefix.Append(lhs_i); |
| 131 rhs_prefix = rhs_prefix.Append(rhs_i); | 132 rhs_prefix = rhs_prefix.Append(rhs_i); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (!key.Valid()) | 255 if (!key.Valid()) |
| 255 return false; | 256 return false; |
| 256 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), | 257 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), |
| 257 sort_index); | 258 sort_index); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // Reads the sort order from registry. If failed, we don't touch the list | 261 // Reads the sort order from registry. If failed, we don't touch the list |
| 261 // and use the default (alphabetical) order. | 262 // and use the default (alphabetical) order. |
| 262 void SortBookmarksInIEOrder( | 263 void SortBookmarksInIEOrder( |
| 263 const Importer* importer, | 264 const Importer* importer, |
| 264 std::vector<ProfileWriter::BookmarkEntry>* bookmarks) { | 265 std::vector<ImportedBookmarkEntry>* bookmarks) { |
| 265 std::map<base::FilePath, uint32> sort_index; | 266 std::map<base::FilePath, uint32> sort_index; |
| 266 if (!ParseFavoritesOrderInfo(importer, &sort_index)) | 267 if (!ParseFavoritesOrderInfo(importer, &sort_index)) |
| 267 return; | 268 return; |
| 268 IEOrderBookmarkComparator compare = {&sort_index}; | 269 IEOrderBookmarkComparator compare = {&sort_index}; |
| 269 std::sort(bookmarks->begin(), bookmarks->end(), compare); | 270 std::sort(bookmarks->begin(), bookmarks->end(), compare); |
| 270 } | 271 } |
| 271 | 272 |
| 272 // Reads an internet shortcut (*.url) |file| and returns a COM object | 273 // Reads an internet shortcut (*.url) |file| and returns a COM object |
| 273 // representing it. | 274 // representing it. |
| 274 bool LoadInternetShortcut( | 275 bool LoadInternetShortcut( |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 // ex. Suppose that the Favorites folder is C:\Users\Foo\Favorites. | 857 // ex. Suppose that the Favorites folder is C:\Users\Foo\Favorites. |
| 857 // C:\Users\Foo\Favorites\Foo.url -> "" | 858 // C:\Users\Foo\Favorites\Foo.url -> "" |
| 858 // C:\Users\Foo\Favorites\Links\Bar\Baz.url -> "Links\Bar" | 859 // C:\Users\Foo\Favorites\Links\Bar\Baz.url -> "Links\Bar" |
| 859 base::FilePath::StringType relative_string = | 860 base::FilePath::StringType relative_string = |
| 860 shortcut.DirName().value().substr(favorites_path_len); | 861 shortcut.DirName().value().substr(favorites_path_len); |
| 861 if (!relative_string.empty() && | 862 if (!relative_string.empty() && |
| 862 base::FilePath::IsSeparator(relative_string[0])) | 863 base::FilePath::IsSeparator(relative_string[0])) |
| 863 relative_string = relative_string.substr(1); | 864 relative_string = relative_string.substr(1); |
| 864 base::FilePath relative_path(relative_string); | 865 base::FilePath relative_path(relative_string); |
| 865 | 866 |
| 866 ProfileWriter::BookmarkEntry entry; | 867 ImportedBookmarkEntry entry; |
| 867 // Remove the dot, the file extension, and the directory path. | 868 // Remove the dot, the file extension, and the directory path. |
| 868 entry.title = shortcut.RemoveExtension().BaseName().value(); | 869 entry.title = shortcut.RemoveExtension().BaseName().value(); |
| 869 entry.url = url; | 870 entry.url = url; |
| 870 entry.creation_time = GetFileCreationTime(*it); | 871 entry.creation_time = GetFileCreationTime(*it); |
| 871 if (!relative_path.empty()) | 872 if (!relative_path.empty()) |
| 872 relative_path.GetComponents(&entry.path); | 873 relative_path.GetComponents(&entry.path); |
| 873 | 874 |
| 874 // Add the bookmark. | 875 // Add the bookmark. |
| 875 if (!entry.path.empty() && entry.path[0] == info.links_folder) { | 876 if (!entry.path.empty() && entry.path[0] == info.links_folder) { |
| 876 // Bookmarks in the Link folder should be imported to the toolbar. | 877 // Bookmarks in the Link folder should be imported to the toolbar. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 892 static int version = -1; | 893 static int version = -1; |
| 893 if (version < 0) { | 894 if (version < 0) { |
| 894 wchar_t buffer[128]; | 895 wchar_t buffer[128]; |
| 895 DWORD buffer_length = sizeof(buffer); | 896 DWORD buffer_length = sizeof(buffer); |
| 896 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 897 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 897 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 898 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 898 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 899 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 899 } | 900 } |
| 900 return version; | 901 return version; |
| 901 } | 902 } |
| OLD | NEW |