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