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

Side by Side Diff: webkit/fileapi/sandbox_mount_point_provider.cc

Issue 12193007: Deprecate MountPointProvider::IsAccessAllowed in favor of GetPermissionPolicy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base::FilePath fix Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/fileapi/sandbox_mount_point_provider.h" 5 #include "webkit/fileapi/sandbox_mount_point_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (file_system_options_.is_incognito()) 218 if (file_system_options_.is_incognito())
219 // TODO(kinuko): return an isolated temporary directory. 219 // TODO(kinuko): return an isolated temporary directory.
220 return base::FilePath(); 220 return base::FilePath();
221 221
222 if (!IsAllowedScheme(url.origin())) 222 if (!IsAllowedScheme(url.origin()))
223 return base::FilePath(); 223 return base::FilePath();
224 224
225 return GetBaseDirectoryForOriginAndType(url.origin(), url.type(), create); 225 return GetBaseDirectoryForOriginAndType(url.origin(), url.type(), create);
226 } 226 }
227 227
228 bool SandboxMountPointProvider::IsAccessAllowed(const FileSystemURL& url) {
229 if (!CanHandleType(url.type()))
230 return false;
231 // We essentially depend on quota to do our access controls, so here
232 // we only check if the requested scheme is allowed or not.
233 return IsAllowedScheme(url.origin());
234 }
235
236 bool SandboxMountPointProvider::IsRestrictedFileName(const base::FilePath& filen ame)
237 const {
238 if (filename.value().empty())
239 return false;
240
241 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) {
242 // Exact match.
243 if (filename.value() == kRestrictedNames[i])
244 return true;
245 }
246
247 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) {
248 if (filename.value().find(kRestrictedChars[i]) !=
249 base::FilePath::StringType::npos)
250 return true;
251 }
252
253 return false;
254 }
255
256 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil( 228 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil(
257 FileSystemType type) { 229 FileSystemType type) {
258 DCHECK(sandbox_file_util_.get()); 230 DCHECK(sandbox_file_util_.get());
259 return sandbox_file_util_->sync_file_util(); 231 return sandbox_file_util_->sync_file_util();
260 } 232 }
261 233
262 AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil( 234 AsyncFileUtil* SandboxMountPointProvider::GetAsyncFileUtil(
263 FileSystemType type) { 235 FileSystemType type) {
264 return sandbox_file_util_.get(); 236 return sandbox_file_util_.get();
265 } 237 }
266 238
267 FilePermissionPolicy SandboxMountPointProvider::GetPermissionPolicy( 239 FilePermissionPolicy SandboxMountPointProvider::GetPermissionPolicy(
268 const FileSystemURL& url, int permissions) const { 240 const FileSystemURL& url, int permissions) const {
241 if (!CanHandleType(url.type()) || !IsAllowedScheme(url.origin()))
242 return FILE_PERMISSION_ALWAYS_DENY;
243
244 if (url.path().ReferencesParent())
245 return FILE_PERMISSION_ALWAYS_DENY;
246
247 // Any write access is disallowed on the root path.
248 if ((url.path().empty() || VirtualPath::DirName(url.path()) == url.path())
249 && (permissions & ~kReadFilePermissions))
250 return FILE_PERMISSION_ALWAYS_DENY;
251
252 if ((permissions & kCreateFilePermissions) == kCreateFilePermissions) {
253 base::FilePath filename = VirtualPath::BaseName(url.path());
254 // See if the name is allowed to create.
255 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) {
256 if (filename.value() == kRestrictedNames[i])
257 return FILE_PERMISSION_ALWAYS_DENY;
258 }
259 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) {
260 if (filename.value().find(kRestrictedChars[i]) !=
261 base::FilePath::StringType::npos)
262 return FILE_PERMISSION_ALWAYS_DENY;
263 }
264 }
265
269 // Access to the sandbox directory (and only to the directory) should be 266 // Access to the sandbox directory (and only to the directory) should be
270 // always allowed. 267 // always allowed.
271 CHECK(CanHandleType(url.type()));
272 CHECK(!url.path().ReferencesParent());
273 return FILE_PERMISSION_ALWAYS_ALLOW; 268 return FILE_PERMISSION_ALWAYS_ALLOW;
274 } 269 }
275 270
276 FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation( 271 FileSystemOperation* SandboxMountPointProvider::CreateFileSystemOperation(
277 const FileSystemURL& url, 272 const FileSystemURL& url,
278 FileSystemContext* context, 273 FileSystemContext* context,
279 base::PlatformFileError* error_code) const { 274 base::PlatformFileError* error_code) const {
280 scoped_ptr<FileSystemOperationContext> operation_context( 275 scoped_ptr<FileSystemOperationContext> operation_context(
281 new FileSystemOperationContext(context)); 276 new FileSystemOperationContext(context));
282 277
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } 578 }
584 return false; 579 return false;
585 } 580 }
586 581
587 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() { 582 ObfuscatedFileUtil* SandboxMountPointProvider::sandbox_sync_file_util() {
588 DCHECK(sandbox_file_util_.get()); 583 DCHECK(sandbox_file_util_.get());
589 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util()); 584 return static_cast<ObfuscatedFileUtil*>(sandbox_file_util_->sync_file_util());
590 } 585 }
591 586
592 } // namespace fileapi 587 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/sandbox_mount_point_provider.h ('k') | webkit/fileapi/sandbox_mount_point_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698