| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 9 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" | 10 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
| 10 #include "content/renderer/pepper/pepper_in_process_router.h" | 11 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 11 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 12 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 12 #include "content/renderer/render_view_impl.h" | 13 #include "content/renderer/render_view_impl.h" |
| 14 #include "ppapi/host/ppapi_host.h" |
| 13 #include "ppapi/proxy/host_dispatcher.h" | 15 #include "ppapi/proxy/host_dispatcher.h" |
| 14 #include "webkit/plugins/ppapi/host_globals.h" | 16 #include "webkit/plugins/ppapi/host_globals.h" |
| 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 15 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
| 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 17 | 20 |
| 18 using webkit::ppapi::HostGlobals; | 21 using webkit::ppapi::HostGlobals; |
| 19 using webkit::ppapi::PluginInstance; | 22 using webkit::ppapi::PluginInstance; |
| 20 using webkit::ppapi::PluginModule; | 23 using webkit::ppapi::PluginModule; |
| 21 | 24 |
| 22 namespace content { | 25 namespace content { |
| 23 | 26 |
| 24 // static | 27 // static |
| (...skipping 27 matching lines...) Expand all Loading... |
| 52 PluginModule* module, | 55 PluginModule* module, |
| 53 ppapi::proxy::HostDispatcher* dispatcher, | 56 ppapi::proxy::HostDispatcher* dispatcher, |
| 54 const ppapi::PpapiPermissions& permissions) | 57 const ppapi::PpapiPermissions& permissions) |
| 55 : module_(module) { | 58 : module_(module) { |
| 56 // Hook the PpapiHost up to the dispatcher for out-of-process communication. | 59 // Hook the PpapiHost up to the dispatcher for out-of-process communication. |
| 57 ppapi_host_.reset( | 60 ppapi_host_.reset( |
| 58 new ppapi::host::PpapiHost(dispatcher, permissions)); | 61 new ppapi::host::PpapiHost(dispatcher, permissions)); |
| 59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 62 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
| 60 new ContentRendererPepperHostFactory(this))); | 63 new ContentRendererPepperHostFactory(this))); |
| 61 dispatcher->AddFilter(ppapi_host_.get()); | 64 dispatcher->AddFilter(ppapi_host_.get()); |
| 65 is_running_in_process_ = false; |
| 62 } | 66 } |
| 63 | 67 |
| 64 // In-process constructor. | 68 // In-process constructor. |
| 65 RendererPpapiHostImpl::RendererPpapiHostImpl( | 69 RendererPpapiHostImpl::RendererPpapiHostImpl( |
| 66 PluginModule* module, | 70 PluginModule* module, |
| 67 const ppapi::PpapiPermissions& permissions) | 71 const ppapi::PpapiPermissions& permissions) |
| 68 : module_(module) { | 72 : module_(module) { |
| 69 // Hook the host up to the in-process router. | 73 // Hook the host up to the in-process router. |
| 70 in_process_router_.reset(new PepperInProcessRouter(this)); | 74 in_process_router_.reset(new PepperInProcessRouter(this)); |
| 71 ppapi_host_.reset(new ppapi::host::PpapiHost( | 75 ppapi_host_.reset(new ppapi::host::PpapiHost( |
| 72 in_process_router_->GetRendererToPluginSender(), permissions)); | 76 in_process_router_->GetRendererToPluginSender(), permissions)); |
| 73 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 77 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
| 74 new ContentRendererPepperHostFactory(this))); | 78 new ContentRendererPepperHostFactory(this))); |
| 79 is_running_in_process_ = true; |
| 75 } | 80 } |
| 76 | 81 |
| 77 RendererPpapiHostImpl::~RendererPpapiHostImpl() { | 82 RendererPpapiHostImpl::~RendererPpapiHostImpl() { |
| 78 } | 83 } |
| 79 | 84 |
| 80 // static | 85 // static |
| 81 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 86 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
| 82 PluginModule* module, | 87 PluginModule* module, |
| 83 ppapi::proxy::HostDispatcher* dispatcher, | 88 ppapi::proxy::HostDispatcher* dispatcher, |
| 84 const ppapi::PpapiPermissions& permissions) { | 89 const ppapi::PpapiPermissions& permissions) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 PluginInstance* instance_object = GetAndValidateInstance(instance); | 142 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 138 if (!instance_object) | 143 if (!instance_object) |
| 139 return NULL; | 144 return NULL; |
| 140 | 145 |
| 141 // Since we're the embedder, we can make assumptions about the delegate on | 146 // Since we're the embedder, we can make assumptions about the delegate on |
| 142 // the instance and get back to our RenderView. | 147 // the instance and get back to our RenderView. |
| 143 return static_cast<PepperPluginDelegateImpl*>( | 148 return static_cast<PepperPluginDelegateImpl*>( |
| 144 instance_object->delegate())->render_view(); | 149 instance_object->delegate())->render_view(); |
| 145 } | 150 } |
| 146 | 151 |
| 152 webkit::ppapi::PluginDelegate::PlatformGraphics2D* |
| 153 RendererPpapiHostImpl::GetPlatformGraphics2D( |
| 154 PP_Resource resource) { |
| 155 ppapi::host::ResourceHost* resource_host = |
| 156 GetPpapiHost()->GetResourceHost(resource); |
| 157 if (!resource_host || !resource_host->IsGraphics2DHost()) { |
| 158 DLOG(ERROR) << "Resource is not Graphics2D"; |
| 159 return NULL; |
| 160 } |
| 161 return static_cast<PepperGraphics2DHost*>(resource_host); |
| 162 } |
| 163 |
| 147 bool RendererPpapiHostImpl::IsValidInstance( | 164 bool RendererPpapiHostImpl::IsValidInstance( |
| 148 PP_Instance instance) const { | 165 PP_Instance instance) const { |
| 149 return !!GetAndValidateInstance(instance); | 166 return !!GetAndValidateInstance(instance); |
| 150 } | 167 } |
| 151 | 168 |
| 152 WebKit::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( | 169 WebKit::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( |
| 153 PP_Instance instance) const { | 170 PP_Instance instance) const { |
| 154 PluginInstance* instance_object = GetAndValidateInstance(instance); | 171 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 155 if (!instance_object) | 172 if (!instance_object) |
| 156 return NULL; | 173 return NULL; |
| 157 return instance_object->container(); | 174 return instance_object->container(); |
| 158 } | 175 } |
| 159 | 176 |
| 160 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { | 177 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { |
| 161 PluginInstance* instance_object = GetAndValidateInstance(instance); | 178 PluginInstance* instance_object = GetAndValidateInstance(instance); |
| 162 if (!instance_object) | 179 if (!instance_object) |
| 163 return false; | 180 return false; |
| 164 | 181 |
| 165 if (instance_object->module()->permissions().HasPermission( | 182 if (instance_object->module()->permissions().HasPermission( |
| 166 ppapi::PERMISSION_BYPASS_USER_GESTURE)) | 183 ppapi::PERMISSION_BYPASS_USER_GESTURE)) |
| 167 return true; | 184 return true; |
| 168 return instance_object->IsProcessingUserGesture(); | 185 return instance_object->IsProcessingUserGesture(); |
| 169 } | 186 } |
| 170 | 187 |
| 188 bool RendererPpapiHostImpl::IsRunningInProcess() const { |
| 189 return is_running_in_process_; |
| 190 } |
| 191 |
| 171 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( | 192 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( |
| 172 PP_Instance pp_instance) const { | 193 PP_Instance pp_instance) const { |
| 173 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 194 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 174 if (!instance) | 195 if (!instance) |
| 175 return NULL; | 196 return NULL; |
| 176 if (instance->module() != module_) | 197 if (instance->module() != module_) |
| 177 return NULL; | 198 return NULL; |
| 178 return instance; | 199 return instance; |
| 179 } | 200 } |
| 180 | 201 |
| 181 } // namespace content | 202 } // namespace content |
| OLD | NEW |