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