summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 00:26:07 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 00:26:07 +0000
commit0f6646d8f0940a8b1c4ebfda247a4f062d3feb9e (patch)
tree872eb8366c232683ea048d33e09dac150a102ca3 /webkit/glue/plugins
parenteff5e88804ca872d3603a5123cd90164bb68a5dd (diff)
downloadchromium_src-0f6646d8f0940a8b1c4ebfda247a4f062d3feb9e.zip
chromium_src-0f6646d8f0940a8b1c4ebfda247a4f062d3feb9e.tar.gz
chromium_src-0f6646d8f0940a8b1c4ebfda247a4f062d3feb9e.tar.bz2
Update Pepper's FileSystem and FileRef implementations.
BUG=none TEST=test_file_ref, test_file_system, test_url_loader Review URL: http://codereview.chromium.org/3602008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins')
-rw-r--r--webkit/glue/plugins/pepper_error_util.cc1
-rw-r--r--webkit/glue/plugins/pepper_file_callbacks.cc88
-rw-r--r--webkit/glue/plugins/pepper_file_callbacks.h53
-rw-r--r--webkit/glue/plugins/pepper_file_chooser.cc3
-rw-r--r--webkit/glue/plugins/pepper_file_io.cc11
-rw-r--r--webkit/glue/plugins/pepper_file_io.h1
-rw-r--r--webkit/glue/plugins/pepper_file_ref.cc243
-rw-r--r--webkit/glue/plugins/pepper_file_ref.h31
-rw-r--r--webkit/glue/plugins/pepper_file_system.cc259
-rw-r--r--webkit/glue/plugins/pepper_file_system.h22
-rw-r--r--webkit/glue/plugins/pepper_plugin_delegate.h7
-rw-r--r--webkit/glue/plugins/pepper_plugin_module.cc18
-rw-r--r--webkit/glue/plugins/pepper_resource.h7
-rw-r--r--webkit/glue/plugins/pepper_url_request_info.cc3
14 files changed, 421 insertions, 326 deletions
diff --git a/webkit/glue/plugins/pepper_error_util.cc b/webkit/glue/plugins/pepper_error_util.cc
index a1b5c06..895626a 100644
--- a/webkit/glue/plugins/pepper_error_util.cc
+++ b/webkit/glue/plugins/pepper_error_util.cc
@@ -17,6 +17,7 @@ int PlatformFileErrorToPepperError(base::PlatformFileError error_code) {
case base::PLATFORM_FILE_ERROR_NOT_FOUND:
return PP_ERROR_FILENOTFOUND;
case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
+ case base::PLATFORM_FILE_ERROR_SECURITY:
return PP_ERROR_NOACCESS;
case base::PLATFORM_FILE_ERROR_NO_MEMORY:
return PP_ERROR_NOMEMORY;
diff --git a/webkit/glue/plugins/pepper_file_callbacks.cc b/webkit/glue/plugins/pepper_file_callbacks.cc
new file mode 100644
index 0000000..3c52a0f
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_callbacks.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2010 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.
+
+#include "webkit/glue/plugins/pepper_file_callbacks.h"
+
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "third_party/ppapi/c/dev/ppb_file_system_dev.h"
+#include "third_party/ppapi/c/dev/pp_file_info_dev.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "webkit/glue/plugins/pepper_error_util.h"
+#include "webkit/glue/plugins/pepper_file_system.h"
+#include "webkit/fileapi/file_system_types.h"
+
+namespace pepper {
+
+FileCallbacks::FileCallbacks(const base::WeakPtr<PluginModule>& module,
+ PP_CompletionCallback callback,
+ PP_FileInfo_Dev* info,
+ scoped_refptr<FileSystem> file_system)
+ : module_(module),
+ callback_(callback),
+ info_(info),
+ file_system_(file_system) {
+}
+
+void FileCallbacks::DidSucceed() {
+ if (!module_.get() || !callback_.func)
+ return;
+
+ PP_RunCompletionCallback(&callback_, PP_OK);
+}
+
+void FileCallbacks::DidReadMetadata(
+ const base::PlatformFileInfo& file_info) {
+ if (!module_.get() || !callback_.func)
+ return;
+
+ DCHECK(info_);
+ DCHECK(file_system_);
+ info_->size = file_info.size;
+ info_->creation_time = file_info.creation_time.ToDoubleT();
+ info_->last_access_time = file_info.last_accessed.ToDoubleT();
+ info_->last_modified_time = file_info.last_modified.ToDoubleT();
+ info_->system_type = file_system_->type();
+ if (file_info.is_directory)
+ info_->type = PP_FILETYPE_DIRECTORY;
+ else
+ info_->type = PP_FILETYPE_REGULAR;
+
+ PP_RunCompletionCallback(&callback_, PP_OK);
+}
+
+void FileCallbacks::DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>&, bool) {
+ NOTREACHED();
+}
+
+void FileCallbacks::DidOpenFileSystem(const std::string&,
+ const FilePath& root_path) {
+ if (!module_.get() || !callback_.func)
+ return;
+
+ DCHECK(file_system_);
+ file_system_->set_root_path(root_path);
+ file_system_->set_opened(true);
+
+ PP_RunCompletionCallback(&callback_, PP_OK);
+}
+
+void FileCallbacks::DidFail(base::PlatformFileError error_code) {
+ RunCallback(error_code);
+}
+
+void FileCallbacks::DidWrite(int64 bytes, bool complete) {
+ NOTREACHED();
+}
+
+void FileCallbacks::RunCallback(base::PlatformFileError error_code) {
+ if (!module_.get() || !callback_.func)
+ return;
+
+ PP_RunCompletionCallback(
+ &callback_, pepper::PlatformFileErrorToPepperError(error_code));
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_callbacks.h b/webkit/glue/plugins/pepper_file_callbacks.h
new file mode 100644
index 0000000..407672e
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_callbacks.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2010 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.
+
+#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_FILE_CALLBACKS_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_CALLBACKS_H_
+
+#include "base/platform_file.h"
+#include "base/weak_ptr.h"
+#include "third_party/ppapi/c/pp_completion_callback.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
+
+struct PP_FileInfo_Dev;
+
+namespace base {
+class FilePath;
+}
+
+namespace pepper {
+
+class FileSystem;
+class PluginModule;
+
+// Instances of this class are deleted by FileSystemDispatcher.
+class FileCallbacks : public fileapi::FileSystemCallbackDispatcher {
+ public:
+ FileCallbacks(const base::WeakPtr<PluginModule>& module,
+ PP_CompletionCallback callback,
+ PP_FileInfo_Dev* info,
+ scoped_refptr<FileSystem> file_system);
+
+ // FileSystemCallbackDispatcher implementation.
+ virtual void DidSucceed();
+ virtual void DidReadMetadata(const base::PlatformFileInfo& file_info);
+ virtual void DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>&, bool);
+ virtual void DidOpenFileSystem(const std::string&,
+ const FilePath& root_path);
+ virtual void DidFail(base::PlatformFileError error_code);
+ virtual void DidWrite(int64 bytes, bool complete);
+
+ private:
+ void RunCallback(base::PlatformFileError error_code);
+
+ base::WeakPtr<pepper::PluginModule> module_;
+ PP_CompletionCallback callback_;
+ PP_FileInfo_Dev* info_;
+ scoped_refptr<FileSystem> file_system_;
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FILE_CALLBACKS_H_
diff --git a/webkit/glue/plugins/pepper_file_chooser.cc b/webkit/glue/plugins/pepper_file_chooser.cc
index 12b04a4..07524e9 100644
--- a/webkit/glue/plugins/pepper_file_chooser.cc
+++ b/webkit/glue/plugins/pepper_file_chooser.cc
@@ -119,8 +119,7 @@ void FileChooser::StoreChosenFiles(const std::vector<std::string>& files) {
std::vector<std::string>::const_iterator end_it = files.end();
for (std::vector<std::string>::const_iterator it = files.begin();
it != end_it; it++)
- chosen_files_.push_back(
- new FileRef(module(), PP_FILESYSTEMTYPE_LOCALPERSISTENT, *it, ""));
+ chosen_files_.push_back(new FileRef(module(), FilePath().AppendASCII(*it)));
if (!completion_callback_.func)
return;
diff --git a/webkit/glue/plugins/pepper_file_io.cc b/webkit/glue/plugins/pepper_file_io.cc
index 9d26899..b979ac2 100644
--- a/webkit/glue/plugins/pepper_file_io.cc
+++ b/webkit/glue/plugins/pepper_file_io.cc
@@ -225,12 +225,11 @@ int32_t FileIO::Open(FileRef* file_ref,
flags |= base::PLATFORM_FILE_WRITE;
flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES;
}
+
if (open_flags & PP_FILEOPENFLAG_TRUNCATE) {
- DCHECK(flags & PP_FILEOPENFLAG_WRITE);
+ DCHECK(open_flags & PP_FILEOPENFLAG_WRITE);
flags |= base::PLATFORM_FILE_TRUNCATE;
- }
-
- if (open_flags & PP_FILEOPENFLAG_CREATE) {
+ } else if (open_flags & PP_FILEOPENFLAG_CREATE) {
if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE)
flags |= base::PLATFORM_FILE_CREATE;
else
@@ -238,9 +237,9 @@ int32_t FileIO::Open(FileRef* file_ref,
} else
flags |= base::PLATFORM_FILE_OPEN;
- file_system_type_ = file_ref->file_system_type();
+ file_system_type_ = file_ref->GetFileSystemType();
if (!delegate_->AsyncOpenFile(
- file_ref->system_path(), flags,
+ file_ref->GetSystemPath(), flags,
callback_factory_.NewCallback(&FileIO::AsyncOpenFileCallback)))
return PP_ERROR_FAILED;
diff --git a/webkit/glue/plugins/pepper_file_io.h b/webkit/glue/plugins/pepper_file_io.h
index bda8ed6..9fa24ba 100644
--- a/webkit/glue/plugins/pepper_file_io.h
+++ b/webkit/glue/plugins/pepper_file_io.h
@@ -16,7 +16,6 @@
#include "webkit/glue/plugins/pepper_resource.h"
struct PP_CompletionCallback;
-struct PP_FileInfo_Dev;
struct PPB_FileIO_Dev;
struct PPB_FileIOTrusted_Dev;
diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc
index 5ff6f8e..0a64678 100644
--- a/webkit/glue/plugins/pepper_file_ref.cc
+++ b/webkit/glue/plugins/pepper_file_ref.cc
@@ -4,12 +4,14 @@
#include "webkit/glue/plugins/pepper_file_ref.h"
-#include "base/base_paths.h"
-#include "base/path_service.h"
#include "base/string_util.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "webkit/glue/plugins/pepper_file_callbacks.h"
+#include "webkit/glue/plugins/pepper_file_system.h"
+#include "webkit/glue/plugins/pepper_plugin_delegate.h"
#include "webkit/glue/plugins/pepper_plugin_instance.h"
+#include "webkit/glue/plugins/pepper_plugin_module.h"
#include "webkit/glue/plugins/pepper_var.h"
-#include "webkit/glue/plugins/pepper_resource_tracker.h"
namespace pepper {
@@ -34,35 +36,26 @@ void TrimTrailingSlash(std::string* path) {
path->erase(path->size() - 1, 1);
}
-PP_Resource CreateFileRef(PP_Instance instance_id,
- PP_FileSystemType_Dev fs_type,
- const char* path) {
- PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
- if (!instance)
+PP_Resource Create(PP_Resource file_system_id, const char* path) {
+ scoped_refptr<FileSystem> file_system(
+ Resource::GetAs<FileSystem>(file_system_id));
+ if (!file_system)
return 0;
- std::string origin; // TODO(darin): Extract from PluginInstance.
+ if (!file_system->instance())
+ return 0;
std::string validated_path(path);
if (!IsValidLocalPath(validated_path))
return 0;
TrimTrailingSlash(&validated_path);
- FileRef* file_ref = new FileRef(instance->module(),
- fs_type,
- validated_path,
- origin);
+ FileRef* file_ref = new FileRef(file_system->instance()->module(),
+ file_system,
+ validated_path);
return file_ref->GetReference();
}
-PP_Resource CreatePersistentFileRef(PP_Instance instance_id, const char* path) {
- return CreateFileRef(instance_id, PP_FILESYSTEMTYPE_LOCALPERSISTENT, path);
-}
-
-PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) {
- return CreateFileRef(instance_id, PP_FILESYSTEMTYPE_LOCALTEMPORARY, path);
-}
-
bool IsFileRef(PP_Resource resource) {
return !!Resource::GetAs<FileRef>(resource);
}
@@ -71,7 +64,7 @@ PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) {
scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
if (!file_ref)
return PP_FILESYSTEMTYPE_EXTERNAL;
- return file_ref->file_system_type();
+ return file_ref->GetFileSystemType();
}
PP_Var GetName(PP_Resource file_ref_id) {
@@ -86,10 +79,10 @@ PP_Var GetPath(PP_Resource file_ref_id) {
if (!file_ref)
return PP_MakeUndefined();
- if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
+ if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
return PP_MakeUndefined();
- return StringVar::StringToPPVar(file_ref->module(), file_ref->path());
+ return StringVar::StringToPPVar(file_ref->module(), file_ref->GetPath());
}
PP_Resource GetParent(PP_Resource file_ref_id) {
@@ -97,7 +90,7 @@ PP_Resource GetParent(PP_Resource file_ref_id) {
if (!file_ref)
return 0;
- if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
+ if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
return 0;
scoped_refptr<FileRef> parent_ref(file_ref->GetParent());
@@ -107,34 +100,158 @@ PP_Resource GetParent(PP_Resource file_ref_id) {
return parent_ref->GetReference();
}
+int32_t MakeDirectory(PP_Resource directory_ref_id,
+ bool make_ancestors,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileRef> directory_ref(
+ Resource::GetAs<FileRef>(directory_ref_id));
+ if (!directory_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileSystem> file_system = directory_ref->GetFileSystem();
+ if (!file_system || !file_system->opened() ||
+ (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL))
+ return PP_ERROR_NOACCESS;
+
+ PluginInstance* instance = file_system->instance();
+ if (!instance->delegate()->MakeDirectory(
+ directory_ref->GetSystemPath(), make_ancestors,
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, NULL, NULL)))
+ return PP_ERROR_FAILED;
+
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t Query(PP_Resource file_ref_id,
+ PP_FileInfo_Dev* info,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
+ if (!file_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem();
+ if (!file_system || !file_system->opened() ||
+ (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL))
+ return PP_ERROR_NOACCESS;
+
+ PluginInstance* instance = file_system->instance();
+ if (!instance->delegate()->Query(
+ file_ref->GetSystemPath(),
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, info, file_system)))
+ return PP_ERROR_FAILED;
+
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t Touch(PP_Resource file_ref_id,
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
+ if (!file_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem();
+ if (!file_system || !file_system->opened() ||
+ (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL))
+ return PP_ERROR_NOACCESS;
+
+ PluginInstance* instance = file_system->instance();
+ if (!instance->delegate()->Touch(
+ file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time),
+ base::Time::FromDoubleT(last_modified_time),
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, NULL, NULL)))
+ return PP_ERROR_FAILED;
+
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t Delete(PP_Resource file_ref_id,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
+ if (!file_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem();
+ if (!file_system || !file_system->opened() ||
+ (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL))
+ return PP_ERROR_NOACCESS;
+
+ PluginInstance* instance = file_system->instance();
+ if (!instance->delegate()->Delete(
+ file_ref->GetSystemPath(),
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, NULL, NULL)))
+ return PP_ERROR_FAILED;
+
+ return PP_ERROR_WOULDBLOCK;
+}
+
+int32_t Rename(PP_Resource file_ref_id,
+ PP_Resource new_file_ref_id,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
+ if (!file_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileRef> new_file_ref(
+ Resource::GetAs<FileRef>(new_file_ref_id));
+ if (!new_file_ref)
+ return PP_ERROR_BADRESOURCE;
+
+ scoped_refptr<FileSystem> file_system = file_ref->GetFileSystem();
+ if (!file_system || !file_system->opened() ||
+ (file_system != new_file_ref->GetFileSystem()) ||
+ (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL))
+ return PP_ERROR_NOACCESS;
+
+ PluginInstance* instance = file_system->instance();
+ if (!instance->delegate()->Rename(
+ file_ref->GetSystemPath(), new_file_ref->GetSystemPath(),
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, NULL, NULL)))
+ return PP_ERROR_FAILED;
+
+ return PP_ERROR_WOULDBLOCK;
+}
+
const PPB_FileRef_Dev ppb_fileref = {
- &CreatePersistentFileRef,
- &CreateTemporaryFileRef,
+ &Create,
&IsFileRef,
&GetFileSystemType,
&GetName,
&GetPath,
- &GetParent
+ &GetParent,
+ &MakeDirectory,
+ &Query,
+ &Touch,
+ &Delete,
+ &Rename
};
} // namespace
+FileRef::FileRef()
+ : Resource(NULL),
+ file_system_(NULL) {
+}
+
FileRef::FileRef(PluginModule* module,
- PP_FileSystemType_Dev file_system_type,
- const std::string& validated_path,
- const std::string& origin)
+ scoped_refptr<FileSystem> file_system,
+ const std::string& validated_path)
: Resource(module),
- fs_type_(file_system_type),
- path_(validated_path),
- origin_(origin) {
- // TODO(darin): Need to initialize system_path_.
+ file_system_(file_system),
+ virtual_path_(validated_path) {
}
FileRef::FileRef(PluginModule* module,
const FilePath& external_file_path)
: Resource(module),
- system_path_(external_file_path),
- fs_type_(PP_FILESYSTEMTYPE_EXTERNAL) {
+ file_system_(NULL),
+ system_path_(external_file_path) {
}
FileRef::~FileRef() {
@@ -146,48 +263,56 @@ const PPB_FileRef_Dev* FileRef::GetInterface() {
}
std::string FileRef::GetName() const {
- if (path_.size() == 1 && path_[0] == '/')
- return path_;
+ if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
+ return std::string();
+
+ if (virtual_path_.size() == 1 && virtual_path_[0] == '/')
+ return virtual_path_;
// There should always be a leading slash at least!
- size_t pos = path_.rfind('/');
+ size_t pos = virtual_path_.rfind('/');
DCHECK(pos != std::string::npos);
- return path_.substr(pos + 1);
+ return virtual_path_.substr(pos + 1);
}
scoped_refptr<FileRef> FileRef::GetParent() {
- if (path_.size() == 1 && path_[0] == '/')
- return this;
+ if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
+ return new FileRef();
// There should always be a leading slash at least!
- size_t pos = path_.rfind('/');
+ size_t pos = virtual_path_.rfind('/');
DCHECK(pos != std::string::npos);
// If the path is "/foo", then we want to include the slash.
if (pos == 0)
pos++;
- std::string parent_path = path_.substr(0, pos);
+ std::string parent_path = virtual_path_.substr(0, pos);
- FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_);
+ FileRef* parent_ref = new FileRef(module(), file_system_, parent_path);
return parent_ref;
}
-// static
-FileRef* FileRef::GetInaccessibleFileRef(PluginModule* module) {
- FilePath inaccessible_path;
- if (!PathService::Get(base::FILE_MODULE, &inaccessible_path))
- return NULL;
- return new FileRef(module, inaccessible_path);
+scoped_refptr<FileSystem> FileRef::GetFileSystem() const {
+ return file_system_;
}
-// static
-FileRef* FileRef::GetNonexistentFileRef(PluginModule* module) {
- FilePath dir_module_path;
- if (!PathService::Get(base::DIR_MODULE, &dir_module_path))
- return NULL;
- return new FileRef(module, dir_module_path.Append(
- FILE_PATH_LITERAL("nonexistent_file")));
+PP_FileSystemType_Dev FileRef::GetFileSystemType() const {
+ if (!file_system_)
+ return PP_FILESYSTEMTYPE_EXTERNAL;
+
+ return file_system_->type();
+}
+
+std::string FileRef::GetPath() const {
+ return virtual_path_;
+}
+
+FilePath FileRef::GetSystemPath() const {
+ if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
+ return system_path_;
+
+ return file_system_->root_path().AppendASCII(virtual_path_);
}
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_ref.h b/webkit/glue/plugins/pepper_file_ref.h
index 0ab0e65..4dd8826 100644
--- a/webkit/glue/plugins/pepper_file_ref.h
+++ b/webkit/glue/plugins/pepper_file_ref.h
@@ -13,14 +13,16 @@
namespace pepper {
+class FileSystem;
+class PluginInstance;
class PluginModule;
class FileRef : public Resource {
public:
+ FileRef();
FileRef(PluginModule* module,
- PP_FileSystemType_Dev file_system_type,
- const std::string& validated_path,
- const std::string& origin);
+ scoped_refptr<FileSystem> file_system,
+ const std::string& validated_path);
FileRef(PluginModule* module,
const FilePath& external_file_path);
virtual ~FileRef();
@@ -36,28 +38,23 @@ class FileRef : public Resource {
std::string GetName() const;
scoped_refptr<FileRef> GetParent();
- PP_FileSystemType_Dev file_system_type() const { return fs_type_; }
+ // Returns the file system to which this FileRef belongs.
+ scoped_refptr<FileSystem> GetFileSystem() const;
+
+ // Returns the type of the file system to which this FileRef belongs.
+ PP_FileSystemType_Dev GetFileSystemType() const;
// Returns the virtual path (i.e., the path that the pepper plugin sees)
// corresponding to this file.
- const std::string& path() const { return path_; }
+ std::string GetPath() const;
// Returns the system path corresponding to this file.
- const FilePath& system_path() const { return system_path_; }
-
- // Returns a FileRef instance pointing to a file that should not be
- // accessible by the plugin. Should be used for testing only.
- static FileRef* GetInaccessibleFileRef(PluginModule* module);
-
- // Returns a FileRef instance pointing to a nonexistent file.
- // Should be used for testing only.
- static FileRef* GetNonexistentFileRef(PluginModule* module);
+ FilePath GetSystemPath() const;
private:
+ scoped_refptr<FileSystem> file_system_;
+ std::string virtual_path_; // UTF-8 encoded
FilePath system_path_;
- PP_FileSystemType_Dev fs_type_;
- std::string path_; // UTF-8 encoded.
- std::string origin_;
};
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_system.cc b/webkit/glue/plugins/pepper_file_system.cc
index 6068ca5..ca62ac0 100644
--- a/webkit/glue/plugins/pepper_file_system.cc
+++ b/webkit/glue/plugins/pepper_file_system.cc
@@ -4,252 +4,79 @@
#include "webkit/glue/plugins/pepper_file_system.h"
-#include "base/logging.h"
#include "base/ref_counted.h"
-#include "base/weak_ptr.h"
#include "third_party/ppapi/c/dev/ppb_file_system_dev.h"
#include "third_party/ppapi/c/pp_completion_callback.h"
-#include "third_party/ppapi/c/pp_time.h"
-#include "webkit/fileapi/file_system_callback_dispatcher.h"
-#include "webkit/glue/plugins/pepper_resource.h"
-#include "webkit/glue/plugins/pepper_error_util.h"
-#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
+#include "webkit/fileapi/file_system_types.h"
+#include "webkit/glue/plugins/pepper_file_callbacks.h"
#include "webkit/glue/plugins/pepper_plugin_delegate.h"
#include "webkit/glue/plugins/pepper_plugin_instance.h"
#include "webkit/glue/plugins/pepper_plugin_module.h"
#include "webkit/glue/plugins/pepper_resource.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
namespace pepper {
namespace {
-// Instances of this class are deleted when RunCallback() is called.
-class StatusCallback : public fileapi::FileSystemCallbackDispatcher {
- public:
- StatusCallback(base::WeakPtr<pepper::PluginModule> module,
- PP_CompletionCallback callback)
- : module_(module),
- callback_(callback) {
- }
-
- // FileSystemCallbackDispatcher implementation.
- virtual void DidSucceed() {
- RunCallback(base::PLATFORM_FILE_OK);
- }
-
- virtual void DidReadMetadata(const base::PlatformFileInfo&) {
- NOTREACHED();
- }
-
- virtual void DidReadDirectory(
- const std::vector<base::file_util_proxy::Entry>&, bool) {
- NOTREACHED();
- }
-
- virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
- NOTREACHED();
- }
-
- virtual void DidFail(base::PlatformFileError error_code) {
- RunCallback(error_code);
- }
-
- virtual void DidWrite(int64 bytes, bool complete) {
- NOTREACHED();
- }
-
- private:
- void RunCallback(base::PlatformFileError error_code) {
- if (!module_.get() || !callback_.func)
- return;
-
- PP_RunCompletionCallback(
- &callback_, pepper::PlatformFileErrorToPepperError(error_code));
-
- delete this;
- }
-
- base::WeakPtr<pepper::PluginModule> module_;
- PP_CompletionCallback callback_;
-};
-
-// Instances of this class are deleted when RunCallback() is called.
-class QueryInfoCallback : public fileapi::FileSystemCallbackDispatcher {
- public:
- QueryInfoCallback(base::WeakPtr<pepper::PluginModule> module,
- PP_CompletionCallback callback,
- PP_FileInfo_Dev* info,
- PP_FileSystemType_Dev file_system_type)
- : module_(module),
- callback_(callback),
- info_(info),
- file_system_type_(file_system_type) {
- DCHECK(info_);
- }
-
- // FileSystemCallbackDispatcher implementation.
- virtual void DidSucceed() {
- NOTREACHED();
- }
-
- virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) {
- RunCallback(base::PLATFORM_FILE_OK, file_info);
- }
+PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) {
+ PluginInstance* plugin_instance =
+ ResourceTracker::Get()->GetInstance(instance);
+ if (!plugin_instance)
+ return 0;
- virtual void DidReadDirectory(
- const std::vector<base::file_util_proxy::Entry>&, bool) {
- NOTREACHED();
- }
-
- virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
- NOTREACHED();
- }
-
- virtual void DidFail(base::PlatformFileError error_code) {
- RunCallback(error_code, base::PlatformFileInfo());
- }
-
- virtual void DidWrite(int64 bytes, bool complete) {
- NOTREACHED();
- }
-
- private:
- void RunCallback(base::PlatformFileError error_code,
- const base::PlatformFileInfo& file_info) {
- if (!module_.get() || !callback_.func)
- return;
-
- if (error_code == base::PLATFORM_FILE_OK) {
- info_->size = file_info.size;
- info_->creation_time = file_info.creation_time.ToDoubleT();
- info_->last_access_time = file_info.last_accessed.ToDoubleT();
- info_->last_modified_time = file_info.last_modified.ToDoubleT();
- info_->system_type = file_system_type_;
- if (file_info.is_directory)
- info_->type = PP_FILETYPE_DIRECTORY;
- else
- info_->type = PP_FILETYPE_REGULAR;
- }
- PP_RunCompletionCallback(
- &callback_, pepper::PlatformFileErrorToPepperError(error_code));
-
- delete this;
- }
-
- base::WeakPtr<pepper::PluginModule> module_;
- PP_CompletionCallback callback_;
- PP_FileInfo_Dev* info_;
- PP_FileSystemType_Dev file_system_type_;
-};
-
-int32_t MakeDirectory(PP_Resource directory_ref_id,
- bool make_ancestors,
- PP_CompletionCallback callback) {
- scoped_refptr<FileRef> directory_ref(
- Resource::GetAs<FileRef>(directory_ref_id));
- if (!directory_ref)
- return PP_ERROR_BADRESOURCE;
-
- if (directory_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
- return PP_ERROR_FAILED;
-
- PluginModule* module = directory_ref->module();
- if (!module->GetSomeInstance()->delegate()->MakeDirectory(
- directory_ref->system_path(), make_ancestors,
- new StatusCallback(module->AsWeakPtr(), callback)))
- return PP_ERROR_FAILED;
-
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t Query(PP_Resource file_ref_id,
- PP_FileInfo_Dev* info,
- PP_CompletionCallback callback) {
- scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
- if (!file_ref)
- return PP_ERROR_BADRESOURCE;
-
- PluginModule* module = file_ref->module();
- if (!module->GetSomeInstance()->delegate()->Query(
- file_ref->system_path(),
- new QueryInfoCallback(module->AsWeakPtr(), callback,
- info, file_ref->file_system_type())))
- return PP_ERROR_FAILED;
-
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t Touch(PP_Resource file_ref_id,
- PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) {
- scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
- if (!file_ref)
- return PP_ERROR_BADRESOURCE;
-
- PluginModule* module = file_ref->module();
- if (!module->GetSomeInstance()->delegate()->Touch(
- file_ref->system_path(), base::Time::FromDoubleT(last_access_time),
- base::Time::FromDoubleT(last_modified_time),
- new StatusCallback(module->AsWeakPtr(), callback)))
- return PP_ERROR_FAILED;
-
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t Delete(PP_Resource file_ref_id,
- PP_CompletionCallback callback) {
- scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
- if (!file_ref)
- return PP_ERROR_BADRESOURCE;
-
- if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
- return PP_ERROR_FAILED;
-
- PluginModule* module = file_ref->module();
- if (!module->GetSomeInstance()->delegate()->Delete(
- file_ref->system_path(),
- new StatusCallback(module->AsWeakPtr(), callback)))
- return PP_ERROR_FAILED;
-
- return PP_ERROR_WOULDBLOCK;
+ FileSystem* file_system = new FileSystem(plugin_instance, type);
+ return file_system->GetReference();
}
-int32_t Rename(PP_Resource file_ref_id,
- PP_Resource new_file_ref_id,
- PP_CompletionCallback callback) {
- scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
- if (!file_ref)
+int32_t Open(PP_Resource file_system_id,
+ long long expected_size,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileSystem> file_system(
+ Resource::GetAs<FileSystem>(file_system_id));
+ if (!file_system)
return PP_ERROR_BADRESOURCE;
- scoped_refptr<FileRef> new_file_ref(
- Resource::GetAs<FileRef>(new_file_ref_id));
- if (!new_file_ref)
- return PP_ERROR_BADRESOURCE;
+ if (file_system->opened())
+ return PP_OK;
- if ((file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) ||
- (file_ref->file_system_type() != new_file_ref->file_system_type()))
+ if ((file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) &&
+ (file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY))
return PP_ERROR_FAILED;
- PluginModule* module = file_ref->module();
- if (!module->GetSomeInstance()->delegate()->Rename(
- file_ref->system_path(), new_file_ref->system_path(),
- new StatusCallback(module->AsWeakPtr(), callback)))
+ PluginInstance* instance = file_system->instance();
+ fileapi::FileSystemType file_system_type =
+ (file_system->type() == PP_FILESYSTEMTYPE_LOCALTEMPORARY ?
+ fileapi::kFileSystemTypeTemporary :
+ fileapi::kFileSystemTypePersistent);
+ if (!instance->delegate()->OpenFileSystem(
+ instance->container()->element().document().frame()->url(),
+ file_system_type, expected_size,
+ new FileCallbacks(instance->module()->AsWeakPtr(),
+ callback, NULL, file_system)))
return PP_ERROR_FAILED;
return PP_ERROR_WOULDBLOCK;
}
const PPB_FileSystem_Dev ppb_filesystem = {
- &MakeDirectory,
- &Query,
- &Touch,
- &Delete,
- &Rename
+ &Create,
+ &Open
};
} // namespace
+FileSystem::FileSystem(PluginInstance* instance, PP_FileSystemType_Dev type)
+ : Resource(instance->module()),
+ instance_(instance),
+ type_(type),
+ opened_(false) {
+}
+
const PPB_FileSystem_Dev* FileSystem::GetInterface() {
return &ppb_filesystem;
}
diff --git a/webkit/glue/plugins/pepper_file_system.h b/webkit/glue/plugins/pepper_file_system.h
index 1abfc52..f883299 100644
--- a/webkit/glue/plugins/pepper_file_system.h
+++ b/webkit/glue/plugins/pepper_file_system.h
@@ -6,19 +6,37 @@
#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_SYSTEM_H_
#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "third_party/ppapi/c/dev/pp_file_info_dev.h"
+#include "webkit/glue/plugins/pepper_resource.h"
struct PPB_FileSystem_Dev;
namespace pepper {
-class FileSystem {
+class PluginInstance;
+
+class FileSystem : public Resource {
public:
// Returns a pointer to the interface implementing PPB_FileSystem that is
// exposed to the plugin.
static const PPB_FileSystem_Dev* GetInterface();
+ FileSystem(PluginInstance* instance, PP_FileSystemType_Dev type);
+ FileSystem* AsFileSystem() { return this; }
+
+ PluginInstance* instance() { return instance_; }
+ PP_FileSystemType_Dev type() { return type_; }
+ 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; }
+
private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystem);
+ PluginInstance* instance_;
+ PP_FileSystemType_Dev type_;
+ FilePath root_path_;
+ bool opened_;
};
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_plugin_delegate.h b/webkit/glue/plugins/pepper_plugin_delegate.h
index 7558a2c..7738fbf 100644
--- a/webkit/glue/plugins/pepper_plugin_delegate.h
+++ b/webkit/glue/plugins/pepper_plugin_delegate.h
@@ -13,9 +13,11 @@
#include "base/shared_memory.h"
#include "base/sync_socket.h"
#include "base/task.h"
+#include "googleurl/src/gurl.h"
#include "third_party/ppapi/c/pp_completion_callback.h"
#include "third_party/ppapi/c/pp_errors.h"
#include "third_party/ppapi/c/pp_stdint.h"
+#include "webkit/fileapi/file_system_types.h"
#include "webkit/glue/plugins/pepper_dir_contents.h"
class AudioMessageFilter;
@@ -176,6 +178,11 @@ class PluginDelegate {
virtual bool AsyncOpenFile(const FilePath& path,
int flags,
AsyncOpenFileCallback* callback) = 0;
+ virtual bool OpenFileSystem(
+ const GURL& url,
+ fileapi::FileSystemType type,
+ long long size,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
virtual bool MakeDirectory(
const FilePath& path,
bool recursive,
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc
index d54eaa1..13390d5 100644
--- a/webkit/glue/plugins/pepper_plugin_module.cc
+++ b/webkit/glue/plugins/pepper_plugin_module.cc
@@ -185,27 +185,11 @@ uint32_t GetLiveObjectCount(PP_Module module_id) {
return ResourceTracker::Get()->GetLiveObjectsForModule(module);
}
-PP_Resource GetInaccessibleFileRef(PP_Module module_id) {
- PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
- if (!module)
- return static_cast<uint32_t>(-1);
- return FileRef::GetInaccessibleFileRef(module)->GetReference();
-}
-
-PP_Resource GetNonexistentFileRef(PP_Module module_id) {
- PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
- if (!module)
- return static_cast<uint32_t>(-1);
- return FileRef::GetNonexistentFileRef(module)->GetReference();
-}
-
const PPB_Testing_Dev testing_interface = {
&ReadImageData,
&RunMessageLoop,
&QuitMessageLoop,
- &GetLiveObjectCount,
- &GetInaccessibleFileRef,
- &GetNonexistentFileRef
+ &GetLiveObjectCount
};
// GetInterface ----------------------------------------------------------------
diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h
index e920ab1..a0685a2 100644
--- a/webkit/glue/plugins/pepper_resource.h
+++ b/webkit/glue/plugins/pepper_resource.h
@@ -14,13 +14,10 @@ namespace pepper {
// If you inherit from resource, make sure you add the class name here.
#define FOR_ALL_RESOURCES(F) \
- F(Audio) \
- F(Buffer) \
- F(AudioConfig) \
- F(DirectoryReader) \
F(FileChooser) \
F(FileIO) \
F(FileRef) \
+ F(FileSystem) \
F(Font) \
F(Graphics2D) \
F(Graphics3D) \
@@ -92,7 +89,6 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER)
#undef DEFINE_TYPE_GETTER
-
private:
// If referenced by a plugin, holds the id of this resource object. Do not
// access this member directly, because it is possible that the plugin holds
@@ -118,6 +114,7 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
template <> inline Type* Resource::Cast<Type>() { \
return As##Type(); \
}
+
FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST)
#undef DEFINE_RESOURCE_CAST
diff --git a/webkit/glue/plugins/pepper_url_request_info.cc b/webkit/glue/plugins/pepper_url_request_info.cc
index 45ae2d6..dd8f7a6 100644
--- a/webkit/glue/plugins/pepper_url_request_info.cc
+++ b/webkit/glue/plugins/pepper_url_request_info.cc
@@ -238,7 +238,8 @@ WebURLRequest URLRequestInfo::ToWebURLRequest(WebFrame* frame) const {
for (size_t i = 0; i < body_.size(); ++i) {
if (body_[i].file_ref) {
http_body.appendFileRange(
- webkit_glue::FilePathToWebString(body_[i].file_ref->system_path()),
+ webkit_glue::FilePathToWebString(
+ body_[i].file_ref->GetSystemPath()),
body_[i].start_offset,
body_[i].number_of_bytes,
body_[i].expected_last_modified_time);