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/browser_plugin/guest_to_embedder_channel.h" | 5 #include "content/renderer/browser_plugin/guest_to_embedder_channel.h" |
6 | 6 |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "content/common/browser_plugin_messages.h" | 8 #include "content/common/browser_plugin_messages.h" |
9 #include "content/common/child_process.h" | 9 #include "content/common/child_process.h" |
10 #include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" | 10 #include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" |
11 #include "content/renderer/browser_plugin/browser_plugin_var_serialization_rules
.h" | 11 #include "content/renderer/browser_plugin/browser_plugin_var_serialization_rules
.h" |
12 #include "content/renderer/render_thread_impl.h" | 12 #include "content/renderer/render_thread_impl.h" |
13 #include "content/renderer/render_view_impl.h" | 13 #include "content/renderer/render_view_impl.h" |
14 #include "ppapi/c/pp_bool.h" | 14 #include "ppapi/c/pp_bool.h" |
15 #include "ppapi/c/pp_graphics_3d.h" | 15 #include "ppapi/c/pp_graphics_3d.h" |
16 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" | 16 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
18 #include "ppapi/shared_impl/api_id.h" | 18 #include "ppapi/shared_impl/api_id.h" |
19 #include "ppapi/shared_impl/ppapi_globals.h" | 19 #include "ppapi/shared_impl/ppapi_globals.h" |
20 #include "ppapi/shared_impl/var.h" | 20 #include "ppapi/shared_impl/var.h" |
21 #include "webkit/plugins/ppapi/event_conversion.h" | 21 #include "webkit/plugins/ppapi/event_conversion.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 GuestToEmbedderChannel::GuestToEmbedderChannel( | 25 GuestToEmbedderChannel::GuestToEmbedderChannel( |
26 const std::string& embedder_channel_name) | 26 const std::string& embedder_channel_name, |
| 27 const IPC::ChannelHandle& embedder_channel_handle) |
27 : Dispatcher(NULL), | 28 : Dispatcher(NULL), |
28 embedder_channel_name_(embedder_channel_name) { | 29 embedder_channel_name_(embedder_channel_name), |
| 30 embedder_channel_handle_(embedder_channel_handle) { |
29 SetSerializationRules(new BrowserPluginVarSerializationRules()); | 31 SetSerializationRules(new BrowserPluginVarSerializationRules()); |
30 } | 32 } |
31 | 33 |
32 GuestToEmbedderChannel::~GuestToEmbedderChannel() { | 34 GuestToEmbedderChannel::~GuestToEmbedderChannel() { |
33 } | 35 } |
34 | 36 |
35 bool GuestToEmbedderChannel::OnMessageReceived(const IPC::Message& message) { | 37 bool GuestToEmbedderChannel::OnMessageReceived(const IPC::Message& message) { |
36 bool handled = true; | 38 bool handled = true; |
37 IPC_BEGIN_MESSAGE_MAP(GuestToEmbedderChannel, message) | 39 IPC_BEGIN_MESSAGE_MAP(GuestToEmbedderChannel, message) |
38 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnSupportsInterface) | 40 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnSupportsInterface) |
39 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnSetPreferences) | 41 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnSetPreferences) |
40 IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnReserveInstanceId) | 42 IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnReserveInstanceId) |
41 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, | 43 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, |
42 OnDidCreate) | 44 OnDidCreate) |
43 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, | 45 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, |
44 OnDidDestroy) | 46 OnDidDestroy) |
45 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, | 47 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, |
46 OnDidChangeView) | 48 OnDidChangeView) |
47 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, | 49 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, |
48 OnDidChangeFocus) | 50 OnDidChangeFocus) |
49 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, | 51 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, |
50 OnHandleMessage) | 52 OnHandleMessage) |
51 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent, | 53 IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent, |
52 OnHandleFilteredInputEvent) | 54 OnHandleFilteredInputEvent) |
53 IPC_MESSAGE_HANDLER(PpapiMsg_PPPGraphics3D_ContextLost, | 55 IPC_MESSAGE_HANDLER(PpapiMsg_PPPGraphics3D_ContextLost, |
54 OnContextLost) | 56 OnContextLost) |
| 57 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestReady, |
| 58 OnGuestReady) |
55 // Have the super handle all other messages. | 59 // Have the super handle all other messages. |
56 IPC_MESSAGE_UNHANDLED(handled = false) | 60 IPC_MESSAGE_UNHANDLED(handled = false) |
57 IPC_END_MESSAGE_MAP() | 61 IPC_END_MESSAGE_MAP() |
58 | 62 |
59 return handled; | 63 return handled; |
60 } | 64 } |
61 | 65 |
62 bool GuestToEmbedderChannel::Send(IPC::Message* message) { | 66 bool GuestToEmbedderChannel::Send(IPC::Message* message) { |
63 // We always want guest->host messages to arrive in-order. If some sync | 67 // We always want guest->host messages to arrive in-order. If some sync |
64 // and some async messages are sent in response to a synchronous | 68 // and some async messages are sent in response to a synchronous |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 bool GuestToEmbedderChannel::CreateGraphicsContext( | 157 bool GuestToEmbedderChannel::CreateGraphicsContext( |
154 WebGraphicsContext3DCommandBufferImpl* context, | 158 WebGraphicsContext3DCommandBufferImpl* context, |
155 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 159 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
156 bool offscreen, | 160 bool offscreen, |
157 RenderViewImpl* render_view) { | 161 RenderViewImpl* render_view) { |
158 std::vector<int32_t> attribs; | 162 std::vector<int32_t> attribs; |
159 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 163 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
160 | 164 |
161 ppapi::HostResource resource; | 165 ppapi::HostResource resource; |
162 DCHECK(render_view->guest_pp_instance()); | 166 DCHECK(render_view->guest_pp_instance()); |
163 // TODO(fsamuel): Support child contexts. | 167 // TODO(fsamuel): Support shared contexts. |
164 bool success = Send(new PpapiHostMsg_PPBGraphics3D_Create( | 168 bool success = Send(new PpapiHostMsg_PPBGraphics3D_Create( |
165 ppapi::API_ID_PPB_GRAPHICS_3D, | 169 ppapi::API_ID_PPB_GRAPHICS_3D, |
166 render_view->guest_pp_instance(), | 170 render_view->guest_pp_instance(), |
167 attribs, | 171 attribs, |
168 &resource)); | 172 &resource)); |
169 if (!success || resource.is_null()) | 173 if (!success || resource.is_null()) |
170 return false; | 174 return false; |
171 if (!offscreen) { | 175 if (!offscreen) { |
172 PP_Bool result = PP_FALSE; | 176 PP_Bool result = PP_FALSE; |
173 Send(new PpapiHostMsg_PPBInstance_BindGraphics( | 177 Send(new PpapiHostMsg_PPBInstance_BindGraphics( |
(...skipping 23 matching lines...) Expand all Loading... |
197 DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); | 201 DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); |
198 render_view_instances_[instance] = render_view->AsWeakPtr(); | 202 render_view_instances_[instance] = render_view->AsWeakPtr(); |
199 } | 203 } |
200 | 204 |
201 | 205 |
202 void GuestToEmbedderChannel::RemoveGuest(PP_Instance instance) { | 206 void GuestToEmbedderChannel::RemoveGuest(PP_Instance instance) { |
203 DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); | 207 DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); |
204 render_view_instances_.erase(instance); | 208 render_view_instances_.erase(instance); |
205 } | 209 } |
206 | 210 |
207 void GuestToEmbedderChannel::OnDidCreate(PP_Instance instance, | 211 void GuestToEmbedderChannel::OnDidCreate( |
| 212 PP_Instance instance, |
208 const std::vector<std::string>& argn, | 213 const std::vector<std::string>& argn, |
209 const std::vector<std::string>& argv, | 214 const std::vector<std::string>& argv, |
210 PP_Bool* result) { | 215 PP_Bool* result) { |
| 216 DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); |
| 217 RequestInputEvents(instance); |
211 *result = PP_TRUE; | 218 *result = PP_TRUE; |
212 } | 219 } |
213 | 220 |
214 void GuestToEmbedderChannel::OnDidDestroy(PP_Instance instance) { | 221 void GuestToEmbedderChannel::OnDidDestroy(PP_Instance instance) { |
| 222 InstanceMap::iterator it = render_view_instances_.find(instance); |
| 223 DCHECK(it != render_view_instances_.end()); |
| 224 RenderViewImpl* render_view = it->second; |
| 225 render_view->SetGuestToEmbedderChannel(NULL); |
| 226 render_view->set_guest_pp_instance(0); |
215 RemoveGuest(instance); | 227 RemoveGuest(instance); |
216 } | 228 } |
217 | 229 |
218 void GuestToEmbedderChannel::OnDidChangeView( | 230 void GuestToEmbedderChannel::OnDidChangeView( |
219 PP_Instance instance, | 231 PP_Instance instance, |
220 const ppapi::ViewData& new_data, | 232 const ppapi::ViewData& new_data, |
221 PP_Bool flash_fullscreen) { | 233 PP_Bool flash_fullscreen) { |
222 // We can't do anything with this message if we don't have a render view | 234 // We can't do anything with this message if we don't have a render view |
223 // yet. If we do have a RenderView then we need to tell the associated | 235 // yet. If we do have a RenderView then we need to tell the associated |
224 // WebContentsObserver to resize. | 236 // WebContentsObserver to resize. |
(...skipping 30 matching lines...) Expand all Loading... |
255 new BrowserPluginHostMsg_NavigateFromGuest( | 267 new BrowserPluginHostMsg_NavigateFromGuest( |
256 render_view->GetRoutingID(), | 268 render_view->GetRoutingID(), |
257 instance, | 269 instance, |
258 var->value())); | 270 var->value())); |
259 } | 271 } |
260 | 272 |
261 void GuestToEmbedderChannel::OnHandleFilteredInputEvent( | 273 void GuestToEmbedderChannel::OnHandleFilteredInputEvent( |
262 PP_Instance instance, | 274 PP_Instance instance, |
263 const ppapi::InputEventData& data, | 275 const ppapi::InputEventData& data, |
264 PP_Bool* result) { | 276 PP_Bool* result) { |
265 DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); | 277 if (render_view_instances_.find(instance) == render_view_instances_.end()) |
| 278 return; |
266 | 279 |
267 RenderViewImpl* render_view = render_view_instances_[instance]; | 280 RenderViewImpl* render_view = render_view_instances_[instance]; |
268 scoped_ptr<WebKit::WebInputEvent> web_input_event( | 281 scoped_ptr<WebKit::WebInputEvent> web_input_event( |
269 webkit::ppapi::CreateWebInputEvent(data)); | 282 webkit::ppapi::CreateWebInputEvent(data)); |
270 *result = PP_FromBool( | 283 *result = PP_FromBool( |
271 render_view->GetWebView()->handleInputEvent(*web_input_event)); | 284 render_view->GetWebView()->handleInputEvent(*web_input_event)); |
272 } | 285 } |
273 | 286 |
274 void GuestToEmbedderChannel::OnContextLost(PP_Instance instance) { | 287 void GuestToEmbedderChannel::OnContextLost(PP_Instance instance) { |
275 DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); | 288 DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); |
276 RenderViewImpl* render_view = render_view_instances_[instance]; | 289 RenderViewImpl* render_view = render_view_instances_[instance]; |
277 render_view->GetWebView()->loseCompositorContext(1); | 290 render_view->GetWebView()->loseCompositorContext(1); |
278 } | 291 } |
279 | 292 |
| 293 void GuestToEmbedderChannel::OnGuestReady(PP_Instance instance, |
| 294 int embedder_container_id) { |
| 295 RenderThreadImpl::current()->browser_plugin_channel_manager()-> |
| 296 GuestReady(instance, embedder_channel_name(), embedder_container_id); |
| 297 } |
| 298 |
280 } // namespace content | 299 } // namespace content |
OLD | NEW |