| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "content/common/sandbox_util.h" | 10 #include "content/common/sandbox_util.h" |
| 11 #include "content/renderer/pepper/pepper_browser_connection.h" | 11 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 12 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 12 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 13 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" | 13 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
| 14 #include "content/renderer/pepper/pepper_in_process_router.h" | 14 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 15 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 15 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 16 #include "content/renderer/render_view_impl.h" | 16 #include "content/renderer/render_view_impl.h" |
| 17 #include "content/renderer/render_widget_fullscreen_pepper.h" | 17 #include "content/renderer/render_widget_fullscreen_pepper.h" |
| 18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 19 #include "ppapi/host/ppapi_host.h" | 19 #include "ppapi/host/ppapi_host.h" |
| 20 #include "ppapi/proxy/host_dispatcher.h" | 20 #include "ppapi/proxy/host_dispatcher.h" |
| 21 #include "third_party/WebKit/public/platform/WebRect.h" | 21 #include "third_party/WebKit/public/platform/WebRect.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebElement.h" | 23 #include "third_party/WebKit/public/web/WebElement.h" |
| 24 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 24 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 25 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
| 26 #include "webkit/plugins/ppapi/fullscreen_container.h" | 26 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 27 #include "webkit/plugins/ppapi/host_globals.h" | 27 #include "webkit/plugins/ppapi/host_globals.h" |
| 28 #include "webkit/plugins/ppapi/plugin_delegate.h" | 28 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 29 #include "webkit/plugins/ppapi/plugin_module.h" | 29 #include "webkit/plugins/ppapi/plugin_module.h" |
| 30 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 30 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 31 | 31 |
| 32 using webkit::ppapi::HostGlobals; | 32 using webkit::ppapi::HostGlobals; |
| 33 using webkit::ppapi::PluginInstance; | 33 using webkit::ppapi::PluginInstance; |
| 34 using webkit::ppapi::PluginInstanceImpl; |
| 34 using webkit::ppapi::PluginModule; | 35 using webkit::ppapi::PluginModule; |
| 35 | 36 |
| 36 namespace content { | 37 namespace content { |
| 37 // static | 38 // static |
| 38 CONTENT_EXPORT RendererPpapiHost* | 39 CONTENT_EXPORT RendererPpapiHost* |
| 39 RendererPpapiHost::GetForPPInstance(PP_Instance instance) { | 40 RendererPpapiHost::GetForPPInstance(PP_Instance instance) { |
| 40 return RendererPpapiHostImpl::GetForPPInstance(instance); | 41 return RendererPpapiHostImpl::GetForPPInstance(instance); |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Out-of-process constructor. | 44 // Out-of-process constructor. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Takes ownership of pointer. | 106 // Takes ownership of pointer. |
| 106 module->SetEmbedderState( | 107 module->SetEmbedderState( |
| 107 scoped_ptr<PluginModule::EmbedderState>(result)); | 108 scoped_ptr<PluginModule::EmbedderState>(result)); |
| 108 | 109 |
| 109 return result; | 110 return result; |
| 110 } | 111 } |
| 111 | 112 |
| 112 // static | 113 // static |
| 113 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( | 114 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( |
| 114 PP_Instance pp_instance) { | 115 PP_Instance pp_instance) { |
| 115 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 116 PluginInstanceImpl* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 116 if (!instance) | 117 if (!instance) |
| 117 return NULL; | 118 return NULL; |
| 118 | 119 |
| 119 // All modules created by content will have their embedder state be the | 120 // All modules created by content will have their embedder state be the |
| 120 // host impl. | 121 // host impl. |
| 121 return static_cast<RendererPpapiHostImpl*>( | 122 return static_cast<RendererPpapiHostImpl*>( |
| 122 instance->module()->GetEmbedderState()); | 123 instance->module()->GetEmbedderState()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> | 126 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
| 126 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( | 127 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( |
| 127 PluginInstance* instance) { | 128 PluginInstanceImpl* instance) { |
| 128 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( | 129 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( |
| 129 new PepperInProcessResourceCreation(this, instance)); | 130 new PepperInProcessResourceCreation(this, instance)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 PepperBrowserConnection* | 133 PepperBrowserConnection* |
| 133 RendererPpapiHostImpl::GetBrowserConnection(PP_Instance instance) const { | 134 RendererPpapiHostImpl::GetBrowserConnection(PP_Instance instance) const { |
| 134 PluginInstance* instance_object = GetAndValidateInstance(instance); | 135 PluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
| 135 if (!instance_object) | 136 if (!instance_object) |
| 136 return NULL; | 137 return NULL; |
| 137 | 138 |
| 138 // Since we're the embedder, we can make assumptions about the delegate on | 139 // Since we're the embedder, we can make assumptions about the delegate on |
| 139 // the instance. | 140 // the instance. |
| 140 PepperPluginDelegateImpl* delegate = | 141 PepperPluginDelegateImpl* delegate = |
| 141 static_cast<PepperPluginDelegateImpl*>(instance_object->delegate()); | 142 static_cast<PepperPluginDelegateImpl*>(instance_object->delegate()); |
| 142 if (!delegate) | 143 if (!delegate) |
| 143 return NULL; | 144 return NULL; |
| 144 | 145 |
| 145 return delegate->pepper_browser_connection(); | 146 return delegate->pepper_browser_connection(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { | 149 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { |
| 149 return ppapi_host_.get(); | 150 return ppapi_host_.get(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( | 153 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( |
| 153 PP_Instance instance) const { | 154 PP_Instance instance) const { |
| 154 PluginInstance* instance_object = GetAndValidateInstance(instance); | 155 PluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
| 155 if (!instance_object) | 156 if (!instance_object) |
| 156 return NULL; | 157 return NULL; |
| 157 | 158 |
| 158 // Since we're the embedder, we can make assumptions about the delegate on | 159 // Since we're the embedder, we can make assumptions about the delegate on |
| 159 // the instance and get back to our RenderView. | 160 // the instance and get back to our RenderView. |
| 160 return static_cast<PepperPluginDelegateImpl*>( | 161 return static_cast<PepperPluginDelegateImpl*>( |
| 161 instance_object->delegate())->render_view(); | 162 instance_object->delegate())->render_view(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 bool RendererPpapiHostImpl::IsValidInstance( | 165 bool RendererPpapiHostImpl::IsValidInstance(PP_Instance instance) const { |
| 165 PP_Instance instance) const { | |
| 166 return !!GetAndValidateInstance(instance); | 166 return !!GetAndValidateInstance(instance); |
| 167 } | 167 } |
| 168 | 168 |
| 169 webkit::ppapi::PluginInstance* RendererPpapiHostImpl::GetPluginInstance( | 169 webkit::ppapi::PluginInstance* RendererPpapiHostImpl::GetPluginInstance( |
| 170 PP_Instance instance) const { | 170 PP_Instance instance) const { |
| 171 return GetAndValidateInstance(instance); | 171 return GetAndValidateInstance(instance); |
| 172 } | 172 } |
| 173 | 173 |
| 174 WebKit::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( | 174 WebKit::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( |
| 175 PP_Instance instance) const { | 175 PP_Instance instance) const { |
| 176 PluginInstance* instance_object = GetAndValidateInstance(instance); | 176 PluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
| 177 if (!instance_object) | 177 if (!instance_object) |
| 178 return NULL; | 178 return NULL; |
| 179 return instance_object->container(); | 179 return instance_object->container(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 base::ProcessId RendererPpapiHostImpl::GetPluginPID() const { | 182 base::ProcessId RendererPpapiHostImpl::GetPluginPID() const { |
| 183 if (dispatcher_) | 183 if (dispatcher_) |
| 184 return dispatcher_->channel()->peer_pid(); | 184 return dispatcher_->channel()->peer_pid(); |
| 185 return base::kNullProcessId; | 185 return base::kNullProcessId; |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { | 188 bool RendererPpapiHostImpl::HasUserGesture(PP_Instance instance) const { |
| 189 PluginInstance* instance_object = GetAndValidateInstance(instance); | 189 PluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
| 190 if (!instance_object) | 190 if (!instance_object) |
| 191 return false; | 191 return false; |
| 192 | 192 |
| 193 if (instance_object->module()->permissions().HasPermission( | 193 if (instance_object->module()->permissions().HasPermission( |
| 194 ppapi::PERMISSION_BYPASS_USER_GESTURE)) | 194 ppapi::PERMISSION_BYPASS_USER_GESTURE)) |
| 195 return true; | 195 return true; |
| 196 return instance_object->IsProcessingUserGesture(); | 196 return instance_object->IsProcessingUserGesture(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 int RendererPpapiHostImpl::GetRoutingIDForWidget(PP_Instance instance) const { | 199 int RendererPpapiHostImpl::GetRoutingIDForWidget(PP_Instance instance) const { |
| 200 webkit::ppapi::PluginInstance* plugin_instance = | 200 webkit::ppapi::PluginInstanceImpl* plugin_instance = |
| 201 GetAndValidateInstance(instance); | 201 GetAndValidateInstance(instance); |
| 202 if (!plugin_instance) | 202 if (!plugin_instance) |
| 203 return 0; | 203 return 0; |
| 204 if (plugin_instance->flash_fullscreen()) { | 204 if (plugin_instance->flash_fullscreen()) { |
| 205 webkit::ppapi::FullscreenContainer* container = | 205 webkit::ppapi::FullscreenContainer* container = |
| 206 plugin_instance->fullscreen_container(); | 206 plugin_instance->fullscreen_container(); |
| 207 return static_cast<RenderWidgetFullscreenPepper*>(container)->routing_id(); | 207 return static_cast<RenderWidgetFullscreenPepper*>(container)->routing_id(); |
| 208 } | 208 } |
| 209 return GetRenderViewForInstance(instance)->GetRoutingID(); | 209 return GetRenderViewForInstance(instance)->GetRoutingID(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 gfx::Point RendererPpapiHostImpl::PluginPointToRenderView( | 212 gfx::Point RendererPpapiHostImpl::PluginPointToRenderView( |
| 213 PP_Instance instance, | 213 PP_Instance instance, |
| 214 const gfx::Point& pt) const { | 214 const gfx::Point& pt) const { |
| 215 webkit::ppapi::PluginInstance* plugin_instance = | 215 webkit::ppapi::PluginInstanceImpl* plugin_instance = |
| 216 GetAndValidateInstance(instance); | 216 GetAndValidateInstance(instance); |
| 217 if (!plugin_instance) | 217 if (!plugin_instance) |
| 218 return pt; | 218 return pt; |
| 219 | 219 |
| 220 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( | 220 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( |
| 221 GetRenderViewForInstance(instance)); | 221 GetRenderViewForInstance(instance)); |
| 222 if (plugin_instance->view_data().is_fullscreen || | 222 if (plugin_instance->view_data().is_fullscreen || |
| 223 plugin_instance->flash_fullscreen()) { | 223 plugin_instance->flash_fullscreen()) { |
| 224 WebKit::WebRect window_rect = render_view->windowRect(); | 224 WebKit::WebRect window_rect = render_view->windowRect(); |
| 225 WebKit::WebRect screen_rect = render_view->screenInfo().rect; | 225 WebKit::WebRect screen_rect = render_view->screenInfo().rect; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 if (browser_connection == NULL) { | 257 if (browser_connection == NULL) { |
| 258 callback.Run(0); | 258 callback.Run(0); |
| 259 } else { | 259 } else { |
| 260 browser_connection->SendBrowserCreate(module_->GetPluginChildId(), | 260 browser_connection->SendBrowserCreate(module_->GetPluginChildId(), |
| 261 instance, | 261 instance, |
| 262 nested_msg, | 262 nested_msg, |
| 263 callback); | 263 callback); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance( | 267 PluginInstanceImpl* RendererPpapiHostImpl::GetAndValidateInstance( |
| 268 PP_Instance pp_instance) const { | 268 PP_Instance pp_instance) const { |
| 269 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 269 PluginInstanceImpl* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 270 if (!instance) | 270 if (!instance) |
| 271 return NULL; | 271 return NULL; |
| 272 if (!instance->IsValidInstanceOf(module_)) | 272 if (!instance->IsValidInstanceOf(module_)) |
| 273 return NULL; | 273 return NULL; |
| 274 return instance; | 274 return instance; |
| 275 } | 275 } |
| 276 | 276 |
| 277 } // namespace content | 277 } // namespace content |
| OLD | NEW |