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/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 if (profile->HasOffTheRecordProfile() && | 330 if (profile->HasOffTheRecordProfile() && |
331 (include_incognito || | 331 (include_incognito || |
332 profile->IsOffTheRecord())) { | 332 profile->IsOffTheRecord())) { |
333 *incognito_manager = BrowserContext::GetDownloadManager( | 333 *incognito_manager = BrowserContext::GetDownloadManager( |
334 profile->GetOffTheRecordProfile()); | 334 profile->GetOffTheRecordProfile()); |
335 } else { | 335 } else { |
336 *incognito_manager = NULL; | 336 *incognito_manager = NULL; |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
340 DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) { | 340 DownloadItem* GetDownload(Profile* profile, bool include_incognito, int id) { |
341 DownloadManager* manager = NULL; | 341 DownloadManager* manager = NULL; |
342 DownloadManager* incognito_manager = NULL; | 342 DownloadManager* incognito_manager = NULL; |
343 GetManagers(profile, include_incognito, &manager, &incognito_manager); | 343 GetManagers(profile, include_incognito, &manager, &incognito_manager); |
344 DownloadItem* download_item = manager->GetDownload(id); | 344 DownloadItem* download_item = manager->GetDownload(id); |
345 if (!download_item && incognito_manager) | 345 if (!download_item && incognito_manager) |
346 download_item = incognito_manager->GetDownload(id); | 346 download_item = incognito_manager->GetDownload(id); |
347 return download_item; | |
348 } | |
349 | |
350 DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) { | |
Randy Smith (Not in Mondays)
2012/12/05 14:17:42
Maybe regularize the names of these two functions?
benjhayden
2012/12/05 18:41:02
Is GetDownloadIfInProgress ok?
Randy Smith (Not in Mondays)
2012/12/05 19:12:05
Sure.
| |
351 DownloadItem* download_item = GetDownload(profile, include_incognito, id); | |
347 return download_item && download_item->IsInProgress() ? download_item : NULL; | 352 return download_item && download_item->IsInProgress() ? download_item : NULL; |
348 } | 353 } |
349 | 354 |
350 enum DownloadsFunctionName { | 355 enum DownloadsFunctionName { |
351 DOWNLOADS_FUNCTION_DOWNLOAD = 0, | 356 DOWNLOADS_FUNCTION_DOWNLOAD = 0, |
352 DOWNLOADS_FUNCTION_SEARCH = 1, | 357 DOWNLOADS_FUNCTION_SEARCH = 1, |
353 DOWNLOADS_FUNCTION_PAUSE = 2, | 358 DOWNLOADS_FUNCTION_PAUSE = 2, |
354 DOWNLOADS_FUNCTION_RESUME = 3, | 359 DOWNLOADS_FUNCTION_RESUME = 3, |
355 DOWNLOADS_FUNCTION_CANCEL = 4, | 360 DOWNLOADS_FUNCTION_CANCEL = 4, |
356 DOWNLOADS_FUNCTION_ERASE = 5, | 361 DOWNLOADS_FUNCTION_ERASE = 5, |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 return error_.empty(); | 800 return error_.empty(); |
796 } | 801 } |
797 | 802 |
798 DownloadsOpenFunction::DownloadsOpenFunction() {} | 803 DownloadsOpenFunction::DownloadsOpenFunction() {} |
799 DownloadsOpenFunction::~DownloadsOpenFunction() {} | 804 DownloadsOpenFunction::~DownloadsOpenFunction() {} |
800 | 805 |
801 bool DownloadsOpenFunction::RunImpl() { | 806 bool DownloadsOpenFunction::RunImpl() { |
802 scoped_ptr<extensions::api::downloads::Open::Params> params( | 807 scoped_ptr<extensions::api::downloads::Open::Params> params( |
803 extensions::api::downloads::Open::Params::Create(*args_)); | 808 extensions::api::downloads::Open::Params::Create(*args_)); |
804 EXTENSION_FUNCTION_VALIDATE(params.get()); | 809 EXTENSION_FUNCTION_VALIDATE(params.get()); |
805 error_ = download_extension_errors::kNotImplementedError; | 810 DownloadItem* download_item = GetDownload( |
806 if (error_.empty()) | 811 profile(), include_incognito(), params->download_id); |
807 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); | 812 if (!download_item || !download_item->IsComplete()) { |
Randy Smith (Not in Mondays)
2012/12/05 14:17:42
I think I agree with the behavioral choice to not
benjhayden
2012/12/05 18:41:02
Decided to use SetOpenWhenComplete. PTAL.
Randy Smith (Not in Mondays)
2012/12/05 19:12:05
*wince* I guess that's fine. I'm uncomfortable w
benjhayden
2012/12/05 19:29:48
Actually, the primary reason that I'd like for ope
| |
808 return error_.empty(); | 813 error_ = download_extension_errors::kInvalidOperationError; |
814 return false; | |
815 } | |
816 download_item->OpenDownload(); | |
817 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); | |
818 return true; | |
809 } | 819 } |
810 | 820 |
811 DownloadsDragFunction::DownloadsDragFunction() {} | 821 DownloadsDragFunction::DownloadsDragFunction() {} |
812 DownloadsDragFunction::~DownloadsDragFunction() {} | 822 DownloadsDragFunction::~DownloadsDragFunction() {} |
813 | 823 |
814 bool DownloadsDragFunction::RunImpl() { | 824 bool DownloadsDragFunction::RunImpl() { |
815 scoped_ptr<extensions::api::downloads::Drag::Params> params( | 825 scoped_ptr<extensions::api::downloads::Drag::Params> params( |
816 extensions::api::downloads::Drag::Params::Create(*args_)); | 826 extensions::api::downloads::Drag::Params::Create(*args_)); |
817 EXTENSION_FUNCTION_VALIDATE(params.get()); | 827 EXTENSION_FUNCTION_VALIDATE(params.get()); |
818 error_ = download_extension_errors::kNotImplementedError; | 828 error_ = download_extension_errors::kNotImplementedError; |
(...skipping 16 matching lines...) Expand all Loading... | |
835 | 845 |
836 bool DownloadsGetFileIconFunction::RunImpl() { | 846 bool DownloadsGetFileIconFunction::RunImpl() { |
837 scoped_ptr<extensions::api::downloads::GetFileIcon::Params> params( | 847 scoped_ptr<extensions::api::downloads::GetFileIcon::Params> params( |
838 extensions::api::downloads::GetFileIcon::Params::Create(*args_)); | 848 extensions::api::downloads::GetFileIcon::Params::Create(*args_)); |
839 EXTENSION_FUNCTION_VALIDATE(params.get()); | 849 EXTENSION_FUNCTION_VALIDATE(params.get()); |
840 const extensions::api::downloads::GetFileIconOptions* options = | 850 const extensions::api::downloads::GetFileIconOptions* options = |
841 params->options.get(); | 851 params->options.get(); |
842 int icon_size = kDefaultIconSize; | 852 int icon_size = kDefaultIconSize; |
843 if (options && options->size.get()) | 853 if (options && options->size.get()) |
844 icon_size = *options->size.get(); | 854 icon_size = *options->size.get(); |
845 DownloadManager* manager = NULL; | 855 DownloadItem* download_item = GetDownload( |
846 DownloadManager* incognito_manager = NULL; | 856 profile(), include_incognito(), params->download_id); |
847 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); | |
848 DownloadItem* download_item = manager->GetDownload(params->download_id); | |
849 if (!download_item && incognito_manager) | |
850 download_item = incognito_manager->GetDownload(params->download_id); | |
851 if (!download_item || download_item->GetTargetFilePath().empty()) { | 857 if (!download_item || download_item->GetTargetFilePath().empty()) { |
852 error_ = download_extension_errors::kInvalidOperationError; | 858 error_ = download_extension_errors::kInvalidOperationError; |
853 return false; | 859 return false; |
854 } | 860 } |
855 // In-progress downloads return the intermediate filename for GetFullPath() | 861 // In-progress downloads return the intermediate filename for GetFullPath() |
856 // which doesn't have the final extension. Therefore we won't be able to | 862 // which doesn't have the final extension. Therefore we won't be able to |
857 // derive a good file icon for it. So we use GetTargetFilePath() instead. | 863 // derive a good file icon for it. So we use GetTargetFilePath() instead. |
858 DCHECK(icon_extractor_.get()); | 864 DCHECK(icon_extractor_.get()); |
859 DCHECK(icon_size == 16 || icon_size == 32); | 865 DCHECK(icon_size == 16 || icon_size == 32); |
860 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( | 866 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 if (profile_->HasOffTheRecordProfile() && | 997 if (profile_->HasOffTheRecordProfile() && |
992 !profile_->IsOffTheRecord()) { | 998 !profile_->IsOffTheRecord()) { |
993 DispatchEventInternal( | 999 DispatchEventInternal( |
994 profile_->GetOffTheRecordProfile(), | 1000 profile_->GetOffTheRecordProfile(), |
995 event_name, | 1001 event_name, |
996 json_args, | 1002 json_args, |
997 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1003 scoped_ptr<base::ListValue>(args->DeepCopy())); |
998 } | 1004 } |
999 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1005 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
1000 } | 1006 } |
OLD | NEW |