Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: chrome/browser/download/download_query.cc

Issue 1706193002: Expose final download URL (actual url after redirects) in the extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/download/download_query.h" 5 #include "chrome/browser/download/download_query.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 static std::string GetFilenameUTF8(const DownloadItem& item) { 115 static std::string GetFilenameUTF8(const DownloadItem& item) {
116 return base::UTF16ToUTF8(GetFilename(item)); 116 return base::UTF16ToUTF8(GetFilename(item));
117 } 117 }
118 118
119 static std::string GetUrl(const DownloadItem& item) { 119 static std::string GetUrl(const DownloadItem& item) {
120 return item.GetOriginalUrl().spec(); 120 return item.GetOriginalUrl().spec();
121 } 121 }
122 122
123 static std::string GetFinalUrl(const DownloadItem& item) {
asanka 2016/02/18 15:32:27 "static" unnecessary for functions defined within
124 return item.GetURL().spec();
125 }
126
123 static DownloadItem::DownloadState GetState(const DownloadItem& item) { 127 static DownloadItem::DownloadState GetState(const DownloadItem& item) {
124 return item.GetState(); 128 return item.GetState();
125 } 129 }
126 130
127 static DownloadDangerType GetDangerType(const DownloadItem& item) { 131 static DownloadDangerType GetDangerType(const DownloadItem& item) {
128 return item.GetDangerType(); 132 return item.GetDangerType();
129 } 133 }
130 134
131 static int GetReceivedBytes(const DownloadItem& item) { 135 static int GetReceivedBytes(const DownloadItem& item) {
132 return item.GetReceivedBytes(); 136 return item.GetReceivedBytes();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } // anonymous namespace 216 } // anonymous namespace
213 217
214 // static 218 // static
215 bool DownloadQuery::MatchesQuery(const std::vector<base::string16>& query_terms, 219 bool DownloadQuery::MatchesQuery(const std::vector<base::string16>& query_terms,
216 const DownloadItem& item) { 220 const DownloadItem& item) {
217 if (query_terms.empty()) 221 if (query_terms.empty())
218 return true; 222 return true;
219 223
220 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec())); 224 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec()));
221 base::string16 url_formatted = url_raw; 225 base::string16 url_formatted = url_raw;
226 base::string16 final_url_raw(base::UTF8ToUTF16(item.GetURL().spec()));
227 base::string16 final_url_formatted = final_url_raw;
222 if (item.GetBrowserContext()) { 228 if (item.GetBrowserContext()) {
223 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); 229 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext());
224 url_formatted = url_formatter::FormatUrl( 230 url_formatted = url_formatter::FormatUrl(
225 item.GetOriginalUrl(), 231 item.GetOriginalUrl(),
226 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); 232 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
233 final_url_formatted = url_formatter::FormatUrl(
234 item.GetURL(), profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
227 } 235 }
228 base::string16 path(item.GetTargetFilePath().LossyDisplayName()); 236 base::string16 path(item.GetTargetFilePath().LossyDisplayName());
229 237
230 for (std::vector<base::string16>::const_iterator it = query_terms.begin(); 238 for (std::vector<base::string16>::const_iterator it = query_terms.begin();
231 it != query_terms.end(); ++it) { 239 it != query_terms.end(); ++it) {
232 base::string16 term = base::i18n::ToLower(*it); 240 base::string16 term = base::i18n::ToLower(*it);
233 if (!base::i18n::StringSearchIgnoringCaseAndAccents( 241 if (!base::i18n::StringSearchIgnoringCaseAndAccents(
234 term, url_raw, NULL, NULL) && 242 term, url_raw, NULL, NULL) &&
235 !base::i18n::StringSearchIgnoringCaseAndAccents( 243 !base::i18n::StringSearchIgnoringCaseAndAccents(
236 term, url_formatted, NULL, NULL) && 244 term, url_formatted, NULL, NULL) &&
237 !base::i18n::StringSearchIgnoringCaseAndAccents( 245 !base::i18n::StringSearchIgnoringCaseAndAccents(
246 term, final_url_raw, NULL, NULL) &&
247 !base::i18n::StringSearchIgnoringCaseAndAccents(
248 term, final_url_formatted, NULL, NULL) &&
249 !base::i18n::StringSearchIgnoringCaseAndAccents(
238 term, path, NULL, NULL)) { 250 term, path, NULL, NULL)) {
239 return false; 251 return false;
240 } 252 }
241 } 253 }
242 return true; 254 return true;
243 } 255 }
244 256
245 DownloadQuery::DownloadQuery() : limit_(std::numeric_limits<uint32_t>::max()) {} 257 DownloadQuery::DownloadQuery() : limit_(std::numeric_limits<uint32_t>::max()) {}
246 DownloadQuery::~DownloadQuery() {} 258 DownloadQuery::~DownloadQuery() {}
247 259
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 case FILTER_TOTAL_BYTES: 316 case FILTER_TOTAL_BYTES:
305 return AddFilter(BuildFilter<int>(value, EQ, &GetTotalBytes)); 317 return AddFilter(BuildFilter<int>(value, EQ, &GetTotalBytes));
306 case FILTER_TOTAL_BYTES_GREATER: 318 case FILTER_TOTAL_BYTES_GREATER:
307 return AddFilter(BuildFilter<int>(value, GT, &GetTotalBytes)); 319 return AddFilter(BuildFilter<int>(value, GT, &GetTotalBytes));
308 case FILTER_TOTAL_BYTES_LESS: 320 case FILTER_TOTAL_BYTES_LESS:
309 return AddFilter(BuildFilter<int>(value, LT, &GetTotalBytes)); 321 return AddFilter(BuildFilter<int>(value, LT, &GetTotalBytes));
310 case FILTER_URL: 322 case FILTER_URL:
311 return AddFilter(BuildFilter<std::string>(value, EQ, &GetUrl)); 323 return AddFilter(BuildFilter<std::string>(value, EQ, &GetUrl));
312 case FILTER_URL_REGEX: 324 case FILTER_URL_REGEX:
313 return AddFilter(BuildRegexFilter(value, &GetUrl)); 325 return AddFilter(BuildRegexFilter(value, &GetUrl));
326 case FILTER_FINAL_URL:
327 return AddFilter(BuildFilter<std::string>(value, EQ, &GetFinalUrl));
328 case FILTER_FINAL_URL_REGEX:
329 return AddFilter(BuildRegexFilter(value, &GetFinalUrl));
314 } 330 }
315 return false; 331 return false;
316 } 332 }
317 333
318 bool DownloadQuery::Matches(const DownloadItem& item) const { 334 bool DownloadQuery::Matches(const DownloadItem& item) const {
319 for (FilterCallbackVector::const_iterator filter = filters_.begin(); 335 for (FilterCallbackVector::const_iterator filter = filters_.begin();
320 filter != filters_.end(); ++filter) { 336 filter != filters_.end(); ++filter) {
321 if (!filter->Run(item)) 337 if (!filter->Run(item))
322 return false; 338 return false;
323 } 339 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 case SORT_END_TIME: 409 case SORT_END_TIME:
394 sorters_.push_back(Sorter::Build<int64_t>(direction, &GetEndTimeMsEpoch)); 410 sorters_.push_back(Sorter::Build<int64_t>(direction, &GetEndTimeMsEpoch));
395 break; 411 break;
396 case SORT_START_TIME: 412 case SORT_START_TIME:
397 sorters_.push_back( 413 sorters_.push_back(
398 Sorter::Build<int64_t>(direction, &GetStartTimeMsEpoch)); 414 Sorter::Build<int64_t>(direction, &GetStartTimeMsEpoch));
399 break; 415 break;
400 case SORT_URL: 416 case SORT_URL:
401 sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl)); 417 sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl));
402 break; 418 break;
419 case SORT_FINAL_URL:
420 sorters_.push_back(Sorter::Build<std::string>(direction, &GetFinalUrl));
421 break;
403 case SORT_FILENAME: 422 case SORT_FILENAME:
404 sorters_.push_back( 423 sorters_.push_back(
405 Sorter::Build<base::string16>(direction, &GetFilename)); 424 Sorter::Build<base::string16>(direction, &GetFilename));
406 break; 425 break;
407 case SORT_DANGER: 426 case SORT_DANGER:
408 sorters_.push_back(Sorter::Build<DownloadDangerType>( 427 sorters_.push_back(Sorter::Build<DownloadDangerType>(
409 direction, &GetDangerType)); 428 direction, &GetDangerType));
410 break; 429 break;
411 case SORT_DANGER_ACCEPTED: 430 case SORT_DANGER_ACCEPTED:
412 sorters_.push_back(Sorter::Build<bool>(direction, &GetDangerAccepted)); 431 sorters_.push_back(Sorter::Build<bool>(direction, &GetDangerAccepted));
(...skipping 24 matching lines...) Expand all
437 if (!sorters_.empty()) { 456 if (!sorters_.empty()) {
438 std::partial_sort(results->begin(), 457 std::partial_sort(results->begin(),
439 results->begin() + std::min(limit_, results->size()), 458 results->begin() + std::min(limit_, results->size()),
440 results->end(), 459 results->end(),
441 DownloadComparator(sorters_)); 460 DownloadComparator(sorters_));
442 } 461 }
443 462
444 if (results->size() > limit_) 463 if (results->size() > limit_)
445 results->resize(limit_); 464 results->resize(limit_);
446 } 465 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_query.h ('k') | chrome/browser/download/download_query_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698