Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / public / renderer / renderer_ppapi_host.h
blob00f23c0c7b38aae663d68f6e2f68ea4eb9068779
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_
8 #include <vector>
10 #include "base/callback_forward.h"
11 #include "base/files/file.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/process/process.h"
15 #include "content/common/content_export.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "ppapi/c/pp_instance.h"
18 #include "url/gurl.h"
20 namespace base {
21 class FilePath;
24 namespace gfx {
25 class Point;
28 namespace IPC {
29 class Message;
32 namespace ppapi {
33 namespace host {
34 class PpapiHost;
38 namespace blink {
39 class WebPluginContainer;
42 namespace content {
43 class PepperPluginInstance;
44 class RenderFrame;
45 class RenderView;
47 // Interface that allows components in the embedder app to talk to the
48 // PpapiHost in the renderer process.
50 // There will be one of these objects in the renderer per plugin module.
51 class RendererPpapiHost {
52 public:
53 // Returns the RendererPpapiHost associated with the given PP_Instance,
54 // or NULL if the instance is invalid.
56 // Do NOT use this when dealing with an "external plugin" that serves as a
57 // bootstrap to load a second plugin. This is because the two will share a
58 // PP_Instance, and the RendererPpapiHost* for the second plugin will be
59 // returned after we switch the proxy on.
60 CONTENT_EXPORT static RendererPpapiHost* GetForPPInstance(
61 PP_Instance instance);
63 // Returns the PpapiHost object.
64 virtual ppapi::host::PpapiHost* GetPpapiHost() = 0;
66 // Returns true if the given PP_Instance is valid and belongs to the
67 // plugin associated with this host.
68 virtual bool IsValidInstance(PP_Instance instance) const = 0;
70 // Returns the PluginInstance for the given PP_Instance, or NULL if the
71 // PP_Instance is invalid (the common case this will be invalid is during
72 // plugin teardown when resource hosts are being force-freed).
73 virtual PepperPluginInstance* GetPluginInstance(
74 PP_Instance instance) const = 0;
76 // Returns the RenderFrame for the given plugin instance, or NULL if the
77 // instance is invalid.
78 virtual RenderFrame* GetRenderFrameForInstance(
79 PP_Instance instance) const = 0;
81 // Returns the RenderView for the given plugin instance, or NULL if the
82 // instance is invalid.
83 virtual RenderView* GetRenderViewForInstance(PP_Instance instance) const = 0;
85 // Returns the WebPluginContainer for the given plugin instance, or NULL if
86 // the instance is invalid.
87 virtual blink::WebPluginContainer* GetContainerForInstance(
88 PP_Instance instance) const = 0;
90 // Returns the PID of the child process containing the plugin. If running
91 // in-process, this returns base::kNullProcessId.
92 virtual base::ProcessId GetPluginPID() const = 0;
94 // Returns true if the given instance is considered to be currently
95 // processing a user gesture or the plugin module has the "override user
96 // gesture" flag set (in which case it can always do things normally
97 // restricted by user gestures). Returns false if the instance is invalid or
98 // if there is no current user gesture.
99 virtual bool HasUserGesture(PP_Instance instance) const = 0;
101 // Returns the routing ID for the render widget containing the given
102 // instance. This will take into account the current Flash fullscreen state,
103 // so if there is a Flash fullscreen instance active, this will return the
104 // routing ID of the fullscreen widget. Returns 0 on failure.
105 virtual int GetRoutingIDForWidget(PP_Instance instance) const = 0;
107 // Converts the given plugin coordinate to the containing RenderFrame. This
108 // will take into account the current Flash fullscreen state so will use
109 // the fullscreen widget if it's displayed.
110 virtual gfx::Point PluginPointToRenderFrame(
111 PP_Instance instance,
112 const gfx::Point& pt) const = 0;
114 // Shares a file handle (HANDLE / file descriptor) with the remote side. It
115 // returns a handle that should be sent in exactly one IPC message. Upon
116 // receipt, the remote side then owns that handle. Note: if sending the
117 // message fails, the returned handle is properly closed by the IPC system. If
118 // |should_close_source| is set to true, the original handle is closed by this
119 // operation and should not be used again.
120 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
121 base::PlatformFile handle,
122 bool should_close_source) = 0;
124 // Shares a shared memory handle with the remote side. It
125 // returns a handle that should be sent in exactly one IPC message. Upon
126 // receipt, the remote side then owns that handle. Note: if sending the
127 // message fails, the returned handle is properly closed by the IPC system.
128 virtual base::SharedMemoryHandle ShareSharedMemoryHandleWithRemote(
129 const base::SharedMemoryHandle& handle) = 0;
131 // Returns true if the plugin is running in process.
132 virtual bool IsRunningInProcess() const = 0;
134 virtual std::string GetPluginName() const = 0;
136 // Used by the embedder to inform this RendererPpapiHost that the associated
137 // plugin module is a host for "external plugins."
139 // An embedder may, at the time a plugin module is created, configure it to
140 // be a host for external plugins. Instances of such plugins go through two
141 // two stages of initialization; the first stage initializes a host plugin
142 // instance, which then loads and initializes a child plugin which takes
143 // over control. These are treated as one Pepper Instance, because despite the
144 // two-stage initialization process, the host and child appear to blink as
145 // one plugin instance.
147 // The host plugin appears as an in-process plugin, while we interact with the
148 // child plugin via the Pepper proxy.
149 virtual void SetToExternalPluginHost() = 0;
151 // There are times when the renderer needs to create a ResourceHost in the
152 // browser. This function does so asynchronously. |nested_msgs| is a list of
153 // resource host creation messages and |instance| is the PP_Instance which
154 // the resource will belong to. |callback| will be called asynchronously with
155 // the pending host IDs when the ResourceHosts have been created. This can be
156 // passed back to the plugin to attach to the ResourceHosts. Pending IDs of 0
157 // will be passed to the callback if a ResourceHost fails to be created.
158 virtual void CreateBrowserResourceHosts(
159 PP_Instance instance,
160 const std::vector<IPC::Message>& nested_msgs,
161 const base::Callback<void(const std::vector<int>&)>& callback) const = 0;
163 // Gets the URL of the document containing the given PP_Instance.
164 // Returns an empty URL if the instance is invalid.
165 // TODO(yzshen): Some methods such as this one don't need to be pure virtual.
166 // Instead, they could be directly implemented using other methods in this
167 // interface. Consider changing them to static helpers.
168 virtual GURL GetDocumentURL(PP_Instance instance) const = 0;
170 protected:
171 virtual ~RendererPpapiHost() {}
174 } // namespace content
176 #endif // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_