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.
5 #ifndef CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_
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"
25 class ResourceCreationAPI
;
32 class PepperInProcessRouter
;
33 class PepperPluginInstanceImpl
;
36 // This class is attached to a PluginModule which manages our lifetime.
37 class RendererPpapiHostImpl
: public RendererPpapiHost
{
39 ~RendererPpapiHostImpl() override
;
41 // Factory functions to create in process or out-of-process host impls. The
42 // host will be created and associated with the given module, which must not
43 // already have embedder state on it.
45 // The module will take ownership of the new host impl. The returned value
46 // does not pass ownership, it's just for the information of the caller.
47 static RendererPpapiHostImpl
* CreateOnModuleForOutOfProcess(
49 ppapi::proxy::HostDispatcher
* dispatcher
,
50 const ppapi::PpapiPermissions
& permissions
);
51 static RendererPpapiHostImpl
* CreateOnModuleForInProcess(
53 const ppapi::PpapiPermissions
& permissions
);
55 // Returns the RendererPpapiHostImpl associated with the given PP_Instance,
56 // or NULL if the instance is invalid.
57 static RendererPpapiHostImpl
* GetForPPInstance(PP_Instance pp_instance
);
59 // Returns the router that we use for in-process IPC emulation (see the
60 // pepper_in_process_router.h for more). This will be NULL when the plugin
61 // is running out-of-process.
62 PepperInProcessRouter
* in_process_router() {
63 return in_process_router_
.get();
66 // Creates the in-process resource creation API wrapper for the given
67 // plugin instance. This object will reference the host impl, so the
68 // host impl should outlive the returned pointer. Since the resource
69 // creation object is associated with the instance, this will generally
70 // happen automatically.
71 scoped_ptr
<ppapi::thunk::ResourceCreationAPI
>
72 CreateInProcessResourceCreationAPI(PepperPluginInstanceImpl
* instance
);
74 PepperPluginInstanceImpl
* GetPluginInstanceImpl(PP_Instance instance
) const;
76 bool IsExternalPluginHost() const;
78 // RendererPpapiHost implementation.
79 ppapi::host::PpapiHost
* GetPpapiHost() override
;
80 bool IsValidInstance(PP_Instance instance
) const override
;
81 PepperPluginInstance
* GetPluginInstance(PP_Instance instance
) const override
;
82 RenderFrame
* GetRenderFrameForInstance(PP_Instance instance
) const override
;
83 RenderView
* GetRenderViewForInstance(PP_Instance instance
) const override
;
84 blink::WebPluginContainer
* GetContainerForInstance(
85 PP_Instance instance
) const override
;
86 base::ProcessId
GetPluginPID() const override
;
87 bool HasUserGesture(PP_Instance instance
) const override
;
88 int GetRoutingIDForWidget(PP_Instance instance
) const override
;
89 gfx::Point
PluginPointToRenderFrame(PP_Instance instance
,
90 const gfx::Point
& pt
) const override
;
91 IPC::PlatformFileForTransit
ShareHandleWithRemote(
92 base::PlatformFile handle
,
93 bool should_close_source
) override
;
94 base::SharedMemoryHandle
ShareSharedMemoryHandleWithRemote(
95 const base::SharedMemoryHandle
& handle
) override
;
96 bool IsRunningInProcess() const override
;
97 std::string
GetPluginName() const override
;
98 void SetToExternalPluginHost() override
;
99 void CreateBrowserResourceHosts(
100 PP_Instance instance
,
101 const std::vector
<IPC::Message
>& nested_msgs
,
102 const base::Callback
<void(const std::vector
<int>&)>& callback
)
104 GURL
GetDocumentURL(PP_Instance pp_instance
) const override
;
107 RendererPpapiHostImpl(PluginModule
* module
,
108 ppapi::proxy::HostDispatcher
* dispatcher
,
109 const ppapi::PpapiPermissions
& permissions
);
110 RendererPpapiHostImpl(PluginModule
* module
,
111 const ppapi::PpapiPermissions
& permissions
);
113 // Retrieves the plugin instance object associated with the given PP_Instance
114 // and validates that it is one of the instances associated with our module.
115 // Returns NULL on failure.
117 // We use this to security check the PP_Instance values sent from a plugin to
118 // make sure it's not trying to spoof another instance.
119 PepperPluginInstanceImpl
* GetAndValidateInstance(PP_Instance instance
) const;
121 PluginModule
* module_
; // Non-owning pointer.
123 // The dispatcher we use to send messagse when the plugin is out-of-process.
124 // Will be null when running in-process. Non-owning pointer.
125 ppapi::proxy::HostDispatcher
* dispatcher_
;
127 scoped_ptr
<ppapi::host::PpapiHost
> ppapi_host_
;
129 // Null when running out-of-process.
130 scoped_ptr
<PepperInProcessRouter
> in_process_router_
;
132 // Whether the plugin is running in process.
133 bool is_running_in_process_
;
135 // Whether this is a host for external plugins.
136 bool is_external_plugin_host_
;
138 DISALLOW_COPY_AND_ASSIGN(RendererPpapiHostImpl
);
141 } // namespace content
143 #endif // CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_