| Index: content/renderer/guest_render_view_observer.cc
|
| diff --git a/content/renderer/guest_render_view_observer.cc b/content/renderer/guest_render_view_observer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d418dc3908e5f67f00b5e75ccf2111ef4c8d8b63
|
| --- /dev/null
|
| +++ b/content/renderer/guest_render_view_observer.cc
|
| @@ -0,0 +1,91 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/renderer/guest_render_view_observer.h"
|
| +
|
| +#include "base/process_util.h"
|
| +#include "content/common/child_process.h"
|
| +#include "content/common/view_messages.h"
|
| +#include "content/public/renderer/render_view.h"
|
| +#include "content/renderer/plugins/browser_plugin_placeholder.h"
|
| +#include "content/renderer/render_view_impl.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
| +
|
| +using WebKit::WebGraphicsContext3D;
|
| +
|
| +GuestRenderViewObserver::GuestRenderViewObserver(
|
| + content::RenderView* render_view)
|
| + : RenderViewObserver(render_view),
|
| + guest_to_host_channel_(this, render_view->GetWebView()) {
|
| +}
|
| +
|
| +bool GuestRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(GuestRenderViewObserver, message)
|
| + IPC_MESSAGE_HANDLER(PpapiMsg_CreateChannel, OnMsgCreateChannel)
|
| + IPC_MESSAGE_HANDLER(ViewMsg_GuestReady, OnMsgGuestReady)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| +
|
| + return handled;
|
| +}
|
| +
|
| +void GuestRenderViewObserver::OnMsgCreateChannel(
|
| + base::ProcessHandle host_process_handle,
|
| + int renderer_id) {
|
| + IPC::ChannelHandle plugin_handle;
|
| + plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(),
|
| + renderer_id);
|
| + bool success = guest_to_host_channel_.InitChannel(plugin_handle);
|
| +#if defined(OS_POSIX)
|
| + // On POSIX, transfer ownership of the renderer-side (client) FD.
|
| + // This ensures this process will be notified when it is closed even if a
|
| + // connection is not established.
|
| + plugin_handle.socket =
|
| + base::FileDescriptor(guest_to_host_channel_.TakeRendererFD(), true);
|
| + // Check the validity of fd for bug investigation. Remove after fixed.
|
| + // See for details: crbug.com/103957.
|
| + CHECK_NE(-1, plugin_handle.socket.fd);
|
| + if (plugin_handle.socket.fd == -1)
|
| + success = false;
|
| +#endif
|
| + PpapiHostMsg_ChannelCreated* msg;
|
| + if (success)
|
| + msg = new PpapiHostMsg_ChannelCreated(plugin_handle);
|
| + else
|
| + msg = new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle());
|
| + msg->set_routing_id(routing_id());
|
| + Send(msg);
|
| +}
|
| +
|
| +void GuestRenderViewObserver::OnMsgGuestReady(
|
| + int instance_id,
|
| + base::ProcessHandle process_handle,
|
| + const IPC::ChannelHandle& channel_handle) {
|
| + BrowserPluginPlaceholder* placeholder =
|
| + BrowserPluginPlaceholder::FromID(instance_id);
|
| + if (placeholder)
|
| + placeholder->GuestReady(process_handle, channel_handle);
|
| +}
|
| +
|
| +WebGraphicsContext3D* GuestRenderViewObserver::GetWebGraphicsContext3D() {
|
| + return guest_to_host_channel_.GetWebGraphicsContext3D();
|
| +}
|
| +
|
| +void GuestRenderViewObserver::GraphicsContextCreated() {
|
| + gfx::Size size(guest_to_host_channel_.width(),
|
| + guest_to_host_channel_.height());
|
| + gfx::Rect rect(size);
|
| +
|
| + DCHECK(render_view()->GetWebView()->graphicsContext3D());
|
| + // Tell the existing WebGraphicsContext3D to fake a
|
| + // lost context.
|
| + render_view()->GetWebView()->graphicsContext3D()->playDead();
|
| + // By forcing a new layout and composite, we force WebKit
|
| + // to pick up a new WebGraphicsContext3D. In this case, it will
|
| + // grab a WebGraphicsContext3DGuest.
|
| + render_view()->GetWebView()->layout();
|
| + render_view()->GetWebView()->composite(true);
|
| +}
|
|
|