| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 im->LoadIcon(path, | 327 im->LoadIcon(path, |
| 328 icon_size, | 328 icon_size, |
| 329 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete, | 329 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete, |
| 330 base::Unretained(this), scale, callback), | 330 base::Unretained(this), scale, callback), |
| 331 &cancelable_task_tracker_); | 331 &cancelable_task_tracker_); |
| 332 return true; | 332 return true; |
| 333 } | 333 } |
| 334 | 334 |
| 335 void DownloadFileIconExtractorImpl::OnIconLoadComplete( | 335 void DownloadFileIconExtractorImpl::OnIconLoadComplete( |
| 336 float scale, const IconURLCallback& callback, gfx::Image* icon) { | 336 float scale, const IconURLCallback& callback, gfx::Image* icon) { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 338 callback.Run(!icon ? std::string() : webui::GetBitmapDataUrl( | 338 callback.Run(!icon ? std::string() : webui::GetBitmapDataUrl( |
| 339 icon->ToImageSkia()->GetRepresentation(scale).sk_bitmap())); | 339 icon->ToImageSkia()->GetRepresentation(scale).sk_bitmap())); |
| 340 } | 340 } |
| 341 | 341 |
| 342 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { | 342 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { |
| 343 switch (pixel_size) { | 343 switch (pixel_size) { |
| 344 case 16: return IconLoader::SMALL; | 344 case 16: return IconLoader::SMALL; |
| 345 case 32: return IconLoader::NORMAL; | 345 case 32: return IconLoader::NORMAL; |
| 346 default: | 346 default: |
| 347 NOTREACHED(); | 347 NOTREACHED(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 explicit ExtensionDownloadsEventRouterData( | 593 explicit ExtensionDownloadsEventRouterData( |
| 594 DownloadItem* download_item, | 594 DownloadItem* download_item, |
| 595 scoped_ptr<base::DictionaryValue> json_item) | 595 scoped_ptr<base::DictionaryValue> json_item) |
| 596 : updated_(0), | 596 : updated_(0), |
| 597 changed_fired_(0), | 597 changed_fired_(0), |
| 598 json_(json_item.Pass()), | 598 json_(json_item.Pass()), |
| 599 creator_conflict_action_( | 599 creator_conflict_action_( |
| 600 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY), | 600 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY), |
| 601 determined_conflict_action_( | 601 determined_conflict_action_( |
| 602 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY) { | 602 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY) { |
| 603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 603 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 604 download_item->SetUserData(kKey, this); | 604 download_item->SetUserData(kKey, this); |
| 605 } | 605 } |
| 606 | 606 |
| 607 virtual ~ExtensionDownloadsEventRouterData() { | 607 virtual ~ExtensionDownloadsEventRouterData() { |
| 608 if (updated_ > 0) { | 608 if (updated_ > 0) { |
| 609 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", | 609 UMA_HISTOGRAM_PERCENTAGE("Download.OnChanged", |
| 610 (changed_fired_ * 100 / updated_)); | 610 (changed_fired_ * 100 / updated_)); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 | 613 |
| 614 const base::DictionaryValue& json() const { return *json_.get(); } | 614 const base::DictionaryValue& json() const { return *json_.get(); } |
| 615 void set_json(scoped_ptr<base::DictionaryValue> json_item) { | 615 void set_json(scoped_ptr<base::DictionaryValue> json_item) { |
| 616 json_ = json_item.Pass(); | 616 json_ = json_item.Pass(); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void OnItemUpdated() { ++updated_; } | 619 void OnItemUpdated() { ++updated_; } |
| 620 void OnChangedFired() { ++changed_fired_; } | 620 void OnChangedFired() { ++changed_fired_; } |
| 621 | 621 |
| 622 void set_filename_change_callbacks( | 622 void set_filename_change_callbacks( |
| 623 const base::Closure& no_change, | 623 const base::Closure& no_change, |
| 624 const ExtensionDownloadsEventRouter::FilenameChangedCallback& change) { | 624 const ExtensionDownloadsEventRouter::FilenameChangedCallback& change) { |
| 625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 625 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 626 filename_no_change_ = no_change; | 626 filename_no_change_ = no_change; |
| 627 filename_change_ = change; | 627 filename_change_ = change; |
| 628 determined_filename_ = creator_suggested_filename_; | 628 determined_filename_ = creator_suggested_filename_; |
| 629 determined_conflict_action_ = creator_conflict_action_; | 629 determined_conflict_action_ = creator_conflict_action_; |
| 630 // determiner_.install_time should default to 0 so that creator suggestions | 630 // determiner_.install_time should default to 0 so that creator suggestions |
| 631 // should be lower priority than any actual onDeterminingFilename listeners. | 631 // should be lower priority than any actual onDeterminingFilename listeners. |
| 632 } | 632 } |
| 633 | 633 |
| 634 void ClearPendingDeterminers() { | 634 void ClearPendingDeterminers() { |
| 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 635 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 636 determined_filename_.clear(); | 636 determined_filename_.clear(); |
| 637 determined_conflict_action_ = | 637 determined_conflict_action_ = |
| 638 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY; | 638 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY; |
| 639 determiner_ = DeterminerInfo(); | 639 determiner_ = DeterminerInfo(); |
| 640 filename_no_change_ = base::Closure(); | 640 filename_no_change_ = base::Closure(); |
| 641 filename_change_ = ExtensionDownloadsEventRouter::FilenameChangedCallback(); | 641 filename_change_ = ExtensionDownloadsEventRouter::FilenameChangedCallback(); |
| 642 weak_ptr_factory_.reset(); | 642 weak_ptr_factory_.reset(); |
| 643 determiners_.clear(); | 643 determiners_.clear(); |
| 644 } | 644 } |
| 645 | 645 |
| 646 void DeterminerRemoved(const std::string& extension_id) { | 646 void DeterminerRemoved(const std::string& extension_id) { |
| 647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 647 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 648 for (DeterminerInfoVector::iterator iter = determiners_.begin(); | 648 for (DeterminerInfoVector::iterator iter = determiners_.begin(); |
| 649 iter != determiners_.end();) { | 649 iter != determiners_.end();) { |
| 650 if (iter->extension_id == extension_id) { | 650 if (iter->extension_id == extension_id) { |
| 651 iter = determiners_.erase(iter); | 651 iter = determiners_.erase(iter); |
| 652 } else { | 652 } else { |
| 653 ++iter; | 653 ++iter; |
| 654 } | 654 } |
| 655 } | 655 } |
| 656 // If we just removed the last unreported determiner, then we need to call a | 656 // If we just removed the last unreported determiner, then we need to call a |
| 657 // callback. | 657 // callback. |
| 658 CheckAllDeterminersCalled(); | 658 CheckAllDeterminersCalled(); |
| 659 } | 659 } |
| 660 | 660 |
| 661 void AddPendingDeterminer(const std::string& extension_id, | 661 void AddPendingDeterminer(const std::string& extension_id, |
| 662 const base::Time& installed) { | 662 const base::Time& installed) { |
| 663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 663 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 664 for (size_t index = 0; index < determiners_.size(); ++index) { | 664 for (size_t index = 0; index < determiners_.size(); ++index) { |
| 665 if (determiners_[index].extension_id == extension_id) { | 665 if (determiners_[index].extension_id == extension_id) { |
| 666 DCHECK(false) << extension_id; | 666 DCHECK(false) << extension_id; |
| 667 return; | 667 return; |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 determiners_.push_back(DeterminerInfo(extension_id, installed)); | 670 determiners_.push_back(DeterminerInfo(extension_id, installed)); |
| 671 } | 671 } |
| 672 | 672 |
| 673 bool DeterminerAlreadyReported(const std::string& extension_id) { | 673 bool DeterminerAlreadyReported(const std::string& extension_id) { |
| 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 675 for (size_t index = 0; index < determiners_.size(); ++index) { | 675 for (size_t index = 0; index < determiners_.size(); ++index) { |
| 676 if (determiners_[index].extension_id == extension_id) { | 676 if (determiners_[index].extension_id == extension_id) { |
| 677 return determiners_[index].reported; | 677 return determiners_[index].reported; |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 return false; | 680 return false; |
| 681 } | 681 } |
| 682 | 682 |
| 683 void CreatorSuggestedFilename( | 683 void CreatorSuggestedFilename( |
| 684 const base::FilePath& filename, | 684 const base::FilePath& filename, |
| 685 downloads::FilenameConflictAction conflict_action) { | 685 downloads::FilenameConflictAction conflict_action) { |
| 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 686 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 687 creator_suggested_filename_ = filename; | 687 creator_suggested_filename_ = filename; |
| 688 creator_conflict_action_ = conflict_action; | 688 creator_conflict_action_ = conflict_action; |
| 689 } | 689 } |
| 690 | 690 |
| 691 base::FilePath creator_suggested_filename() const { | 691 base::FilePath creator_suggested_filename() const { |
| 692 return creator_suggested_filename_; | 692 return creator_suggested_filename_; |
| 693 } | 693 } |
| 694 | 694 |
| 695 downloads::FilenameConflictAction | 695 downloads::FilenameConflictAction |
| 696 creator_conflict_action() const { | 696 creator_conflict_action() const { |
| 697 return creator_conflict_action_; | 697 return creator_conflict_action_; |
| 698 } | 698 } |
| 699 | 699 |
| 700 void ResetCreatorSuggestion() { | 700 void ResetCreatorSuggestion() { |
| 701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 701 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 702 creator_suggested_filename_.clear(); | 702 creator_suggested_filename_.clear(); |
| 703 creator_conflict_action_ = | 703 creator_conflict_action_ = |
| 704 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY; | 704 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY; |
| 705 } | 705 } |
| 706 | 706 |
| 707 // Returns false if this |extension_id| was not expected or if this | 707 // Returns false if this |extension_id| was not expected or if this |
| 708 // |extension_id| has already reported. The caller is responsible for | 708 // |extension_id| has already reported. The caller is responsible for |
| 709 // validating |filename|. | 709 // validating |filename|. |
| 710 bool DeterminerCallback( | 710 bool DeterminerCallback( |
| 711 Profile* profile, | 711 Profile* profile, |
| 712 const std::string& extension_id, | 712 const std::string& extension_id, |
| 713 const base::FilePath& filename, | 713 const base::FilePath& filename, |
| 714 downloads::FilenameConflictAction conflict_action) { | 714 downloads::FilenameConflictAction conflict_action) { |
| 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 715 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 716 bool found_info = false; | 716 bool found_info = false; |
| 717 for (size_t index = 0; index < determiners_.size(); ++index) { | 717 for (size_t index = 0; index < determiners_.size(); ++index) { |
| 718 if (determiners_[index].extension_id == extension_id) { | 718 if (determiners_[index].extension_id == extension_id) { |
| 719 found_info = true; | 719 found_info = true; |
| 720 if (determiners_[index].reported) | 720 if (determiners_[index].reported) |
| 721 return false; | 721 return false; |
| 722 determiners_[index].reported = true; | 722 determiners_[index].reported = true; |
| 723 // Do not use filename if another determiner has already overridden the | 723 // Do not use filename if another determiner has already overridden the |
| 724 // filename and they take precedence. Extensions that were installed | 724 // filename and they take precedence. Extensions that were installed |
| 725 // later take precedence over previous extensions. | 725 // later take precedence over previous extensions. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION); | 1036 RecordDownloadSource(DOWNLOAD_INITIATED_BY_EXTENSION); |
| 1037 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); | 1037 RecordApiFunctions(DOWNLOADS_FUNCTION_DOWNLOAD); |
| 1038 return true; | 1038 return true; |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 void DownloadsDownloadFunction::OnStarted( | 1041 void DownloadsDownloadFunction::OnStarted( |
| 1042 const base::FilePath& creator_suggested_filename, | 1042 const base::FilePath& creator_suggested_filename, |
| 1043 downloads::FilenameConflictAction creator_conflict_action, | 1043 downloads::FilenameConflictAction creator_conflict_action, |
| 1044 DownloadItem* item, | 1044 DownloadItem* item, |
| 1045 content::DownloadInterruptReason interrupt_reason) { | 1045 content::DownloadInterruptReason interrupt_reason) { |
| 1046 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1046 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1047 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason; | 1047 VLOG(1) << __FUNCTION__ << " " << item << " " << interrupt_reason; |
| 1048 if (item) { | 1048 if (item) { |
| 1049 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); | 1049 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 1050 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); | 1050 SetResult(new base::FundamentalValue(static_cast<int>(item->GetId()))); |
| 1051 if (!creator_suggested_filename.empty()) { | 1051 if (!creator_suggested_filename.empty()) { |
| 1052 ExtensionDownloadsEventRouterData* data = | 1052 ExtensionDownloadsEventRouterData* data = |
| 1053 ExtensionDownloadsEventRouterData::Get(item); | 1053 ExtensionDownloadsEventRouterData::Get(item); |
| 1054 if (!data) { | 1054 if (!data) { |
| 1055 data = new ExtensionDownloadsEventRouterData( | 1055 data = new ExtensionDownloadsEventRouterData( |
| 1056 item, | 1056 item, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 Fault(download_item->GetFileExternallyRemoved(), | 1219 Fault(download_item->GetFileExternallyRemoved(), |
| 1220 errors::kFileAlreadyDeleted, &error_)) | 1220 errors::kFileAlreadyDeleted, &error_)) |
| 1221 return false; | 1221 return false; |
| 1222 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); | 1222 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); |
| 1223 download_item->DeleteFile( | 1223 download_item->DeleteFile( |
| 1224 base::Bind(&DownloadsRemoveFileFunction::Done, this)); | 1224 base::Bind(&DownloadsRemoveFileFunction::Done, this)); |
| 1225 return true; | 1225 return true; |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 void DownloadsRemoveFileFunction::Done(bool success) { | 1228 void DownloadsRemoveFileFunction::Done(bool success) { |
| 1229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1229 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1230 if (!success) { | 1230 if (!success) { |
| 1231 error_ = errors::kFileNotRemoved; | 1231 error_ = errors::kFileNotRemoved; |
| 1232 } | 1232 } |
| 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 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 base::Bind(&DownloadsAcceptDangerFunction::DangerPromptCallback, | 1286 base::Bind(&DownloadsAcceptDangerFunction::DangerPromptCallback, |
| 1287 this, download_id)); | 1287 this, download_id)); |
| 1288 // DownloadDangerPrompt deletes itself | 1288 // DownloadDangerPrompt deletes itself |
| 1289 if (on_prompt_created_ && !on_prompt_created_->is_null()) | 1289 if (on_prompt_created_ && !on_prompt_created_->is_null()) |
| 1290 on_prompt_created_->Run(prompt); | 1290 on_prompt_created_->Run(prompt); |
| 1291 SendResponse(error_.empty()); | 1291 SendResponse(error_.empty()); |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 void DownloadsAcceptDangerFunction::DangerPromptCallback( | 1294 void DownloadsAcceptDangerFunction::DangerPromptCallback( |
| 1295 int download_id, DownloadDangerPrompt::Action action) { | 1295 int download_id, DownloadDangerPrompt::Action action) { |
| 1296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1297 DownloadItem* download_item = | 1297 DownloadItem* download_item = |
| 1298 GetDownload(GetProfile(), include_incognito(), download_id); | 1298 GetDownload(GetProfile(), include_incognito(), download_id); |
| 1299 if (InvalidId(download_item, &error_) || | 1299 if (InvalidId(download_item, &error_) || |
| 1300 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, | 1300 Fault(download_item->GetState() != DownloadItem::IN_PROGRESS, |
| 1301 errors::kNotInProgress, &error_)) | 1301 errors::kNotInProgress, &error_)) |
| 1302 return; | 1302 return; |
| 1303 switch (action) { | 1303 switch (action) { |
| 1304 case DownloadDangerPrompt::ACCEPT: | 1304 case DownloadDangerPrompt::ACCEPT: |
| 1305 download_item->ValidateDangerousDownload(); | 1305 download_item->ValidateDangerousDownload(); |
| 1306 break; | 1306 break; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } | 1495 } |
| 1496 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( | 1496 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( |
| 1497 download_item->GetTargetFilePath(), | 1497 download_item->GetTargetFilePath(), |
| 1498 scale, | 1498 scale, |
| 1499 IconLoaderSizeFromPixelSize(icon_size), | 1499 IconLoaderSizeFromPixelSize(icon_size), |
| 1500 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); | 1500 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); |
| 1501 return true; | 1501 return true; |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { | 1504 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { |
| 1505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1505 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1506 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { | 1506 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { |
| 1507 SendResponse(false); | 1507 SendResponse(false); |
| 1508 return; | 1508 return; |
| 1509 } | 1509 } |
| 1510 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); | 1510 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); |
| 1511 SetResult(new base::StringValue(url)); | 1511 SetResult(new base::StringValue(url)); |
| 1512 SendResponse(true); | 1512 SendResponse(true); |
| 1513 } | 1513 } |
| 1514 | 1514 |
| 1515 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 1515 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( |
| 1516 Profile* profile, | 1516 Profile* profile, |
| 1517 DownloadManager* manager) | 1517 DownloadManager* manager) |
| 1518 : profile_(profile), | 1518 : profile_(profile), |
| 1519 notifier_(manager, this) { | 1519 notifier_(manager, this) { |
| 1520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1520 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1521 DCHECK(profile_); | 1521 DCHECK(profile_); |
| 1522 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 1522 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 1523 content::Source<Profile>(profile_)); | 1523 content::Source<Profile>(profile_)); |
| 1524 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1524 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> |
| 1525 event_router(); | 1525 event_router(); |
| 1526 if (router) | 1526 if (router) |
| 1527 router->RegisterObserver(this, | 1527 router->RegisterObserver(this, |
| 1528 downloads::OnDeterminingFilename::kEventName); | 1528 downloads::OnDeterminingFilename::kEventName); |
| 1529 } | 1529 } |
| 1530 | 1530 |
| 1531 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { | 1531 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { |
| 1532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1532 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1533 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1533 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> |
| 1534 event_router(); | 1534 event_router(); |
| 1535 if (router) | 1535 if (router) |
| 1536 router->UnregisterObserver(this); | 1536 router->UnregisterObserver(this); |
| 1537 } | 1537 } |
| 1538 | 1538 |
| 1539 void ExtensionDownloadsEventRouter::SetShelfEnabled( | 1539 void ExtensionDownloadsEventRouter::SetShelfEnabled( |
| 1540 const extensions::Extension* extension, bool enabled) { | 1540 const extensions::Extension* extension, bool enabled) { |
| 1541 std::set<const extensions::Extension*>::iterator iter = | 1541 std::set<const extensions::Extension*>::iterator iter = |
| 1542 shelf_disabling_extensions_.find(extension); | 1542 shelf_disabling_extensions_.find(extension); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 // When the last extension's event handler returns, EDERD calls one of the two | 1575 // When the last extension's event handler returns, EDERD calls one of the two |
| 1576 // callbacks that CVRBD passed to ODF, allowing CDMD to complete the filename | 1576 // callbacks that CVRBD passed to ODF, allowing CDMD to complete the filename |
| 1577 // determination process. If multiple extensions wish to override the filename, | 1577 // determination process. If multiple extensions wish to override the filename, |
| 1578 // then the extension that was last installed wins. | 1578 // then the extension that was last installed wins. |
| 1579 | 1579 |
| 1580 void ExtensionDownloadsEventRouter::OnDeterminingFilename( | 1580 void ExtensionDownloadsEventRouter::OnDeterminingFilename( |
| 1581 DownloadItem* item, | 1581 DownloadItem* item, |
| 1582 const base::FilePath& suggested_path, | 1582 const base::FilePath& suggested_path, |
| 1583 const base::Closure& no_change, | 1583 const base::Closure& no_change, |
| 1584 const FilenameChangedCallback& change) { | 1584 const FilenameChangedCallback& change) { |
| 1585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1585 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1586 ExtensionDownloadsEventRouterData* data = | 1586 ExtensionDownloadsEventRouterData* data = |
| 1587 ExtensionDownloadsEventRouterData::Get(item); | 1587 ExtensionDownloadsEventRouterData::Get(item); |
| 1588 if (!data) { | 1588 if (!data) { |
| 1589 no_change.Run(); | 1589 no_change.Run(); |
| 1590 return; | 1590 return; |
| 1591 } | 1591 } |
| 1592 data->ClearPendingDeterminers(); | 1592 data->ClearPendingDeterminers(); |
| 1593 data->set_filename_change_callbacks(no_change, change); | 1593 data->set_filename_change_callbacks(no_change, change); |
| 1594 bool any_determiners = false; | 1594 bool any_determiners = false; |
| 1595 base::DictionaryValue* json = DownloadItemToJSON( | 1595 base::DictionaryValue* json = DownloadItemToJSON( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 bool ExtensionDownloadsEventRouter::DetermineFilename( | 1661 bool ExtensionDownloadsEventRouter::DetermineFilename( |
| 1662 Profile* profile, | 1662 Profile* profile, |
| 1663 bool include_incognito, | 1663 bool include_incognito, |
| 1664 const std::string& ext_id, | 1664 const std::string& ext_id, |
| 1665 int download_id, | 1665 int download_id, |
| 1666 const base::FilePath& const_filename, | 1666 const base::FilePath& const_filename, |
| 1667 downloads::FilenameConflictAction conflict_action, | 1667 downloads::FilenameConflictAction conflict_action, |
| 1668 std::string* error) { | 1668 std::string* error) { |
| 1669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1669 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1670 DownloadItem* item = GetDownload(profile, include_incognito, download_id); | 1670 DownloadItem* item = GetDownload(profile, include_incognito, download_id); |
| 1671 ExtensionDownloadsEventRouterData* data = | 1671 ExtensionDownloadsEventRouterData* data = |
| 1672 item ? ExtensionDownloadsEventRouterData::Get(item) : NULL; | 1672 item ? ExtensionDownloadsEventRouterData::Get(item) : NULL; |
| 1673 // maxListeners=1 in downloads.idl and suggestCallback in | 1673 // maxListeners=1 in downloads.idl and suggestCallback in |
| 1674 // downloads_custom_bindings.js should prevent duplicate DeterminerCallback | 1674 // downloads_custom_bindings.js should prevent duplicate DeterminerCallback |
| 1675 // calls from the same renderer, but an extension may have more than one | 1675 // calls from the same renderer, but an extension may have more than one |
| 1676 // renderer, so don't DCHECK(!reported). | 1676 // renderer, so don't DCHECK(!reported). |
| 1677 if (InvalidId(item, error) || | 1677 if (InvalidId(item, error) || |
| 1678 Fault(item->GetState() != DownloadItem::IN_PROGRESS, | 1678 Fault(item->GetState() != DownloadItem::IN_PROGRESS, |
| 1679 errors::kNotInProgress, error) || | 1679 errors::kNotInProgress, error) || |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1695 profile, ext_id, filename, conflict_action), | 1695 profile, ext_id, filename, conflict_action), |
| 1696 errors::kUnexpectedDeterminer, error) || | 1696 errors::kUnexpectedDeterminer, error) || |
| 1697 Fault((!const_filename.empty() && !valid_filename), | 1697 Fault((!const_filename.empty() && !valid_filename), |
| 1698 errors::kInvalidFilename, error)) | 1698 errors::kInvalidFilename, error)) |
| 1699 return false; | 1699 return false; |
| 1700 return true; | 1700 return true; |
| 1701 } | 1701 } |
| 1702 | 1702 |
| 1703 void ExtensionDownloadsEventRouter::OnListenerRemoved( | 1703 void ExtensionDownloadsEventRouter::OnListenerRemoved( |
| 1704 const extensions::EventListenerInfo& details) { | 1704 const extensions::EventListenerInfo& details) { |
| 1705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1705 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1706 DownloadManager* manager = notifier_.GetManager(); | 1706 DownloadManager* manager = notifier_.GetManager(); |
| 1707 if (!manager) | 1707 if (!manager) |
| 1708 return; | 1708 return; |
| 1709 bool determiner_removed = ( | 1709 bool determiner_removed = ( |
| 1710 details.event_name == downloads::OnDeterminingFilename::kEventName); | 1710 details.event_name == downloads::OnDeterminingFilename::kEventName); |
| 1711 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1711 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> |
| 1712 event_router(); | 1712 event_router(); |
| 1713 bool any_listeners = | 1713 bool any_listeners = |
| 1714 router->HasEventListener(downloads::OnChanged::kEventName) || | 1714 router->HasEventListener(downloads::OnChanged::kEventName) || |
| 1715 router->HasEventListener(downloads::OnDeterminingFilename::kEventName); | 1715 router->HasEventListener(downloads::OnDeterminingFilename::kEventName); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1737 ExtensionDownloadsEventRouterData::Remove(*iter); | 1737 ExtensionDownloadsEventRouterData::Remove(*iter); |
| 1738 } | 1738 } |
| 1739 } | 1739 } |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 // That's all the methods that have to do with filename determination. The rest | 1742 // That's all the methods that have to do with filename determination. The rest |
| 1743 // have to do with the other, less special events. | 1743 // have to do with the other, less special events. |
| 1744 | 1744 |
| 1745 void ExtensionDownloadsEventRouter::OnDownloadCreated( | 1745 void ExtensionDownloadsEventRouter::OnDownloadCreated( |
| 1746 DownloadManager* manager, DownloadItem* download_item) { | 1746 DownloadManager* manager, DownloadItem* download_item) { |
| 1747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1747 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1748 if (download_item->IsTemporary()) | 1748 if (download_item->IsTemporary()) |
| 1749 return; | 1749 return; |
| 1750 | 1750 |
| 1751 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1751 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> |
| 1752 event_router(); | 1752 event_router(); |
| 1753 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going | 1753 // Avoid allocating a bunch of memory in DownloadItemToJSON if it isn't going |
| 1754 // to be used. | 1754 // to be used. |
| 1755 if (!router || | 1755 if (!router || |
| 1756 (!router->HasEventListener(downloads::OnCreated::kEventName) && | 1756 (!router->HasEventListener(downloads::OnCreated::kEventName) && |
| 1757 !router->HasEventListener(downloads::OnChanged::kEventName) && | 1757 !router->HasEventListener(downloads::OnChanged::kEventName) && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1768 if (!ExtensionDownloadsEventRouterData::Get(download_item) && | 1768 if (!ExtensionDownloadsEventRouterData::Get(download_item) && |
| 1769 (router->HasEventListener(downloads::OnChanged::kEventName) || | 1769 (router->HasEventListener(downloads::OnChanged::kEventName) || |
| 1770 router->HasEventListener( | 1770 router->HasEventListener( |
| 1771 downloads::OnDeterminingFilename::kEventName))) { | 1771 downloads::OnDeterminingFilename::kEventName))) { |
| 1772 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass()); | 1772 new ExtensionDownloadsEventRouterData(download_item, json_item.Pass()); |
| 1773 } | 1773 } |
| 1774 } | 1774 } |
| 1775 | 1775 |
| 1776 void ExtensionDownloadsEventRouter::OnDownloadUpdated( | 1776 void ExtensionDownloadsEventRouter::OnDownloadUpdated( |
| 1777 DownloadManager* manager, DownloadItem* download_item) { | 1777 DownloadManager* manager, DownloadItem* download_item) { |
| 1778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1778 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1779 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> | 1779 extensions::EventRouter* router = extensions::ExtensionSystem::Get(profile_)-> |
| 1780 event_router(); | 1780 event_router(); |
| 1781 ExtensionDownloadsEventRouterData* data = | 1781 ExtensionDownloadsEventRouterData* data = |
| 1782 ExtensionDownloadsEventRouterData::Get(download_item); | 1782 ExtensionDownloadsEventRouterData::Get(download_item); |
| 1783 if (download_item->IsTemporary() || | 1783 if (download_item->IsTemporary() || |
| 1784 !router->HasEventListener(downloads::OnChanged::kEventName)) { | 1784 !router->HasEventListener(downloads::OnChanged::kEventName)) { |
| 1785 return; | 1785 return; |
| 1786 } | 1786 } |
| 1787 if (!data) { | 1787 if (!data) { |
| 1788 // The download_item probably transitioned from temporary to not temporary, | 1788 // The download_item probably transitioned from temporary to not temporary, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 true, | 1838 true, |
| 1839 extensions::Event::WillDispatchCallback(), | 1839 extensions::Event::WillDispatchCallback(), |
| 1840 delta.release()); | 1840 delta.release()); |
| 1841 data->OnChangedFired(); | 1841 data->OnChangedFired(); |
| 1842 } | 1842 } |
| 1843 data->set_json(new_json.Pass()); | 1843 data->set_json(new_json.Pass()); |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 void ExtensionDownloadsEventRouter::OnDownloadRemoved( | 1846 void ExtensionDownloadsEventRouter::OnDownloadRemoved( |
| 1847 DownloadManager* manager, DownloadItem* download_item) { | 1847 DownloadManager* manager, DownloadItem* download_item) { |
| 1848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1848 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1849 if (download_item->IsTemporary()) | 1849 if (download_item->IsTemporary()) |
| 1850 return; | 1850 return; |
| 1851 DispatchEvent(downloads::OnErased::kEventName, | 1851 DispatchEvent(downloads::OnErased::kEventName, |
| 1852 true, | 1852 true, |
| 1853 extensions::Event::WillDispatchCallback(), | 1853 extensions::Event::WillDispatchCallback(), |
| 1854 new base::FundamentalValue( | 1854 new base::FundamentalValue( |
| 1855 static_cast<int>(download_item->GetId()))); | 1855 static_cast<int>(download_item->GetId()))); |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 void ExtensionDownloadsEventRouter::DispatchEvent( | 1858 void ExtensionDownloadsEventRouter::DispatchEvent( |
| 1859 const std::string& event_name, | 1859 const std::string& event_name, |
| 1860 bool include_incognito, | 1860 bool include_incognito, |
| 1861 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 1861 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
| 1862 base::Value* arg) { | 1862 base::Value* arg) { |
| 1863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1863 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1864 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) | 1864 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) |
| 1865 return; | 1865 return; |
| 1866 scoped_ptr<base::ListValue> args(new base::ListValue()); | 1866 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 1867 args->Append(arg); | 1867 args->Append(arg); |
| 1868 std::string json_args; | 1868 std::string json_args; |
| 1869 base::JSONWriter::Write(args.get(), &json_args); | 1869 base::JSONWriter::Write(args.get(), &json_args); |
| 1870 scoped_ptr<extensions::Event> event(new extensions::Event( | 1870 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 1871 event_name, args.Pass())); | 1871 event_name, args.Pass())); |
| 1872 // The downloads system wants to share on-record events with off-record | 1872 // The downloads system wants to share on-record events with off-record |
| 1873 // extension renderers even in incognito_split_mode because that's how | 1873 // extension renderers even in incognito_split_mode because that's how |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1887 content::NotificationService::current()->Notify( | 1887 content::NotificationService::current()->Notify( |
| 1888 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | 1888 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, |
| 1889 content_source, | 1889 content_source, |
| 1890 content::Details<std::string>(&json_args)); | 1890 content::Details<std::string>(&json_args)); |
| 1891 } | 1891 } |
| 1892 | 1892 |
| 1893 void ExtensionDownloadsEventRouter::Observe( | 1893 void ExtensionDownloadsEventRouter::Observe( |
| 1894 int type, | 1894 int type, |
| 1895 const content::NotificationSource& source, | 1895 const content::NotificationSource& source, |
| 1896 const content::NotificationDetails& details) { | 1896 const content::NotificationDetails& details) { |
| 1897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1897 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1898 switch (type) { | 1898 switch (type) { |
| 1899 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 1899 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
| 1900 extensions::UnloadedExtensionInfo* unloaded = | 1900 extensions::UnloadedExtensionInfo* unloaded = |
| 1901 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1901 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 1902 std::set<const extensions::Extension*>::iterator iter = | 1902 std::set<const extensions::Extension*>::iterator iter = |
| 1903 shelf_disabling_extensions_.find(unloaded->extension); | 1903 shelf_disabling_extensions_.find(unloaded->extension); |
| 1904 if (iter != shelf_disabling_extensions_.end()) | 1904 if (iter != shelf_disabling_extensions_.end()) |
| 1905 shelf_disabling_extensions_.erase(iter); | 1905 shelf_disabling_extensions_.erase(iter); |
| 1906 break; | 1906 break; |
| 1907 } | 1907 } |
| 1908 } | 1908 } |
| 1909 } | 1909 } |
| OLD | NEW |