| 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/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 470 } |
| 471 | 471 |
| 472 void IEImporter::ImportHistory() { | 472 void IEImporter::ImportHistory() { |
| 473 const std::string kSchemes[] = {url::kHttpScheme, | 473 const std::string kSchemes[] = {url::kHttpScheme, |
| 474 url::kHttpsScheme, | 474 url::kHttpsScheme, |
| 475 url::kFtpScheme, | 475 url::kFtpScheme, |
| 476 url::kFileScheme}; | 476 url::kFileScheme}; |
| 477 int total_schemes = arraysize(kSchemes); | 477 int total_schemes = arraysize(kSchemes); |
| 478 | 478 |
| 479 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; | 479 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; |
| 480 HRESULT result; | 480 if (FAILED(url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, |
| 481 result = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, | 481 CLSCTX_INPROC_SERVER))) { |
| 482 CLSCTX_INPROC_SERVER); | |
| 483 if (FAILED(result)) | |
| 484 return; | 482 return; |
| 483 } |
| 485 base::win::ScopedComPtr<IEnumSTATURL> enum_url; | 484 base::win::ScopedComPtr<IEnumSTATURL> enum_url; |
| 486 if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) { | 485 if (SUCCEEDED(url_history_stg2->EnumUrls(enum_url.Receive()))) { |
| 487 std::vector<ImporterURLRow> rows; | 486 std::vector<ImporterURLRow> rows; |
| 488 STATURL stat_url; | 487 STATURL stat_url; |
| 489 ULONG fetched; | 488 |
| 489 // IEnumSTATURL::Next() doesn't fill STATURL::dwFlags by default. Need to |
| 490 // call IEnumSTATURL::SetFilter() with STATURL_QUERYFLAG_TOPLEVEL flag to |
| 491 // specify how STATURL structure will be filled. |
| 492 // The first argument of IEnumSTATURL::SetFilter() specifies the URL prefix |
| 493 // that is used by IEnumSTATURL::Next() for filtering items by URL. |
| 494 // So need to pass an empty string here to get all history items. |
| 495 enum_url->SetFilter(L"", STATURL_QUERYFLAG_TOPLEVEL); |
| 490 while (!cancelled() && | 496 while (!cancelled() && |
| 491 (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) { | 497 enum_url->Next(1, &stat_url, NULL) == S_OK) { |
| 492 base::string16 url_string; | 498 base::string16 url_string; |
| 493 if (stat_url.pwcsUrl) { | 499 if (stat_url.pwcsUrl) { |
| 494 url_string = stat_url.pwcsUrl; | 500 url_string = stat_url.pwcsUrl; |
| 495 CoTaskMemFree(stat_url.pwcsUrl); | 501 CoTaskMemFree(stat_url.pwcsUrl); |
| 496 } | 502 } |
| 497 base::string16 title_string; | 503 base::string16 title_string; |
| 498 if (stat_url.pwcsTitle) { | 504 if (stat_url.pwcsTitle) { |
| 499 title_string = stat_url.pwcsTitle; | 505 title_string = stat_url.pwcsTitle; |
| 500 CoTaskMemFree(stat_url.pwcsTitle); | 506 CoTaskMemFree(stat_url.pwcsTitle); |
| 501 } | 507 } |
| 502 | 508 |
| 503 GURL url(url_string); | 509 GURL url(url_string); |
| 504 // Skips the URLs that are invalid or have other schemes. | 510 // Skips the URLs that are invalid or have other schemes. |
| 505 if (!url.is_valid() || | 511 if (!url.is_valid() || |
| 506 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == | 512 (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) == |
| 507 kSchemes + total_schemes)) | 513 kSchemes + total_schemes)) |
| 508 continue; | 514 continue; |
| 509 | 515 |
| 510 ImporterURLRow row(url); | 516 ImporterURLRow row(url); |
| 511 row.title = title_string; | 517 row.title = title_string; |
| 512 row.last_visit = base::Time::FromFileTime(stat_url.ftLastVisited); | 518 row.last_visit = base::Time::FromFileTime(stat_url.ftLastVisited); |
| 513 if (stat_url.dwFlags == STATURL_QUERYFLAG_TOPLEVEL) { | 519 if (stat_url.dwFlags == STATURLFLAG_ISTOPLEVEL) { |
| 514 row.visit_count = 1; | 520 row.visit_count = 1; |
| 515 row.hidden = false; | 521 row.hidden = false; |
| 516 } else { | 522 } else { |
| 523 // dwFlags should only contain the STATURLFLAG_ISTOPLEVEL bit per |
| 524 // the filter set above. |
| 525 DCHECK(!stat_url.dwFlags); |
| 517 row.hidden = true; | 526 row.hidden = true; |
| 518 } | 527 } |
| 519 | 528 |
| 520 rows.push_back(row); | 529 rows.push_back(row); |
| 521 } | 530 } |
| 522 | 531 |
| 523 if (!rows.empty() && !cancelled()) { | 532 if (!rows.empty() && !cancelled()) { |
| 524 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); | 533 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); |
| 525 } | 534 } |
| 526 } | 535 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 static int version = -1; | 883 static int version = -1; |
| 875 if (version < 0) { | 884 if (version < 0) { |
| 876 wchar_t buffer[128]; | 885 wchar_t buffer[128]; |
| 877 DWORD buffer_length = sizeof(buffer); | 886 DWORD buffer_length = sizeof(buffer); |
| 878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 887 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 888 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 889 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 881 } | 890 } |
| 882 return version; | 891 return version; |
| 883 } | 892 } |
| OLD | NEW |