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/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
6 | 6 |
7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
8 #include "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
9 #include "apps/browser/file_handler_util.h" | 9 #include "apps/browser/file_handler_util.h" |
10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "webkit/browser/fileapi/isolated_context.h" | 43 #include "webkit/browser/fileapi/isolated_context.h" |
44 #include "webkit/common/fileapi/file_system_types.h" | 44 #include "webkit/common/fileapi/file_system_types.h" |
45 #include "webkit/common/fileapi/file_system_util.h" | 45 #include "webkit/common/fileapi/file_system_util.h" |
46 | 46 |
47 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
48 #include <CoreFoundation/CoreFoundation.h> | 48 #include <CoreFoundation/CoreFoundation.h> |
49 #include "base/mac/foundation_util.h" | 49 #include "base/mac/foundation_util.h" |
50 #endif | 50 #endif |
51 | 51 |
52 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
53 #include "chrome/browser/chromeos/drive/file_system_util.h" | 53 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
54 #endif | 54 #endif |
55 | 55 |
56 using apps::SavedFileEntry; | 56 using apps::SavedFileEntry; |
57 using apps::SavedFilesService; | 57 using apps::SavedFilesService; |
58 using apps::AppWindow; | 58 using apps::AppWindow; |
59 using fileapi::IsolatedContext; | 59 using fileapi::IsolatedContext; |
60 | 60 |
61 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " | 61 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " |
62 "be called from a background page."; | 62 "be called from a background page."; |
63 const char kUserCancelled[] = "User cancelled"; | 63 const char kUserCancelled[] = "User cancelled"; |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 DCHECK(registry); | 673 DCHECK(registry); |
674 AppWindow* app_window = | 674 AppWindow* app_window = |
675 registry->GetAppWindowForRenderViewHost(render_view_host()); | 675 registry->GetAppWindowForRenderViewHost(render_view_host()); |
676 if (!app_window) { | 676 if (!app_window) { |
677 error_ = kInvalidCallingPage; | 677 error_ = kInvalidCallingPage; |
678 SendResponse(false); | 678 SendResponse(false); |
679 return; | 679 return; |
680 } | 680 } |
681 content::WebContents* web_contents = app_window->web_contents(); | 681 content::WebContents* web_contents = app_window->web_contents(); |
682 | 682 |
| 683 DCHECK_EQ(paths.size(), 1u); |
| 684 #if defined(OS_CHROMEOS) |
| 685 base::FilePath check_path = |
| 686 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]) |
| 687 ? paths[0] |
| 688 : base::MakeAbsoluteFilePath(paths[0]); |
| 689 #else |
| 690 base::FilePath check_path = base::MakeAbsoluteFilePath(paths[0]); |
| 691 #endif |
| 692 |
683 content::BrowserThread::PostTask( | 693 content::BrowserThread::PostTask( |
684 content::BrowserThread::FILE, | 694 content::BrowserThread::FILE, |
685 FROM_HERE, | 695 FROM_HERE, |
686 base::Bind( | 696 base::Bind( |
687 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, | 697 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, |
688 this, | 698 this, |
| 699 check_path, |
689 paths, | 700 paths, |
690 web_contents)); | 701 web_contents)); |
691 return; | 702 return; |
692 } | 703 } |
693 | 704 |
694 OnDirectoryAccessConfirmed(paths); | 705 OnDirectoryAccessConfirmed(paths); |
695 } | 706 } |
696 | 707 |
697 void FileSystemChooseEntryFunction::FileSelectionCanceled() { | 708 void FileSystemChooseEntryFunction::FileSelectionCanceled() { |
698 error_ = kUserCancelled; | 709 error_ = kUserCancelled; |
699 SendResponse(false); | 710 SendResponse(false); |
700 } | 711 } |
701 | 712 |
702 void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( | 713 void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( |
| 714 const base::FilePath& check_path, |
703 const std::vector<base::FilePath>& paths, | 715 const std::vector<base::FilePath>& paths, |
704 content::WebContents* web_contents) { | 716 content::WebContents* web_contents) { |
705 DCHECK_EQ(paths.size(), 1u); | 717 if (check_path.empty()) { |
706 #if defined(OS_CHROMEOS) | |
707 const base::FilePath path = | |
708 drive::util::IsUnderDriveMountPoint(paths[0]) ? paths[0] : | |
709 base::MakeAbsoluteFilePath(paths[0]); | |
710 #else | |
711 const base::FilePath path = base::MakeAbsoluteFilePath(paths[0]); | |
712 #endif | |
713 if (path.empty()) { | |
714 content::BrowserThread::PostTask( | 718 content::BrowserThread::PostTask( |
715 content::BrowserThread::UI, | 719 content::BrowserThread::UI, |
716 FROM_HERE, | 720 FROM_HERE, |
717 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 721 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, |
718 this)); | 722 this)); |
719 return; | 723 return; |
720 } | 724 } |
721 | 725 |
722 for (size_t i = 0; i < arraysize(kGraylistedPaths); i++) { | 726 for (size_t i = 0; i < arraysize(kGraylistedPaths); i++) { |
723 base::FilePath graylisted_path; | 727 base::FilePath graylisted_path; |
724 if (PathService::Get(kGraylistedPaths[i], &graylisted_path) && | 728 if (PathService::Get(kGraylistedPaths[i], &graylisted_path) && |
725 (path == graylisted_path || path.IsParent(graylisted_path))) { | 729 (check_path == graylisted_path || |
| 730 check_path.IsParent(graylisted_path))) { |
726 if (g_skip_directory_confirmation_for_test) { | 731 if (g_skip_directory_confirmation_for_test) { |
727 if (g_allow_directory_access_for_test) { | 732 if (g_allow_directory_access_for_test) { |
728 break; | 733 break; |
729 } else { | 734 } else { |
730 content::BrowserThread::PostTask( | 735 content::BrowserThread::PostTask( |
731 content::BrowserThread::UI, | 736 content::BrowserThread::UI, |
732 FROM_HERE, | 737 FROM_HERE, |
733 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, | 738 base::Bind(&FileSystemChooseEntryFunction::FileSelectionCanceled, |
734 this)); | 739 this)); |
735 } | 740 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 if (needs_new_entry) { | 982 if (needs_new_entry) { |
978 is_directory_ = file_entry->is_directory; | 983 is_directory_ = file_entry->is_directory; |
979 CreateResponse(); | 984 CreateResponse(); |
980 AddEntryToResponse(file_entry->path, file_entry->id); | 985 AddEntryToResponse(file_entry->path, file_entry->id); |
981 } | 986 } |
982 SendResponse(true); | 987 SendResponse(true); |
983 return true; | 988 return true; |
984 } | 989 } |
985 | 990 |
986 } // namespace extensions | 991 } // namespace extensions |
OLD | NEW |