| 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/browser/browser_plugin/browser_plugin_message_filter.h" | 5 #include "content/browser/browser_plugin/browser_plugin_message_filter.h" |
| 6 | 6 |
| 7 #include "base/supports_user_data.h" | 7 #include "base/supports_user_data.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/gpu/gpu_process_host.h" | 9 #include "content/browser/gpu/gpu_process_host.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 void BrowserPluginMessageFilter::OnDestruct() const { | 52 void BrowserPluginMessageFilter::OnDestruct() const { |
| 53 BrowserThread::DeleteOnIOThread::Destruct(this); | 53 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BrowserPluginMessageFilter::OverrideThreadForMessage( | 56 void BrowserPluginMessageFilter::OverrideThreadForMessage( |
| 57 const IPC::Message& message, BrowserThread::ID* thread) { | 57 const IPC::Message& message, BrowserThread::ID* thread) { |
| 58 if (BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)) | 58 if (BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)) |
| 59 *thread = BrowserThread::UI; | 59 *thread = BrowserThread::UI; |
| 60 } | 60 } |
| 61 | 61 |
| 62 static void BrowserPluginGuestMessageCallback(const IPC::Message& message, | |
| 63 WebContents* guest_web_contents) { | |
| 64 if (!guest_web_contents) | |
| 65 return; | |
| 66 static_cast<WebContentsImpl*>(guest_web_contents)->GetBrowserPluginGuest()-> | |
| 67 OnMessageReceivedFromEmbedder(message); | |
| 68 } | |
| 69 | |
| 70 void BrowserPluginMessageFilter::ForwardMessageToGuest( | 62 void BrowserPluginMessageFilter::ForwardMessageToGuest( |
| 71 const IPC::Message& message) { | 63 const IPC::Message& message) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 73 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id_, | 65 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id_, |
| 74 message.routing_id()); | 66 message.routing_id()); |
| 75 if (!rvh) | 67 if (!rvh) |
| 76 return; | 68 return; |
| 77 | 69 |
| 78 WebContents* embedder_web_contents = WebContents::FromRenderViewHost(rvh); | 70 WebContents* embedder_web_contents = WebContents::FromRenderViewHost(rvh); |
| 79 | 71 |
| 80 int browser_plugin_instance_id = 0; | 72 int browser_plugin_instance_id = 0; |
| 81 // All allowed messages must have instance_id as their first parameter. | 73 // All allowed messages must have instance_id as their first parameter. |
| 82 PickleIterator iter(message); | 74 PickleIterator iter(message); |
| 83 bool success = iter.ReadInt(&browser_plugin_instance_id); | 75 bool success = iter.ReadInt(&browser_plugin_instance_id); |
| 84 DCHECK(success); | 76 DCHECK(success); |
| 85 embedder_web_contents->GetBrowserContext()->GetGuestManager()-> | 77 WebContents* guest_web_contents = |
| 86 MaybeGetGuestByInstanceIDOrKill( | 78 embedder_web_contents->GetBrowserContext() |
| 87 embedder_web_contents, | 79 ->GetGuestManager() |
| 88 browser_plugin_instance_id, | 80 ->GetGuestByInstanceID(embedder_web_contents, |
| 89 base::Bind(&BrowserPluginGuestMessageCallback, | 81 browser_plugin_instance_id); |
| 90 message)); | 82 if (!guest_web_contents) |
| 83 return; |
| 84 |
| 85 static_cast<WebContentsImpl*>(guest_web_contents) |
| 86 ->GetBrowserPluginGuest() |
| 87 ->OnMessageReceivedFromEmbedder(message); |
| 91 } | 88 } |
| 92 | 89 |
| 93 void BrowserPluginMessageFilter::OnSwapBuffersACK( | 90 void BrowserPluginMessageFilter::OnSwapBuffersACK( |
| 94 const FrameHostMsg_BuffersSwappedACK_Params& params) { | 91 const FrameHostMsg_BuffersSwappedACK_Params& params) { |
| 95 GpuProcessHost* gpu_host = GpuProcessHost::FromID(params.gpu_host_id); | 92 GpuProcessHost* gpu_host = GpuProcessHost::FromID(params.gpu_host_id); |
| 96 if (!gpu_host) | 93 if (!gpu_host) |
| 97 return; | 94 return; |
| 98 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 95 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 99 ack_params.mailbox = params.mailbox; | 96 ack_params.mailbox = params.mailbox; |
| 100 ack_params.sync_point = params.sync_point; | 97 ack_params.sync_point = params.sync_point; |
| 101 gpu_host->Send(new AcceleratedSurfaceMsg_BufferPresented(params.gpu_route_id, | 98 gpu_host->Send(new AcceleratedSurfaceMsg_BufferPresented(params.gpu_route_id, |
| 102 ack_params)); | 99 ack_params)); |
| 103 } | 100 } |
| 104 | 101 |
| 105 } // namespace content | 102 } // namespace content |
| OLD | NEW |