renderer_ppapi_host.h revision 868fa2fe829687343ffae624259930155e16dbd8
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_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
6#define CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/platform_file.h"
10#include "base/process.h"
11#include "content/common/content_export.h"
12#include "ipc/ipc_platform_file.h"
13#include "ppapi/c/pp_instance.h"
14#include "webkit/plugins/ppapi/plugin_delegate.h"
15
16namespace base {
17class FilePath;
18}
19
20namespace gfx {
21class Point;
22}
23
24namespace IPC {
25struct ChannelHandle;
26class Message;
27}
28
29namespace ppapi {
30class PpapiPermissions;
31namespace host {
32class PpapiHost;
33}
34}
35
36namespace WebKit {
37class WebPluginContainer;
38}
39
40namespace webkit {
41namespace ppapi {
42class PluginInstance;
43class PluginModule;
44}
45}
46
47namespace content {
48
49class RenderView;
50
51// Interface that allows components in the embedder app to talk to the
52// PpapiHost in the renderer process.
53//
54// There will be one of these objects in the renderer per plugin module.
55class RendererPpapiHost {
56 public:
57  // Creates a host and sets up an out-of-process proxy for an external plugin
58  // module. |file_path| should identify the module. It is only used to report
59  // failures to the renderer.
60  // Returns a host if the external module is proxied successfully, otherwise
61  // returns NULL.
62  CONTENT_EXPORT static RendererPpapiHost* CreateExternalPluginModule(
63      scoped_refptr<webkit::ppapi::PluginModule> plugin_module,
64      webkit::ppapi::PluginInstance* plugin_instance,
65      const base::FilePath& file_path,
66      ppapi::PpapiPermissions permissions,
67      const IPC::ChannelHandle& channel_handle,
68      base::ProcessId plugin_pid,
69      int plugin_child_id);
70
71  // Returns the RendererPpapiHost associated with the given PP_Instance,
72  // or NULL if the instance is invalid.
73  CONTENT_EXPORT static RendererPpapiHost* GetForPPInstance(
74      PP_Instance instance);
75
76  // Returns the PpapiHost object.
77  virtual ppapi::host::PpapiHost* GetPpapiHost() = 0;
78
79  // Returns true if the given PP_Instance is valid and belongs to the
80  // plugin associated with this host.
81  virtual bool IsValidInstance(PP_Instance instance) const = 0;
82
83  // Returns the PluginInstance for the given PP_Instance, or NULL if the
84  // PP_Instance is invalid (the common case this will be invalid is during
85  // plugin teardown when resource hosts are being force-freed).
86  virtual webkit::ppapi::PluginInstance* GetPluginInstance(
87      PP_Instance instance) const = 0;
88
89  // Returns the RenderView for the given plugin instance, or NULL if the
90  // instance is invalid.
91  virtual RenderView* GetRenderViewForInstance(PP_Instance instance) const = 0;
92
93  // Returns the WebPluginContainer for the given plugin instance, or NULL if
94  // the instance is invalid.
95  virtual WebKit::WebPluginContainer* GetContainerForInstance(
96      PP_Instance instance) const = 0;
97
98  // Returns the PID of the child process containing the plugin. If running
99  // in-process, this returns base::kNullProcessId.
100  virtual base::ProcessId GetPluginPID() const = 0;
101
102  // Returns true if the given instance is considered to be currently
103  // processing a user gesture or the plugin module has the "override user
104  // gesture" flag set (in which case it can always do things normally
105  // restricted by user gestures). Returns false if the instance is invalid or
106  // if there is no current user gesture.
107  virtual bool HasUserGesture(PP_Instance instance) const = 0;
108
109  // Returns the routing ID for the render widget containing the given
110  // instance. This will take into account the current Flash fullscreen state,
111  // so if there is a Flash fullscreen instance active, this will return the
112  // routing ID of the fullscreen widget. Returns 0 on failure.
113  virtual int GetRoutingIDForWidget(PP_Instance instance) const = 0;
114
115  // Converts the given plugin coordinate to the containing RenderView. This
116  // will take into account the current Flash fullscreen state so will use
117  // the fullscreen widget if it's displayed.
118  virtual gfx::Point PluginPointToRenderView(
119      PP_Instance instance,
120      const gfx::Point& pt) const = 0;
121
122  // Shares a file handle (HANDLE / file descriptor) with the remote side. It
123  // returns a handle that should be sent in exactly one IPC message. Upon
124  // receipt, the remote side then owns that handle. Note: if sending the
125  // message fails, the returned handle is properly closed by the IPC system. If
126  // |should_close_source| is set to true, the original handle is closed by this
127  // operation and should not be used again.
128  virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
129      base::PlatformFile handle,
130      bool should_close_source) = 0;
131
132  // Returns true if the plugin is running in process.
133  virtual bool IsRunningInProcess() const = 0;
134
135  // There are times when the renderer needs to create a ResourceHost in the
136  // browser. This function does so asynchronously. |nested_msg| is the
137  // resource host creation message and |instance| is the PP_Instance which
138  // the resource will belong to. |callback| will be called with the pending
139  // host ID when the ResourceHost has been created. This can be passed back
140  // to the plugin to attach to the ResourceHost. A pending ID of 0 will be
141  // passed to the callback upon error.
142  virtual void CreateBrowserResourceHost(
143      PP_Instance instance,
144      const IPC::Message& nested_msg,
145      const base::Callback<void(int)>& callback) const = 0;
146
147 protected:
148  virtual ~RendererPpapiHost() {}
149};
150
151}  // namespace content
152
153#endif  // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
154