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