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

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
30 const char kChromeUIScheme[] = "chrome";
31
29 // Top level file system elements exposed in FileAPI in ChromeOS: 32 // Top level file system elements exposed in FileAPI in ChromeOS:
30 FixedExposedPaths fixed_exposed_paths[] = { 33 FixedExposedPaths fixed_exposed_paths[] = {
31 {"/home/chronos/user/", "Downloads"}, 34 {"/home/chronos/user/", "Downloads"},
32 {"/", "media"}, 35 {"/", "media"},
33 {"/", "tmp"},
34 }; 36 };
35 37
36 CrosMountPointProvider::CrosMountPointProvider( 38 CrosMountPointProvider::CrosMountPointProvider(
37 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) 39 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy)
38 : special_storage_policy_(special_storage_policy), 40 : special_storage_policy_(special_storage_policy),
39 file_access_permissions_(new FileAccessPermissions()) { 41 file_access_permissions_(new FileAccessPermissions()) {
40 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) { 42 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) {
41 mount_point_map_.insert(std::pair<std::string, FilePath>( 43 mount_point_map_.insert(std::pair<std::string, FilePath>(
42 std::string(fixed_exposed_paths[i].web_root_path), 44 std::string(fixed_exposed_paths[i].web_root_path),
43 FilePath(std::string(fixed_exposed_paths[i].local_root_path)))); 45 FilePath(std::string(fixed_exposed_paths[i].local_root_path))));
44 } 46 }
45 } 47 }
46 48
47 CrosMountPointProvider::~CrosMountPointProvider() { 49 CrosMountPointProvider::~CrosMountPointProvider() {
48 } 50 }
49 51
50 // TODO(zelidrag) share with SandboxMountPointProvider impl. 52 // TODO(zelidrag) share with SandboxMountPointProvider impl.
51 std::string GetOriginIdentifierFromURL( 53 std::string GetOriginIdentifierFromURL(
52 const GURL& url) { 54 const GURL& url) {
53 WebKit::WebSecurityOrigin web_security_origin = 55 WebKit::WebSecurityOrigin web_security_origin =
54 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); 56 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec()));
55 return web_security_origin.databaseIdentifier().utf8(); 57 return web_security_origin.databaseIdentifier().utf8();
56 } 58 }
57 59
60 bool CrosMountPointProvider::GetRootForVirtualPath(
61 const FilePath& virtual_path, FilePath* root_path) {
62 std::vector<FilePath::StringType> components;
63 virtual_path.GetComponents(&components);
64 if (components.size() < 1) {
65 return false;
66 }
67
68 base::AutoLock locker(lock_);
69 // Check if this root mount point is exposed by this provider.
70 MountPointMap::iterator iter = mount_point_map_.find(components[0]);
71 if (iter == mount_point_map_.end()) {
72 return false;
73 }
74 *root_path = iter->second;
75 return true;
76 }
77
58 void CrosMountPointProvider::GetFileSystemRootPath( 78 void CrosMountPointProvider::GetFileSystemRootPath(
ericu 2011/04/19 20:30:49 Add a comment explaining that this is only called
zel 2011/04/19 23:14:00 Done.
59 const GURL& origin_url, 79 const GURL& origin_url,
60 fileapi::FileSystemType type, 80 fileapi::FileSystemType type,
61 bool create, 81 bool create,
62 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) { 82 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) {
63 DCHECK(type == fileapi::kFileSystemTypeExternal); 83 DCHECK(type == fileapi::kFileSystemTypeExternal);
64
65 std::string name(GetOriginIdentifierFromURL(origin_url)); 84 std::string name(GetOriginIdentifierFromURL(origin_url));
66 name += ':'; 85 name += ':';
67 name += fileapi::kExternalName; 86 name += fileapi::kExternalName;
68 87 FilePath root_path;
69 FilePath root_path = FilePath(fileapi::kExternalDir); 88 root_path = FilePath(fileapi::kExternalDir);
70 callback_ptr->Run(!root_path.empty(), root_path, name); 89 callback_ptr->Run(!root_path.empty(), root_path, name);
ericu 2011/04/19 20:30:49 This code looks odd. Why check if it's empty? Als
zel 2011/04/19 23:14:00 What do you mean URL? This one is accepting FilePa
ericu 2011/04/19 23:36:19 You're right--I got myself confused. Nevermind.
zel 2011/04/20 02:02:07 I think there are tests on my side that expect /ex
71 } 90 }
72 91
73 // Like GetFileSystemRootPath, but synchronous, and can be called only while 92 // Like GetFileSystemRootPath, but synchronous, and can be called only while
74 // running on the file thread. 93 // running on the file thread.
75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( 94 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
76 const GURL& origin_url, 95 const GURL& origin_url,
77 fileapi::FileSystemType type, 96 fileapi::FileSystemType type,
78 const FilePath& virtual_path, 97 const FilePath& virtual_path,
79 bool create) { 98 bool create) {
80 DCHECK(type == fileapi::kFileSystemTypeExternal); 99 DCHECK(type == fileapi::kFileSystemTypeExternal);
100 FilePath root_path;
101 if (!GetRootForVirtualPath(virtual_path, &root_path))
102 return FilePath();
81 103
82 std::vector<FilePath::StringType> components; 104 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 } 105 }
96 106
97 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. 107 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
98 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { 108 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const {
99 return false; 109 return false;
100 } 110 }
101 111
102 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, 112 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url,
103 fileapi::FileSystemType type, 113 fileapi::FileSystemType type,
104 const FilePath& virtual_path) { 114 const FilePath& virtual_path) {
105 if (type != fileapi::kFileSystemTypeExternal) 115 if (type != fileapi::kFileSystemTypeExternal)
106 return false; 116 return false;
117
118 // Permit access to mount points from internal WebUI.
119 if (origin_url.SchemeIs(kChromeUIScheme))
120 return true;
121
107 std::string extension_id = origin_url.host(); 122 std::string extension_id = origin_url.host();
108 // Check first to make sure this extension has fileBrowserHander permissions. 123 // Check first to make sure this extension has fileBrowserHander permissions.
109 if (!special_storage_policy_->IsFileHandler(extension_id)) 124 if (!special_storage_policy_->IsFileHandler(extension_id))
110 return false; 125 return false;
126
111 return file_access_permissions_->HasAccessPermission(extension_id, 127 return file_access_permissions_->HasAccessPermission(extension_id,
112 virtual_path); 128 virtual_path);
113 } 129 }
114 130
131 void CrosMountPointProvider::AddMountPoint(FilePath mount_point) {
132 base::AutoLock locker(lock_);
133 mount_point_map_.insert(std::pair<std::string, FilePath>(
134 mount_point.BaseName().value(), mount_point.DirName()));
135 }
136
137 void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) {
138 base::AutoLock locker(lock_);
139 mount_point_map_.erase(mount_point.BaseName().value());
140 }
141
115 void CrosMountPointProvider::GrantFullAccessToExtension( 142 void CrosMountPointProvider::GrantFullAccessToExtension(
116 const std::string& extension_id) { 143 const std::string& extension_id) {
117 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); 144 DCHECK(special_storage_policy_->IsFileHandler(extension_id));
118 if (!special_storage_policy_->IsFileHandler(extension_id)) 145 if (!special_storage_policy_->IsFileHandler(extension_id))
119 return; 146 return;
120 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 147 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
121 iter != mount_point_map_.end(); 148 iter != mount_point_map_.end();
122 ++iter) { 149 ++iter) {
123 GrantFileAccessToExtension(extension_id, FilePath(iter->first)); 150 GrantFileAccessToExtension(extension_id, FilePath(iter->first));
124 } 151 }
(...skipping 18 matching lines...) Expand all
143 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 170 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
144 iter != mount_point_map_.end(); 171 iter != mount_point_map_.end();
145 ++iter) { 172 ++iter) {
146 root_dirs.push_back(iter->second.Append(iter->first)); 173 root_dirs.push_back(iter->second.Append(iter->first));
147 } 174 }
148 return root_dirs; 175 return root_dirs;
149 } 176 }
150 177
151 } // namespace chromeos 178 } // namespace chromeos
152 179
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698