Chromium Code Reviews| Index: chrome/browser/download/download_query.cc |
| diff --git a/chrome/browser/download/download_query.cc b/chrome/browser/download/download_query.cc |
| index c2049d21dd05c2ebec94d887eada5932d4deec97..67ca9c63415851241ebee81e54a2e7f329da95cc 100644 |
| --- a/chrome/browser/download/download_query.cc |
| +++ b/chrome/browser/download/download_query.cc |
| @@ -11,6 +11,8 @@ |
| #include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/file_path.h" |
| +#include "base/i18n/case_conversion.h" |
| +#include "base/i18n/string_search.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/stl_util.h" |
| @@ -19,8 +21,10 @@ |
| #include "base/time.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/values.h" |
| +#include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/download_item.h" |
| #include "googleurl/src/gurl.h" |
| +#include "net/base/net_util.h" |
| #include "unicode/regex.h" |
| using content::DownloadDangerType; |
| @@ -46,8 +50,37 @@ template<> bool GetAs(const base::Value& in, string16* out) { |
| // The next several functions are helpers for making Callbacks that access |
| // DownloadItem fields. |
| -static bool MatchesQuery(const string16& value, const DownloadItem& item) { |
| - return item.MatchesQuery(value); |
| +static bool MatchesQuery(const string16& query, const DownloadItem& item) { |
| + if (query.empty()) |
| + return true; |
| + |
| + DCHECK_EQ(query, base::i18n::ToLower(query)); |
| + |
| + string16 url_raw(UTF8ToUTF16(item.GetOriginalUrl().spec())); |
| + if (base::i18n::StringSearchIgnoringCaseAndAccents( |
| + query, url_raw, NULL, NULL)) { |
| + return true; |
| + } |
| + |
| + // TODO(phajdan.jr): write a test case for the following code. |
| + // A good test case would be: |
| + // "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", |
| + // L"/\x4f60\x597d\x4f60\x597d", |
| + // "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD" |
| + string16 url_formatted = url_raw; |
| + if (item.GetBrowserContext()) |
|
asanka
2012/09/12 18:43:49
Nit: Braces
benjhayden
2012/09/12 19:31:57
Done.
|
| + url_formatted = net::FormatUrl( |
| + item.GetOriginalUrl(), |
| + content::GetContentClient()->browser()->GetAcceptLangs( |
| + item.GetBrowserContext())); |
| + if (base::i18n::StringSearchIgnoringCaseAndAccents( |
| + query, url_formatted, NULL, NULL)) { |
| + return true; |
| + } |
| + |
| + string16 path(item.GetTargetFilePath().LossyDisplayName()); |
| + return base::i18n::StringSearchIgnoringCaseAndAccents( |
| + query, path, NULL, NULL); |
| } |
| static int GetStartTime(const DownloadItem& item) { |
| @@ -61,7 +94,7 @@ static bool GetDangerAccepted(const DownloadItem& item) { |
| static string16 GetFilename(const DownloadItem& item) { |
| // This filename will be compared with strings that could be passed in by the |
| // user, who only sees LossyDisplayNames. |
| - return item.GetFullPath().LossyDisplayName(); |
| + return item.GetTargetFilePath().LossyDisplayName(); |
| } |
| static std::string GetFilenameUTF8(const DownloadItem& item) { |