summaryrefslogtreecommitdiffstats
path: root/webkit/chromeos
diff options
context:
space:
mode:
authorkerz@chromium.org <kerz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 22:19:17 +0000
committerkerz@chromium.org <kerz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-20 22:19:17 +0000
commiteeed85c4662942e0c9e557d36fa0d26a938058e5 (patch)
tree3e6e267779cd0de15b1dfb8543e399023a4b1342 /webkit/chromeos
parentfe2534f1d0294dadd3bc915982ef378906a2be57 (diff)
downloadchromium_src-eeed85c4662942e0c9e557d36fa0d26a938058e5.zip
chromium_src-eeed85c4662942e0c9e557d36fa0d26a938058e5.tar.gz
chromium_src-eeed85c4662942e0c9e557d36fa0d26a938058e5.tar.bz2
Merge 82266 - Fixed file/directory url resolution for external mount point provider.Per Eric's request, refactored FileSystemDirURLRequestJob and FileSystemURLRequestJob classes to resolve local file system through a new operation.BUG=chromium-os:14225TEST=added new test cases to FileSystemPathManagerTest.*, added FileSystemOperationTest.TestGetLocalFilePathSuccessReview URL: http://codereview.chromium.org/6864040
TBR=zelidrag@chromium.org Review URL: http://codereview.chromium.org/6882102 git-svn-id: svn://svn.chromium.org/chrome/branches/742/src@82372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/chromeos')
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc67
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.h15
2 files changed, 58 insertions, 24 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index 9efc5cc..b5d40ae 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/stringprintf.h"
+#include "base/synchronization/lock.h"
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
@@ -26,11 +27,12 @@ typedef struct {
const char* web_root_path;
} FixedExposedPaths;
+const char kChromeUIScheme[] = "chrome";
+
// Top level file system elements exposed in FileAPI in ChromeOS:
FixedExposedPaths fixed_exposed_paths[] = {
{"/home/chronos/user/", "Downloads"},
{"/", "media"},
- {"/", "tmp"},
};
CrosMountPointProvider::CrosMountPointProvider(
@@ -55,43 +57,49 @@ std::string GetOriginIdentifierFromURL(
return web_security_origin.databaseIdentifier().utf8();
}
-void CrosMountPointProvider::GetFileSystemRootPath(
+bool CrosMountPointProvider::GetRootForVirtualPath(
+ const FilePath& virtual_path, FilePath* root_path) {
+ std::vector<FilePath::StringType> components;
+ virtual_path.GetComponents(&components);
+ if (components.size() < 1) {
+ return false;
+ }
+
+ base::AutoLock locker(lock_);
+ // Check if this root mount point is exposed by this provider.
+ MountPointMap::iterator iter = mount_point_map_.find(components[0]);
+ if (iter == mount_point_map_.end()) {
+ return false;
+ }
+ *root_path = iter->second;
+ return true;
+}
+
+void CrosMountPointProvider::ValidateFileSystemRootAndGetURL(
const GURL& origin_url,
fileapi::FileSystemType type,
bool create,
fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) {
DCHECK(type == fileapi::kFileSystemTypeExternal);
-
std::string name(GetOriginIdentifierFromURL(origin_url));
name += ':';
name += fileapi::kExternalName;
-
- FilePath root_path = FilePath(fileapi::kExternalDir);
- callback_ptr->Run(!root_path.empty(), root_path, name);
+ FilePath root_path;
+ root_path = FilePath(fileapi::kExternalDir);
+ callback_ptr->Run(true, root_path, name);
}
-// Like GetFileSystemRootPath, but synchronous, and can be called only while
-// running on the file thread.
-FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
+FilePath CrosMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread(
const GURL& origin_url,
fileapi::FileSystemType type,
const FilePath& virtual_path,
bool create) {
DCHECK(type == fileapi::kFileSystemTypeExternal);
-
- std::vector<FilePath::StringType> components;
- virtual_path.GetComponents(&components);
- if (components.size() < 1) {
- return FilePath();
- }
-
- // Check if this root directory is exposed by this provider.
- MountPointMap::iterator iter = mount_point_map_.find(components[0]);
- if (iter == mount_point_map_.end()) {
+ FilePath root_path;
+ if (!GetRootForVirtualPath(virtual_path, &root_path))
return FilePath();
- }
- return iter->second;
+ return root_path;
}
// TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
@@ -104,14 +112,31 @@ bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url,
const FilePath& virtual_path) {
if (type != fileapi::kFileSystemTypeExternal)
return false;
+
+ // Permit access to mount points from internal WebUI.
+ if (origin_url.SchemeIs(kChromeUIScheme))
+ return true;
+
std::string extension_id = origin_url.host();
// Check first to make sure this extension has fileBrowserHander permissions.
if (!special_storage_policy_->IsFileHandler(extension_id))
return false;
+
return file_access_permissions_->HasAccessPermission(extension_id,
virtual_path);
}
+void CrosMountPointProvider::AddMountPoint(FilePath mount_point) {
+ base::AutoLock locker(lock_);
+ mount_point_map_.insert(std::pair<std::string, FilePath>(
+ mount_point.BaseName().value(), mount_point.DirName()));
+}
+
+void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) {
+ base::AutoLock locker(lock_);
+ mount_point_map_.erase(mount_point.BaseName().value());
+}
+
void CrosMountPointProvider::GrantFullAccessToExtension(
const std::string& extension_id) {
DCHECK(special_storage_policy_->IsFileHandler(extension_id));
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h
index 23af15f..7c48df4 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.h
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h
@@ -10,6 +10,7 @@
#include <vector>
#include "base/file_path.h"
+#include "base/synchronization/lock.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/quota/special_storage_policy.h"
@@ -29,12 +30,12 @@ class CrosMountPointProvider
virtual bool IsAccessAllowed(const GURL& origin_url,
fileapi::FileSystemType type,
const FilePath& virtual_path) OVERRIDE;
- virtual void GetFileSystemRootPath(
+ virtual void ValidateFileSystemRootAndGetURL(
const GURL& origin_url,
fileapi::FileSystemType type,
bool create,
fileapi::FileSystemPathManager::GetRootPathCallback* callback) OVERRIDE;
- virtual FilePath GetFileSystemRootPathOnFileThread(
+ virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
const GURL& origin_url,
fileapi::FileSystemType type,
const FilePath& virtual_path,
@@ -47,12 +48,20 @@ class CrosMountPointProvider
const std::string& extension_id) OVERRIDE;
virtual void GrantFileAccessToExtension(
const std::string& extension_id, const FilePath& virtual_path) OVERRIDE;
- void RevokeAccessForExtension(const std::string& extension_id) OVERRIDE;
+ virtual void RevokeAccessForExtension(
+ const std::string& extension_id) OVERRIDE;
+ virtual void AddMountPoint(FilePath mount_point) OVERRIDE;
+ virtual void RemoveMountPoint(FilePath mount_point) OVERRIDE;
private:
class GetFileSystemRootPathTask;
typedef std::map<std::string, FilePath> MountPointMap;
+ // Gives the real file system's |root_path| for given |virtual_path|. Returns
+ // false when |virtual_path| cannot be mapped to the real file system.
+ bool GetRootForVirtualPath(const FilePath& virtual_path, FilePath* root_path);
+
+ base::Lock lock_; // Synchronize all access to path_map_.
MountPointMap mount_point_map_;
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
scoped_ptr<FileAccessPermissions> file_access_permissions_;