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