Chromium Code Reviews| 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 that STATURL::dwFlags will indicate whether this URL is dated | |
|
gab
2014/12/23 22:00:58
I prefered your previous wording, e.g. something l
Alexey Seren
2014/12/24 07:23:19
Acknowledged. Changed to previous comment.
| |
| 492 // (top level). First argument of IEnumSTATURL::SetFilter() specifies the | |
| 493 // URL prefix that is used by IEnumSTATURL::Next() for filtering items by | |
| 494 // URL. 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 DCHECK(!stat_url.dwFlags); | |
|
gab
2014/12/23 22:00:58
As in code provided in previous comment, add this
Alexey Seren
2014/12/24 07:23:19
Acknowledged.
| |
| 517 row.hidden = true; | 524 row.hidden = true; |
| 518 } | 525 } |
| 519 | 526 |
| 520 rows.push_back(row); | 527 rows.push_back(row); |
| 521 } | 528 } |
| 522 | 529 |
| 523 if (!rows.empty() && !cancelled()) { | 530 if (!rows.empty() && !cancelled()) { |
| 524 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); | 531 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_IE_IMPORTED); |
| 525 } | 532 } |
| 526 } | 533 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 static int version = -1; | 881 static int version = -1; |
| 875 if (version < 0) { | 882 if (version < 0) { |
| 876 wchar_t buffer[128]; | 883 wchar_t buffer[128]; |
| 877 DWORD buffer_length = sizeof(buffer); | 884 DWORD buffer_length = sizeof(buffer); |
| 878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 885 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
| 879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 886 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
| 880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 887 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
| 881 } | 888 } |
| 882 return version; | 889 return version; |
| 883 } | 890 } |
| OLD | NEW |