From aea270f67aaf7b259b3ab48bc5b7c086b053f155 Mon Sep 17 00:00:00 2001 From: "kinuko@chromium.org" Date: Thu, 27 Jun 2013 12:16:06 +0000 Subject: Cleanup: Add VirtualPath::IsRootPath() BUG=241701 TEST=FileSystemUtilTest.IsRootPath NOTRY=true R=tzik@chromium.org Review URL: https://codereview.chromium.org/18018002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208889 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/browser/fileapi/sandbox_mount_point_provider.cc | 2 +- webkit/common/fileapi/file_system_util.cc | 8 ++++++++ webkit/common/fileapi/file_system_util.h | 3 +++ webkit/common/fileapi/file_system_util_unittest.cc | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/webkit/browser/fileapi/sandbox_mount_point_provider.cc b/webkit/browser/fileapi/sandbox_mount_point_provider.cc index 2590007e..0c89438 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/browser/fileapi/sandbox_mount_point_provider.cc @@ -281,7 +281,7 @@ FilePermissionPolicy SandboxMountPointProvider::GetPermissionPolicy( return FILE_PERMISSION_ALWAYS_DENY; // Any write access is disallowed on the root path. - if ((url.path().empty() || VirtualPath::DirName(url.path()) == url.path()) + if (VirtualPath::IsRootPath(url.path()) && (permissions & ~kReadFilePermissions)) return FILE_PERMISSION_ALWAYS_DENY; diff --git a/webkit/common/fileapi/file_system_util.cc b/webkit/common/fileapi/file_system_util.cc index 2ce3c99..9ed0cd9 100644 --- a/webkit/common/fileapi/file_system_util.cc +++ b/webkit/common/fileapi/file_system_util.cc @@ -137,6 +137,14 @@ bool VirtualPath::IsAbsolute(const base::FilePath::StringType& path) { return path.find(kRoot) == 0; } +bool VirtualPath::IsRootPath(const base::FilePath& path) { + std::vector components; + VirtualPath::GetComponents(path, &components); + return (path.empty() || components.empty() || + (components.size() == 1 && + components[0] == VirtualPath::kRoot)); +} + GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { // origin_url is based on a security origin, so http://foo.com or file:/// // instead of the corresponding filesystem URL. diff --git a/webkit/common/fileapi/file_system_util.h b/webkit/common/fileapi/file_system_util.h index 1059f14..bf0cc85 100644 --- a/webkit/common/fileapi/file_system_util.h +++ b/webkit/common/fileapi/file_system_util.h @@ -59,6 +59,9 @@ class WEBKIT_STORAGE_COMMON_EXPORT VirtualPath { // Returns true if the given path begins with kRoot. static bool IsAbsolute(const base::FilePath::StringType& path); + + // Returns true if the given path points to the root. + static bool IsRootPath(const base::FilePath& path); }; // Returns the root URI of the filesystem that can be specified by a pair of diff --git a/webkit/common/fileapi/file_system_util_unittest.cc b/webkit/common/fileapi/file_system_util_unittest.cc index f1a03dd..6bb6d4f 100644 --- a/webkit/common/fileapi/file_system_util_unittest.cc +++ b/webkit/common/fileapi/file_system_util_unittest.cc @@ -121,6 +121,20 @@ TEST_F(FileSystemUtilTest, IsAbsolutePath) { EXPECT_FALSE(VirtualPath::IsAbsolute(FILE_PATH_LITERAL("foo/bar"))); } +TEST_F(FileSystemUtilTest, IsRootPath) { + EXPECT_TRUE(VirtualPath::IsRootPath(base::FilePath(FILE_PATH_LITERAL("")))); + EXPECT_TRUE(VirtualPath::IsRootPath(base::FilePath())); + EXPECT_TRUE(VirtualPath::IsRootPath(base::FilePath(FILE_PATH_LITERAL("/")))); + EXPECT_TRUE(VirtualPath::IsRootPath(base::FilePath(FILE_PATH_LITERAL("//")))); + EXPECT_FALSE(VirtualPath::IsRootPath( + base::FilePath(FILE_PATH_LITERAL("c:/")))); +#if defined(FILE_PATH_USES_WIN_SEPARATORS) + EXPECT_TRUE(VirtualPath::IsRootPath(base::FilePath(FILE_PATH_LITERAL("\\")))); + EXPECT_FALSE(VirtualPath::IsRootPath( + base::FilePath(FILE_PATH_LITERAL("c:\\")))); +#endif +} + TEST_F(FileSystemUtilTest, VirtualPathGetComponents) { struct test_data { const base::FilePath::StringType path; -- cgit v1.1