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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 || download_item->GetTargetFilePath().empty()) { | 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 DCHECK(icon_extractor_.get()); | 870 DCHECK(icon_extractor_.get()); |
874 DCHECK(icon_size == 16 || icon_size == 32); | 871 DCHECK(icon_size == 16 || icon_size == 32); |
875 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( | 872 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( |
876 download_item->GetTargetFilePath(), | 873 download_item->GetTargetFilePath(), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 if (profile_->HasOffTheRecordProfile() && | 1003 if (profile_->HasOffTheRecordProfile() && |
1007 !profile_->IsOffTheRecord()) { | 1004 !profile_->IsOffTheRecord()) { |
1008 DispatchEventInternal( | 1005 DispatchEventInternal( |
1009 profile_->GetOffTheRecordProfile(), | 1006 profile_->GetOffTheRecordProfile(), |
1010 event_name, | 1007 event_name, |
1011 json_args, | 1008 json_args, |
1012 scoped_ptr<base::ListValue>(args->DeepCopy())); | 1009 scoped_ptr<base::ListValue>(args->DeepCopy())); |
1013 } | 1010 } |
1014 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); | 1011 DispatchEventInternal(profile_, event_name, json_args, args.Pass()); |
1015 } | 1012 } |
OLD | NEW |