Chromium Code Reviews| Index: content/browser/browser_plugin/renderer_host/browser_plugin_message_filter.cc |
| diff --git a/content/browser/browser_plugin/renderer_host/browser_plugin_message_filter.cc b/content/browser/browser_plugin/renderer_host/browser_plugin_message_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ebbd684806c56443aaab08a69c2fdc8c5d5576e2 |
| --- /dev/null |
| +++ b/content/browser/browser_plugin/renderer_host/browser_plugin_message_filter.cc |
| @@ -0,0 +1,123 @@ |
| +// 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/browser/browser_plugin/renderer_host/browser_plugin_message_filter.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h" |
| +#include "content/browser/browser_plugin/guest_render_view_host_observer.h" |
| +#include "content/browser/renderer_host/render_view_host_impl.h" |
| +#include "content/browser/renderer_host/render_widget_helper.h" |
|
jam
2012/03/30 05:44:11
nit: here and below, only add the headers that you
Fady Samuel
2012/04/03 17:01:45
File Deleted.
|
| +#include "content/browser/tab_contents/tab_contents.h" |
| +#include "content/public/browser/navigation_controller.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_widget_host_view.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_view.h" |
| +#include "content/common/view_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/site_instance.h" |
| +#include "content/public/common/content_client.h" |
| +#include "ipc/ipc_message_macros.h" |
|
jam
2012/03/30 05:44:11
nit: not needed because by definition this comes w
Fady Samuel
2012/04/03 17:01:45
File Deleted.
|
| + |
| +BrowserPluginMessageFilter::BrowserPluginMessageFilter(int render_process_id) |
| + : render_process_id_(render_process_id) |
| +{ |
|
jam
2012/03/30 05:44:11
nit: should be in previous line according to style
Fady Samuel
2012/04/03 17:01:45
File Deleted.
|
| +} |
| + |
| +BrowserPluginMessageFilter::~BrowserPluginMessageFilter() { |
| +} |
| + |
| +bool BrowserPluginMessageFilter::OnMessageReceived(const IPC::Message& message, |
| + bool* message_was_ok) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP_EX(BrowserPluginMessageFilter, message, *message_was_ok) |
| + IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToBrowserPlugin, |
| + OnOpenChannelToBrowserPlugin) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP_EX() |
| + return handled; |
| +} |
| + |
| +void BrowserPluginMessageFilter::InitBrowserPluginOnUIThread( |
| + int32 routing_id, |
| + int32 instance_id, |
| + long long frame_id, |
| + const std::string& src, |
| + const gfx::Size& size) { |
| + |
|
jam
2012/03/30 05:44:11
nit: blank line
Fady Samuel
2012/04/03 17:01:45
File Deleted
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
|
jam
2012/03/30 05:44:11
If you want to filter messages on the UI thread, t
Fady Samuel
2012/04/03 17:01:45
Done.
|
| + |
| + content::RenderViewHost* render_view_host = |
| + content::RenderViewHost::FromID(render_process_id_, routing_id); |
| + DCHECK(render_view_host); |
| + |
| + TabContents* host_tab_contents = |
| + static_cast<TabContents*>(render_view_host->GetDelegate()); |
|
jam
2012/03/30 05:44:11
we try to avoid this cast, since it destroys the R
Fady Samuel
2012/04/03 17:01:45
Moved to BrowserPluginWebContentsObserver
|
| + BrowserPluginWebContentsObserver* contents_observer = NULL; |
| + if (hosts_.find(host_tab_contents) == hosts_.end()) { |
| + contents_observer = |
| + BrowserPluginWebContentsObserver::Create(host_tab_contents); |
| + hosts_[host_tab_contents] = contents_observer; |
| + } else { |
| + contents_observer = hosts_[host_tab_contents]; |
| + } |
| + DCHECK(contents_observer); |
| + |
| + content::BrowserContext* browser_context = |
| + render_view_host->GetProcess()->GetBrowserContext(); |
| + DCHECK(browser_context); |
| + |
| + GURL url(src); |
| + content::SiteInstance* site_instance = |
| + content::SiteInstance::CreateForURL( |
| + browser_context, url); |
| + content::WebContents* web_contents = content::WebContents::Create( |
| + browser_context, |
| + site_instance, |
| + MSG_ROUTING_NONE, |
| + NULL, // base tab contents |
| + NULL // session storage namespace |
| + ); |
| + // TODO(fsamuel): Set the WebContentsDelegate here. |
| + content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
| + DCHECK(host); |
| + |
| + // We need to make sure that the RenderViewHost knows that it's |
| + // hosting a guest RenderView so that it informs the RenderView |
| + // on a ViewMsg_RenderView. Guest RenderViews will avoid compositing |
| + // until a WebGraphicsContext3D is ready. |
| + static_cast<content::RenderViewHostImpl*>(host)->set_guest(true); |
| + |
| + // This should also create a RenderViewHost |
| + web_contents->GetController().LoadURL( |
| + url, |
| + content::Referrer(), |
| + content::PAGE_TRANSITION_HOME_PAGE, |
| + std::string()); |
| + |
| + host->GetView()->SetSize(size); |
| + |
| + GuestRenderViewHostObserver::Create(this, host, routing_id, instance_id); |
| + |
| + contents_observer->AddGuest(web_contents, frame_id); |
| +} |
| + |
| +// TODO(fsamuel): Can we get the initial URL to navigate to here too? |
| +void BrowserPluginMessageFilter::OnOpenChannelToBrowserPlugin( |
| + int32 host_id, |
| + int instance_id, |
| + long long frame_id, |
| + const std::string& src, |
| + const gfx::Size& size) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&BrowserPluginMessageFilter::InitBrowserPluginOnUIThread, |
| + base::Unretained(this), host_id, instance_id, frame_id, src, size)); |
| +} |
| + |