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 #ifndef CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/public/renderer/renderer_ppapi_host.h" |
| 11 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
| 12 #include "ppapi/host/ppapi_host.h" |
| 13 #include "webkit/plugins/ppapi/plugin_module.h" |
| 14 |
| 15 namespace IPC { |
| 16 class Sender; |
| 17 } |
| 18 |
| 19 namespace ppapi { |
| 20 |
| 21 namespace proxy { |
| 22 class HostDispatcher; |
| 23 } |
| 24 |
| 25 namespace thunk { |
| 26 class ResourceCreationAPI; |
| 27 } |
| 28 |
| 29 } // namespace ppapi |
| 30 |
| 31 namespace webkit { |
| 32 namespace ppapi { |
| 33 class PluginInstance; |
| 34 class PluginModule; |
| 35 } |
| 36 } |
| 37 |
| 38 namespace content { |
| 39 |
| 40 class PepperInProcessRouter; |
| 41 |
| 42 // This class is attached to a PluginModule via the module's embedder state. |
| 43 // The plugin module manages our lifetime. |
| 44 class RendererPpapiHostImpl |
| 45 : public RendererPpapiHost, |
| 46 public webkit::ppapi::PluginModule::EmbedderState { |
| 47 public: |
| 48 virtual ~RendererPpapiHostImpl(); |
| 49 |
| 50 // Factory functions to create in process or out-of-process host impls. The |
| 51 // host will be created and associated with the given module, which must not |
| 52 // already have embedder state on it. |
| 53 // |
| 54 // The module will take ownership of the new host impl. The returned value |
| 55 // does not pass ownership, it's just for the information of the caller. |
| 56 static RendererPpapiHostImpl* CreateOnModuleForOutOfProcess( |
| 57 webkit::ppapi::PluginModule* module, |
| 58 ppapi::proxy::HostDispatcher* dispatcher, |
| 59 const ppapi::PpapiPermissions& permissions); |
| 60 static RendererPpapiHostImpl* CreateOnModuleForInProcess( |
| 61 webkit::ppapi::PluginModule* module, |
| 62 const ppapi::PpapiPermissions& permissions); |
| 63 |
| 64 // Returns the router that we use for in-process IPC emulation (see the |
| 65 // pepper_in_process_router.h for more). This will be NULL when the plugin |
| 66 // is running out-of-process. |
| 67 PepperInProcessRouter* in_process_router() { |
| 68 return in_process_router_.get(); |
| 69 } |
| 70 |
| 71 // Creates the in-process resource creation API wrapper for the given |
| 72 // plugin instance. This object will reference the host impl, so the |
| 73 // host impl should outlive the returned pointer. Since the resource |
| 74 // creation object is associated with the instance, this will generally |
| 75 // happen automatically. |
| 76 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
| 77 CreateInProcessResourceCreationAPI( |
| 78 webkit::ppapi::PluginInstance* instance); |
| 79 |
| 80 // RendererPpapiHost. |
| 81 virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; |
| 82 virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE; |
| 83 virtual RenderView* GetRenderViewForInstance( |
| 84 PP_Instance instance) const OVERRIDE; |
| 85 virtual bool HasUserGesture(PP_Instance instance) const OVERRIDE; |
| 86 |
| 87 private: |
| 88 RendererPpapiHostImpl(webkit::ppapi::PluginModule* module, |
| 89 ppapi::proxy::HostDispatcher* dispatcher, |
| 90 const ppapi::PpapiPermissions& permissions); |
| 91 RendererPpapiHostImpl(webkit::ppapi::PluginModule* module, |
| 92 const ppapi::PpapiPermissions& permissions); |
| 93 |
| 94 // Retrieves the plugin instance object associated with the given PP_Instance |
| 95 // and validates that it is one of the instances associated with our module. |
| 96 // Returns NULL on failure. |
| 97 // |
| 98 // We use this to security check the PP_Instance values sent from a plugin to |
| 99 // make sure it's not trying to spoof another instance. |
| 100 webkit::ppapi::PluginInstance* GetAndValidateInstance( |
| 101 PP_Instance instance) const; |
| 102 |
| 103 webkit::ppapi::PluginModule* module_; // Non-owning pointer. |
| 104 |
| 105 ContentRendererPepperHostFactory host_factory_; |
| 106 scoped_ptr<ppapi::host::PpapiHost> ppapi_host_; |
| 107 |
| 108 // Null when running out-of-process. |
| 109 scoped_ptr<PepperInProcessRouter> in_process_router_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(RendererPpapiHostImpl); |
| 112 }; |
| 113 |
| 114 } // namespace content |
| 115 |
| 116 #endif // CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_ |
OLD | NEW |