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> |
11 #include <urlhist.h> | 11 #include <urlhist.h> |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <map> | 14 #include <map> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/string_split.h" | 20 #include "base/string_split.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/string16.h" |
22 #include "base/time.h" | 23 #include "base/time.h" |
23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
24 #include "base/win/registry.h" | 25 #include "base/win/registry.h" |
25 #include "base/win/scoped_co_mem.h" | 26 #include "base/win/scoped_co_mem.h" |
26 #include "base/win/scoped_com_initializer.h" | 27 #include "base/win/scoped_com_initializer.h" |
27 #include "base/win/scoped_comptr.h" | 28 #include "base/win/scoped_comptr.h" |
28 #include "base/win/scoped_handle.h" | 29 #include "base/win/scoped_handle.h" |
29 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
30 #include "chrome/browser/importer/importer_bridge.h" | 31 #include "chrome/browser/importer/importer_bridge.h" |
31 #include "chrome/browser/importer/importer_data_types.h" | 32 #include "chrome/browser/importer/importer_data_types.h" |
32 #include "chrome/browser/password_manager/ie7_password.h" | 33 #include "chrome/browser/password_manager/ie7_password.h" |
33 #include "chrome/browser/search_engines/template_url.h" | 34 #include "chrome/browser/search_engines/template_url.h" |
34 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
35 #include "chrome/browser/search_engines/template_url_service.h" | 36 #include "chrome/browser/search_engines/template_url_service.h" |
36 #include "chrome/common/time_format.h" | 37 #include "chrome/common/time_format.h" |
37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
38 #include "googleurl/src/gurl.h" | 39 #include "googleurl/src/gurl.h" |
39 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 #include "webkit/glue/password_form.h" | 42 #include "webkit/glue/password_form.h" |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 // A struct that hosts the information of AutoComplete data in PStore. | 46 // A struct that hosts the information of AutoComplete data in PStore. |
46 struct AutoCompleteInfo { | 47 struct AutoCompleteInfo { |
47 std::wstring key; | 48 string16 key; |
48 std::vector<std::wstring> data; | 49 std::vector<string16> data; |
49 bool is_url; | 50 bool is_url; |
50 }; | 51 }; |
51 | 52 |
52 // Gets the creation time of the given file or directory. | 53 // Gets the creation time of the given file or directory. |
53 base::Time GetFileCreationTime(const std::wstring& file) { | 54 base::Time GetFileCreationTime(const string16& file) { |
54 base::Time creation_time; | 55 base::Time creation_time; |
55 base::win::ScopedHandle file_handle( | 56 base::win::ScopedHandle file_handle( |
56 CreateFile(file.c_str(), GENERIC_READ, | 57 CreateFile(file.c_str(), GENERIC_READ, |
57 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 58 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
58 NULL, OPEN_EXISTING, | 59 NULL, OPEN_EXISTING, |
59 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)); | 60 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL)); |
60 FILETIME creation_filetime; | 61 FILETIME creation_filetime; |
61 if (GetFileTime(file_handle, &creation_filetime, NULL, NULL)) | 62 if (GetFileTime(file_handle, &creation_filetime, NULL, NULL)) |
62 creation_time = base::Time::FromFileTime(creation_filetime); | 63 creation_time = base::Time::FromFileTime(creation_filetime); |
63 return creation_time; | 64 return creation_time; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ImportPasswordsIE7(); | 119 ImportPasswordsIE7(); |
119 bridge_->NotifyItemEnded(importer::PASSWORDS); | 120 bridge_->NotifyItemEnded(importer::PASSWORDS); |
120 } | 121 } |
121 bridge_->NotifyEnded(); | 122 bridge_->NotifyEnded(); |
122 } | 123 } |
123 | 124 |
124 IEImporter::~IEImporter() { | 125 IEImporter::~IEImporter() { |
125 } | 126 } |
126 | 127 |
127 void IEImporter::ImportFavorites() { | 128 void IEImporter::ImportFavorites() { |
128 std::wstring path; | |
129 | |
130 FavoritesInfo info; | 129 FavoritesInfo info; |
131 if (!GetFavoritesInfo(&info)) | 130 if (!GetFavoritesInfo(&info)) |
132 return; | 131 return; |
133 | 132 |
134 BookmarkVector bookmarks; | 133 BookmarkVector bookmarks; |
135 ParseFavoritesFolder(info, &bookmarks); | 134 ParseFavoritesFolder(info, &bookmarks); |
136 | 135 |
137 if (!bookmarks.empty() && !cancelled()) { | 136 if (!bookmarks.empty() && !cancelled()) { |
138 const string16& first_folder_name = | 137 const string16& first_folder_name = |
139 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); | 138 l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE); |
(...skipping 14 matching lines...) Expand all Loading... |
154 CLSCTX_INPROC_SERVER); | 153 CLSCTX_INPROC_SERVER); |
155 if (FAILED(result)) | 154 if (FAILED(result)) |
156 return; | 155 return; |
157 base::win::ScopedComPtr<IEnumSTATURL> enum_url; | 156 base::win::ScopedComPtr<IEnumSTATURL> enum_url; |
158 if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) { | 157 if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) { |
159 std::vector<history::URLRow> rows; | 158 std::vector<history::URLRow> rows; |
160 STATURL stat_url; | 159 STATURL stat_url; |
161 ULONG fetched; | 160 ULONG fetched; |
162 while (!cancelled() && | 161 while (!cancelled() && |
163 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { | 162 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { |
164 std::wstring url_string; | 163 string16 url_string; |
165 std::wstring title_string; | |
166 if (stat_url.pwcsUrl) { | 164 if (stat_url.pwcsUrl) { |
167 url_string = stat_url.pwcsUrl; | 165 url_string = stat_url.pwcsUrl; |
168 CoTaskMemFree(stat_url.pwcsUrl); | 166 CoTaskMemFree(stat_url.pwcsUrl); |
169 } | 167 } |
| 168 string16 title_string; |
170 if (stat_url.pwcsTitle) { | 169 if (stat_url.pwcsTitle) { |
171 title_string = stat_url.pwcsTitle; | 170 title_string = stat_url.pwcsTitle; |
172 CoTaskMemFree(stat_url.pwcsTitle); | 171 CoTaskMemFree(stat_url.pwcsTitle); |
173 } | 172 } |
174 | 173 |
175 GURL url(url_string); | 174 GURL url(url_string); |
176 // Skips the URLs that are invalid or have other schemes. | 175 // Skips the URLs that are invalid or have other schemes. |
177 if (!url.is_valid() || | 176 if (!url.is_valid() || |
178 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == | 177 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == |
179 kSchemes + total_schemes)) | 178 kSchemes + total_schemes)) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 240 |
242 wchar_t* item_name; | 241 wchar_t* item_name; |
243 while (!cancelled() && SUCCEEDED(item->Next(1, &item_name, 0))) { | 242 while (!cancelled() && SUCCEEDED(item->Next(1, &item_name, 0))) { |
244 DWORD length = 0; | 243 DWORD length = 0; |
245 unsigned char* buffer = NULL; | 244 unsigned char* buffer = NULL; |
246 result = pstore->ReadItem(0, &AutocompleteGUID, &AutocompleteGUID, | 245 result = pstore->ReadItem(0, &AutocompleteGUID, &AutocompleteGUID, |
247 item_name, &length, &buffer, NULL, 0); | 246 item_name, &length, &buffer, NULL, 0); |
248 if (SUCCEEDED(result)) { | 247 if (SUCCEEDED(result)) { |
249 AutoCompleteInfo ac; | 248 AutoCompleteInfo ac; |
250 ac.key = item_name; | 249 ac.key = item_name; |
251 std::wstring data; | 250 string16 data; |
252 data.insert(0, reinterpret_cast<wchar_t*>(buffer), | 251 data.insert(0, reinterpret_cast<wchar_t*>(buffer), |
253 length / sizeof(wchar_t)); | 252 length / sizeof(wchar_t)); |
254 | 253 |
255 // The key name is always ended with ":StringData". | 254 // The key name is always ended with ":StringData". |
256 const wchar_t kDataSuffix[] = L":StringData"; | 255 const wchar_t kDataSuffix[] = L":StringData"; |
257 size_t i = ac.key.rfind(kDataSuffix); | 256 size_t i = ac.key.rfind(kDataSuffix); |
258 if (i != std::wstring::npos && ac.key.substr(i) == kDataSuffix) { | 257 if (i != string16::npos && ac.key.substr(i) == kDataSuffix) { |
259 ac.key.erase(i); | 258 ac.key.erase(i); |
260 ac.is_url = (ac.key.find(L"://") != std::wstring::npos); | 259 ac.is_url = (ac.key.find(L"://") != string16::npos); |
261 ac_list.push_back(ac); | 260 ac_list.push_back(ac); |
262 base::SplitString(data, L'\0', &ac_list[ac_list.size() - 1].data); | 261 base::SplitString(data, L'\0', &ac_list[ac_list.size() - 1].data); |
263 } | 262 } |
264 CoTaskMemFree(buffer); | 263 CoTaskMemFree(buffer); |
265 } | 264 } |
266 CoTaskMemFree(item_name); | 265 CoTaskMemFree(item_name); |
267 } | 266 } |
268 // Releases them before unload the dll. | 267 // Releases them before unload the dll. |
269 item.Release(); | 268 item.Release(); |
270 pstore.Release(); | 269 pstore.Release(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 void IEImporter::ImportSearchEngines() { | 353 void IEImporter::ImportSearchEngines() { |
355 // On IE, search engines are stored in the registry, under: | 354 // On IE, search engines are stored in the registry, under: |
356 // Software\Microsoft\Internet Explorer\SearchScopes | 355 // Software\Microsoft\Internet Explorer\SearchScopes |
357 // Each key represents a search engine. The URL value contains the URL and | 356 // Each key represents a search engine. The URL value contains the URL and |
358 // the DisplayName the name. | 357 // the DisplayName the name. |
359 // The default key's name is contained under DefaultScope. | 358 // The default key's name is contained under DefaultScope. |
360 const wchar_t* kSearchScopePath = | 359 const wchar_t* kSearchScopePath = |
361 L"Software\\Microsoft\\Internet Explorer\\SearchScopes"; | 360 L"Software\\Microsoft\\Internet Explorer\\SearchScopes"; |
362 | 361 |
363 base::win::RegKey key(HKEY_CURRENT_USER, kSearchScopePath, KEY_READ); | 362 base::win::RegKey key(HKEY_CURRENT_USER, kSearchScopePath, KEY_READ); |
364 std::wstring default_search_engine_name; | 363 string16 default_search_engine_name; |
365 const TemplateURL* default_search_engine = NULL; | 364 const TemplateURL* default_search_engine = NULL; |
366 std::map<std::string, TemplateURL*> search_engines_map; | 365 std::map<std::string, TemplateURL*> search_engines_map; |
367 key.ReadValue(L"DefaultScope", &default_search_engine_name); | 366 key.ReadValue(L"DefaultScope", &default_search_engine_name); |
368 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, | 367 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, |
369 kSearchScopePath); | 368 kSearchScopePath); |
370 while (key_iterator.Valid()) { | 369 while (key_iterator.Valid()) { |
371 std::wstring sub_key_name = kSearchScopePath; | 370 string16 sub_key_name = kSearchScopePath; |
372 sub_key_name.append(L"\\").append(key_iterator.Name()); | 371 sub_key_name.append(L"\\").append(key_iterator.Name()); |
373 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), | 372 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), |
374 KEY_READ); | 373 KEY_READ); |
375 std::wstring wide_url; | 374 string16 wide_url; |
376 if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) || | 375 if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) || |
377 wide_url.empty()) { | 376 wide_url.empty()) { |
378 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); | 377 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); |
379 ++key_iterator; | 378 ++key_iterator; |
380 continue; | 379 continue; |
381 } | 380 } |
382 // For the name, we try the default value first (as Live Search uses a | 381 // For the name, we try the default value first (as Live Search uses a |
383 // non displayable name in DisplayName, and the readable name under the | 382 // non displayable name in DisplayName, and the readable name under the |
384 // default value). | 383 // default value). |
385 std::wstring name; | 384 string16 name; |
386 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) { | 385 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) { |
387 // Try the displayable name. | 386 // Try the displayable name. |
388 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) || | 387 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) || |
389 name.empty()) { | 388 name.empty()) { |
390 VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); | 389 VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); |
391 ++key_iterator; | 390 ++key_iterator; |
392 continue; | 391 continue; |
393 } | 392 } |
394 } | 393 } |
395 | 394 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 bridge_->SetKeywords(search_engines, default_search_engine_index, true); | 433 bridge_->SetKeywords(search_engines, default_search_engine_index, true); |
435 } | 434 } |
436 | 435 |
437 void IEImporter::ImportHomepage() { | 436 void IEImporter::ImportHomepage() { |
438 const wchar_t* kIESettingsMain = | 437 const wchar_t* kIESettingsMain = |
439 L"Software\\Microsoft\\Internet Explorer\\Main"; | 438 L"Software\\Microsoft\\Internet Explorer\\Main"; |
440 const wchar_t* kIEHomepage = L"Start Page"; | 439 const wchar_t* kIEHomepage = L"Start Page"; |
441 const wchar_t* kIEDefaultHomepage = L"Default_Page_URL"; | 440 const wchar_t* kIEDefaultHomepage = L"Default_Page_URL"; |
442 | 441 |
443 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); | 442 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); |
444 std::wstring homepage_url; | 443 string16 homepage_url; |
445 if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS || | 444 if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS || |
446 homepage_url.empty()) | 445 homepage_url.empty()) |
447 return; | 446 return; |
448 | 447 |
449 GURL homepage = GURL(homepage_url); | 448 GURL homepage = GURL(homepage_url); |
450 if (!homepage.is_valid()) | 449 if (!homepage.is_valid()) |
451 return; | 450 return; |
452 | 451 |
453 // Check to see if this is the default website and skip import. | 452 // Check to see if this is the default website and skip import. |
454 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); | 453 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); |
455 std::wstring default_homepage_url; | 454 string16 default_homepage_url; |
456 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); | 455 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); |
457 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { | 456 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { |
458 if (homepage.spec() == GURL(default_homepage_url).spec()) | 457 if (homepage.spec() == GURL(default_homepage_url).spec()) |
459 return; | 458 return; |
460 } | 459 } |
461 | 460 |
462 bridge_->AddHomePage(homepage); | 461 bridge_->AddHomePage(homepage); |
463 } | 462 } |
464 | 463 |
465 string16 IEImporter::ResolveInternetShortcut(const string16& file) { | 464 string16 IEImporter::ResolveInternetShortcut(const string16& file) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 if (version < 0) { | 587 if (version < 0) { |
589 wchar_t buffer[128]; | 588 wchar_t buffer[128]; |
590 DWORD buffer_length = sizeof(buffer); | 589 DWORD buffer_length = sizeof(buffer); |
591 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, | 590 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, |
592 L"Software\\Microsoft\\Internet Explorer", KEY_READ); | 591 L"Software\\Microsoft\\Internet Explorer", KEY_READ); |
593 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 592 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
594 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 593 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
595 } | 594 } |
596 return version; | 595 return version; |
597 } | 596 } |
OLD | NEW |