Index: content/renderer/pepper/pepper_in_process_resource_creation.cc |
diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.cc b/content/renderer/pepper/pepper_in_process_resource_creation.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b32d82051e01ddad73e44f55e1d76d7cb9b51693 |
--- /dev/null |
+++ b/content/renderer/pepper/pepper_in_process_resource_creation.cc |
@@ -0,0 +1,114 @@ |
+// Copyright (c) 2012 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 "content/renderer/pepper/pepper_in_process_resource_creation.h" |
+ |
+#include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
+#include "ipc/ipc_message.h" |
+#include "ipc/ipc_message_macros.h" |
+#include "ppapi/host/ppapi_host.h" |
+#include "ppapi/proxy/file_chooser_resource.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/shared_impl/ppapi_globals.h" |
+#include "ppapi/shared_impl/resource_tracker.h" |
+ |
+// Note that the code in the functions in this file should be identical to that |
+// in pepper/proxy/resource_creation_proxy.cc. See |
+// pepper_in_process_resource_creation.h for what this file is for. |
+ |
+namespace content { |
+ |
+class PepperInProcessResourceCreation::PluginToHostRouter |
+ : public IPC::Message::Sender { |
+ public: |
+ PluginToHostRouter(RenderViewImpl* render_view, |
+ IPC::Message::Sender* host_to_plugin_sender); |
+ virtual ~PluginToHostRouter() {} |
+ |
+ // Sender implementation. |
+ virtual bool Send(IPC::Message* msg) OVERRIDE; |
+ |
+ private: |
+ ContentRendererPepperHostFactory factory_; |
+ ppapi::host::PpapiHost host_; |
+}; |
+ |
+PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter( |
+ RenderViewImpl* render_view, |
+ IPC::Message::Sender* host_to_plugin_sender) |
+ : factory_(render_view), |
+ host_(host_to_plugin_sender, &factory_) { |
+} |
+ |
+bool PepperInProcessResourceCreation::PluginToHostRouter::Send( |
+ IPC::Message* msg) { |
+ scoped_ptr<IPC::Message> msg_deletor(msg); |
+ return host_.OnMessageReceived(*msg); |
+} |
+ |
+// HostToPluginRouter --------------------------------------------------------- |
+ |
+class PepperInProcessResourceCreation::HostToPluginRouter |
+ : public IPC::Message::Sender { |
+ public: |
+ HostToPluginRouter() {} |
+ virtual ~HostToPluginRouter() {} |
+ |
+ // Sender implementation. |
+ virtual bool Send(IPC::Message* msg) OVERRIDE; |
+ |
+ private: |
+ void OnMsgResourceReply( |
+ const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
+ const IPC::Message& nested_msg); |
+}; |
+ |
+bool PepperInProcessResourceCreation::HostToPluginRouter::Send( |
+ IPC::Message* msg) { |
+ scoped_ptr<IPC::Message> msg_deletor(msg); |
+ IPC_BEGIN_MESSAGE_MAP(HostToPluginRouter, *msg) |
+ IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply) |
+ IPC_MESSAGE_UNHANDLED(return false); |
+ IPC_END_MESSAGE_MAP() |
+ return true; |
+} |
+ |
+void PepperInProcessResourceCreation::HostToPluginRouter::OnMsgResourceReply( |
+ const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
+ const IPC::Message& nested_msg) { |
+ ppapi::Resource* resource = |
+ ppapi::PpapiGlobals::Get()->GetResourceTracker()->GetResource( |
+ reply_params.pp_resource()); |
+ if (!resource) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ resource->OnReplyReceived(reply_params.sequence(), reply_params.result(), |
+ nested_msg); |
+} |
+ |
+// PepperInProcessResourceCreation -------------------------------------------- |
+ |
+PepperInProcessResourceCreation::PepperInProcessResourceCreation( |
+ RenderViewImpl* render_view, |
+ webkit::ppapi::PluginInstance* instance) |
+ : ResourceCreationImpl(instance), |
+ host_to_plugin_router_(new HostToPluginRouter), |
+ plugin_to_host_router_( |
+ new PluginToHostRouter(render_view, host_to_plugin_router_.get())) { |
+} |
+ |
+PepperInProcessResourceCreation::~PepperInProcessResourceCreation() { |
+} |
+ |
+PP_Resource PepperInProcessResourceCreation::CreateFileChooser( |
+ PP_Instance instance, |
+ PP_FileChooserMode_Dev mode, |
+ const char* accept_types) { |
+ return (new ppapi::proxy::FileChooserResource( |
+ plugin_to_host_router_.get(), |
+ instance, mode, accept_types))->GetReference(); |
+} |
+ |
+} // namespace content |