diff options
author | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 00:49:40 +0000 |
---|---|---|
committer | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 00:49:40 +0000 |
commit | 073a04f0599beb27670d8a6738fcbbc22fa97bcf (patch) | |
tree | d7393b3cd3463dbfaf4bbdc02fdd0a4de0c83995 /webkit/fileapi/file_system_util.cc | |
parent | 6bcd5f36cd94649887eff0c87df4f4496001984a (diff) | |
download | chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.zip chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.tar.gz chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.tar.bz2 |
Stop returning the true root path of each filesystem from openFileSystem.
Instead, return the FileSystem URI of the root. This will make it easier
to swap in different filesystem implementations.
BUG=71635
TEST=Just a couple in FileSystemUtilTests, but a bunch of existing ones [this doesn't add much new functionality].
Review URL: http://codereview.chromium.org/6603034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_util.cc')
-rw-r--r-- | webkit/fileapi/file_system_util.cc | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 07aa5a6..ae36fa850 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -7,6 +7,7 @@ #include "build/build_config.h" #include "base/file_path.h" +#include "base/logging.h" #include "base/sys_string_conversions.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" @@ -19,27 +20,61 @@ static const char kTemporaryDir[] = "/temporary/"; bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, FilePath* file_path) { - *origin_url = GURL(); - *type = kFileSystemTypeUnknown; - *file_path = FilePath(); + GURL origin; + FileSystemType file_system_type; if (url.scheme() != "filesystem") return false; - GURL bare_url(url.path()); - *origin_url = bare_url.GetOrigin(); + std::string temp = url.path(); + // TODO(ericu) remove this code when that ceases to be true, which should be + // soon. + // On Windows, this will have backslashes for now. + // url will look something like: + // filesystem:http://example.com/temporary/\dir\file.txt + // temp will look something like: + // http://example.com/temporary/\dir\file.txt + // On posix, url will look something like: + // filesystem:http://example.com/temporary/dir/file.txt + // temp will look something like: + // http://example.com/temporary/dir/file.txt + size_t pos = temp.find('\\'); + for (; pos != std::string::npos; pos = temp.find('\\', pos + 1)) { + temp[pos] = '/'; + } + // TODO(ericu): This should probably be done elsewhere after the stackable + // layers are properly in. We're supposed to reject any paths that contain + // '..' segments, but the GURL constructor is helpfully resolving them for us. + // Make sure there aren't any before we call it. + pos = temp.find(".."); + for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { + if ((pos == 0 || temp[pos - 1] == '/') && + (pos == temp.length() - 2 || temp[pos + 2] == '/')) + return false; + } + + // bare_url will look something like: + // http://example.com/temporary//dir/file.txt [on Windows; the double slash + // before dir will be single on posix]. + GURL bare_url(temp); + + // The input URL was malformed, bail out early. + if (bare_url.path().empty()) + return false; + + origin = bare_url.GetOrigin(); // The input URL was malformed, bail out early. - if (origin_url->is_empty() || bare_url.path().empty()) + if (origin.is_empty()) return false; std::string path = UnescapeURLComponent(bare_url.path(), UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); if (path.compare(0, strlen(kPersistentDir), kPersistentDir) == 0) { - *type = kFileSystemTypePersistent; + file_system_type = kFileSystemTypePersistent; path = path.substr(strlen(kPersistentDir)); } else if (path.compare(0, strlen(kTemporaryDir), kTemporaryDir) == 0) { - *type = kFileSystemTypeTemporary; + file_system_type = kFileSystemTypeTemporary; path = path.substr(strlen(kTemporaryDir)); } else { return false; @@ -50,13 +85,36 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, path.erase(0, 1); #if defined(OS_WIN) - const FilePath::StringType& sys_path = base::SysUTF8ToWide(path); + const FilePath::StringType sys_path = base::SysUTF8ToWide(path); #elif defined(OS_POSIX) - const FilePath::StringType& sys_path = path; + const FilePath::StringType sys_path = path; #endif + if (origin_url) + *origin_url = origin; + if (type) + *type = file_system_type; + if (file_path) + *file_path = FilePath(sys_path); - *file_path = FilePath(sys_path); return true; } +GURL GetFileSystemRootURI( + const GURL& origin_url, fileapi::FileSystemType type) { + std::string path("filesystem:"); + path += origin_url.spec(); + switch (type) { + case kFileSystemTypeTemporary: + path += (kTemporaryDir + 1); // We don't want the leading slash. + break; + case kFileSystemTypePersistent: + path += (kPersistentDir + 1); // We don't want the leading slash. + break; + default: + NOTREACHED(); + return GURL(); + } + return GURL(path); +} + } // namespace fileapi |