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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.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/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 const char kStartedBeforeKey[] = "startedBefore"; 165 const char kStartedBeforeKey[] = "startedBefore";
166 const char kStateComplete[] = "complete"; 166 const char kStateComplete[] = "complete";
167 const char kStateInProgress[] = "in_progress"; 167 const char kStateInProgress[] = "in_progress";
168 const char kStateInterrupted[] = "interrupted"; 168 const char kStateInterrupted[] = "interrupted";
169 const char kStateKey[] = "state"; 169 const char kStateKey[] = "state";
170 const char kTotalBytesGreaterKey[] = "totalBytesGreater"; 170 const char kTotalBytesGreaterKey[] = "totalBytesGreater";
171 const char kTotalBytesKey[] = "totalBytes"; 171 const char kTotalBytesKey[] = "totalBytes";
172 const char kTotalBytesLessKey[] = "totalBytesLess"; 172 const char kTotalBytesLessKey[] = "totalBytesLess";
173 const char kUrlKey[] = "url"; 173 const char kUrlKey[] = "url";
174 const char kUrlRegexKey[] = "urlRegex"; 174 const char kUrlRegexKey[] = "urlRegex";
175 const char kFinalUrlKey[] = "finalUrl";
176 const char kFinalUrlRegexKey[] = "finalUrlRegex";
175 177
176 // Note: Any change to the danger type strings, should be accompanied by a 178 // Note: Any change to the danger type strings, should be accompanied by a
177 // corresponding change to downloads.json. 179 // corresponding change to downloads.json.
178 const char* const kDangerStrings[] = { 180 const char* const kDangerStrings[] = {
179 kDangerSafe, 181 kDangerSafe,
180 kDangerFile, 182 kDangerFile,
181 kDangerUrl, 183 kDangerUrl,
182 kDangerContent, 184 kDangerContent,
183 kDangerSafe, 185 kDangerSafe,
184 kDangerUncommon, 186 kDangerUncommon,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 248 }
247 249
248 scoped_ptr<base::DictionaryValue> DownloadItemToJSON( 250 scoped_ptr<base::DictionaryValue> DownloadItemToJSON(
249 DownloadItem* download_item, 251 DownloadItem* download_item,
250 Profile* profile) { 252 Profile* profile) {
251 base::DictionaryValue* json = new base::DictionaryValue(); 253 base::DictionaryValue* json = new base::DictionaryValue();
252 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved()); 254 json->SetBoolean(kExistsKey, !download_item->GetFileExternallyRemoved());
253 json->SetInteger(kIdKey, download_item->GetId()); 255 json->SetInteger(kIdKey, download_item->GetId());
254 const GURL& url = download_item->GetOriginalUrl(); 256 const GURL& url = download_item->GetOriginalUrl();
255 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string())); 257 json->SetString(kUrlKey, (url.is_valid() ? url.spec() : std::string()));
258 const GURL& finalUrl = download_item->GetURL();
259 json->SetString(kFinalUrlKey,
260 (finalUrl.is_valid() ? finalUrl.spec() : std::string()));
256 const GURL& referrer = download_item->GetReferrerUrl(); 261 const GURL& referrer = download_item->GetReferrerUrl();
257 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec() 262 json->SetString(kReferrerUrlKey, (referrer.is_valid() ? referrer.spec()
258 : std::string())); 263 : std::string()));
259 json->SetString(kFilenameKey, 264 json->SetString(kFilenameKey,
260 download_item->GetTargetFilePath().LossyDisplayName()); 265 download_item->GetTargetFilePath().LossyDisplayName());
261 json->SetString(kDangerKey, DangerString(download_item->GetDangerType())); 266 json->SetString(kDangerKey, DangerString(download_item->GetDangerType()));
262 json->SetString(kStateKey, StateString(download_item->GetState())); 267 json->SetString(kStateKey, StateString(download_item->GetState()));
263 json->SetBoolean(kCanResumeKey, download_item->CanResume()); 268 json->SetBoolean(kCanResumeKey, download_item->CanResume());
264 json->SetBoolean(kPausedKey, download_item->IsPaused()); 269 json->SetBoolean(kPausedKey, download_item->IsPaused());
265 json->SetString(kMimeKey, download_item->GetMimeType()); 270 json->SetString(kMimeKey, download_item->GetMimeType());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; 374 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME;
370 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; 375 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER;
371 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; 376 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE;
372 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; 377 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME;
373 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; 378 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES;
374 filter_types[kTotalBytesGreaterKey] = 379 filter_types[kTotalBytesGreaterKey] =
375 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; 380 DownloadQuery::FILTER_TOTAL_BYTES_GREATER;
376 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; 381 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS;
377 filter_types[kUrlKey] = DownloadQuery::FILTER_URL; 382 filter_types[kUrlKey] = DownloadQuery::FILTER_URL;
378 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; 383 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX;
384 filter_types[kFinalUrlKey] = DownloadQuery::FILTER_FINAL_URL;
385 filter_types[kFinalUrlRegexKey] = DownloadQuery::FILTER_FINAL_URL_REGEX;
379 } 386 }
380 387
381 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; 388 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap;
382 389
383 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { 390 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) {
384 SortTypeMap& sorter_types = *sorter_types_ptr; 391 SortTypeMap& sorter_types = *sorter_types_ptr;
385 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; 392 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED;
386 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; 393 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER;
387 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; 394 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME;
388 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; 395 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS;
389 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; 396 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME;
390 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; 397 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME;
391 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; 398 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED;
392 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; 399 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME;
393 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; 400 sorter_types[kStateKey] = DownloadQuery::SORT_STATE;
394 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; 401 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES;
395 sorter_types[kUrlKey] = DownloadQuery::SORT_URL; 402 sorter_types[kUrlKey] = DownloadQuery::SORT_URL;
403 sorter_types[kFinalUrlKey] = DownloadQuery::SORT_FINAL_URL;
396 } 404 }
397 405
398 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { 406 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) {
399 return !download_item.IsTemporary(); 407 return !download_item.IsTemporary();
400 } 408 }
401 409
402 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to 410 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to
403 // the off-record DownloadManager if one exists and is requested via 411 // the off-record DownloadManager if one exists and is requested via
404 // |include_incognito|. This should work regardless of whether |profile| is 412 // |include_incognito|. This should work regardless of whether |profile| is
405 // original or incognito. 413 // original or incognito.
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 *message_out = message_in; 906 *message_out = message_in;
899 return true; 907 return true;
900 } 908 }
901 909
902 bool InvalidId(DownloadItem* valid_item, std::string* message_out) { 910 bool InvalidId(DownloadItem* valid_item, std::string* message_out) {
903 return Fault(!valid_item, errors::kInvalidId, message_out); 911 return Fault(!valid_item, errors::kInvalidId, message_out);
904 } 912 }
905 913
906 bool IsDownloadDeltaField(const std::string& field) { 914 bool IsDownloadDeltaField(const std::string& field) {
907 return ((field == kUrlKey) || 915 return ((field == kUrlKey) ||
916 (field == kFinalUrlKey) ||
908 (field == kFilenameKey) || 917 (field == kFilenameKey) ||
909 (field == kDangerKey) || 918 (field == kDangerKey) ||
910 (field == kMimeKey) || 919 (field == kMimeKey) ||
911 (field == kStartTimeKey) || 920 (field == kStartTimeKey) ||
912 (field == kEndTimeKey) || 921 (field == kEndTimeKey) ||
913 (field == kStateKey) || 922 (field == kStateKey) ||
914 (field == kCanResumeKey) || 923 (field == kCanResumeKey) ||
915 (field == kPausedKey) || 924 (field == kPausedKey) ||
916 (field == kErrorKey) || 925 (field == kErrorKey) ||
917 (field == kTotalBytesKey) || 926 (field == kTotalBytesKey) ||
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 return; 1912 return;
1904 base::Time now(base::Time::Now()); 1913 base::Time now(base::Time::Now());
1905 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); 1914 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT();
1906 if (delta <= kFileExistenceRateLimitSeconds) 1915 if (delta <= kFileExistenceRateLimitSeconds)
1907 return; 1916 return;
1908 last_checked_removal_ = now; 1917 last_checked_removal_ = now;
1909 manager->CheckForHistoryFilesRemoval(); 1918 manager->CheckForHistoryFilesRemoval();
1910 } 1919 }
1911 1920
1912 } // namespace extensions 1921 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698