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

Side by Side Diff: webkit/chromeos/fileapi/cros_mount_point_provider.cc

Issue 6864040: Fixed file/directory url resolution for external mount point provider. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/chromeos/fileapi/cros_mount_point_provider.h" 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_callback_factory.h" 8 #include "base/memory/scoped_callback_factory.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/synchronization/lock.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
17 #include "webkit/chromeos/fileapi/file_access_permissions.h" 18 #include "webkit/chromeos/fileapi/file_access_permissions.h"
18 #include "webkit/fileapi/file_system_path_manager.h" 19 #include "webkit/fileapi/file_system_path_manager.h"
19 #include "webkit/fileapi/file_system_util.h" 20 #include "webkit/fileapi/file_system_util.h"
20 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
21 22
22 namespace chromeos { 23 namespace chromeos {
23 24
24 typedef struct { 25 typedef struct {
25 const char* local_root_path; 26 const char* local_root_path;
26 const char* web_root_path; 27 const char* web_root_path;
27 } FixedExposedPaths; 28 } FixedExposedPaths;
28 29
29 // Top level file system elements exposed in FileAPI in ChromeOS: 30 // Top level file system elements exposed in FileAPI in ChromeOS:
30 FixedExposedPaths fixed_exposed_paths[] = { 31 FixedExposedPaths fixed_exposed_paths[] = {
31 {"/home/chronos/user/", "Downloads"}, 32 {"/home/chronos/user/", "Downloads"},
32 {"/", "media"}, 33 {"/", "media"},
33 {"/", "tmp"},
34 }; 34 };
35 35
36 CrosMountPointProvider::CrosMountPointProvider( 36 CrosMountPointProvider::CrosMountPointProvider(
37 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) 37 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy)
38 : special_storage_policy_(special_storage_policy), 38 : special_storage_policy_(special_storage_policy),
39 file_access_permissions_(new FileAccessPermissions()) { 39 file_access_permissions_(new FileAccessPermissions()) {
40 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) { 40 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) {
41 mount_point_map_.insert(std::pair<std::string, FilePath>( 41 mount_point_map_.insert(std::pair<std::string, FilePath>(
42 std::string(fixed_exposed_paths[i].web_root_path), 42 std::string(fixed_exposed_paths[i].web_root_path),
43 FilePath(std::string(fixed_exposed_paths[i].local_root_path)))); 43 FilePath(std::string(fixed_exposed_paths[i].local_root_path))));
44 } 44 }
45 } 45 }
46 46
47 CrosMountPointProvider::~CrosMountPointProvider() { 47 CrosMountPointProvider::~CrosMountPointProvider() {
48 } 48 }
49 49
50 // TODO(zelidrag) share with SandboxMountPointProvider impl. 50 // TODO(zelidrag) share with SandboxMountPointProvider impl.
51 std::string GetOriginIdentifierFromURL( 51 std::string GetOriginIdentifierFromURL(
52 const GURL& url) { 52 const GURL& url) {
53 WebKit::WebSecurityOrigin web_security_origin = 53 WebKit::WebSecurityOrigin web_security_origin =
54 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); 54 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec()));
55 return web_security_origin.databaseIdentifier().utf8(); 55 return web_security_origin.databaseIdentifier().utf8();
56 } 56 }
57 57
58 bool CrosMountPointProvider::GetRootForVirtualPath(
59 const FilePath& virtual_path, FilePath* root_path) {
60 // On the other hand, the root path of a file/dir from the real file system
ericu 2011/04/18 20:35:56 I don't understand this comment. Also, the start "
zel 2011/04/18 20:51:12 sorry, this got removed from the context of other
61 // needs to be mapped based on its first virtual directory segment that
62 // comes just after as in /external/<first-dir-segment>/file.foo
63 std::vector<FilePath::StringType> components;
64 virtual_path.GetComponents(&components);
65 if (components.size() < 1) {
66 return false;
67 }
68
69 base::AutoLock locker(lock_);
70 // Check if this root directory is exposed by this provider.
71 MountPointMap::iterator iter = mount_point_map_.find(components[0]);
72 if (iter == mount_point_map_.end()) {
73 return false;
74 }
75 *root_path = iter->second;
76 return true;
77 }
78
58 void CrosMountPointProvider::GetFileSystemRootPath( 79 void CrosMountPointProvider::GetFileSystemRootPath(
59 const GURL& origin_url, 80 const GURL& origin_url,
60 fileapi::FileSystemType type, 81 fileapi::FileSystemType type,
61 bool create, 82 bool create,
83 bool is_file_system,
ericu 2011/04/18 20:35:56 is_file_system seems poorly named. If this flag i
zel 2011/04/18 20:51:12 I agree about the name, any suggestion is welcomed
84 const FilePath& virtual_path,
62 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) { 85 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) {
63 DCHECK(type == fileapi::kFileSystemTypeExternal); 86 DCHECK(type == fileapi::kFileSystemTypeExternal);
64
65 std::string name(GetOriginIdentifierFromURL(origin_url)); 87 std::string name(GetOriginIdentifierFromURL(origin_url));
66 name += ':'; 88 name += ':';
67 name += fileapi::kExternalName; 89 name += fileapi::kExternalName;
68 90 // File system root path is a non-existent path from the file system...
ericu 2011/04/18 20:35:56 Why are we looking up a nonexistent path?
zel 2011/04/18 20:51:12 see above
69 FilePath root_path = FilePath(fileapi::kExternalDir); 91 FilePath root_path;
92 if (is_file_system) {
93 root_path = FilePath(fileapi::kExternalDir);
ericu 2011/04/18 20:35:56 This is kind of weird. '/external/' is in the nam
zel 2011/04/18 20:51:12 see my first comment on this one as well
94 } else {
95 if (!GetRootForVirtualPath(virtual_path, &root_path)) {
96 callback_ptr->Run(false, FilePath(), std::string());
97 return;
98 }
99 }
70 callback_ptr->Run(!root_path.empty(), root_path, name); 100 callback_ptr->Run(!root_path.empty(), root_path, name);
71 } 101 }
72 102
73 // Like GetFileSystemRootPath, but synchronous, and can be called only while 103 // Like GetFileSystemRootPath, but synchronous, and can be called only while
74 // running on the file thread. 104 // running on the file thread.
75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( 105 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
76 const GURL& origin_url, 106 const GURL& origin_url,
77 fileapi::FileSystemType type, 107 fileapi::FileSystemType type,
78 const FilePath& virtual_path, 108 const FilePath& virtual_path,
79 bool create) { 109 bool create) {
80 DCHECK(type == fileapi::kFileSystemTypeExternal); 110 DCHECK(type == fileapi::kFileSystemTypeExternal);
111 FilePath root_path;
112 if (!GetRootForVirtualPath(virtual_path, &root_path))
113 return FilePath();
81 114
82 std::vector<FilePath::StringType> components; 115 return root_path;
83 virtual_path.GetComponents(&components);
84 if (components.size() < 1) {
85 return FilePath();
86 }
87
88 // Check if this root directory is exposed by this provider.
89 MountPointMap::iterator iter = mount_point_map_.find(components[0]);
90 if (iter == mount_point_map_.end()) {
91 return FilePath();
92 }
93
94 return iter->second;
95 } 116 }
96 117
97 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. 118 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
98 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { 119 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const {
99 return false; 120 return false;
100 } 121 }
101 122
102 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, 123 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url,
103 fileapi::FileSystemType type, 124 fileapi::FileSystemType type,
104 const FilePath& virtual_path) { 125 const FilePath& virtual_path) {
105 if (type != fileapi::kFileSystemTypeExternal) 126 if (type != fileapi::kFileSystemTypeExternal)
106 return false; 127 return false;
107 std::string extension_id = origin_url.host(); 128 std::string extension_id = origin_url.host();
108 // Check first to make sure this extension has fileBrowserHander permissions. 129 // Check first to make sure this extension has fileBrowserHander permissions.
109 if (!special_storage_policy_->IsFileHandler(extension_id)) 130 if (!special_storage_policy_->IsFileHandler(extension_id))
110 return false; 131 return false;
111 return file_access_permissions_->HasAccessPermission(extension_id, 132 return file_access_permissions_->HasAccessPermission(extension_id,
112 virtual_path); 133 virtual_path);
113 } 134 }
114 135
136 void CrosMountPointProvider::AddMountPoint(FilePath mount_point) {
137 base::AutoLock locker(lock_);
138 mount_point_map_.insert(std::pair<std::string, FilePath>(
139 mount_point.BaseName().value(), mount_point.DirName()));
140 }
141
142 void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) {
143 base::AutoLock locker(lock_);
144 mount_point_map_.erase(mount_point.BaseName().value());
145 }
146
115 void CrosMountPointProvider::GrantFullAccessToExtension( 147 void CrosMountPointProvider::GrantFullAccessToExtension(
116 const std::string& extension_id) { 148 const std::string& extension_id) {
117 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); 149 DCHECK(special_storage_policy_->IsFileHandler(extension_id));
118 if (!special_storage_policy_->IsFileHandler(extension_id)) 150 if (!special_storage_policy_->IsFileHandler(extension_id))
119 return; 151 return;
120 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 152 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
121 iter != mount_point_map_.end(); 153 iter != mount_point_map_.end();
122 ++iter) { 154 ++iter) {
123 GrantFileAccessToExtension(extension_id, FilePath(iter->first)); 155 GrantFileAccessToExtension(extension_id, FilePath(iter->first));
124 } 156 }
(...skipping 18 matching lines...) Expand all
143 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 175 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
144 iter != mount_point_map_.end(); 176 iter != mount_point_map_.end();
145 ++iter) { 177 ++iter) {
146 root_dirs.push_back(iter->second.Append(iter->first)); 178 root_dirs.push_back(iter->second.Append(iter->first));
147 } 179 }
148 return root_dirs; 180 return root_dirs;
149 } 181 }
150 182
151 } // namespace chromeos 183 } // namespace chromeos
152 184
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698