diff options
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/pepper_file_message_filter.cc | 271 | ||||
-rw-r--r-- | chrome/browser/renderer_host/pepper_file_message_filter.h | 87 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/common/pepper_plugin_registry.cc | 2 | ||||
-rw-r--r-- | chrome/common/render_messages.cc | 20 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 9 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 38 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 116 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 24 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_dir_contents.h | 18 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_delegate.h | 26 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.h | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_private2.cc | 189 | ||||
-rw-r--r-- | webkit/glue/plugins/ppb_private2.h | 72 |
15 files changed, 879 insertions, 8 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); diff --git a/webkit/glue/plugins/pepper_dir_contents.h b/webkit/glue/plugins/pepper_dir_contents.h new file mode 100644 index 0000000..661c577 --- /dev/null +++ b/webkit/glue/plugins/pepper_dir_contents.h @@ -0,0 +1,18 @@ +// 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_DIR_CONTENTS_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_DIR_CONTENTS_H_ + +#include <vector> +#include "base/file_path.h" + +struct PepperDirEntry { + FilePath name; + bool is_dir; +}; + +typedef std::vector<PepperDirEntry> PepperDirContents; + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_DIR_CONTENTS_H_ diff --git a/webkit/glue/plugins/pepper_plugin_delegate.h b/webkit/glue/plugins/pepper_plugin_delegate.h index f080f34..7558a2c 100644 --- a/webkit/glue/plugins/pepper_plugin_delegate.h +++ b/webkit/glue/plugins/pepper_plugin_delegate.h @@ -16,6 +16,7 @@ #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/glue/plugins/pepper_dir_contents.h" class AudioMessageFilter; class GURL; @@ -191,6 +192,31 @@ class PluginDelegate { const FilePath& new_file_path, fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + virtual base::PlatformFileError OpenModuleLocalFile( + const std::string& module_name, + const FilePath& path, + int flags, + base::PlatformFile* file) = 0; + virtual base::PlatformFileError RenameModuleLocalFile( + const std::string& module_name, + const FilePath& path_from, + const FilePath& path_to) = 0; + virtual base::PlatformFileError DeleteModuleLocalFileOrDir( + const std::string& module_name, + const FilePath& path, + bool recursive) = 0; + virtual base::PlatformFileError CreateModuleLocalDir( + const std::string& module_name, + const FilePath& path) = 0; + virtual base::PlatformFileError QueryModuleLocalFile( + const std::string& module_name, + const FilePath& path, + base::PlatformFileInfo* info) = 0; + virtual base::PlatformFileError GetModuleLocalDirContents( + const std::string& module_name, + const FilePath& path, + PepperDirContents* contents) = 0; + // Returns a MessageLoopProxy instance associated with the message loop // of the file thread in this renderer. virtual scoped_refptr<base::MessageLoopProxy> diff --git a/webkit/glue/plugins/pepper_plugin_module.h b/webkit/glue/plugins/pepper_plugin_module.h index edb9e12..4ac13c3 100644 --- a/webkit/glue/plugins/pepper_plugin_module.h +++ b/webkit/glue/plugins/pepper_plugin_module.h @@ -61,6 +61,9 @@ class PluginModule : public base::RefCounted<PluginModule>, PP_Module pp_module() const { return pp_module_; } + void set_name(const std::string& name) { name_ = name; } + const std::string& name() const { return name_; } + PluginInstance* CreateInstance(PluginDelegate* delegate); // Returns "some" plugin instance associated with this module. This is not @@ -115,6 +118,9 @@ class PluginModule : public base::RefCounted<PluginModule>, // implementation. EntryPoints entry_points_; + // The name of the module. + std::string name_; + // Non-owning pointers to all instances associated with this module. When // there are no more instances, this object should be deleted. typedef std::set<PluginInstance*> PluginInstanceSet; diff --git a/webkit/glue/plugins/pepper_private2.cc b/webkit/glue/plugins/pepper_private2.cc index 71ffc4b..a96ef30 100644 --- a/webkit/glue/plugins/pepper_private2.cc +++ b/webkit/glue/plugins/pepper_private2.cc @@ -4,8 +4,15 @@ #include "webkit/glue/plugins/pepper_private2.h" +#include <string.h> + +#include "base/file_path.h" #include "base/stringprintf.h" +#include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" +#include "third_party/ppapi/c/dev/pp_file_info_dev.h" +#include "third_party/ppapi/c/dev/ppb_file_io_dev.h" +#include "webkit/glue/plugins/pepper_error_util.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" @@ -16,6 +23,14 @@ namespace pepper { namespace { +PluginInstance* GetSomeInstance(PP_Module pp_module) { + PluginModule* module = ResourceTracker::Get()->GetModule(pp_module); + if (!module) + return NULL; + + return module->GetSomeInstance(); +} + void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) @@ -24,11 +39,7 @@ void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) { } PP_Var GetProxyForURL(PP_Module pp_module, const char* url) { - PluginModule* module = ResourceTracker::Get()->GetModule(pp_module); - if (!module) - return PP_MakeUndefined(); - - PluginInstance* instance = module->GetSomeInstance(); + PluginInstance* instance = GetSomeInstance(pp_module); if (!instance) return PP_MakeUndefined(); @@ -39,13 +50,177 @@ PP_Var GetProxyForURL(PP_Module pp_module, const char* url) { std::string proxy_host = instance->delegate()->ResolveProxy(gurl); if (proxy_host.empty()) return PP_MakeUndefined(); // No proxy. - return StringVar::StringToPPVar(module, proxy_host); + return StringVar::StringToPPVar(instance->module(), proxy_host); +} + +FilePath GetFilePathFromUTF8(const char* path) { +#if defined(OS_WIN) + return FilePath(UTF8ToUTF16(path)); +#else + return FilePath(path); +#endif +} + +int32_t OpenModuleLocalFile(PP_Module module, + const char* path, + int32_t mode, + PP_FileHandle* file) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + int flags = 0; + if (mode & PP_FILEOPENFLAG_READ) + flags |= base::PLATFORM_FILE_READ; + if (mode & PP_FILEOPENFLAG_WRITE) { + flags |= base::PLATFORM_FILE_WRITE; + flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; + } + if (mode & PP_FILEOPENFLAG_TRUNCATE) { + DCHECK(mode & PP_FILEOPENFLAG_WRITE); + flags |= base::PLATFORM_FILE_TRUNCATE; + } + + if (mode & PP_FILEOPENFLAG_CREATE) { + if (mode & PP_FILEOPENFLAG_EXCLUSIVE) + flags |= base::PLATFORM_FILE_CREATE; + else + flags |= base::PLATFORM_FILE_OPEN_ALWAYS; + } else { + flags |= base::PLATFORM_FILE_OPEN; + } + + base::PlatformFile base_file; + base::PlatformFileError result = instance->delegate()->OpenModuleLocalFile( + instance->module()->name(), + GetFilePathFromUTF8(path), + flags, + &base_file); + *file = base_file; + return PlatformFileErrorToPepperError(result); +} + + +int32_t RenameModuleLocalFile(PP_Module module, + const char* path_from, + const char* path_to) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + base::PlatformFileError result = instance->delegate()->RenameModuleLocalFile( + instance->module()->name(), + GetFilePathFromUTF8(path_from), + GetFilePathFromUTF8(path_to)); + return PlatformFileErrorToPepperError(result); +} + +int32_t DeleteModuleLocalFileOrDir(PP_Module module, + const char* path, + bool recursive) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + base::PlatformFileError result = + instance->delegate()->DeleteModuleLocalFileOrDir( + instance->module()->name(), GetFilePathFromUTF8(path), recursive); + return PlatformFileErrorToPepperError(result); +} + +int32_t CreateModuleLocalDir(PP_Module module, const char* path) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + base::PlatformFileError result = instance->delegate()->CreateModuleLocalDir( + instance->module()->name(), GetFilePathFromUTF8(path)); + return PlatformFileErrorToPepperError(result); +} + +int32_t QueryModuleLocalFile(PP_Module module, + const char* path, + PP_FileInfo_Dev* info) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + base::PlatformFileInfo file_info; + base::PlatformFileError result = instance->delegate()->QueryModuleLocalFile( + instance->module()->name(), GetFilePathFromUTF8(path), &file_info); + if (result == 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 = PP_FILESYSTEMTYPE_EXTERNAL; + if (file_info.is_directory) + info->type = PP_FILETYPE_DIRECTORY; + else + info->type = PP_FILETYPE_REGULAR; + } + return PlatformFileErrorToPepperError(result); +} + +int32_t GetModuleLocalDirContents(PP_Module module, + const char* path, + PP_DirContents_Dev** contents) { + PluginInstance* instance = GetSomeInstance(module); + if (!instance) + return PP_ERROR_FAILED; + + *contents = NULL; + PepperDirContents pepper_contents; + base::PlatformFileError result = + instance->delegate()->GetModuleLocalDirContents( + instance->module()->name(), + GetFilePathFromUTF8(path), + &pepper_contents); + + if (result != base::PLATFORM_FILE_OK) + return PlatformFileErrorToPepperError(result); + + *contents = new PP_DirContents_Dev; + size_t count = pepper_contents.size(); + (*contents)->count = count; + (*contents)->entries = new PP_DirEntry_Dev[count]; + for (size_t i = 0; i < count; ++i) { + PP_DirEntry_Dev& entry = (*contents)->entries[i]; +#if defined(OS_WIN) + const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); +#else + const std::string& name = pepper_contents[i].name.value(); +#endif + size_t size = name.size() + 1; + char* name_copy = new char[size]; + memcpy(name_copy, name.c_str(), size); + entry.name = name_copy; + entry.is_dir = pepper_contents[i].is_dir; + } + return PP_OK; +} + +void FreeModuleLocalDirContents(PP_Module module, + PP_DirContents_Dev* contents) { + DCHECK(contents); + for (int32_t i = 0; i < contents->count; ++i) { + delete [] contents->entries[i].name; + } + delete [] contents->entries; + delete contents; } const PPB_Private2 ppb_private2 = { &SetInstanceAlwaysOnTop, &Private2::DrawGlyphs, - &GetProxyForURL + &GetProxyForURL, + &OpenModuleLocalFile, + &RenameModuleLocalFile, + &DeleteModuleLocalFileOrDir, + &CreateModuleLocalDir, + &QueryModuleLocalFile, + &GetModuleLocalDirContents, + &FreeModuleLocalDirContents, }; } // namespace diff --git a/webkit/glue/plugins/ppb_private2.h b/webkit/glue/plugins/ppb_private2.h index 667d5c5..0b0df98 100644 --- a/webkit/glue/plugins/ppb_private2.h +++ b/webkit/glue/plugins/ppb_private2.h @@ -5,6 +5,11 @@ #ifndef WEBKIT_GLUE_PLUGINS_PPB_PRIVATE2_H_ #define WEBKIT_GLUE_PLUGINS_PPB_PRIVATE2_H_ +#ifdef _WIN32 +#include <windows.h> +#endif + +#include "third_party/ppapi/c/pp_errors.h" #include "third_party/ppapi/c/pp_instance.h" #include "third_party/ppapi/c/pp_module.h" #include "third_party/ppapi/c/pp_point.h" @@ -12,9 +17,28 @@ #include "third_party/ppapi/c/pp_resource.h" #include "third_party/ppapi/c/pp_var.h" -#define PPB_PRIVATE2_INTERFACE "PPB_Private2;2" +#define PPB_PRIVATE2_INTERFACE "PPB_Private2;3" + +#ifdef _WIN32 +typedef HANDLE PP_FileHandle; +static const PP_FileHandle PP_kInvalidFileHandle = NULL; +#else +typedef int PP_FileHandle; +static const PP_FileHandle PP_kInvalidFileHandle = -1; +#endif struct PP_FontDescription_Dev; +struct PP_FileInfo_Dev; + +struct PP_DirEntry_Dev { + const char* name; + bool is_dir; +}; + +struct PP_DirContents_Dev { + int32_t count; + PP_DirEntry_Dev* entries; +}; struct PPB_Private2 { // Sets or clears the rendering hint that the given plugin instance is always @@ -35,6 +59,52 @@ struct PPB_Private2 { // Retrieves the proxy that will be used for the given URL. The result will // be a string in PAC format, or an undefined var on error. PP_Var (*GetProxyForURL)(PP_Module module, const char* url); + + // Opens a module-local file, returning a file descriptor (posix) or a HANDLE + // (win32) into file. Module-local file paths (here and below) are + // '/'-separated UTF-8 strings, relative to a module-specific root. The return + // value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case + // of failure. + int32_t (*OpenModuleLocalFile)(PP_Module module, + const char* path, + int32_t mode, + PP_FileHandle* file); + + // Renames a module-local file. The return value is the ppapi error, PP_OK if + // success, one of the PP_ERROR_* in case of failure. + int32_t (*RenameModuleLocalFile)(PP_Module module, + const char* path_from, + const char* path_to); + + // Deletes a module-local file or directory. If recursive is set and the path + // points to a directory, deletes all the contents of the directory. The + // return value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in + // case of failure. + int32_t (*DeleteModuleLocalFileOrDir)(PP_Module module, + const char* path, + bool recursive); + + // Creates a module-local directory. The return value is the ppapi error, + // PP_OK if success, one of the PP_ERROR_* in case of failure. + int32_t (*CreateModuleLocalDir)(PP_Module module, const char* path); + + // Queries information about a module-local file. The return value is the + // ppapi error, PP_OK if success, one of the PP_ERROR_* in case of failure. + int32_t (*QueryModuleLocalFile)(PP_Module module, + const char* path, + PP_FileInfo_Dev* info); + + // Gets the list of files contained in a module-local directory. The return + // value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case + // of failure. If non-NULL, the returned contents should be freed with + // FreeModuleLocalDirContents. + int32_t (*GetModuleLocalDirContents)(PP_Module module, + const char* path, + PP_DirContents_Dev** contents); + + // Frees the data allocated by GetModuleLocalDirContents. + void (*FreeModuleLocalDirContents)(PP_Module module, + PP_DirContents_Dev* contents); }; #endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE2_H_ |