diff options
author | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 16:56:58 +0000 |
---|---|---|
committer | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 16:56:58 +0000 |
commit | 932df839a6562730cd741f24fc469606d9d9ffb7 (patch) | |
tree | 2c244f93639d2c0f50e6e917cc01ea33fd637a43 /webkit | |
parent | 3bfc16cf47deae24f43b3967edf769112a674482 (diff) | |
download | chromium_src-932df839a6562730cd741f24fc469606d9d9ffb7.zip chromium_src-932df839a6562730cd741f24fc469606d9d9ffb7.tar.gz chromium_src-932df839a6562730cd741f24fc469606d9d9ffb7.tar.bz2 |
Add full support for filesystem URLs.
BUG=114484
TEST=existing filesystem tests don't break
Review URL: https://chromiumcodereview.appspot.com/7811006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/appcache/appcache_interfaces.cc | 12 | ||||
-rw-r--r-- | webkit/fileapi/file_system_util.cc | 84 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_mount_point_provider.cc | 3 |
3 files changed, 45 insertions, 54 deletions
diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc index aac9766..70de5ff 100644 --- a/webkit/appcache/appcache_interfaces.cc +++ b/webkit/appcache/appcache_interfaces.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -63,11 +63,11 @@ bool IsSchemeSupported(const GURL& url) { bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme); #ifndef NDEBUG // TODO(michaeln): It would be really nice if this could optionally work for - // file urls too to help web developers experiment and test their apps, - // perhaps enabled via a cmd line flag or some other developer tool setting. - // Unfortunately file scheme net::URLRequest don't produce the same signalling - // (200 response codes, headers) as http URLRequests, so this doesn't work - // just yet. + // file and filesystem urls too to help web developers experiment and test + // their apps, perhaps enabled via a cmd line flag or some other developer + // tool setting. Unfortunately file scheme net::URLRequests don't produce the + // same signalling (200 response codes, headers) as http URLRequests, so this + // doesn't work just yet. // supported |= url.SchemeIsFile(); #endif return supported; diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index c5a3047..382c7b6 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -19,9 +19,9 @@ namespace fileapi { -const char kPersistentDir[] = "/persistent/"; -const char kTemporaryDir[] = "/temporary/"; -const char kExternalDir[] = "/external/"; +const char kPersistentDir[] = "/persistent"; +const char kTemporaryDir[] = "/temporary"; +const char kExternalDir[] = "/external"; const char kPersistentName[] = "Persistent"; const char kTemporaryName[] = "Temporary"; @@ -32,62 +32,45 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, GURL origin; FileSystemType file_system_type; - if (url.scheme() != "filesystem") + if (!url.is_valid() || !url.SchemeIsFileSystem()) return false; + DCHECK(url.inner_url()); - std::string temp = url.path(); - // 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. - size_t 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. - 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.is_empty()) - return false; - - std::string path = net::UnescapeURLComponent(bare_url.path(), - net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | - net::UnescapeRule::CONTROL_CHARS); - if (path.compare(0, strlen(kPersistentDir), kPersistentDir) == 0) { + std::string inner_path = url.inner_url()->path(); + if (inner_path.compare( + 0, arraysize(kPersistentDir) - 1, kPersistentDir) == 0) { file_system_type = kFileSystemTypePersistent; - path = path.substr(strlen(kPersistentDir)); - } else if (path.compare(0, strlen(kTemporaryDir), kTemporaryDir) == 0) { + } else if (inner_path.compare( + 0, arraysize(kTemporaryDir) - 1, kTemporaryDir) == 0) { file_system_type = kFileSystemTypeTemporary; - path = path.substr(strlen(kTemporaryDir)); - } else if (path.compare(0, strlen(kExternalDir), kExternalDir) == 0) { + } else if (inner_path.compare( + 0, arraysize(kExternalDir) - 1, kExternalDir) == 0) { file_system_type = kFileSystemTypeExternal; - path = path.substr(strlen(kExternalDir)); } else { return false; } + std::string path = net::UnescapeURLComponent(url.path(), + net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | + net::UnescapeRule::CONTROL_CHARS); + // Ensure the path is relative. while (!path.empty() && path[0] == '/') path.erase(0, 1); + FilePath converted_path = FilePath::FromUTF8Unsafe(path); + + // All parent references should have been resolved in the renderer. + if (converted_path.ReferencesParent()) + return false; + if (origin_url) - *origin_url = origin; + *origin_url = url.GetOrigin(); if (type) *type = file_system_type; if (file_path) - *file_path = FilePath::FromUTF8Unsafe(path). - NormalizePathSeparators().StripTrailingSeparators(); + *file_path = converted_path.NormalizePathSeparators(). + StripTrailingSeparators(); return true; } @@ -138,23 +121,28 @@ void VirtualPath::GetComponents( } GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { - std::string path("filesystem:"); - path += origin_url.spec(); + // origin_url is based on a security origin, so http://foo.com or file:/// + // instead of the corresponding filesystem URL. + DCHECK(!origin_url.SchemeIsFileSystem()); + + std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); switch (type) { case kFileSystemTypeTemporary: - path += (kTemporaryDir + 1); // We don't want the leading slash. + url += (kTemporaryDir + 1); // We don't want the leading slash. break; case kFileSystemTypePersistent: - path += (kPersistentDir + 1); // We don't want the leading slash. + url += (kPersistentDir + 1); // We don't want the leading slash. break; case kFileSystemTypeExternal: - path += (kExternalDir + 1); // We don't want the leading slash. + url += (kExternalDir + 1); // We don't want the leading slash. break; default: NOTREACHED(); return GURL(); } - return GURL(path); + url += "/"; + + return GURL(url); } std::string GetFileSystemName(const GURL& origin_url, FileSystemType type) { diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc index b5a9a8b..34aec23 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/fileapi/sandbox_mount_point_provider.cc @@ -651,6 +651,9 @@ bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { // only if --allow-file-access-from-files flag is given. if (url.SchemeIs("http") || url.SchemeIs("https")) return true; + if (url.SchemeIsFileSystem()) + return url.inner_url() && IsAllowedScheme(*url.inner_url()); + for (size_t i = 0; i < file_system_options_.additional_allowed_schemes().size(); ++i) { |