| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // The order of these includes is important. | 5 // The order of these includes is important. |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #include <unknwn.h> | 7 #include <unknwn.h> |
| 8 #include <intshcut.h> | 8 #include <intshcut.h> |
| 9 #include <propvarutil.h> | 9 #include <propvarutil.h> |
| 10 #include <shlguid.h> | 10 #include <shlguid.h> |
| 11 #include <shlobj.h> | 11 #include <shlobj.h> |
| 12 #include <stddef.h> |
| 13 #include <stdint.h> |
| 12 #include <urlhist.h> | 14 #include <urlhist.h> |
| 13 | 15 |
| 14 #include <algorithm> | 16 #include <algorithm> |
| 15 #include <vector> | 17 #include <vector> |
| 16 | 18 |
| 17 #include "base/bind.h" | 19 #include "base/bind.h" |
| 18 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
| 20 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
| 23 #include "base/macros.h" |
| 21 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
| 22 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
| 23 #include "base/strings/string16.h" | 26 #include "base/strings/string16.h" |
| 24 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/win/registry.h" | 29 #include "base/win/registry.h" |
| 27 #include "base/win/scoped_comptr.h" | 30 #include "base/win/scoped_comptr.h" |
| 28 #include "base/win/scoped_propvariant.h" | 31 #include "base/win/scoped_propvariant.h" |
| 29 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 30 #include "chrome/browser/importer/external_process_importer_host.h" | 33 #include "chrome/browser/importer/external_process_importer_host.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 121 |
| 119 bool CreateOrderBlob(const base::FilePath& favorites_folder, | 122 bool CreateOrderBlob(const base::FilePath& favorites_folder, |
| 120 const base::string16& path, | 123 const base::string16& path, |
| 121 const std::vector<base::string16>& entries) { | 124 const std::vector<base::string16>& entries) { |
| 122 if (entries.size() > 255) | 125 if (entries.size() > 255) |
| 123 return false; | 126 return false; |
| 124 | 127 |
| 125 // Create a binary sequence for setting a specific order of favorites. | 128 // Create a binary sequence for setting a specific order of favorites. |
| 126 // The format depends on the version of Shell32.dll, so we cannot embed | 129 // The format depends on the version of Shell32.dll, so we cannot embed |
| 127 // a binary constant here. | 130 // a binary constant here. |
| 128 std::vector<uint8> blob(20, 0); | 131 std::vector<uint8_t> blob(20, 0); |
| 129 blob[16] = static_cast<uint8>(entries.size()); | 132 blob[16] = static_cast<uint8_t>(entries.size()); |
| 130 | 133 |
| 131 for (size_t i = 0; i < entries.size(); ++i) { | 134 for (size_t i = 0; i < entries.size(); ++i) { |
| 132 PIDLIST_ABSOLUTE id_list_full = ILCreateFromPath( | 135 PIDLIST_ABSOLUTE id_list_full = ILCreateFromPath( |
| 133 favorites_folder.Append(path).Append(entries[i]).value().c_str()); | 136 favorites_folder.Append(path).Append(entries[i]).value().c_str()); |
| 134 PUITEMID_CHILD id_list = ILFindLastID(id_list_full); | 137 PUITEMID_CHILD id_list = ILFindLastID(id_list_full); |
| 135 // Include the trailing zero-length item id. Don't include the single | 138 // Include the trailing zero-length item id. Don't include the single |
| 136 // element array. | 139 // element array. |
| 137 size_t id_list_size = id_list->mkid.cb + sizeof(id_list->mkid.cb); | 140 size_t id_list_size = id_list->mkid.cb + sizeof(id_list->mkid.cb); |
| 138 | 141 |
| 139 blob.resize(blob.size() + 8); | 142 blob.resize(blob.size() + 8); |
| 140 uint32 total_size = id_list_size + 8; | 143 uint32_t total_size = id_list_size + 8; |
| 141 memcpy(&blob[blob.size() - 8], &total_size, 4); | 144 memcpy(&blob[blob.size() - 8], &total_size, 4); |
| 142 uint32 sort_index = i; | 145 uint32_t sort_index = i; |
| 143 memcpy(&blob[blob.size() - 4], &sort_index, 4); | 146 memcpy(&blob[blob.size() - 4], &sort_index, 4); |
| 144 blob.resize(blob.size() + id_list_size); | 147 blob.resize(blob.size() + id_list_size); |
| 145 memcpy(&blob[blob.size() - id_list_size], id_list, id_list_size); | 148 memcpy(&blob[blob.size() - id_list_size], id_list, id_list_size); |
| 146 ILFree(id_list_full); | 149 ILFree(id_list_full); |
| 147 } | 150 } |
| 148 | 151 |
| 149 base::string16 key_path(importer::GetIEFavoritesOrderKey()); | 152 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
| 150 if (!path.empty()) | 153 if (!path.empty()) |
| 151 key_path += L"\\" + path; | 154 key_path += L"\\" + path; |
| 152 base::win::RegKey key; | 155 base::win::RegKey key; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 219 } |
| 217 | 220 |
| 218 class TestObserver : public ProfileWriter, | 221 class TestObserver : public ProfileWriter, |
| 219 public importer::ImporterProgressObserver { | 222 public importer::ImporterProgressObserver { |
| 220 public: | 223 public: |
| 221 enum TestIEVersion { | 224 enum TestIEVersion { |
| 222 IE6, | 225 IE6, |
| 223 IE7, | 226 IE7, |
| 224 }; | 227 }; |
| 225 | 228 |
| 226 explicit TestObserver(uint16 importer_items, TestIEVersion ie_version) | 229 explicit TestObserver(uint16_t importer_items, TestIEVersion ie_version) |
| 227 : ProfileWriter(NULL), | 230 : ProfileWriter(NULL), |
| 228 bookmark_count_(0), | 231 bookmark_count_(0), |
| 229 history_count_(0), | 232 history_count_(0), |
| 230 password_count_(0), | 233 password_count_(0), |
| 231 favicon_count_(0), | 234 favicon_count_(0), |
| 232 homepage_count_(0), | 235 homepage_count_(0), |
| 233 ie7_password_count_(0), | 236 ie7_password_count_(0), |
| 234 importer_items_(importer_items), | 237 importer_items_(importer_items), |
| 235 ie_version_(ie_version) { | 238 ie_version_(ie_version) {} |
| 236 } | |
| 237 | 239 |
| 238 // importer::ImporterProgressObserver: | 240 // importer::ImporterProgressObserver: |
| 239 void ImportStarted() override {} | 241 void ImportStarted() override {} |
| 240 void ImportItemStarted(importer::ImportItem item) override {} | 242 void ImportItemStarted(importer::ImportItem item) override {} |
| 241 void ImportItemEnded(importer::ImportItem item) override {} | 243 void ImportItemEnded(importer::ImportItem item) override {} |
| 242 void ImportEnded() override { | 244 void ImportEnded() override { |
| 243 base::MessageLoop::current()->QuitWhenIdle(); | 245 base::MessageLoop::current()->QuitWhenIdle(); |
| 244 if (importer_items_ & importer::FAVORITES) { | 246 if (importer_items_ & importer::FAVORITES) { |
| 245 EXPECT_EQ(arraysize(kIEBookmarks), bookmark_count_); | 247 EXPECT_EQ(arraysize(kIEBookmarks), bookmark_count_); |
| 246 EXPECT_EQ(arraysize(kIEFaviconGroup), favicon_count_); | 248 EXPECT_EQ(arraysize(kIEFaviconGroup), favicon_count_); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 366 |
| 365 private: | 367 private: |
| 366 ~TestObserver() override {} | 368 ~TestObserver() override {} |
| 367 | 369 |
| 368 size_t bookmark_count_; | 370 size_t bookmark_count_; |
| 369 size_t history_count_; | 371 size_t history_count_; |
| 370 size_t password_count_; | 372 size_t password_count_; |
| 371 size_t favicon_count_; | 373 size_t favicon_count_; |
| 372 size_t homepage_count_; | 374 size_t homepage_count_; |
| 373 size_t ie7_password_count_; | 375 size_t ie7_password_count_; |
| 374 uint16 importer_items_; | 376 uint16_t importer_items_; |
| 375 TestIEVersion ie_version_; | 377 TestIEVersion ie_version_; |
| 376 }; | 378 }; |
| 377 | 379 |
| 378 class MalformedFavoritesRegistryTestObserver | 380 class MalformedFavoritesRegistryTestObserver |
| 379 : public ProfileWriter, | 381 : public ProfileWriter, |
| 380 public importer::ImporterProgressObserver { | 382 public importer::ImporterProgressObserver { |
| 381 public: | 383 public: |
| 382 MalformedFavoritesRegistryTestObserver() : ProfileWriter(NULL) { | 384 MalformedFavoritesRegistryTestObserver() : ProfileWriter(NULL) { |
| 383 bookmark_count_ = 0; | 385 bookmark_count_ = 0; |
| 384 } | 386 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 source_profile.source_path = temp_dir_.path(); | 648 source_profile.source_path = temp_dir_.path(); |
| 647 | 649 |
| 648 host->StartImportSettings( | 650 host->StartImportSettings( |
| 649 source_profile, | 651 source_profile, |
| 650 browser()->profile(), | 652 browser()->profile(), |
| 651 importer::HOME_PAGE, | 653 importer::HOME_PAGE, |
| 652 observer); | 654 observer); |
| 653 base::MessageLoop::current()->Run(); | 655 base::MessageLoop::current()->Run(); |
| 654 } | 656 } |
| 655 | 657 |
| OLD | NEW |