OLD | NEW |
(Empty) | |
| 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 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
| 9 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 10 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 11 #include "content/renderer/render_view_impl.h" |
| 12 #include "ppapi/proxy/host_dispatcher.h" |
| 13 #include "webkit/plugins/ppapi/host_globals.h" |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 15 |
| 16 using webkit::ppapi::HostGlobals; |
| 17 using webkit::ppapi::PluginInstance; |
| 18 |
| 19 namespace content { |
| 20 |
| 21 // Out-of-process constructor. |
| 22 RendererPpapiHostImpl::RendererPpapiHostImpl( |
| 23 webkit::ppapi::PluginModule* module, |
| 24 ppapi::proxy::HostDispatcher* dispatcher, |
| 25 const ppapi::PpapiPermissions& permissions) |
| 26 : module_(module), |
| 27 host_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 28 // Hook the PpapiHost up to the dispatcher for out-of-process communication. |
| 29 ppapi_host_.reset( |
| 30 new ppapi::host::PpapiHost(dispatcher, &host_factory_, permissions)); |
| 31 dispatcher->AddFilter(ppapi_host_.get()); |
| 32 } |
| 33 |
| 34 // In-process constructor. |
| 35 RendererPpapiHostImpl::RendererPpapiHostImpl( |
| 36 webkit::ppapi::PluginModule* module, |
| 37 const ppapi::PpapiPermissions& permissions) |
| 38 : module_(module), |
| 39 host_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 40 // Hook the host up to the in-process router. |
| 41 in_process_router_.reset(new PepperInProcessRouter(this)); |
| 42 ppapi_host_.reset(new ppapi::host::PpapiHost( |
| 43 in_process_router_->GetRendererToPluginSender(), |
| 44 &host_factory_, permissions)); |
| 45 } |
| 46 |
| 47 RendererPpapiHostImpl::~RendererPpapiHostImpl() { |
| 48 } |
| 49 |
| 50 // static |
| 51 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
| 52 webkit::ppapi::PluginModule* module, |
| 53 ppapi::proxy::HostDispatcher* dispatcher, |
| 54 const ppapi::PpapiPermissions& permissions) { |
| 55 DCHECK(!module->GetEmbedderState()); |
| 56 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( |
| 57 module, dispatcher, permissions); |
| 58 |
| 59 // Takes ownership of pointer. |
| 60 module->SetEmbedderState( |
| 61 scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result)); |
| 62 |
| 63 return result; |
| 64 } |
| 65 |
| 66 // static |
| 67 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess( |
| 68 webkit::ppapi::PluginModule* module, |
| 69 const ppapi::PpapiPermissions& permissions) { |
| 70 DCHECK(!module->GetEmbedderState()); |
| 71 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( |
| 72 module, permissions); |
| 73 |
| 74 // Takes ownership of pointer. |
| 75 module->SetEmbedderState( |
| 76 scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result)); |
| 77 |
| 78 return result; |
| 79 } |
| 80 |
| 81 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
| 82 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( |
| 83 webkit::ppapi::PluginInstance* instance) { |
| 84 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( |
| 85 new PepperInProcessResourceCreation(this, instance)); |
| 86 } |
| 87 |
| 88 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { |
| 89 return ppapi_host_.get(); |
| 90 } |
| 91 |
| 92 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( |
| 93 PP_Instance instance) const { |
| 94 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 95 if (!instance_object) |
| 96 return NULL; |
| 97 |
| 98 // Since we're the embedder, we can make assumptions about the delegate on |
| 99 // the instance and get back to our RenderView. |
| 100 return static_cast<PepperPluginDelegateImpl*>( |
| 101 instance_object->delegate())->render_view(); |
| 102 } |
| 103 |
| 104 bool RendererPpapiHostImpl::IsValidInstance( |
| 105 PP_Instance instance) const { |
| 106 return !!GetAndValidateInstance(instance); |
| 107 } |
| 108 |
| 109 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { |
| 110 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 111 if (!instance_object) |
| 112 return false; |
| 113 |
| 114 if (instance_object->module()->permissions().HasPermission( |
| 115 ppapi::PERMISSION_BYPASS_USER_GESTURE)) |
| 116 return true; |
| 117 return instance_object->IsProcessingUserGesture(); |
| 118 } |
| 119 |
| 120 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( |
| 121 PP_Instance pp_instance) const { |
| 122 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 123 if (!instance) |
| 124 return NULL; |
| 125 if (instance->module() != module_) |
| 126 return NULL; |
| 127 return instance; |
| 128 } |
| 129 |
| 130 } // namespace content |
OLD | NEW |