| 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_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 mount_info->SetString("mountCondition", | 172 mount_info->SetString("mountCondition", |
| 173 DiskMountManager::MountConditionToString( | 173 DiskMountManager::MountConditionToString( |
| 174 mount_point_info.mount_condition)); | 174 mount_point_info.mount_condition)); |
| 175 | 175 |
| 176 return mount_info; | 176 return mount_info; |
| 177 } | 177 } |
| 178 #endif // defined(OS_CHROMEOS) | 178 #endif // defined(OS_CHROMEOS) |
| 179 | 179 |
| 180 |
| 181 // Gives the extension renderer |host| file |permissions| for the given |path|. |
| 182 void GrantFilePermissionsToHost(content::RenderViewHost* host, |
| 183 const FilePath& path, |
| 184 int permissions) { |
| 185 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
| 186 host->GetProcess()->GetID(), path, permissions); |
| 187 } |
| 188 |
| 180 // Given a file url, find the virtual FilePath associated with it. | 189 // Given a file url, find the virtual FilePath associated with it. |
| 181 FilePath GetVirtualPathFromURL(const GURL& file_url) { | 190 FilePath GetVirtualPathFromURL(const GURL& file_url) { |
| 182 FilePath virtual_path; | 191 FilePath virtual_path; |
| 183 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | 192 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; |
| 184 GURL file_origin_url; | 193 GURL file_origin_url; |
| 185 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || | 194 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || |
| 186 type != fileapi::kFileSystemTypeExternal) { | 195 type != fileapi::kFileSystemTypeExternal) { |
| 187 NOTREACHED(); | 196 NOTREACHED(); |
| 188 return FilePath(); | 197 return FilePath(); |
| 189 } | 198 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 this, | 460 this, |
| 452 source_url_, | 461 source_url_, |
| 453 render_view_host()->GetProcess()->GetID())); | 462 render_view_host()->GetProcess()->GetID())); |
| 454 // Will finish asynchronously. | 463 // Will finish asynchronously. |
| 455 return true; | 464 return true; |
| 456 } | 465 } |
| 457 | 466 |
| 458 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( | 467 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( |
| 459 const std::string& name, const GURL& root_path) { | 468 const std::string& name, const GURL& root_path) { |
| 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 470 // Add gdata mount point immediately when we kick of first instance of file |
| 471 // manager. The actual mount event will be sent to UI only when we perform |
| 472 // proper authentication. |
| 473 AddGDataMountPoint(); |
| 461 result_.reset(new DictionaryValue()); | 474 result_.reset(new DictionaryValue()); |
| 462 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); | 475 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); |
| 463 dict->SetString("name", name); | 476 dict->SetString("name", name); |
| 464 dict->SetString("path", root_path.spec()); | 477 dict->SetString("path", root_path.spec()); |
| 465 dict->SetInteger("error", base::PLATFORM_FILE_OK); | 478 dict->SetInteger("error", base::PLATFORM_FILE_OK); |
| 466 SendResponse(true); | 479 SendResponse(true); |
| 467 } | 480 } |
| 468 | 481 |
| 482 void RequestLocalFileSystemFunction::AddGDataMountPoint() { |
| 483 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 484 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 485 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); |
| 486 if (!provider || provider->HasMountPoint(mount_point)) |
| 487 return; |
| 488 |
| 489 // Grant R/W permissions to gdata 'folder'. File API layer still |
| 490 // expects this to be satisfied. |
| 491 GrantFilePermissionsToHost(render_view_host(), |
| 492 mount_point, |
| 493 file_handler_util::GetReadWritePermissions()); |
| 494 |
| 495 // Grant R/W permission for tmp and pinned cache folder. |
| 496 gdata::GDataSystemService* system_service = |
| 497 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 498 DCHECK(system_service); |
| 499 gdata::GDataFileSystem* gdata_file_system = system_service->file_system(); |
| 500 |
| 501 // We check permissions for raw cache file paths only for read-only |
| 502 // operations (when fileEntry.file() is called), so read only permissions |
| 503 // should be sufficient for all cache paths. For the rest of supported |
| 504 // operations the file access check is done for gdata/ paths. |
| 505 GrantFilePermissionsToHost(render_view_host(), |
| 506 gdata_file_system->GetGDataCacheTmpDirectory(), |
| 507 file_handler_util::GetReadOnlyPermissions()); |
| 508 GrantFilePermissionsToHost( |
| 509 render_view_host(), |
| 510 gdata_file_system->GetGDataCachePersistentDirectory(), |
| 511 file_handler_util::GetReadOnlyPermissions()); |
| 512 |
| 513 provider->AddRemoteMountPoint( |
| 514 mount_point, |
| 515 new gdata::GDataFileSystemProxy(gdata_file_system)); |
| 516 |
| 517 FilePath mount_point_virtual; |
| 518 if (provider->GetVirtualPath(mount_point, &mount_point_virtual)) |
| 519 provider->GrantFileAccessToExtension(extension_id(), mount_point_virtual); |
| 520 } |
| 521 |
| 469 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( | 522 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( |
| 470 base::PlatformFileError error_code) { | 523 base::PlatformFileError error_code) { |
| 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 472 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); | 525 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); |
| 473 SendResponse(false); | 526 SendResponse(false); |
| 474 } | 527 } |
| 475 | 528 |
| 476 bool FileWatchBrowserFunctionBase::GetLocalFilePath( | 529 bool FileWatchBrowserFunctionBase::GetLocalFilePath( |
| 477 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { | 530 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { |
| 478 GURL file_origin_url; | 531 GURL file_origin_url; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 this, | 1064 this, |
| 1012 mount_type_str)); | 1065 mount_type_str)); |
| 1013 break; | 1066 break; |
| 1014 } | 1067 } |
| 1015 } | 1068 } |
| 1016 #endif // defined(OS_CHROMEOS) | 1069 #endif // defined(OS_CHROMEOS) |
| 1017 | 1070 |
| 1018 return true; | 1071 return true; |
| 1019 } | 1072 } |
| 1020 | 1073 |
| 1021 void AddMountFunction::GrantFilePermissionsToHost(const FilePath& path, | |
| 1022 int permissions) { | |
| 1023 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | |
| 1024 render_view_host()->GetProcess()->GetID(), path, permissions); | |
| 1025 } | |
| 1026 | |
| 1027 void AddMountFunction::AddGDataMountPoint() { | |
| 1028 fileapi::ExternalFileSystemMountPointProvider* provider = | |
| 1029 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | |
| 1030 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | |
| 1031 if (!provider || provider->HasMountPoint(mount_point)) | |
| 1032 return; | |
| 1033 | |
| 1034 // Grant R/W permissions to gdata 'folder'. File API layer still | |
| 1035 // expects this to be satisfied. | |
| 1036 GrantFilePermissionsToHost(mount_point, | |
| 1037 file_handler_util::GetReadWritePermissions()); | |
| 1038 | |
| 1039 // Grant R/W permission for tmp and pinned cache folder. | |
| 1040 gdata::GDataSystemService* system_service = | |
| 1041 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | |
| 1042 DCHECK(system_service); | |
| 1043 gdata::GDataFileSystem* gdata_file_system = system_service->file_system(); | |
| 1044 | |
| 1045 // We check permissions for raw cache file paths only for read-only | |
| 1046 // operations (when fileEntry.file() is called), so read only permissions | |
| 1047 // should be sufficient for all cache paths. For the rest of supported | |
| 1048 // operations the file access check is done for gdata/ paths. | |
| 1049 GrantFilePermissionsToHost(gdata_file_system->GetGDataCacheTmpDirectory(), | |
| 1050 file_handler_util::GetReadOnlyPermissions()); | |
| 1051 GrantFilePermissionsToHost( | |
| 1052 gdata_file_system->GetGDataCachePersistentDirectory(), | |
| 1053 file_handler_util::GetReadOnlyPermissions()); | |
| 1054 | |
| 1055 provider->AddRemoteMountPoint( | |
| 1056 mount_point, | |
| 1057 new gdata::GDataFileSystemProxy(gdata_file_system)); | |
| 1058 | |
| 1059 FilePath mount_point_virtual; | |
| 1060 if (provider->GetVirtualPath(mount_point, &mount_point_virtual)) | |
| 1061 provider->GrantFileAccessToExtension(extension_id(), mount_point_virtual); | |
| 1062 } | |
| 1063 | |
| 1064 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { | 1074 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { |
| 1065 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? | 1075 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? |
| 1066 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | 1076 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; |
| 1067 DiskMountManager::MountPointInfo mount_info( | 1077 DiskMountManager::MountPointInfo mount_info( |
| 1068 gdata::util::GetGDataMountPointPathAsString(), | 1078 gdata::util::GetGDataMountPointPathAsString(), |
| 1069 gdata::util::GetGDataMountPointPathAsString(), | 1079 gdata::util::GetGDataMountPointPathAsString(), |
| 1070 chromeos::MOUNT_TYPE_GDATA, | 1080 chromeos::MOUNT_TYPE_GDATA, |
| 1071 chromeos::disks::MOUNT_CONDITION_NONE); | 1081 chromeos::disks::MOUNT_CONDITION_NONE); |
| 1072 // Raise mount event | 1082 // Raise mount event |
| 1073 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 1083 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
| 1074 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | 1084 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); |
| 1075 } | 1085 } |
| 1076 | 1086 |
| 1077 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, | 1087 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, |
| 1078 const std::string& token) { | 1088 const std::string& token) { |
| 1079 if (error == gdata::HTTP_SUCCESS) | |
| 1080 AddGDataMountPoint(); | |
| 1081 | |
| 1082 RaiseGDataMountEvent(error); | 1089 RaiseGDataMountEvent(error); |
| 1083 SendResponse(true); | 1090 SendResponse(true); |
| 1084 } | 1091 } |
| 1085 | 1092 |
| 1086 void AddMountFunction::GetLocalPathsResponseOnUIThread( | 1093 void AddMountFunction::GetLocalPathsResponseOnUIThread( |
| 1087 const std::string& mount_type_str, | 1094 const std::string& mount_type_str, |
| 1088 const SelectedFileInfoList& files) { | 1095 const SelectedFileInfoList& files) { |
| 1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1090 | 1097 |
| 1091 if (!files.size()) { | 1098 if (!files.size()) { |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 SET_STRING(IDS_FILE_BROWSER, TAR_GZIP_ARCHIVE_FILE_TYPE); | 1554 SET_STRING(IDS_FILE_BROWSER, TAR_GZIP_ARCHIVE_FILE_TYPE); |
| 1548 SET_STRING(IDS_FILE_BROWSER, PLAIN_TEXT_FILE_TYPE); | 1555 SET_STRING(IDS_FILE_BROWSER, PLAIN_TEXT_FILE_TYPE); |
| 1549 SET_STRING(IDS_FILE_BROWSER, PDF_DOCUMENT_FILE_TYPE); | 1556 SET_STRING(IDS_FILE_BROWSER, PDF_DOCUMENT_FILE_TYPE); |
| 1550 SET_STRING(IDS_FILE_BROWSER, WORD_DOCUMENT_FILE_TYPE); | 1557 SET_STRING(IDS_FILE_BROWSER, WORD_DOCUMENT_FILE_TYPE); |
| 1551 SET_STRING(IDS_FILE_BROWSER, POWERPOINT_PRESENTATION_FILE_TYPE); | 1558 SET_STRING(IDS_FILE_BROWSER, POWERPOINT_PRESENTATION_FILE_TYPE); |
| 1552 SET_STRING(IDS_FILE_BROWSER, EXCEL_FILE_TYPE); | 1559 SET_STRING(IDS_FILE_BROWSER, EXCEL_FILE_TYPE); |
| 1553 | 1560 |
| 1554 SET_STRING(IDS_FILE_BROWSER, GDOC_DOCUMENT_FILE_TYPE); | 1561 SET_STRING(IDS_FILE_BROWSER, GDOC_DOCUMENT_FILE_TYPE); |
| 1555 SET_STRING(IDS_FILE_BROWSER, GSHEET_DOCUMENT_FILE_TYPE); | 1562 SET_STRING(IDS_FILE_BROWSER, GSHEET_DOCUMENT_FILE_TYPE); |
| 1556 SET_STRING(IDS_FILE_BROWSER, GSLIDES_DOCUMENT_FILE_TYPE); | 1563 SET_STRING(IDS_FILE_BROWSER, GSLIDES_DOCUMENT_FILE_TYPE); |
| 1557 SET_STRING(IDS_FILE_BROWSER, GSLIDES_DOCUMENT_FILE_TYPE); | 1564 SET_STRING(IDS_FILE_BROWSER, GDRAW_DOCUMENT_FILE_TYPE); |
| 1558 SET_STRING(IDS_FILE_BROWSER, GTABLE_DOCUMENT_FILE_TYPE); | 1565 SET_STRING(IDS_FILE_BROWSER, GTABLE_DOCUMENT_FILE_TYPE); |
| 1559 | 1566 |
| 1567 |
| 1560 SET_STRING(IDS_FILE_BROWSER, AUDIO_PLAYER_TITLE); | 1568 SET_STRING(IDS_FILE_BROWSER, AUDIO_PLAYER_TITLE); |
| 1561 #undef SET_STRING | 1569 #undef SET_STRING |
| 1562 | 1570 |
| 1563 dict->SetString("PDF_VIEW_ENABLED", | 1571 dict->SetString("PDF_VIEW_ENABLED", |
| 1564 file_manager_util::ShouldBeOpenedWithPdfPlugin(".pdf") ? | 1572 file_manager_util::ShouldBeOpenedWithPdfPlugin(".pdf") ? |
| 1565 "true" : "false"); | 1573 "true" : "false"); |
| 1566 | 1574 |
| 1567 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1575 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
| 1568 | 1576 |
| 1569 if (!profile_->GetPrefs()->GetBoolean(prefs::kDisableGData)) | 1577 if (!profile_->GetPrefs()->GetBoolean(prefs::kDisableGData)) |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 local_source_file, | 1942 local_source_file, |
| 1935 remote_destination_file, | 1943 remote_destination_file, |
| 1936 base::Bind(&TransferFileFunction::OnTransferCompleted, | 1944 base::Bind(&TransferFileFunction::OnTransferCompleted, |
| 1937 this)); | 1945 this)); |
| 1938 } | 1946 } |
| 1939 | 1947 |
| 1940 void TransferFileFunction::OnTransferCompleted( | 1948 void TransferFileFunction::OnTransferCompleted( |
| 1941 base::PlatformFileError error) { | 1949 base::PlatformFileError error) { |
| 1942 SendResponse(error == base::PLATFORM_FILE_OK); | 1950 SendResponse(error == base::PLATFORM_FILE_OK); |
| 1943 } | 1951 } |
| OLD | NEW |