- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / renderer_ppapi_host_impl.h
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
14 namespace IPC {
15 class Sender;
16 }
17
18 namespace ppapi {
19
20 namespace proxy {
21 class HostDispatcher;
22 }
23
24 namespace thunk {
25 class ResourceCreationAPI;
26 }
27
28 }  // namespace ppapi
29
30 namespace content {
31
32 class PepperInProcessRouter;
33 class PepperPluginInstanceImpl;
34 class PluginModule;
35
36 // This class is attached to a PluginModule which manages our lifetime.
37 class RendererPpapiHostImpl : public RendererPpapiHost {
38  public:
39   virtual ~RendererPpapiHostImpl();
40
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.
44   //
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(
48       PluginModule* module,
49       ppapi::proxy::HostDispatcher* dispatcher,
50       const ppapi::PpapiPermissions& permissions);
51   static RendererPpapiHostImpl* CreateOnModuleForInProcess(
52       PluginModule* module,
53       const ppapi::PpapiPermissions& permissions);
54
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);
58
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();
64   }
65
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);
73
74   PepperPluginInstanceImpl* GetPluginInstanceImpl(PP_Instance instance) const;
75
76   // RendererPpapiHost implementation.
77   virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE;
78   virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE;
79   virtual PepperPluginInstance* GetPluginInstance(
80       PP_Instance instance) const OVERRIDE;
81   virtual RenderView* GetRenderViewForInstance(
82       PP_Instance instance) const OVERRIDE;
83   virtual WebKit::WebPluginContainer* GetContainerForInstance(
84       PP_Instance instance) const OVERRIDE;
85   virtual base::ProcessId GetPluginPID() const OVERRIDE;
86   virtual bool HasUserGesture(PP_Instance instance) const OVERRIDE;
87   virtual int GetRoutingIDForWidget(PP_Instance instance) const OVERRIDE;
88   virtual gfx::Point PluginPointToRenderView(
89       PP_Instance instance,
90       const gfx::Point& pt) const OVERRIDE;
91   virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
92       base::PlatformFile handle,
93       bool should_close_source) OVERRIDE;
94   virtual bool IsRunningInProcess() const OVERRIDE;
95   virtual void CreateBrowserResourceHosts(
96       PP_Instance instance,
97       const std::vector<IPC::Message>& nested_msgs,
98       const base::Callback<void(
99           const std::vector<int>&)>& callback) const OVERRIDE;
100
101  private:
102   RendererPpapiHostImpl(PluginModule* module,
103                         ppapi::proxy::HostDispatcher* dispatcher,
104                         const ppapi::PpapiPermissions& permissions);
105   RendererPpapiHostImpl(PluginModule* module,
106                         const ppapi::PpapiPermissions& permissions);
107
108   // Retrieves the plugin instance object associated with the given PP_Instance
109   // and validates that it is one of the instances associated with our module.
110   // Returns NULL on failure.
111   //
112   // We use this to security check the PP_Instance values sent from a plugin to
113   // make sure it's not trying to spoof another instance.
114   PepperPluginInstanceImpl* GetAndValidateInstance(PP_Instance instance) const;
115
116   PluginModule* module_;  // Non-owning pointer.
117
118   // The dispatcher we use to send messagse when the plugin is out-of-process.
119   // Will be null when running in-process. Non-owning pointer.
120   ppapi::proxy::HostDispatcher* dispatcher_;
121
122   scoped_ptr<ppapi::host::PpapiHost> ppapi_host_;
123
124   // Null when running out-of-process.
125   scoped_ptr<PepperInProcessRouter> in_process_router_;
126
127   // Whether the plugin is running in process.
128   bool is_running_in_process_;
129
130   DISALLOW_COPY_AND_ASSIGN(RendererPpapiHostImpl);
131 };
132
133 }  // namespace content
134
135 #endif  // CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_