OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <atlbase.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> |
| 15 #include <string> |
| 16 #include <vector> |
14 | 17 |
15 #include "app/l10n_util.h" | 18 #include "app/l10n_util.h" |
16 #include "app/win_util.h" | 19 #include "app/win_util.h" |
17 #include "base/file_path.h" | 20 #include "base/file_path.h" |
18 #include "base/file_util.h" | 21 #include "base/file_util.h" |
19 #include "base/registry.h" | 22 #include "base/registry.h" |
| 23 #include "base/scoped_comptr_win.h" |
20 #include "base/string_util.h" | 24 #include "base/string_util.h" |
21 #include "base/time.h" | 25 #include "base/time.h" |
22 #include "base/win_util.h" | 26 #include "base/win_util.h" |
23 #include "chrome/browser/bookmarks/bookmark_model.h" | 27 #include "chrome/browser/bookmarks/bookmark_model.h" |
24 #include "chrome/browser/password_manager/ie7_password.h" | 28 #include "chrome/browser/password_manager/ie7_password.h" |
25 #include "chrome/browser/search_engines/template_url_model.h" | 29 #include "chrome/browser/search_engines/template_url_model.h" |
26 #include "chrome/common/time_format.h" | 30 #include "chrome/common/time_format.h" |
27 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
28 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
29 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 uint16 items, | 66 uint16 items, |
63 ProfileWriter* writer, | 67 ProfileWriter* writer, |
64 MessageLoop* delagate_loop, | 68 MessageLoop* delagate_loop, |
65 ImporterHost* host) { | 69 ImporterHost* host) { |
66 writer_ = writer; | 70 writer_ = writer; |
67 source_path_ = profile_info.source_path; | 71 source_path_ = profile_info.source_path; |
68 importer_host_ = host; | 72 importer_host_ = host; |
69 | 73 |
70 NotifyStarted(); | 74 NotifyStarted(); |
71 | 75 |
72 // Some IE settings (such as Protected Storage) is obtained via COM APIs. | 76 // Some IE settings (such as Protected Storage) are obtained via COM APIs. |
73 win_util::ScopedCOMInitializer com_initializer; | 77 win_util::ScopedCOMInitializer com_initializer; |
74 | 78 |
75 if ((items & HOME_PAGE) && !cancelled()) | 79 if ((items & HOME_PAGE) && !cancelled()) |
76 ImportHomepage(); // Doesn't have a UI item. | 80 ImportHomepage(); // Doesn't have a UI item. |
77 // The order here is important! | 81 // The order here is important! |
78 if ((items & FAVORITES) && !cancelled()) { | 82 if ((items & FAVORITES) && !cancelled()) { |
79 NotifyItemStarted(FAVORITES); | 83 NotifyItemStarted(FAVORITES); |
80 ImportFavorites(); | 84 ImportFavorites(); |
81 NotifyItemEnded(FAVORITES); | 85 NotifyItemEnded(FAVORITES); |
82 } | 86 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 HMODULE pstorec_dll = LoadLibrary(L"pstorec.dll"); | 139 HMODULE pstorec_dll = LoadLibrary(L"pstorec.dll"); |
136 if (!pstorec_dll) | 140 if (!pstorec_dll) |
137 return; | 141 return; |
138 PStoreCreateFunc PStoreCreateInstance = | 142 PStoreCreateFunc PStoreCreateInstance = |
139 (PStoreCreateFunc)GetProcAddress(pstorec_dll, "PStoreCreateInstance"); | 143 (PStoreCreateFunc)GetProcAddress(pstorec_dll, "PStoreCreateInstance"); |
140 if (!PStoreCreateInstance) { | 144 if (!PStoreCreateInstance) { |
141 FreeLibrary(pstorec_dll); | 145 FreeLibrary(pstorec_dll); |
142 return; | 146 return; |
143 } | 147 } |
144 | 148 |
145 CComPtr<IPStore> pstore; | 149 ScopedComPtr<IPStore, &IID_IPStore> pstore; |
146 HRESULT result = PStoreCreateInstance(&pstore, 0, 0, 0); | 150 HRESULT result = PStoreCreateInstance(pstore.Receive(), 0, 0, 0); |
147 if (result != S_OK) { | 151 if (result != S_OK) { |
148 FreeLibrary(pstorec_dll); | 152 FreeLibrary(pstorec_dll); |
149 return; | 153 return; |
150 } | 154 } |
151 | 155 |
152 std::vector<AutoCompleteInfo> ac_list; | 156 std::vector<AutoCompleteInfo> ac_list; |
153 | 157 |
154 // Enumerates AutoComplete items in the protected database. | 158 // Enumerates AutoComplete items in the protected database. |
155 CComPtr<IEnumPStoreItems> item; | 159 ScopedComPtr<IEnumPStoreItems, &IID_IEnumPStoreItems> item; |
156 result = pstore->EnumItems(0, &AutocompleteGUID, | 160 result = pstore->EnumItems(0, &AutocompleteGUID, |
157 &AutocompleteGUID, 0, &item); | 161 &AutocompleteGUID, 0, item.Receive()); |
158 if (result != PST_E_OK) { | 162 if (result != PST_E_OK) { |
159 pstore.Release(); | 163 pstore.Release(); |
160 FreeLibrary(pstorec_dll); | 164 FreeLibrary(pstorec_dll); |
161 return; | 165 return; |
162 } | 166 } |
163 | 167 |
164 wchar_t* item_name; | 168 wchar_t* item_name; |
165 while (!cancelled() && SUCCEEDED(item->Next(1, &item_name, 0))) { | 169 while (!cancelled() && SUCCEEDED(item->Next(1, &item_name, 0))) { |
166 DWORD length = 0; | 170 DWORD length = 0; |
167 unsigned char* buffer = NULL; | 171 unsigned char* buffer = NULL; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 279 } |
276 | 280 |
277 // Reads history information from COM interface. | 281 // Reads history information from COM interface. |
278 void IEImporter::ImportHistory() { | 282 void IEImporter::ImportHistory() { |
279 const std::string kSchemes[] = {chrome::kHttpScheme, | 283 const std::string kSchemes[] = {chrome::kHttpScheme, |
280 chrome::kHttpsScheme, | 284 chrome::kHttpsScheme, |
281 chrome::kFtpScheme, | 285 chrome::kFtpScheme, |
282 chrome::kFileScheme}; | 286 chrome::kFileScheme}; |
283 int total_schemes = arraysize(kSchemes); | 287 int total_schemes = arraysize(kSchemes); |
284 | 288 |
285 CComPtr<IUrlHistoryStg2> url_history_stg2; | 289 ScopedComPtr<IUrlHistoryStg2> url_history_stg2; |
286 HRESULT result; | 290 HRESULT result; |
287 result = url_history_stg2.CoCreateInstance(CLSID_CUrlHistory, NULL, | 291 result = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, |
288 CLSCTX_INPROC_SERVER); | 292 CLSCTX_INPROC_SERVER); |
289 if (FAILED(result)) | 293 if (FAILED(result)) |
290 return; | 294 return; |
291 CComPtr<IEnumSTATURL> enum_url; | 295 ScopedComPtr<IEnumSTATURL> enum_url; |
292 if (SUCCEEDED(result = url_history_stg2->EnumUrls(&enum_url))) { | 296 if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) { |
293 std::vector<history::URLRow> rows; | 297 std::vector<history::URLRow> rows; |
294 STATURL stat_url; | 298 STATURL stat_url; |
295 ULONG fetched; | 299 ULONG fetched; |
296 while (!cancelled() && | 300 while (!cancelled() && |
297 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { | 301 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { |
298 std::wstring url_string; | 302 std::wstring url_string; |
299 std::wstring title_string; | 303 std::wstring title_string; |
300 if (stat_url.pwcsUrl) { | 304 if (stat_url.pwcsUrl) { |
301 url_string = stat_url.pwcsUrl; | 305 url_string = stat_url.pwcsUrl; |
302 CoTaskMemFree(stat_url.pwcsUrl); | 306 CoTaskMemFree(stat_url.pwcsUrl); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 entry.path.insert(entry.path.begin(), ie_folder); | 538 entry.path.insert(entry.path.begin(), ie_folder); |
535 bookmarks->push_back(entry); | 539 bookmarks->push_back(entry); |
536 } | 540 } |
537 } | 541 } |
538 bookmarks->insert(bookmarks->begin(), toolbar_bookmarks.begin(), | 542 bookmarks->insert(bookmarks->begin(), toolbar_bookmarks.begin(), |
539 toolbar_bookmarks.end()); | 543 toolbar_bookmarks.end()); |
540 } | 544 } |
541 | 545 |
542 std::wstring IEImporter::ResolveInternetShortcut(const std::wstring& file) { | 546 std::wstring IEImporter::ResolveInternetShortcut(const std::wstring& file) { |
543 win_util::CoMemReleaser<wchar_t> url; | 547 win_util::CoMemReleaser<wchar_t> url; |
544 CComPtr<IUniformResourceLocator> url_locator; | 548 ScopedComPtr<IUniformResourceLocator> url_locator; |
545 HRESULT result = url_locator.CoCreateInstance(CLSID_InternetShortcut, NULL, | 549 HRESULT result = url_locator.CreateInstance(CLSID_InternetShortcut, NULL, |
546 CLSCTX_INPROC_SERVER); | 550 CLSCTX_INPROC_SERVER); |
547 if (FAILED(result)) | 551 if (FAILED(result)) |
548 return std::wstring(); | 552 return std::wstring(); |
549 | 553 |
550 CComPtr<IPersistFile> persist_file; | 554 ScopedComPtr<IPersistFile> persist_file; |
551 result = url_locator.QueryInterface(&persist_file); | 555 result = persist_file.QueryFrom(url_locator); |
552 if (FAILED(result)) | 556 if (FAILED(result)) |
553 return std::wstring(); | 557 return std::wstring(); |
554 | 558 |
555 // Loads the Internet Shortcut from persistent storage. | 559 // Loads the Internet Shortcut from persistent storage. |
556 result = persist_file->Load(file.c_str(), STGM_READ); | 560 result = persist_file->Load(file.c_str(), STGM_READ); |
557 if (FAILED(result)) | 561 if (FAILED(result)) |
558 return std::wstring(); | 562 return std::wstring(); |
559 | 563 |
560 result = url_locator->GetURL(&url); | 564 result = url_locator->GetURL(&url); |
561 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. | 565 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. |
562 if (FAILED(result) || (url == NULL)) | 566 if (FAILED(result) || (url == NULL)) |
563 return std::wstring(); | 567 return std::wstring(); |
564 | 568 |
565 return std::wstring(url); | 569 return std::wstring(url); |
566 } | 570 } |
567 | 571 |
568 int IEImporter::CurrentIEVersion() const { | 572 int IEImporter::CurrentIEVersion() const { |
569 static int version = -1; | 573 static int version = -1; |
570 if (version < 0) { | 574 if (version < 0) { |
571 wchar_t buffer[128]; | 575 wchar_t buffer[128]; |
572 DWORD buffer_length = sizeof(buffer); | 576 DWORD buffer_length = sizeof(buffer); |
573 bool result = ReadFromRegistry(HKEY_LOCAL_MACHINE, | 577 bool result = ReadFromRegistry(HKEY_LOCAL_MACHINE, |
574 L"Software\\Microsoft\\Internet Explorer", | 578 L"Software\\Microsoft\\Internet Explorer", |
575 L"Version", buffer, &buffer_length); | 579 L"Version", buffer, &buffer_length); |
576 version = (result ? _wtoi(buffer) : 0); | 580 version = (result ? _wtoi(buffer) : 0); |
577 } | 581 } |
578 return version; | 582 return version; |
579 } | 583 } |
OLD | NEW |