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/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "content/renderer/media/audio_hardware.h" | 40 #include "content/renderer/media/audio_hardware.h" |
41 #include "content/renderer/media/media_stream_dispatcher.h" | 41 #include "content/renderer/media/media_stream_dispatcher.h" |
42 #include "content/renderer/media/pepper_platform_video_decoder_impl.h" | 42 #include "content/renderer/media/pepper_platform_video_decoder_impl.h" |
43 #include "content/renderer/p2p/p2p_transport_impl.h" | 43 #include "content/renderer/p2p/p2p_transport_impl.h" |
44 #include "content/renderer/p2p/socket_dispatcher.h" | 44 #include "content/renderer/p2p/socket_dispatcher.h" |
45 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" | 45 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" |
46 #include "content/renderer/pepper/pepper_broker_impl.h" | 46 #include "content/renderer/pepper/pepper_broker_impl.h" |
47 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h" | 47 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h" |
48 #include "content/renderer/pepper/pepper_hung_plugin_filter.h" | 48 #include "content/renderer/pepper/pepper_hung_plugin_filter.h" |
49 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" | 49 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" |
50 #include "content/renderer/pepper/pepper_instance_state_accessor.h" | |
51 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" | 50 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" |
52 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h" | 51 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h" |
53 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" | 52 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" |
54 #include "content/renderer/pepper/pepper_platform_image_2d_impl.h" | 53 #include "content/renderer/pepper/pepper_platform_image_2d_impl.h" |
55 #include "content/renderer/pepper/pepper_platform_video_capture_impl.h" | 54 #include "content/renderer/pepper/pepper_platform_video_capture_impl.h" |
56 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" | 55 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
| 56 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
57 #include "content/renderer/render_thread_impl.h" | 57 #include "content/renderer/render_thread_impl.h" |
58 #include "content/renderer/render_view_impl.h" | 58 #include "content/renderer/render_view_impl.h" |
59 #include "content/renderer/render_widget_fullscreen_pepper.h" | 59 #include "content/renderer/render_widget_fullscreen_pepper.h" |
60 #include "content/renderer/renderer_clipboard_client.h" | 60 #include "content/renderer/renderer_clipboard_client.h" |
61 #include "content/renderer/webplugin_delegate_proxy.h" | 61 #include "content/renderer/webplugin_delegate_proxy.h" |
62 #include "googleurl/src/gurl.h" | 62 #include "googleurl/src/gurl.h" |
63 #include "ipc/ipc_channel_handle.h" | 63 #include "ipc/ipc_channel_handle.h" |
64 #include "media/video/capture/video_capture_proxy.h" | 64 #include "media/video/capture/video_capture_proxy.h" |
65 #include "ppapi/c/dev/pp_video_dev.h" | 65 #include "ppapi/c/dev/pp_video_dev.h" |
66 #include "ppapi/c/pp_errors.h" | 66 #include "ppapi/c/pp_errors.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 namespace { | 104 namespace { |
105 | 105 |
106 class HostDispatcherWrapper | 106 class HostDispatcherWrapper |
107 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { | 107 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { |
108 public: | 108 public: |
109 HostDispatcherWrapper(RenderViewImpl* rv, | 109 HostDispatcherWrapper(RenderViewImpl* rv, |
110 webkit::ppapi::PluginModule* module, | 110 webkit::ppapi::PluginModule* module, |
111 const ppapi::PpapiPermissions& perms) | 111 const ppapi::PpapiPermissions& perms) |
112 : module_(module), | 112 : module_(module), |
113 instance_state_(module), | 113 permissions_(perms) { |
114 host_factory_(rv, perms, &instance_state_), | |
115 render_view_(rv) { | |
116 } | 114 } |
117 virtual ~HostDispatcherWrapper() {} | 115 virtual ~HostDispatcherWrapper() {} |
118 | 116 |
119 bool Init(const IPC::ChannelHandle& channel_handle, | 117 bool Init(const IPC::ChannelHandle& channel_handle, |
120 PP_GetInterface_Func local_get_interface, | 118 PP_GetInterface_Func local_get_interface, |
121 const ppapi::Preferences& preferences, | 119 const ppapi::Preferences& preferences, |
122 const ppapi::PpapiPermissions& permissions, | 120 const ppapi::PpapiPermissions& permissions, |
123 PepperHungPluginFilter* filter) { | 121 PepperHungPluginFilter* filter) { |
124 if (channel_handle.name.empty()) | 122 if (channel_handle.name.empty()) |
125 return false; | 123 return false; |
126 | 124 |
127 #if defined(OS_POSIX) | 125 #if defined(OS_POSIX) |
128 DCHECK_NE(-1, channel_handle.socket.fd); | 126 DCHECK_NE(-1, channel_handle.socket.fd); |
129 if (channel_handle.socket.fd == -1) | 127 if (channel_handle.socket.fd == -1) |
130 return false; | 128 return false; |
131 #endif | 129 #endif |
132 | 130 |
133 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); | 131 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); |
134 dispatcher_.reset(new ppapi::proxy::HostDispatcher( | 132 dispatcher_.reset(new ppapi::proxy::HostDispatcher( |
135 module_->pp_module(), local_get_interface, filter)); | 133 module_->pp_module(), local_get_interface, filter)); |
136 | 134 |
137 host_.reset(new ppapi::host::PpapiHost(dispatcher_.get(), &host_factory_, | |
138 permissions)); | |
139 dispatcher_->AddFilter(host_.get()); | |
140 | |
141 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), | 135 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), |
142 channel_handle, | 136 channel_handle, |
143 true, // Client. | 137 true, // Client. |
144 preferences)) { | 138 preferences)) { |
145 dispatcher_.reset(); | 139 dispatcher_.reset(); |
146 dispatcher_delegate_.reset(); | 140 dispatcher_delegate_.reset(); |
147 return false; | 141 return false; |
148 } | 142 } |
149 dispatcher_->channel()->SetRestrictDispatchChannelGroup( | 143 dispatcher_->channel()->SetRestrictDispatchChannelGroup( |
150 content::kRendererRestrictDispatchGroup_Pepper); | 144 content::kRendererRestrictDispatchGroup_Pepper); |
151 render_view_->PpapiPluginCreated(host_.get()); | |
152 return true; | 145 return true; |
153 } | 146 } |
154 | 147 |
155 // OutOfProcessProxy implementation. | 148 // OutOfProcessProxy implementation. |
156 virtual const void* GetProxiedInterface(const char* name) { | 149 virtual const void* GetProxiedInterface(const char* name) { |
157 return dispatcher_->GetProxiedInterface(name); | 150 return dispatcher_->GetProxiedInterface(name); |
158 } | 151 } |
159 virtual void AddInstance(PP_Instance instance) { | 152 virtual void AddInstance(PP_Instance instance) { |
160 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); | 153 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); |
161 } | 154 } |
162 virtual void RemoveInstance(PP_Instance instance) { | 155 virtual void RemoveInstance(PP_Instance instance) { |
163 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); | 156 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); |
164 } | 157 } |
165 | 158 |
| 159 ppapi::proxy::HostDispatcher* dispatcher() { return dispatcher_.get(); } |
| 160 |
166 private: | 161 private: |
167 webkit::ppapi::PluginModule* module_; | 162 webkit::ppapi::PluginModule* module_; |
168 PepperInstanceStateAccessorImpl instance_state_; | |
169 ContentRendererPepperHostFactory host_factory_; | |
170 | 163 |
171 RenderViewImpl* render_view_; | 164 ppapi::PpapiPermissions permissions_; |
172 scoped_ptr<ppapi::host::PpapiHost> host_; | |
173 | 165 |
174 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; | 166 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; |
175 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; | 167 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; |
176 }; | 168 }; |
177 | 169 |
178 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { | 170 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { |
179 public: | 171 public: |
180 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; | 172 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; |
181 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} | 173 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} |
182 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { | 174 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 264 |
273 private: | 265 private: |
274 webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback callback_; | 266 webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback callback_; |
275 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback close_file_callback_; | 267 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback close_file_callback_; |
276 }; | 268 }; |
277 | 269 |
278 void DoNotifyCloseFile(const GURL& path, base::PlatformFileError /* unused */) { | 270 void DoNotifyCloseFile(const GURL& path, base::PlatformFileError /* unused */) { |
279 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile(path); | 271 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile(path); |
280 } | 272 } |
281 | 273 |
| 274 void CreateHostForInProcessModule(RenderViewImpl* render_view, |
| 275 webkit::ppapi::PluginModule* module, |
| 276 const webkit::WebPluginInfo& webplugin_info) { |
| 277 // First time an in-process plugin was used, make a host for it. |
| 278 const PepperPluginInfo* info = |
| 279 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
| 280 DCHECK(!info->is_out_of_process); |
| 281 |
| 282 ppapi::PpapiPermissions perms( |
| 283 PepperPluginRegistry::GetInstance()->GetInfoForPlugin( |
| 284 webplugin_info)->permissions); |
| 285 RendererPpapiHostImpl* host_impl = |
| 286 content::RendererPpapiHostImpl::CreateOnModuleForInProcess( |
| 287 module, perms); |
| 288 render_view->PpapiPluginCreated(host_impl); |
| 289 } |
| 290 |
282 } // namespace | 291 } // namespace |
283 | 292 |
284 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 293 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
285 : RenderViewObserver(render_view), | 294 : RenderViewObserver(render_view), |
286 render_view_(render_view), | 295 render_view_(render_view), |
287 has_saved_context_menu_action_(false), | 296 has_saved_context_menu_action_(false), |
288 saved_context_menu_action_(0), | 297 saved_context_menu_action_(0), |
289 focused_plugin_(NULL), | 298 focused_plugin_(NULL), |
290 last_mouse_event_target_(NULL), | 299 last_mouse_event_target_(NULL), |
291 device_enumeration_event_handler_( | 300 device_enumeration_event_handler_( |
292 new PepperDeviceEnumerationEventHandler()) { | 301 new PepperDeviceEnumerationEventHandler()) { |
293 } | 302 } |
294 | 303 |
295 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 304 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
296 DCHECK(mouse_lock_instances_.empty()); | 305 DCHECK(mouse_lock_instances_.empty()); |
297 } | 306 } |
298 | 307 |
299 scoped_refptr<webkit::ppapi::PluginModule> | 308 scoped_refptr<webkit::ppapi::PluginModule> |
300 PepperPluginDelegateImpl::CreatePepperPluginModule( | 309 PepperPluginDelegateImpl::CreatePepperPluginModule( |
301 const webkit::WebPluginInfo& webplugin_info, | 310 const webkit::WebPluginInfo& webplugin_info, |
302 bool* pepper_plugin_was_registered) { | 311 bool* pepper_plugin_was_registered) { |
303 *pepper_plugin_was_registered = true; | 312 *pepper_plugin_was_registered = true; |
304 | 313 |
305 // See if a module has already been loaded for this plugin. | 314 // See if a module has already been loaded for this plugin. |
306 FilePath path(webplugin_info.path); | 315 FilePath path(webplugin_info.path); |
307 scoped_refptr<webkit::ppapi::PluginModule> module = | 316 scoped_refptr<webkit::ppapi::PluginModule> module = |
308 PepperPluginRegistry::GetInstance()->GetLiveModule(path); | 317 PepperPluginRegistry::GetInstance()->GetLiveModule(path); |
309 if (module) | 318 if (module) { |
| 319 if (!module->GetEmbedderState()) { |
| 320 // If the module exists and no embedder state was associated with it, |
| 321 // then the module was one of the ones preloaded and is an in-process |
| 322 // plugin. We need to associate our host state with it. |
| 323 CreateHostForInProcessModule(render_view_, module, webplugin_info); |
| 324 } |
310 return module; | 325 return module; |
| 326 } |
311 | 327 |
312 // In-process plugins will have always been created up-front to avoid the | 328 // In-process plugins will have always been created up-front to avoid the |
313 // sandbox restrictions. So getting here implies it doesn't exist or should | 329 // sandbox restrictions. So getting here implies it doesn't exist or should |
314 // be out of process. | 330 // be out of process. |
315 const PepperPluginInfo* info = | 331 const PepperPluginInfo* info = |
316 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); | 332 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
317 if (!info) { | 333 if (!info) { |
318 *pepper_plugin_was_registered = false; | 334 *pepper_plugin_was_registered = false; |
319 return scoped_refptr<webkit::ppapi::PluginModule>(); | 335 return scoped_refptr<webkit::ppapi::PluginModule>(); |
320 } else if (!info->is_out_of_process) { | 336 } else if (!info->is_out_of_process) { |
(...skipping 26 matching lines...) Expand all Loading... |
347 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); | 363 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); |
348 scoped_ptr<HostDispatcherWrapper> dispatcher( | 364 scoped_ptr<HostDispatcherWrapper> dispatcher( |
349 new HostDispatcherWrapper(render_view_, module, permissions)); | 365 new HostDispatcherWrapper(render_view_, module, permissions)); |
350 if (!dispatcher->Init( | 366 if (!dispatcher->Init( |
351 channel_handle, | 367 channel_handle, |
352 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), | 368 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), |
353 GetPreferences(), | 369 GetPreferences(), |
354 permissions, | 370 permissions, |
355 hung_filter.get())) | 371 hung_filter.get())) |
356 return scoped_refptr<webkit::ppapi::PluginModule>(); | 372 return scoped_refptr<webkit::ppapi::PluginModule>(); |
| 373 |
| 374 RendererPpapiHostImpl* host_impl = |
| 375 content::RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
| 376 module, dispatcher->dispatcher(), permissions); |
| 377 render_view_->PpapiPluginCreated(host_impl); |
| 378 |
357 module->InitAsProxied(dispatcher.release()); | 379 module->InitAsProxied(dispatcher.release()); |
358 return module; | 380 return module; |
359 } | 381 } |
360 | 382 |
361 scoped_refptr<webkit::ppapi::PluginModule> | 383 scoped_refptr<webkit::ppapi::PluginModule> |
362 PepperPluginDelegateImpl::CreateBrowserPluginModule( | 384 PepperPluginDelegateImpl::CreateBrowserPluginModule( |
363 const IPC::ChannelHandle& channel_handle, | 385 const IPC::ChannelHandle& channel_handle, |
364 int guest_process_id) { | 386 int guest_process_id) { |
365 content::old::BrowserPluginRegistry* registry = | 387 content::old::BrowserPluginRegistry* registry = |
366 RenderThreadImpl::current()->browser_plugin_registry(); | 388 RenderThreadImpl::current()->browser_plugin_registry(); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 | 709 |
688 if (last_mouse_event_target_ == instance) | 710 if (last_mouse_event_target_ == instance) |
689 last_mouse_event_target_ = NULL; | 711 last_mouse_event_target_ = NULL; |
690 if (focused_plugin_ == instance) | 712 if (focused_plugin_ == instance) |
691 PluginFocusChanged(instance, false); | 713 PluginFocusChanged(instance, false); |
692 } | 714 } |
693 | 715 |
694 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> | 716 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
695 PepperPluginDelegateImpl::CreateResourceCreationAPI( | 717 PepperPluginDelegateImpl::CreateResourceCreationAPI( |
696 webkit::ppapi::PluginInstance* instance) { | 718 webkit::ppapi::PluginInstance* instance) { |
697 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( | 719 RendererPpapiHostImpl* host_impl = static_cast<RendererPpapiHostImpl*>( |
698 new PepperInProcessResourceCreation(render_view_, instance, | 720 instance->module()->GetEmbedderState()); |
699 instance->module()->permissions())); | 721 return host_impl->CreateInProcessResourceCreationAPI(instance); |
700 } | 722 } |
701 | 723 |
702 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { | 724 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { |
703 return GetContentClient()->renderer()->GetSadPluginBitmap(); | 725 return GetContentClient()->renderer()->GetSadPluginBitmap(); |
704 } | 726 } |
705 | 727 |
706 WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePluginReplacement( | 728 WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePluginReplacement( |
707 const FilePath& file_path) { | 729 const FilePath& file_path) { |
708 return GetContentClient()->renderer()->CreatePluginReplacement( | 730 return GetContentClient()->renderer()->CreatePluginReplacement( |
709 render_view_, file_path); | 731 render_view_, file_path); |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 else | 1799 else |
1778 return render_view_->mouse_lock_dispatcher(); | 1800 return render_view_->mouse_lock_dispatcher(); |
1779 } | 1801 } |
1780 | 1802 |
1781 webkit_glue::ClipboardClient* | 1803 webkit_glue::ClipboardClient* |
1782 PepperPluginDelegateImpl::CreateClipboardClient() const { | 1804 PepperPluginDelegateImpl::CreateClipboardClient() const { |
1783 return new RendererClipboardClient; | 1805 return new RendererClipboardClient; |
1784 } | 1806 } |
1785 | 1807 |
1786 } // namespace content | 1808 } // namespace content |
OLD | NEW |