Index: webkit/fileapi/file_system_util.cc |
diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc |
index e0c16a5298e958606d8466d2f3023cf193cb50f4..26c6a0fc7fd56ee6f4b399e0344acd5a4c32e034 100644 |
--- a/webkit/fileapi/file_system_util.cc |
+++ b/webkit/fileapi/file_system_util.cc |
@@ -92,6 +92,51 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, |
return true; |
} |
+//TODO(ericu): Consider removing support for '\', even on Windows, if possible. |
+// There's a lot of test code that will need reworking, and we may have trouble |
+// with FilePath elsewhere [e.g. DirName and other methods may also need |
+// replacement]. |
+FilePath VirtualPath::BaseName(const FilePath& virtual_path) { |
+ FilePath::StringType path = virtual_path.value(); |
+ |
+ // Keep everything after the final separator, but if the pathname is only |
+ // one character and it's a separator, leave it alone. |
+ while (path.size() > 1 && FilePath::IsSeparator(path[path.size() - 1])) |
+ path.resize(path.size() - 1); |
+ FilePath::StringType::size_type last_separator = |
+ path.find_last_of(FilePath::kSeparators); |
+ if (last_separator != FilePath::StringType::npos && |
+ last_separator < path.size() - 1) |
+ path.erase(0, last_separator + 1); |
+ |
+ return FilePath(path); |
+} |
+ |
+void VirtualPath::GetComponents( |
+ const FilePath& path, std::vector<FilePath::StringType>* components) { |
+ DCHECK(components); |
+ if (!components) |
+ return; |
+ components->clear(); |
+ if (path.value().empty()) |
+ return; |
+ |
+ std::vector<FilePath::StringType> ret_val; |
+ FilePath current = path; |
+ FilePath base; |
+ |
+ // Due to the way things are implemented, FilePath::DirName works here, |
+ // whereas FilePath::BaseName doesn't. |
+ while (current != current.DirName()) { |
+ base = BaseName(current); |
+ ret_val.push_back(base.value()); |
+ current = current.DirName(); |
+ } |
+ |
+ *components = |
+ std::vector<FilePath::StringType>(ret_val.rbegin(), ret_val.rend()); |
+} |
+ |
GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { |
std::string path("filesystem:"); |
path += origin_url.spec(); |