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 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 const std::string& name) | 982 const std::string& name) |
983 : id_(id), | 983 : id_(id), |
984 name_(name) { | 984 name_(name) { |
985 item->SetUserData(kKey, this); | 985 item->SetUserData(kKey, this); |
986 } | 986 } |
987 | 987 |
988 DownloadsDownloadFunction::DownloadsDownloadFunction() {} | 988 DownloadsDownloadFunction::DownloadsDownloadFunction() {} |
989 | 989 |
990 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} | 990 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} |
991 | 991 |
992 bool DownloadsDownloadFunction::RunImpl() { | 992 bool DownloadsDownloadFunction::RunAsync() { |
993 scoped_ptr<downloads::Download::Params> params( | 993 scoped_ptr<downloads::Download::Params> params( |
994 downloads::Download::Params::Create(*args_)); | 994 downloads::Download::Params::Create(*args_)); |
995 EXTENSION_FUNCTION_VALIDATE(params.get()); | 995 EXTENSION_FUNCTION_VALIDATE(params.get()); |
996 const downloads::DownloadOptions& options = params->options; | 996 const downloads::DownloadOptions& options = params->options; |
997 GURL download_url(options.url); | 997 GURL download_url(options.url); |
998 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_)) | 998 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_)) |
999 return false; | 999 return false; |
1000 | 1000 |
1001 Profile* current_profile = GetProfile(); | 1001 Profile* current_profile = GetProfile(); |
1002 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) | 1002 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); | 1231 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); |
1232 return true; | 1232 return true; |
1233 } | 1233 } |
1234 | 1234 |
1235 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { | 1235 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { |
1236 } | 1236 } |
1237 | 1237 |
1238 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { | 1238 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { |
1239 } | 1239 } |
1240 | 1240 |
1241 bool DownloadsRemoveFileFunction::RunImpl() { | 1241 bool DownloadsRemoveFileFunction::RunAsync() { |
1242 scoped_ptr<downloads::RemoveFile::Params> params( | 1242 scoped_ptr<downloads::RemoveFile::Params> params( |
1243 downloads::RemoveFile::Params::Create(*args_)); | 1243 downloads::RemoveFile::Params::Create(*args_)); |
1244 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1244 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1245 DownloadItem* download_item = | 1245 DownloadItem* download_item = |
1246 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1246 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1247 if (InvalidId(download_item, &error_) || | 1247 if (InvalidId(download_item, &error_) || |
1248 Fault((download_item->GetState() != DownloadItem::COMPLETE), | 1248 Fault((download_item->GetState() != DownloadItem::COMPLETE), |
1249 errors::kNotComplete, &error_) || | 1249 errors::kNotComplete, &error_) || |
1250 Fault(download_item->GetFileExternallyRemoved(), | 1250 Fault(download_item->GetFileExternallyRemoved(), |
1251 errors::kFileAlreadyDeleted, &error_)) | 1251 errors::kFileAlreadyDeleted, &error_)) |
(...skipping 12 matching lines...) Expand all Loading... |
1264 SendResponse(error_.empty()); | 1264 SendResponse(error_.empty()); |
1265 } | 1265 } |
1266 | 1266 |
1267 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} | 1267 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} |
1268 | 1268 |
1269 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} | 1269 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} |
1270 | 1270 |
1271 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* | 1271 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* |
1272 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; | 1272 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; |
1273 | 1273 |
1274 bool DownloadsAcceptDangerFunction::RunImpl() { | 1274 bool DownloadsAcceptDangerFunction::RunAsync() { |
1275 scoped_ptr<downloads::AcceptDanger::Params> params( | 1275 scoped_ptr<downloads::AcceptDanger::Params> params( |
1276 downloads::AcceptDanger::Params::Create(*args_)); | 1276 downloads::AcceptDanger::Params::Create(*args_)); |
1277 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1277 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1278 PromptOrWait(params->download_id, 10); | 1278 PromptOrWait(params->download_id, 10); |
1279 return true; | 1279 return true; |
1280 } | 1280 } |
1281 | 1281 |
1282 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { | 1282 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { |
1283 DownloadItem* download_item = | 1283 DownloadItem* download_item = |
1284 GetDownload(GetProfile(), include_incognito(), download_id); | 1284 GetDownload(GetProfile(), include_incognito(), download_id); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 case DownloadDangerPrompt::DISMISS: | 1341 case DownloadDangerPrompt::DISMISS: |
1342 break; | 1342 break; |
1343 } | 1343 } |
1344 SendResponse(error_.empty()); | 1344 SendResponse(error_.empty()); |
1345 } | 1345 } |
1346 | 1346 |
1347 DownloadsShowFunction::DownloadsShowFunction() {} | 1347 DownloadsShowFunction::DownloadsShowFunction() {} |
1348 | 1348 |
1349 DownloadsShowFunction::~DownloadsShowFunction() {} | 1349 DownloadsShowFunction::~DownloadsShowFunction() {} |
1350 | 1350 |
1351 bool DownloadsShowFunction::RunImpl() { | 1351 bool DownloadsShowFunction::RunAsync() { |
1352 scoped_ptr<downloads::Show::Params> params( | 1352 scoped_ptr<downloads::Show::Params> params( |
1353 downloads::Show::Params::Create(*args_)); | 1353 downloads::Show::Params::Create(*args_)); |
1354 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1354 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1355 DownloadItem* download_item = | 1355 DownloadItem* download_item = |
1356 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1356 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1357 if (InvalidId(download_item, &error_)) | 1357 if (InvalidId(download_item, &error_)) |
1358 return false; | 1358 return false; |
1359 download_item->ShowDownloadInShell(); | 1359 download_item->ShowDownloadInShell(); |
1360 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); | 1360 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); |
1361 return true; | 1361 return true; |
1362 } | 1362 } |
1363 | 1363 |
1364 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {} | 1364 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {} |
1365 | 1365 |
1366 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {} | 1366 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {} |
1367 | 1367 |
1368 bool DownloadsShowDefaultFolderFunction::RunImpl() { | 1368 bool DownloadsShowDefaultFolderFunction::RunAsync() { |
1369 DownloadManager* manager = NULL; | 1369 DownloadManager* manager = NULL; |
1370 DownloadManager* incognito_manager = NULL; | 1370 DownloadManager* incognito_manager = NULL; |
1371 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); | 1371 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); |
1372 platform_util::OpenItem( | 1372 platform_util::OpenItem( |
1373 GetProfile(), | 1373 GetProfile(), |
1374 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); | 1374 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); |
1375 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); | 1375 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); |
1376 return true; | 1376 return true; |
1377 } | 1377 } |
1378 | 1378 |
(...skipping 17 matching lines...) Expand all Loading... |
1396 return false; | 1396 return false; |
1397 download_item->OpenDownload(); | 1397 download_item->OpenDownload(); |
1398 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); | 1398 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); |
1399 return true; | 1399 return true; |
1400 } | 1400 } |
1401 | 1401 |
1402 DownloadsDragFunction::DownloadsDragFunction() {} | 1402 DownloadsDragFunction::DownloadsDragFunction() {} |
1403 | 1403 |
1404 DownloadsDragFunction::~DownloadsDragFunction() {} | 1404 DownloadsDragFunction::~DownloadsDragFunction() {} |
1405 | 1405 |
1406 bool DownloadsDragFunction::RunImpl() { | 1406 bool DownloadsDragFunction::RunAsync() { |
1407 scoped_ptr<downloads::Drag::Params> params( | 1407 scoped_ptr<downloads::Drag::Params> params( |
1408 downloads::Drag::Params::Create(*args_)); | 1408 downloads::Drag::Params::Create(*args_)); |
1409 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1409 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1410 DownloadItem* download_item = | 1410 DownloadItem* download_item = |
1411 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1411 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1412 content::WebContents* web_contents = | 1412 content::WebContents* web_contents = |
1413 dispatcher()->delegate()->GetVisibleWebContents(); | 1413 dispatcher()->delegate()->GetVisibleWebContents(); |
1414 if (InvalidId(download_item, &error_) || | 1414 if (InvalidId(download_item, &error_) || |
1415 Fault(!web_contents, errors::kInvisibleContext, &error_)) | 1415 Fault(!web_contents, errors::kInvisibleContext, &error_)) |
1416 return false; | 1416 return false; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 } | 1490 } |
1491 | 1491 |
1492 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} | 1492 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} |
1493 | 1493 |
1494 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( | 1494 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( |
1495 DownloadFileIconExtractor* extractor) { | 1495 DownloadFileIconExtractor* extractor) { |
1496 DCHECK(extractor); | 1496 DCHECK(extractor); |
1497 icon_extractor_.reset(extractor); | 1497 icon_extractor_.reset(extractor); |
1498 } | 1498 } |
1499 | 1499 |
1500 bool DownloadsGetFileIconFunction::RunImpl() { | 1500 bool DownloadsGetFileIconFunction::RunAsync() { |
1501 scoped_ptr<downloads::GetFileIcon::Params> params( | 1501 scoped_ptr<downloads::GetFileIcon::Params> params( |
1502 downloads::GetFileIcon::Params::Create(*args_)); | 1502 downloads::GetFileIcon::Params::Create(*args_)); |
1503 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1503 EXTENSION_FUNCTION_VALIDATE(params.get()); |
1504 const downloads::GetFileIconOptions* options = | 1504 const downloads::GetFileIconOptions* options = |
1505 params->options.get(); | 1505 params->options.get(); |
1506 int icon_size = kDefaultIconSize; | 1506 int icon_size = kDefaultIconSize; |
1507 if (options && options->size.get()) | 1507 if (options && options->size.get()) |
1508 icon_size = *options->size.get(); | 1508 icon_size = *options->size.get(); |
1509 DownloadItem* download_item = | 1509 DownloadItem* download_item = |
1510 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1510 GetDownload(GetProfile(), include_incognito(), params->download_id); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 // | 1597 // |
1598 // When a download's filename is being determined, DownloadTargetDeterminer (via | 1598 // When a download's filename is being determined, DownloadTargetDeterminer (via |
1599 // ChromeDownloadManagerDelegate (CDMD) ::NotifyExtensions()) passes 2 callbacks | 1599 // ChromeDownloadManagerDelegate (CDMD) ::NotifyExtensions()) passes 2 callbacks |
1600 // to ExtensionDownloadsEventRouter::OnDeterminingFilename (ODF), which stores | 1600 // to ExtensionDownloadsEventRouter::OnDeterminingFilename (ODF), which stores |
1601 // the callbacks in the item's ExtensionDownloadsEventRouterData (EDERD) along | 1601 // the callbacks in the item's ExtensionDownloadsEventRouterData (EDERD) along |
1602 // with all of the extension IDs that are listening for onDeterminingFilename | 1602 // with all of the extension IDs that are listening for onDeterminingFilename |
1603 // events. ODF dispatches chrome.downloads.onDeterminingFilename. | 1603 // events. ODF dispatches chrome.downloads.onDeterminingFilename. |
1604 // | 1604 // |
1605 // When the extension's event handler calls |suggestCallback|, | 1605 // When the extension's event handler calls |suggestCallback|, |
1606 // downloads_custom_bindings.js calls | 1606 // downloads_custom_bindings.js calls |
1607 // DownloadsInternalDetermineFilenameFunction::RunImpl, which calls | 1607 // DownloadsInternalDetermineFilenameFunction::RunAsync, which calls |
1608 // EDER::DetermineFilename, which notifies the item's EDERD. | 1608 // EDER::DetermineFilename, which notifies the item's EDERD. |
1609 // | 1609 // |
1610 // When the last extension's event handler returns, EDERD calls one of the two | 1610 // When the last extension's event handler returns, EDERD calls one of the two |
1611 // callbacks that CDMD passed to ODF, allowing DownloadTargetDeterminer to | 1611 // callbacks that CDMD passed to ODF, allowing DownloadTargetDeterminer to |
1612 // continue the filename determination process. If multiple extensions wish to | 1612 // continue the filename determination process. If multiple extensions wish to |
1613 // override the filename, then the extension that was last installed wins. | 1613 // override the filename, then the extension that was last installed wins. |
1614 | 1614 |
1615 void ExtensionDownloadsEventRouter::OnDeterminingFilename( | 1615 void ExtensionDownloadsEventRouter::OnDeterminingFilename( |
1616 DownloadItem* item, | 1616 DownloadItem* item, |
1617 const base::FilePath& suggested_path, | 1617 const base::FilePath& suggested_path, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 const extensions::Extension* extension, | 1932 const extensions::Extension* extension, |
1933 extensions::UnloadedExtensionInfo::Reason reason) { | 1933 extensions::UnloadedExtensionInfo::Reason reason) { |
1934 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1934 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1935 std::set<const extensions::Extension*>::iterator iter = | 1935 std::set<const extensions::Extension*>::iterator iter = |
1936 shelf_disabling_extensions_.find(extension); | 1936 shelf_disabling_extensions_.find(extension); |
1937 if (iter != shelf_disabling_extensions_.end()) | 1937 if (iter != shelf_disabling_extensions_.end()) |
1938 shelf_disabling_extensions_.erase(iter); | 1938 shelf_disabling_extensions_.erase(iter); |
1939 } | 1939 } |
1940 | 1940 |
1941 } // namespace extensions | 1941 } // namespace extensions |
OLD | NEW |