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/browser/download/download_extension_api.h" | 5 #include "chrome/browser/download/download_extension_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <set> | 10 #include <set> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 const char kEndTimeKey[] = "endTime"; | 86 const char kEndTimeKey[] = "endTime"; |
87 const char kErrorKey[] = "error"; | 87 const char kErrorKey[] = "error"; |
88 const char kFileSizeKey[] = "fileSize"; | 88 const char kFileSizeKey[] = "fileSize"; |
89 const char kFilenameKey[] = "filename"; | 89 const char kFilenameKey[] = "filename"; |
90 const char kFilenameRegexKey[] = "filenameRegex"; | 90 const char kFilenameRegexKey[] = "filenameRegex"; |
91 const char kHeaderNameKey[] = "name"; | 91 const char kHeaderNameKey[] = "name"; |
92 const char kHeaderValueKey[] = "value"; | 92 const char kHeaderValueKey[] = "value"; |
93 const char kHeaderBinaryValueKey[] = "binaryValue"; | 93 const char kHeaderBinaryValueKey[] = "binaryValue"; |
94 const char kHeadersKey[] = "headers"; | 94 const char kHeadersKey[] = "headers"; |
95 const char kIdKey[] = "id"; | 95 const char kIdKey[] = "id"; |
96 const char kIncognito[] = "incognito"; | |
96 const char kLimitKey[] = "limit"; | 97 const char kLimitKey[] = "limit"; |
97 const char kMethodKey[] = "method"; | 98 const char kMethodKey[] = "method"; |
98 const char kMimeKey[] = "mime"; | 99 const char kMimeKey[] = "mime"; |
99 const char kOrderByKey[] = "orderBy"; | 100 const char kOrderByKey[] = "orderBy"; |
100 const char kPausedKey[] = "paused"; | 101 const char kPausedKey[] = "paused"; |
101 const char kQueryKey[] = "query"; | 102 const char kQueryKey[] = "query"; |
102 const char kSaveAsKey[] = "saveAs"; | 103 const char kSaveAsKey[] = "saveAs"; |
103 const char kSizeKey[] = "size"; | 104 const char kSizeKey[] = "size"; |
104 const char kStartTimeKey[] = "startTime"; | 105 const char kStartTimeKey[] = "startTime"; |
105 const char kStartedAfterKey[] = "startedAfter"; | 106 const char kStartedAfterKey[] = "startedAfter"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) | 190 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
190 json->SetBoolean(kDangerAcceptedKey, | 191 json->SetBoolean(kDangerAcceptedKey, |
191 item->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED); | 192 item->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED); |
192 json->SetString(kStateKey, StateString(item->GetState())); | 193 json->SetString(kStateKey, StateString(item->GetState())); |
193 json->SetBoolean(kPausedKey, item->IsPaused()); | 194 json->SetBoolean(kPausedKey, item->IsPaused()); |
194 json->SetString(kMimeKey, item->GetMimeType()); | 195 json->SetString(kMimeKey, item->GetMimeType()); |
195 json->SetInteger(kStartTimeKey, | 196 json->SetInteger(kStartTimeKey, |
196 (item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds()); | 197 (item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds()); |
197 json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes()); | 198 json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes()); |
198 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); | 199 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); |
200 json->SetBoolean(kIncognito, item->IsOtr()); | |
199 if (item->GetState() == DownloadItem::INTERRUPTED) { | 201 if (item->GetState() == DownloadItem::INTERRUPTED) { |
200 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); | 202 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); |
201 } else if (item->GetState() == DownloadItem::CANCELLED) { | 203 } else if (item->GetState() == DownloadItem::CANCELLED) { |
202 json->SetInteger(kErrorKey, static_cast<int>( | 204 json->SetInteger(kErrorKey, static_cast<int>( |
203 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); | 205 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); |
204 } | 206 } |
205 // TODO(benjhayden): Implement endTime and fileSize. | 207 // TODO(benjhayden): Implement endTime and fileSize. |
206 // json->SetInteger(kEndTimeKey, -1); | 208 // json->SetInteger(kEndTimeKey, -1); |
207 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); | 209 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); |
208 return scoped_ptr<base::DictionaryValue>(json); | 210 return scoped_ptr<base::DictionaryValue>(json); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; | 302 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; |
301 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; | 303 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; |
302 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; | 304 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; |
303 sorter_types[kUrlKey] = DownloadQuery::SORT_URL; | 305 sorter_types[kUrlKey] = DownloadQuery::SORT_URL; |
304 } | 306 } |
305 | 307 |
306 bool IsNotTemporaryDownloadFilter(const DownloadItem& item) { | 308 bool IsNotTemporaryDownloadFilter(const DownloadItem& item) { |
307 return !item.IsTemporary(); | 309 return !item.IsTemporary(); |
308 } | 310 } |
309 | 311 |
312 void GetManagers( | |
313 Profile* profile, | |
314 bool include_incognito, | |
315 DownloadManager** manager, DownloadManager** incognito_manager) { | |
316 *manager = DownloadServiceFactory::GetForProfile(profile)-> | |
317 GetDownloadManager(); | |
Matt Perry
2012/05/15 21:46:58
indent += 2
benjhayden
2012/05/16 15:01:27
Done.
| |
318 *incognito_manager = (include_incognito && | |
319 profile->HasOffTheRecordProfile()) ? | |
320 DownloadServiceFactory::GetForProfile(profile-> | |
321 GetOffTheRecordProfile())->GetDownloadManager() : | |
322 NULL; | |
323 } | |
324 | |
325 DownloadItem* GetActiveItemInternal( | |
326 Profile* profile, | |
327 bool include_incognito, | |
328 int id) { | |
329 DownloadManager* manager = NULL; | |
330 DownloadManager* incognito_manager = NULL; | |
331 GetManagers(profile, include_incognito, &manager, &incognito_manager); | |
332 DownloadItem* download_item = manager->GetActiveDownloadItem(id); | |
333 if (!download_item && incognito_manager) | |
334 download_item = incognito_manager->GetActiveDownloadItem(id); | |
335 return download_item; | |
336 } | |
337 | |
310 } // namespace | 338 } // namespace |
311 | 339 |
312 bool DownloadsFunctionInterface::RunImplImpl( | 340 bool DownloadsFunctionInterface::RunImplImpl( |
313 DownloadsFunctionInterface* pimpl) { | 341 DownloadsFunctionInterface* pimpl) { |
314 CHECK(pimpl); | 342 CHECK(pimpl); |
315 if (!pimpl->ParseArgs()) return false; | 343 if (!pimpl->ParseArgs()) return false; |
316 UMA_HISTOGRAM_ENUMERATION( | 344 UMA_HISTOGRAM_ENUMERATION( |
317 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); | 345 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); |
318 return pimpl->RunInternal(); | 346 return pimpl->RunInternal(); |
319 } | 347 } |
320 | 348 |
321 SyncDownloadsFunction::SyncDownloadsFunction( | 349 SyncDownloadsFunction::SyncDownloadsFunction( |
322 DownloadsFunctionInterface::DownloadsFunctionName function) | 350 DownloadsFunctionInterface::DownloadsFunctionName function) |
323 : function_(function) { | 351 : function_(function) { |
324 } | 352 } |
325 | 353 |
326 SyncDownloadsFunction::~SyncDownloadsFunction() {} | 354 SyncDownloadsFunction::~SyncDownloadsFunction() {} |
327 | 355 |
328 bool SyncDownloadsFunction::RunImpl() { | 356 bool SyncDownloadsFunction::RunImpl() { |
329 return DownloadsFunctionInterface::RunImplImpl(this); | 357 return DownloadsFunctionInterface::RunImplImpl(this); |
330 } | 358 } |
331 | 359 |
332 DownloadsFunctionInterface::DownloadsFunctionName | 360 DownloadsFunctionInterface::DownloadsFunctionName |
333 SyncDownloadsFunction::function() const { | 361 SyncDownloadsFunction::function() const { |
334 return function_; | 362 return function_; |
335 } | 363 } |
336 | 364 |
365 DownloadItem* SyncDownloadsFunction::GetActiveItem(int download_id) { | |
366 return GetActiveItemInternal( | |
Matt Perry
2012/05/15 21:46:58
This can probably fit on 1 line now.
benjhayden
2012/05/16 15:01:27
Done.
| |
367 profile(), | |
368 include_incognito(), | |
369 download_id); | |
370 } | |
371 | |
337 AsyncDownloadsFunction::AsyncDownloadsFunction( | 372 AsyncDownloadsFunction::AsyncDownloadsFunction( |
338 DownloadsFunctionInterface::DownloadsFunctionName function) | 373 DownloadsFunctionInterface::DownloadsFunctionName function) |
339 : function_(function) { | 374 : function_(function) { |
340 } | 375 } |
341 | 376 |
342 AsyncDownloadsFunction::~AsyncDownloadsFunction() {} | 377 AsyncDownloadsFunction::~AsyncDownloadsFunction() {} |
343 | 378 |
344 bool AsyncDownloadsFunction::RunImpl() { | 379 bool AsyncDownloadsFunction::RunImpl() { |
345 return DownloadsFunctionInterface::RunImplImpl(this); | 380 return DownloadsFunctionInterface::RunImplImpl(this); |
346 } | 381 } |
347 | 382 |
348 DownloadsFunctionInterface::DownloadsFunctionName | 383 DownloadsFunctionInterface::DownloadsFunctionName |
349 AsyncDownloadsFunction::function() const { | 384 AsyncDownloadsFunction::function() const { |
350 return function_; | 385 return function_; |
351 } | 386 } |
352 | 387 |
388 DownloadItem* AsyncDownloadsFunction::GetActiveItem(int download_id) { | |
389 return GetActiveItemInternal( | |
390 profile(), | |
391 include_incognito(), | |
392 download_id); | |
393 } | |
394 | |
353 DownloadsDownloadFunction::DownloadsDownloadFunction() | 395 DownloadsDownloadFunction::DownloadsDownloadFunction() |
354 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_DOWNLOAD) { | 396 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_DOWNLOAD) { |
355 } | 397 } |
356 | 398 |
357 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} | 399 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} |
358 | 400 |
359 DownloadsDownloadFunction::IOData::IOData() | 401 DownloadsDownloadFunction::IOData::IOData() |
360 : save_as(false), | 402 : save_as(false), |
361 extra_headers(NULL), | 403 extra_headers(NULL), |
362 method("GET"), | 404 method("GET"), |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 if (sorter_type == sorter_types.Get().end()) { | 667 if (sorter_type == sorter_types.Get().end()) { |
626 error_ = download_extension_errors::kInvalidOrderByError; | 668 error_ = download_extension_errors::kInvalidOrderByError; |
627 return false; | 669 return false; |
628 } | 670 } |
629 query_->AddSorter(sorter_type->second, direction); | 671 query_->AddSorter(sorter_type->second, direction); |
630 } | 672 } |
631 return true; | 673 return true; |
632 } | 674 } |
633 | 675 |
634 bool DownloadsSearchFunction::RunInternal() { | 676 bool DownloadsSearchFunction::RunInternal() { |
677 DownloadManager* manager = NULL; | |
678 DownloadManager* incognito_manager = NULL; | |
679 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); | |
635 DownloadQuery::DownloadVector all_items, cpp_results; | 680 DownloadQuery::DownloadVector all_items, cpp_results; |
636 DownloadManager* manager = DownloadServiceFactory::GetForProfile(profile()) | |
637 ->GetDownloadManager(); | |
638 if (has_get_id_) { | 681 if (has_get_id_) { |
639 DownloadItem* item = manager->GetDownloadItem(get_id_); | 682 DownloadItem* item = manager->GetDownloadItem(get_id_); |
640 if (item != NULL) | 683 if (!item && incognito_manager) |
684 item = incognito_manager->GetDownloadItem(get_id_); | |
685 if (item) | |
641 all_items.push_back(item); | 686 all_items.push_back(item); |
642 } else { | 687 } else { |
643 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items); | 688 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items); |
689 if (incognito_manager) | |
690 incognito_manager->GetAllDownloads( | |
691 FilePath(FILE_PATH_LITERAL("")), &all_items); | |
644 } | 692 } |
645 query_->Search(all_items.begin(), all_items.end(), &cpp_results); | 693 query_->Search(all_items.begin(), all_items.end(), &cpp_results); |
646 base::ListValue* json_results = new base::ListValue(); | 694 base::ListValue* json_results = new base::ListValue(); |
647 for (DownloadManager::DownloadVector::const_iterator it = cpp_results.begin(); | 695 for (DownloadManager::DownloadVector::const_iterator it = cpp_results.begin(); |
648 it != cpp_results.end(); ++it) { | 696 it != cpp_results.end(); ++it) { |
649 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); | 697 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); |
650 json_results->Append(item.release()); | 698 json_results->Append(item.release()); |
651 } | 699 } |
652 result_.reset(json_results); | 700 result_.reset(json_results); |
653 return true; | 701 return true; |
654 } | 702 } |
655 | 703 |
656 DownloadsPauseFunction::DownloadsPauseFunction() | 704 DownloadsPauseFunction::DownloadsPauseFunction() |
657 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_PAUSE), | 705 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_PAUSE), |
658 download_id_(DownloadId::Invalid().local()) { | 706 download_id_(DownloadId::Invalid().local()) { |
659 } | 707 } |
660 | 708 |
661 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 709 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
662 | 710 |
663 bool DownloadsPauseFunction::ParseArgs() { | 711 bool DownloadsPauseFunction::ParseArgs() { |
664 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 712 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
665 return true; | 713 return true; |
666 } | 714 } |
667 | 715 |
668 bool DownloadsPauseFunction::RunInternal() { | 716 bool DownloadsPauseFunction::RunInternal() { |
669 DownloadManager* download_manager = | 717 DownloadItem* download_item = GetActiveItem(download_id_); |
670 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 718 if ((download_item == NULL) || !download_item->IsInProgress()) { |
671 DownloadItem* download_item = | |
672 download_manager->GetActiveDownloadItem(download_id_); | |
673 DCHECK(!download_item || download_item->IsInProgress()); | |
674 | |
675 if (!download_item) { | |
676 // This could be due to an invalid download ID, or it could be due to the | 719 // This could be due to an invalid download ID, or it could be due to the |
677 // download not being currently active. | 720 // download not being currently active. |
678 error_ = download_extension_errors::kInvalidOperationError; | 721 error_ = download_extension_errors::kInvalidOperationError; |
679 } else if (!download_item->IsPaused()) { | 722 } else if (!download_item->IsPaused()) { |
680 // If download_item->IsPaused() already then we treat it as a success. | 723 // If download_item->IsPaused() already then we treat it as a success. |
681 download_item->TogglePause(); | 724 download_item->TogglePause(); |
682 } | 725 } |
683 return error_.empty(); | 726 return error_.empty(); |
684 } | 727 } |
685 | 728 |
686 DownloadsResumeFunction::DownloadsResumeFunction() | 729 DownloadsResumeFunction::DownloadsResumeFunction() |
687 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_RESUME), | 730 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_RESUME), |
688 download_id_(DownloadId::Invalid().local()) { | 731 download_id_(DownloadId::Invalid().local()) { |
689 } | 732 } |
690 | 733 |
691 DownloadsResumeFunction::~DownloadsResumeFunction() {} | 734 DownloadsResumeFunction::~DownloadsResumeFunction() {} |
692 | 735 |
693 bool DownloadsResumeFunction::ParseArgs() { | 736 bool DownloadsResumeFunction::ParseArgs() { |
694 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 737 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
695 return true; | 738 return true; |
696 } | 739 } |
697 | 740 |
698 bool DownloadsResumeFunction::RunInternal() { | 741 bool DownloadsResumeFunction::RunInternal() { |
699 DownloadManager* download_manager = | 742 DownloadItem* download_item = GetActiveItem(download_id_); |
700 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 743 if (download_item == NULL) { |
701 DownloadItem* download_item = | |
702 download_manager->GetActiveDownloadItem(download_id_); | |
703 DCHECK(!download_item || download_item->IsInProgress()); | |
704 | |
705 if (!download_item) { | |
706 // This could be due to an invalid download ID, or it could be due to the | 744 // This could be due to an invalid download ID, or it could be due to the |
707 // download not being currently active. | 745 // download not being currently active. |
708 error_ = download_extension_errors::kInvalidOperationError; | 746 error_ = download_extension_errors::kInvalidOperationError; |
709 } else if (download_item->IsPaused()) { | 747 } else if (download_item->IsPaused()) { |
710 // If !download_item->IsPaused() already, then we treat it as a success. | 748 // If !download_item->IsPaused() already, then we treat it as a success. |
711 download_item->TogglePause(); | 749 download_item->TogglePause(); |
712 } | 750 } |
713 return error_.empty(); | 751 return error_.empty(); |
714 } | 752 } |
715 | 753 |
716 DownloadsCancelFunction::DownloadsCancelFunction() | 754 DownloadsCancelFunction::DownloadsCancelFunction() |
717 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_CANCEL), | 755 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_CANCEL), |
718 download_id_(DownloadId::Invalid().local()) { | 756 download_id_(DownloadId::Invalid().local()) { |
719 } | 757 } |
720 | 758 |
721 DownloadsCancelFunction::~DownloadsCancelFunction() {} | 759 DownloadsCancelFunction::~DownloadsCancelFunction() {} |
722 | 760 |
723 bool DownloadsCancelFunction::ParseArgs() { | 761 bool DownloadsCancelFunction::ParseArgs() { |
724 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 762 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
725 return true; | 763 return true; |
726 } | 764 } |
727 | 765 |
728 bool DownloadsCancelFunction::RunInternal() { | 766 bool DownloadsCancelFunction::RunInternal() { |
729 DownloadManager* download_manager = | 767 DownloadItem* download_item = GetActiveItem(download_id_); |
730 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 768 if (download_item != NULL) |
731 DownloadItem* download_item = | |
732 download_manager->GetActiveDownloadItem(download_id_); | |
733 | |
734 if (download_item) | |
735 download_item->Cancel(true); | 769 download_item->Cancel(true); |
736 // |download_item| can be NULL if the download ID was invalid or if the | 770 // |download_item| can be NULL if the download ID was invalid or if the |
737 // download is not currently active. Either way, we don't consider it a | 771 // download is not currently active. Either way, we don't consider it a |
738 // failure. | 772 // failure. |
739 return error_.empty(); | 773 return error_.empty(); |
740 } | 774 } |
741 | 775 |
742 DownloadsEraseFunction::DownloadsEraseFunction() | 776 DownloadsEraseFunction::DownloadsEraseFunction() |
743 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_ERASE) { | 777 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_ERASE) { |
744 } | 778 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 | 889 |
856 base::DictionaryValue* options = NULL; | 890 base::DictionaryValue* options = NULL; |
857 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); | 891 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); |
858 if (options->HasKey(kSizeKey)) { | 892 if (options->HasKey(kSizeKey)) { |
859 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kSizeKey, &icon_size_)); | 893 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kSizeKey, &icon_size_)); |
860 // We only support 16px and 32px icons. This is enforced in | 894 // We only support 16px and 32px icons. This is enforced in |
861 // experimental.downloads.json. | 895 // experimental.downloads.json. |
862 DCHECK(icon_size_ == 16 || icon_size_ == 32); | 896 DCHECK(icon_size_ == 16 || icon_size_ == 32); |
863 } | 897 } |
864 | 898 |
865 DownloadManager* download_manager = | 899 DownloadManager* manager = NULL; |
866 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 900 DownloadManager* incognito_manager = NULL; |
867 DownloadItem* download_item = download_manager->GetDownloadItem(dl_id); | 901 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
868 if (download_item == NULL) { | 902 DownloadItem* download_item = manager->GetDownloadItem(dl_id); |
903 if (!download_item && incognito_manager) | |
904 download_item = incognito_manager->GetDownloadItem(dl_id); | |
905 if (!download_item) { | |
869 // The DownloadItem is is added to history when the path is determined. If | 906 // The DownloadItem is is added to history when the path is determined. If |
870 // the download is not in history, then we don't have a path / final | 907 // the download is not in history, then we don't have a path / final |
871 // filename and no icon. | 908 // filename and no icon. |
872 error_ = download_extension_errors::kInvalidOperationError; | 909 error_ = download_extension_errors::kInvalidOperationError; |
873 return false; | 910 return false; |
874 } | 911 } |
875 // In-progress downloads return the intermediate filename for GetFullPath() | 912 // In-progress downloads return the intermediate filename for GetFullPath() |
876 // which doesn't have the final extension. Therefore we won't be able to | 913 // which doesn't have the final extension. Therefore we won't be able to |
877 // derive a good file icon for it. So we use GetTargetFilePath() instead. | 914 // derive a good file icon for it. So we use GetTargetFilePath() instead. |
878 path_ = download_item->GetTargetFilePath(); | 915 path_ = download_item->GetTargetFilePath(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 ListValue args; | 1111 ListValue args; |
1075 args.Append(arg); | 1112 args.Append(arg); |
1076 std::string json_args; | 1113 std::string json_args; |
1077 base::JSONWriter::Write(&args, &json_args); | 1114 base::JSONWriter::Write(&args, &json_args); |
1078 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 1115 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
1079 event_name, | 1116 event_name, |
1080 json_args, | 1117 json_args, |
1081 profile_, | 1118 profile_, |
1082 GURL()); | 1119 GURL()); |
1083 } | 1120 } |
OLD | NEW |