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