summaryrefslogtreecommitdiffstats
path: root/webkit/chromeos/fileapi/cros_mount_point_provider.cc
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 04:01:08 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 04:01:08 +0000
commitb777b3386e10d38944cc717e4192b7858cbdc7fe (patch)
tree85d37a15e729df855d81e0973d9ed1bb3f90d347 /webkit/chromeos/fileapi/cros_mount_point_provider.cc
parent4b59a325a589190ab95622be4e1b6a70bc02914f (diff)
downloadchromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.zip
chromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.tar.gz
chromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.tar.bz2
File API changes needed for safely passing user selected file entities from the file browser component extension to a 3rd party extension.
BUG=chromium-os:11996 TEST=FileAccessPermissionsTest.FileAccessChecks Review URL: http://codereview.chromium.org/6810037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/chromeos/fileapi/cros_mount_point_provider.cc')
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc88
1 files changed, 58 insertions, 30 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index 159dc3b..9efc5cc 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -14,14 +14,13 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
+#include "webkit/chromeos/fileapi/file_access_permissions.h"
#include "webkit/fileapi/file_system_path_manager.h"
+#include "webkit/fileapi/file_system_util.h"
#include "webkit/glue/webkit_glue.h"
namespace chromeos {
-const char CrosMountPointProvider::kLocalName[] = "Local";
-const char CrosMountPointProvider::kLocalDirName[] = "/local/";
-
typedef struct {
const char* local_root_path;
const char* web_root_path;
@@ -36,28 +35,12 @@ FixedExposedPaths fixed_exposed_paths[] = {
CrosMountPointProvider::CrosMountPointProvider(
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy)
- : local_dir_name_(kLocalName),
- special_storage_policy_(special_storage_policy) {
-
- // TODO(zelidrag): There's got to be a better way to generate UUID.
- srand(time(NULL));
- std::string virtual_root;
- virtual_root.append(base::StringPrintf("%hx%hx-%hx-%hx-%hx-%hx%hx%hx",
- static_cast<unsigned short>(rand()), static_cast<unsigned short>(rand()),
- static_cast<unsigned short>(rand()),
- static_cast<unsigned short>(rand()),
- static_cast<unsigned short>(rand()),
- static_cast<unsigned short>(rand()), static_cast<unsigned short>(rand()),
- static_cast<unsigned short>(rand())));
-
- // Create virtual root node.
- virtual_root_path_ = FilePath(virtual_root);
- base_path_ = virtual_root_path_.Append(local_dir_name_);
-
+ : special_storage_policy_(special_storage_policy),
+ file_access_permissions_(new FileAccessPermissions()) {
for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) {
- mount_point_map_.insert(std::pair<std::string, std::string>(
+ mount_point_map_.insert(std::pair<std::string, FilePath>(
std::string(fixed_exposed_paths[i].web_root_path),
- std::string(fixed_exposed_paths[i].local_root_path)));
+ FilePath(std::string(fixed_exposed_paths[i].local_root_path))));
}
}
@@ -77,13 +60,13 @@ void CrosMountPointProvider::GetFileSystemRootPath(
fileapi::FileSystemType type,
bool create,
fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) {
- DCHECK(type == fileapi::kFileSystemTypeLocal);
+ DCHECK(type == fileapi::kFileSystemTypeExternal);
std::string name(GetOriginIdentifierFromURL(origin_url));
name += ':';
- name += CrosMountPointProvider::kLocalName;
+ name += fileapi::kExternalName;
- FilePath root_path = FilePath(CrosMountPointProvider::kLocalDirName);
+ FilePath root_path = FilePath(fileapi::kExternalDir);
callback_ptr->Run(!root_path.empty(), root_path, name);
}
@@ -94,7 +77,7 @@ FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
fileapi::FileSystemType type,
const FilePath& virtual_path,
bool create) {
- DCHECK(type == fileapi::kFileSystemTypeLocal);
+ DCHECK(type == fileapi::kFileSystemTypeExternal);
std::vector<FilePath::StringType> components;
virtual_path.GetComponents(&components);
@@ -108,7 +91,7 @@ FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
return FilePath();
}
- return FilePath(iter->second);
+ return iter->second;
}
// TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
@@ -116,8 +99,53 @@ bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const {
return false;
}
-bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url) {
- return special_storage_policy_->IsLocalFileSystemAccessAllowed(origin_url);
+bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url,
+ fileapi::FileSystemType type,
+ const FilePath& virtual_path) {
+ if (type != fileapi::kFileSystemTypeExternal)
+ return false;
+ 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::GrantFullAccessToExtension(
+ const std::string& extension_id) {
+ DCHECK(special_storage_policy_->IsFileHandler(extension_id));
+ if (!special_storage_policy_->IsFileHandler(extension_id))
+ return;
+ for (MountPointMap::const_iterator iter = mount_point_map_.begin();
+ iter != mount_point_map_.end();
+ ++iter) {
+ GrantFileAccessToExtension(extension_id, FilePath(iter->first));
+ }
+}
+
+void CrosMountPointProvider::GrantFileAccessToExtension(
+ const std::string& extension_id, const FilePath& virtual_path) {
+ // All we care about here is access from extensions for now.
+ DCHECK(special_storage_policy_->IsFileHandler(extension_id));
+ if (!special_storage_policy_->IsFileHandler(extension_id))
+ return;
+ file_access_permissions_->GrantAccessPermission(extension_id, virtual_path);
+}
+
+void CrosMountPointProvider::RevokeAccessForExtension(
+ const std::string& extension_id) {
+ file_access_permissions_->RevokePermissions(extension_id);
+}
+
+std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const {
+ std::vector<FilePath> root_dirs;
+ for (MountPointMap::const_iterator iter = mount_point_map_.begin();
+ iter != mount_point_map_.end();
+ ++iter) {
+ root_dirs.push_back(iter->second.Append(iter->first));
+ }
+ return root_dirs;
}
} // namespace chromeos