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_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/platform_file.h"
13 #include "base/process/process.h"
14 #include "content/common/content_export.h"
15 #include "ipc/ipc_platform_file.h"
16 #include "ppapi/c/pp_instance.h"
37 class WebPluginContainer
;
41 class PepperPluginInstance
;
44 // Interface that allows components in the embedder app to talk to the
45 // PpapiHost in the renderer process.
47 // There will be one of these objects in the renderer per plugin module.
48 class RendererPpapiHost
{
50 // Returns the RendererPpapiHost associated with the given PP_Instance,
51 // or NULL if the instance is invalid.
53 // Do NOT use this when dealing with an "external plugin" that serves as a
54 // bootstrap to load a second plugin. This is because the two will share a
55 // PP_Instance, and the RendererPpapiHost* for the second plugin will be
56 // returned after we switch the proxy on.
57 CONTENT_EXPORT
static RendererPpapiHost
* GetForPPInstance(
58 PP_Instance instance
);
60 // Returns the PpapiHost object.
61 virtual ppapi::host::PpapiHost
* GetPpapiHost() = 0;
63 // Returns true if the given PP_Instance is valid and belongs to the
64 // plugin associated with this host.
65 virtual bool IsValidInstance(PP_Instance instance
) const = 0;
67 // Returns the PluginInstance for the given PP_Instance, or NULL if the
68 // PP_Instance is invalid (the common case this will be invalid is during
69 // plugin teardown when resource hosts are being force-freed).
70 virtual PepperPluginInstance
* GetPluginInstance(
71 PP_Instance instance
) const = 0;
73 // Returns the RenderView for the given plugin instance, or NULL if the
74 // instance is invalid.
75 virtual RenderView
* GetRenderViewForInstance(PP_Instance instance
) const = 0;
77 // Returns the WebPluginContainer for the given plugin instance, or NULL if
78 // the instance is invalid.
79 virtual WebKit::WebPluginContainer
* GetContainerForInstance(
80 PP_Instance instance
) const = 0;
82 // Returns the PID of the child process containing the plugin. If running
83 // in-process, this returns base::kNullProcessId.
84 virtual base::ProcessId
GetPluginPID() const = 0;
86 // Returns true if the given instance is considered to be currently
87 // processing a user gesture or the plugin module has the "override user
88 // gesture" flag set (in which case it can always do things normally
89 // restricted by user gestures). Returns false if the instance is invalid or
90 // if there is no current user gesture.
91 virtual bool HasUserGesture(PP_Instance instance
) const = 0;
93 // Returns the routing ID for the render widget containing the given
94 // instance. This will take into account the current Flash fullscreen state,
95 // so if there is a Flash fullscreen instance active, this will return the
96 // routing ID of the fullscreen widget. Returns 0 on failure.
97 virtual int GetRoutingIDForWidget(PP_Instance instance
) const = 0;
99 // Converts the given plugin coordinate to the containing RenderView. This
100 // will take into account the current Flash fullscreen state so will use
101 // the fullscreen widget if it's displayed.
102 virtual gfx::Point
PluginPointToRenderView(
103 PP_Instance instance
,
104 const gfx::Point
& pt
) const = 0;
106 // Shares a file handle (HANDLE / file descriptor) with the remote side. It
107 // returns a handle that should be sent in exactly one IPC message. Upon
108 // receipt, the remote side then owns that handle. Note: if sending the
109 // message fails, the returned handle is properly closed by the IPC system. If
110 // |should_close_source| is set to true, the original handle is closed by this
111 // operation and should not be used again.
112 virtual IPC::PlatformFileForTransit
ShareHandleWithRemote(
113 base::PlatformFile handle
,
114 bool should_close_source
) = 0;
116 // Returns true if the plugin is running in process.
117 virtual bool IsRunningInProcess() const = 0;
119 // There are times when the renderer needs to create a ResourceHost in the
120 // browser. This function does so asynchronously. |nested_msgs| is a list of
121 // resource host creation messages and |instance| is the PP_Instance which
122 // the resource will belong to. |callback| will be called asynchronously with
123 // the pending host IDs when the ResourceHosts have been created. This can be
124 // passed back to the plugin to attach to the ResourceHosts. Pending IDs of 0
125 // will be passed to the callback if a ResourceHost fails to be created.
126 virtual void CreateBrowserResourceHosts(
127 PP_Instance instance
,
128 const std::vector
<IPC::Message
>& nested_msgs
,
129 const base::Callback
<void(const std::vector
<int>&)>& callback
) const = 0;
132 virtual ~RendererPpapiHost() {}
135 } // namespace content
137 #endif // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_