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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ppapi/host/ppapi_host.h" | 24 #include "ppapi/host/ppapi_host.h" |
25 #include "ppapi/proxy/host_dispatcher.h" | 25 #include "ppapi/proxy/host_dispatcher.h" |
26 #include "third_party/WebKit/public/platform/WebRect.h" | 26 #include "third_party/WebKit/public/platform/WebRect.h" |
27 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
28 #include "third_party/WebKit/public/web/WebElement.h" | 28 #include "third_party/WebKit/public/web/WebElement.h" |
29 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 29 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
30 #include "ui/gfx/point.h" | 30 #include "ui/gfx/point.h" |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 // static | 33 // static |
34 CONTENT_EXPORT RendererPpapiHost* | 34 CONTENT_EXPORT RendererPpapiHost* RendererPpapiHost::GetForPPInstance( |
35 RendererPpapiHost::GetForPPInstance(PP_Instance instance) { | 35 PP_Instance instance) { |
36 return RendererPpapiHostImpl::GetForPPInstance(instance); | 36 return RendererPpapiHostImpl::GetForPPInstance(instance); |
37 } | 37 } |
38 | 38 |
39 // Out-of-process constructor. | 39 // Out-of-process constructor. |
40 RendererPpapiHostImpl::RendererPpapiHostImpl( | 40 RendererPpapiHostImpl::RendererPpapiHostImpl( |
41 PluginModule* module, | 41 PluginModule* module, |
42 ppapi::proxy::HostDispatcher* dispatcher, | 42 ppapi::proxy::HostDispatcher* dispatcher, |
43 const ppapi::PpapiPermissions& permissions) | 43 const ppapi::PpapiPermissions& permissions) |
44 : module_(module), | 44 : module_(module), dispatcher_(dispatcher) { |
45 dispatcher_(dispatcher) { | |
46 // Hook the PpapiHost up to the dispatcher for out-of-process communication. | 45 // Hook the PpapiHost up to the dispatcher for out-of-process communication. |
47 ppapi_host_.reset( | 46 ppapi_host_.reset(new ppapi::host::PpapiHost(dispatcher, permissions)); |
48 new ppapi::host::PpapiHost(dispatcher, permissions)); | |
49 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 47 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
50 new ContentRendererPepperHostFactory(this))); | 48 new ContentRendererPepperHostFactory(this))); |
51 dispatcher->AddFilter(ppapi_host_.get()); | 49 dispatcher->AddFilter(ppapi_host_.get()); |
52 is_running_in_process_ = false; | 50 is_running_in_process_ = false; |
53 } | 51 } |
54 | 52 |
55 // In-process constructor. | 53 // In-process constructor. |
56 RendererPpapiHostImpl::RendererPpapiHostImpl( | 54 RendererPpapiHostImpl::RendererPpapiHostImpl( |
57 PluginModule* module, | 55 PluginModule* module, |
58 const ppapi::PpapiPermissions& permissions) | 56 const ppapi::PpapiPermissions& permissions) |
59 : module_(module), | 57 : module_(module), dispatcher_(NULL) { |
60 dispatcher_(NULL) { | |
61 // Hook the host up to the in-process router. | 58 // Hook the host up to the in-process router. |
62 in_process_router_.reset(new PepperInProcessRouter(this)); | 59 in_process_router_.reset(new PepperInProcessRouter(this)); |
63 ppapi_host_.reset(new ppapi::host::PpapiHost( | 60 ppapi_host_.reset(new ppapi::host::PpapiHost( |
64 in_process_router_->GetRendererToPluginSender(), permissions)); | 61 in_process_router_->GetRendererToPluginSender(), permissions)); |
65 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( | 62 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
66 new ContentRendererPepperHostFactory(this))); | 63 new ContentRendererPepperHostFactory(this))); |
67 is_running_in_process_ = true; | 64 is_running_in_process_ = true; |
68 } | 65 } |
69 | 66 |
70 RendererPpapiHostImpl::~RendererPpapiHostImpl() { | 67 RendererPpapiHostImpl::~RendererPpapiHostImpl() { |
71 // Delete the host explicitly first. This shutdown will destroy the | 68 // Delete the host explicitly first. This shutdown will destroy the |
72 // resources, which may want to do cleanup in their destructors and expect | 69 // resources, which may want to do cleanup in their destructors and expect |
73 // their pointers to us to be valid. | 70 // their pointers to us to be valid. |
74 ppapi_host_.reset(); | 71 ppapi_host_.reset(); |
75 } | 72 } |
76 | 73 |
77 // static | 74 // static |
78 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 75 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
79 PluginModule* module, | 76 PluginModule* module, |
80 ppapi::proxy::HostDispatcher* dispatcher, | 77 ppapi::proxy::HostDispatcher* dispatcher, |
81 const ppapi::PpapiPermissions& permissions) { | 78 const ppapi::PpapiPermissions& permissions) { |
82 DCHECK(!module->renderer_ppapi_host()); | 79 DCHECK(!module->renderer_ppapi_host()); |
83 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( | 80 RendererPpapiHostImpl* result = |
84 module, dispatcher, permissions); | 81 new RendererPpapiHostImpl(module, dispatcher, permissions); |
85 | 82 |
86 // Takes ownership of pointer. | 83 // Takes ownership of pointer. |
87 module->SetRendererPpapiHost(scoped_ptr<RendererPpapiHostImpl>(result)); | 84 module->SetRendererPpapiHost(scoped_ptr<RendererPpapiHostImpl>(result)); |
88 | 85 |
89 return result; | 86 return result; |
90 } | 87 } |
91 | 88 |
92 // static | 89 // static |
93 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess( | 90 RendererPpapiHostImpl* RendererPpapiHostImpl::CreateOnModuleForInProcess( |
94 PluginModule* module, | 91 PluginModule* module, |
95 const ppapi::PpapiPermissions& permissions) { | 92 const ppapi::PpapiPermissions& permissions) { |
96 DCHECK(!module->renderer_ppapi_host()); | 93 DCHECK(!module->renderer_ppapi_host()); |
97 RendererPpapiHostImpl* result = new RendererPpapiHostImpl( | 94 RendererPpapiHostImpl* result = |
98 module, permissions); | 95 new RendererPpapiHostImpl(module, permissions); |
99 | 96 |
100 // Takes ownership of pointer. | 97 // Takes ownership of pointer. |
101 module->SetRendererPpapiHost(scoped_ptr<RendererPpapiHostImpl>(result)); | 98 module->SetRendererPpapiHost(scoped_ptr<RendererPpapiHostImpl>(result)); |
102 | 99 |
103 return result; | 100 return result; |
104 } | 101 } |
105 | 102 |
106 // static | 103 // static |
107 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( | 104 RendererPpapiHostImpl* RendererPpapiHostImpl::GetForPPInstance( |
108 PP_Instance pp_instance) { | 105 PP_Instance pp_instance) { |
(...skipping 17 matching lines...) Expand all Loading... |
126 PepperPluginInstanceImpl* RendererPpapiHostImpl::GetPluginInstanceImpl( | 123 PepperPluginInstanceImpl* RendererPpapiHostImpl::GetPluginInstanceImpl( |
127 PP_Instance instance) const { | 124 PP_Instance instance) const { |
128 return GetAndValidateInstance(instance); | 125 return GetAndValidateInstance(instance); |
129 } | 126 } |
130 | 127 |
131 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { | 128 ppapi::host::PpapiHost* RendererPpapiHostImpl::GetPpapiHost() { |
132 return ppapi_host_.get(); | 129 return ppapi_host_.get(); |
133 } | 130 } |
134 | 131 |
135 RenderFrame* RendererPpapiHostImpl::GetRenderFrameForInstance( | 132 RenderFrame* RendererPpapiHostImpl::GetRenderFrameForInstance( |
136 PP_Instance instance) const { | 133 PP_Instance instance) const { |
137 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); | 134 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
138 if (!instance_object) | 135 if (!instance_object) |
139 return NULL; | 136 return NULL; |
140 | 137 |
141 // Since we're the embedder, we can make assumptions about the helper on | 138 // Since we're the embedder, we can make assumptions about the helper on |
142 // the instance and get back to our RenderFrame. | 139 // the instance and get back to our RenderFrame. |
143 return instance_object->render_frame(); | 140 return instance_object->render_frame(); |
144 } | 141 } |
145 | 142 |
146 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( | 143 RenderView* RendererPpapiHostImpl::GetRenderViewForInstance( |
(...skipping 10 matching lines...) Expand all Loading... |
157 bool RendererPpapiHostImpl::IsValidInstance(PP_Instance instance) const { | 154 bool RendererPpapiHostImpl::IsValidInstance(PP_Instance instance) const { |
158 return !!GetAndValidateInstance(instance); | 155 return !!GetAndValidateInstance(instance); |
159 } | 156 } |
160 | 157 |
161 PepperPluginInstance* RendererPpapiHostImpl::GetPluginInstance( | 158 PepperPluginInstance* RendererPpapiHostImpl::GetPluginInstance( |
162 PP_Instance instance) const { | 159 PP_Instance instance) const { |
163 return GetAndValidateInstance(instance); | 160 return GetAndValidateInstance(instance); |
164 } | 161 } |
165 | 162 |
166 blink::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( | 163 blink::WebPluginContainer* RendererPpapiHostImpl::GetContainerForInstance( |
167 PP_Instance instance) const { | 164 PP_Instance instance) const { |
168 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); | 165 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
169 if (!instance_object) | 166 if (!instance_object) |
170 return NULL; | 167 return NULL; |
171 return instance_object->container(); | 168 return instance_object->container(); |
172 } | 169 } |
173 | 170 |
174 base::ProcessId RendererPpapiHostImpl::GetPluginPID() const { | 171 base::ProcessId RendererPpapiHostImpl::GetPluginPID() const { |
175 if (dispatcher_) | 172 if (dispatcher_) |
176 return dispatcher_->channel()->peer_pid(); | 173 return dispatcher_->channel()->peer_pid(); |
177 return base::kNullProcessId; | 174 return base::kNullProcessId; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 210 } |
214 | 211 |
215 IPC::PlatformFileForTransit RendererPpapiHostImpl::ShareHandleWithRemote( | 212 IPC::PlatformFileForTransit RendererPpapiHostImpl::ShareHandleWithRemote( |
216 base::PlatformFile handle, | 213 base::PlatformFile handle, |
217 bool should_close_source) { | 214 bool should_close_source) { |
218 if (!dispatcher_) { | 215 if (!dispatcher_) { |
219 DCHECK(is_running_in_process_); | 216 DCHECK(is_running_in_process_); |
220 // Duplicate the file handle for in process mode so this function | 217 // Duplicate the file handle for in process mode so this function |
221 // has the same semantics for both in process mode and out of | 218 // has the same semantics for both in process mode and out of |
222 // process mode (i.e., the remote side must cloes the handle). | 219 // process mode (i.e., the remote side must cloes the handle). |
223 return BrokerGetFileHandleForProcess(handle, | 220 return BrokerGetFileHandleForProcess( |
224 base::GetCurrentProcId(), | 221 handle, base::GetCurrentProcId(), should_close_source); |
225 should_close_source); | |
226 } | 222 } |
227 return dispatcher_->ShareHandleWithRemote(handle, should_close_source); | 223 return dispatcher_->ShareHandleWithRemote(handle, should_close_source); |
228 } | 224 } |
229 | 225 |
230 bool RendererPpapiHostImpl::IsRunningInProcess() const { | 226 bool RendererPpapiHostImpl::IsRunningInProcess() const { |
231 return is_running_in_process_; | 227 return is_running_in_process_; |
232 } | 228 } |
233 | 229 |
234 void RendererPpapiHostImpl::CreateBrowserResourceHosts( | 230 void RendererPpapiHostImpl::CreateBrowserResourceHosts( |
235 PP_Instance instance, | 231 PP_Instance instance, |
236 const std::vector<IPC::Message>& nested_msgs, | 232 const std::vector<IPC::Message>& nested_msgs, |
237 const base::Callback<void(const std::vector<int>&)>& callback) const { | 233 const base::Callback<void(const std::vector<int>&)>& callback) const { |
238 RenderFrame* render_frame = GetRenderFrameForInstance(instance); | 234 RenderFrame* render_frame = GetRenderFrameForInstance(instance); |
239 PepperBrowserConnection* browser_connection = | 235 PepperBrowserConnection* browser_connection = |
240 PepperBrowserConnection::Get(render_frame); | 236 PepperBrowserConnection::Get(render_frame); |
241 if (!browser_connection) { | 237 if (!browser_connection) { |
242 base::MessageLoop::current()->PostTask(FROM_HERE, | 238 base::MessageLoop::current()->PostTask( |
| 239 FROM_HERE, |
243 base::Bind(callback, std::vector<int>(nested_msgs.size(), 0))); | 240 base::Bind(callback, std::vector<int>(nested_msgs.size(), 0))); |
244 } else { | 241 } else { |
245 browser_connection->SendBrowserCreate(module_->GetPluginChildId(), | 242 browser_connection->SendBrowserCreate( |
246 instance, | 243 module_->GetPluginChildId(), instance, nested_msgs, callback); |
247 nested_msgs, | |
248 callback); | |
249 } | 244 } |
250 } | 245 } |
251 | 246 |
252 GURL RendererPpapiHostImpl::GetDocumentURL(PP_Instance instance) const { | 247 GURL RendererPpapiHostImpl::GetDocumentURL(PP_Instance instance) const { |
253 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); | 248 PepperPluginInstanceImpl* instance_object = GetAndValidateInstance(instance); |
254 if (!instance_object) | 249 if (!instance_object) |
255 return GURL(); | 250 return GURL(); |
256 | 251 |
257 return instance_object->container()->element().document().url(); | 252 return instance_object->container()->element().document().url(); |
258 } | 253 } |
259 | 254 |
260 PepperPluginInstanceImpl* RendererPpapiHostImpl::GetAndValidateInstance( | 255 PepperPluginInstanceImpl* RendererPpapiHostImpl::GetAndValidateInstance( |
261 PP_Instance pp_instance) const { | 256 PP_Instance pp_instance) const { |
262 PepperPluginInstanceImpl* instance = | 257 PepperPluginInstanceImpl* instance = |
263 HostGlobals::Get()->GetInstance(pp_instance); | 258 HostGlobals::Get()->GetInstance(pp_instance); |
264 if (!instance) | 259 if (!instance) |
265 return NULL; | 260 return NULL; |
266 if (!instance->IsValidInstanceOf(module_)) | 261 if (!instance->IsValidInstanceOf(module_)) |
267 return NULL; | 262 return NULL; |
268 return instance; | 263 return instance; |
269 } | 264 } |
270 | 265 |
271 } // namespace content | 266 } // namespace content |
OLD | NEW |