OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
| 6 |
| 7 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
| 8 #include "ipc/ipc_message.h" |
| 9 #include "ipc/ipc_message_macros.h" |
| 10 #include "ppapi/host/ppapi_host.h" |
| 11 #include "ppapi/proxy/file_chooser_resource.h" |
| 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/shared_impl/ppapi_globals.h" |
| 14 #include "ppapi/shared_impl/resource_tracker.h" |
| 15 |
| 16 // Note that the code in the functions in this file should be identical to that |
| 17 // in pepper/proxy/resource_creation_proxy.cc. See |
| 18 // pepper_in_process_resource_creation.h for what this file is for. |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class PepperInProcessResourceCreation::PluginToHostRouter |
| 23 : public IPC::Message::Sender { |
| 24 public: |
| 25 PluginToHostRouter(RenderViewImpl* render_view, |
| 26 IPC::Message::Sender* host_to_plugin_sender); |
| 27 virtual ~PluginToHostRouter() {} |
| 28 |
| 29 // Sender implementation. |
| 30 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 31 |
| 32 private: |
| 33 ContentRendererPepperHostFactory factory_; |
| 34 ppapi::host::PpapiHost host_; |
| 35 }; |
| 36 |
| 37 PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter( |
| 38 RenderViewImpl* render_view, |
| 39 IPC::Message::Sender* host_to_plugin_sender) |
| 40 : factory_(render_view), |
| 41 host_(host_to_plugin_sender, &factory_) { |
| 42 } |
| 43 |
| 44 bool PepperInProcessResourceCreation::PluginToHostRouter::Send( |
| 45 IPC::Message* msg) { |
| 46 scoped_ptr<IPC::Message> msg_deletor(msg); |
| 47 return host_.OnMessageReceived(*msg); |
| 48 } |
| 49 |
| 50 // HostToPluginRouter --------------------------------------------------------- |
| 51 |
| 52 class PepperInProcessResourceCreation::HostToPluginRouter |
| 53 : public IPC::Message::Sender { |
| 54 public: |
| 55 HostToPluginRouter() {} |
| 56 virtual ~HostToPluginRouter() {} |
| 57 |
| 58 // Sender implementation. |
| 59 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 60 |
| 61 private: |
| 62 void OnMsgResourceReply( |
| 63 const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
| 64 const IPC::Message& nested_msg); |
| 65 }; |
| 66 |
| 67 bool PepperInProcessResourceCreation::HostToPluginRouter::Send( |
| 68 IPC::Message* msg) { |
| 69 scoped_ptr<IPC::Message> msg_deletor(msg); |
| 70 IPC_BEGIN_MESSAGE_MAP(HostToPluginRouter, *msg) |
| 71 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply) |
| 72 IPC_MESSAGE_UNHANDLED(return false); |
| 73 IPC_END_MESSAGE_MAP() |
| 74 return true; |
| 75 } |
| 76 |
| 77 void PepperInProcessResourceCreation::HostToPluginRouter::OnMsgResourceReply( |
| 78 const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
| 79 const IPC::Message& nested_msg) { |
| 80 ppapi::Resource* resource = |
| 81 ppapi::PpapiGlobals::Get()->GetResourceTracker()->GetResource( |
| 82 reply_params.pp_resource()); |
| 83 if (!resource) { |
| 84 NOTREACHED(); |
| 85 return; |
| 86 } |
| 87 resource->OnReplyReceived(reply_params.sequence(), reply_params.result(), |
| 88 nested_msg); |
| 89 } |
| 90 |
| 91 // PepperInProcessResourceCreation -------------------------------------------- |
| 92 |
| 93 PepperInProcessResourceCreation::PepperInProcessResourceCreation( |
| 94 RenderViewImpl* render_view, |
| 95 webkit::ppapi::PluginInstance* instance) |
| 96 : ResourceCreationImpl(instance), |
| 97 host_to_plugin_router_(new HostToPluginRouter), |
| 98 plugin_to_host_router_( |
| 99 new PluginToHostRouter(render_view, host_to_plugin_router_.get())) { |
| 100 } |
| 101 |
| 102 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() { |
| 103 } |
| 104 |
| 105 PP_Resource PepperInProcessResourceCreation::CreateFileChooser( |
| 106 PP_Instance instance, |
| 107 PP_FileChooserMode_Dev mode, |
| 108 const char* accept_types) { |
| 109 return (new ppapi::proxy::FileChooserResource( |
| 110 plugin_to_host_router_.get(), |
| 111 instance, mode, accept_types))->GetReference(); |
| 112 } |
| 113 |
| 114 } // namespace content |
OLD | NEW |