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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "webkit/fileapi/file_system_url.h" | 42 #include "webkit/fileapi/file_system_url.h" |
43 #include "webkit/fileapi/file_system_util.h" | 43 #include "webkit/fileapi/file_system_util.h" |
44 #include "webkit/fileapi/isolated_context.h" | 44 #include "webkit/fileapi/isolated_context.h" |
45 | 45 |
46 using content::BrowserContext; | 46 using content::BrowserContext; |
47 using content::BrowserThread; | 47 using content::BrowserThread; |
48 using content::ChildProcessSecurityPolicy; | 48 using content::ChildProcessSecurityPolicy; |
49 using content::SiteInstance; | 49 using content::SiteInstance; |
50 using content::WebContents; | 50 using content::WebContents; |
51 using extensions::Extension; | 51 using extensions::Extension; |
| 52 using fileapi::FileSystemURL; |
52 | 53 |
53 namespace file_handler_util { | 54 namespace file_handler_util { |
54 | 55 |
55 const char kTaskFile[] = "file"; | 56 const char kTaskFile[] = "file"; |
56 const char kTaskDrive[] = "drive"; | 57 const char kTaskDrive[] = "drive"; |
57 const char kTaskWebIntent[] = "web-intent"; | 58 const char kTaskWebIntent[] = "web-intent"; |
58 const char kTaskApp[] = "app"; | 59 const char kTaskApp[] = "app"; |
59 | 60 |
60 namespace { | 61 namespace { |
61 | 62 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 while (iter != handler_set->end() && | 340 while (iter != handler_set->end() && |
340 !((*iter)->extension_id() == extension_id && | 341 !((*iter)->extension_id() == extension_id && |
341 (*iter)->id() == id)) { | 342 (*iter)->id() == id)) { |
342 iter++; | 343 iter++; |
343 } | 344 } |
344 return iter; | 345 return iter; |
345 } | 346 } |
346 | 347 |
347 // Given the list of selected files, returns array of file action tasks | 348 // Given the list of selected files, returns array of file action tasks |
348 // that are shared between them. | 349 // that are shared between them. |
| 350 // TODO(tbarzic): Pass set of file extensions instead file urls. |
349 void FindDefaultTasks(Profile* profile, | 351 void FindDefaultTasks(Profile* profile, |
350 const std::vector<GURL>& files_list, | 352 const std::vector<GURL>& files_list, |
351 const FileBrowserHandlerSet& common_tasks, | 353 const FileBrowserHandlerSet& common_tasks, |
352 FileBrowserHandlerSet* default_tasks) { | 354 FileBrowserHandlerSet* default_tasks) { |
353 DCHECK(default_tasks); | 355 DCHECK(default_tasks); |
354 default_tasks->clear(); | 356 default_tasks->clear(); |
355 | 357 |
356 std::set<std::string> default_ids; | 358 std::set<std::string> default_ids; |
357 for (std::vector<GURL>::const_iterator it = files_list.begin(); | 359 for (std::vector<GURL>::const_iterator it = files_list.begin(); |
358 it != files_list.end(); ++it) { | 360 it != files_list.end(); ++it) { |
359 // Get the default task for this file based only on the extension (since | 361 // Get the default task for this file based only on the extension (since |
360 // we don't have MIME types here), and add it to the set of default tasks. | 362 // we don't have MIME types here), and add it to the set of default tasks. |
361 fileapi::FileSystemURL filesystem_url(*it); | 363 // |
362 if (filesystem_url.is_valid() && | 364 // There is no need to crack the URL, since only path's extension is needed |
363 (filesystem_url.type() == fileapi::kFileSystemTypeDrive || | 365 // from FileSystemURL. |
364 filesystem_url.type() == fileapi::kFileSystemTypeNativeMedia || | 366 FileSystemURL non_cracked_url(*it); |
365 filesystem_url.type() == fileapi::kFileSystemTypeNativeLocal)) { | 367 DCHECK(non_cracked_url.is_valid() && |
366 std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs( | 368 non_cracked_url.type() == fileapi::kFileSystemTypeExternal); |
367 profile, "", filesystem_url.virtual_path().Extension()); | 369 |
368 if (!task_id.empty()) | 370 std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs( |
369 default_ids.insert(task_id); | 371 profile, "", non_cracked_url.path().Extension()); |
370 } | 372 if (!task_id.empty()) |
| 373 default_ids.insert(task_id); |
371 } | 374 } |
372 | 375 |
373 const FileBrowserHandler* builtin_task = NULL; | 376 const FileBrowserHandler* builtin_task = NULL; |
374 // Convert the default task IDs collected above to one of the handler pointers | 377 // Convert the default task IDs collected above to one of the handler pointers |
375 // from common_tasks. | 378 // from common_tasks. |
376 for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin(); | 379 for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin(); |
377 task_iter != common_tasks.end(); ++task_iter) { | 380 task_iter != common_tasks.end(); ++task_iter) { |
378 std::string task_id = MakeTaskID((*task_iter)->extension_id(), kTaskFile, | 381 std::string task_id = MakeTaskID((*task_iter)->extension_id(), kTaskFile, |
379 (*task_iter)->id()); | 382 (*task_iter)->id()); |
380 std::set<std::string>::iterator default_iter = default_ids.find(task_id); | 383 std::set<std::string>::iterator default_iter = default_ids.find(task_id); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 if (files_list.size() == 1) | 450 if (files_list.size() == 1) |
448 common_task_set.erase(gallery_iter); | 451 common_task_set.erase(gallery_iter); |
449 else | 452 else |
450 common_task_set.erase(watch_iter); | 453 common_task_set.erase(watch_iter); |
451 } | 454 } |
452 | 455 |
453 common_tasks->swap(common_task_set); | 456 common_tasks->swap(common_task_set); |
454 return true; | 457 return true; |
455 } | 458 } |
456 | 459 |
457 bool GetTaskForURL( | 460 bool GetTaskForURL(Profile* profile, |
458 Profile* profile, const GURL& url, const FileBrowserHandler** handler) { | 461 const GURL& url, |
| 462 const FileBrowserHandler** handler) { |
459 std::vector<GURL> file_urls; | 463 std::vector<GURL> file_urls; |
460 file_urls.push_back(url); | 464 file_urls.push_back(url); |
461 | 465 |
462 FileBrowserHandlerSet default_tasks; | 466 FileBrowserHandlerSet default_tasks; |
463 FileBrowserHandlerSet common_tasks; | 467 FileBrowserHandlerSet common_tasks; |
464 if (!FindCommonTasks(profile, file_urls, &common_tasks)) | 468 if (!FindCommonTasks(profile, file_urls, &common_tasks)) |
465 return false; | 469 return false; |
466 | 470 |
467 if (common_tasks.empty()) | 471 if (common_tasks.empty()) |
468 return false; | 472 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
481 // If there are no default tasks, use first task in the list (file manager | 485 // If there are no default tasks, use first task in the list (file manager |
482 // does the same in this situation). | 486 // does the same in this situation). |
483 // TODO(tbarzic): This is so not optimal behaviour. | 487 // TODO(tbarzic): This is so not optimal behaviour. |
484 *handler = *common_tasks.begin(); | 488 *handler = *common_tasks.begin(); |
485 return true; | 489 return true; |
486 } | 490 } |
487 | 491 |
488 class ExtensionTaskExecutor : public FileTaskExecutor { | 492 class ExtensionTaskExecutor : public FileTaskExecutor { |
489 public: | 493 public: |
490 // FileTaskExecutor overrides. | 494 // FileTaskExecutor overrides. |
491 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, | 495 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls, |
492 const FileTaskFinishedCallback& done) OVERRIDE; | 496 const FileTaskFinishedCallback& done) OVERRIDE; |
493 | 497 |
494 private: | 498 private: |
495 // FileTaskExecutor is the only class allowed to create one. | 499 // FileTaskExecutor is the only class allowed to create one. |
496 friend class FileTaskExecutor; | 500 friend class FileTaskExecutor; |
497 | 501 |
498 ExtensionTaskExecutor(Profile* profile, | 502 ExtensionTaskExecutor(Profile* profile, |
499 const GURL& source_url, | 503 const GURL& source_url, |
500 const std::string& file_browser_id, | 504 const std::string& file_browser_id, |
501 int32 tab_id, | 505 int32 tab_id, |
502 const std::string& extension_id, | 506 const std::string& extension_id, |
503 const std::string& action_id); | 507 const std::string& action_id); |
504 virtual ~ExtensionTaskExecutor(); | 508 virtual ~ExtensionTaskExecutor(); |
505 | 509 |
506 struct FileDefinition { | 510 struct FileDefinition { |
507 FileDefinition(); | 511 FileDefinition(); |
508 ~FileDefinition(); | 512 ~FileDefinition(); |
509 | 513 |
510 GURL target_file_url; | |
511 FilePath virtual_path; | 514 FilePath virtual_path; |
512 FilePath absolute_path; | 515 FilePath absolute_path; |
513 bool is_directory; | 516 bool is_directory; |
514 }; | 517 }; |
515 | 518 |
516 typedef std::vector<FileDefinition> FileDefinitionList; | 519 typedef std::vector<FileDefinition> FileDefinitionList; |
517 class ExecuteTasksFileSystemCallbackDispatcher; | 520 class ExecuteTasksFileSystemCallbackDispatcher; |
518 void RequestFileEntryOnFileThread( | 521 void RequestFileEntryOnFileThread( |
519 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 522 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, |
520 const GURL& handler_base_url, | 523 const GURL& handler_base_url, |
521 const scoped_refptr<const extensions::Extension>& handler, | 524 const scoped_refptr<const extensions::Extension>& handler, |
522 int handler_pid, | 525 int handler_pid, |
523 const std::vector<GURL>& file_urls); | 526 const std::vector<FileSystemURL>& file_urls); |
524 | 527 |
525 void ExecuteDoneOnUIThread(bool success); | 528 void ExecuteDoneOnUIThread(bool success); |
526 void ExecuteFileActionsOnUIThread(const std::string& file_system_name, | 529 void ExecuteFileActionsOnUIThread(const std::string& file_system_name, |
527 const GURL& file_system_root, | 530 const GURL& file_system_root, |
528 const FileDefinitionList& file_list, | 531 const FileDefinitionList& file_list, |
529 int handler_pid); | 532 int handler_pid); |
530 void SetupPermissionsAndDispatchEvent(const std::string& file_system_name, | 533 void SetupPermissionsAndDispatchEvent(const std::string& file_system_name, |
531 const GURL& file_system_root, | 534 const GURL& file_system_root, |
532 const FileDefinitionList& file_list, | 535 const FileDefinitionList& file_list, |
533 int handler_pid_in, | 536 int handler_pid_in, |
534 extensions::ExtensionHost* host); | 537 extensions::ExtensionHost* host); |
535 | 538 |
536 // Registers file permissions from |handler_host_permissions_| with | 539 // Registers file permissions from |handler_host_permissions_| with |
537 // ChildProcessSecurityPolicy for process with id |handler_pid|. | 540 // ChildProcessSecurityPolicy for process with id |handler_pid|. |
538 void SetupHandlerHostFileAccessPermissions( | 541 void SetupHandlerHostFileAccessPermissions( |
539 const FileDefinitionList& file_list, | 542 const FileDefinitionList& file_list, |
540 const Extension* extension, | 543 const Extension* extension, |
541 int handler_pid); | 544 int handler_pid); |
542 | 545 |
543 int32 tab_id_; | 546 int32 tab_id_; |
544 const std::string action_id_; | 547 const std::string action_id_; |
545 FileTaskFinishedCallback done_; | 548 FileTaskFinishedCallback done_; |
546 }; | 549 }; |
547 | 550 |
548 class WebIntentTaskExecutor : public FileTaskExecutor { | 551 class WebIntentTaskExecutor : public FileTaskExecutor { |
549 public: | 552 public: |
550 // FileTaskExecutor overrides. | 553 // FileTaskExecutor overrides. |
551 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, | 554 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls, |
552 const FileTaskFinishedCallback& done) OVERRIDE; | 555 const FileTaskFinishedCallback& done) OVERRIDE; |
553 | 556 |
554 private: | 557 private: |
555 // FileTaskExecutor is the only class allowed to create one. | 558 // FileTaskExecutor is the only class allowed to create one. |
556 friend class FileTaskExecutor; | 559 friend class FileTaskExecutor; |
557 | 560 |
558 WebIntentTaskExecutor(Profile* profile, | 561 WebIntentTaskExecutor(Profile* profile, |
559 const GURL& source_url, | 562 const GURL& source_url, |
560 const std::string& file_browser_id, | 563 const std::string& file_browser_id, |
561 const std::string& extension_id, | 564 const std::string& extension_id, |
562 const std::string& action_id); | 565 const std::string& action_id); |
563 virtual ~WebIntentTaskExecutor(); | 566 virtual ~WebIntentTaskExecutor(); |
564 | 567 |
565 const std::string extension_id_; | 568 const std::string extension_id_; |
566 const std::string action_id_; | 569 const std::string action_id_; |
567 }; | 570 }; |
568 | 571 |
569 class AppTaskExecutor : public FileTaskExecutor { | 572 class AppTaskExecutor : public FileTaskExecutor { |
570 public: | 573 public: |
571 // FileTaskExecutor overrides. | 574 // FileTaskExecutor overrides. |
572 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, | 575 virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls, |
573 const FileTaskFinishedCallback& done) OVERRIDE; | 576 const FileTaskFinishedCallback& done) OVERRIDE; |
574 | 577 |
575 private: | 578 private: |
576 // FileTaskExecutor is the only class allowed to create one. | 579 // FileTaskExecutor is the only class allowed to create one. |
577 friend class FileTaskExecutor; | 580 friend class FileTaskExecutor; |
578 | 581 |
579 AppTaskExecutor(Profile* profile, | 582 AppTaskExecutor(Profile* profile, |
580 const GURL& source_url, | 583 const GURL& source_url, |
581 const std::string& file_browser_id, | 584 const std::string& file_browser_id, |
582 const std::string& extension_id, | 585 const std::string& extension_id, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 const std::string& extension_id) | 635 const std::string& extension_id) |
633 : profile_(profile), | 636 : profile_(profile), |
634 source_url_(source_url), | 637 source_url_(source_url), |
635 file_browser_id_(file_browser_id), | 638 file_browser_id_(file_browser_id), |
636 extension_id_(extension_id) { | 639 extension_id_(extension_id) { |
637 } | 640 } |
638 | 641 |
639 FileTaskExecutor::~FileTaskExecutor() { | 642 FileTaskExecutor::~FileTaskExecutor() { |
640 } | 643 } |
641 | 644 |
642 bool FileTaskExecutor::Execute(const std::vector<GURL>& file_urls) { | 645 bool FileTaskExecutor::Execute(const std::vector<FileSystemURL>& file_urls) { |
643 return ExecuteAndNotify(file_urls, FileTaskFinishedCallback()); | 646 return ExecuteAndNotify(file_urls, FileTaskFinishedCallback()); |
644 } | 647 } |
645 | 648 |
646 bool FileTaskExecutor::FileBrowserHasAccessPermissionForFiles( | 649 bool FileTaskExecutor::FileBrowserHasAccessPermissionForFiles( |
647 const std::vector<GURL>& files) { | 650 const std::vector<FileSystemURL>& files) { |
648 // Check if the file browser extension has permissions for the files in its | 651 // Check if the file browser extension has permissions for the files in its |
649 // file system context. | 652 // file system context. |
650 GURL site = extensions::ExtensionSystem::Get(profile())->extension_service()-> | 653 GURL site = extensions::ExtensionSystem::Get(profile())->extension_service()-> |
651 GetSiteForExtensionId(file_browser_id_); | 654 GetSiteForExtensionId(file_browser_id_); |
652 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 655 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
653 BrowserContext::GetStoragePartitionForSite(profile(), site)-> | 656 BrowserContext::GetStoragePartitionForSite(profile(), site)-> |
654 GetFileSystemContext()->external_provider(); | 657 GetFileSystemContext()->external_provider(); |
655 | 658 |
656 if (!external_provider) | 659 if (!external_provider) |
657 return false; | 660 return false; |
658 | 661 |
659 for (size_t i = 0; i < files.size(); ++i) { | 662 for (size_t i = 0; i < files.size(); ++i) { |
660 fileapi::FileSystemURL url(files[i]); | |
661 // Make sure this url really being used by the right caller extension. | 663 // Make sure this url really being used by the right caller extension. |
662 if (source_url_.GetOrigin() != url.origin()) | 664 if (source_url_.GetOrigin() != files[i].origin()) |
663 return false; | 665 return false; |
664 | 666 |
665 if (!chromeos::CrosMountPointProvider::CanHandleURL(url) || | 667 if (!chromeos::CrosMountPointProvider::CanHandleURL(files[i]) || |
666 !external_provider->IsAccessAllowed(url)) { | 668 !external_provider->IsAccessAllowed(files[i])) { |
667 return false; | 669 return false; |
668 } | 670 } |
669 } | 671 } |
670 | 672 |
671 return true; | 673 return true; |
672 } | 674 } |
673 | 675 |
674 // TODO(kaznacheev): Remove this method and inline its implementation at the | 676 // TODO(kaznacheev): Remove this method and inline its implementation at the |
675 // only place where it is used (DriveTaskExecutor::OnAppAuthorized) | 677 // only place where it is used (DriveTaskExecutor::OnAppAuthorized) |
676 Browser* FileTaskExecutor::GetBrowser() const { | 678 Browser* FileTaskExecutor::GetBrowser() const { |
(...skipping 18 matching lines...) Expand all Loading... |
695 } | 697 } |
696 | 698 |
697 class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher { | 699 class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher { |
698 public: | 700 public: |
699 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 701 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
700 ExtensionTaskExecutor* executor, | 702 ExtensionTaskExecutor* executor, |
701 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 703 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, |
702 scoped_refptr<const Extension> handler_extension, | 704 scoped_refptr<const Extension> handler_extension, |
703 int handler_pid, | 705 int handler_pid, |
704 const std::string& action_id, | 706 const std::string& action_id, |
705 const std::vector<GURL>& file_urls) { | 707 const std::vector<FileSystemURL>& file_urls) { |
706 return base::Bind( | 708 return base::Bind( |
707 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem, | 709 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem, |
708 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher( | 710 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher( |
709 executor, file_system_context_handler, handler_extension, | 711 executor, file_system_context_handler, handler_extension, |
710 handler_pid, action_id, file_urls))); | 712 handler_pid, action_id, file_urls))); |
711 } | 713 } |
712 | 714 |
713 void DidOpenFileSystem(base::PlatformFileError result, | 715 void DidOpenFileSystem(base::PlatformFileError result, |
714 const std::string& file_system_name, | 716 const std::string& file_system_name, |
715 const GURL& file_system_root) { | 717 const GURL& file_system_root) { |
716 if (result != base::PLATFORM_FILE_OK) { | 718 if (result != base::PLATFORM_FILE_OK) { |
717 DidFail(result); | 719 DidFail(result); |
718 return; | 720 return; |
719 } | 721 } |
720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
721 ExtensionTaskExecutor::FileDefinitionList file_list; | 723 ExtensionTaskExecutor::FileDefinitionList file_list; |
722 for (std::vector<GURL>::iterator iter = origin_file_urls_.begin(); | 724 for (std::vector<FileSystemURL>::iterator iter = urls_.begin(); |
723 iter != origin_file_urls_.end(); | 725 iter != urls_.end(); |
724 ++iter) { | 726 ++iter) { |
725 // Set up file permission access. | 727 // Set up file permission access. |
726 ExtensionTaskExecutor::FileDefinition file; | 728 ExtensionTaskExecutor::FileDefinition file; |
727 if (!SetupFileAccessPermissions(*iter, &file)) | 729 if (!SetupFileAccessPermissions(*iter, &file)) |
728 continue; | 730 continue; |
729 file_list.push_back(file); | 731 file_list.push_back(file); |
730 } | 732 } |
731 if (file_list.empty()) { | 733 if (file_list.empty()) { |
732 BrowserThread::PostTask( | 734 BrowserThread::PostTask( |
733 BrowserThread::UI, FROM_HERE, | 735 BrowserThread::UI, FROM_HERE, |
(...skipping 24 matching lines...) Expand all Loading... |
758 false)); | 760 false)); |
759 } | 761 } |
760 | 762 |
761 private: | 763 private: |
762 ExecuteTasksFileSystemCallbackDispatcher( | 764 ExecuteTasksFileSystemCallbackDispatcher( |
763 ExtensionTaskExecutor* executor, | 765 ExtensionTaskExecutor* executor, |
764 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 766 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, |
765 const scoped_refptr<const Extension>& handler_extension, | 767 const scoped_refptr<const Extension>& handler_extension, |
766 int handler_pid, | 768 int handler_pid, |
767 const std::string& action_id, | 769 const std::string& action_id, |
768 const std::vector<GURL>& file_urls) | 770 const std::vector<FileSystemURL>& file_urls) |
769 : executor_(executor), | 771 : executor_(executor), |
770 file_system_context_handler_(file_system_context_handler), | 772 file_system_context_handler_(file_system_context_handler), |
771 handler_extension_(handler_extension), | 773 handler_extension_(handler_extension), |
772 handler_pid_(handler_pid), | 774 handler_pid_(handler_pid), |
773 action_id_(action_id), | 775 action_id_(action_id), |
774 origin_file_urls_(file_urls) { | 776 urls_(file_urls) { |
775 DCHECK(executor_); | 777 DCHECK(executor_); |
776 } | 778 } |
777 | 779 |
778 // Checks legitimacy of file url and grants file RO access permissions from | 780 // Checks legitimacy of file url and grants file RO access permissions from |
779 // handler (target) extension and its renderer process. | 781 // handler (target) extension and its renderer process. |
780 bool SetupFileAccessPermissions(const GURL& origin_file_url, | 782 bool SetupFileAccessPermissions(const FileSystemURL& url, |
781 FileDefinition* file) { | 783 FileDefinition* file) { |
782 if (!handler_extension_.get()) | 784 if (!handler_extension_.get()) |
783 return false; | 785 return false; |
784 | 786 |
785 if (handler_pid_ == 0) | 787 if (handler_pid_ == 0) |
786 return false; | 788 return false; |
787 | 789 |
788 fileapi::FileSystemURL url(origin_file_url); | |
789 | |
790 fileapi::ExternalFileSystemMountPointProvider* external_provider_handler = | 790 fileapi::ExternalFileSystemMountPointProvider* external_provider_handler = |
791 file_system_context_handler_->external_provider(); | 791 file_system_context_handler_->external_provider(); |
792 | 792 |
793 // Check if this file system entry exists first. | 793 // Check if this file system entry exists first. |
794 base::PlatformFileInfo file_info; | 794 base::PlatformFileInfo file_info; |
795 | 795 |
796 FilePath local_path = url.path(); | 796 FilePath local_path = url.path(); |
797 FilePath virtual_path = url.virtual_path(); | 797 FilePath virtual_path = url.virtual_path(); |
798 | 798 |
799 bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive; | 799 bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive; |
800 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); | 800 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); |
801 | 801 |
802 // If the file is under gdata mount point, there is no actual file to be | 802 // If the file is under gdata mount point, there is no actual file to be |
803 // found on the url.path(). | 803 // found on the url.path(). |
804 if (!is_drive_file) { | 804 if (!is_drive_file) { |
805 if (!file_util::PathExists(local_path) || | 805 if (!file_util::PathExists(local_path) || |
806 file_util::IsLink(local_path) || | 806 file_util::IsLink(local_path) || |
807 !file_util::GetFileInfo(local_path, &file_info)) { | 807 !file_util::GetFileInfo(local_path, &file_info)) { |
808 return false; | 808 return false; |
809 } | 809 } |
810 } | 810 } |
811 | 811 |
812 // Grant access to this particular file to target extension. This will | 812 // Grant access to this particular file to target extension. This will |
813 // ensure that the target extension can access only this FS entry and | 813 // ensure that the target extension can access only this FS entry and |
814 // prevent from traversing FS hierarchy upward. | 814 // prevent from traversing FS hierarchy upward. |
815 external_provider_handler->GrantFileAccessToExtension( | 815 external_provider_handler->GrantFileAccessToExtension( |
816 handler_extension_->id(), virtual_path); | 816 handler_extension_->id(), virtual_path); |
817 | 817 |
818 // Output values. | 818 // Output values. |
819 GURL target_origin_url(Extension::GetBaseURLFromExtensionId( | |
820 handler_extension_->id())); | |
821 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, | |
822 fileapi::kFileSystemTypeExternal); | |
823 file->target_file_url = GURL(base_url.spec() + virtual_path.value()); | |
824 file->virtual_path = virtual_path; | 819 file->virtual_path = virtual_path; |
825 file->is_directory = file_info.is_directory; | 820 file->is_directory = file_info.is_directory; |
826 file->absolute_path = local_path; | 821 file->absolute_path = local_path; |
827 return true; | 822 return true; |
828 } | 823 } |
829 | 824 |
830 ExtensionTaskExecutor* executor_; | 825 ExtensionTaskExecutor* executor_; |
831 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler_; | 826 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler_; |
832 scoped_refptr<const Extension> handler_extension_; | 827 scoped_refptr<const Extension> handler_extension_; |
833 int handler_pid_; | 828 int handler_pid_; |
834 std::string action_id_; | 829 std::string action_id_; |
835 std::vector<GURL> origin_file_urls_; | 830 std::vector<FileSystemURL> urls_; |
836 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); | 831 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); |
837 }; | 832 }; |
838 | 833 |
839 ExtensionTaskExecutor::ExtensionTaskExecutor( | 834 ExtensionTaskExecutor::ExtensionTaskExecutor( |
840 Profile* profile, | 835 Profile* profile, |
841 const GURL& source_url, | 836 const GURL& source_url, |
842 const std::string& file_browser_id, | 837 const std::string& file_browser_id, |
843 int tab_id, | 838 int tab_id, |
844 const std::string& extension_id, | 839 const std::string& extension_id, |
845 const std::string& action_id) | 840 const std::string& action_id) |
846 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), | 841 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), |
847 tab_id_(tab_id), | 842 tab_id_(tab_id), |
848 action_id_(action_id) { | 843 action_id_(action_id) { |
849 } | 844 } |
850 | 845 |
851 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} | 846 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} |
852 | 847 |
853 bool ExtensionTaskExecutor::ExecuteAndNotify( | 848 bool ExtensionTaskExecutor::ExecuteAndNotify( |
854 const std::vector<GURL>& file_urls, | 849 const std::vector<FileSystemURL>& file_urls, |
855 const FileTaskFinishedCallback& done) { | 850 const FileTaskFinishedCallback& done) { |
856 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) | 851 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) |
857 return false; | 852 return false; |
858 | 853 |
859 scoped_refptr<const Extension> handler = GetExtension(); | 854 scoped_refptr<const Extension> handler = GetExtension(); |
860 if (!handler.get()) | 855 if (!handler.get()) |
861 return false; | 856 return false; |
862 | 857 |
863 int handler_pid = ExtractProcessFromExtensionId(profile(), handler->id()); | 858 int handler_pid = ExtractProcessFromExtensionId(profile(), handler->id()); |
864 if (handler_pid <= 0) { | 859 if (handler_pid <= 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
888 handler_pid, | 883 handler_pid, |
889 file_urls)); | 884 file_urls)); |
890 return true; | 885 return true; |
891 } | 886 } |
892 | 887 |
893 void ExtensionTaskExecutor::RequestFileEntryOnFileThread( | 888 void ExtensionTaskExecutor::RequestFileEntryOnFileThread( |
894 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 889 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, |
895 const GURL& handler_base_url, | 890 const GURL& handler_base_url, |
896 const scoped_refptr<const Extension>& handler, | 891 const scoped_refptr<const Extension>& handler, |
897 int handler_pid, | 892 int handler_pid, |
898 const std::vector<GURL>& file_urls) { | 893 const std::vector<FileSystemURL>& file_urls) { |
899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
900 GURL origin_url = handler_base_url.GetOrigin(); | 895 GURL origin_url = handler_base_url.GetOrigin(); |
901 file_system_context_handler->OpenFileSystem( | 896 file_system_context_handler->OpenFileSystem( |
902 origin_url, fileapi::kFileSystemTypeExternal, false, // create | 897 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
903 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( | 898 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( |
904 this, | 899 this, |
905 file_system_context_handler, | 900 file_system_context_handler, |
906 handler, | 901 handler, |
907 handler_pid, | 902 handler_pid, |
908 action_id_, | 903 action_id_, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 const std::string& file_browser_id, | 1024 const std::string& file_browser_id, |
1030 const std::string& extension_id, | 1025 const std::string& extension_id, |
1031 const std::string& action_id) | 1026 const std::string& action_id) |
1032 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), | 1027 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), |
1033 action_id_(action_id) { | 1028 action_id_(action_id) { |
1034 } | 1029 } |
1035 | 1030 |
1036 WebIntentTaskExecutor::~WebIntentTaskExecutor() {} | 1031 WebIntentTaskExecutor::~WebIntentTaskExecutor() {} |
1037 | 1032 |
1038 bool WebIntentTaskExecutor::ExecuteAndNotify( | 1033 bool WebIntentTaskExecutor::ExecuteAndNotify( |
1039 const std::vector<GURL>& file_urls, | 1034 const std::vector<FileSystemURL>& file_urls, |
1040 const FileTaskFinishedCallback& done) { | 1035 const FileTaskFinishedCallback& done) { |
1041 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) | 1036 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) |
1042 return false; | 1037 return false; |
1043 | 1038 |
1044 for (size_t i = 0; i != file_urls.size(); ++i) { | 1039 for (size_t i = 0; i != file_urls.size(); ++i) { |
1045 fileapi::FileSystemURL url(file_urls[i]); | |
1046 extensions::LaunchPlatformAppWithPath(profile(), GetExtension(), | 1040 extensions::LaunchPlatformAppWithPath(profile(), GetExtension(), |
1047 url.path()); | 1041 file_urls[i].path()); |
1048 } | 1042 } |
1049 | 1043 |
1050 if (!done.is_null()) | 1044 if (!done.is_null()) |
1051 done.Run(true); | 1045 done.Run(true); |
1052 | 1046 |
1053 return true; | 1047 return true; |
1054 } | 1048 } |
1055 | 1049 |
1056 AppTaskExecutor::AppTaskExecutor( | 1050 AppTaskExecutor::AppTaskExecutor( |
1057 Profile* profile, | 1051 Profile* profile, |
1058 const GURL& source_url, | 1052 const GURL& source_url, |
1059 const std::string& file_browser_id, | 1053 const std::string& file_browser_id, |
1060 const std::string& extension_id, | 1054 const std::string& extension_id, |
1061 const std::string& action_id) | 1055 const std::string& action_id) |
1062 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), | 1056 : FileTaskExecutor(profile, source_url, file_browser_id, extension_id), |
1063 action_id_(action_id) { | 1057 action_id_(action_id) { |
1064 } | 1058 } |
1065 | 1059 |
1066 AppTaskExecutor::~AppTaskExecutor() {} | 1060 AppTaskExecutor::~AppTaskExecutor() {} |
1067 | 1061 |
1068 bool AppTaskExecutor::ExecuteAndNotify( | 1062 bool AppTaskExecutor::ExecuteAndNotify( |
1069 const std::vector<GURL>& file_urls, | 1063 const std::vector<FileSystemURL>& file_urls, |
1070 const FileTaskFinishedCallback& done) { | 1064 const FileTaskFinishedCallback& done) { |
1071 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) | 1065 if (!FileBrowserHasAccessPermissionForFiles(file_urls)) |
1072 return false; | 1066 return false; |
1073 | 1067 |
1074 for (size_t i = 0; i != file_urls.size(); ++i) { | 1068 for (size_t i = 0; i != file_urls.size(); ++i) { |
1075 fileapi::FileSystemURL url(file_urls[i]); | |
1076 extensions::LaunchPlatformAppWithFileHandler(profile(), GetExtension(), | 1069 extensions::LaunchPlatformAppWithFileHandler(profile(), GetExtension(), |
1077 action_id_, url.path()); | 1070 action_id_, file_urls[i].path()); |
1078 } | 1071 } |
1079 | 1072 |
1080 if (!done.is_null()) | 1073 if (!done.is_null()) |
1081 done.Run(true); | 1074 done.Run(true); |
1082 | |
1083 return true; | 1075 return true; |
1084 } | 1076 } |
1085 | 1077 |
1086 } // namespace file_handler_util | 1078 } // namespace file_handler_util |
OLD | NEW |