OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/guest_render_view_observer.h" |
| 6 |
| 7 #include "base/process_util.h" |
| 8 #include "content/common/child_process.h" |
| 9 #include "content/common/view_messages.h" |
| 10 #include "content/public/renderer/render_view.h" |
| 11 #include "content/renderer/plugins/browser_plugin_placeholder.h" |
| 12 #include "content/renderer/render_view_impl.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 15 |
| 16 using WebKit::WebGraphicsContext3D; |
| 17 |
| 18 GuestRenderViewObserver::GuestRenderViewObserver( |
| 19 content::RenderView* render_view) |
| 20 : RenderViewObserver(render_view), |
| 21 guest_to_host_channel_(this, render_view->GetWebView()) { |
| 22 } |
| 23 |
| 24 bool GuestRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
| 25 bool handled = true; |
| 26 IPC_BEGIN_MESSAGE_MAP(GuestRenderViewObserver, message) |
| 27 IPC_MESSAGE_HANDLER(PpapiMsg_CreateChannel, OnMsgCreateChannel) |
| 28 IPC_MESSAGE_HANDLER(ViewMsg_GuestReady, OnMsgGuestReady) |
| 29 IPC_MESSAGE_UNHANDLED(handled = false) |
| 30 IPC_END_MESSAGE_MAP() |
| 31 |
| 32 return handled; |
| 33 } |
| 34 |
| 35 void GuestRenderViewObserver::OnMsgCreateChannel( |
| 36 base::ProcessHandle host_process_handle, |
| 37 int renderer_id) { |
| 38 IPC::ChannelHandle plugin_handle; |
| 39 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(), |
| 40 renderer_id); |
| 41 bool success = guest_to_host_channel_.InitChannel(plugin_handle); |
| 42 #if defined(OS_POSIX) |
| 43 // On POSIX, transfer ownership of the renderer-side (client) FD. |
| 44 // This ensures this process will be notified when it is closed even if a |
| 45 // connection is not established. |
| 46 plugin_handle.socket = |
| 47 base::FileDescriptor(guest_to_host_channel_.TakeRendererFD(), true); |
| 48 // Check the validity of fd for bug investigation. Remove after fixed. |
| 49 // See for details: crbug.com/103957. |
| 50 CHECK_NE(-1, plugin_handle.socket.fd); |
| 51 if (plugin_handle.socket.fd == -1) |
| 52 success = false; |
| 53 #endif |
| 54 PpapiHostMsg_ChannelCreated* msg; |
| 55 if (success) |
| 56 msg = new PpapiHostMsg_ChannelCreated(plugin_handle); |
| 57 else |
| 58 msg = new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle()); |
| 59 msg->set_routing_id(routing_id()); |
| 60 Send(msg); |
| 61 } |
| 62 |
| 63 void GuestRenderViewObserver::OnMsgGuestReady( |
| 64 int instance_id, |
| 65 base::ProcessHandle process_handle, |
| 66 const IPC::ChannelHandle& channel_handle) { |
| 67 BrowserPluginPlaceholder* placeholder = |
| 68 BrowserPluginPlaceholder::FromID(instance_id); |
| 69 if (placeholder) |
| 70 placeholder->GuestReady(process_handle, channel_handle); |
| 71 } |
| 72 |
| 73 WebGraphicsContext3D* GuestRenderViewObserver::GetWebGraphicsContext3D() { |
| 74 return guest_to_host_channel_.GetWebGraphicsContext3D(); |
| 75 } |
| 76 |
| 77 void GuestRenderViewObserver::GraphicsContextCreated() { |
| 78 gfx::Size size(guest_to_host_channel_.width(), |
| 79 guest_to_host_channel_.height()); |
| 80 gfx::Rect rect(size); |
| 81 |
| 82 DCHECK(render_view()->GetWebView()->graphicsContext3D()); |
| 83 // Tell the existing WebGraphicsContext3D to fake a |
| 84 // lost context. |
| 85 render_view()->GetWebView()->graphicsContext3D()->playDead(); |
| 86 // By forcing a new layout and composite, we force WebKit |
| 87 // to pick up a new WebGraphicsContext3D. In this case, it will |
| 88 // grab a WebGraphicsContext3DGuest. |
| 89 render_view()->GetWebView()->layout(); |
| 90 render_view()->GetWebView()->composite(true); |
| 91 } |
OLD | NEW |