Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 257333002: Drive extension functions from ExtensionFunction::Run. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: appshell Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 const std::string& name) 951 const std::string& name)
952 : id_(id), 952 : id_(id),
953 name_(name) { 953 name_(name) {
954 item->SetUserData(kKey, this); 954 item->SetUserData(kKey, this);
955 } 955 }
956 956
957 DownloadsDownloadFunction::DownloadsDownloadFunction() {} 957 DownloadsDownloadFunction::DownloadsDownloadFunction() {}
958 958
959 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} 959 DownloadsDownloadFunction::~DownloadsDownloadFunction() {}
960 960
961 bool DownloadsDownloadFunction::RunImpl() { 961 bool DownloadsDownloadFunction::RunAsync() {
962 scoped_ptr<downloads::Download::Params> params( 962 scoped_ptr<downloads::Download::Params> params(
963 downloads::Download::Params::Create(*args_)); 963 downloads::Download::Params::Create(*args_));
964 EXTENSION_FUNCTION_VALIDATE(params.get()); 964 EXTENSION_FUNCTION_VALIDATE(params.get());
965 const downloads::DownloadOptions& options = params->options; 965 const downloads::DownloadOptions& options = params->options;
966 GURL download_url(options.url); 966 GURL download_url(options.url);
967 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_)) 967 if (Fault(!download_url.is_valid(), errors::kInvalidURL, &error_))
968 return false; 968 return false;
969 969
970 Profile* current_profile = GetProfile(); 970 Profile* current_profile = GetProfile();
971 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) 971 if (include_incognito() && GetProfile()->HasOffTheRecordProfile())
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); 1200 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE);
1201 return true; 1201 return true;
1202 } 1202 }
1203 1203
1204 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { 1204 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() {
1205 } 1205 }
1206 1206
1207 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { 1207 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() {
1208 } 1208 }
1209 1209
1210 bool DownloadsRemoveFileFunction::RunImpl() { 1210 bool DownloadsRemoveFileFunction::RunAsync() {
1211 scoped_ptr<downloads::RemoveFile::Params> params( 1211 scoped_ptr<downloads::RemoveFile::Params> params(
1212 downloads::RemoveFile::Params::Create(*args_)); 1212 downloads::RemoveFile::Params::Create(*args_));
1213 EXTENSION_FUNCTION_VALIDATE(params.get()); 1213 EXTENSION_FUNCTION_VALIDATE(params.get());
1214 DownloadItem* download_item = 1214 DownloadItem* download_item =
1215 GetDownload(GetProfile(), include_incognito(), params->download_id); 1215 GetDownload(GetProfile(), include_incognito(), params->download_id);
1216 if (InvalidId(download_item, &error_) || 1216 if (InvalidId(download_item, &error_) ||
1217 Fault((download_item->GetState() != DownloadItem::COMPLETE), 1217 Fault((download_item->GetState() != DownloadItem::COMPLETE),
1218 errors::kNotComplete, &error_) || 1218 errors::kNotComplete, &error_) ||
1219 Fault(download_item->GetFileExternallyRemoved(), 1219 Fault(download_item->GetFileExternallyRemoved(),
1220 errors::kFileAlreadyDeleted, &error_)) 1220 errors::kFileAlreadyDeleted, &error_))
(...skipping 12 matching lines...) Expand all
1233 SendResponse(error_.empty()); 1233 SendResponse(error_.empty());
1234 } 1234 }
1235 1235
1236 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} 1236 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {}
1237 1237
1238 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} 1238 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {}
1239 1239
1240 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* 1240 DownloadsAcceptDangerFunction::OnPromptCreatedCallback*
1241 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; 1241 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL;
1242 1242
1243 bool DownloadsAcceptDangerFunction::RunImpl() { 1243 bool DownloadsAcceptDangerFunction::RunAsync() {
1244 scoped_ptr<downloads::AcceptDanger::Params> params( 1244 scoped_ptr<downloads::AcceptDanger::Params> params(
1245 downloads::AcceptDanger::Params::Create(*args_)); 1245 downloads::AcceptDanger::Params::Create(*args_));
1246 EXTENSION_FUNCTION_VALIDATE(params.get()); 1246 EXTENSION_FUNCTION_VALIDATE(params.get());
1247 PromptOrWait(params->download_id, 10); 1247 PromptOrWait(params->download_id, 10);
1248 return true; 1248 return true;
1249 } 1249 }
1250 1250
1251 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) { 1251 void DownloadsAcceptDangerFunction::PromptOrWait(int download_id, int retries) {
1252 DownloadItem* download_item = 1252 DownloadItem* download_item =
1253 GetDownload(GetProfile(), include_incognito(), download_id); 1253 GetDownload(GetProfile(), include_incognito(), download_id);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 case DownloadDangerPrompt::DISMISS: 1310 case DownloadDangerPrompt::DISMISS:
1311 break; 1311 break;
1312 } 1312 }
1313 SendResponse(error_.empty()); 1313 SendResponse(error_.empty());
1314 } 1314 }
1315 1315
1316 DownloadsShowFunction::DownloadsShowFunction() {} 1316 DownloadsShowFunction::DownloadsShowFunction() {}
1317 1317
1318 DownloadsShowFunction::~DownloadsShowFunction() {} 1318 DownloadsShowFunction::~DownloadsShowFunction() {}
1319 1319
1320 bool DownloadsShowFunction::RunImpl() { 1320 bool DownloadsShowFunction::RunAsync() {
1321 scoped_ptr<downloads::Show::Params> params( 1321 scoped_ptr<downloads::Show::Params> params(
1322 downloads::Show::Params::Create(*args_)); 1322 downloads::Show::Params::Create(*args_));
1323 EXTENSION_FUNCTION_VALIDATE(params.get()); 1323 EXTENSION_FUNCTION_VALIDATE(params.get());
1324 DownloadItem* download_item = 1324 DownloadItem* download_item =
1325 GetDownload(GetProfile(), include_incognito(), params->download_id); 1325 GetDownload(GetProfile(), include_incognito(), params->download_id);
1326 if (InvalidId(download_item, &error_)) 1326 if (InvalidId(download_item, &error_))
1327 return false; 1327 return false;
1328 download_item->ShowDownloadInShell(); 1328 download_item->ShowDownloadInShell();
1329 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW); 1329 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW);
1330 return true; 1330 return true;
1331 } 1331 }
1332 1332
1333 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {} 1333 DownloadsShowDefaultFolderFunction::DownloadsShowDefaultFolderFunction() {}
1334 1334
1335 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {} 1335 DownloadsShowDefaultFolderFunction::~DownloadsShowDefaultFolderFunction() {}
1336 1336
1337 bool DownloadsShowDefaultFolderFunction::RunImpl() { 1337 bool DownloadsShowDefaultFolderFunction::RunAsync() {
1338 DownloadManager* manager = NULL; 1338 DownloadManager* manager = NULL;
1339 DownloadManager* incognito_manager = NULL; 1339 DownloadManager* incognito_manager = NULL;
1340 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager); 1340 GetManagers(GetProfile(), include_incognito(), &manager, &incognito_manager);
1341 platform_util::OpenItem( 1341 platform_util::OpenItem(
1342 GetProfile(), 1342 GetProfile(),
1343 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); 1343 DownloadPrefs::FromDownloadManager(manager)->DownloadPath());
1344 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER); 1344 RecordApiFunctions(DOWNLOADS_FUNCTION_SHOW_DEFAULT_FOLDER);
1345 return true; 1345 return true;
1346 } 1346 }
1347 1347
(...skipping 17 matching lines...) Expand all
1365 return false; 1365 return false;
1366 download_item->OpenDownload(); 1366 download_item->OpenDownload();
1367 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN); 1367 RecordApiFunctions(DOWNLOADS_FUNCTION_OPEN);
1368 return true; 1368 return true;
1369 } 1369 }
1370 1370
1371 DownloadsDragFunction::DownloadsDragFunction() {} 1371 DownloadsDragFunction::DownloadsDragFunction() {}
1372 1372
1373 DownloadsDragFunction::~DownloadsDragFunction() {} 1373 DownloadsDragFunction::~DownloadsDragFunction() {}
1374 1374
1375 bool DownloadsDragFunction::RunImpl() { 1375 bool DownloadsDragFunction::RunAsync() {
1376 scoped_ptr<downloads::Drag::Params> params( 1376 scoped_ptr<downloads::Drag::Params> params(
1377 downloads::Drag::Params::Create(*args_)); 1377 downloads::Drag::Params::Create(*args_));
1378 EXTENSION_FUNCTION_VALIDATE(params.get()); 1378 EXTENSION_FUNCTION_VALIDATE(params.get());
1379 DownloadItem* download_item = 1379 DownloadItem* download_item =
1380 GetDownload(GetProfile(), include_incognito(), params->download_id); 1380 GetDownload(GetProfile(), include_incognito(), params->download_id);
1381 content::WebContents* web_contents = 1381 content::WebContents* web_contents =
1382 dispatcher()->delegate()->GetVisibleWebContents(); 1382 dispatcher()->delegate()->GetVisibleWebContents();
1383 if (InvalidId(download_item, &error_) || 1383 if (InvalidId(download_item, &error_) ||
1384 Fault(!web_contents, errors::kInvisibleContext, &error_)) 1384 Fault(!web_contents, errors::kInvisibleContext, &error_))
1385 return false; 1385 return false;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 } 1459 }
1460 1460
1461 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {} 1461 DownloadsGetFileIconFunction::~DownloadsGetFileIconFunction() {}
1462 1462
1463 void DownloadsGetFileIconFunction::SetIconExtractorForTesting( 1463 void DownloadsGetFileIconFunction::SetIconExtractorForTesting(
1464 DownloadFileIconExtractor* extractor) { 1464 DownloadFileIconExtractor* extractor) {
1465 DCHECK(extractor); 1465 DCHECK(extractor);
1466 icon_extractor_.reset(extractor); 1466 icon_extractor_.reset(extractor);
1467 } 1467 }
1468 1468
1469 bool DownloadsGetFileIconFunction::RunImpl() { 1469 bool DownloadsGetFileIconFunction::RunAsync() {
1470 scoped_ptr<downloads::GetFileIcon::Params> params( 1470 scoped_ptr<downloads::GetFileIcon::Params> params(
1471 downloads::GetFileIcon::Params::Create(*args_)); 1471 downloads::GetFileIcon::Params::Create(*args_));
1472 EXTENSION_FUNCTION_VALIDATE(params.get()); 1472 EXTENSION_FUNCTION_VALIDATE(params.get());
1473 const downloads::GetFileIconOptions* options = 1473 const downloads::GetFileIconOptions* options =
1474 params->options.get(); 1474 params->options.get();
1475 int icon_size = kDefaultIconSize; 1475 int icon_size = kDefaultIconSize;
1476 if (options && options->size.get()) 1476 if (options && options->size.get())
1477 icon_size = *options->size.get(); 1477 icon_size = *options->size.get();
1478 DownloadItem* download_item = 1478 DownloadItem* download_item =
1479 GetDownload(GetProfile(), include_incognito(), params->download_id); 1479 GetDownload(GetProfile(), include_incognito(), params->download_id);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 // When a download's filename is being determined, 1561 // When a download's filename is being determined,
1562 // ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone (CVRBD) passes 1562 // ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone (CVRBD) passes
1563 // 2 callbacks to ExtensionDownloadsEventRouter::OnDeterminingFilename (ODF), 1563 // 2 callbacks to ExtensionDownloadsEventRouter::OnDeterminingFilename (ODF),
1564 // which stores the callbacks in the item's ExtensionDownloadsEventRouterData 1564 // which stores the callbacks in the item's ExtensionDownloadsEventRouterData
1565 // (EDERD) along with all of the extension IDs that are listening for 1565 // (EDERD) along with all of the extension IDs that are listening for
1566 // onDeterminingFilename events. ODF dispatches 1566 // onDeterminingFilename events. ODF dispatches
1567 // chrome.downloads.onDeterminingFilename. 1567 // chrome.downloads.onDeterminingFilename.
1568 // 1568 //
1569 // When the extension's event handler calls |suggestCallback|, 1569 // When the extension's event handler calls |suggestCallback|,
1570 // downloads_custom_bindings.js calls 1570 // downloads_custom_bindings.js calls
1571 // DownloadsInternalDetermineFilenameFunction::RunImpl, which calls 1571 // DownloadsInternalDetermineFilenameFunction::RunAsync, which calls
1572 // EDER::DetermineFilename, which notifies the item's EDERD. 1572 // EDER::DetermineFilename, which notifies the item's EDERD.
1573 // 1573 //
1574 // When the last extension's event handler returns, EDERD calls one of the two 1574 // When the last extension's event handler returns, EDERD calls one of the two
1575 // callbacks that CVRBD passed to ODF, allowing CDMD to complete the filename 1575 // callbacks that CVRBD passed to ODF, allowing CDMD to complete the filename
1576 // determination process. If multiple extensions wish to override the filename, 1576 // determination process. If multiple extensions wish to override the filename,
1577 // then the extension that was last installed wins. 1577 // then the extension that was last installed wins.
1578 1578
1579 void ExtensionDownloadsEventRouter::OnDeterminingFilename( 1579 void ExtensionDownloadsEventRouter::OnDeterminingFilename(
1580 DownloadItem* item, 1580 DownloadItem* item,
1581 const base::FilePath& suggested_path, 1581 const base::FilePath& suggested_path,
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 const extensions::Extension* extension, 1897 const extensions::Extension* extension,
1898 extensions::UnloadedExtensionInfo::Reason reason) { 1898 extensions::UnloadedExtensionInfo::Reason reason) {
1899 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1899 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1900 std::set<const extensions::Extension*>::iterator iter = 1900 std::set<const extensions::Extension*>::iterator iter =
1901 shelf_disabling_extensions_.find(extension); 1901 shelf_disabling_extensions_.find(extension);
1902 if (iter != shelf_disabling_extensions_.end()) 1902 if (iter != shelf_disabling_extensions_.end())
1903 shelf_disabling_extensions_.erase(iter); 1903 shelf_disabling_extensions_.erase(iter);
1904 } 1904 }
1905 1905
1906 } // namespace extensions 1906 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698