| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 28 matching lines...) Expand all Loading... |
| 39 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
| 40 #include "googleurl/src/gurl.h" | 40 #include "googleurl/src/gurl.h" |
| 41 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 42 #include "grit/platform_locale_settings.h" | 42 #include "grit/platform_locale_settings.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "webkit/fileapi/file_system_context.h" | 44 #include "webkit/fileapi/file_system_context.h" |
| 45 #include "webkit/fileapi/file_system_file_util.h" | 45 #include "webkit/fileapi/file_system_file_util.h" |
| 46 #include "webkit/fileapi/file_system_mount_point_provider.h" | 46 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 47 #include "webkit/fileapi/file_system_operation.h" | 47 #include "webkit/fileapi/file_system_operation.h" |
| 48 #include "webkit/fileapi/file_system_operation_context.h" | 48 #include "webkit/fileapi/file_system_operation_context.h" |
| 49 #include "webkit/fileapi/file_system_path_manager.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 | 53 |
| 55 namespace { | 54 namespace { |
| 56 | 55 |
| 57 // Error messages. | 56 // Error messages. |
| 58 const char kFileError[] = "File error %d"; | 57 const char kFileError[] = "File error %d"; |
| 59 const char kInvalidFileUrl[] = "Invalid file URL"; | 58 const char kInvalidFileUrl[] = "Invalid file URL"; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 return false; | 373 return false; |
| 375 | 374 |
| 376 // Make sure that only component extension can access the entire | 375 // Make sure that only component extension can access the entire |
| 377 // local file system. | 376 // local file system. |
| 378 if (extension_->location() != Extension::COMPONENT) { | 377 if (extension_->location() != Extension::COMPONENT) { |
| 379 NOTREACHED() << "Private method access by non-component extension " | 378 NOTREACHED() << "Private method access by non-component extension " |
| 380 << extension_->id(); | 379 << extension_->id(); |
| 381 return false; | 380 return false; |
| 382 } | 381 } |
| 383 | 382 |
| 384 fileapi::FileSystemPathManager* path_manager = | |
| 385 profile_->GetFileSystemContext()->path_manager(); | |
| 386 fileapi::ExternalFileSystemMountPointProvider* provider = | 383 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 387 path_manager->external_provider(); | 384 profile_->GetFileSystemContext()->external_provider(); |
| 388 if (!provider) | 385 if (!provider) |
| 389 return false; | 386 return false; |
| 390 | 387 |
| 391 // Grant full access to File API from this component extension. | 388 // Grant full access to File API from this component extension. |
| 392 provider->GrantFullAccessToExtension(extension_->id()); | 389 provider->GrantFullAccessToExtension(extension_->id()); |
| 393 | 390 |
| 394 // Grant R/W file permissions to the renderer hosting component | 391 // Grant R/W file permissions to the renderer hosting component |
| 395 // extension for all paths exposed by our local file system provider. | 392 // extension for all paths exposed by our local file system provider. |
| 396 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); | 393 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); |
| 397 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); | 394 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 453 |
| 457 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( | 454 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( |
| 458 base::PlatformFileError error_code) { | 455 base::PlatformFileError error_code) { |
| 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 460 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); | 457 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); |
| 461 SendResponse(false); | 458 SendResponse(false); |
| 462 } | 459 } |
| 463 | 460 |
| 464 bool FileWatchBrowserFunctionBase::GetLocalFilePath( | 461 bool FileWatchBrowserFunctionBase::GetLocalFilePath( |
| 465 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { | 462 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { |
| 466 fileapi::FileSystemPathManager* path_manager = | |
| 467 profile_->GetFileSystemContext()->path_manager(); | |
| 468 GURL file_origin_url; | 463 GURL file_origin_url; |
| 469 fileapi::FileSystemType type; | 464 fileapi::FileSystemType type; |
| 470 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 465 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
| 471 virtual_path)) { | 466 virtual_path)) { |
| 472 return false; | 467 return false; |
| 473 } | 468 } |
| 474 if (type != fileapi::kFileSystemTypeExternal) | 469 if (type != fileapi::kFileSystemTypeExternal) |
| 475 return false; | 470 return false; |
| 476 | 471 |
| 477 FilePath root_path = | 472 FilePath root_path = profile_->GetFileSystemContext()->external_provider()-> |
| 478 path_manager->ValidateFileSystemRootAndGetPathOnFileThread( | 473 ValidateFileSystemRootAndGetPathOnFileThread( |
| 479 file_origin_url, | 474 file_origin_url, |
| 480 fileapi::kFileSystemTypeExternal, | 475 fileapi::kFileSystemTypeExternal, |
| 481 *virtual_path, | 476 *virtual_path, |
| 482 false); | 477 false); |
| 483 if (root_path == FilePath()) | 478 if (root_path == FilePath()) |
| 484 return false; | 479 return false; |
| 485 | 480 |
| 486 *local_path = root_path.Append(*virtual_path); | 481 *local_path = root_path.Append(*virtual_path); |
| 487 return true; | 482 return true; |
| 488 } | 483 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 FilePath virtual_path; | 731 FilePath virtual_path; |
| 737 fileapi::FileSystemType type; | 732 fileapi::FileSystemType type; |
| 738 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, | 733 if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, |
| 739 &virtual_path)) { | 734 &virtual_path)) { |
| 740 return false; | 735 return false; |
| 741 } | 736 } |
| 742 | 737 |
| 743 if (type != fileapi::kFileSystemTypeExternal) | 738 if (type != fileapi::kFileSystemTypeExternal) |
| 744 return false; | 739 return false; |
| 745 | 740 |
| 746 fileapi::FileSystemPathManager* path_manager = | 741 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
| 747 profile_->GetFileSystemContext()->path_manager(); | 742 profile_->GetFileSystemContext()->external_provider(); |
| 748 if (!path_manager->IsAccessAllowed(file_origin_url, | 743 if (!external_provider) |
| 749 type, | 744 return false; |
| 750 virtual_path)) { | 745 |
| 746 if (!external_provider->IsAccessAllowed(file_origin_url, |
| 747 type, |
| 748 virtual_path)) { |
| 751 return false; | 749 return false; |
| 752 } | 750 } |
| 753 | 751 |
| 754 // Make sure this url really being used by the right caller extension. | 752 // Make sure this url really being used by the right caller extension. |
| 755 if (source_url_.GetOrigin() != file_origin_url) { | 753 if (source_url_.GetOrigin() != file_origin_url) { |
| 756 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 754 DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 757 return false; | 755 return false; |
| 758 } | 756 } |
| 759 | 757 |
| 760 FilePath root_path = | 758 FilePath root_path = |
| 761 path_manager->ValidateFileSystemRootAndGetPathOnFileThread( | 759 external_provider->ValidateFileSystemRootAndGetPathOnFileThread( |
| 762 file_origin_url, | 760 file_origin_url, |
| 763 fileapi::kFileSystemTypeExternal, | 761 fileapi::kFileSystemTypeExternal, |
| 764 virtual_path, | 762 virtual_path, |
| 765 false); // create | 763 false); // create |
| 766 FilePath final_file_path = root_path.Append(virtual_path); | 764 FilePath final_file_path = root_path.Append(virtual_path); |
| 767 | 765 |
| 768 fileapi::ExternalFileSystemMountPointProvider* external_provider = | |
| 769 path_manager->external_provider(); | |
| 770 if (!external_provider) | |
| 771 return false; | |
| 772 | |
| 773 // Check if this file system entry exists first. | 766 // Check if this file system entry exists first. |
| 774 base::PlatformFileInfo file_info; | 767 base::PlatformFileInfo file_info; |
| 775 | 768 |
| 776 if (!file_util::PathExists(final_file_path) || | 769 if (!file_util::PathExists(final_file_path) || |
| 777 file_util::IsLink(final_file_path) || | 770 file_util::IsLink(final_file_path) || |
| 778 !file_util::GetFileInfo(final_file_path, &file_info)) | 771 !file_util::GetFileInfo(final_file_path, &file_info)) |
| 779 return false; | 772 return false; |
| 780 | 773 |
| 781 // TODO(zelidrag): Let's just prevent all symlinks for now. We don't want a | 774 // TODO(zelidrag): Let's just prevent all symlinks for now. We don't want a |
| 782 // USB drive content to point to something in the rest of the file system. | 775 // USB drive content to point to something in the rest of the file system. |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 // thread. | 997 // thread. |
| 1005 void FileBrowserFunction::GetLocalPathsOnFileThread( | 998 void FileBrowserFunction::GetLocalPathsOnFileThread( |
| 1006 const UrlList& file_urls, | 999 const UrlList& file_urls, |
| 1007 GetLocalPathsCallback callback) { | 1000 GetLocalPathsCallback callback) { |
| 1008 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1009 FilePathList selected_files; | 1002 FilePathList selected_files; |
| 1010 | 1003 |
| 1011 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. | 1004 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. |
| 1012 #if defined(OS_CHROMEOS) | 1005 #if defined(OS_CHROMEOS) |
| 1013 GURL origin_url = source_url().GetOrigin(); | 1006 GURL origin_url = source_url().GetOrigin(); |
| 1014 fileapi::FileSystemPathManager* path_manager = | |
| 1015 profile()->GetFileSystemContext()->path_manager(); | |
| 1016 | |
| 1017 size_t len = file_urls.size(); | 1007 size_t len = file_urls.size(); |
| 1018 selected_files.reserve(len); | 1008 selected_files.reserve(len); |
| 1019 for (size_t i = 0; i < len; ++i) { | 1009 for (size_t i = 0; i < len; ++i) { |
| 1020 const GURL& file_url = file_urls[i]; | 1010 const GURL& file_url = file_urls[i]; |
| 1021 GURL file_origin_url; | 1011 GURL file_origin_url; |
| 1022 FilePath virtual_path; | 1012 FilePath virtual_path; |
| 1023 fileapi::FileSystemType type; | 1013 fileapi::FileSystemType type; |
| 1024 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 1014 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
| 1025 &virtual_path)) { | 1015 &virtual_path)) { |
| 1026 continue; | 1016 continue; |
| 1027 } | 1017 } |
| 1028 if (type != fileapi::kFileSystemTypeExternal) { | 1018 if (type != fileapi::kFileSystemTypeExternal) { |
| 1029 NOTREACHED(); | 1019 NOTREACHED(); |
| 1030 continue; | 1020 continue; |
| 1031 } | 1021 } |
| 1032 FilePath root = path_manager->ValidateFileSystemRootAndGetPathOnFileThread( | 1022 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 1023 profile_->GetFileSystemContext()->external_provider(); |
| 1024 if (!provider) { |
| 1025 LOG(WARNING) << "External provider is not available"; |
| 1026 continue; |
| 1027 } |
| 1028 FilePath root = provider->ValidateFileSystemRootAndGetPathOnFileThread( |
| 1033 origin_url, | 1029 origin_url, |
| 1034 fileapi::kFileSystemTypeExternal, | 1030 fileapi::kFileSystemTypeExternal, |
| 1035 FilePath(virtual_path), | 1031 FilePath(virtual_path), |
| 1036 false); | 1032 false); |
| 1037 if (!root.empty()) { | 1033 if (!root.empty()) { |
| 1038 selected_files.push_back(root.Append(virtual_path)); | 1034 selected_files.push_back(root.Append(virtual_path)); |
| 1039 } else { | 1035 } else { |
| 1040 LOG(WARNING) << "GetLocalPathsOnFileThread failed " | 1036 LOG(WARNING) << "GetLocalPathsOnFileThread failed " |
| 1041 << file_url.spec(); | 1037 << file_url.spec(); |
| 1042 } | 1038 } |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); | 1668 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); |
| 1673 #undef SET_STRING | 1669 #undef SET_STRING |
| 1674 | 1670 |
| 1675 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1671 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
| 1676 | 1672 |
| 1677 dict->SetString("PLAY_MEDIA", | 1673 dict->SetString("PLAY_MEDIA", |
| 1678 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1674 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
| 1679 | 1675 |
| 1680 return true; | 1676 return true; |
| 1681 } | 1677 } |
| OLD | NEW |