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