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/chromeos/extensions/file_handler_util.h" | 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 handler, | 540 handler, |
541 handler_pid, | 541 handler_pid, |
542 action_id_, | 542 action_id_, |
543 file_urls)); | 543 file_urls)); |
544 } | 544 } |
545 | 545 |
546 void FileTaskExecutor::ExecuteFailedOnUIThread() { | 546 void FileTaskExecutor::ExecuteFailedOnUIThread() { |
547 Done(false); | 547 Done(false); |
548 } | 548 } |
549 | 549 |
| 550 const Extension* FileTaskExecutor::GetExtension() { |
| 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 552 |
| 553 ExtensionService* service = profile_->GetExtensionService(); |
| 554 return service ? service->GetExtensionById(extension_id_, false) : |
| 555 NULL; |
| 556 } |
| 557 |
550 void FileTaskExecutor::ExecuteFileActionsOnUIThread( | 558 void FileTaskExecutor::ExecuteFileActionsOnUIThread( |
551 const std::string& file_system_name, | 559 const std::string& file_system_name, |
552 const GURL& file_system_root, | 560 const GURL& file_system_root, |
553 const FileDefinitionList& file_list, | 561 const FileDefinitionList& file_list, |
554 int handler_pid) { | 562 int handler_pid) { |
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
556 | 564 |
557 ExtensionService* service = profile_->GetExtensionService(); | 565 const Extension* extension = GetExtension(); |
558 if (!service) { | |
559 Done(false); | |
560 return; | |
561 } | |
562 | |
563 const Extension* extension = service->GetExtensionById(extension_id_, false); | |
564 if (!extension) { | 566 if (!extension) { |
565 Done(false); | 567 Done(false); |
566 return; | 568 return; |
567 } | 569 } |
568 | 570 |
569 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_); | 571 InitHandlerHostFileAccessPermissions( |
| 572 file_list, |
| 573 extension, |
| 574 action_id_, |
| 575 base::Bind(&FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, |
| 576 this, |
| 577 file_system_name, |
| 578 file_system_root, |
| 579 file_list, |
| 580 handler_pid)); |
| 581 } |
| 582 |
| 583 void FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( |
| 584 const std::string& file_system_name, |
| 585 const GURL& file_system_root, |
| 586 const FileDefinitionList& file_list, |
| 587 int handler_pid) { |
| 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 589 |
| 590 const Extension* extension = GetExtension(); |
| 591 if (!extension) { |
| 592 Done(false); |
| 593 return; |
| 594 } |
570 | 595 |
571 if (handler_pid > 0) { | 596 if (handler_pid > 0) { |
572 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, | 597 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, |
573 file_list, handler_pid, NULL); | 598 file_list, handler_pid, NULL); |
574 } else { | 599 } else { |
575 // We have to wake the handler background page before we proceed. | 600 // We have to wake the handler background page before we proceed. |
576 extensions::LazyBackgroundTaskQueue* queue = | 601 extensions::LazyBackgroundTaskQueue* queue = |
577 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 602 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
578 if (!queue->ShouldEnqueueTask(profile_, extension)) { | 603 if (!queue->ShouldEnqueueTask(profile_, extension)) { |
579 Done(false); | 604 Done(false); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 extension_id_, std::string("fileBrowserHandler.onExecute"), | 667 extension_id_, std::string("fileBrowserHandler.onExecute"), |
643 json_args, profile_, | 668 json_args, profile_, |
644 GURL()); | 669 GURL()); |
645 | 670 |
646 Done(true); | 671 Done(true); |
647 } | 672 } |
648 | 673 |
649 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( | 674 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( |
650 const FileDefinitionList& file_list, | 675 const FileDefinitionList& file_list, |
651 const Extension* handler_extension, | 676 const Extension* handler_extension, |
652 const std::string& action_id) { | 677 const std::string& action_id, |
| 678 const base::Closure& callback) { |
653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
654 | 680 |
| 681 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); |
655 for (FileDefinitionList::const_iterator iter = file_list.begin(); | 682 for (FileDefinitionList::const_iterator iter = file_list.begin(); |
656 iter != file_list.end(); | 683 iter != file_list.end(); |
657 ++iter) { | 684 ++iter) { |
658 // Setup permission for file's absolute file. | 685 // Setup permission for file's absolute file. |
659 handler_host_permissions_.push_back(std::make_pair( | 686 handler_host_permissions_.push_back(std::make_pair( |
660 iter->absolute_path, | 687 iter->absolute_path, |
661 GetAccessPermissionsForHandler(handler_extension, action_id))); | 688 GetAccessPermissionsForHandler(handler_extension, action_id))); |
662 | 689 |
663 if (!gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) | 690 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) |
664 continue; | 691 gdata_paths->push_back(iter->virtual_path); |
| 692 } |
665 | 693 |
666 // If the file is on gdata mount point, we'll have to give handler host | 694 if (gdata_paths->empty()) { |
667 // permissions for file's gdata cache paths. | 695 // Invoke callback if none of the files are on gdata mount point. |
668 // This has to be called on UI thread. | 696 callback.Run(); |
669 gdata::util::InsertGDataCachePathsPermissions(profile_, iter->virtual_path, | 697 return; |
670 &handler_host_permissions_); | |
671 } | 698 } |
| 699 |
| 700 // For files on gdata mount point, we'll have to give handler host permissions |
| 701 // for their cache paths. This has to be called on UI thread. |
| 702 gdata::util::InsertGDataCachePathsPermissions(profile_, |
| 703 gdata_paths.Pass(), |
| 704 &handler_host_permissions_, |
| 705 callback); |
672 } | 706 } |
673 | 707 |
674 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { | 708 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { |
675 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { | 709 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { |
676 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 710 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
677 handler_pid, | 711 handler_pid, |
678 handler_host_permissions_[i].first, | 712 handler_host_permissions_[i].first, |
679 handler_host_permissions_[i].second); | 713 handler_host_permissions_[i].second); |
680 } | 714 } |
681 | 715 |
682 // We don't need this anymore. | 716 // We don't need this anymore. |
683 handler_host_permissions_.clear(); | 717 handler_host_permissions_.clear(); |
684 } | 718 } |
685 | 719 |
686 } // namespace file_handler_util | 720 } // namespace file_handler_util |
687 | 721 |
OLD | NEW |