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

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
58 void CrosMountPointProvider::GetFileSystemRootPath( 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
78 void CrosMountPointProvider::ValidateFileSystemRootAndGetURL(
kinuko 2011/04/20 14:44:18 I'm afraid this new method name may confuse the re
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(true, root_path, name);
71 } 90 }
72 91
73 // Like GetFileSystemRootPath, but synchronous, and can be called only while 92 FilePath CrosMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread(
74 // running on the file thread.
75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread(
76 const GURL& origin_url, 93 const GURL& origin_url,
77 fileapi::FileSystemType type, 94 fileapi::FileSystemType type,
78 const FilePath& virtual_path, 95 const FilePath& virtual_path,
79 bool create) { 96 bool create) {
80 DCHECK(type == fileapi::kFileSystemTypeExternal); 97 DCHECK(type == fileapi::kFileSystemTypeExternal);
98 FilePath root_path;
99 if (!GetRootForVirtualPath(virtual_path, &root_path))
100 return FilePath();
81 101
82 std::vector<FilePath::StringType> components; 102 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 } 103 }
96 104
97 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. 105 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl.
98 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { 106 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const {
99 return false; 107 return false;
100 } 108 }
101 109
102 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, 110 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url,
103 fileapi::FileSystemType type, 111 fileapi::FileSystemType type,
104 const FilePath& virtual_path) { 112 const FilePath& virtual_path) {
105 if (type != fileapi::kFileSystemTypeExternal) 113 if (type != fileapi::kFileSystemTypeExternal)
106 return false; 114 return false;
115
116 // Permit access to mount points from internal WebUI.
117 if (origin_url.SchemeIs(kChromeUIScheme))
118 return true;
119
107 std::string extension_id = origin_url.host(); 120 std::string extension_id = origin_url.host();
108 // Check first to make sure this extension has fileBrowserHander permissions. 121 // Check first to make sure this extension has fileBrowserHander permissions.
109 if (!special_storage_policy_->IsFileHandler(extension_id)) 122 if (!special_storage_policy_->IsFileHandler(extension_id))
110 return false; 123 return false;
124
111 return file_access_permissions_->HasAccessPermission(extension_id, 125 return file_access_permissions_->HasAccessPermission(extension_id,
112 virtual_path); 126 virtual_path);
113 } 127 }
114 128
129 void CrosMountPointProvider::AddMountPoint(FilePath mount_point) {
130 base::AutoLock locker(lock_);
131 mount_point_map_.insert(std::pair<std::string, FilePath>(
132 mount_point.BaseName().value(), mount_point.DirName()));
133 }
134
135 void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) {
136 base::AutoLock locker(lock_);
137 mount_point_map_.erase(mount_point.BaseName().value());
138 }
139
115 void CrosMountPointProvider::GrantFullAccessToExtension( 140 void CrosMountPointProvider::GrantFullAccessToExtension(
116 const std::string& extension_id) { 141 const std::string& extension_id) {
117 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); 142 DCHECK(special_storage_policy_->IsFileHandler(extension_id));
118 if (!special_storage_policy_->IsFileHandler(extension_id)) 143 if (!special_storage_policy_->IsFileHandler(extension_id))
119 return; 144 return;
120 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 145 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
121 iter != mount_point_map_.end(); 146 iter != mount_point_map_.end();
122 ++iter) { 147 ++iter) {
123 GrantFileAccessToExtension(extension_id, FilePath(iter->first)); 148 GrantFileAccessToExtension(extension_id, FilePath(iter->first));
124 } 149 }
(...skipping 18 matching lines...) Expand all
143 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); 168 for (MountPointMap::const_iterator iter = mount_point_map_.begin();
144 iter != mount_point_map_.end(); 169 iter != mount_point_map_.end();
145 ++iter) { 170 ++iter) {
146 root_dirs.push_back(iter->second.Append(iter->first)); 171 root_dirs.push_back(iter->second.Append(iter->first));
147 } 172 }
148 return root_dirs; 173 return root_dirs;
149 } 174 }
150 175
151 } // namespace chromeos 176 } // namespace chromeos
152 177
OLDNEW
« no previous file with comments | « webkit/chromeos/fileapi/cros_mount_point_provider.h ('k') | webkit/fileapi/file_system_callback_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698