renderer_ppapi_host.h revision a3f7b4e666c476898878fa745f637129375cd889
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 {
25class Message;
26}
27
28namespace ppapi {
29namespace host {
30class PpapiHost;
31}
32}
33
34namespace WebKit {
35class WebPluginContainer;
36}
37
38namespace webkit {
39namespace ppapi {
40class PluginInstance;
41class PluginModule;
42}
43}
44
45namespace content {
46
47class RenderView;
48
49// Interface that allows components in the embedder app to talk to the
50// PpapiHost in the renderer process.
51//
52// There will be one of these objects in the renderer per plugin module.
53class RendererPpapiHost {
54 public:
55  // Returns the RendererPpapiHost associated with the given PP_Instance,
56  // or NULL if the instance is invalid.
57  CONTENT_EXPORT static RendererPpapiHost* GetForPPInstance(
58      PP_Instance instance);
59
60  // Returns the PpapiHost object.
61  virtual ppapi::host::PpapiHost* GetPpapiHost() = 0;
62
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;
66
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 webkit::ppapi::PluginInstance* GetPluginInstance(
71      PP_Instance instance) const = 0;
72
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;
76
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;
81
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;
85
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;
92
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;
98
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;
105
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;
115
116  // Returns true if the plugin is running in process.
117  virtual bool IsRunningInProcess() const = 0;
118
119  // There are times when the renderer needs to create a ResourceHost in the
120  // browser. This function does so asynchronously. |nested_msg| is the
121  // resource host creation message and |instance| is the PP_Instance which
122  // the resource will belong to. |callback| will be called with the pending
123  // host ID when the ResourceHost has been created. This can be passed back
124  // to the plugin to attach to the ResourceHost. A pending ID of 0 will be
125  // passed to the callback upon error.
126  virtual void CreateBrowserResourceHost(
127      PP_Instance instance,
128      const IPC::Message& nested_msg,
129      const base::Callback<void(int)>& callback) const = 0;
130
131 protected:
132  virtual ~RendererPpapiHost() {}
133};
134
135}  // namespace content
136
137#endif  // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
138