#ifndef CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_
#define CONTENT_RENDERER_PEPPER_RENDERER_PPAPI_HOST_IMPL_H_
#include <memory>
#include "content/common/content_export.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
#include "ppapi/host/ppapi_host.h"
namespace ppapi {
namespace proxy {
class HostDispatcher;
}
namespace thunk {
class ResourceCreationAPI;
}
}
namespace content {
class PepperInProcessRouter;
class PepperPluginInstanceImpl;
class PluginModule;
class RendererPpapiHostImpl : public RendererPpapiHost {
public:
RendererPpapiHostImpl(const RendererPpapiHostImpl&) = delete;
RendererPpapiHostImpl& operator=(const RendererPpapiHostImpl&) = delete;
~RendererPpapiHostImpl() override;
static RendererPpapiHostImpl* CreateOnModuleForOutOfProcess(
PluginModule* module,
ppapi::proxy::HostDispatcher* dispatcher,
const ppapi::PpapiPermissions& permissions);
CONTENT_EXPORT static RendererPpapiHostImpl* CreateOnModuleForInProcess(
PluginModule* module,
const ppapi::PpapiPermissions& permissions);
static RendererPpapiHostImpl* GetForPPInstance(PP_Instance pp_instance);
PepperInProcessRouter* in_process_router() {
return in_process_router_.get();
}
std::unique_ptr<ppapi::thunk::ResourceCreationAPI>
CreateInProcessResourceCreationAPI(PepperPluginInstanceImpl* instance);
PepperPluginInstanceImpl* GetPluginInstanceImpl(PP_Instance instance) const;
bool IsExternalPluginHost() const;
ppapi::host::PpapiHost* GetPpapiHost() override;
bool IsValidInstance(PP_Instance instance) override;
PepperPluginInstance* GetPluginInstance(PP_Instance instance) override;
RenderFrame* GetRenderFrameForInstance(PP_Instance instance) override;
blink::WebPluginContainer* GetContainerForInstance(
PP_Instance instance) override;
bool HasUserGesture(PP_Instance instance) override;
int GetRoutingIDForFrame(PP_Instance instance) override;
gfx::Point PluginPointToRenderFrame(PP_Instance instance,
const gfx::Point& pt) override;
IPC::PlatformFileForTransit ShareHandleWithRemote(
base::PlatformFile handle,
bool should_close_source) override;
base::UnsafeSharedMemoryRegion ShareUnsafeSharedMemoryRegionWithRemote(
const base::UnsafeSharedMemoryRegion& region) override;
base::ReadOnlySharedMemoryRegion ShareReadOnlySharedMemoryRegionWithRemote(
const base::ReadOnlySharedMemoryRegion& region) override;
bool IsRunningInProcess() override;
std::string GetPluginName() override;
void SetToExternalPluginHost() override;
void CreateBrowserResourceHosts(
PP_Instance instance,
const std::vector<IPC::Message>& nested_msgs,
base::OnceCallback<void(const std::vector<int>&)> callback) override;
GURL GetDocumentURL(PP_Instance pp_instance) override;
bool IsSecureContext(PP_Instance pp_instance) const;
int GetPluginChildId() const;
void set_viewport_to_dip_scale(float viewport_to_dip_scale) {
DCHECK_LT(0, viewport_to_dip_scale_);
viewport_to_dip_scale_ = viewport_to_dip_scale;
}
private:
RendererPpapiHostImpl(PluginModule* module,
ppapi::proxy::HostDispatcher* dispatcher,
const ppapi::PpapiPermissions& permissions);
RendererPpapiHostImpl(PluginModule* module,
const ppapi::PpapiPermissions& permissions);
PepperPluginInstanceImpl* GetAndValidateInstance(PP_Instance instance) const;
PluginModule* module_;
ppapi::proxy::HostDispatcher* dispatcher_;
std::unique_ptr<ppapi::host::PpapiHost> ppapi_host_;
std::unique_ptr<PepperInProcessRouter> in_process_router_;
bool is_running_in_process_;
bool is_external_plugin_host_;
float viewport_to_dip_scale_ = 1.0f;
};
}
#endif