| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" | 5 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" | 10 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
| 11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 13 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
| 14 #include "ppapi/proxy/file_chooser_resource.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
| 16 #include "ppapi/shared_impl/ppapi_permissions.h" | 17 #include "ppapi/shared_impl/ppapi_permissions.h" |
| 17 #include "ppapi/shared_impl/resource_tracker.h" | 18 #include "ppapi/shared_impl/resource_tracker.h" |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 18 | 20 |
| 19 // Note that the code in the creation functions in this file should generally | 21 // Note that the code in the creation functions in this file should generally |
| 20 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See | 22 // be the same as that in ppapi/proxy/resource_creation_proxy.cc. See |
| 21 // pepper_in_process_resource_creation.h for what this file is for. | 23 // pepper_in_process_resource_creation.h for what this file is for. |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 class PepperInProcessResourceCreation::PluginToHostRouter | 27 class PepperInProcessResourceCreation::PluginToHostRouter |
| 26 : public IPC::Sender { | 28 : public IPC::Sender { |
| 27 public: | 29 public: |
| 28 PluginToHostRouter(RenderViewImpl* render_view, | 30 PluginToHostRouter(RenderViewImpl* render_view, |
| 31 ContentInstanceGlue* glue, |
| 29 IPC::Sender* host_to_plugin_sender, | 32 IPC::Sender* host_to_plugin_sender, |
| 30 const ppapi::PpapiPermissions& perms); | 33 const ppapi::PpapiPermissions& perms); |
| 31 virtual ~PluginToHostRouter() {} | 34 virtual ~PluginToHostRouter() {} |
| 32 | 35 |
| 33 // Sender implementation. | 36 // Sender implementation. |
| 34 virtual bool Send(IPC::Message* msg) OVERRIDE; | 37 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 35 | 38 |
| 36 private: | 39 private: |
| 37 void DoSend(IPC::Message* msg); | 40 void DoSend(IPC::Message* msg); |
| 38 | 41 |
| 39 base::WeakPtrFactory<PluginToHostRouter> weak_factory_; | 42 base::WeakPtrFactory<PluginToHostRouter> weak_factory_; |
| 40 | 43 |
| 41 ContentRendererPepperHostFactory factory_; | 44 ContentRendererPepperHostFactory factory_; |
| 42 ppapi::host::PpapiHost host_; | 45 ppapi::host::PpapiHost host_; |
| 43 | 46 |
| 44 DISALLOW_COPY_AND_ASSIGN(PluginToHostRouter); | 47 DISALLOW_COPY_AND_ASSIGN(PluginToHostRouter); |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter( | 50 PepperInProcessResourceCreation::PluginToHostRouter::PluginToHostRouter( |
| 48 RenderViewImpl* render_view, | 51 RenderViewImpl* render_view, |
| 52 ContentInstanceGlue* glue, |
| 49 IPC::Sender* host_to_plugin_sender, | 53 IPC::Sender* host_to_plugin_sender, |
| 50 const ppapi::PpapiPermissions& perms) | 54 const ppapi::PpapiPermissions& perms) |
| 51 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 55 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 52 factory_(render_view), | 56 factory_(render_view, perms, glue), |
| 53 host_(host_to_plugin_sender, &factory_, perms) { | 57 host_(host_to_plugin_sender, &factory_, perms) { |
| 54 } | 58 } |
| 55 | 59 |
| 56 bool PepperInProcessResourceCreation::PluginToHostRouter::Send( | 60 bool PepperInProcessResourceCreation::PluginToHostRouter::Send( |
| 57 IPC::Message* msg) { | 61 IPC::Message* msg) { |
| 58 // Don't directly call into the message handler to avoid reentrancy. The IPC | 62 // Don't directly call into the message handler to avoid reentrancy. The IPC |
| 59 // systen assumes everything is executed from the message loop, so emulate | 63 // systen assumes everything is executed from the message loop, so emulate |
| 60 // the same thing for in-process. | 64 // the same thing for in-process. |
| 61 MessageLoop::current()->PostTask(FROM_HERE, | 65 MessageLoop::current()->PostTask(FROM_HERE, |
| 62 base::Bind(&PluginToHostRouter::DoSend, weak_factory_.GetWeakPtr(), | 66 base::Bind(&PluginToHostRouter::DoSend, weak_factory_.GetWeakPtr(), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 nested_msg); | 133 nested_msg); |
| 130 } | 134 } |
| 131 | 135 |
| 132 // PepperInProcessResourceCreation -------------------------------------------- | 136 // PepperInProcessResourceCreation -------------------------------------------- |
| 133 | 137 |
| 134 PepperInProcessResourceCreation::PepperInProcessResourceCreation( | 138 PepperInProcessResourceCreation::PepperInProcessResourceCreation( |
| 135 RenderViewImpl* render_view, | 139 RenderViewImpl* render_view, |
| 136 webkit::ppapi::PluginInstance* instance, | 140 webkit::ppapi::PluginInstance* instance, |
| 137 const ppapi::PpapiPermissions& perms) | 141 const ppapi::PpapiPermissions& perms) |
| 138 : ResourceCreationImpl(instance), | 142 : ResourceCreationImpl(instance), |
| 143 instance_glue_(instance->module()), |
| 139 host_to_plugin_router_(new HostToPluginRouter), | 144 host_to_plugin_router_(new HostToPluginRouter), |
| 140 plugin_to_host_router_( | 145 plugin_to_host_router_( |
| 141 new PluginToHostRouter(render_view, host_to_plugin_router_.get(), | 146 new PluginToHostRouter(render_view, &instance_glue_, |
| 147 host_to_plugin_router_.get(), |
| 142 perms)) { | 148 perms)) { |
| 143 } | 149 } |
| 144 | 150 |
| 145 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() { | 151 PepperInProcessResourceCreation::~PepperInProcessResourceCreation() { |
| 146 } | 152 } |
| 147 | 153 |
| 154 PP_Resource PepperInProcessResourceCreation::CreateFileChooser( |
| 155 PP_Instance instance, |
| 156 PP_FileChooserMode_Dev mode, |
| 157 const char* accept_types) { |
| 158 return (new ppapi::proxy::FileChooserResource( |
| 159 plugin_to_host_router_.get(), |
| 160 instance, mode, accept_types))->GetReference(); |
| 161 } |
| 162 |
| 148 } // namespace content | 163 } // namespace content |
| OLD | NEW |