| 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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 params->options.get(); | 853 params->options.get(); |
| 854 int icon_size = kDefaultIconSize; | 854 int icon_size = kDefaultIconSize; |
| 855 if (options && options->size.get()) | 855 if (options && options->size.get()) |
| 856 icon_size = *options->size.get(); | 856 icon_size = *options->size.get(); |
| 857 DownloadManager* manager = NULL; | 857 DownloadManager* manager = NULL; |
| 858 DownloadManager* incognito_manager = NULL; | 858 DownloadManager* incognito_manager = NULL; |
| 859 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); | 859 GetManagers(profile(), include_incognito(), &manager, &incognito_manager); |
| 860 DownloadItem* download_item = manager->GetDownload(params->download_id); | 860 DownloadItem* download_item = manager->GetDownload(params->download_id); |
| 861 if (!download_item && incognito_manager) | 861 if (!download_item && incognito_manager) |
| 862 download_item = incognito_manager->GetDownload(params->download_id); | 862 download_item = incognito_manager->GetDownload(params->download_id); |
| 863 if (!download_item) { | 863 if (!download_item || download_item->GetTargetFilePath().empty()) { |
| 864 // The DownloadItem is is added to history when the path is determined. If | |
| 865 // the download is not in history, then we don't have a path / final | |
| 866 // filename and no icon. | |
| 867 error_ = download_extension_errors::kInvalidOperationError; | 864 error_ = download_extension_errors::kInvalidOperationError; |
| 868 return false; | 865 return false; |
| 869 } | 866 } |
| 870 // In-progress downloads return the intermediate filename for GetFullPath() | 867 // In-progress downloads return the intermediate filename for GetFullPath() |
| 871 // which doesn't have the final extension. Therefore we won't be able to | 868 // which doesn't have the final extension. Therefore we won't be able to |
| 872 // derive a good file icon for it. So we use GetTargetFilePath() instead. | 869 // derive a good file icon for it. So we use GetTargetFilePath() instead. |
| 873 FilePath path = download_item->GetTargetFilePath(); | |
| 874 DCHECK(!path.empty()); | |
| 875 DCHECK(icon_extractor_.get()); | 870 DCHECK(icon_extractor_.get()); |
| 876 DCHECK(icon_size == 16 || icon_size == 32); | 871 DCHECK(icon_size == 16 || icon_size == 32); |
| 877 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( | 872 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( |
| 878 path, IconLoaderSizeFromPixelSize(icon_size), | 873 download_item->GetTargetFilePath(), |
| 874 IconLoaderSizeFromPixelSize(icon_size), |
| 879 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); | 875 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); |
| 880 return true; | 876 return true; |
| 881 } | 877 } |
| 882 | 878 |
| 883 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { | 879 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { |
| 884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 885 if (url.empty()) { | 881 if (url.empty()) { |
| 886 error_ = download_extension_errors::kIconNotFoundError; | 882 error_ = download_extension_errors::kIconNotFoundError; |
| 887 } else { | 883 } else { |
| 888 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); | 884 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 if (profile_->HasOffTheRecordProfile() && | 1003 if (profile_->HasOffTheRecordProfile() && |
| 1008 !profile_->IsOffTheRecord()) { | 1004 !profile_->IsOffTheRecord()) { |
| 1009 DispatchEventInternal( | 1005 DispatchEventInternal( |
| 1010 profile_->GetOffTheRecordProfile(), | 1006 profile_->GetOffTheRecordProfile(), |
| 1011 event_name, | 1007 event_name, |
| 1012 json_args, | 1008 json_args, |
| 1013 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1009 scoped_ptr<base::ListValue>(args->DeepCopy())); |
| 1014 } | 1010 } |
| 1015 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1011 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
| 1016 } | 1012 } |
| OLD | NEW |