summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-27 12:16:06 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-27 12:16:06 +0000
commitaea270f67aaf7b259b3ab48bc5b7c086b053f155 (patch)
tree6574655f9b121ff3651c25074c07cdcdfbf91836
parent55d406c74ac70e004ee899bdbaa517504f506fd5 (diff)
downloadchromium_src-aea270f67aaf7b259b3ab48bc5b7c086b053f155.zip
chromium_src-aea270f67aaf7b259b3ab48bc5b7c086b053f155.tar.gz
chromium_src-aea270f67aaf7b259b3ab48bc5b7c086b053f155.tar.bz2
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
-rw-r--r--webkit/browser/fileapi/sandbox_mount_point_provider.cc2
-rw-r--r--webkit/common/fileapi/file_system_util.cc8
-rw-r--r--webkit/common/fileapi/file_system_util.h3
-rw-r--r--webkit/common/fileapi/file_system_util_unittest.cc14
4 files changed, 26 insertions, 1 deletions
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<base::FilePath::StringType> 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;