| 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/extension_file_browser_private_api.h" | 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 mount_info->SetString("mountCondition", | 307 mount_info->SetString("mountCondition", |
| 308 DiskMountManager::MountConditionToString( | 308 DiskMountManager::MountConditionToString( |
| 309 mount_point_info.mount_condition)); | 309 mount_point_info.mount_condition)); |
| 310 | 310 |
| 311 return mount_info; | 311 return mount_info; |
| 312 } | 312 } |
| 313 #endif | 313 #endif |
| 314 | 314 |
| 315 } // namespace | 315 } // namespace |
| 316 | 316 |
| 317 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 317 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher |
| 318 : public fileapi::FileSystemCallbackDispatcher { |
| 318 public: | 319 public: |
| 319 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 320 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
| 320 RequestLocalFileSystemFunction* function, | 321 RequestLocalFileSystemFunction* function, |
| 321 Profile* profile, | 322 Profile* profile, |
| 322 int child_id, | 323 int child_id, |
| 323 scoped_refptr<const Extension> extension) { | 324 scoped_refptr<const Extension> extension) { |
| 324 return base::Bind( | 325 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( |
| 325 &LocalFileSystemCallbackDispatcher::DidOpenFileSystem, | 326 new LocalFileSystemCallbackDispatcher( |
| 326 base::Owned(new LocalFileSystemCallbackDispatcher( | 327 function, profile, child_id, extension)); |
| 327 function, profile, child_id, extension))); | |
| 328 } | 328 } |
| 329 | 329 |
| 330 void DidOpenFileSystem(base::PlatformFileError result, | 330 // fileapi::FileSystemCallbackDispatcher overrides. |
| 331 const std::string& name, | 331 virtual void DidSucceed() OVERRIDE { |
| 332 const GURL& root_path) OVERRIDE { | 332 NOTREACHED(); |
| 333 if (result != base::PLATFORM_FILE_OK) { | 333 } |
| 334 DidFail(result); | 334 |
| 335 return; | 335 virtual void DidReadMetadata(const base::PlatformFileInfo& info, |
| 336 } | 336 const FilePath& unused) OVERRIDE { |
| 337 NOTREACHED(); |
| 338 } |
| 339 |
| 340 virtual void DidReadDirectory( |
| 341 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 342 bool has_more) OVERRIDE { |
| 343 NOTREACHED(); |
| 344 } |
| 345 |
| 346 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { |
| 347 NOTREACHED(); |
| 348 } |
| 349 |
| 350 virtual void DidOpenFileSystem(const std::string& name, |
| 351 const GURL& root_path) OVERRIDE { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 338 // Set up file permission access. | 353 // Set up file permission access. |
| 339 if (!SetupFileSystemAccessPermissions()) { | 354 if (!SetupFileSystemAccessPermissions()) { |
| 340 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 355 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 341 return; | 356 return; |
| 342 } | 357 } |
| 343 | 358 |
| 344 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
| 345 BrowserThread::UI, FROM_HERE, | 360 BrowserThread::UI, FROM_HERE, |
| 346 base::Bind( | 361 base::Bind( |
| 347 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread, | 362 &RequestLocalFileSystemFunction::RespondSuccessOnUIThread, |
| 348 function_, | 363 function_, |
| 349 name, | 364 name, |
| 350 root_path)); | 365 root_path)); |
| 351 } | 366 } |
| 352 | 367 |
| 353 void DidFail(base::PlatformFileError error_code) OVERRIDE { | 368 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
| 354 BrowserThread::PostTask( | 369 BrowserThread::PostTask( |
| 355 BrowserThread::UI, FROM_HERE, | 370 BrowserThread::UI, FROM_HERE, |
| 356 base::Bind( | 371 base::Bind( |
| 357 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, | 372 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, |
| 358 function_, | 373 function_, |
| 359 error_code)); | 374 error_code)); |
| 360 } | 375 } |
| 361 | 376 |
| 362 private: | 377 private: |
| 363 LocalFileSystemCallbackDispatcher( | 378 LocalFileSystemCallbackDispatcher( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // Extension source URL. | 427 // Extension source URL. |
| 413 scoped_refptr<const Extension> extension_; | 428 scoped_refptr<const Extension> extension_; |
| 414 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); | 429 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); |
| 415 }; | 430 }; |
| 416 | 431 |
| 417 void RequestLocalFileSystemFunction::RequestOnFileThread( | 432 void RequestLocalFileSystemFunction::RequestOnFileThread( |
| 418 const GURL& source_url, int child_id) { | 433 const GURL& source_url, int child_id) { |
| 419 GURL origin_url = source_url.GetOrigin(); | 434 GURL origin_url = source_url.GetOrigin(); |
| 420 profile()->GetFileSystemContext()->OpenFileSystem( | 435 profile()->GetFileSystemContext()->OpenFileSystem( |
| 421 origin_url, fileapi::kFileSystemTypeExternal, false, // create | 436 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
| 422 LocalFileSystemCallbackDispatcher::CreateCallback( | 437 LocalFileSystemCallbackDispatcher::Create( |
| 423 this, | 438 this, |
| 424 profile(), | 439 profile(), |
| 425 child_id, | 440 child_id, |
| 426 GetExtension())); | 441 GetExtension())); |
| 427 } | 442 } |
| 428 | 443 |
| 429 bool RequestLocalFileSystemFunction::RunImpl() { | 444 bool RequestLocalFileSystemFunction::RunImpl() { |
| 430 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) | 445 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) |
| 431 return false; | 446 return false; |
| 432 | 447 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 task->SetString("iconUrl", icon.spec()); | 621 task->SetString("iconUrl", icon.spec()); |
| 607 result_list->Append(task); | 622 result_list->Append(task); |
| 608 } | 623 } |
| 609 | 624 |
| 610 // TODO(zelidrag, serya): Add intent content tasks to result_list once we | 625 // TODO(zelidrag, serya): Add intent content tasks to result_list once we |
| 611 // implement that API. | 626 // implement that API. |
| 612 SendResponse(true); | 627 SendResponse(true); |
| 613 return true; | 628 return true; |
| 614 } | 629 } |
| 615 | 630 |
| 616 class | 631 class ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher |
| 617 ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher { | 632 : public fileapi::FileSystemCallbackDispatcher { |
| 618 public: | 633 public: |
| 619 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 634 static scoped_ptr<fileapi::FileSystemCallbackDispatcher> Create( |
| 620 ExecuteTasksFileBrowserFunction* function, | 635 ExecuteTasksFileBrowserFunction* function, |
| 621 Profile* profile, | 636 Profile* profile, |
| 622 int child_id, | 637 int child_id, |
| 623 const GURL& source_url, | 638 const GURL& source_url, |
| 624 scoped_refptr<const Extension> extension, | 639 scoped_refptr<const Extension> extension, |
| 625 const std::string task_id, | 640 const std::string task_id, |
| 626 const std::vector<GURL>& file_urls) { | 641 const std::vector<GURL>& file_urls) { |
| 627 return base::Bind( | 642 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( |
| 628 &ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem, | 643 new ExecuteTasksFileSystemCallbackDispatcher( |
| 629 base::Owned(new ExecuteTasksFileSystemCallbackDispatcher( | |
| 630 function, profile, child_id, source_url, extension, | 644 function, profile, child_id, source_url, extension, |
| 631 task_id, file_urls))); | 645 task_id, file_urls)); |
| 632 } | 646 } |
| 633 | 647 |
| 634 void DidOpenFileSystem(base::PlatformFileError result, | 648 // fileapi::FileSystemCallbackDispatcher overrides. |
| 635 const std::string& file_system_name, | 649 virtual void DidSucceed() OVERRIDE { |
| 636 const GURL& file_system_root) OVERRIDE { | 650 NOTREACHED(); |
| 637 if (result != base::PLATFORM_FILE_OK) { | 651 } |
| 638 DidFail(result); | 652 |
| 639 return; | 653 virtual void DidReadMetadata(const base::PlatformFileInfo& info, |
| 640 } | 654 const FilePath& unused) OVERRIDE { |
| 655 NOTREACHED(); |
| 656 } |
| 657 |
| 658 virtual void DidReadDirectory( |
| 659 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 660 bool has_more) OVERRIDE { |
| 661 NOTREACHED(); |
| 662 } |
| 663 |
| 664 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { |
| 665 NOTREACHED(); |
| 666 } |
| 667 |
| 668 virtual void DidOpenFileSystem(const std::string& file_system_name, |
| 669 const GURL& file_system_root) OVERRIDE { |
| 641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 642 ExecuteTasksFileBrowserFunction::FileDefinitionList file_list; | 671 ExecuteTasksFileBrowserFunction::FileDefinitionList file_list; |
| 643 for (std::vector<GURL>::iterator iter = origin_file_urls_.begin(); | 672 for (std::vector<GURL>::iterator iter = origin_file_urls_.begin(); |
| 644 iter != origin_file_urls_.end(); | 673 iter != origin_file_urls_.end(); |
| 645 ++iter) { | 674 ++iter) { |
| 646 // Set up file permission access. | 675 // Set up file permission access. |
| 647 ExecuteTasksFileBrowserFunction::FileDefinition file; | 676 ExecuteTasksFileBrowserFunction::FileDefinition file; |
| 648 if (!SetupFileAccessPermissions(*iter, &file.target_file_url, | 677 if (!SetupFileAccessPermissions(*iter, &file.target_file_url, |
| 649 &file.virtual_path, &file.is_directory)) { | 678 &file.virtual_path, &file.is_directory)) { |
| 650 continue; | 679 continue; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 664 BrowserThread::UI, FROM_HERE, | 693 BrowserThread::UI, FROM_HERE, |
| 665 base::Bind( | 694 base::Bind( |
| 666 &ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread, | 695 &ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread, |
| 667 function_, | 696 function_, |
| 668 task_id_, | 697 task_id_, |
| 669 file_system_name, | 698 file_system_name, |
| 670 file_system_root, | 699 file_system_root, |
| 671 file_list)); | 700 file_list)); |
| 672 } | 701 } |
| 673 | 702 |
| 674 void DidFail(base::PlatformFileError error_code) { | 703 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
| 675 BrowserThread::PostTask( | 704 BrowserThread::PostTask( |
| 676 BrowserThread::UI, FROM_HERE, | 705 BrowserThread::UI, FROM_HERE, |
| 677 base::Bind( | 706 base::Bind( |
| 678 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread, | 707 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread, |
| 679 function_)); | 708 function_)); |
| 680 } | 709 } |
| 681 | 710 |
| 682 private: | 711 private: |
| 683 ExecuteTasksFileSystemCallbackDispatcher( | 712 ExecuteTasksFileSystemCallbackDispatcher( |
| 684 ExecuteTasksFileBrowserFunction* function, | 713 ExecuteTasksFileBrowserFunction* function, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 return true; | 892 return true; |
| 864 } | 893 } |
| 865 | 894 |
| 866 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( | 895 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( |
| 867 const GURL& source_url, const std::string& task_id, | 896 const GURL& source_url, const std::string& task_id, |
| 868 const std::vector<GURL>& file_urls) { | 897 const std::vector<GURL>& file_urls) { |
| 869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 870 GURL origin_url = source_url.GetOrigin(); | 899 GURL origin_url = source_url.GetOrigin(); |
| 871 profile()->GetFileSystemContext()->OpenFileSystem( | 900 profile()->GetFileSystemContext()->OpenFileSystem( |
| 872 origin_url, fileapi::kFileSystemTypeExternal, false, // create | 901 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
| 873 ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( | 902 ExecuteTasksFileSystemCallbackDispatcher::Create( |
| 874 this, | 903 this, |
| 875 profile(), | 904 profile(), |
| 876 render_view_host()->process()->GetID(), | 905 render_view_host()->process()->GetID(), |
| 877 source_url, | 906 source_url, |
| 878 GetExtension(), | 907 GetExtension(), |
| 879 task_id, | 908 task_id, |
| 880 file_urls)); | 909 file_urls)); |
| 881 } | 910 } |
| 882 | 911 |
| 883 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() { | 912 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() { |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); | 1725 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); |
| 1697 #undef SET_STRING | 1726 #undef SET_STRING |
| 1698 | 1727 |
| 1699 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1728 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
| 1700 | 1729 |
| 1701 dict->SetString("PLAY_MEDIA", | 1730 dict->SetString("PLAY_MEDIA", |
| 1702 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1731 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
| 1703 | 1732 |
| 1704 return true; | 1733 return true; |
| 1705 } | 1734 } |
| OLD | NEW |