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/logging.h" | 8 #include "base/logging.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_module.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; |
| 20 using webkit::ppapi::PluginModule; |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 | 23 |
| 24 // static |
| 25 CONTENT_EXPORT RendererPpapiHost* |
| 26 RendererPpapiHost::CreateExternalPluginModule( |
| 27 scoped_refptr<PluginModule> plugin_module, |
| 28 PluginInstance* plugin_instance, |
| 29 const FilePath& file_path, |
| 30 ppapi::PpapiPermissions permissions, |
| 31 const IPC::ChannelHandle& channel_handle, |
| 32 int plugin_child_id) { |
| 33 RendererPpapiHost* renderer_ppapi_host = NULL; |
| 34 // Since we're the embedder, we can make assumptions about the delegate on |
| 35 // the instance. |
| 36 PepperPluginDelegateImpl* pepper_plugin_delegate = |
| 37 static_cast<PepperPluginDelegateImpl*>(plugin_instance->delegate()); |
| 38 if (pepper_plugin_delegate) { |
| 39 renderer_ppapi_host = pepper_plugin_delegate->CreateExternalPluginModule( |
| 40 plugin_module, |
| 41 file_path, |
| 42 permissions, |
| 43 channel_handle, |
| 44 plugin_child_id); |
| 45 } |
| 46 return renderer_ppapi_host; |
| 47 } |
| 48 |
| 49 |
21 // Out-of-process constructor. | 50 // Out-of-process constructor. |
22 RendererPpapiHostImpl::RendererPpapiHostImpl( | 51 RendererPpapiHostImpl::RendererPpapiHostImpl( |
23 webkit::ppapi::PluginModule* module, | 52 PluginModule* module, |
24 ppapi::proxy::HostDispatcher* dispatcher, | 53 ppapi::proxy::HostDispatcher* dispatcher, |
25 const ppapi::PpapiPermissions& permissions) | 54 const ppapi::PpapiPermissions& permissions) |
26 : module_(module) { | 55 : module_(module) { |
27 // Hook the PpapiHost up to the dispatcher for out-of-process communication. | 56 // Hook the PpapiHost up to the dispatcher for out-of-process communication. |
28 ppapi_host_.reset( | 57 ppapi_host_.reset( |
29 new ppapi::host::PpapiHost(dispatcher, permissions)); | 58 new ppapi::host::PpapiHost(dispatcher, permissions)); |
30 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
31 new ContentRendererPepperHostFactory(this))); | 60 new ContentRendererPepperHostFactory(this))); |
32 dispatcher->AddFilter(ppapi_host_.get()); | 61 dispatcher->AddFilter(ppapi_host_.get()); |
33 } | 62 } |
34 | 63 |
35 // In-process constructor. | 64 // In-process constructor. |
36 RendererPpapiHostImpl::RendererPpapiHostImpl( | 65 RendererPpapiHostImpl::RendererPpapiHostImpl( |
37 webkit::ppapi::PluginModule* module, | 66 PluginModule* module, |
38 const ppapi::PpapiPermissions& permissions) | 67 const ppapi::PpapiPermissions& permissions) |
39 : module_(module) { | 68 : module_(module) { |
40 // Hook the host up to the in-process router. | 69 // Hook the host up to the in-process router. |
41 in_process_router_.reset(new PepperInProcessRouter(this)); | 70 in_process_router_.reset(new PepperInProcessRouter(this)); |
42 ppapi_host_.reset(new ppapi::host::PpapiHost( | 71 ppapi_host_.reset(new ppapi::host::PpapiHost( |
43 in_process_router_->GetRendererToPluginSender(), permissions)); | 72 in_process_router_->GetRendererToPluginSender(), permissions)); |
44 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 73 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
45 new ContentRendererPepperHostFactory(this))); | 74 new ContentRendererPepperHostFactory(this))); |
46 } | 75 } |
47 | 76 |
48 RendererPpapiHostImpl::~RendererPpapiHostImpl() { | 77 RendererPpapiHostImpl::~RendererPpapiHostImpl() { |
49 } | 78 } |
50 | 79 |
51 // static | 80 // static |
52 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 81 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
53 webkit::ppapi::PluginModule* module, | 82 PluginModule* module, |
54 ppapi::proxy::HostDispatcher* dispatcher, | 83 ppapi::proxy::HostDispatcher* dispatcher, |
55 const ppapi::PpapiPermissions& permissions) { | 84 const ppapi::PpapiPermissions& permissions) { |
56 DCHECK(!module->GetEmbedderState()); | 85 DCHECK(!module->GetEmbedderState()); |
57 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( | 86 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( |
58 module, dispatcher, permissions); | 87 module, dispatcher, permissions); |
59 | 88 |
60 // Takes ownership of pointer. | 89 // Takes ownership of pointer. |
61 module->SetEmbedderState( | 90 module->SetEmbedderState( |
62 scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result)); | 91 scoped_ptr<PluginModule::EmbedderState>(result)); |
63 | 92 |
64 return result; | 93 return result; |
65 } | 94 } |
66 | 95 |
67 // static | 96 // static |
68 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess( | 97 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess( |
69 webkit::ppapi::PluginModule* module, | 98 PluginModule* module, |
70 const ppapi::PpapiPermissions& permissions) { | 99 const ppapi::PpapiPermissions& permissions) { |
71 DCHECK(!module->GetEmbedderState()); | 100 DCHECK(!module->GetEmbedderState()); |
72 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( | 101 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( |
73 module, permissions); | 102 module, permissions); |
74 | 103 |
75 // Takes ownership of pointer. | 104 // Takes ownership of pointer. |
76 module->SetEmbedderState( | 105 module->SetEmbedderState( |
77 scoped_ptr<webkit::ppapi::PluginModule::EmbedderState>(result)); | 106 scoped_ptr<PluginModule::EmbedderState>(result)); |
78 | 107 |
79 return result; | 108 return result; |
80 } | 109 } |
81 | 110 |
82 // static | 111 // static |
83 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( | 112 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( |
84 PP_Instance pp_instance) { | 113 PP_Instance pp_instance) { |
85 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 114 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
86 if (!instance) | 115 if (!instance) |
87 return NULL; | 116 return NULL; |
88 | 117 |
89 // All modules created by content will have their embedders state be the | 118 // All modules created by content will have their embedders state be the |
90 // host impl. | 119 // host impl. |
91 return static_cast<RendererPpapiHostImpl*>( | 120 return static_cast<RendererPpapiHostImpl*>( |
92 instance->module()->GetEmbedderState()); | 121 instance->module()->GetEmbedderState()); |
93 } | 122 } |
94 | 123 |
95 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> | 124 scoped_ptr< ::ppapi::thunk::ResourceCreationAPI> |
96 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( | 125 RendererPpapiHostImpl::CreateInProcessResourceCreationAPI( |
97 webkit::ppapi::PluginInstance* instance) { | 126 PluginInstance* instance) { |
98 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( | 127 return scoped_ptr< ::ppapi::thunk::ResourceCreationAPI>( |
99 new PepperInProcessResourceCreation(this, instance)); | 128 new PepperInProcessResourceCreation(this, instance)); |
100 } | 129 } |
101 | 130 |
102 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { | 131 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { |
103 return ppapi_host_.get(); | 132 return ppapi_host_.get(); |
104 } | 133 } |
105 | 134 |
106 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( | 135 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( |
107 PP_Instance instance) const { | 136 PP_Instance instance) const { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 PP_Instance pp_instance) const { | 172 PP_Instance pp_instance) const { |
144 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 173 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
145 if (!instance) | 174 if (!instance) |
146 return NULL; | 175 return NULL; |
147 if (instance->module() != module_) | 176 if (instance->module() != module_) |
148 return NULL; | 177 return NULL; |
149 return instance; | 178 return instance; |
150 } | 179 } |
151 | 180 |
152 } // namespace content | 181 } // namespace content |
OLD | NEW |