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