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 27 matching lines...) Expand all Loading... | |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
41 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
42 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
43 #include "grit/platform_locale_settings.h" | 43 #include "grit/platform_locale_settings.h" |
44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
45 #include "webkit/fileapi/file_system_context.h" | 45 #include "webkit/fileapi/file_system_context.h" |
46 #include "webkit/fileapi/file_system_file_util.h" | 46 #include "webkit/fileapi/file_system_file_util.h" |
47 #include "webkit/fileapi/file_system_mount_point_provider.h" | 47 #include "webkit/fileapi/file_system_mount_point_provider.h" |
48 #include "webkit/fileapi/file_system_operation.h" | |
49 #include "webkit/fileapi/file_system_operation_context.h" | 48 #include "webkit/fileapi/file_system_operation_context.h" |
50 #include "webkit/fileapi/file_system_types.h" | 49 #include "webkit/fileapi/file_system_types.h" |
51 #include "webkit/fileapi/file_system_util.h" | 50 #include "webkit/fileapi/file_system_util.h" |
52 | 51 |
53 using content::BrowserThread; | 52 using content::BrowserThread; |
54 using content::WebContents; | 53 using content::WebContents; |
55 | 54 |
56 namespace { | 55 namespace { |
57 | 56 |
58 // Error messages. | 57 // Error messages. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 300 |
302 return mount_info; | 301 return mount_info; |
303 } | 302 } |
304 #endif | 303 #endif |
305 | 304 |
306 } // namespace | 305 } // namespace |
307 | 306 |
308 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher | 307 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher |
309 : public fileapi::FileSystemCallbackDispatcher { | 308 : public fileapi::FileSystemCallbackDispatcher { |
310 public: | 309 public: |
311 explicit LocalFileSystemCallbackDispatcher( | 310 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
312 RequestLocalFileSystemFunction* function, | 311 RequestLocalFileSystemFunction* function, |
313 Profile* profile, | 312 Profile* profile, |
314 int child_id, | 313 int child_id, |
315 scoped_refptr<const Extension> extension) | 314 scoped_refptr<const Extension> extension) { |
316 : function_(function), | 315 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( |
317 profile_(profile), | 316 new LocalFileSystemCallbackDispatcher( |
318 child_id_(child_id), | 317 function, profile, child_id, extension)); |
319 extension_(extension) { | |
320 DCHECK(function_); | |
321 } | 318 } |
322 | 319 |
323 // fileapi::FileSystemCallbackDispatcher overrides. | 320 // fileapi::FileSystemCallbackDispatcher overrides. |
324 virtual void DidSucceed() OVERRIDE { | 321 virtual void DidSucceed() OVERRIDE { |
325 NOTREACHED(); | 322 NOTREACHED(); |
326 } | 323 } |
327 | 324 |
328 virtual void DidReadMetadata(const base::PlatformFileInfo& info, | 325 virtual void DidReadMetadata(const base::PlatformFileInfo& info, |
329 const FilePath& unused) OVERRIDE { | 326 const FilePath& unused) OVERRIDE { |
330 NOTREACHED(); | 327 NOTREACHED(); |
(...skipping 30 matching lines...) Expand all Loading... | |
361 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | 358 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
362 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
363 BrowserThread::UI, FROM_HERE, | 360 BrowserThread::UI, FROM_HERE, |
364 base::Bind( | 361 base::Bind( |
365 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, | 362 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, |
366 function_, | 363 function_, |
367 error_code)); | 364 error_code)); |
368 } | 365 } |
369 | 366 |
370 private: | 367 private: |
368 LocalFileSystemCallbackDispatcher( | |
369 RequestLocalFileSystemFunction* function, | |
370 Profile* profile, | |
371 int child_id, | |
372 scoped_refptr<const Extension> extension) | |
373 : function_(function), | |
374 profile_(profile), | |
375 child_id_(child_id), | |
376 extension_(extension) { | |
377 DCHECK(function_); | |
378 } | |
371 | 379 |
372 // Grants file system access permissions to file browser component. | 380 // Grants file system access permissions to file browser component. |
373 bool SetupFileSystemAccessPermissions() { | 381 bool SetupFileSystemAccessPermissions() { |
374 if (!extension_.get()) | 382 if (!extension_.get()) |
375 return false; | 383 return false; |
376 | 384 |
377 // Make sure that only component extension can access the entire | 385 // Make sure that only component extension can access the entire |
378 // local file system. | 386 // local file system. |
379 if (extension_->location() != Extension::COMPONENT) { | 387 if (extension_->location() != Extension::COMPONENT) { |
380 NOTREACHED() << "Private method access by non-component extension " | 388 NOTREACHED() << "Private method access by non-component extension " |
(...skipping 25 matching lines...) Expand all Loading... | |
406 Profile* profile_; | 414 Profile* profile_; |
407 // Renderer process id. | 415 // Renderer process id. |
408 int child_id_; | 416 int child_id_; |
409 // Extension source URL. | 417 // Extension source URL. |
410 scoped_refptr<const Extension> extension_; | 418 scoped_refptr<const Extension> extension_; |
411 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); | 419 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); |
412 }; | 420 }; |
413 | 421 |
414 void RequestLocalFileSystemFunction::RequestOnFileThread( | 422 void RequestLocalFileSystemFunction::RequestOnFileThread( |
415 const GURL& source_url, int child_id) { | 423 const GURL& source_url, int child_id) { |
416 fileapi::FileSystemOperation* operation = | |
417 new fileapi::FileSystemOperation( | |
418 new LocalFileSystemCallbackDispatcher( | |
419 this, | |
420 profile(), | |
421 child_id, | |
422 GetExtension()), | |
423 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
424 profile()->GetFileSystemContext()); | |
425 GURL origin_url = source_url.GetOrigin(); | 424 GURL origin_url = source_url.GetOrigin(); |
426 operation->OpenFileSystem(origin_url, fileapi::kFileSystemTypeExternal, | 425 profile()->GetFileSystemContext()->OpenFileSystem( |
427 false); // create | 426 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
427 LocalFileSystemCallbackDispatcher::Create( | |
428 this, | |
429 profile(), | |
430 child_id, | |
431 GetExtension())); | |
428 } | 432 } |
429 | 433 |
430 bool RequestLocalFileSystemFunction::RunImpl() { | 434 bool RequestLocalFileSystemFunction::RunImpl() { |
431 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) | 435 if (!dispatcher() || !render_view_host() || !render_view_host()->process()) |
432 return false; | 436 return false; |
433 | 437 |
434 BrowserThread::PostTask( | 438 BrowserThread::PostTask( |
435 BrowserThread::FILE, FROM_HERE, | 439 BrowserThread::FILE, FROM_HERE, |
436 base::Bind( | 440 base::Bind( |
437 &RequestLocalFileSystemFunction::RequestOnFileThread, | 441 &RequestLocalFileSystemFunction::RequestOnFileThread, |
(...skipping 27 matching lines...) Expand all Loading... | |
465 GURL file_origin_url; | 469 GURL file_origin_url; |
466 fileapi::FileSystemType type; | 470 fileapi::FileSystemType type; |
467 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 471 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
468 virtual_path)) { | 472 virtual_path)) { |
469 return false; | 473 return false; |
470 } | 474 } |
471 if (type != fileapi::kFileSystemTypeExternal) | 475 if (type != fileapi::kFileSystemTypeExternal) |
472 return false; | 476 return false; |
473 | 477 |
474 FilePath root_path = profile_->GetFileSystemContext()->external_provider()-> | 478 FilePath root_path = profile_->GetFileSystemContext()->external_provider()-> |
475 ValidateFileSystemRootAndGetPathOnFileThread( | 479 GetFileSystemRootPathOnFileThread( |
476 file_origin_url, | 480 file_origin_url, |
477 fileapi::kFileSystemTypeExternal, | 481 fileapi::kFileSystemTypeExternal, |
478 *virtual_path, | 482 *virtual_path, |
479 false); | 483 false); |
480 if (root_path == FilePath()) | 484 if (root_path == FilePath()) |
481 return false; | 485 return false; |
482 | 486 |
483 *local_path = root_path.Append(*virtual_path); | 487 *local_path = root_path.Append(*virtual_path); |
484 return true; | 488 return true; |
485 } | 489 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 | 614 |
611 // TODO(zelidrag, serya): Add intent content tasks to result_list once we | 615 // TODO(zelidrag, serya): Add intent content tasks to result_list once we |
612 // implement that API. | 616 // implement that API. |
613 SendResponse(true); | 617 SendResponse(true); |
614 return true; | 618 return true; |
615 } | 619 } |
616 | 620 |
617 class ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher | 621 class ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher |
618 : public fileapi::FileSystemCallbackDispatcher { | 622 : public fileapi::FileSystemCallbackDispatcher { |
619 public: | 623 public: |
620 explicit ExecuteTasksFileSystemCallbackDispatcher( | 624 static scoped_ptr<fileapi::FileSystemCallbackDispatcher> Create( |
621 ExecuteTasksFileBrowserFunction* function, | 625 ExecuteTasksFileBrowserFunction* function, |
622 Profile* profile, | 626 Profile* profile, |
623 int child_id, | 627 int child_id, |
624 const GURL& source_url, | 628 const GURL& source_url, |
625 scoped_refptr<const Extension> extension, | 629 scoped_refptr<const Extension> extension, |
626 const std::string task_id, | 630 const std::string task_id, |
627 const std::vector<GURL>& file_urls) | 631 const std::vector<GURL>& file_urls) { |
628 : function_(function), | 632 return scoped_ptr<fileapi::FileSystemCallbackDispatcher>( |
629 target_process_id_(0), | 633 new ExecuteTasksFileSystemCallbackDispatcher( |
630 profile_(profile), | 634 function, profile, child_id, source_url, extension, |
631 source_url_(source_url), | 635 task_id, file_urls)); |
632 extension_(extension), | |
633 task_id_(task_id), | |
634 origin_file_urls_(file_urls) { | |
635 DCHECK(function_); | |
636 ExtractTargetExtensionAndProcessID(); | |
637 } | 636 } |
638 | 637 |
639 // fileapi::FileSystemCallbackDispatcher overrides. | 638 // fileapi::FileSystemCallbackDispatcher overrides. |
640 virtual void DidSucceed() OVERRIDE { | 639 virtual void DidSucceed() OVERRIDE { |
641 NOTREACHED(); | 640 NOTREACHED(); |
642 } | 641 } |
643 | 642 |
644 virtual void DidReadMetadata(const base::PlatformFileInfo& info, | 643 virtual void DidReadMetadata(const base::PlatformFileInfo& info, |
645 const FilePath& unused) OVERRIDE { | 644 const FilePath& unused) OVERRIDE { |
646 NOTREACHED(); | 645 NOTREACHED(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 | 692 |
694 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | 693 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { |
695 BrowserThread::PostTask( | 694 BrowserThread::PostTask( |
696 BrowserThread::UI, FROM_HERE, | 695 BrowserThread::UI, FROM_HERE, |
697 base::Bind( | 696 base::Bind( |
698 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread, | 697 &ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread, |
699 function_)); | 698 function_)); |
700 } | 699 } |
701 | 700 |
702 private: | 701 private: |
702 ExecuteTasksFileSystemCallbackDispatcher( | |
703 ExecuteTasksFileBrowserFunction* function, | |
704 Profile* profile, | |
705 int child_id, | |
706 const GURL& source_url, | |
707 scoped_refptr<const Extension> extension, | |
tzik
2012/01/10 08:31:13
can be const&?
kinuko
2012/01/10 09:48:53
Done.
| |
708 const std::string task_id, | |
709 const std::vector<GURL>& file_urls) | |
710 : function_(function), | |
711 target_process_id_(0), | |
712 profile_(profile), | |
713 source_url_(source_url), | |
714 extension_(extension), | |
715 task_id_(task_id), | |
716 origin_file_urls_(file_urls) { | |
717 DCHECK(function_); | |
718 ExtractTargetExtensionAndProcessID(); | |
719 } | |
720 | |
703 // Extracts target extension's id and process from the tasks's id. | 721 // Extracts target extension's id and process from the tasks's id. |
704 void ExtractTargetExtensionAndProcessID() { | 722 void ExtractTargetExtensionAndProcessID() { |
705 // Get task details. | 723 // Get task details. |
706 std::string action_id; | 724 std::string action_id; |
707 if (!CrackTaskIdentifier(task_id_, &target_extension_id_, &action_id)) | 725 if (!CrackTaskIdentifier(task_id_, &target_extension_id_, &action_id)) |
708 return; | 726 return; |
709 | 727 |
710 GURL extension_url = | 728 GURL extension_url = |
711 Extension::GetBaseURLFromExtensionId(target_extension_id_); | 729 Extension::GetBaseURLFromExtensionId(target_extension_id_); |
712 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); | 730 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 return false; | 769 return false; |
752 } | 770 } |
753 | 771 |
754 // Make sure this url really being used by the right caller extension. | 772 // Make sure this url really being used by the right caller extension. |
755 if (source_url_.GetOrigin() != file_origin_url) { | 773 if (source_url_.GetOrigin() != file_origin_url) { |
756 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 774 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
757 return false; | 775 return false; |
758 } | 776 } |
759 | 777 |
760 FilePath root_path = | 778 FilePath root_path = |
761 external_provider->ValidateFileSystemRootAndGetPathOnFileThread( | 779 external_provider->GetFileSystemRootPathOnFileThread( |
762 file_origin_url, | 780 file_origin_url, |
763 fileapi::kFileSystemTypeExternal, | 781 fileapi::kFileSystemTypeExternal, |
764 virtual_path, | 782 virtual_path, |
765 false); // create | 783 false); // create |
766 FilePath final_file_path = root_path.Append(virtual_path); | 784 FilePath final_file_path = root_path.Append(virtual_path); |
767 | 785 |
768 // Check if this file system entry exists first. | 786 // Check if this file system entry exists first. |
769 base::PlatformFileInfo file_info; | 787 base::PlatformFileInfo file_info; |
770 | 788 |
771 if (!file_util::PathExists(final_file_path) || | 789 if (!file_util::PathExists(final_file_path) || |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 task_id, | 878 task_id, |
861 file_urls)); | 879 file_urls)); |
862 result_.reset(new base::FundamentalValue(true)); | 880 result_.reset(new base::FundamentalValue(true)); |
863 return true; | 881 return true; |
864 } | 882 } |
865 | 883 |
866 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( | 884 void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( |
867 const GURL& source_url, const std::string& task_id, | 885 const GURL& source_url, const std::string& task_id, |
868 const std::vector<GURL>& file_urls) { | 886 const std::vector<GURL>& file_urls) { |
869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
870 fileapi::FileSystemOperation* operation = | |
871 new fileapi::FileSystemOperation( | |
872 new ExecuteTasksFileSystemCallbackDispatcher( | |
873 this, | |
874 profile(), | |
875 render_view_host()->process()->GetID(), | |
876 source_url, | |
877 GetExtension(), | |
878 task_id, | |
879 file_urls), | |
880 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
881 profile()->GetFileSystemContext()); | |
882 GURL origin_url = source_url.GetOrigin(); | 888 GURL origin_url = source_url.GetOrigin(); |
883 operation->OpenFileSystem(origin_url, fileapi::kFileSystemTypeExternal, | 889 profile()->GetFileSystemContext()->OpenFileSystem( |
884 false); // create | 890 origin_url, fileapi::kFileSystemTypeExternal, false, // create |
891 ExecuteTasksFileSystemCallbackDispatcher::Create( | |
892 this, | |
893 profile(), | |
894 render_view_host()->process()->GetID(), | |
895 source_url, | |
896 GetExtension(), | |
897 task_id, | |
898 file_urls)); | |
885 } | 899 } |
886 | 900 |
887 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() { | 901 void ExecuteTasksFileBrowserFunction::ExecuteFailedOnUIThread() { |
888 SendResponse(false); | 902 SendResponse(false); |
889 } | 903 } |
890 | 904 |
891 | 905 |
892 void ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread( | 906 void ExecuteTasksFileBrowserFunction::ExecuteFileActionsOnUIThread( |
893 const std::string& task_id, | 907 const std::string& task_id, |
894 const std::string& file_system_name, | 908 const std::string& file_system_name, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1023 FilePath virtual_path; | 1037 FilePath virtual_path; |
1024 fileapi::FileSystemType type; | 1038 fileapi::FileSystemType type; |
1025 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 1039 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
1026 &virtual_path)) { | 1040 &virtual_path)) { |
1027 continue; | 1041 continue; |
1028 } | 1042 } |
1029 if (type != fileapi::kFileSystemTypeExternal) { | 1043 if (type != fileapi::kFileSystemTypeExternal) { |
1030 NOTREACHED(); | 1044 NOTREACHED(); |
1031 continue; | 1045 continue; |
1032 } | 1046 } |
1033 FilePath root = provider->ValidateFileSystemRootAndGetPathOnFileThread( | 1047 FilePath root = provider->GetFileSystemRootPathOnFileThread( |
1034 origin_url, | 1048 origin_url, |
1035 fileapi::kFileSystemTypeExternal, | 1049 fileapi::kFileSystemTypeExternal, |
1036 FilePath(virtual_path), | 1050 FilePath(virtual_path), |
1037 false); | 1051 false); |
1038 if (!root.empty()) { | 1052 if (!root.empty()) { |
1039 selected_files.push_back(root.Append(virtual_path)); | 1053 selected_files.push_back(root.Append(virtual_path)); |
1040 } else { | 1054 } else { |
1041 LOG(WARNING) << "GetLocalPathsOnFileThread failed " | 1055 LOG(WARNING) << "GetLocalPathsOnFileThread failed " |
1042 << file_url.spec(); | 1056 << file_url.spec(); |
1043 } | 1057 } |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1673 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); | 1687 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); |
1674 #undef SET_STRING | 1688 #undef SET_STRING |
1675 | 1689 |
1676 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1690 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
1677 | 1691 |
1678 dict->SetString("PLAY_MEDIA", | 1692 dict->SetString("PLAY_MEDIA", |
1679 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1693 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1680 | 1694 |
1681 return true; | 1695 return true; |
1682 } | 1696 } |
OLD | NEW |