| 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1064 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 1065 error_ = content::DownloadInterruptReasonToString(interrupt_reason); | 1065 error_ = content::DownloadInterruptReasonToString(interrupt_reason); |
| 1066 } | 1066 } |
| 1067 SendResponse(error_.empty()); | 1067 SendResponse(error_.empty()); |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 DownloadsSearchFunction::DownloadsSearchFunction() {} | 1070 DownloadsSearchFunction::DownloadsSearchFunction() {} |
| 1071 | 1071 |
| 1072 DownloadsSearchFunction::~DownloadsSearchFunction() {} | 1072 DownloadsSearchFunction::~DownloadsSearchFunction() {} |
| 1073 | 1073 |
| 1074 bool DownloadsSearchFunction::RunImpl() { | 1074 bool DownloadsSearchFunction::RunSync() { |
| 1075 scoped_ptr<downloads::Search::Params> params( | 1075 scoped_ptr<downloads::Search::Params> params( |
| 1076 downloads::Search::Params::Create(*args_)); | 1076 downloads::Search::Params::Create(*args_)); |
| 1077 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1077 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1078 DownloadManager* manager = NULL; | 1078 DownloadManager* manager = NULL; |
| 1079 DownloadManager* incognito_manager = NULL; | 1079 DownloadManager* incognito_manager = NULL; |
| 1080 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1080 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
| 1081 ManagerDestructionObserver::CheckForHistoryFilesRemoval(manager); | 1081 ManagerDestructionObserver::CheckForHistoryFilesRemoval(manager); |
| 1082 ManagerDestructionObserver::CheckForHistoryFilesRemoval(incognito_manager); | 1082 ManagerDestructionObserver::CheckForHistoryFilesRemoval(incognito_manager); |
| 1083 DownloadQuery::DownloadVector results; | 1083 DownloadQuery::DownloadVector results; |
| 1084 RunDownloadQuery(params->query, | 1084 RunDownloadQuery(params->query, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1104 } | 1104 } |
| 1105 SetResult(json_results); | 1105 SetResult(json_results); |
| 1106 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); | 1106 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); |
| 1107 return true; | 1107 return true; |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 DownloadsPauseFunction::DownloadsPauseFunction() {} | 1110 DownloadsPauseFunction::DownloadsPauseFunction() {} |
| 1111 | 1111 |
| 1112 DownloadsPauseFunction::~DownloadsPauseFunction() {} | 1112 DownloadsPauseFunction::~DownloadsPauseFunction() {} |
| 1113 | 1113 |
| 1114 bool DownloadsPauseFunction::RunImpl() { | 1114 bool DownloadsPauseFunction::RunSync() { |
| 1115 scoped_ptr<downloads::Pause::Params> params( | 1115 scoped_ptr<downloads::Pause::Params> params( |
| 1116 downloads::Pause::Params::Create(*args_)); | 1116 downloads::Pause::Params::Create(*args_)); |
| 1117 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1117 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1118 DownloadItem* download_item = | 1118 DownloadItem* download_item = |
| 1119 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1119 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1120 if (InvalidId(download_item, &error_) || | 1120 if (InvalidId(download_item, &error_) || |
| 1121 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, | 1121 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, |
| 1122 errors::kNotInProgress, &error_)) | 1122 errors::kNotInProgress, &error_)) |
| 1123 return false; | 1123 return false; |
| 1124 // If the item is already paused, this is a no-op and the operation will | 1124 // If the item is already paused, this is a no-op and the operation will |
| 1125 // silently succeed. | 1125 // silently succeed. |
| 1126 download_item->Pause(); | 1126 download_item->Pause(); |
| 1127 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); | 1127 RecordApiFunctions(DOWNLOADS_FUNCTION_PAUSE); |
| 1128 return true; | 1128 return true; |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 DownloadsResumeFunction::DownloadsResumeFunction() {} | 1131 DownloadsResumeFunction::DownloadsResumeFunction() {} |
| 1132 | 1132 |
| 1133 DownloadsResumeFunction::~DownloadsResumeFunction() {} | 1133 DownloadsResumeFunction::~DownloadsResumeFunction() {} |
| 1134 | 1134 |
| 1135 bool DownloadsResumeFunction::RunImpl() { | 1135 bool DownloadsResumeFunction::RunSync() { |
| 1136 scoped_ptr<downloads::Resume::Params> params( | 1136 scoped_ptr<downloads::Resume::Params> params( |
| 1137 downloads::Resume::Params::Create(*args_)); | 1137 downloads::Resume::Params::Create(*args_)); |
| 1138 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1138 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1139 DownloadItem* download_item = | 1139 DownloadItem* download_item = |
| 1140 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1140 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1141 if (InvalidId(download_item, &error_) || | 1141 if (InvalidId(download_item, &error_) || |
| 1142 Fault(download_item->IsPaused() && !download_item->CanResume(), | 1142 Fault(download_item->IsPaused() && !download_item->CanResume(), |
| 1143 errors::kNotResumable, &error_)) | 1143 errors::kNotResumable, &error_)) |
| 1144 return false; | 1144 return false; |
| 1145 // Note that if the item isn't paused, this will be a no-op, and the extension | 1145 // Note that if the item isn't paused, this will be a no-op, and the extension |
| 1146 // call will seem successful. | 1146 // call will seem successful. |
| 1147 download_item->Resume(); | 1147 download_item->Resume(); |
| 1148 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); | 1148 RecordApiFunctions(DOWNLOADS_FUNCTION_RESUME); |
| 1149 return true; | 1149 return true; |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 DownloadsCancelFunction::DownloadsCancelFunction() {} | 1152 DownloadsCancelFunction::DownloadsCancelFunction() {} |
| 1153 | 1153 |
| 1154 DownloadsCancelFunction::~DownloadsCancelFunction() {} | 1154 DownloadsCancelFunction::~DownloadsCancelFunction() {} |
| 1155 | 1155 |
| 1156 bool DownloadsCancelFunction::RunImpl() { | 1156 bool DownloadsCancelFunction::RunSync() { |
| 1157 scoped_ptr<downloads::Resume::Params> params( | 1157 scoped_ptr<downloads::Resume::Params> params( |
| 1158 downloads::Resume::Params::Create(*args_)); | 1158 downloads::Resume::Params::Create(*args_)); |
| 1159 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1159 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1160 DownloadItem* download_item = | 1160 DownloadItem* download_item = |
| 1161 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1161 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1162 if (download_item && | 1162 if (download_item && |
| 1163 (download_item->GetState() == DownloadItem::IN_PROGRESS)) | 1163 (download_item->GetState() == DownloadItem::IN_PROGRESS)) |
| 1164 download_item->Cancel(true); | 1164 download_item->Cancel(true); |
| 1165 // |download_item| can be NULL if the download ID was invalid or if the | 1165 // |download_item| can be NULL if the download ID was invalid or if the |
| 1166 // download is not currently active. Either way, it's not a failure. | 1166 // download is not currently active. Either way, it's not a failure. |
| 1167 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); | 1167 RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL); |
| 1168 return true; | 1168 return true; |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 DownloadsEraseFunction::DownloadsEraseFunction() {} | 1171 DownloadsEraseFunction::DownloadsEraseFunction() {} |
| 1172 | 1172 |
| 1173 DownloadsEraseFunction::~DownloadsEraseFunction() {} | 1173 DownloadsEraseFunction::~DownloadsEraseFunction() {} |
| 1174 | 1174 |
| 1175 bool DownloadsEraseFunction::RunImpl() { | 1175 bool DownloadsEraseFunction::RunSync() { |
| 1176 scoped_ptr<downloads::Erase::Params> params( | 1176 scoped_ptr<downloads::Erase::Params> params( |
| 1177 downloads::Erase::Params::Create(*args_)); | 1177 downloads::Erase::Params::Create(*args_)); |
| 1178 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1178 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1179 DownloadManager* manager = NULL; | 1179 DownloadManager* manager = NULL; |
| 1180 DownloadManager* incognito_manager = NULL; | 1180 DownloadManager* incognito_manager = NULL; |
| 1181 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1181 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
| 1182 DownloadQuery::DownloadVector results; | 1182 DownloadQuery::DownloadVector results; |
| 1183 RunDownloadQuery(params->query, | 1183 RunDownloadQuery(params->query, |
| 1184 manager, | 1184 manager, |
| 1185 incognito_manager, | 1185 incognito_manager, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 GetProfile(), | 1340 GetProfile(), |
| 1341 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); | 1341 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); |
| 1342 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); | 1342 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); |
| 1343 return true; | 1343 return true; |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 DownloadsOpenFunction::DownloadsOpenFunction() {} | 1346 DownloadsOpenFunction::DownloadsOpenFunction() {} |
| 1347 | 1347 |
| 1348 DownloadsOpenFunction::~DownloadsOpenFunction() {} | 1348 DownloadsOpenFunction::~DownloadsOpenFunction() {} |
| 1349 | 1349 |
| 1350 bool DownloadsOpenFunction::RunImpl() { | 1350 bool DownloadsOpenFunction::RunSync() { |
| 1351 scoped_ptr<downloads::Open::Params> params( | 1351 scoped_ptr<downloads::Open::Params> params( |
| 1352 downloads::Open::Params::Create(*args_)); | 1352 downloads::Open::Params::Create(*args_)); |
| 1353 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1353 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1354 DownloadItem* download_item = | 1354 DownloadItem* download_item = |
| 1355 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1355 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1356 if (InvalidId(download_item, &error_) || | 1356 if (InvalidId(download_item, &error_) || |
| 1357 Fault(!user_gesture(), errors::kUserGesture, &error_) || | 1357 Fault(!user_gesture(), errors::kUserGesture, &error_) || |
| 1358 Fault(download_item->GetState() != DownloadItem::COMPLETE, | 1358 Fault(download_item->GetState() != DownloadItem::COMPLETE, |
| 1359 errors::kNotComplete, &error_) || | 1359 errors::kNotComplete, &error_) || |
| 1360 Fault(!GetExtension()->HasAPIPermission( | 1360 Fault(!GetExtension()->HasAPIPermission( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1391 base::MessageLoop::current()); | 1391 base::MessageLoop::current()); |
| 1392 DragDownloadItem(download_item, icon, view); | 1392 DragDownloadItem(download_item, icon, view); |
| 1393 } | 1393 } |
| 1394 return true; | 1394 return true; |
| 1395 } | 1395 } |
| 1396 | 1396 |
| 1397 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} | 1397 DownloadsSetShelfEnabledFunction::DownloadsSetShelfEnabledFunction() {} |
| 1398 | 1398 |
| 1399 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} | 1399 DownloadsSetShelfEnabledFunction::~DownloadsSetShelfEnabledFunction() {} |
| 1400 | 1400 |
| 1401 bool DownloadsSetShelfEnabledFunction::RunImpl() { | 1401 bool DownloadsSetShelfEnabledFunction::RunSync() { |
| 1402 scoped_ptr<downloads::SetShelfEnabled::Params> params( | 1402 scoped_ptr<downloads::SetShelfEnabled::Params> params( |
| 1403 downloads::SetShelfEnabled::Params::Create(*args_)); | 1403 downloads::SetShelfEnabled::Params::Create(*args_)); |
| 1404 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1404 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1405 if (!GetExtension()->HasAPIPermission( | 1405 if (!GetExtension()->HasAPIPermission( |
| 1406 extensions::APIPermission::kDownloadsShelf)) { | 1406 extensions::APIPermission::kDownloadsShelf)) { |
| 1407 error_ = download_extension_errors::kShelfPermission; | 1407 error_ = download_extension_errors::kShelfPermission; |
| 1408 return false; | 1408 return false; |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); | 1411 RecordApiFunctions(DOWNLOADS_FUNCTION_SET_SHELF_ENABLED); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 void ExtensionDownloadsEventRouter::OnExtensionUnloaded( | 1893 void ExtensionDownloadsEventRouter::OnExtensionUnloaded( |
| 1894 content::BrowserContext* browser_context, | 1894 content::BrowserContext* browser_context, |
| 1895 const extensions::Extension* extension, | 1895 const extensions::Extension* extension, |
| 1896 extensions::UnloadedExtensionInfo::Reason reason) { | 1896 extensions::UnloadedExtensionInfo::Reason reason) { |
| 1897 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1897 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1898 std::set<const extensions::Extension*>::iterator iter = | 1898 std::set<const extensions::Extension*>::iterator iter = |
| 1899 shelf_disabling_extensions_.find(extension); | 1899 shelf_disabling_extensions_.find(extension); |
| 1900 if (iter != shelf_disabling_extensions_.end()) | 1900 if (iter != shelf_disabling_extensions_.end()) |
| 1901 shelf_disabling_extensions_.erase(iter); | 1901 shelf_disabling_extensions_.erase(iter); |
| 1902 } | 1902 } |
| OLD | NEW |