renderer_ppapi_host.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 PlatformGraphics2D for the given plugin resource, or NULL if 98 // the resource is invalid. 99 virtual webkit::ppapi::PluginDelegate::PlatformGraphics2D* 100 GetPlatformGraphics2D(PP_Resource resource) = 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 protected: 136 virtual ~RendererPpapiHost() {} 137}; 138 139} // namespace content 140 141#endif // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_ 142