| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 5 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 8 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" | 9 #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_in_process_router.h" |
| 10 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 11 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 11 #include "content/renderer/render_view_impl.h" | 12 #include "content/renderer/render_view_impl.h" |
| 12 #include "ppapi/proxy/host_dispatcher.h" | 13 #include "ppapi/proxy/host_dispatcher.h" |
| 13 #include "webkit/plugins/ppapi/host_globals.h" | 14 #include "webkit/plugins/ppapi/host_globals.h" |
| 15 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 15 | 17 |
| 16 using webkit::ppapi::HostGlobals; | 18 using webkit::ppapi::HostGlobals; |
| 17 using webkit::ppapi::PluginInstance; | 19 using webkit::ppapi::PluginInstance; |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 // Out-of-process constructor. | 23 // Out-of-process constructor. |
| 22 RendererPpapiHostImpl::RendererPpapiHostImpl( | 24 RendererPpapiHostImpl::RendererPpapiHostImpl( |
| 23 webkit::ppapi::PluginModule* module, | 25 webkit::ppapi::PluginModule* module, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 instance->module()->GetEmbedderState()); | 94 instance->module()->GetEmbedderState()); |
| 93 } | 95 } |
| 94 | 96 |
| 95 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> | 97 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
| 96 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( | 98 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( |
| 97 webkit::ppapi::PluginInstance* instance) { | 99 webkit::ppapi::PluginInstance* instance) { |
| 98 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( | 100 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( |
| 99 new PepperInProcessResourceCreation(this, instance)); | 101 new PepperInProcessResourceCreation(this, instance)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { | 104 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() const { |
| 103 return ppapi_host_.get(); | 105 return ppapi_host_.get(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( | 108 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( |
| 107 PP_Instance instance) const { | 109 PP_Instance instance) const { |
| 108 PluginInstance* instance_object = GetAndValidateInstance(instance); | 110 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 109 if (!instance_object) | 111 if (!instance_object) |
| 110 return NULL; | 112 return NULL; |
| 111 | 113 |
| 112 // Since we're the embedder, we can make assumptions about the delegate on | 114 // Since we're the embedder, we can make assumptions about the delegate on |
| 113 // the instance and get back to our RenderView. | 115 // the instance and get back to our RenderView. |
| 114 return static_cast<PepperPluginDelegateImpl*>( | 116 return static_cast<PepperPluginDelegateImpl*>( |
| 115 instance_object->delegate())->render_view(); | 117 instance_object->delegate())->render_view(); |
| 116 } | 118 } |
| 117 | 119 |
| 120 webkit::ppapi::PluginDelegate::PlatformGraphics2D* |
| 121 RendererPpapiHostImpl::GetPlatformGraphics2D( |
| 122 PP_Resource resource) const { |
| 123 ppapi::host::PpapiHost* ppapi_host = GetPpapiHost(); |
| 124 // Make sure the resource from the plugin is a known one, so that we can cast |
| 125 // it safely. |
| 126 if (!ppapi_host->IsGraphics2DResource(resource)) { |
| 127 LOG(ERROR) << "Resource is not Graphics2d"; |
| 128 return NULL; |
| 129 } |
| 130 return static_cast<PepperGraphics2DHost*>( |
| 131 ppapi_host->GetResourceHost(resource)); |
| 132 } |
| 133 |
| 118 bool RendererPpapiHostImpl::IsValidInstance( | 134 bool RendererPpapiHostImpl::IsValidInstance( |
| 119 PP_Instance instance) const { | 135 PP_Instance instance) const { |
| 120 return !!GetAndValidateInstance(instance); | 136 return !!GetAndValidateInstance(instance); |
| 121 } | 137 } |
| 122 | 138 |
| 123 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { | 139 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { |
| 124 PluginInstance* instance_object = GetAndValidateInstance(instance); | 140 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 125 if (!instance_object) | 141 if (!instance_object) |
| 126 return false; | 142 return false; |
| 127 | 143 |
| 128 if (instance_object->module()->permissions().HasPermission( | 144 if (instance_object->module()->permissions().HasPermission( |
| 129 ppapi::PERMISSION_BYPASS_USER_GESTURE)) | 145 ppapi::PERMISSION_BYPASS_USER_GESTURE)) |
| 130 return true; | 146 return true; |
| 131 return instance_object->IsProcessingUserGesture(); | 147 return instance_object->IsProcessingUserGesture(); |
| 132 } | 148 } |
| 133 | 149 |
| 134 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( | 150 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( |
| 135 PP_Instance pp_instance) const { | 151 PP_Instance pp_instance) const { |
| 136 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 152 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 137 if (!instance) | 153 if (!instance) |
| 138 return NULL; | 154 return NULL; |
| 139 if (instance->module() != module_) | 155 if (instance->module() != module_) |
| 140 return NULL; | 156 return NULL; |
| 141 return instance; | 157 return instance; |
| 142 } | 158 } |
| 143 | 159 |
| 144 } // namespace content | 160 } // namespace content |
| OLD | NEW |