summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-26 19:56:31 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-26 19:56:31 +0000
commit21ca7bf8f06e3b6e608f26eed8dce30515721b86 (patch)
treefc05f8fdf597babb2bff70dd8ceecd4bb7aa0a19 /webkit
parent1c8857bce13d0fb7a7ee8f12c154a2392afe00a2 (diff)
downloadchromium_src-21ca7bf8f06e3b6e608f26eed8dce30515721b86.zip
chromium_src-21ca7bf8f06e3b6e608f26eed8dce30515721b86.tar.gz
chromium_src-21ca7bf8f06e3b6e608f26eed8dce30515721b86.tar.bz2
File API boilerplate.
R=brettw BUG=41774 TEST=none Review URL: http://codereview.chromium.org/2822031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50939 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/pepper_directory_reader.cc69
-rw-r--r--webkit/glue/plugins/pepper_directory_reader.h37
-rw-r--r--webkit/glue/plugins/pepper_file_chooser.cc90
-rw-r--r--webkit/glue/plugins/pepper_file_chooser.h40
-rw-r--r--webkit/glue/plugins/pepper_file_io.cc268
-rw-r--r--webkit/glue/plugins/pepper_file_io.h69
-rw-r--r--webkit/glue/plugins/pepper_file_ref.cc175
-rw-r--r--webkit/glue/plugins/pepper_file_ref.h47
-rw-r--r--webkit/glue/plugins/pepper_file_system.cc59
-rw-r--r--webkit/glue/plugins/pepper_file_system.h21
-rw-r--r--webkit/glue/plugins/pepper_plugin_module.cc17
-rw-r--r--webkit/glue/plugins/pepper_resource.h10
-rw-r--r--webkit/glue/plugins/pepper_resource_tracker.cc68
-rw-r--r--webkit/glue/plugins/pepper_resource_tracker.h10
-rw-r--r--webkit/glue/plugins/pepper_var.cc5
-rw-r--r--webkit/glue/plugins/pepper_var.h6
-rw-r--r--webkit/glue/webkit_glue.gypi10
17 files changed, 953 insertions, 48 deletions
diff --git a/webkit/glue/plugins/pepper_directory_reader.cc b/webkit/glue/plugins/pepper_directory_reader.cc
new file mode 100644
index 0000000..3abaa40
--- /dev/null
+++ b/webkit/glue/plugins/pepper_directory_reader.cc
@@ -0,0 +1,69 @@
+// 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_directory_reader.h"
+
+#include "base/logging.h"
+#include "third_party/ppapi/c/pp_completion_callback.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
+
+namespace pepper {
+
+namespace {
+
+PP_Resource Create(PP_Resource directory_ref_id) {
+ scoped_refptr<FileRef> directory_ref(
+ ResourceTracker::Get()->GetAsFileRef(directory_ref_id));
+ if (!directory_ref.get())
+ return 0;
+
+ DirectoryReader* reader = new DirectoryReader(directory_ref);
+ reader->AddRef(); // AddRef for the caller;
+ return reader->GetResource();
+}
+
+bool IsDirectoryReader(PP_Resource resource) {
+ return !!ResourceTracker::Get()->GetAsDirectoryReader(resource).get();
+}
+
+int32_t GetNextEntry(PP_Resource reader_id,
+ PP_DirectoryEntry* entry,
+ PP_CompletionCallback callback) {
+ scoped_refptr<DirectoryReader> reader(
+ ResourceTracker::Get()->GetAsDirectoryReader(reader_id));
+ if (!reader.get())
+ return PP_Error_BadResource;
+
+ return reader->GetNextEntry(entry, callback);
+}
+
+const PPB_DirectoryReader ppb_directoryreader = {
+ &Create,
+ &IsDirectoryReader,
+ &GetNextEntry
+};
+
+} // namespace
+
+DirectoryReader::DirectoryReader(FileRef* directory_ref)
+ : Resource(directory_ref->module()),
+ directory_ref_(directory_ref) {
+}
+
+DirectoryReader::~DirectoryReader() {
+}
+
+const PPB_DirectoryReader* DirectoryReader::GetInterface() {
+ return &ppb_directoryreader;
+}
+
+int32_t DirectoryReader::GetNextEntry(PP_DirectoryEntry* entry,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_directory_reader.h b/webkit/glue/plugins/pepper_directory_reader.h
new file mode 100644
index 0000000..c477a3e
--- /dev/null
+++ b/webkit/glue/plugins/pepper_directory_reader.h
@@ -0,0 +1,37 @@
+// 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_DIRECTORY_READER_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_DIRECTORY_READER_H_
+
+#include "third_party/ppapi/c/ppb_directory_reader.h"
+#include "webkit/glue/plugins/pepper_resource.h"
+
+namespace pepper {
+
+class FileRef;
+
+class DirectoryReader : public Resource {
+ public:
+ explicit DirectoryReader(FileRef* directory_ref);
+ virtual ~DirectoryReader();
+
+ // Returns a pointer to the interface implementing PPB_DirectoryReader that
+ // is exposed to the plugin.
+ static const PPB_DirectoryReader* GetInterface();
+
+ // Resource overrides.
+ DirectoryReader* AsDirectoryReader() { return this; }
+
+ // PPB_DirectoryReader implementation.
+ int32_t GetNextEntry(PP_DirectoryEntry* entry,
+ PP_CompletionCallback callback);
+
+ private:
+ scoped_refptr<FileRef> directory_ref_;
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_DIRECTORY_READER_H_
diff --git a/webkit/glue/plugins/pepper_file_chooser.cc b/webkit/glue/plugins/pepper_file_chooser.cc
new file mode 100644
index 0000000..8a5e2b0
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_chooser.cc
@@ -0,0 +1,90 @@
+// 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_chooser.h"
+
+#include "base/logging.h"
+#include "third_party/ppapi/c/pp_completion_callback.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "webkit/glue/plugins/pepper_plugin_instance.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
+
+namespace pepper {
+
+namespace {
+
+PP_Resource Create(PP_Instance instance_id,
+ const PP_FileChooserOptions* options) {
+ PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ if (!instance)
+ return 0;
+
+ FileChooser* chooser = new FileChooser(instance, options);
+ chooser->AddRef(); // AddRef for the caller.
+ return chooser->GetResource();
+}
+
+bool IsFileChooser(PP_Resource resource) {
+ return !!ResourceTracker::Get()->GetAsFileChooser(resource).get();
+}
+
+int32_t Show(PP_Resource chooser_id, PP_CompletionCallback callback) {
+ scoped_refptr<FileChooser> chooser(
+ ResourceTracker::Get()->GetAsFileChooser(chooser_id).get());
+ if (!chooser.get())
+ return PP_Error_BadResource;
+
+ return chooser->Show(callback);
+}
+
+PP_Resource GetNextChosenFile(PP_Resource chooser_id) {
+ scoped_refptr<FileChooser> chooser(
+ ResourceTracker::Get()->GetAsFileChooser(chooser_id).get());
+ if (!chooser.get())
+ return 0;
+
+ scoped_refptr<FileRef> file_ref(chooser->GetNextChosenFile());
+ if (!file_ref.get())
+ return 0;
+ file_ref->AddRef(); // AddRef for the caller.
+
+ return file_ref->GetResource();
+}
+
+const PPB_FileChooser ppb_filechooser = {
+ &Create,
+ &IsFileChooser,
+ &Show,
+ &GetNextChosenFile
+};
+
+} // namespace
+
+FileChooser::FileChooser(PluginInstance* instance,
+ const PP_FileChooserOptions* options)
+ : Resource(instance->module()),
+ mode_(options->mode),
+ accept_mime_types_(options->accept_mime_types) {
+}
+
+FileChooser::~FileChooser() {
+}
+
+// static
+const PPB_FileChooser* FileChooser::GetInterface() {
+ return &ppb_filechooser;
+}
+
+int32_t FileChooser::Show(PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+scoped_refptr<FileRef> FileChooser::GetNextChosenFile() {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return NULL;
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_chooser.h b/webkit/glue/plugins/pepper_file_chooser.h
new file mode 100644
index 0000000..8474188
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_chooser.h
@@ -0,0 +1,40 @@
+// 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_CHOOSER_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_CHOOSER_H_
+
+#include <string>
+
+#include "third_party/ppapi/c/ppb_file_chooser.h"
+#include "webkit/glue/plugins/pepper_resource.h"
+
+namespace pepper {
+
+class PluginInstance;
+
+class FileChooser : public Resource {
+ public:
+ FileChooser(PluginInstance* instance, const PP_FileChooserOptions* options);
+ virtual ~FileChooser();
+
+ // Returns a pointer to the interface implementing PPB_FileChooser that is
+ // exposed to the plugin.
+ static const PPB_FileChooser* GetInterface();
+
+ // Resource overrides.
+ FileChooser* AsFileChooser() { return this; }
+
+ // PPB_FileChooser implementation.
+ int32_t Show(PP_CompletionCallback callback);
+ scoped_refptr<FileRef> GetNextChosenFile();
+
+ private:
+ PP_FileChooserMode mode_;
+ std::string accept_mime_types_;
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FILE_CHOOSER_H_
diff --git a/webkit/glue/plugins/pepper_file_io.cc b/webkit/glue/plugins/pepper_file_io.cc
new file mode 100644
index 0000000..72ffc12
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_io.cc
@@ -0,0 +1,268 @@
+// 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_io.h"
+
+#include "base/logging.h"
+#include "third_party/ppapi/c/pp_completion_callback.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "third_party/ppapi/c/ppb_file_io.h"
+#include "third_party/ppapi/c/ppb_file_io_trusted.h"
+#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "webkit/glue/plugins/pepper_plugin_module.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
+
+namespace pepper {
+
+namespace {
+
+PP_Resource Create(PP_Module module_id) {
+ PluginModule* module = PluginModule::FromPPModule(module_id);
+ if (!module)
+ return 0;
+
+ FileIO* file_io = new FileIO(module);
+ file_io->AddRef(); // AddRef for the caller.
+ return file_io->GetResource();
+}
+
+bool IsFileIO(PP_Resource resource) {
+ return !!ResourceTracker::Get()->GetAsFileIO(resource).get();
+}
+
+int32_t Open(PP_Resource file_io_id,
+ PP_Resource file_ref_id,
+ int32_t open_flags,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ scoped_refptr<FileRef> file_ref(
+ ResourceTracker::Get()->GetAsFileRef(file_ref_id));
+ if (!file_ref.get())
+ return PP_Error_BadResource;
+
+ return file_io->Open(file_ref, open_flags, callback);
+}
+
+int32_t Query(PP_Resource file_io_id,
+ PP_FileInfo* info,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->Query(info, callback);
+}
+
+int32_t Touch(PP_Resource file_io_id,
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->Touch(last_access_time, last_modified_time, callback);
+}
+
+int32_t Read(PP_Resource file_io_id,
+ int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->Read(offset, buffer, bytes_to_read, callback);
+}
+
+int32_t Write(PP_Resource file_io_id,
+ int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->Write(offset, buffer, bytes_to_write, callback);
+}
+
+int32_t SetLength(PP_Resource file_io_id,
+ int64_t length,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->SetLength(length, callback);
+}
+
+int32_t Flush(PP_Resource file_io_id,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->Flush(callback);
+}
+
+void Close(PP_Resource file_io_id) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return;
+
+ file_io->Close();
+}
+
+const PPB_FileIO ppb_fileio = {
+ &Create,
+ &IsFileIO,
+ &Open,
+ &Query,
+ &Touch,
+ &Read,
+ &Write,
+ &SetLength,
+ &Flush,
+ &Close
+};
+
+int32_t GetOSFileDescriptor(PP_Resource file_io_id) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->GetOSFileDescriptor();
+}
+
+int32_t WillWrite(PP_Resource file_io_id,
+ int64_t offset,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->WillWrite(offset, bytes_to_write, callback);
+}
+
+int32_t WillSetLength(PP_Resource file_io_id,
+ int64_t length,
+ PP_CompletionCallback callback) {
+ scoped_refptr<FileIO> file_io(
+ ResourceTracker::Get()->GetAsFileIO(file_io_id));
+ if (!file_io.get())
+ return PP_Error_BadResource;
+
+ return file_io->WillSetLength(length, callback);
+}
+
+const PPB_FileIOTrusted ppb_fileiotrusted = {
+ &GetOSFileDescriptor,
+ &WillWrite,
+ &WillSetLength
+};
+
+} // namespace
+
+FileIO::FileIO(PluginModule* module) : Resource(module) {
+}
+
+FileIO::~FileIO() {
+}
+
+// static
+const PPB_FileIO* FileIO::GetInterface() {
+ return &ppb_fileio;
+}
+
+// static
+const PPB_FileIOTrusted* FileIO::GetTrustedInterface() {
+ return &ppb_fileiotrusted;
+}
+
+int32_t FileIO::Open(FileRef* file_ref,
+ int32_t open_flags,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::Query(PP_FileInfo* info,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::Touch(PP_Time last_access_time,
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::Read(int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::Write(int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::SetLength(int64_t length,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::Flush(PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+void FileIO::Close() {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+}
+
+int32_t FileIO::GetOSFileDescriptor() {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::WillWrite(int64_t offset,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+int32_t FileIO::WillSetLength(int64_t length,
+ PP_CompletionCallback callback) {
+ NOTIMPLEMENTED(); // TODO(darin): Implement me!
+ return PP_Error_Failed;
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_io.h b/webkit/glue/plugins/pepper_file_io.h
new file mode 100644
index 0000000..4af6f2b
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_io.h
@@ -0,0 +1,69 @@
+// 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_IO_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_IO_H_
+
+#include "third_party/ppapi/c/pp_time.h"
+#include "webkit/glue/plugins/pepper_resource.h"
+
+typedef struct _pp_CompletionCallback PP_CompletionCallback;
+typedef struct _pp_FileInfo PP_FileInfo;
+typedef struct _ppb_FileIO PPB_FileIO;
+typedef struct _ppb_FileIOTrusted PPB_FileIOTrusted;
+
+namespace pepper {
+
+class PluginModule;
+
+class FileIO : public Resource {
+ public:
+ explicit FileIO(PluginModule* module);
+ virtual ~FileIO();
+
+ // Returns a pointer to the interface implementing PPB_FileIO that is exposed
+ // to the plugin.
+ static const PPB_FileIO* GetInterface();
+
+ // Returns a pointer to the interface implementing PPB_FileIOTrusted that is
+ // exposed to the plugin.
+ static const PPB_FileIOTrusted* GetTrustedInterface();
+
+ // Resource overrides.
+ FileIO* AsFileIO() { return this; }
+
+ // PPB_FileIO implementation.
+ int32_t Open(FileRef* file_ref,
+ int32_t open_flags,
+ PP_CompletionCallback callback);
+ int32_t Query(PP_FileInfo* info,
+ PP_CompletionCallback callback);
+ int32_t Touch(PP_Time last_access_time,
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback);
+ int32_t Read(int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ PP_CompletionCallback callback);
+ int32_t Write(int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback);
+ int32_t SetLength(int64_t length,
+ PP_CompletionCallback callback);
+ int32_t Flush(PP_CompletionCallback callback);
+ void Close();
+
+ // PPB_FileIOTrusted implementation.
+ int32_t GetOSFileDescriptor();
+ int32_t WillWrite(int64_t offset,
+ int32_t bytes_to_write,
+ PP_CompletionCallback callback);
+ int32_t WillSetLength(int64_t length,
+ PP_CompletionCallback callback);
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FILE_IO_H_
diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc
new file mode 100644
index 0000000..e014ff6
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_ref.cc
@@ -0,0 +1,175 @@
+// 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_ref.h"
+
+#include "base/string_util.h"
+#include "webkit/glue/plugins/pepper_plugin_instance.h"
+#include "webkit/glue/plugins/pepper_var.h"
+#include "webkit/glue/plugins/pepper_resource_tracker.h"
+
+namespace pepper {
+
+namespace {
+
+bool IsValidLocalPath(const std::string& path) {
+ // The path must start with '/'
+ if (path.empty() || path[0] != '/')
+ return false;
+
+ // The path must contain valid UTF-8 characters.
+ if (!IsStringUTF8(path))
+ return false;
+
+ return true;
+}
+
+void TrimTrailingSlash(std::string* path) {
+ // If this path ends with a slash, then normalize it away unless path is the
+ // root path.
+ if (path->size() > 1 && path->at(path->size() - 1) == '/')
+ path->erase(path->size() - 1, 1);
+}
+
+PP_Resource CreateFileRef(PP_Instance instance_id,
+ PP_FileSystemType fs_type,
+ const char* path) {
+ PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ if (!instance)
+ return 0;
+
+ std::string origin; // TODO(darin): Extract from PluginInstance.
+
+ 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);
+ file_ref->AddRef(); // AddRef for the caller.
+ return file_ref->GetResource();
+}
+
+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 !!ResourceTracker::Get()->GetAsFileRef(resource).get();
+}
+
+PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) {
+ scoped_refptr<FileRef> file_ref(
+ ResourceTracker::Get()->GetAsFileRef(file_ref_id));
+ if (!file_ref.get())
+ return PP_FileSystemType_External;
+
+ return file_ref->file_system_type();
+}
+
+PP_Var GetName(PP_Resource file_ref_id) {
+ scoped_refptr<FileRef> file_ref(
+ ResourceTracker::Get()->GetAsFileRef(file_ref_id));
+ if (!file_ref.get())
+ return PP_MakeVoid();
+
+ return StringToPPVar(file_ref->GetName());
+}
+
+PP_Var GetPath(PP_Resource file_ref_id) {
+ scoped_refptr<FileRef> file_ref(
+ ResourceTracker::Get()->GetAsFileRef(file_ref_id));
+ if (!file_ref.get())
+ return PP_MakeVoid();
+
+ if (file_ref->file_system_type() == PP_FileSystemType_External)
+ return PP_MakeVoid();
+
+ return StringToPPVar(file_ref->path());
+}
+
+PP_Resource GetParent(PP_Resource file_ref_id) {
+ scoped_refptr<FileRef> file_ref(
+ ResourceTracker::Get()->GetAsFileRef(file_ref_id));
+ if (!file_ref.get())
+ return 0;
+
+ if (file_ref->file_system_type() == PP_FileSystemType_External)
+ return 0;
+
+ scoped_refptr<FileRef> parent_ref(file_ref->GetParent());
+ if (!parent_ref.get())
+ return 0;
+ parent_ref->AddRef(); // AddRef for the caller.
+
+ return parent_ref->GetResource();
+}
+
+const PPB_FileRef ppb_fileref = {
+ &CreatePersistentFileRef,
+ &CreateTemporaryFileRef,
+ &IsFileRef,
+ &GetFileSystemType,
+ &GetName,
+ &GetPath,
+ &GetParent
+};
+
+} // namespace
+
+FileRef::FileRef(PluginModule* module,
+ PP_FileSystemType file_system_type,
+ const std::string& validated_path,
+ const std::string& origin)
+ : Resource(module),
+ fs_type_(file_system_type),
+ path_(validated_path),
+ origin_(origin) {
+}
+
+FileRef::~FileRef() {
+}
+
+// static
+const PPB_FileRef* FileRef::GetInterface() {
+ return &ppb_fileref;
+}
+
+std::string FileRef::GetName() const {
+ if (path_.size() == 1 && path_[0] == '/')
+ return path_;
+
+ // There should always be a leading slash at least!
+ size_t pos = path_.rfind('/');
+ DCHECK(pos != std::string::npos);
+
+ return path_.substr(pos + 1);
+}
+
+scoped_refptr<FileRef> FileRef::GetParent() {
+ if (path_.size() == 1 && path_[0] == '/')
+ return this;
+
+ // There should always be a leading slash at least!
+ size_t pos = 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);
+
+ FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_);
+ parent_ref->AddRef(); // AddRef for the caller.
+ return parent_ref;
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_ref.h b/webkit/glue/plugins/pepper_file_ref.h
new file mode 100644
index 0000000..b43cba5
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_ref.h
@@ -0,0 +1,47 @@
+// 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_REF_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_REF_H_
+
+#include <string>
+
+#include "third_party/ppapi/c/ppb_file_ref.h"
+#include "webkit/glue/plugins/pepper_resource.h"
+
+namespace pepper {
+
+class PluginModule;
+
+class FileRef : public Resource {
+ public:
+ FileRef(PluginModule* module,
+ PP_FileSystemType file_system_type,
+ const std::string& validated_path,
+ const std::string& origin);
+ virtual ~FileRef();
+
+ // Returns a pointer to the interface implementing PPB_FileRef that is
+ // exposed to the plugin.
+ static const PPB_FileRef* GetInterface();
+
+ // Resource overrides.
+ FileRef* AsFileRef() { return this; }
+
+ // PPB_FileRef implementation.
+ std::string GetName() const;
+ scoped_refptr<FileRef> GetParent();
+
+ PP_FileSystemType file_system_type() const { return fs_type_; }
+ const std::string& path() const { return path_; }
+
+ private:
+ PP_FileSystemType fs_type_;
+ std::string path_; // UTF-8 encoded.
+ std::string origin_;
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FILE_REF_H_
diff --git a/webkit/glue/plugins/pepper_file_system.cc b/webkit/glue/plugins/pepper_file_system.cc
new file mode 100644
index 0000000..f9dcc0f
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_system.cc
@@ -0,0 +1,59 @@
+// 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_system.h"
+
+#include "third_party/ppapi/c/pp_completion_callback.h"
+#include "third_party/ppapi/c/pp_errors.h"
+#include "third_party/ppapi/c/ppb_file_system.h"
+
+namespace pepper {
+
+namespace {
+
+int32_t MakeDirectory(PP_Resource directory_ref,
+ bool make_ancestors,
+ PP_CompletionCallback callback) {
+ return PP_Error_Failed; // TODO(darin): Implement me!
+}
+
+int32_t Query(PP_Resource file_ref,
+ PP_FileInfo* info,
+ PP_CompletionCallback callback) {
+ return PP_Error_Failed; // TODO(darin): Implement me!
+}
+
+int32_t Touch(PP_Resource file_ref,
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ PP_CompletionCallback callback) {
+ return PP_Error_Failed; // TODO(darin): Implement me!
+}
+
+int32_t Delete(PP_Resource file_ref,
+ PP_CompletionCallback callback) {
+ return PP_Error_Failed; // TODO(darin): Implement me!
+}
+
+int32_t Rename(PP_Resource file_ref,
+ PP_Resource new_file_ref,
+ PP_CompletionCallback callback) {
+ return PP_Error_Failed; // TODO(darin): Implement me!
+}
+
+const PPB_FileSystem ppb_filesystem = {
+ &MakeDirectory,
+ &Query,
+ &Touch,
+ &Delete,
+ &Rename
+};
+
+} // namespace
+
+const PPB_FileSystem* FileSystem::GetInterface() {
+ return &ppb_filesystem;
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_file_system.h b/webkit/glue/plugins/pepper_file_system.h
new file mode 100644
index 0000000..b8ad01a9
--- /dev/null
+++ b/webkit/glue/plugins/pepper_file_system.h
@@ -0,0 +1,21 @@
+// 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_SYSTEM_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FILE_SYSTEM_H_
+
+typedef struct _ppb_FileSystem PPB_FileSystem;
+
+namespace pepper {
+
+class FileSystem {
+ public:
+ // Returns a pointer to the interface implementing PPB_FileSystem that is
+ // exposed to the plugin.
+ static const PPB_FileSystem* GetInterface();
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FILE_SYSTEM_H_
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc
index 10ed52e..3f5d767 100644
--- a/webkit/glue/plugins/pepper_plugin_module.cc
+++ b/webkit/glue/plugins/pepper_plugin_module.cc
@@ -15,6 +15,9 @@
#include "third_party/ppapi/c/ppb_buffer.h"
#include "third_party/ppapi/c/ppb_core.h"
#include "third_party/ppapi/c/ppb_device_context_2d.h"
+#include "third_party/ppapi/c/ppb_file_io.h"
+#include "third_party/ppapi/c/ppb_file_io_trusted.h"
+#include "third_party/ppapi/c/ppb_file_system.h"
#include "third_party/ppapi/c/ppb_image_data.h"
#include "third_party/ppapi/c/ppb_instance.h"
#include "third_party/ppapi/c/ppb_testing.h"
@@ -29,6 +32,10 @@
#include "third_party/ppapi/c/pp_var.h"
#include "webkit/glue/plugins/pepper_buffer.h"
#include "webkit/glue/plugins/pepper_device_context_2d.h"
+#include "webkit/glue/plugins/pepper_directory_reader.h"
+#include "webkit/glue/plugins/pepper_file_io.h"
+#include "webkit/glue/plugins/pepper_file_ref.h"
+#include "webkit/glue/plugins/pepper_file_system.h"
#include "webkit/glue/plugins/pepper_image_data.h"
#include "webkit/glue/plugins/pepper_plugin_instance.h"
#include "webkit/glue/plugins/pepper_resource_tracker.h"
@@ -157,6 +164,16 @@ const void* GetInterface(const char* name) {
return URLResponseInfo::GetInterface();
if (strcmp(name, PPB_BUFFER_INTERFACE) == 0)
return Buffer::GetInterface();
+ if (strcmp(name, PPB_FILEREF_INTERFACE) == 0)
+ return FileRef::GetInterface();
+ if (strcmp(name, PPB_FILEIO_INTERFACE) == 0)
+ return FileIO::GetInterface();
+ if (strcmp(name, PPB_FILEIOTRUSTED_INTERFACE) == 0)
+ return FileIO::GetTrustedInterface();
+ if (strcmp(name, PPB_FILESYSTEM_INTERFACE) == 0)
+ return FileSystem::GetInterface();
+ if (strcmp(name, PPB_DIRECTORYREADER_INTERFACE) == 0)
+ return DirectoryReader::GetInterface();
// Only support the testing interface when the command line switch is
// specified. This allows us to prevent people from (ab)using this interface
diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h
index dc8de11..efcc211 100644
--- a/webkit/glue/plugins/pepper_resource.h
+++ b/webkit/glue/plugins/pepper_resource.h
@@ -13,6 +13,10 @@ namespace pepper {
class Buffer;
class DeviceContext2D;
+class DirectoryReader;
+class FileChooser;
+class FileIO;
+class FileRef;
class ImageData;
class PluginModule;
class URLLoader;
@@ -30,12 +34,16 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
// Type-specific getters for individual resource types. These will return
// NULL if the resource does not match the specified type.
+ virtual Buffer* AsBuffer() { return NULL; }
virtual DeviceContext2D* AsDeviceContext2D() { return NULL; }
+ virtual DirectoryReader* AsDirectoryReader() { return NULL; }
+ virtual FileChooser* AsFileChooser() { return NULL; }
+ virtual FileIO* AsFileIO() { return NULL; }
+ virtual FileRef* AsFileRef() { return NULL; }
virtual ImageData* AsImageData() { return NULL; }
virtual URLLoader* AsURLLoader() { return NULL; }
virtual URLRequestInfo* AsURLRequestInfo() { return NULL; }
virtual URLResponseInfo* AsURLResponseInfo() { return NULL; }
- virtual Buffer* AsBuffer() { return NULL; }
private:
PluginModule* module_; // Non-owning pointer to our module.
diff --git a/webkit/glue/plugins/pepper_resource_tracker.cc b/webkit/glue/plugins/pepper_resource_tracker.cc
index 597d3fb..077c95b 100644
--- a/webkit/glue/plugins/pepper_resource_tracker.cc
+++ b/webkit/glue/plugins/pepper_resource_tracker.cc
@@ -10,6 +10,10 @@
#include "third_party/ppapi/c/pp_resource.h"
#include "webkit/glue/plugins/pepper_buffer.h"
#include "webkit/glue/plugins/pepper_device_context_2d.h"
+#include "webkit/glue/plugins/pepper_directory_reader.h"
+#include "webkit/glue/plugins/pepper_file_chooser.h"
+#include "webkit/glue/plugins/pepper_file_io.h"
+#include "webkit/glue/plugins/pepper_file_ref.h"
#include "webkit/glue/plugins/pepper_image_data.h"
#include "webkit/glue/plugins/pepper_resource.h"
#include "webkit/glue/plugins/pepper_url_loader.h"
@@ -53,52 +57,24 @@ void ResourceTracker::DeleteResource(Resource* resource) {
live_resources_.erase(found);
}
-scoped_refptr<DeviceContext2D> ResourceTracker::GetAsDeviceContext2D(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<DeviceContext2D>();
- return scoped_refptr<DeviceContext2D>(resource->AsDeviceContext2D());
-}
-
-scoped_refptr<ImageData> ResourceTracker::GetAsImageData(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<ImageData>();
- return scoped_refptr<ImageData>(resource->AsImageData());
-}
-
-scoped_refptr<URLLoader> ResourceTracker::GetAsURLLoader(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<URLLoader>();
- return scoped_refptr<URLLoader>(resource->AsURLLoader());
-}
-
-scoped_refptr<URLRequestInfo> ResourceTracker::GetAsURLRequestInfo(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<URLRequestInfo>();
- return scoped_refptr<URLRequestInfo>(resource->AsURLRequestInfo());
-}
-
-scoped_refptr<URLResponseInfo> ResourceTracker::GetAsURLResponseInfo(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<URLResponseInfo>();
- return scoped_refptr<URLResponseInfo>(resource->AsURLResponseInfo());
-}
+#define GET_AS_TYPE_IMPL(Type) \
+ scoped_refptr<Type> ResourceTracker::GetAs##Type( \
+ PP_Resource res) const { \
+ scoped_refptr<Resource> resource = GetResource(res); \
+ if (!resource.get()) \
+ return scoped_refptr<Type>(); \
+ return scoped_refptr<Type>(resource->As##Type()); \
+ }
-scoped_refptr<Buffer> ResourceTracker::GetAsBuffer(
- PP_Resource res) const {
- scoped_refptr<Resource> resource = GetResource(res);
- if (!resource.get())
- return scoped_refptr<Buffer>();
- return scoped_refptr<Buffer>(resource->AsBuffer());
-}
+GET_AS_TYPE_IMPL(Buffer)
+GET_AS_TYPE_IMPL(DeviceContext2D)
+GET_AS_TYPE_IMPL(DirectoryReader)
+GET_AS_TYPE_IMPL(FileChooser)
+GET_AS_TYPE_IMPL(FileIO)
+GET_AS_TYPE_IMPL(FileRef)
+GET_AS_TYPE_IMPL(ImageData)
+GET_AS_TYPE_IMPL(URLLoader)
+GET_AS_TYPE_IMPL(URLRequestInfo)
+GET_AS_TYPE_IMPL(URLResponseInfo)
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_resource_tracker.h b/webkit/glue/plugins/pepper_resource_tracker.h
index 6df79c6..cfe2e68 100644
--- a/webkit/glue/plugins/pepper_resource_tracker.h
+++ b/webkit/glue/plugins/pepper_resource_tracker.h
@@ -18,6 +18,10 @@ namespace pepper {
class Buffer;
class DeviceContext2D;
+class DirectoryReader;
+class FileChooser;
+class FileIO;
+class FileRef;
class ImageData;
class Resource;
class URLLoader;
@@ -48,12 +52,16 @@ class ResourceTracker {
// Helpers for converting resources to a specific type. Returns NULL if the
// resource is invalid or is a different type.
+ scoped_refptr<Buffer> GetAsBuffer(PP_Resource res) const;
scoped_refptr<DeviceContext2D> GetAsDeviceContext2D(PP_Resource res) const;
+ scoped_refptr<DirectoryReader> GetAsDirectoryReader(PP_Resource res) const;
+ scoped_refptr<FileChooser> GetAsFileChooser(PP_Resource res) const;
+ scoped_refptr<FileIO> GetAsFileIO(PP_Resource res) const;
+ scoped_refptr<FileRef> GetAsFileRef(PP_Resource res) const;
scoped_refptr<ImageData> GetAsImageData(PP_Resource res) const;
scoped_refptr<URLLoader> GetAsURLLoader(PP_Resource res) const;
scoped_refptr<URLRequestInfo> GetAsURLRequestInfo(PP_Resource res) const;
scoped_refptr<URLResponseInfo> GetAsURLResponseInfo(PP_Resource res) const;
- scoped_refptr<Buffer> GetAsBuffer(PP_Resource res) const;
private:
friend struct DefaultSingletonTraits<ResourceTracker>;
diff --git a/webkit/glue/plugins/pepper_var.cc b/webkit/glue/plugins/pepper_var.cc
index a911575..bb2d885 100644
--- a/webkit/glue/plugins/pepper_var.cc
+++ b/webkit/glue/plugins/pepper_var.cc
@@ -839,6 +839,11 @@ NPObject* GetNPObject(PP_Var var) {
return GetNPObjectUnchecked(var);
}
+PP_Var StringToPPVar(const std::string& str) {
+ DCHECK(IsStringUTF8(str));
+ return VarFromUtf8(str.data(), str.size());
+}
+
String* GetString(PP_Var var) {
if (var.type != PP_VarType_String)
return NULL;
diff --git a/webkit/glue/plugins/pepper_var.h b/webkit/glue/plugins/pepper_var.h
index b78f388..b8c31cc 100644
--- a/webkit/glue/plugins/pepper_var.h
+++ b/webkit/glue/plugins/pepper_var.h
@@ -5,6 +5,8 @@
#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_
+#include <string>
+
typedef struct _pp_Var PP_Var;
typedef struct _ppb_Var PPB_Var;
typedef struct NPObject NPObject;
@@ -30,6 +32,10 @@ PP_Var NPObjectToPPVar(NPObject* object);
// type.
NPObject* GetNPObject(PP_Var var);
+// Returns a PP_Var of type string that contains a copy of the given string.
+// The input data must be valid UTF-8 encoded text.
+PP_Var StringToPPVar(const std::string& str);
+
// Returns the String corresponding to the PP_Var. This pointer has not been
// AddRef'd, so you should not call Release! Returns NULL if the PP_Var is not
// a string type.
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 8d712ae..aaa1d3f 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -166,6 +166,16 @@
'plugins/pepper_buffer.h',
'plugins/pepper_device_context_2d.cc',
'plugins/pepper_device_context_2d.h',
+ 'plugins/pepper_directory_reader.cc',
+ 'plugins/pepper_directory_reader.h',
+ 'plugins/pepper_file_chooser.cc',
+ 'plugins/pepper_file_chooser.h',
+ 'plugins/pepper_file_io.cc',
+ 'plugins/pepper_file_io.h',
+ 'plugins/pepper_file_ref.cc',
+ 'plugins/pepper_file_ref.h',
+ 'plugins/pepper_file_system.cc',
+ 'plugins/pepper_file_system.h',
'plugins/pepper_image_data.cc',
'plugins/pepper_image_data.h',
'plugins/pepper_plugin_delegate.h',