| 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_manager/file_handler_util.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/drive/file_task_executor.h" | 14 #include "chrome/browser/chromeos/drive/file_task_executor.h" |
| 15 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler.h
" | 15 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler.h
" |
| 16 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" | 16 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" |
| 17 #include "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h" | 17 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
| 19 #include "chrome/browser/extensions/extension_host.h" | 19 #include "chrome/browser/extensions/extension_host.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
| 22 #include "chrome/browser/extensions/extension_tab_util.h" | 22 #include "chrome/browser/extensions/extension_tab_util.h" |
| 23 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 23 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 24 #include "chrome/browser/extensions/platform_app_launcher.h" | 24 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 25 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 25 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 GetFileSystemContext(); | 180 GetFileSystemContext(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Checks if the file browser extension has permissions for the files in its | 183 // Checks if the file browser extension has permissions for the files in its |
| 184 // file system context. | 184 // file system context. |
| 185 bool FileBrowserHasAccessPermissionForFiles( | 185 bool FileBrowserHasAccessPermissionForFiles( |
| 186 Profile* profile, | 186 Profile* profile, |
| 187 const GURL& source_url, | 187 const GURL& source_url, |
| 188 const std::string& file_browser_id, | 188 const std::string& file_browser_id, |
| 189 const std::vector<FileSystemURL>& files) { | 189 const std::vector<FileSystemURL>& files) { |
| 190 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 190 fileapi::ExternalFileSystemBackend* backend = |
| 191 GetFileSystemContextForExtension(profile, file_browser_id)-> | 191 GetFileSystemContextForExtension(profile, file_browser_id)-> |
| 192 external_provider(); | 192 external_backend(); |
| 193 if (!external_provider) | 193 if (!backend) |
| 194 return false; | 194 return false; |
| 195 | 195 |
| 196 for (size_t i = 0; i < files.size(); ++i) { | 196 for (size_t i = 0; i < files.size(); ++i) { |
| 197 // Make sure this url really being used by the right caller extension. | 197 // Make sure this url really being used by the right caller extension. |
| 198 if (source_url.GetOrigin() != files[i].origin()) | 198 if (source_url.GetOrigin() != files[i].origin()) |
| 199 return false; | 199 return false; |
| 200 | 200 |
| 201 if (!chromeos::CrosMountPointProvider::CanHandleURL(files[i]) || | 201 if (!chromeos::FileSystemBackend::CanHandleURL(files[i]) || |
| 202 !external_provider->IsAccessAllowed(files[i])) { | 202 !backend->IsAccessAllowed(files[i])) { |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 return true; | 207 return true; |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace | 210 } // namespace |
| 211 | 211 |
| 212 bool IsFallbackTask(const FileBrowserHandler* task) { | 212 bool IsFallbackTask(const FileBrowserHandler* task) { |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 | 622 |
| 623 // static | 623 // static |
| 624 ExtensionTaskExecutor::FileDefinitionList | 624 ExtensionTaskExecutor::FileDefinitionList |
| 625 ExtensionTaskExecutor::SetupFileAccessPermissions( | 625 ExtensionTaskExecutor::SetupFileAccessPermissions( |
| 626 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 626 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, |
| 627 const scoped_refptr<const Extension>& handler_extension, | 627 const scoped_refptr<const Extension>& handler_extension, |
| 628 const std::vector<FileSystemURL>& file_urls) { | 628 const std::vector<FileSystemURL>& file_urls) { |
| 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 630 DCHECK(handler_extension.get()); | 630 DCHECK(handler_extension.get()); |
| 631 | 631 |
| 632 fileapi::ExternalFileSystemMountPointProvider* external_provider_handler = | 632 fileapi::ExternalFileSystemBackend* backend = |
| 633 file_system_context_handler->external_provider(); | 633 file_system_context_handler->external_backend(); |
| 634 | 634 |
| 635 FileDefinitionList file_list; | 635 FileDefinitionList file_list; |
| 636 for (size_t i = 0; i < file_urls.size(); ++i) { | 636 for (size_t i = 0; i < file_urls.size(); ++i) { |
| 637 const FileSystemURL& url = file_urls[i]; | 637 const FileSystemURL& url = file_urls[i]; |
| 638 | 638 |
| 639 // Check if this file system entry exists first. | 639 // Check if this file system entry exists first. |
| 640 base::PlatformFileInfo file_info; | 640 base::PlatformFileInfo file_info; |
| 641 | 641 |
| 642 base::FilePath local_path = url.path(); | 642 base::FilePath local_path = url.path(); |
| 643 base::FilePath virtual_path = url.virtual_path(); | 643 base::FilePath virtual_path = url.virtual_path(); |
| 644 | 644 |
| 645 bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive; | 645 bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive; |
| 646 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); | 646 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); |
| 647 | 647 |
| 648 // If the file is under drive mount point, there is no actual file to be | 648 // If the file is under drive mount point, there is no actual file to be |
| 649 // found on the url.path(). | 649 // found on the url.path(). |
| 650 if (!is_drive_file) { | 650 if (!is_drive_file) { |
| 651 if (!file_util::PathExists(local_path) || | 651 if (!file_util::PathExists(local_path) || |
| 652 file_util::IsLink(local_path) || | 652 file_util::IsLink(local_path) || |
| 653 !file_util::GetFileInfo(local_path, &file_info)) { | 653 !file_util::GetFileInfo(local_path, &file_info)) { |
| 654 continue; | 654 continue; |
| 655 } | 655 } |
| 656 } | 656 } |
| 657 | 657 |
| 658 // Grant access to this particular file to target extension. This will | 658 // Grant access to this particular file to target extension. This will |
| 659 // ensure that the target extension can access only this FS entry and | 659 // ensure that the target extension can access only this FS entry and |
| 660 // prevent from traversing FS hierarchy upward. | 660 // prevent from traversing FS hierarchy upward. |
| 661 external_provider_handler->GrantFileAccessToExtension( | 661 backend->GrantFileAccessToExtension( |
| 662 handler_extension->id(), virtual_path); | 662 handler_extension->id(), virtual_path); |
| 663 | 663 |
| 664 // Output values. | 664 // Output values. |
| 665 FileDefinition file; | 665 FileDefinition file; |
| 666 file.virtual_path = virtual_path; | 666 file.virtual_path = virtual_path; |
| 667 file.is_directory = file_info.is_directory; | 667 file.is_directory = file_info.is_directory; |
| 668 file.absolute_path = local_path; | 668 file.absolute_path = local_path; |
| 669 file_list.push_back(file); | 669 file_list.push_back(file); |
| 670 } | 670 } |
| 671 return file_list; | 671 return file_list; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 ++iter) { | 838 ++iter) { |
| 839 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 839 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
| 840 handler_pid, | 840 handler_pid, |
| 841 iter->absolute_path, | 841 iter->absolute_path, |
| 842 GetAccessPermissionsForFileBrowserHandler(extension_.get(), | 842 GetAccessPermissionsForFileBrowserHandler(extension_.get(), |
| 843 action_id_)); | 843 action_id_)); |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 | 846 |
| 847 } // namespace file_handler_util | 847 } // namespace file_handler_util |
| OLD | NEW |