namespace extensions {
namespace {
-// Sets permissions for the Drive mount point so Files.app can access files
-// in the mount point directory. It's safe to call this function even if
-// Drive is disabled by the setting (i.e. prefs::kDisableDrive is true).
-void SetDriveMountPointPermissions(
- Profile* profile,
- const std::string& extension_id,
- content::RenderViewHost* render_view_host) {
- if (!render_view_host ||
- !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) {
- return;
- }
-
- fileapi::ExternalFileSystemBackend* backend =
- file_manager::util::GetFileSystemContextForRenderViewHost(
- profile, render_view_host)->external_backend();
- if (!backend)
- return;
-
- const base::FilePath mount_point = drive::util::GetDriveMountPointPath();
- // Grant R/W permissions to drive 'folder'. File API layer still
- // expects this to be satisfied.
- ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
- render_view_host->GetProcess()->GetID(), mount_point);
-
- base::FilePath mount_point_virtual;
- if (backend->GetVirtualPath(mount_point, &mount_point_virtual))
- backend->GrantFileAccessToExtension(extension_id, mount_point_virtual);
-}
-
// Retrieves total and remaining available size on |mount_path|.
void GetSizeStatsOnBlockingPool(const std::string& mount_path,
uint64* total_size,
base::File::Error error_code) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- error_ = base::StringPrintf("File error %d", static_cast<int>(error_code));
+ SetError(base::StringPrintf("File error %d", static_cast<int>(error_code)));
SendResponse(false);
}
SetupFileSystemAccessPermissions(
scoped_refptr<fileapi::FileSystemContext> file_system_context,
int child_id,
+ Profile* profile,
scoped_refptr<const extensions::Extension> extension) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
child_id, root_dirs[i]);
}
+
+ // Grant R/W permissions to profile-specific directories (Drive, Downloads)
+ // from other profiles. Those directories may not be mounted at this moment
+ // yet, so we need to do this separately from the above loop over
+ // GetRootDirectories().
+ const std::vector<Profile*>& profiles =
+ g_browser_process->profile_manager()->GetLoadedProfiles();
+ for (size_t i = 0; i < profiles.size(); ++i) {
+ if (!profiles[i]->IsOffTheRecord()) {
+ file_manager::util::SetupProfileFileAccessPermissions(child_id,
+ profiles[i]);
+ }
+ }
+
return true;
}
const int child_id = render_view_host()->GetProcess()->GetID();
if (!SetupFileSystemAccessPermissions(file_system_context,
child_id,
+ GetProfile(),
GetExtension())) {
DidFail(base::File::FILE_ERROR_SECURITY);
return false;
}
- // Set permissions for the Drive mount point immediately when we kick of
- // first instance of file manager. The actual mount event will be sent to
- // UI only when we perform proper authentication.
- //
- // Note that we call this function even when Drive is disabled by the
- // setting. Otherwise, we need to call this when the setting is changed at
- // a later time, which complicates the code.
- SetDriveMountPointPermissions(
- GetProfile(), extension_id(), render_view_host());
-
fileapi::FileSystemInfo info =
fileapi::GetFileSystemInfoForChromeOS(source_url_.GetOrigin());
const scoped_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
- base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
- render_view_host(), GetProfile(), GURL(params->mount_path));
- if (file_path.empty())
+ using file_manager::VolumeManager;
+ using file_manager::VolumeInfo;
+ VolumeManager* volume_manager = VolumeManager::Get(GetProfile());
+ if (!volume_manager)
+ return false;
+
+ VolumeInfo volume_info;
+ if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info))
return false;
- if (file_path == drive::util::GetDriveMountPointPath()) {
+ if (volume_info.type == file_manager::VOLUME_TYPE_GOOGLE_DRIVE) {
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(GetProfile());
if (!file_system) {
BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE,
base::Bind(&GetSizeStatsOnBlockingPool,
- file_path.value(),
+ volume_info.mount_path.value(),
total_size,
remaining_size),
base::Bind(&FileBrowserPrivateGetSizeStatsFunction::
if (params->source_url.empty() || params->parent.empty() ||
params->new_name.empty()) {
// Error code in format of DOMError.name.
- error_ = "EncodingError";
+ SetError("EncodingError");
return false;
}
fileapi::FileSystemURL source_url(
file_system_context->CrackURL(GURL(params->source_url)));
fileapi::FileSystemURL destination_url(file_system_context->CrackURL(
- GURL(params->parent + "/" + params->new_name)));
+ GURL(params->parent + "/" + net::EscapePath(params->new_name))));
if (!source_url.is_valid() || !destination_url.is_valid()) {
// Error code in format of DOMError.name.
- error_ = "EncodingError";
+ SetError("EncodingError");
return false;
}