Index: webkit/fileapi/sandbox_mount_point_provider.cc |
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc |
index 661d760ffab35a2fcd12623a95da155b664d3c0d..0d31db392627f920035740c9f4f260b8663fb6a2 100644 |
--- a/webkit/fileapi/sandbox_mount_point_provider.cc |
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc |
@@ -18,7 +18,7 @@ |
#include "googleurl/src/gurl.h" |
#include "net/base/net_util.h" |
#include "webkit/fileapi/file_system_operation_context.h" |
-#include "webkit/fileapi/file_system_path_manager.h" |
+#include "webkit/fileapi/file_system_options.h" |
#include "webkit/fileapi/file_system_types.h" |
#include "webkit/fileapi/file_system_usage_cache.h" |
#include "webkit/fileapi/file_system_util.h" |
@@ -31,10 +31,13 @@ using quota::QuotaManagerProxy; |
namespace { |
-static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = |
+const char kChromeScheme[] = "chrome"; |
+const char kExtensionScheme[] = "chrome-extension"; |
+ |
+const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = |
FILE_PATH_LITERAL("chrome-"); |
-static const int kOldFileSystemUniqueLength = 16; |
-static const unsigned kOldFileSystemUniqueDirectoryNameLength = |
+const int kOldFileSystemUniqueLength = 16; |
+const unsigned kOldFileSystemUniqueDirectoryNameLength = |
kOldFileSystemUniqueLength + arraysize(kOldFileSystemUniqueNamePrefix) - 1; |
tzik
2011/12/21 02:52:33
size_t?
kinuko
2011/12/21 13:00:50
Done.
|
const char kOpenFileSystem[] = "FileSystem.OpenFileSystem"; |
@@ -48,24 +51,15 @@ enum FileSystemError { |
// Restricted names. |
// http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
-static const char* const kRestrictedNames[] = { |
+const char* const kRestrictedNames[] = { |
".", "..", |
}; |
// Restricted chars. |
-static const FilePath::CharType kRestrictedChars[] = { |
+const FilePath::CharType kRestrictedChars[] = { |
'/', '\\', |
tzik
2011/12/21 02:52:33
FILE_PATH_LITERAL?
kinuko
2011/12/21 13:00:50
Done.
|
}; |
-inline std::string FilePathStringToASCII( |
- const FilePath::StringType& path_string) { |
-#if defined(OS_WIN) |
- return WideToASCII(path_string); |
-#elif defined(OS_POSIX) |
- return path_string; |
-#endif |
-} |
- |
FilePath::StringType OldCreateUniqueDirectoryName(const GURL& origin_url) { |
// This can be anything but need to be unpredictable. |
static const FilePath::CharType letters[] = FILE_PATH_LITERAL( |
@@ -136,14 +130,13 @@ class OldSandboxOriginEnumerator |
if (current_.empty()) |
return GURL(); |
return fileapi::GetOriginURLFromIdentifier( |
- FilePathStringToASCII(current_.BaseName().value())); |
+ current_.BaseName().MaybeAsASCII()); |
} |
virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
if (current_.empty()) |
return false; |
- std::string directory = |
- fileapi::FileSystemPathManager::GetFileSystemTypeString(type); |
+ std::string directory = GetFileSystemTypeString(type); |
DCHECK(!directory.empty()); |
return file_util::DirectoryExists(current_.AppendASCII(directory)); |
} |
@@ -165,8 +158,7 @@ FilePath OldGetBaseDirectoryForOrigin( |
FilePath OldGetBaseDirectoryForOriginAndType( |
const FilePath& old_base_path, |
const GURL& origin_url, fileapi::FileSystemType type) { |
- std::string type_string = |
- fileapi::FileSystemPathManager::GetFileSystemTypeString(type); |
+ std::string type_string = GetFileSystemTypeString(type); |
if (type_string.empty()) { |
NOTREACHED(); |
return FilePath(); |
@@ -279,34 +271,6 @@ const FilePath::CharType |
SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
FILE_PATH_LITERAL("FS.old"); |
-SandboxMountPointProvider::SandboxMountPointProvider( |
- FileSystemPathManager* path_manager, |
- scoped_refptr<base::MessageLoopProxy> file_message_loop, |
- const FilePath& profile_path) |
- : FileSystemQuotaUtil(file_message_loop), |
- path_manager_(path_manager), |
- file_message_loop_(file_message_loop), |
- profile_path_(profile_path), |
- sandbox_file_util_( |
- new ObfuscatedFileUtil( |
- profile_path.Append(kNewFileSystemDirectory), |
- QuotaFileUtil::CreateDefault())) { |
-} |
- |
-SandboxMountPointProvider::~SandboxMountPointProvider() { |
- if (!file_message_loop_->BelongsToCurrentThread()) |
- file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); |
-} |
- |
-bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
- FileSystemType type, |
- const FilePath& unused) { |
- if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
- return false; |
- // We essentially depend on quota to do our access controls. |
- return path_manager_->IsAllowedScheme(origin_url); |
-} |
- |
class SandboxMountPointProvider::GetFileSystemRootPathTask |
: public base::RefCountedThreadSafe< |
SandboxMountPointProvider::GetFileSystemRootPathTask> { |
@@ -317,7 +281,7 @@ class SandboxMountPointProvider::GetFileSystemRootPathTask |
FileSystemType type, |
ObfuscatedFileUtil* file_util, |
const FilePath& old_base_path, |
- const FileSystemPathManager::GetRootPathCallback& callback) |
+ const FileSystemMountPointProvider::GetRootPathCallback& callback) |
: file_message_loop_(file_message_loop), |
origin_message_loop_proxy_( |
base::MessageLoopProxy::current()), |
@@ -366,8 +330,7 @@ class SandboxMountPointProvider::GetFileSystemRootPathTask |
void DispatchCallback(const FilePath& root_path) { |
std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); |
- std::string type_string = |
- FileSystemPathManager::GetFileSystemTypeString(type_); |
+ std::string type_string = GetFileSystemTypeString(type_); |
DCHECK(!type_string.empty()); |
std::string name = origin_identifier + ":" + type_string; |
@@ -384,64 +347,45 @@ class SandboxMountPointProvider::GetFileSystemRootPathTask |
FileSystemType type_; |
scoped_refptr<ObfuscatedFileUtil> file_util_; |
FilePath old_base_path_; |
- FileSystemPathManager::GetRootPathCallback callback_; |
+ FileSystemMountPointProvider::GetRootPathCallback callback_; |
}; |
-FilePath SandboxMountPointProvider::old_base_path() const { |
- return profile_path_.Append(kOldFileSystemDirectory); |
-} |
- |
-FilePath SandboxMountPointProvider::new_base_path() const { |
- return profile_path_.Append(kNewFileSystemDirectory); |
+SandboxMountPointProvider::SandboxMountPointProvider( |
+ scoped_refptr<base::MessageLoopProxy> file_message_loop, |
+ const FilePath& profile_path, |
+ FileSystemOptions* file_system_options) |
+ : FileSystemQuotaUtil(file_message_loop), |
+ file_message_loop_(file_message_loop), |
+ profile_path_(profile_path), |
+ file_system_options_(file_system_options), |
+ sandbox_file_util_( |
+ new ObfuscatedFileUtil( |
+ profile_path.Append(kNewFileSystemDirectory), |
+ QuotaFileUtil::CreateDefault())) { |
+ DCHECK(file_system_options); |
} |
-FilePath SandboxMountPointProvider::renamed_old_base_path() const { |
- return profile_path_.Append(kRenamedOldFileSystemDirectory); |
+SandboxMountPointProvider::~SandboxMountPointProvider() { |
+ if (!file_message_loop_->BelongsToCurrentThread()) |
+ file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); |
} |
-bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) |
- const { |
- if (filename.value().empty()) |
+bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
+ FileSystemType type, |
+ const FilePath& unused) { |
+ if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
return false; |
- |
- std::string filename_lower = StringToLowerASCII( |
- FilePathStringToASCII(filename.value())); |
- |
- for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { |
- // Exact match. |
- if (filename_lower == kRestrictedNames[i]) |
- return true; |
- } |
- |
- for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { |
- if (filename.value().find(kRestrictedChars[i]) != |
- FilePath::StringType::npos) |
- return true; |
- } |
- |
- return false; |
-} |
- |
-std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { |
- NOTREACHED(); |
- // TODO(ericu): Implement this method and check for access permissions as |
- // fileBrowserPrivate extension API does. We currently have another mechanism, |
- // but we should switch over. This may also need to call MigrateIfNeeded(). |
- return std::vector<FilePath>(); |
-} |
- |
-SandboxMountPointProvider::OriginEnumerator* |
-SandboxMountPointProvider::CreateOriginEnumerator() const { |
- MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
- return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); |
+ // We essentially depend on quota to do our access controls, so here |
+ // we only check if the requested scheme is allowed or not. |
+ return IsAllowedScheme(origin_url); |
} |
void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
const GURL& origin_url, fileapi::FileSystemType type, bool create, |
- const FileSystemPathManager::GetRootPathCallback& callback) { |
+ const FileSystemMountPointProvider::GetRootPathCallback& callback) { |
FilePath origin_base_path; |
- if (path_manager_->is_incognito()) { |
+ if (file_system_options_->is_incognito()) { |
// TODO(kinuko): return an isolated temporary directory. |
callback.Run(false, FilePath(), std::string()); |
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
@@ -450,7 +394,7 @@ void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
return; |
} |
- if (!path_manager_->IsAllowedScheme(origin_url)) { |
+ if (!IsAllowedScheme(origin_url)) { |
callback.Run(false, FilePath(), std::string()); |
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
kInvalidScheme, |
@@ -469,11 +413,11 @@ FilePath |
SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
const GURL& origin_url, FileSystemType type, const FilePath& unused, |
bool create) { |
- if (path_manager_->is_incognito()) |
+ if (file_system_options_->is_incognito()) |
// TODO(kinuko): return an isolated temporary directory. |
return FilePath(); |
- if (!path_manager_->IsAllowedScheme(origin_url)) |
+ if (!IsAllowedScheme(origin_url)) |
return FilePath(); |
MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
@@ -482,6 +426,58 @@ SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
origin_url, type, create); |
} |
+bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) |
+ const { |
+ if (filename.value().empty()) |
+ return false; |
+ |
+ std::string filename_lower = StringToLowerASCII(filename.MaybeAsASCII()); |
tzik
2011/12/21 02:52:33
MaybeAsASCII will return empty string if filename
kinuko
2011/12/21 13:00:50
Good catch. Changed the code to use FilePath::Cha
|
+ |
+ for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { |
+ // Exact match. |
+ if (filename_lower == kRestrictedNames[i]) |
+ return true; |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { |
+ if (filename.value().find(kRestrictedChars[i]) != |
+ FilePath::StringType::npos) |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
+std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { |
+ NOTREACHED(); |
+ // TODO(ericu): Implement this method and check for access permissions as |
+ // fileBrowserPrivate extension API does. We currently have another mechanism, |
+ // but we should switch over. This may also need to call MigrateIfNeeded(). |
+ return std::vector<FilePath>(); |
+} |
+ |
+FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { |
+ return sandbox_file_util_.get(); |
+} |
+ |
+FilePath SandboxMountPointProvider::old_base_path() const { |
+ return profile_path_.Append(kOldFileSystemDirectory); |
+} |
+ |
+FilePath SandboxMountPointProvider::new_base_path() const { |
+ return profile_path_.Append(kNewFileSystemDirectory); |
+} |
+ |
+FilePath SandboxMountPointProvider::renamed_old_base_path() const { |
+ return profile_path_.Append(kRenamedOldFileSystemDirectory); |
+} |
+ |
+SandboxMountPointProvider::OriginEnumerator* |
+SandboxMountPointProvider::CreateOriginEnumerator() const { |
+ MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
+ return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); |
+} |
+ |
FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( |
const GURL& origin_url, fileapi::FileSystemType type, bool create) const { |
@@ -640,10 +636,6 @@ void SandboxMountPointProvider::InvalidateUsageCache( |
FileSystemUsageCache::IncrementDirty(usage_file_path); |
} |
-FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { |
- return sandbox_file_util_.get(); |
-} |
- |
FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( |
const GURL& origin_url, fileapi::FileSystemType type) const { |
FilePath base_path = |
@@ -678,4 +670,13 @@ FilePath SandboxMountPointProvider::OldCreateFileSystemRootPath( |
return root; |
} |
+bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { |
+ // Basically we only accept http or https. We allow file:// URLs |
+ // only if --allow-file-access-from-files flag is given. |
+ return url.SchemeIs("http") || url.SchemeIs("https") || |
+ url.SchemeIs(kExtensionScheme) || url.SchemeIs(kChromeScheme) || |
+ (url.SchemeIsFile() && |
+ file_system_options_->allow_file_access_from_files()); |
+} |
+ |
} // namespace fileapi |