Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: webkit/chromeos/fileapi/cros_mount_point_provider.cc

Issue 6810037: File API changes needed for safely passing user selected file entities from the file browser comp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/chromeos/fileapi/cros_mount_point_provider.cc
===================================================================
--- webkit/chromeos/fileapi/cros_mount_point_provider.cc (revision 81835)
+++ webkit/chromeos/fileapi/cros_mount_point_provider.cc (working copy)
@@ -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 @@
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 @@
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 @@
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 @@
return FilePath();
}
- return FilePath(iter->second);
+ return iter->second;
}
// TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
@@ -116,9 +99,54 @@
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
« no previous file with comments | « webkit/chromeos/fileapi/cros_mount_point_provider.h ('k') | webkit/chromeos/fileapi/file_access_permissions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698