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