summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 00:54:12 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-19 00:54:12 +0000
commit45afd9a78d3316144d6702ff3cc230b4b76d76c7 (patch)
tree1218e4defacc49ab0347605e1150f3baf9b46abb /chrome
parent0e33985b3bf62dab5266b1fcbfbdf11991b0822e (diff)
downloadchromium_src-45afd9a78d3316144d6702ff3cc230b4b76d76c7.zip
chromium_src-45afd9a78d3316144d6702ff3cc230b4b76d76c7.tar.gz
chromium_src-45afd9a78d3316144d6702ff3cc230b4b76d76c7.tar.bz2
Support sync file io for pepper, to support LSOs
BUG=chromium-os:7492 TEST=run pepper flash (with LSO support) on http://www.bestflashanimationsite.com/tutorials/4/ , check that it properly stores the objects. Review URL: http://codereview.chromium.org/3800010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc7
-rw-r--r--chrome/browser/renderer_host/pepper_file_message_filter.cc271
-rw-r--r--chrome/browser/renderer_host/pepper_file_message_filter.h87
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/pepper_plugin_registry.cc2
-rw-r--r--chrome/common/render_messages.cc20
-rw-r--r--chrome/common/render_messages.h9
-rw-r--r--chrome/common/render_messages_internal.h38
-rw-r--r--chrome/renderer/pepper_plugin_delegate_impl.cc116
-rw-r--r--chrome/renderer/pepper_plugin_delegate_impl.h24
10 files changed, 576 insertions, 0 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index f8ef0b1..5e254e5 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -20,6 +20,7 @@
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
+#include "base/path_service.h"
#include "base/platform_file.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
@@ -38,6 +39,7 @@
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/audio_renderer_host.h"
+#include "chrome/browser/renderer_host/pepper_file_message_filter.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/render_widget_helper.h"
@@ -46,6 +48,7 @@
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/visitedlink_master.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/child_process_info.h"
#include "chrome/common/extensions/extension.h"
@@ -331,6 +334,10 @@ bool BrowserRenderProcessHost::Init(
// be doing.
channel_->set_sync_messages_with_no_timeout_allowed(false);
+ scoped_refptr<PepperFileMessageFilter> pepper_file_message_filter =
+ new PepperFileMessageFilter(id(), profile());
+ channel_->AddFilter(pepper_file_message_filter);
+
if (run_renderer_in_process()) {
// Crank up a thread and run the initialization there. With the way that
// messages flow between the browser and renderer, this thread is required
diff --git a/chrome/browser/renderer_host/pepper_file_message_filter.cc b/chrome/browser/renderer_host/pepper_file_message_filter.cc
new file mode 100644
index 0000000..e7b331b
--- /dev/null
+++ b/chrome/browser/renderer_host/pepper_file_message_filter.cc
@@ -0,0 +1,271 @@
+// 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 "chrome/browser/renderer_host/pepper_file_message_filter.h"
+
+#include "base/callback.h"
+#include "base/file_util.h"
+#include "base/file_path.h"
+#include "base/process_util.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
+#include "chrome/common/child_process_host.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/render_messages.h"
+#include "ipc/ipc_platform_file.h"
+
+#if defined(OS_POSIX)
+#include "base/file_descriptor_posix.h"
+#endif
+
+PepperFileMessageFilter::PepperFileMessageFilter(
+ int child_id, Profile* profile)
+ : handle_(base::kNullProcessHandle),
+ channel_(NULL) {
+ pepper_path_ = profile->GetPath().Append(FILE_PATH_LITERAL("Pepper Data"));
+}
+
+PepperFileMessageFilter::~PepperFileMessageFilter() {
+ // This function should be called on the IO thread.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (handle_)
+ base::CloseProcessHandle(handle_);
+}
+
+// Called on the IPC thread:
+void PepperFileMessageFilter::OnFilterAdded(IPC::Channel* channel) {
+ channel_ = channel;
+}
+
+// Called on the IPC thread:
+void PepperFileMessageFilter::OnChannelConnected(int32 peer_pid) {
+ DCHECK(!handle_) << " " << handle_;
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (!base::OpenProcessHandle(peer_pid, &handle_)) {
+ NOTREACHED();
+ }
+}
+
+void PepperFileMessageFilter::OnChannelError() {
+}
+
+// Called on the IPC thread:
+void PepperFileMessageFilter::OnChannelClosing() {
+ channel_ = NULL;
+}
+
+// Called on the IPC thread:
+bool PepperFileMessageFilter::OnMessageReceived(const IPC::Message& msg) {
+ switch (msg.type()) {
+ case ViewHostMsg_PepperOpenFile::ID:
+ case ViewHostMsg_PepperRenameFile::ID:
+ case ViewHostMsg_PepperDeleteFileOrDir::ID:
+ case ViewHostMsg_PepperCreateDir::ID:
+ case ViewHostMsg_PepperQueryFile::ID:
+ case ViewHostMsg_PepperGetDirContents::ID:
+ break;
+ default:
+ return false;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ this, &PepperFileMessageFilter::OnMessageReceivedFileThread, msg));
+
+ return true;
+}
+
+void PepperFileMessageFilter::OnMessageReceivedFileThread(
+ const IPC::Message& msg) {
+ bool msg_is_ok = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(PepperFileMessageFilter, msg, msg_is_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperOpenFile, OnPepperOpenFile)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperRenameFile, OnPepperRenameFile)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperDeleteFileOrDir,
+ OnPepperDeleteFileOrDir)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperCreateDir, OnPepperCreateDir)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperQueryFile, OnPepperQueryFile)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PepperGetDirContents,
+ OnPepperGetDirContents)
+ IPC_MESSAGE_UNHANDLED_ERROR()
+ IPC_END_MESSAGE_MAP_EX()
+
+ if (!msg_is_ok) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(
+ &BrowserRenderProcessHost::BadMessageTerminateProcess,
+ msg.type(), handle_));
+ }
+}
+
+void PepperFileMessageFilter::OnDestruct() {
+ BrowserThread::DeleteOnIOThread::Destruct(this);
+}
+
+// Called on the FILE thread:
+void PepperFileMessageFilter::Send(IPC::Message* message) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &PepperFileMessageFilter::SendFromIOThread, message));
+}
+
+// Called on the IPC thread:
+bool PepperFileMessageFilter::SendFromIOThread(IPC::Message* message) {
+ if (!channel_) {
+ delete message;
+ return false;
+ }
+
+ return channel_->Send(message);
+}
+
+// Called on the FILE thread:
+void PepperFileMessageFilter::OnPepperOpenFile(
+ const FilePath& path,
+ int flags,
+ base::PlatformFileError* error,
+ IPC::PlatformFileForTransit* file) {
+ FilePath full_path = MakePepperPath(path);
+ if (full_path.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ *file = IPC::InvalidPlatformFileForTransit();
+ return;
+ }
+
+ base::PlatformFile file_handle = base::CreatePlatformFile(
+ full_path, flags, NULL, error);
+
+ if (*error != base::PLATFORM_FILE_OK) {
+ *file = IPC::InvalidPlatformFileForTransit();
+ return;
+ }
+
+ // Make sure we didn't try to open a directory: directory fd shouldn't pass
+ // to untrusted processes because they open security holes.
+ base::PlatformFileInfo info;
+ if (!base::GetPlatformFileInfo(file_handle, &info) || info.is_directory) {
+ // When in doubt, throw it out.
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ *file = IPC::InvalidPlatformFileForTransit();
+ return;
+ }
+
+#if defined(OS_WIN)
+ // Duplicate the file handle so that the renderer process can access the file.
+ if (!DuplicateHandle(GetCurrentProcess(), file_handle,
+ handle_, file, 0, false,
+ DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
+ // file_handle is closed whether or not DuplicateHandle succeeds.
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ *file = INVALID_HANDLE_VALUE;
+ }
+#else
+ *file = base::FileDescriptor(file_handle, true);
+#endif
+}
+
+void PepperFileMessageFilter::OnPepperRenameFile(
+ const FilePath& path_from,
+ const FilePath& path_to,
+ base::PlatformFileError* error) {
+ FilePath full_path_from = MakePepperPath(path_from);
+ FilePath full_path_to = MakePepperPath(path_to);
+ if (full_path_from.empty() || full_path_to.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ return;
+ }
+
+ bool result = file_util::Move(full_path_from, full_path_to);
+ *error = result ? base::PLATFORM_FILE_OK
+ : base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+}
+
+void PepperFileMessageFilter::OnPepperDeleteFileOrDir(
+ const FilePath& path,
+ bool recursive,
+ base::PlatformFileError* error) {
+ FilePath full_path = MakePepperPath(path);
+ if (full_path.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ return;
+ }
+
+ bool result = file_util::Delete(full_path, recursive);
+ *error = result ? base::PLATFORM_FILE_OK
+ : base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+}
+
+void PepperFileMessageFilter::OnPepperCreateDir(
+ const FilePath& path,
+ base::PlatformFileError* error) {
+ FilePath full_path = MakePepperPath(path);
+ if (full_path.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ return;
+ }
+
+ bool result = file_util::CreateDirectory(full_path);
+ *error = result ? base::PLATFORM_FILE_OK
+ : base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+}
+
+void PepperFileMessageFilter::OnPepperQueryFile(
+ const FilePath& path,
+ base::PlatformFileInfo* info,
+ base::PlatformFileError* error) {
+ FilePath full_path = MakePepperPath(path);
+ if (full_path.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ return;
+ }
+
+ bool result = file_util::GetFileInfo(full_path, info);
+ *error = result ? base::PLATFORM_FILE_OK
+ : base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+}
+
+void PepperFileMessageFilter::OnPepperGetDirContents(
+ const FilePath& path,
+ PepperDirContents* contents,
+ base::PlatformFileError* error) {
+ FilePath full_path = MakePepperPath(path);
+ if (full_path.empty()) {
+ *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ return;
+ }
+
+ contents->clear();
+
+ file_util::FileEnumerator enumerator(
+ full_path, false,
+ static_cast<file_util::FileEnumerator::FILE_TYPE>(
+ file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES |
+ file_util::FileEnumerator::INCLUDE_DOT_DOT));
+
+ while (!enumerator.Next().empty()) {
+ file_util::FileEnumerator::FindInfo info;
+ enumerator.GetFindInfo(&info);
+ PepperDirEntry entry = {
+ file_util::FileEnumerator::GetFilename(info),
+ file_util::FileEnumerator::IsDirectory(info)
+ };
+ contents->push_back(entry);
+ }
+
+ *error = base::PLATFORM_FILE_OK;
+}
+
+FilePath PepperFileMessageFilter::MakePepperPath(const FilePath& base_path) {
+ if (base_path.IsAbsolute() || base_path.ReferencesParent()) {
+ return FilePath();
+ }
+ return pepper_path_.Append(base_path);
+}
diff --git a/chrome/browser/renderer_host/pepper_file_message_filter.h b/chrome/browser/renderer_host/pepper_file_message_filter.h
new file mode 100644
index 0000000..37e57f6
--- /dev/null
+++ b/chrome/browser/renderer_host/pepper_file_message_filter.h
@@ -0,0 +1,87 @@
+// 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 CHROME_BROWSER_RENDERER_HOST_PEPPER_FILE_MESSAGE_FILTER_H_
+#define CHROME_BROWSER_RENDERER_HOST_PEPPER_FILE_MESSAGE_FILTER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/file_path.h"
+#include "base/process.h"
+#include "base/ref_counted.h"
+#include "base/task.h"
+#include "build/build_config.h"
+#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
+#include "ipc/ipc_channel_proxy.h"
+#include "ipc/ipc_platform_file.h"
+#include "webkit/glue/plugins/pepper_dir_contents.h"
+
+class Profile;
+
+// A message filter for Pepper-specific File I/O messages.
+//
+// NOTE: Contrary to most message filters, this one handles the messages (On*
+// functions) on the FILE thread instead of the IO thread: OnMessageReceived
+// forwards the mesage to the FILE thread, where it's handled by
+// OnMessageReceivedFileThread.
+class PepperFileMessageFilter : public IPC::ChannelProxy::MessageFilter {
+ public:
+ PepperFileMessageFilter(int child_id, Profile* profile);
+
+ // IPC::ChannelProxy::MessageFilter methods:
+ virtual void OnFilterAdded(IPC::Channel* channel);
+ virtual void OnChannelConnected(int32 peer_pid);
+ virtual void OnChannelError();
+ virtual void OnChannelClosing();
+ virtual bool OnMessageReceived(const IPC::Message& message);
+ virtual void OnDestruct();
+
+ // Called from the FILE thread.
+ void Send(IPC::Message* message);
+
+ private:
+ friend class BrowserThread;
+ friend class DeleteTask<PepperFileMessageFilter>;
+ virtual ~PepperFileMessageFilter();
+ void OnMessageReceivedFileThread(const IPC::Message& message);
+ bool SendFromIOThread(IPC::Message* message);
+
+ // Called on the FILE thread:
+ void OnPepperOpenFile(const FilePath& path,
+ int flags,
+ base::PlatformFileError* error,
+ IPC::PlatformFileForTransit* file);
+ void OnPepperRenameFile(const FilePath& path_from,
+ const FilePath& path_to,
+ base::PlatformFileError* error);
+ void OnPepperDeleteFileOrDir(const FilePath& path,
+ bool recursive,
+ base::PlatformFileError* error);
+ void OnPepperCreateDir(const FilePath& path,
+ base::PlatformFileError* error);
+ void OnPepperQueryFile(const FilePath& path,
+ base::PlatformFileInfo* info,
+ base::PlatformFileError* error);
+ void OnPepperGetDirContents(const FilePath& path,
+ PepperDirContents* contents,
+ base::PlatformFileError* error);
+
+ FilePath MakePepperPath(const FilePath& base_path);
+
+ // The process handle for the peer.
+ base::ProcessHandle handle_;
+
+ // The channel associated with the renderer connection. This pointer is not
+ // owned by this class.
+ IPC::Channel* channel_;
+
+ // The base path for the pepper data.
+ FilePath pepper_path_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperFileMessageFilter);
+};
+
+#endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_FILE_MESSAGE_FILTER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index d5a3f8e..fe756da 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2485,6 +2485,8 @@
'browser/renderer_host/gtk_key_bindings_handler.h',
'browser/renderer_host/offline_resource_handler.cc',
'browser/renderer_host/offline_resource_handler.h',
+ 'browser/renderer_host/pepper_file_message_filter.cc',
+ 'browser/renderer_host/pepper_file_message_filter.h',
'browser/renderer_host/redirect_to_file_resource_handler.cc',
'browser/renderer_host/redirect_to_file_resource_handler.h',
'browser/renderer_host/render_process_host.cc',
diff --git a/chrome/common/pepper_plugin_registry.cc b/chrome/common/pepper_plugin_registry.cc
index 87a2bd3..92fae2e 100644
--- a/chrome/common/pepper_plugin_registry.cc
+++ b/chrome/common/pepper_plugin_registry.cc
@@ -193,6 +193,7 @@ PepperPluginRegistry::PepperPluginRegistry() {
DLOG(ERROR) << "Failed to load pepper module: " << path.value();
continue;
}
+ module->set_name(it->name);
modules_[path] = module;
}
@@ -208,6 +209,7 @@ PepperPluginRegistry::PepperPluginRegistry() {
DLOG(ERROR) << "Failed to load pepper module: " << path.value();
continue;
}
+ module->set_name(plugins[i].name);
modules_[path] = module;
}
}
diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc
index 5d422da..b6e6d66 100644
--- a/chrome/common/render_messages.cc
+++ b/chrome/common/render_messages.cc
@@ -1109,4 +1109,24 @@ void ParamTraits<AudioBuffersState>::Log(const param_type& p, std::string* l) {
l->append(")");
}
+void ParamTraits<PepperDirEntry>::Write(Message* m, const param_type& p) {
+ WriteParam(m, p.name);
+ WriteParam(m, p.is_dir);
+}
+
+bool ParamTraits<PepperDirEntry>::Read(const Message* m,
+ void** iter,
+ param_type* p) {
+ return ReadParam(m, iter, &p->name) &&
+ ReadParam(m, iter, &p->is_dir);
+}
+
+void ParamTraits<PepperDirEntry>::Log(const param_type& p, std::string* l) {
+ l->append("(");
+ LogParam(p.name, l);
+ l->append(", ");
+ LogParam(p.is_dir, l);
+ l->append(")");
+}
+
} // namespace IPC
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 29d50e0..ce893d2 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -29,6 +29,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebStorageArea.h"
#include "webkit/appcache/appcache_interfaces.h" // enum appcache::Status
#include "webkit/fileapi/file_system_types.h" // enum fileapi::FileSystemType
+#include "webkit/glue/plugins/pepper_dir_contents.h"
#if defined(OS_MACOSX)
struct FontDescriptor;
@@ -606,6 +607,14 @@ struct ParamTraits<AudioBuffersState> {
static void Log(const param_type& p, std::string* l);
};
+template <>
+struct ParamTraits<PepperDirEntry> {
+ typedef PepperDirEntry param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* p);
+ static void Log(const param_type& p, std::string* l);
+};
+
} // namespace IPC
#define MESSAGES_INTERNAL_FILE "chrome/common/render_messages_internal.h"
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 1cfa70b3..75eacdf 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -2986,4 +2986,42 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateContentRestrictions,
int /* restrictions */)
+ // Trusted Pepper Filesystem messages ----------------------------------------
+
+ // Open the file.
+ IPC_SYNC_MESSAGE_CONTROL2_2(ViewHostMsg_PepperOpenFile,
+ FilePath /* path */,
+ int /* flags */,
+ base::PlatformFileError /* error_code */,
+ IPC::PlatformFileForTransit /* result */)
+
+ // Rename the file.
+ IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_PepperRenameFile,
+ FilePath /* path_from */,
+ FilePath /* path_to */,
+ base::PlatformFileError /* error_code */)
+
+ // Delete the file.
+ IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_PepperDeleteFileOrDir,
+ FilePath /* path */,
+ bool /* recursive */,
+ base::PlatformFileError /* error_code */)
+
+ // Create the directory.
+ IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_PepperCreateDir,
+ FilePath /* path */,
+ base::PlatformFileError /* error_code */)
+
+ // Query the file's info.
+ IPC_SYNC_MESSAGE_CONTROL1_2(ViewHostMsg_PepperQueryFile,
+ FilePath /* path */,
+ base::PlatformFileInfo, /* info */
+ base::PlatformFileError /* error_code */)
+
+ // Get the directory's contents.
+ IPC_SYNC_MESSAGE_CONTROL1_2(ViewHostMsg_PepperGetDirContents,
+ FilePath /* path */,
+ PepperDirContents, /* contents */
+ base::PlatformFileError /* error_code */)
+
IPC_END_MESSAGES(ViewHost)
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc
index a3e18fe..ed0dccd 100644
--- a/chrome/renderer/pepper_plugin_delegate_impl.cc
+++ b/chrome/renderer/pepper_plugin_delegate_impl.cc
@@ -14,6 +14,7 @@
#include "base/string_split.h"
#include "base/task.h"
#include "base/time.h"
+#include "base/utf_string_conversions.h"
#include "chrome/common/child_thread.h"
#include "chrome/common/file_system/file_system_dispatcher.h"
#include "chrome/common/render_messages.h"
@@ -725,6 +726,121 @@ bool PepperPluginDelegateImpl::Rename(
return file_system_dispatcher->Move(file_path, new_file_path, dispatcher);
}
+FilePath GetModuleLocalFilePath(const std::string& module_name,
+ const FilePath& path) {
+#if defined(OS_WIN)
+ FilePath full_path(UTF8ToUTF16(module_name));
+#else
+ FilePath full_path(module_name);
+#endif
+ full_path = full_path.Append(path);
+ return full_path;
+}
+
+base::PlatformFileError PepperPluginDelegateImpl::OpenModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path,
+ int flags,
+ base::PlatformFile* file) {
+ FilePath full_path = GetModuleLocalFilePath(module_name, path);
+ if (full_path.empty()) {
+ *file = base::kInvalidPlatformFileValue;
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ IPC::PlatformFileForTransit transit_file;
+ base::PlatformFileError error;
+ IPC::Message* msg = new ViewHostMsg_PepperOpenFile(
+ full_path, flags, &error, &transit_file);
+ if (!render_view_->Send(msg)) {
+ *file = base::kInvalidPlatformFileValue;
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ *file = IPC::PlatformFileForTransitToPlatformFile(transit_file);
+ return error;
+}
+
+base::PlatformFileError PepperPluginDelegateImpl::RenameModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path_from,
+ const FilePath& path_to) {
+ FilePath full_path_from = GetModuleLocalFilePath(module_name, path_from);
+ FilePath full_path_to = GetModuleLocalFilePath(module_name, path_to);
+ if (full_path_from.empty() || full_path_to.empty()) {
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ base::PlatformFileError error;
+ IPC::Message* msg = new ViewHostMsg_PepperRenameFile(
+ full_path_from, full_path_to, &error);
+ if (!render_view_->Send(msg)) {
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
+}
+
+base::PlatformFileError PepperPluginDelegateImpl::DeleteModuleLocalFileOrDir(
+ const std::string& module_name,
+ const FilePath& path,
+ bool recursive) {
+ FilePath full_path = GetModuleLocalFilePath(module_name, path);
+ if (full_path.empty()) {
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ base::PlatformFileError error;
+ IPC::Message* msg = new ViewHostMsg_PepperDeleteFileOrDir(
+ full_path, recursive, &error);
+ if (!render_view_->Send(msg)) {
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
+}
+
+base::PlatformFileError PepperPluginDelegateImpl::CreateModuleLocalDir(
+ const std::string& module_name,
+ const FilePath& path) {
+ FilePath full_path = GetModuleLocalFilePath(module_name, path);
+ if (full_path.empty()) {
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ base::PlatformFileError error;
+ IPC::Message* msg = new ViewHostMsg_PepperCreateDir(full_path, &error);
+ if (!render_view_->Send(msg)) {
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
+}
+
+base::PlatformFileError PepperPluginDelegateImpl::QueryModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path,
+ base::PlatformFileInfo* info) {
+ FilePath full_path = GetModuleLocalFilePath(module_name, path);
+ if (full_path.empty()) {
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ base::PlatformFileError error;
+ IPC::Message* msg = new ViewHostMsg_PepperQueryFile(full_path, info, &error);
+ if (!render_view_->Send(msg)) {
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
+}
+base::PlatformFileError PepperPluginDelegateImpl::GetModuleLocalDirContents(
+ const std::string& module_name,
+ const FilePath& path,
+ PepperDirContents* contents) {
+ FilePath full_path = GetModuleLocalFilePath(module_name, path);
+ if (full_path.empty()) {
+ return base::PLATFORM_FILE_ERROR_ACCESS_DENIED;
+ }
+ base::PlatformFileError error;
+ IPC::Message* msg =
+ new ViewHostMsg_PepperGetDirContents(full_path, contents, &error);
+ if (!render_view_->Send(msg)) {
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
+}
+
scoped_refptr<base::MessageLoopProxy>
PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() {
return RenderThread::current()->GetFileThreadMessageLoopProxy();
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h
index 790be75..fdaf1e9 100644
--- a/chrome/renderer/pepper_plugin_delegate_impl.h
+++ b/chrome/renderer/pepper_plugin_delegate_impl.h
@@ -99,6 +99,30 @@ class PepperPluginDelegateImpl
virtual bool Rename(const FilePath& file_path,
const FilePath& new_file_path,
fileapi::FileSystemCallbackDispatcher* dispatcher);
+ virtual base::PlatformFileError OpenModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path,
+ int flags,
+ base::PlatformFile* file);
+ virtual base::PlatformFileError RenameModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path_from,
+ const FilePath& path_to);
+ virtual base::PlatformFileError DeleteModuleLocalFileOrDir(
+ const std::string& module_name,
+ const FilePath& path,
+ bool recursive);
+ virtual base::PlatformFileError CreateModuleLocalDir(
+ const std::string& module_name,
+ const FilePath& path);
+ virtual base::PlatformFileError QueryModuleLocalFile(
+ const std::string& module_name,
+ const FilePath& path,
+ base::PlatformFileInfo* info);
+ virtual base::PlatformFileError GetModuleLocalDirContents(
+ const std::string& module_name,
+ const FilePath& path,
+ PepperDirContents* contents);
virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy();
virtual pepper::FullscreenContainer* CreateFullscreenContainer(
pepper::PluginInstance* instance);