| 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 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1072 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 1073 error_ = content::DownloadInterruptReasonToString(interrupt_reason); | 1073 error_ = content::DownloadInterruptReasonToString(interrupt_reason); |
| 1074 } | 1074 } |
| 1075 SendResponse(error_.empty()); | 1075 SendResponse(error_.empty()); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 DownloadsSearchFunction::DownloadsSearchFunction() {} | 1078 DownloadsSearchFunction::DownloadsSearchFunction() {} |
| 1079 | 1079 |
| 1080 DownloadsSearchFunction::~DownloadsSearchFunction() {} | 1080 DownloadsSearchFunction::~DownloadsSearchFunction() {} |
| 1081 | 1081 |
| 1082 bool DownloadsSearchFunction::RunImpl() { | 1082 bool DownloadsSearchFunction::RunSync() { |
| 1083 scoped_ptr<downloads::Search::Params> params( | 1083 scoped_ptr<downloads::Search::Params> params( |
| 1084 downloads::Search::Params::Create(*args_)); | 1084 downloads::Search::Params::Create(*args_)); |
| 1085 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1085 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1086 DownloadManager* manager = NULL; | 1086 DownloadManager* manager = NULL; |
| 1087 DownloadManager* incognito_manager = NULL; | 1087 DownloadManager* incognito_manager = NULL; |
| 1088 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1088 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
| 1089 ManagerDestructionObserver::CheckForHistoryFilesRemoval(manager); | 1089 ManagerDestructionObserver::CheckForHistoryFilesRemoval(manager); |
| 1090 ManagerDestructionObserver::CheckForHistoryFilesRemoval(incognito_manager); | 1090 ManagerDestructionObserver::CheckForHistoryFilesRemoval(incognito_manager); |
| 1091 DownloadQuery::DownloadVector results; | 1091 DownloadQuery::DownloadVector results; |
| 1092 RunDownloadQuery(params->query, | 1092 RunDownloadQuery(params->query, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1112 } | 1112 } |
| 1113 SetResult(json_results); | 1113 SetResult(json_results); |
| 1114 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); | 1114 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); |
| 1115 return true; | 1115 return true; |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 DownloadsPauseFunction::DownloadsPauseFunction() {} | 1118 DownloadsPauseFunction::DownloadsPauseFunction() {} |
| 1119 | 1119 |
| 1120 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 1120 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
| 1121 | 1121 |
| 1122 bool DownloadsPauseFunction::RunImpl() { | 1122 bool DownloadsPauseFunction::RunSync() { |
| 1123 scoped_ptr<downloads::Pause::Params> params( | 1123 scoped_ptr<downloads::Pause::Params> params( |
| 1124 downloads::Pause::Params::Create(*args_)); | 1124 downloads::Pause::Params::Create(*args_)); |
| 1125 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1125 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1126 DownloadItem* download_item = | 1126 DownloadItem* download_item = |
| 1127 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1127 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1128 if (InvalidId(download_item, &error_) || | 1128 if (InvalidId(download_item, &error_) || |
| 1129 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, | 1129 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, |
| 1130 errors::kNotInProgress, &error_)) | 1130 errors::kNotInProgress, &error_)) |
| 1131 return false; | 1131 return false; |
| 1132 // If the item is already paused, this is a no-op and the operation will | 1132 // If the item is already paused, this is a no-op and the operation will |
| 1133 // silently succeed. | 1133 // silently succeed. |
| 1134 download_item->Pause(); | 1134 download_item->Pause(); |
| 1135 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); | 1135 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); |
| 1136 return true; | 1136 return true; |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 DownloadsResumeFunction::DownloadsResumeFunction() {} | 1139 DownloadsResumeFunction::DownloadsResumeFunction() {} |
| 1140 | 1140 |
| 1141 DownloadsResumeFunction::~DownloadsResumeFunction() {} | 1141 DownloadsResumeFunction::~DownloadsResumeFunction() {} |
| 1142 | 1142 |
| 1143 bool DownloadsResumeFunction::RunImpl() { | 1143 bool DownloadsResumeFunction::RunSync() { |
| 1144 scoped_ptr<downloads::Resume::Params> params( | 1144 scoped_ptr<downloads::Resume::Params> params( |
| 1145 downloads::Resume::Params::Create(*args_)); | 1145 downloads::Resume::Params::Create(*args_)); |
| 1146 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1146 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1147 DownloadItem* download_item = | 1147 DownloadItem* download_item = |
| 1148 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1148 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1149 if (InvalidId(download_item, &error_) || | 1149 if (InvalidId(download_item, &error_) || |
| 1150 Fault(download_item->IsPaused() && !download_item->CanResume(), | 1150 Fault(download_item->IsPaused() && !download_item->CanResume(), |
| 1151 errors::kNotResumable, &error_)) | 1151 errors::kNotResumable, &error_)) |
| 1152 return false; | 1152 return false; |
| 1153 // Note that if the item isn't paused, this will be a no-op, and the extension | 1153 // Note that if the item isn't paused, this will be a no-op, and the extension |
| 1154 // call will seem successful. | 1154 // call will seem successful. |
| 1155 download_item->Resume(); | 1155 download_item->Resume(); |
| 1156 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); | 1156 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); |
| 1157 return true; | 1157 return true; |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 DownloadsCancelFunction::DownloadsCancelFunction() {} | 1160 DownloadsCancelFunction::DownloadsCancelFunction() {} |
| 1161 | 1161 |
| 1162 DownloadsCancelFunction::~DownloadsCancelFunction() {} | 1162 DownloadsCancelFunction::~DownloadsCancelFunction() {} |
| 1163 | 1163 |
| 1164 bool DownloadsCancelFunction::RunImpl() { | 1164 bool DownloadsCancelFunction::RunSync() { |
| 1165 scoped_ptr<downloads::Resume::Params> params( | 1165 scoped_ptr<downloads::Resume::Params> params( |
| 1166 downloads::Resume::Params::Create(*args_)); | 1166 downloads::Resume::Params::Create(*args_)); |
| 1167 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1168 DownloadItem* download_item = | 1168 DownloadItem* download_item = |
| 1169 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1169 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1170 if (download_item && | 1170 if (download_item && |
| 1171 (download_item->GetState() == DownloadItem::IN_PROGRESS)) | 1171 (download_item->GetState() == DownloadItem::IN_PROGRESS)) |
| 1172 download_item->Cancel(true); | 1172 download_item->Cancel(true); |
| 1173 // |download_item| can be NULL if the download ID was invalid or if the | 1173 // |download_item| can be NULL if the download ID was invalid or if the |
| 1174 // download is not currently active. Either way, it's not a failure. | 1174 // download is not currently active. Either way, it's not a failure. |
| 1175 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); | 1175 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); |
| 1176 return true; | 1176 return true; |
| 1177 } | 1177 } |
| 1178 | 1178 |
| 1179 DownloadsEraseFunction::DownloadsEraseFunction() {} | 1179 DownloadsEraseFunction::DownloadsEraseFunction() {} |
| 1180 | 1180 |
| 1181 DownloadsEraseFunction::~DownloadsEraseFunction() {} | 1181 DownloadsEraseFunction::~DownloadsEraseFunction() {} |
| 1182 | 1182 |
| 1183 bool DownloadsEraseFunction::RunImpl() { | 1183 bool DownloadsEraseFunction::RunSync() { |
| 1184 scoped_ptr<downloads::Erase::Params> params( | 1184 scoped_ptr<downloads::Erase::Params> params( |
| 1185 downloads::Erase::Params::Create(*args_)); | 1185 downloads::Erase::Params::Create(*args_)); |
| 1186 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1186 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1187 DownloadManager* manager = NULL; | 1187 DownloadManager* manager = NULL; |
| 1188 DownloadManager* incognito_manager = NULL; | 1188 DownloadManager* incognito_manager = NULL; |
| 1189 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1189 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
| 1190 DownloadQuery::DownloadVector results; | 1190 DownloadQuery::DownloadVector results; |
| 1191 RunDownloadQuery(params->query, | 1191 RunDownloadQuery(params->query, |
| 1192 manager, | 1192 manager, |
| 1193 incognito_manager, | 1193 incognito_manager, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 GetProfile(), | 1348 GetProfile(), |
| 1349 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); | 1349 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); |
| 1350 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); | 1350 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); |
| 1351 return true; | 1351 return true; |
| 1352 } | 1352 } |
| 1353 | 1353 |
| 1354 DownloadsOpenFunction::DownloadsOpenFunction() {} | 1354 DownloadsOpenFunction::DownloadsOpenFunction() {} |
| 1355 | 1355 |
| 1356 DownloadsOpenFunction::~DownloadsOpenFunction() {} | 1356 DownloadsOpenFunction::~DownloadsOpenFunction() {} |
| 1357 | 1357 |
| 1358 bool DownloadsOpenFunction::RunImpl() { | 1358 bool DownloadsOpenFunction::RunSync() { |
| 1359 scoped_ptr<downloads::Open::Params> params( | 1359 scoped_ptr<downloads::Open::Params> params( |
| 1360 downloads::Open::Params::Create(*args_)); | 1360 downloads::Open::Params::Create(*args_)); |
| 1361 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1361 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1362 DownloadItem* download_item = | 1362 DownloadItem* download_item = |
| 1363 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1363 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1364 if (InvalidId(download_item, &error_) || | 1364 if (InvalidId(download_item, &error_) || |
| 1365 Fault(!user_gesture(), errors::kUserGesture, &error_) || | 1365 Fault(!user_gesture(), errors::kUserGesture, &error_) || |
| 1366 Fault(download_item->GetState() != DownloadItem::COMPLETE, | 1366 Fault(download_item->GetState() != DownloadItem::COMPLETE, |
| 1367 errors::kNotComplete, &error_) || | 1367 errors::kNotComplete, &error_) || |
| 1368 Fault(!GetExtension()->HasAPIPermission( | 1368 Fault(!GetExtension()->HasAPIPermission( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1399 base::MessageLoop::current()); | 1399 base::MessageLoop::current()); |
| 1400 DragDownloadItem(download_item, icon, view); | 1400 DragDownloadItem(download_item, icon, view); |
| 1401 } | 1401 } |
| 1402 return true; | 1402 return true; |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} | 1405 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} |
| 1406 | 1406 |
| 1407 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} | 1407 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} |
| 1408 | 1408 |
| 1409 bool DownloadsSetShelfEnabledFunction::RunImpl() { | 1409 bool DownloadsSetShelfEnabledFunction::RunSync() { |
| 1410 scoped_ptr<downloads::SetShelfEnabled::Params> params( | 1410 scoped_ptr<downloads::SetShelfEnabled::Params> params( |
| 1411 downloads::SetShelfEnabled::Params::Create(*args_)); | 1411 downloads::SetShelfEnabled::Params::Create(*args_)); |
| 1412 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1412 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1413 if (!GetExtension()->HasAPIPermission( | 1413 if (!GetExtension()->HasAPIPermission( |
| 1414 extensions::APIPermission::kDownloadsShelf)) { | 1414 extensions::APIPermission::kDownloadsShelf)) { |
| 1415 error_ = download_extension_errors::kShelfPermission; | 1415 error_ = download_extension_errors::kShelfPermission; |
| 1416 return false; | 1416 return false; |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); | 1419 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 extensions::UnloadedExtensionInfo* unloaded = | 1907 extensions::UnloadedExtensionInfo* unloaded = |
| 1908 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1908 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 1909 std::set<const extensions::Extension*>::iterator iter = | 1909 std::set<const extensions::Extension*>::iterator iter = |
| 1910 shelf_disabling_extensions_.find(unloaded->extension); | 1910 shelf_disabling_extensions_.find(unloaded->extension); |
| 1911 if (iter != shelf_disabling_extensions_.end()) | 1911 if (iter != shelf_disabling_extensions_.end()) |
| 1912 shelf_disabling_extensions_.erase(iter); | 1912 shelf_disabling_extensions_.erase(iter); |
| 1913 break; | 1913 break; |
| 1914 } | 1914 } |
| 1915 } | 1915 } |
| 1916 } | 1916 } |
| OLD | NEW |