| 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(); |
| 318 *incognito_manager = NULL; |
| 319 if (include_incognito && profile->HasOffTheRecordProfile()) |
| 320 *incognito_manager = DownloadServiceFactory::GetForProfile(profile-> |
| 321 GetOffTheRecordProfile())->GetDownloadManager(); |
| 322 } |
| 323 |
| 324 DownloadItem* GetActiveItemInternal( |
| 325 Profile* profile, |
| 326 bool include_incognito, |
| 327 int id) { |
| 328 DownloadManager* manager = NULL; |
| 329 DownloadManager* incognito_manager = NULL; |
| 330 GetManagers(profile, include_incognito, &manager, &incognito_manager); |
| 331 DownloadItem* download_item = manager->GetActiveDownloadItem(id); |
| 332 if (!download_item && incognito_manager) |
| 333 download_item = incognito_manager->GetActiveDownloadItem(id); |
| 334 return download_item; |
| 335 } |
| 336 |
| 310 } // namespace | 337 } // namespace |
| 311 | 338 |
| 312 bool DownloadsFunctionInterface::RunImplImpl( | 339 bool DownloadsFunctionInterface::RunImplImpl( |
| 313 DownloadsFunctionInterface* pimpl) { | 340 DownloadsFunctionInterface* pimpl) { |
| 314 CHECK(pimpl); | 341 CHECK(pimpl); |
| 315 if (!pimpl->ParseArgs()) return false; | 342 if (!pimpl->ParseArgs()) return false; |
| 316 UMA_HISTOGRAM_ENUMERATION( | 343 UMA_HISTOGRAM_ENUMERATION( |
| 317 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); | 344 "Download.ApiFunctions", pimpl->function(), DOWNLOADS_FUNCTION_LAST); |
| 318 return pimpl->RunInternal(); | 345 return pimpl->RunInternal(); |
| 319 } | 346 } |
| 320 | 347 |
| 321 SyncDownloadsFunction::SyncDownloadsFunction( | 348 SyncDownloadsFunction::SyncDownloadsFunction( |
| 322 DownloadsFunctionInterface::DownloadsFunctionName function) | 349 DownloadsFunctionInterface::DownloadsFunctionName function) |
| 323 : function_(function) { | 350 : function_(function) { |
| 324 } | 351 } |
| 325 | 352 |
| 326 SyncDownloadsFunction::~SyncDownloadsFunction() {} | 353 SyncDownloadsFunction::~SyncDownloadsFunction() {} |
| 327 | 354 |
| 328 bool SyncDownloadsFunction::RunImpl() { | 355 bool SyncDownloadsFunction::RunImpl() { |
| 329 return DownloadsFunctionInterface::RunImplImpl(this); | 356 return DownloadsFunctionInterface::RunImplImpl(this); |
| 330 } | 357 } |
| 331 | 358 |
| 332 DownloadsFunctionInterface::DownloadsFunctionName | 359 DownloadsFunctionInterface::DownloadsFunctionName |
| 333 SyncDownloadsFunction::function() const { | 360 SyncDownloadsFunction::function() const { |
| 334 return function_; | 361 return function_; |
| 335 } | 362 } |
| 336 | 363 |
| 364 DownloadItem* SyncDownloadsFunction::GetActiveItem(int download_id) { |
| 365 return GetActiveItemInternal(profile(), include_incognito(), download_id); |
| 366 } |
| 367 |
| 337 AsyncDownloadsFunction::AsyncDownloadsFunction( | 368 AsyncDownloadsFunction::AsyncDownloadsFunction( |
| 338 DownloadsFunctionInterface::DownloadsFunctionName function) | 369 DownloadsFunctionInterface::DownloadsFunctionName function) |
| 339 : function_(function) { | 370 : function_(function) { |
| 340 } | 371 } |
| 341 | 372 |
| 342 AsyncDownloadsFunction::~AsyncDownloadsFunction() {} | 373 AsyncDownloadsFunction::~AsyncDownloadsFunction() {} |
| 343 | 374 |
| 344 bool AsyncDownloadsFunction::RunImpl() { | 375 bool AsyncDownloadsFunction::RunImpl() { |
| 345 return DownloadsFunctionInterface::RunImplImpl(this); | 376 return DownloadsFunctionInterface::RunImplImpl(this); |
| 346 } | 377 } |
| 347 | 378 |
| 348 DownloadsFunctionInterface::DownloadsFunctionName | 379 DownloadsFunctionInterface::DownloadsFunctionName |
| 349 AsyncDownloadsFunction::function() const { | 380 AsyncDownloadsFunction::function() const { |
| 350 return function_; | 381 return function_; |
| 351 } | 382 } |
| 352 | 383 |
| 384 DownloadItem* AsyncDownloadsFunction::GetActiveItem(int download_id) { |
| 385 return GetActiveItemInternal(profile(), include_incognito(), download_id); |
| 386 } |
| 387 |
| 353 DownloadsDownloadFunction::DownloadsDownloadFunction() | 388 DownloadsDownloadFunction::DownloadsDownloadFunction() |
| 354 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_DOWNLOAD) { | 389 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_DOWNLOAD) { |
| 355 } | 390 } |
| 356 | 391 |
| 357 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} | 392 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} |
| 358 | 393 |
| 359 DownloadsDownloadFunction::IOData::IOData() | 394 DownloadsDownloadFunction::IOData::IOData() |
| 360 : save_as(false), | 395 : save_as(false), |
| 361 extra_headers(NULL), | 396 extra_headers(NULL), |
| 362 method("GET"), | 397 method("GET"), |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 if (sorter_type == sorter_types.Get().end()) { | 660 if (sorter_type == sorter_types.Get().end()) { |
| 626 error_ = download_extension_errors::kInvalidOrderByError; | 661 error_ = download_extension_errors::kInvalidOrderByError; |
| 627 return false; | 662 return false; |
| 628 } | 663 } |
| 629 query_->AddSorter(sorter_type->second, direction); | 664 query_->AddSorter(sorter_type->second, direction); |
| 630 } | 665 } |
| 631 return true; | 666 return true; |
| 632 } | 667 } |
| 633 | 668 |
| 634 bool DownloadsSearchFunction::RunInternal() { | 669 bool DownloadsSearchFunction::RunInternal() { |
| 670 DownloadManager* manager = NULL; |
| 671 DownloadManager* incognito_manager = NULL; |
| 672 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
| 635 DownloadQuery::DownloadVector all_items, cpp_results; | 673 DownloadQuery::DownloadVector all_items, cpp_results; |
| 636 DownloadManager* manager = DownloadServiceFactory::GetForProfile(profile()) | |
| 637 ->GetDownloadManager(); | |
| 638 if (has_get_id_) { | 674 if (has_get_id_) { |
| 639 DownloadItem* item = manager->GetDownloadItem(get_id_); | 675 DownloadItem* item = manager->GetDownloadItem(get_id_); |
| 640 if (item != NULL) | 676 if (!item && incognito_manager) |
| 677 item = incognito_manager->GetDownloadItem(get_id_); |
| 678 if (item) |
| 641 all_items.push_back(item); | 679 all_items.push_back(item); |
| 642 } else { | 680 } else { |
| 643 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items); | 681 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items); |
| 682 if (incognito_manager) |
| 683 incognito_manager->GetAllDownloads( |
| 684 FilePath(FILE_PATH_LITERAL("")), &all_items); |
| 644 } | 685 } |
| 645 query_->Search(all_items.begin(), all_items.end(), &cpp_results); | 686 query_->Search(all_items.begin(), all_items.end(), &cpp_results); |
| 646 base::ListValue* json_results = new base::ListValue(); | 687 base::ListValue* json_results = new base::ListValue(); |
| 647 for (DownloadManager::DownloadVector::const_iterator it = cpp_results.begin(); | 688 for (DownloadManager::DownloadVector::const_iterator it = cpp_results.begin(); |
| 648 it != cpp_results.end(); ++it) { | 689 it != cpp_results.end(); ++it) { |
| 649 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); | 690 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); |
| 650 json_results->Append(item.release()); | 691 json_results->Append(item.release()); |
| 651 } | 692 } |
| 652 result_.reset(json_results); | 693 result_.reset(json_results); |
| 653 return true; | 694 return true; |
| 654 } | 695 } |
| 655 | 696 |
| 656 DownloadsPauseFunction::DownloadsPauseFunction() | 697 DownloadsPauseFunction::DownloadsPauseFunction() |
| 657 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_PAUSE), | 698 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_PAUSE), |
| 658 download_id_(DownloadId::Invalid().local()) { | 699 download_id_(DownloadId::Invalid().local()) { |
| 659 } | 700 } |
| 660 | 701 |
| 661 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 702 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
| 662 | 703 |
| 663 bool DownloadsPauseFunction::ParseArgs() { | 704 bool DownloadsPauseFunction::ParseArgs() { |
| 664 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 705 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
| 665 return true; | 706 return true; |
| 666 } | 707 } |
| 667 | 708 |
| 668 bool DownloadsPauseFunction::RunInternal() { | 709 bool DownloadsPauseFunction::RunInternal() { |
| 669 DownloadManager* download_manager = | 710 DownloadItem* download_item = GetActiveItem(download_id_); |
| 670 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 711 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 | 712 // This could be due to an invalid download ID, or it could be due to the |
| 677 // download not being currently active. | 713 // download not being currently active. |
| 678 error_ = download_extension_errors::kInvalidOperationError; | 714 error_ = download_extension_errors::kInvalidOperationError; |
| 679 } else if (!download_item->IsPaused()) { | 715 } else if (!download_item->IsPaused()) { |
| 680 // If download_item->IsPaused() already then we treat it as a success. | 716 // If download_item->IsPaused() already then we treat it as a success. |
| 681 download_item->TogglePause(); | 717 download_item->TogglePause(); |
| 682 } | 718 } |
| 683 return error_.empty(); | 719 return error_.empty(); |
| 684 } | 720 } |
| 685 | 721 |
| 686 DownloadsResumeFunction::DownloadsResumeFunction() | 722 DownloadsResumeFunction::DownloadsResumeFunction() |
| 687 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_RESUME), | 723 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_RESUME), |
| 688 download_id_(DownloadId::Invalid().local()) { | 724 download_id_(DownloadId::Invalid().local()) { |
| 689 } | 725 } |
| 690 | 726 |
| 691 DownloadsResumeFunction::~DownloadsResumeFunction() {} | 727 DownloadsResumeFunction::~DownloadsResumeFunction() {} |
| 692 | 728 |
| 693 bool DownloadsResumeFunction::ParseArgs() { | 729 bool DownloadsResumeFunction::ParseArgs() { |
| 694 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 730 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
| 695 return true; | 731 return true; |
| 696 } | 732 } |
| 697 | 733 |
| 698 bool DownloadsResumeFunction::RunInternal() { | 734 bool DownloadsResumeFunction::RunInternal() { |
| 699 DownloadManager* download_manager = | 735 DownloadItem* download_item = GetActiveItem(download_id_); |
| 700 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 736 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 | 737 // This could be due to an invalid download ID, or it could be due to the |
| 707 // download not being currently active. | 738 // download not being currently active. |
| 708 error_ = download_extension_errors::kInvalidOperationError; | 739 error_ = download_extension_errors::kInvalidOperationError; |
| 709 } else if (download_item->IsPaused()) { | 740 } else if (download_item->IsPaused()) { |
| 710 // If !download_item->IsPaused() already, then we treat it as a success. | 741 // If !download_item->IsPaused() already, then we treat it as a success. |
| 711 download_item->TogglePause(); | 742 download_item->TogglePause(); |
| 712 } | 743 } |
| 713 return error_.empty(); | 744 return error_.empty(); |
| 714 } | 745 } |
| 715 | 746 |
| 716 DownloadsCancelFunction::DownloadsCancelFunction() | 747 DownloadsCancelFunction::DownloadsCancelFunction() |
| 717 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_CANCEL), | 748 : SyncDownloadsFunction(DOWNLOADS_FUNCTION_CANCEL), |
| 718 download_id_(DownloadId::Invalid().local()) { | 749 download_id_(DownloadId::Invalid().local()) { |
| 719 } | 750 } |
| 720 | 751 |
| 721 DownloadsCancelFunction::~DownloadsCancelFunction() {} | 752 DownloadsCancelFunction::~DownloadsCancelFunction() {} |
| 722 | 753 |
| 723 bool DownloadsCancelFunction::ParseArgs() { | 754 bool DownloadsCancelFunction::ParseArgs() { |
| 724 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); | 755 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &download_id_)); |
| 725 return true; | 756 return true; |
| 726 } | 757 } |
| 727 | 758 |
| 728 bool DownloadsCancelFunction::RunInternal() { | 759 bool DownloadsCancelFunction::RunInternal() { |
| 729 DownloadManager* download_manager = | 760 DownloadItem* download_item = GetActiveItem(download_id_); |
| 730 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 761 if (download_item != NULL) |
| 731 DownloadItem* download_item = | |
| 732 download_manager->GetActiveDownloadItem(download_id_); | |
| 733 | |
| 734 if (download_item) | |
| 735 download_item->Cancel(true); | 762 download_item->Cancel(true); |
| 736 // |download_item| can be NULL if the download ID was invalid or if the | 763 // |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 | 764 // download is not currently active. Either way, we don't consider it a |
| 738 // failure. | 765 // failure. |
| 739 return error_.empty(); | 766 return error_.empty(); |
| 740 } | 767 } |
| 741 | 768 |
| 742 DownloadsEraseFunction::DownloadsEraseFunction() | 769 DownloadsEraseFunction::DownloadsEraseFunction() |
| 743 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_ERASE) { | 770 : AsyncDownloadsFunction(DOWNLOADS_FUNCTION_ERASE) { |
| 744 } | 771 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 882 |
| 856 base::DictionaryValue* options = NULL; | 883 base::DictionaryValue* options = NULL; |
| 857 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); | 884 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options)); |
| 858 if (options->HasKey(kSizeKey)) { | 885 if (options->HasKey(kSizeKey)) { |
| 859 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kSizeKey, &icon_size_)); | 886 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kSizeKey, &icon_size_)); |
| 860 // We only support 16px and 32px icons. This is enforced in | 887 // We only support 16px and 32px icons. This is enforced in |
| 861 // experimental.downloads.json. | 888 // experimental.downloads.json. |
| 862 DCHECK(icon_size_ == 16 || icon_size_ == 32); | 889 DCHECK(icon_size_ == 16 || icon_size_ == 32); |
| 863 } | 890 } |
| 864 | 891 |
| 865 DownloadManager* download_manager = | 892 DownloadManager* manager = NULL; |
| 866 DownloadServiceFactory::GetForProfile(profile())->GetDownloadManager(); | 893 DownloadManager* incognito_manager = NULL; |
| 867 DownloadItem* download_item = download_manager->GetDownloadItem(dl_id); | 894 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
| 868 if (download_item == NULL) { | 895 DownloadItem* download_item = manager->GetDownloadItem(dl_id); |
| 896 if (!download_item && incognito_manager) |
| 897 download_item = incognito_manager->GetDownloadItem(dl_id); |
| 898 if (!download_item) { |
| 869 // The DownloadItem is is added to history when the path is determined. If | 899 // 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 | 900 // the download is not in history, then we don't have a path / final |
| 871 // filename and no icon. | 901 // filename and no icon. |
| 872 error_ = download_extension_errors::kInvalidOperationError; | 902 error_ = download_extension_errors::kInvalidOperationError; |
| 873 return false; | 903 return false; |
| 874 } | 904 } |
| 875 // In-progress downloads return the intermediate filename for GetFullPath() | 905 // In-progress downloads return the intermediate filename for GetFullPath() |
| 876 // which doesn't have the final extension. Therefore we won't be able to | 906 // 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. | 907 // derive a good file icon for it. So we use GetTargetFilePath() instead. |
| 878 path_ = download_item->GetTargetFilePath(); | 908 path_ = download_item->GetTargetFilePath(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 ListValue args; | 1104 ListValue args; |
| 1075 args.Append(arg); | 1105 args.Append(arg); |
| 1076 std::string json_args; | 1106 std::string json_args; |
| 1077 base::JSONWriter::Write(&args, &json_args); | 1107 base::JSONWriter::Write(&args, &json_args); |
| 1078 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 1108 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 1079 event_name, | 1109 event_name, |
| 1080 json_args, | 1110 json_args, |
| 1081 profile_, | 1111 profile_, |
| 1082 GURL()); | 1112 GURL()); |
| 1083 } | 1113 } |
| OLD | NEW |