summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authortkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 02:21:54 +0000
committertkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 02:21:54 +0000
commit6ac99518a9481ab6c13f0d7408f3fb8aab1242a6 (patch)
treee53574e0c71f3ea5d4e1c0632057aaff418014fe /webkit
parentbc78d4db680894f3bf2eaa0d6ee713e9aec5eebb (diff)
downloadchromium_src-6ac99518a9481ab6c13f0d7408f3fb8aab1242a6.zip
chromium_src-6ac99518a9481ab6c13f0d7408f3fb8aab1242a6.tar.gz
chromium_src-6ac99518a9481ab6c13f0d7408f3fb8aab1242a6.tar.bz2
Revert 81028 - It broke LayoutTests/ fast/filesystem/op-copy.html on Windows Release and Debug.
More filesystem cleanup: convert URL-encoded-as-FilePath to actual URL, where possible without WebKit API changes. The WebKit changes will happen in another CL. This is a resubmit of http://codereview.chromium.org/6767010/, which bounced dueto a recent checkin that required a merge. There are a few changes here thatweren't there [in file_system_operation_write_unittest.cc andfile_system_operation.cc], but they're pretty trivial build/test fixes.BUG=none TEST=noneReview URL: http://codereview.chromium.org/6813066 TBR=ericu@google.com Review URL: http://codereview.chromium.org/6813072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/file_system_callback_dispatcher.h4
-rw-r--r--webkit/fileapi/file_system_operation.cc85
-rw-r--r--webkit/fileapi/file_system_operation.h32
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc121
-rw-r--r--webkit/fileapi/file_system_operation_write_unittest.cc24
-rw-r--r--webkit/fileapi/file_system_path_manager.cc100
-rw-r--r--webkit/fileapi/file_system_path_manager.h11
-rw-r--r--webkit/fileapi/file_system_path_manager_unittest.cc88
-rw-r--r--webkit/fileapi/webfilewriter_base.cc4
-rw-r--r--webkit/fileapi/webfilewriter_base.h12
-rw-r--r--webkit/fileapi/webfilewriter_base_unittest.cc62
-rw-r--r--webkit/plugins/ppapi/file_callbacks.cc5
-rw-r--r--webkit/plugins/ppapi/file_callbacks.h2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc14
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h14
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h14
-rw-r--r--webkit/plugins/ppapi/ppb_directory_reader_impl.cc2
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.cc43
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.h4
-rw-r--r--webkit/plugins/ppapi/ppb_file_system_impl.h8
-rw-r--r--webkit/tools/test_shell/simple_file_system.cc50
-rw-r--r--webkit/tools/test_shell/simple_file_writer.cc12
-rw-r--r--webkit/tools/test_shell/simple_file_writer.h6
23 files changed, 416 insertions, 301 deletions
diff --git a/webkit/fileapi/file_system_callback_dispatcher.h b/webkit/fileapi/file_system_callback_dispatcher.h
index 3700891a..2bffe54 100644
--- a/webkit/fileapi/file_system_callback_dispatcher.h
+++ b/webkit/fileapi/file_system_callback_dispatcher.h
@@ -9,8 +9,6 @@
#include "base/file_util_proxy.h"
-class GURL;
-
namespace fileapi {
// This class mirrors the callbacks in
@@ -43,7 +41,7 @@ class FileSystemCallbackDispatcher {
// Callback for opening a file system. Called with a name and root path for
// the FileSystem when the request is accepted. Used by WebFileSystem API.
virtual void DidOpenFileSystem(const std::string& name,
- const GURL& root) = 0;
+ const FilePath& root_path) = 0;
// Called with an error code when a requested operation has failed.
virtual void DidFail(base::PlatformFileError error_code) = 0;
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index e15a7f2..4ddfd0c 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -5,8 +5,6 @@
#include "webkit/fileapi/file_system_operation.h"
#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "net/base/escape.h"
#include "net/url_request/url_request_context.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
@@ -65,7 +63,7 @@ void FileSystemOperation::OpenFileSystem(
callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath));
}
-void FileSystemOperation::CreateFile(const GURL& path,
+void FileSystemOperation::CreateFile(const FilePath& path,
bool exclusive) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
@@ -88,7 +86,7 @@ void FileSystemOperation::CreateFile(const GURL& path,
: &FileSystemOperation::DidEnsureFileExistsNonExclusive));
}
-void FileSystemOperation::CreateDirectory(const GURL& path,
+void FileSystemOperation::CreateDirectory(const FilePath& path,
bool exclusive,
bool recursive) {
#ifndef NDEBUG
@@ -112,8 +110,8 @@ void FileSystemOperation::CreateDirectory(const GURL& path,
&FileSystemOperation::DidFinishFileOperation));
}
-void FileSystemOperation::Copy(const GURL& src_path,
- const GURL& dest_path) {
+void FileSystemOperation::Copy(const FilePath& src_path,
+ const FilePath& dest_path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationCopy;
@@ -151,8 +149,8 @@ void FileSystemOperation::Copy(const GURL& src_path,
&FileSystemOperation::DidFinishFileOperation));
}
-void FileSystemOperation::Move(const GURL& src_path,
- const GURL& dest_path) {
+void FileSystemOperation::Move(const FilePath& src_path,
+ const FilePath& dest_path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationMove;
@@ -188,7 +186,7 @@ void FileSystemOperation::Move(const GURL& src_path,
&FileSystemOperation::DidFinishFileOperation));
}
-void FileSystemOperation::DirectoryExists(const GURL& path) {
+void FileSystemOperation::DirectoryExists(const FilePath& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationDirectoryExists;
@@ -209,7 +207,7 @@ void FileSystemOperation::DirectoryExists(const GURL& path) {
&FileSystemOperation::DidDirectoryExists));
}
-void FileSystemOperation::FileExists(const GURL& path) {
+void FileSystemOperation::FileExists(const FilePath& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationFileExists;
@@ -230,7 +228,7 @@ void FileSystemOperation::FileExists(const GURL& path) {
&FileSystemOperation::DidFileExists));
}
-void FileSystemOperation::GetMetadata(const GURL& path) {
+void FileSystemOperation::GetMetadata(const FilePath& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationGetMetadata;
@@ -251,7 +249,7 @@ void FileSystemOperation::GetMetadata(const GURL& path) {
&FileSystemOperation::DidGetMetadata));
}
-void FileSystemOperation::ReadDirectory(const GURL& path) {
+void FileSystemOperation::ReadDirectory(const FilePath& path) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationReadDirectory;
@@ -272,7 +270,7 @@ void FileSystemOperation::ReadDirectory(const GURL& path) {
&FileSystemOperation::DidReadDirectory));
}
-void FileSystemOperation::Remove(const GURL& path, bool recursive) {
+void FileSystemOperation::Remove(const FilePath& path, bool recursive) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationRemove;
@@ -296,7 +294,7 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) {
void FileSystemOperation::Write(
scoped_refptr<net::URLRequestContext> url_request_context,
- const GURL& path,
+ const FilePath& path,
const GURL& blob_url,
int64 offset) {
#ifndef NDEBUG
@@ -328,7 +326,7 @@ void FileSystemOperation::Write(
&FileSystemOperation::OnFileOpenedForWrite));
}
-void FileSystemOperation::Truncate(const GURL& path, int64 length) {
+void FileSystemOperation::Truncate(const FilePath& path, int64 length) {
#ifndef NDEBUG
DCHECK(kOperationNone == pending_operation_);
pending_operation_ = kOperationTruncate;
@@ -349,7 +347,7 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) {
&FileSystemOperation::DidFinishFileOperation));
}
-void FileSystemOperation::TouchFile(const GURL& path,
+void FileSystemOperation::TouchFile(const FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
#ifndef NDEBUG
@@ -410,13 +408,14 @@ void FileSystemOperation::DidGetRootPath(
bool success,
const FilePath& path, const std::string& name) {
DCHECK(success || path.empty());
- GURL result;
+ FilePath result;
// We ignore the path, and return a URL instead. The point was just to verify
// that we could create/find the path.
if (success) {
- result = GetFileSystemRootURI(
+ GURL root_url = GetFileSystemRootURI(
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type());
+ result = FilePath().AppendASCII(root_url.spec());
}
dispatcher_->DidOpenFileSystem(name, result);
delete this;
@@ -538,37 +537,21 @@ void FileSystemOperation::OnFileOpenedForWrite(
}
bool FileSystemOperation::VerifyFileSystemPathForRead(
- const GURL& path, GURL* origin_url, FileSystemType* type,
+ const FilePath& path, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path) {
// If we have no context, we just allow any operations, for testing.
// TODO(ericu): Revisit this hack for security.
if (!file_system_context()) {
-#ifdef OS_WIN
- // On Windows, the path will look like /C:/foo/bar; we need to remove the
- // leading slash to make it valid. But if it's empty, we shouldn't do
- // anything.
- std::string temp = UnescapeURLComponent(path.path(),
- UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
- if (temp.size())
- temp = temp.substr(1);
- *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators();
-#else
- *virtual_path = FilePath(path.path());
-#endif
+ *virtual_path = path;
*type = file_system_operation_context_.src_type();
- *origin_url = file_system_operation_context_.src_origin_url();
return true;
}
// We may want do more checks, but for now it just checks if the given
- // URL is valid.
- if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return false;
- }
- if (!file_system_context()->path_manager()->IsAllowedFileSystemType(
- *origin_url, *type)) {
+ // |path| is under the valid FileSystem root path for this host context.
+ if (!file_system_context()->path_manager()->CrackFileSystemPath(
+ path, origin_url, type, virtual_path)) {
dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
return false;
}
@@ -577,35 +560,19 @@ bool FileSystemOperation::VerifyFileSystemPathForRead(
}
bool FileSystemOperation::VerifyFileSystemPathForWrite(
- const GURL& path, bool create, GURL* origin_url, FileSystemType* type,
+ const FilePath& path, bool create, GURL* origin_url, FileSystemType* type,
FilePath* virtual_path) {
// If we have no context, we just allow any operations, for testing.
// TODO(ericu): Revisit this hack for security.
if (!file_system_context()) {
-#ifdef OS_WIN
- // On Windows, the path will look like /C:/foo/bar; we need to remove the
- // leading slash to make it valid. But if it's empty, we shouldn't do
- // anything.
- std::string temp = UnescapeURLComponent(path.path(),
- UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
- if (temp.size())
- temp = temp.substr(1);
- *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators();
-#else
- *virtual_path = FilePath(path.path());
-#endif
+ *virtual_path = path;
*type = file_system_operation_context_.dest_type();
- *origin_url = file_system_operation_context_.dest_origin_url();
return true;
}
- if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
- dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return false;
- }
- if (!file_system_context()->path_manager()->IsAllowedFileSystemType(
- *origin_url, *type)) {
+ if (!file_system_context()->path_manager()->CrackFileSystemPath(
+ path, origin_url, type, virtual_path)) {
dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
return false;
}
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 4017235..f6d2016 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -57,26 +57,26 @@ class FileSystemOperation {
void OpenFileSystem(const GURL& origin_url,
fileapi::FileSystemType type,
bool create);
- void CreateFile(const GURL& path,
+ void CreateFile(const FilePath& path,
bool exclusive);
- void CreateDirectory(const GURL& path,
+ void CreateDirectory(const FilePath& path,
bool exclusive,
bool recursive);
- void Copy(const GURL& src_path,
- const GURL& dest_path);
- void Move(const GURL& src_path,
- const GURL& dest_path);
- void DirectoryExists(const GURL& path);
- void FileExists(const GURL& path);
- void GetMetadata(const GURL& path);
- void ReadDirectory(const GURL& path);
- void Remove(const GURL& path, bool recursive);
+ void Copy(const FilePath& src_path,
+ const FilePath& dest_path);
+ void Move(const FilePath& src_path,
+ const FilePath& dest_path);
+ void DirectoryExists(const FilePath& path);
+ void FileExists(const FilePath& path);
+ void GetMetadata(const FilePath& path);
+ void ReadDirectory(const FilePath& path);
+ void Remove(const FilePath& path, bool recursive);
void Write(scoped_refptr<net::URLRequestContext> url_request_context,
- const GURL& path,
+ const FilePath& path,
const GURL& blob_url,
int64 offset);
- void Truncate(const GURL& path, int64 length);
- void TouchFile(const GURL& path,
+ void Truncate(const FilePath& path, int64 length);
+ void TouchFile(const FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time);
@@ -142,7 +142,7 @@ class FileSystemOperation {
// PLATFORM_FILE_ERROR_SECURITY and returns false.
// (Note: this doesn't delete this when it calls DidFail and returns false;
// it's the caller's responsibility.)
- bool VerifyFileSystemPathForRead(const GURL& path,
+ bool VerifyFileSystemPathForRead(const FilePath& path,
GURL* root_url,
FileSystemType* type,
FilePath* virtual_path);
@@ -161,7 +161,7 @@ class FileSystemOperation {
// DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
// (Note: this doesn't delete this when it calls DidFail and returns false;
// it's the caller's responsibility.)
- bool VerifyFileSystemPathForWrite(const GURL& path,
+ bool VerifyFileSystemPathForWrite(const FilePath& path,
bool create,
GURL* root_url,
FileSystemType* type,
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index 310b837..69a79fe 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -56,16 +56,6 @@ class FileSystemOperationTest : public testing::Test {
// Common temp base for nondestructive uses.
ScopedTempDir base_;
- GURL URLForRelativePath(const std::string& path) const {
- // Only the path will actually get used.
- return GURL("file://").Resolve(base_.path().value()).Resolve(path);
- }
-
- GURL URLForPath(const FilePath& path) const {
- // Only the path will actually get used.
- return GURL("file://").Resolve(path.value());
- }
-
// For post-operation status.
int status_;
base::PlatformFileInfo info_;
@@ -101,7 +91,7 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
test_->set_entries(entries);
}
- virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
NOTREACHED();
}
@@ -123,15 +113,12 @@ FileSystemOperation* FileSystemOperationTest::operation() {
kFileSystemTypeTemporary);
operation->file_system_operation_context()->set_dest_type(
kFileSystemTypeTemporary);
- GURL origin_url("fake://fake.foo/");
- operation->file_system_operation_context()->set_src_origin_url(origin_url);
- operation->file_system_operation_context()->set_dest_origin_url(origin_url);
return operation;
}
TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
- GURL src(URLForRelativePath("a"));
- GURL dest(URLForRelativePath("b"));
+ FilePath src(base_.path().Append(FILE_PATH_LITERAL("a")));
+ FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b")));
operation()->Move(src, dest);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -144,7 +131,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) {
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
FILE_PATH_LITERAL("child_dir"),
&dest_dir_path));
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
+ operation()->Move(src_dir.path(), dest_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -159,7 +146,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) {
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_file));
+ operation()->Move(src_dir.path(), dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -174,7 +161,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) {
FilePath child_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Move(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -189,7 +176,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(URLForPath(src_file), URLForPath(dest_dir.path()));
+ operation()->Move(src_file, dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
}
@@ -202,7 +189,7 @@ TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) {
FILE_PATH_LITERAL("NonexistingDir")).Append(
FILE_PATH_LITERAL("NonexistingFile"));
- operation()->Move(URLForPath(src_dir.path()), URLForPath(nonexisting_file));
+ operation()->Move(src_dir.path(), nonexisting_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -218,7 +205,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Move(URLForPath(src_file), URLForPath(dest_file));
+ operation()->Move(src_file, dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -234,7 +221,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Move(URLForPath(src_file), URLForPath(dest_file));
+ operation()->Move(src_file, dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -247,7 +234,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Move(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
@@ -266,7 +253,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) {
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath dest_dir_path(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
+ operation()->Move(src_dir.path(), dest_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
@@ -282,14 +269,16 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Move(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
}
TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
- operation()->Copy(URLForRelativePath("a"), URLForRelativePath("b"));
+ FilePath src(base_.path().Append(FILE_PATH_LITERAL("a")));
+ FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b")));
+ operation()->Copy(src, dest);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -301,7 +290,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) {
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
FILE_PATH_LITERAL("child_dir"),
&dest_dir_path));
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
+ operation()->Copy(src_dir.path(), dest_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -316,7 +305,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) {
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_file));
+ operation()->Copy(src_dir.path(), dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -331,7 +320,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) {
FilePath child_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Copy(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -346,7 +335,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(URLForPath(src_file), URLForPath(dest_dir.path()));
+ operation()->Copy(src_file, dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
}
@@ -362,7 +351,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) {
FilePath nonexisting_file = nonexisting.Append(
FILE_PATH_LITERAL("DontExistFile"));
- operation()->Copy(URLForPath(src_dir), URLForPath(nonexisting_file));
+ operation()->Copy(src_dir, nonexisting_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -378,7 +367,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
+ operation()->Copy(src_file, dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -394,7 +383,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
+ operation()->Copy(src_file, dest_file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -407,7 +396,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Copy(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
@@ -425,7 +414,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath dest_dir(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir));
+ operation()->Copy(src_dir.path(), dest_dir);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(dest_dir));
@@ -440,7 +429,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
+ operation()->Copy(src_dir.path(), dest_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
@@ -453,7 +442,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileFailure) {
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateFile(URLForPath(file), true);
+ operation()->CreateFile(file, true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -465,7 +454,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) {
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateFile(URLForPath(file), false);
+ operation()->CreateFile(file, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(file));
@@ -476,7 +465,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) {
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateFile(URLForPath(file), true);
+ operation()->CreateFile(file, true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(file));
@@ -487,7 +476,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) {
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateFile(URLForPath(file), false);
+ operation()->CreateFile(file, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
}
@@ -499,7 +488,7 @@ TEST_F(FileSystemOperationTest,
FILE_PATH_LITERAL("DirDoesntExist")));
FilePath nonexisting_file = nonexisting.Append(
FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateDirectory(URLForPath(nonexisting_file), false, false);
+ operation()->CreateDirectory(nonexisting_file, false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -508,7 +497,7 @@ TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) {
// Exclusive and dir existing at path.
ScopedTempDir src_dir;
ASSERT_TRUE(src_dir.CreateUniqueTempDir());
- operation()->CreateDirectory(URLForPath(src_dir.path()), true, false);
+ operation()->CreateDirectory(src_dir.path(), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -519,7 +508,7 @@ TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) {
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateDirectory(URLForPath(file), true, false);
+ operation()->CreateDirectory(file, true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -528,14 +517,14 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccess) {
// Dir exists and exclusive is false.
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->CreateDirectory(URLForPath(dir.path()), false, false);
+ operation()->CreateDirectory(dir.path(), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
// Dir doesn't exist.
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false);
+ operation()->CreateDirectory(nonexisting_dir_path, false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
@@ -546,7 +535,7 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false);
+ operation()->CreateDirectory(nonexisting_dir_path, true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
@@ -555,16 +544,16 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) {
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->GetMetadata(URLForPath(nonexisting_dir_path));
+ operation()->GetMetadata(nonexisting_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
- operation()->FileExists(URLForPath(nonexisting_dir_path));
+ operation()->FileExists(nonexisting_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->DirectoryExists(URLForPath(nonexisting_dir_path));
+ operation()->DirectoryExists(nonexisting_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -573,11 +562,11 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->DirectoryExists(URLForPath(dir.path()));
+ operation()->DirectoryExists(dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
- operation()->GetMetadata(URLForPath(dir.path()));
+ operation()->GetMetadata(dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(info().is_directory);
@@ -585,11 +574,11 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->FileExists(URLForPath(file));
+ operation()->FileExists(file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
- operation()->GetMetadata(URLForPath(file));
+ operation()->GetMetadata(file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(info().is_directory);
@@ -599,13 +588,13 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->FileExists(URLForPath(dir.path()));
+ operation()->FileExists(dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
FilePath file;
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file));
- operation()->DirectoryExists(URLForPath(file));
+ operation()->DirectoryExists(file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -615,7 +604,7 @@ TEST_F(FileSystemOperationTest, TestReadDirFailure) {
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->ReadDirectory(URLForPath(nonexisting_dir_path));
+ operation()->ReadDirectory(nonexisting_dir_path);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -624,7 +613,7 @@ TEST_F(FileSystemOperationTest, TestReadDirFailure) {
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->ReadDirectory(URLForPath(file));
+ operation()->ReadDirectory(file);
MessageLoop::current()->RunAllPending();
// TODO(kkanetkar) crbug.com/54309 to change the error code.
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -643,7 +632,7 @@ TEST_F(FileSystemOperationTest, TestReadDirSuccess) {
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->ReadDirectory(URLForPath(parent_dir.path()));
+ operation()->ReadDirectory(parent_dir.path());
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationStatusNotSet, status());
EXPECT_EQ(2u, entries().size());
@@ -665,7 +654,7 @@ TEST_F(FileSystemOperationTest, TestRemoveFailure) {
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting);
- operation()->Remove(URLForPath(nonexisting), false /* recursive */);
+ operation()->Remove(nonexisting, false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -683,7 +672,7 @@ TEST_F(FileSystemOperationTest, TestRemoveFailure) {
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->Remove(URLForPath(parent_dir.path()), false /* recursive */);
+ operation()->Remove(parent_dir.path(), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
status());
@@ -694,7 +683,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
ASSERT_TRUE(empty_dir.CreateUniqueTempDir());
EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path()));
- operation()->Remove(URLForPath(empty_dir.path()), false /* recursive */);
+ operation()->Remove(empty_dir.path(), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path()));
@@ -712,7 +701,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->Remove(URLForPath(parent_dir.path()), true /* recursive */);
+ operation()->Remove(parent_dir.path(), true /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path()));
@@ -730,7 +719,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
file_util::WriteFile(file, test_data, data_size));
// Check that its length is the size of the data written.
- operation()->GetMetadata(URLForPath(file));
+ operation()->GetMetadata(file);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(info().is_directory);
@@ -738,7 +727,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
// Extend the file by truncating it.
int length = 17;
- operation()->Truncate(URLForPath(file), length);
+ operation()->Truncate(file, length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
@@ -759,7 +748,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
// Shorten the file by truncating it.
length = 3;
- operation()->Truncate(URLForPath(file), length);
+ operation()->Truncate(file, length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc
index a678b0a..e331338 100644
--- a/webkit/fileapi/file_system_operation_write_unittest.cc
+++ b/webkit/fileapi/file_system_operation_write_unittest.cc
@@ -10,6 +10,7 @@
#include "webkit/fileapi/file_system_operation.h"
+#include "base/logging.h"
#include "base/message_loop.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_temp_dir.h"
@@ -80,16 +81,6 @@ class FileSystemOperationTest : public testing::Test {
virtual void TearDown();
protected:
- GURL URLForRelativePath(const std::string& path) const {
- // Only the path will actually get used.
- return GURL("file://").Resolve(file_.value()).Resolve(path);
- }
-
- GURL URLForPath(const FilePath& path) const {
- // Only the path will actually get used.
- return GURL("file://").Resolve(path.value());
- }
-
MessageLoop loop_;
ScopedTempDir dir_;
@@ -128,7 +119,7 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
ADD_FAILURE();
}
- virtual void DidOpenFileSystem(const std::string&, const GURL&) {
+ virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
ADD_FAILURE();
}
@@ -174,7 +165,7 @@ TEST_F(FileSystemOperationTest, TestWriteSuccess) {
url_request_context->blob_storage_controller()->
RegisterBlobUrl(blob_url, blob_data);
- operation()->Write(url_request_context, URLForPath(file_), blob_url, 0);
+ operation()->Write(url_request_context, file_, blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
@@ -194,7 +185,7 @@ TEST_F(FileSystemOperationTest, TestWriteZero) {
url_request_context->blob_storage_controller()->
RegisterBlobUrl(blob_url, blob_data);
- operation()->Write(url_request_context, URLForPath(file_), blob_url, 0);
+ operation()->Write(url_request_context, file_, blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
@@ -208,8 +199,7 @@ TEST_F(FileSystemOperationTest, TestWriteInvalidBlobUrl) {
scoped_refptr<TestURLRequestContext> url_request_context(
new TestURLRequestContext());
- operation()->Write(url_request_context, URLForPath(file_),
- GURL("blob:invalid"), 0);
+ operation()->Write(url_request_context, file_, GURL("blob:invalid"), 0);
MessageLoop::current()->Run();
EXPECT_EQ(0, bytes_written());
@@ -228,7 +218,7 @@ TEST_F(FileSystemOperationTest, TestWriteInvalidFile) {
RegisterBlobUrl(blob_url, blob_data);
operation()->Write(url_request_context,
- URLForRelativePath("nonexist"), blob_url, 0);
+ FilePath(FILE_PATH_LITERAL("/nonexist")), blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
@@ -248,7 +238,7 @@ TEST_F(FileSystemOperationTest, TestWriteDir) {
url_request_context->blob_storage_controller()->
RegisterBlobUrl(blob_url, blob_data);
- operation()->Write(url_request_context, URLForPath(dir_.path()), blob_url, 0);
+ operation()->Write(url_request_context, dir_.path(), blob_url, 0);
MessageLoop::current()->Run();
url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
diff --git a/webkit/fileapi/file_system_path_manager.cc b/webkit/fileapi/file_system_path_manager.cc
index 16fc60b..558dc31 100644
--- a/webkit/fileapi/file_system_path_manager.cc
+++ b/webkit/fileapi/file_system_path_manager.cc
@@ -100,6 +100,83 @@ FilePath FileSystemPathManager::GetFileSystemRootPathOnFileThread(
}
}
+bool FileSystemPathManager::CrackFileSystemPath(
+ const FilePath& path, GURL* origin_url, FileSystemType* type,
+ FilePath* virtual_path) const {
+ // TODO(ericu):
+ // Paths come in here [for now] as a URL, followed by a virtual path in
+ // platform format. For example, on Windows, this will look like
+ // filesystem:http://www.example.com/temporary/\path\to\file.txt.
+ // A potentially dangerous malicious path on Windows might look like:
+ // filesystem:http://www.example.com/temporary/foo/../../\path\to\file.txt.
+ // This code is ugly, but will get cleaned up as we fix the calling side.
+ // Eventually there won't be a distinction between a filesystem path and a
+ // filesystem URL--they'll all be URLs.
+ // We should be passing these to WebKit as string, not FilePath, for ease of
+ // manipulation, or possibly as GURL/KURL.
+
+ std::string path_as_string;
+#ifdef OS_WIN
+ path_as_string = WideToUTF8(path.value());
+#else
+ path_as_string = path.value();
+#endif
+ GURL path_as_url(path_as_string);
+
+ FilePath local_path;
+ GURL local_url;
+ FileSystemType local_type;
+ if (!CrackFileSystemURL(path_as_url, &local_url, &local_type, &local_path))
+ return false;
+
+#if defined(FILE_PATH_USES_WIN_SEPARATORS)
+ // TODO(ericu): This puts the separators back to windows-standard; they come
+ // out of the above code as '/' no matter the platform. Long-term, we'll
+ // want to let the underlying FileSystemFileUtil implementation do this part,
+ // since they won't all need it.
+ local_path = local_path.NormalizeWindowsPathSeparators();
+#endif
+
+ // Check if file access to this type of file system is allowed
+ // for this origin.
+ switch (local_type) {
+ case kFileSystemTypeTemporary:
+ case kFileSystemTypePersistent:
+ if (!sandbox_provider_->IsAccessAllowed(local_url))
+ return false;
+ break;
+ case kFileSystemTypeLocal:
+ if (!local_provider_.get() ||
+ !local_provider_->IsAccessAllowed(local_url)) {
+ return false;
+ }
+ break;
+ case kFileSystemTypeUnknown:
+ default:
+ NOTREACHED();
+ return false;
+ }
+ // Any paths that include parent references are considered invalid.
+ // These should have been taken care of in CrackFileSystemURL.
+ DCHECK(!local_path.ReferencesParent());
+
+ // The given |local_path| seems valid. Populates the |origin_url|, |type|
+ // and |virtual_path| if they are given.
+
+ if (origin_url) {
+ *origin_url = local_url;
+ }
+
+ if (type)
+ *type = local_type;
+
+ if (virtual_path) {
+ *virtual_path = local_path;
+ }
+
+ return true;
+}
+
bool FileSystemPathManager::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.
@@ -135,29 +212,6 @@ bool FileSystemPathManager::IsRestrictedFileName(
}
}
-// Checks if an origin has access to a particular filesystem type.
-bool FileSystemPathManager::IsAllowedFileSystemType(
- GURL origin, FileSystemType type) {
- switch (type) {
- case kFileSystemTypeTemporary:
- case kFileSystemTypePersistent:
- if (!sandbox_provider_->IsAccessAllowed(origin))
- return false;
- break;
- case kFileSystemTypeLocal:
- if (!local_provider_.get() ||
- !local_provider_->IsAccessAllowed(origin)) {
- return false;
- }
- break;
- case kFileSystemTypeUnknown:
- default:
- NOTREACHED();
- return false;
- }
- return true;
-}
-
} // namespace fileapi
COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \
diff --git a/webkit/fileapi/file_system_path_manager.h b/webkit/fileapi/file_system_path_manager.h
index feeb603..5a9613a 100644
--- a/webkit/fileapi/file_system_path_manager.h
+++ b/webkit/fileapi/file_system_path_manager.h
@@ -68,6 +68,14 @@ class FileSystemPathManager {
FileSystemType type,
const FilePath& virtual_path,
bool create);
+ // Cracks the given |path|, retrieves the information embedded in the path
+ // and populates |origin_url|, |type| and |virtual_path|. The |virtual_path|
+ // is a sandboxed path in the file system, i.e. the relative path to the
+ // filesystem root for the given domain and type.
+ bool CrackFileSystemPath(const FilePath& path,
+ GURL* origin_url,
+ FileSystemType* type,
+ FilePath* virtual_path) const;
// Returns true if the given |url|'s scheme is allowed to access
// filesystem.
@@ -81,9 +89,6 @@ class FileSystemPathManager {
bool IsRestrictedFileName(FileSystemType type,
const FilePath& filename);
- // Checks if an origin has access to a particular filesystem type.
- bool IsAllowedFileSystemType(GURL origin, FileSystemType type);
-
SandboxMountPointProvider* sandbox_provider() const {
return sandbox_provider_.get();
}
diff --git a/webkit/fileapi/file_system_path_manager_unittest.cc b/webkit/fileapi/file_system_path_manager_unittest.cc
index 8a99b84..fee38c1 100644
--- a/webkit/fileapi/file_system_path_manager_unittest.cc
+++ b/webkit/fileapi/file_system_path_manager_unittest.cc
@@ -228,6 +228,11 @@ class FileSystemPathManagerTest : public testing::Test {
return root_path_callback_status_;
}
+ bool CheckValidFileSystemPath(FileSystemPathManager* manager,
+ const FilePath& path) {
+ return manager->CrackFileSystemPath(path, NULL, NULL, NULL);
+ }
+
FilePath data_path() { return data_dir_.path(); }
FilePath file_system_path() {
return data_dir_.path().Append(
@@ -362,6 +367,89 @@ TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) {
}
}
+TEST_F(FileSystemPathManagerTest, VirtualPathFromFileSystemPathTest) {
+ scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+ GURL root_url = GetFileSystemRootURI(
+ GURL("http://foo.com/"), fileapi::kFileSystemTypeTemporary);
+ FilePath root_path = FilePath().AppendASCII(root_url.spec());
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) {
+ SCOPED_TRACE(testing::Message() << "PathToVirtualPath #"
+ << i << " " << kPathToVirtualPathTestCases[i]);
+ FilePath absolute_path;
+ // TODO(ericu): Clean this up when we've got more sane path-handling.
+ // This hack is necessary because root_path is actually a URL [ending with a
+ // forward slash], and AppendASCII("") on Windows will delete the trailing
+ // slash, making the path invalid as far as CrackFileSystemPath is
+ // concerned.
+ if (strlen(kPathToVirtualPathTestCases[i]))
+ absolute_path = root_path.AppendASCII(
+ kPathToVirtualPathTestCases[i]);
+ else
+ absolute_path = root_path;
+ FilePath virtual_path;
+ EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL,
+ &virtual_path));
+
+ FilePath test_case_path;
+ test_case_path = test_case_path.AppendASCII(
+ kPathToVirtualPathTestCases[i]);
+ EXPECT_EQ(test_case_path.value(), virtual_path.value());
+ }
+}
+
+TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) {
+ scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+
+ fileapi::FileSystemType type;
+
+ GURL root_url = GetFileSystemRootURI(
+ GURL("http://foo.com/"), fileapi::kFileSystemTypeTemporary);
+ FilePath root_path = FilePath().AppendASCII(root_url.spec());
+ FilePath path = root_path.AppendASCII("test");
+ EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL));
+ EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type);
+
+ root_url = GetFileSystemRootURI(
+ GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent);
+ root_path = FilePath().AppendASCII(root_url.spec());
+ path = root_path.AppendASCII("test");
+ EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL));
+ EXPECT_EQ(fileapi::kFileSystemTypePersistent, type);
+}
+
+TEST_F(FileSystemPathManagerTest, CheckValidPath) {
+ scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+ GURL root_url = GetFileSystemRootURI(
+ GURL("http://foo.com/"), fileapi::kFileSystemTypePersistent);
+ FilePath root_path = FilePath().AppendASCII(root_url.spec());
+
+ // The root path must be valid, but upper directories or directories
+ // that are not in our temporary or persistent directory must be
+ // evaluated invalid.
+ EXPECT_TRUE(CheckValidFileSystemPath(manager.get(), root_path));
+ EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), root_path.DirName()));
+ EXPECT_FALSE(CheckValidFileSystemPath(manager.get(),
+ root_path.DirName().DirName()));
+ EXPECT_FALSE(CheckValidFileSystemPath(manager.get(),
+ root_path.DirName().DirName()
+ .AppendASCII("ArbitraryName")
+ .AppendASCII("chrome-dummy")));
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) {
+ SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " "
+ << kCheckValidPathTestCases[i].path);
+ FilePath path(kCheckValidPathTestCases[i].path);
+#ifdef FILE_PATH_USES_WIN_SEPARATORS
+ path = path.NormalizeWindowsPathSeparators();
+#endif
+ if (!path.IsAbsolute())
+ path = root_path.Append(path);
+ EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid,
+ CheckValidFileSystemPath(manager.get(), path));
+ }
+}
+
TEST_F(FileSystemPathManagerTest, IsRestrictedName) {
scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
diff --git a/webkit/fileapi/webfilewriter_base.cc b/webkit/fileapi/webfilewriter_base.cc
index 66f1bd0..cf2a7bc 100644
--- a/webkit/fileapi/webfilewriter_base.cc
+++ b/webkit/fileapi/webfilewriter_base.cc
@@ -13,8 +13,8 @@
namespace fileapi {
WebFileWriterBase::WebFileWriterBase(
- const GURL& path, WebKit::WebFileWriterClient* client)
- : path_(path),
+ const WebKit::WebString& path, WebKit::WebFileWriterClient* client)
+ : path_(webkit_glue::WebStringToFilePath(path)),
client_(client),
operation_(kOperationNone),
cancel_state_(kCancelNotInProgress) {
diff --git a/webkit/fileapi/webfilewriter_base.h b/webkit/fileapi/webfilewriter_base.h
index 15217dd..f47b383 100644
--- a/webkit/fileapi/webfilewriter_base.h
+++ b/webkit/fileapi/webfilewriter_base.h
@@ -5,10 +5,12 @@
#ifndef WEBKIT_FILEAPI_WEBFILEWRITER_BASE_H_
#define WEBKIT_FILEAPI_WEBFILEWRITER_BASE_H_
+#include "base/file_path.h"
#include "base/platform_file.h"
-#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileWriter.h"
+class GURL;
+
namespace WebKit {
class WebFileWriterClient;
class WebString;
@@ -20,7 +22,7 @@ namespace fileapi {
class WebFileWriterBase : public WebKit::WebFileWriter {
public:
WebFileWriterBase(
- const GURL& path, WebKit::WebFileWriterClient* client);
+ const WebKit::WebString& path, WebKit::WebFileWriterClient* client);
virtual ~WebFileWriterBase();
// WebFileWriter implementation
@@ -32,8 +34,8 @@ class WebFileWriterBase : public WebKit::WebFileWriter {
// Derived classes must provide these methods to asynchronously perform
// the requested operation, and they must call the appropiate DidSomething
// method upon completion and as progress is made in the Write case.
- virtual void DoTruncate(const GURL& path, int64 offset) = 0;
- virtual void DoWrite(const GURL& path, const GURL& blob_url,
+ virtual void DoTruncate(const FilePath& path, int64 offset) = 0;
+ virtual void DoWrite(const FilePath& path, const GURL& blob_url,
int64 offset) = 0;
virtual void DoCancel() = 0;
@@ -56,7 +58,7 @@ class WebFileWriterBase : public WebKit::WebFileWriter {
void FinishCancel();
- GURL path_;
+ FilePath path_;
WebKit::WebFileWriterClient* client_;
OperationType operation_;
CancelState cancel_state_;
diff --git a/webkit/fileapi/webfilewriter_base_unittest.cc b/webkit/fileapi/webfilewriter_base_unittest.cc
index 43164e7..7a07cd2 100644
--- a/webkit/fileapi/webfilewriter_base_unittest.cc
+++ b/webkit/fileapi/webfilewriter_base_unittest.cc
@@ -31,8 +31,16 @@ const int kMultiFileWrite_Offset = 3;
const int kCancelFileWriteBeforeCompletion_Offset = 4;
const int kCancelFileWriteAfterCompletion_Offset = 5;
-GURL mock_path_as_gurl() {
- return GURL("MockPath");
+std::string mock_path_as_ascii() {
+ return std::string("MockPath");
+}
+
+string16 mock_path_as_string16() {
+ return ASCIIToUTF16(mock_path_as_ascii());
+}
+
+FilePath mock_path_as_file_path() {
+ return FilePath().AppendASCII(mock_path_as_ascii());
}
} // namespace
@@ -40,32 +48,32 @@ GURL mock_path_as_gurl() {
class TestableFileWriter : public WebFileWriterBase {
public:
explicit TestableFileWriter(WebKit::WebFileWriterClient* client)
- : WebFileWriterBase(mock_path_as_gurl(), client) {
+ : WebFileWriterBase(mock_path_as_string16(), client) {
reset();
}
void reset() {
received_truncate_ = false;
- received_truncate_path_ = GURL();
+ received_truncate_path_ = FilePath();
received_truncate_offset_ = kNoOffset;
received_write_ = false;
- received_write_path_ = GURL();
+ received_write_path_ = FilePath();
received_write_offset_ = kNoOffset;
received_write_blob_url_ = GURL();
received_cancel_ = false;
}
bool received_truncate_;
- GURL received_truncate_path_;
+ FilePath received_truncate_path_;
int64 received_truncate_offset_;
bool received_write_;
- GURL received_write_path_;
+ FilePath received_write_path_;
GURL received_write_blob_url_;
int64 received_write_offset_;
bool received_cancel_;
protected:
- virtual void DoTruncate(const GURL& path, int64 offset) {
+ virtual void DoTruncate(const FilePath& path, int64 offset) {
received_truncate_ = true;
received_truncate_path_ = path;
received_truncate_offset_ = offset;
@@ -87,7 +95,7 @@ class TestableFileWriter : public WebFileWriterBase {
}
}
- virtual void DoWrite(const GURL& path, const GURL& blob_url,
+ virtual void DoWrite(const FilePath& path, const GURL& blob_url,
int64 offset) {
received_write_ = true;
received_write_path_ = path;
@@ -197,8 +205,8 @@ TEST_F(FileWriterTest, BasicFileWrite) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_write_);
- EXPECT_EQ(testable_writer_->received_write_path_,
- mock_path_as_gurl());
+ EXPECT_EQ(testable_writer_->received_write_path_.value(),
+ mock_path_as_file_path().value());
EXPECT_EQ(kBasicFileWrite_Offset,
testable_writer_->received_write_offset_);
EXPECT_EQ(kBlobUrl, testable_writer_->received_write_blob_url_);
@@ -219,8 +227,8 @@ TEST_F(FileWriterTest, BasicFileTruncate) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_truncate_);
- EXPECT_EQ(mock_path_as_gurl(),
- testable_writer_->received_truncate_path_);
+ EXPECT_EQ(mock_path_as_file_path().value(),
+ testable_writer_->received_truncate_path_.value());
EXPECT_EQ(kBasicFileTruncate_Offset,
testable_writer_->received_truncate_offset_);
EXPECT_FALSE(testable_writer_->received_write_);
@@ -239,8 +247,8 @@ TEST_F(FileWriterTest, ErrorFileWrite) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_write_);
- EXPECT_EQ(testable_writer_->received_write_path_,
- mock_path_as_gurl());
+ EXPECT_EQ(testable_writer_->received_write_path_.value(),
+ mock_path_as_file_path().value());
EXPECT_EQ(kErrorFileWrite_Offset,
testable_writer_->received_write_offset_);
EXPECT_EQ(kBlobUrl, testable_writer_->received_write_blob_url_);
@@ -260,8 +268,8 @@ TEST_F(FileWriterTest, ErrorFileTruncate) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_truncate_);
- EXPECT_EQ(mock_path_as_gurl(),
- testable_writer_->received_truncate_path_);
+ EXPECT_EQ(mock_path_as_file_path().value(),
+ testable_writer_->received_truncate_path_.value());
EXPECT_EQ(kErrorFileTruncate_Offset,
testable_writer_->received_truncate_offset_);
EXPECT_FALSE(testable_writer_->received_write_);
@@ -281,8 +289,8 @@ TEST_F(FileWriterTest, MultiFileWrite) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_write_);
- EXPECT_EQ(testable_writer_->received_write_path_,
- mock_path_as_gurl());
+ EXPECT_EQ(testable_writer_->received_write_path_.value(),
+ mock_path_as_file_path().value());
EXPECT_EQ(kMultiFileWrite_Offset,
testable_writer_->received_write_offset_);
EXPECT_EQ(kBlobUrl, testable_writer_->received_write_blob_url_);
@@ -304,8 +312,8 @@ TEST_F(FileWriterTest, CancelFileWriteBeforeCompletion) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_write_);
- EXPECT_EQ(testable_writer_->received_write_path_,
- mock_path_as_gurl());
+ EXPECT_EQ(testable_writer_->received_write_path_.value(),
+ mock_path_as_file_path().value());
EXPECT_EQ(kCancelFileWriteBeforeCompletion_Offset,
testable_writer_->received_write_offset_);
EXPECT_EQ(kBlobUrl, testable_writer_->received_write_blob_url_);
@@ -328,8 +336,8 @@ TEST_F(FileWriterTest, CancelFileWriteAfterCompletion) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_write_);
- EXPECT_EQ(testable_writer_->received_write_path_,
- mock_path_as_gurl());
+ EXPECT_EQ(testable_writer_->received_write_path_.value(),
+ mock_path_as_file_path().value());
EXPECT_EQ(kCancelFileWriteAfterCompletion_Offset,
testable_writer_->received_write_offset_);
EXPECT_EQ(kBlobUrl, testable_writer_->received_write_blob_url_);
@@ -351,8 +359,8 @@ TEST_F(FileWriterTest, CancelFileTruncate) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_truncate_);
- EXPECT_EQ(mock_path_as_gurl(),
- testable_writer_->received_truncate_path_);
+ EXPECT_EQ(mock_path_as_file_path().value(),
+ testable_writer_->received_truncate_path_.value());
EXPECT_EQ(kCancelFileTruncate_Offset,
testable_writer_->received_truncate_offset_);
EXPECT_TRUE(testable_writer_->received_cancel_);
@@ -371,8 +379,8 @@ TEST_F(FileWriterTest, CancelFailedTruncate) {
// Check that the derived class gets called correctly.
EXPECT_TRUE(testable_writer_->received_truncate_);
- EXPECT_EQ(mock_path_as_gurl(),
- testable_writer_->received_truncate_path_);
+ EXPECT_EQ(mock_path_as_file_path().value(),
+ testable_writer_->received_truncate_path_.value());
EXPECT_EQ(kCancelFailedTruncate_Offset,
testable_writer_->received_truncate_offset_);
EXPECT_TRUE(testable_writer_->received_cancel_);
diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc
index 621cd31..92d443b 100644
--- a/webkit/plugins/ppapi/file_callbacks.cc
+++ b/webkit/plugins/ppapi/file_callbacks.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/file_callbacks.h"
+#include "base/file_path.h"
#include "base/logging.h"
#include "ppapi/c/dev/ppb_file_system_dev.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
@@ -75,12 +76,12 @@ void FileCallbacks::DidReadDirectory(
}
void FileCallbacks::DidOpenFileSystem(const std::string&,
- const GURL& root_url) {
+ const FilePath& root_path) {
if (callback_->completed())
return;
DCHECK(file_system_);
- file_system_->set_root_url(root_url);
+ file_system_->set_root_path(root_path);
file_system_->set_opened(true);
callback_->Run(PP_OK);
diff --git a/webkit/plugins/ppapi/file_callbacks.h b/webkit/plugins/ppapi/file_callbacks.h
index 4bdaa1d..e0a129f 100644
--- a/webkit/plugins/ppapi/file_callbacks.h
+++ b/webkit/plugins/ppapi/file_callbacks.h
@@ -45,7 +45,7 @@ class FileCallbacks : public fileapi::FileSystemCallbackDispatcher {
virtual void DidReadDirectory(
const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more);
virtual void DidOpenFileSystem(const std::string&,
- const GURL& root_url);
+ const FilePath& root_path);
virtual void DidFail(base::PlatformFileError error_code);
virtual void DidWrite(int64 bytes, bool complete);
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index f9d8abe..5376483 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -87,20 +87,20 @@ bool MockPluginDelegate::OpenFileSystem(
}
bool MockPluginDelegate::MakeDirectory(
- const GURL& path,
+ const FilePath& path,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
return false;
}
bool MockPluginDelegate::Query(
- const GURL& path,
+ const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
return false;
}
bool MockPluginDelegate::Touch(
- const GURL& path,
+ const FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
@@ -108,20 +108,20 @@ bool MockPluginDelegate::Touch(
}
bool MockPluginDelegate::Delete(
- const GURL& path,
+ const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
return false;
}
bool MockPluginDelegate::Rename(
- const GURL& file_path,
- const GURL& new_file_path,
+ const FilePath& file_path,
+ const FilePath& new_file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
return false;
}
bool MockPluginDelegate::ReadDirectory(
- const GURL& directory_path,
+ const FilePath& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) {
return false;
}
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index a5512b0..754282f7 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -44,22 +44,22 @@ class MockPluginDelegate : public PluginDelegate {
long long size,
fileapi::FileSystemCallbackDispatcher* dispatcher);
virtual bool MakeDirectory(
- const GURL& path,
+ const FilePath& path,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Query(const GURL& path,
+ virtual bool Query(const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Touch(const GURL& path,
+ virtual bool Touch(const FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Delete(const GURL& path,
+ virtual bool Delete(const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Rename(const GURL& file_path,
- const GURL& new_file_path,
+ virtual bool Rename(const FilePath& file_path,
+ const FilePath& new_file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
virtual bool ReadDirectory(
- const GURL& directory_path,
+ const FilePath& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
virtual base::PlatformFileError OpenFile(const PepperFilePath& path,
int flags,
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index e6926a8..6349cd9 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -284,22 +284,22 @@ class PluginDelegate {
long long size,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
virtual bool MakeDirectory(
- const GURL& path,
+ const FilePath& path,
bool recursive,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
- virtual bool Query(const GURL& path,
+ virtual bool Query(const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
- virtual bool Touch(const GURL& path,
+ virtual bool Touch(const FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
- virtual bool Delete(const GURL& path,
+ virtual bool Delete(const FilePath& path,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
- virtual bool Rename(const GURL& file_path,
- const GURL& new_file_path,
+ virtual bool Rename(const FilePath& file_path,
+ const FilePath& new_file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
virtual bool ReadDirectory(
- const GURL& directory_path,
+ const FilePath& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
virtual base::PlatformFileError OpenFile(const PepperFilePath& path,
diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
index ac5a612..36e43bf 100644
--- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
+++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
@@ -113,7 +113,7 @@ int32_t PPB_DirectoryReader_Impl::GetNextEntry(
PP_Resource resource_id = GetReferenceNoAddRef();
DCHECK(resource_id != 0);
if (!instance->delegate()->ReadDirectory(
- directory_ref_->GetFileSystemURL(),
+ directory_ref_->GetSystemPath(),
new FileCallbacks(instance->module()->AsWeakPtr(),
resource_id,
callback, NULL, NULL, this)))
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
index a741858..55bf3f1 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
@@ -6,7 +6,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
-#include "googleurl/src/gurl.h"
#include "ppapi/c/pp_errors.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/file_callbacks.h"
@@ -127,7 +126,7 @@ int32_t MakeDirectory(PP_Resource directory_ref_id,
PluginInstance* instance = file_system->instance();
if (!instance->delegate()->MakeDirectory(
- directory_ref->GetFileSystemURL(), PPBoolToBool(make_ancestors),
+ directory_ref->GetSystemPath(), PPBoolToBool(make_ancestors),
new FileCallbacks(instance->module()->AsWeakPtr(), directory_ref_id,
callback, NULL, NULL, NULL)))
return PP_ERROR_FAILED;
@@ -151,8 +150,7 @@ int32_t Touch(PP_Resource file_ref_id,
PluginInstance* instance = file_system->instance();
if (!instance->delegate()->Touch(
- file_ref->GetFileSystemURL(),
- base::Time::FromDoubleT(last_access_time),
+ file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time),
base::Time::FromDoubleT(last_modified_time),
new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id,
callback, NULL, NULL, NULL)))
@@ -175,7 +173,7 @@ int32_t Delete(PP_Resource file_ref_id,
PluginInstance* instance = file_system->instance();
if (!instance->delegate()->Delete(
- file_ref->GetFileSystemURL(),
+ file_ref->GetSystemPath(),
new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id,
callback, NULL, NULL, NULL)))
return PP_ERROR_FAILED;
@@ -206,7 +204,7 @@ int32_t Rename(PP_Resource file_ref_id,
// http://crbug.com/67624
PluginInstance* instance = file_system->instance();
if (!instance->delegate()->Rename(
- file_ref->GetFileSystemURL(), new_file_ref->GetFileSystemURL(),
+ file_ref->GetSystemPath(), new_file_ref->GetSystemPath(),
new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id,
callback, NULL, NULL, NULL)))
return PP_ERROR_FAILED;
@@ -322,25 +320,22 @@ std::string PPB_FileRef_Impl::GetPath() const {
}
FilePath PPB_FileRef_Impl::GetSystemPath() const {
- if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) {
- NOTREACHED();
- return FilePath();
- }
- return system_path_;
-}
+ if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
+ return system_path_;
-GURL PPB_FileRef_Impl::GetFileSystemURL() const {
- if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
- GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) {
- NOTREACHED();
- return GURL();
- }
- if (!virtual_path_.size())
- return file_system_->root_url();
- // Since |virtual_path_| starts with a '/', it looks like an absolute path.
- // We need to trim off the '/' before calling Resolve, as FileSystem URLs
- // start with a storage type identifier that looks like a path segment.
- return file_system_->root_url().Resolve(virtual_path_.substr(1));
+ // Since |virtual_path_| starts with a '/', it is considered an absolute path
+ // on POSIX systems. We need to remove the '/' before calling Append() or we
+ // will run into a DCHECK.
+ FilePath virtual_file_path(
+#if defined(OS_WIN)
+ UTF8ToWide(virtual_path_.substr(1))
+#elif defined(OS_POSIX)
+ virtual_path_.substr(1)
+#else
+#error "Unsupported platform."
+#endif
+ );
+ return file_system_->root_path().Append(virtual_file_path);
}
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h
index 7fafed1..f006991 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h
@@ -8,7 +8,6 @@
#include <string>
#include "base/file_path.h"
-#include "googleurl/src/gurl.h"
#include "ppapi/c/dev/ppb_file_ref_dev.h"
#include "webkit/plugins/ppapi/resource.h"
@@ -53,9 +52,6 @@ class PPB_FileRef_Impl : public Resource {
// Returns the system path corresponding to this file.
FilePath GetSystemPath() const;
- // Returns the FileSystem API URL corresponding to this file.
- GURL GetFileSystemURL() const;
-
private:
scoped_refptr<PPB_FileSystem_Impl> file_system_;
std::string virtual_path_; // UTF-8 encoded
diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.h b/webkit/plugins/ppapi/ppb_file_system_impl.h
index 76e9858..3ee3756 100644
--- a/webkit/plugins/ppapi/ppb_file_system_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_system_impl.h
@@ -6,7 +6,7 @@
#define WEBKIT_PLUGINS_PPAPI_PPB_FILE_SYSTEM_IMPL_H_
#include "base/basictypes.h"
-#include "googleurl/src/gurl.h"
+#include "base/file_path.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
#include "webkit/plugins/ppapi/resource.h"
@@ -28,8 +28,8 @@ class PPB_FileSystem_Impl : public Resource {
PluginInstance* instance() { return instance_; }
PP_FileSystemType_Dev type() { return type_; }
- const GURL& root_url() const { return root_url_; }
- void set_root_url(const GURL& root_url) { root_url_ = root_url; }
+ const FilePath& root_path() const { return root_path_; }
+ void set_root_path(const FilePath& root_path) { root_path_ = root_path; }
bool opened() const { return opened_; }
void set_opened(bool opened) { opened_ = opened; }
bool called_open() const { return called_open_; }
@@ -38,7 +38,7 @@ class PPB_FileSystem_Impl : public Resource {
private:
PluginInstance* instance_;
PP_FileSystemType_Dev type_;
- GURL root_url_;
+ FilePath root_path_;
bool opened_;
bool called_open_;
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
index ff634eeb..ecbc6d5 100644
--- a/webkit/tools/test_shell/simple_file_system.cc
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -95,13 +95,13 @@ class SimpleFileSystemCallbackDispatcher
}
virtual void DidOpenFileSystem(
- const std::string& name, const GURL& root) {
+ const std::string& name, const FilePath& path) {
DCHECK(file_system_);
- if (!root.is_valid())
+ if (path.empty())
callbacks_->didFail(WebKit::WebFileErrorSecurity);
else
callbacks_->didOpenFileSystem(
- WebString::fromUTF8(name), WebString::fromUTF8(root.spec()));
+ UTF8ToUTF16(name), webkit_glue::FilePathToWebString(path));
}
virtual void DidFail(base::PlatformFileError error_code) {
@@ -168,58 +168,80 @@ void SimpleFileSystem::OpenFileSystem(
void SimpleFileSystem::move(
const WebString& src_path,
const WebString& dest_path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path));
+ FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path));
+ FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path));
+
+ GetNewOperation(callbacks)->Move(src_filepath, dest_filepath);
}
void SimpleFileSystem::copy(
const WebString& src_path, const WebString& dest_path,
WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path));
+ FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path));
+ FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path));
+
+ GetNewOperation(callbacks)->Copy(src_filepath, dest_filepath);
}
void SimpleFileSystem::remove(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Remove(GURL(path), false /* recursive */);
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->Remove(filepath, false /* recursive */);
}
void SimpleFileSystem::removeRecursively(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Remove(GURL(path), true /* recursive */);
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->Remove(filepath, true /* recursive */);
}
void SimpleFileSystem::readMetadata(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->GetMetadata(GURL(path));
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->GetMetadata(filepath);
}
void SimpleFileSystem::createFile(
const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->CreateFile(GURL(path), exclusive);
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->CreateFile(filepath, exclusive);
}
void SimpleFileSystem::createDirectory(
const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->CreateDirectory(GURL(path), exclusive, false);
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->CreateDirectory(filepath, exclusive, false);
}
void SimpleFileSystem::fileExists(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->FileExists(GURL(path));
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->FileExists(filepath);
}
void SimpleFileSystem::directoryExists(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->DirectoryExists(GURL(path));
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->DirectoryExists(filepath);
}
void SimpleFileSystem::readDirectory(
const WebString& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->ReadDirectory(GURL(path));
+ FilePath filepath(webkit_glue::WebStringToFilePath(path));
+
+ GetNewOperation(callbacks)->ReadDirectory(filepath);
}
WebFileWriter* SimpleFileSystem::createFileWriter(
const WebString& path, WebFileWriterClient* client) {
- return new SimpleFileWriter(GURL(path), client, file_system_context_.get());
+ return new SimpleFileWriter(path, client, file_system_context_.get());
}
FileSystemOperation* SimpleFileSystem::GetNewOperation(
diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc
index 657d247..9304978 100644
--- a/webkit/tools/test_shell/simple_file_writer.cc
+++ b/webkit/tools/test_shell/simple_file_writer.cc
@@ -45,7 +45,7 @@ class SimpleFileWriter::IOThreadProxy
virtual ~IOThreadProxy() {
}
- void Truncate(const GURL& path, int64 offset) {
+ void Truncate(const FilePath& path, int64 offset) {
if (!io_thread_->BelongsToCurrentThread()) {
io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
this, &IOThreadProxy::Truncate, path, offset));
@@ -56,7 +56,7 @@ class SimpleFileWriter::IOThreadProxy
operation_->Truncate(path, offset);
}
- void Write(const GURL& path, const GURL& blob_url, int64 offset) {
+ void Write(const FilePath& path, const GURL& blob_url, int64 offset) {
if (!io_thread_->BelongsToCurrentThread()) {
io_thread_->PostTask(FROM_HERE, NewRunnableMethod(
this, &IOThreadProxy::Write, path, blob_url, offset));
@@ -118,7 +118,7 @@ class SimpleFileWriter::IOThreadProxy
virtual void DidOpenFileSystem(
const std::string& name,
- const GURL& root) {
+ const FilePath& root_path) {
NOTREACHED();
}
@@ -181,7 +181,7 @@ class SimpleFileWriter::IOThreadProxy
SimpleFileWriter::SimpleFileWriter(
- const GURL& path,
+ const WebString& path,
WebFileWriterClient* client,
FileSystemContext* file_system_context)
: WebFileWriterBase(path, client),
@@ -191,12 +191,12 @@ SimpleFileWriter::SimpleFileWriter(
SimpleFileWriter::~SimpleFileWriter() {
}
-void SimpleFileWriter::DoTruncate(const GURL& path, int64 offset) {
+void SimpleFileWriter::DoTruncate(const FilePath& path, int64 offset) {
io_thread_proxy_->Truncate(path, offset);
}
void SimpleFileWriter::DoWrite(
- const GURL& path, const GURL& blob_url, int64 offset) {
+ const FilePath& path, const GURL& blob_url, int64 offset) {
io_thread_proxy_->Write(path, blob_url, offset);
}
diff --git a/webkit/tools/test_shell/simple_file_writer.h b/webkit/tools/test_shell/simple_file_writer.h
index 9ea2da5..6ef27b9 100644
--- a/webkit/tools/test_shell/simple_file_writer.h
+++ b/webkit/tools/test_shell/simple_file_writer.h
@@ -22,7 +22,7 @@ class SimpleFileWriter : public fileapi::WebFileWriterBase,
public base::SupportsWeakPtr<SimpleFileWriter> {
public:
SimpleFileWriter(
- const GURL& path,
+ const WebKit::WebString& path,
WebKit::WebFileWriterClient* client,
fileapi::FileSystemContext* file_system_context);
virtual ~SimpleFileWriter();
@@ -38,8 +38,8 @@ class SimpleFileWriter : public fileapi::WebFileWriterBase,
protected:
// WebFileWriterBase overrides
- virtual void DoTruncate(const GURL& path, int64 offset);
- virtual void DoWrite(const GURL& path, const GURL& blob_url,
+ virtual void DoTruncate(const FilePath& path, int64 offset);
+ virtual void DoWrite(const FilePath& path, const GURL& blob_url,
int64 offset);
virtual void DoCancel();