From 14cf0f1e4ecfa9e16b7976895ebbd7fabb4edaae Mon Sep 17 00:00:00 2001 From: "fsamuel@chromium.org" Date: Mon, 18 Jun 2012 17:15:57 +0000 Subject: Browser Plugin: Move to old directories A new implementation is coming but this current implementation is still in use. Moving the current implementation to old directories to make it easy to get rid of once the new implementation has been upstreamed. BUG=none TEST=manually, browser plugin continues to work. Review URL: https://chromiumcodereview.appspot.com/10555029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142743 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/browser_plugin/browser_plugin_host.cc | 227 --------------- .../browser/browser_plugin/browser_plugin_host.h | 129 --------- .../browser_plugin/browser_plugin_host_helper.cc | 61 ---- .../browser_plugin/browser_plugin_host_helper.h | 50 ---- .../browser_plugin/old/browser_plugin_host.cc | 227 +++++++++++++++ .../browser_plugin/old/browser_plugin_host.h | 129 +++++++++ .../old/browser_plugin_host_helper.cc | 61 ++++ .../old/browser_plugin_host_helper.h | 50 ++++ content/browser/web_contents/web_contents_impl.cc | 2 +- content/browser/web_contents/web_contents_impl.h | 2 +- content/content_browser.gypi | 8 +- content/content_renderer.gypi | 24 +- content/renderer/browser_plugin/browser_plugin.cc | 157 ----------- content/renderer/browser_plugin/browser_plugin.h | 90 ------ .../browser_plugin_channel_manager.cc | 144 ---------- .../browser_plugin_channel_manager.h | 82 ------ .../browser_plugin/browser_plugin_constants.cc | 10 - .../browser_plugin/browser_plugin_constants.h | 15 - .../browser_plugin/browser_plugin_registry.cc | 45 --- .../browser_plugin/browser_plugin_registry.h | 37 --- .../browser_plugin_var_serialization_rules.cc | 51 ---- .../browser_plugin_var_serialization_rules.h | 35 --- .../browser_plugin/guest_to_embedder_channel.cc | 306 --------------------- .../browser_plugin/guest_to_embedder_channel.h | 138 ---------- .../renderer/browser_plugin/old/browser_plugin.cc | 157 +++++++++++ .../renderer/browser_plugin/old/browser_plugin.h | 90 ++++++ .../old/browser_plugin_channel_manager.cc | 144 ++++++++++ .../old/browser_plugin_channel_manager.h | 82 ++++++ .../browser_plugin/old/browser_plugin_constants.cc | 10 + .../browser_plugin/old/browser_plugin_constants.h | 15 + .../browser_plugin/old/browser_plugin_registry.cc | 45 +++ .../browser_plugin/old/browser_plugin_registry.h | 37 +++ .../old/browser_plugin_var_serialization_rules.cc | 51 ++++ .../old/browser_plugin_var_serialization_rules.h | 35 +++ .../old/guest_to_embedder_channel.cc | 306 +++++++++++++++++++++ .../browser_plugin/old/guest_to_embedder_channel.h | 138 ++++++++++ .../renderer/pepper/pepper_plugin_delegate_impl.cc | 4 +- content/renderer/render_thread_impl.cc | 4 +- content/renderer/render_view_impl.cc | 8 +- 39 files changed, 1603 insertions(+), 1603 deletions(-) delete mode 100644 content/browser/browser_plugin/browser_plugin_host.cc delete mode 100644 content/browser/browser_plugin/browser_plugin_host.h delete mode 100644 content/browser/browser_plugin/browser_plugin_host_helper.cc delete mode 100644 content/browser/browser_plugin/browser_plugin_host_helper.h create mode 100644 content/browser/browser_plugin/old/browser_plugin_host.cc create mode 100644 content/browser/browser_plugin/old/browser_plugin_host.h create mode 100644 content/browser/browser_plugin/old/browser_plugin_host_helper.cc create mode 100644 content/browser/browser_plugin/old/browser_plugin_host_helper.h delete mode 100644 content/renderer/browser_plugin/browser_plugin.cc delete mode 100644 content/renderer/browser_plugin/browser_plugin.h delete mode 100644 content/renderer/browser_plugin/browser_plugin_channel_manager.cc delete mode 100644 content/renderer/browser_plugin/browser_plugin_channel_manager.h delete mode 100644 content/renderer/browser_plugin/browser_plugin_constants.cc delete mode 100644 content/renderer/browser_plugin/browser_plugin_constants.h delete mode 100644 content/renderer/browser_plugin/browser_plugin_registry.cc delete mode 100644 content/renderer/browser_plugin/browser_plugin_registry.h delete mode 100644 content/renderer/browser_plugin/browser_plugin_var_serialization_rules.cc delete mode 100644 content/renderer/browser_plugin/browser_plugin_var_serialization_rules.h delete mode 100644 content/renderer/browser_plugin/guest_to_embedder_channel.cc delete mode 100644 content/renderer/browser_plugin/guest_to_embedder_channel.h create mode 100644 content/renderer/browser_plugin/old/browser_plugin.cc create mode 100644 content/renderer/browser_plugin/old/browser_plugin.h create mode 100644 content/renderer/browser_plugin/old/browser_plugin_channel_manager.cc create mode 100644 content/renderer/browser_plugin/old/browser_plugin_channel_manager.h create mode 100644 content/renderer/browser_plugin/old/browser_plugin_constants.cc create mode 100644 content/renderer/browser_plugin/old/browser_plugin_constants.h create mode 100644 content/renderer/browser_plugin/old/browser_plugin_registry.cc create mode 100644 content/renderer/browser_plugin/old/browser_plugin_registry.h create mode 100644 content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.cc create mode 100644 content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h create mode 100644 content/renderer/browser_plugin/old/guest_to_embedder_channel.cc create mode 100644 content/renderer/browser_plugin/old/guest_to_embedder_channel.h diff --git a/content/browser/browser_plugin/browser_plugin_host.cc b/content/browser/browser_plugin/browser_plugin_host.cc deleted file mode 100644 index 28e4e8f..0000000 --- a/content/browser/browser_plugin/browser_plugin_host.cc +++ /dev/null @@ -1,227 +0,0 @@ -// 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/browser_plugin_host.h" - -#include "content/browser/browser_plugin/browser_plugin_host_helper.h" -#include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/common/browser_plugin_messages.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/site_instance.h" -#include "content/public/browser/web_contents_view.h" -#include "ppapi/proxy/ppapi_messages.h" - -namespace content { - -BrowserPluginHost::BrowserPluginHost( - WebContentsImpl* web_contents) - : WebContentsObserver(web_contents), - embedder_render_process_host_(NULL), - instance_id_(0) { - // Listen to visibility changes so that an embedder hides its guests - // as well. - registrar_.Add(this, - NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, - Source(web_contents)); - // Construct plumbing helpers when a new RenderViewHost is created for - // this BrowserPluginHost's WebContentsImpl. - registrar_.Add(this, - NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, - Source(web_contents)); -} - -BrowserPluginHost::~BrowserPluginHost() { -} - -BrowserPluginHost* BrowserPluginHost::GetGuestByContainerID(int container_id) { - ContainerInstanceMap::const_iterator it = - guests_by_container_id_.find(container_id); - if (it != guests_by_container_id_.end()) - return it->second; - return NULL; -} - -void BrowserPluginHost::RegisterContainerInstance( - int container_id, - BrowserPluginHost* observer) { - DCHECK(guests_by_container_id_.find(container_id) == - guests_by_container_id_.end()); - guests_by_container_id_[container_id] = observer; -} - -bool BrowserPluginHost::TakeFocus(bool reverse) { - embedder_render_process_host()->Send( - new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); - return true; -} - -bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(BrowserPluginHost, message) - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromGuest, - OnNavigateFromGuest) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void BrowserPluginHost::NavigateGuestFromEmbedder( - RenderViewHost* render_view_host, - int container_instance_id, - long long frame_id, - const std::string& src) { - BrowserPluginHost* guest_observer = - GetGuestByContainerID(container_instance_id); - WebContentsImpl* guest_web_contents = - guest_observer ? - static_cast(guest_observer->web_contents()): NULL; - if (!guest_observer) { - guest_web_contents = - static_cast( - WebContents::Create( - web_contents()->GetBrowserContext(), - render_view_host->GetSiteInstance(), - MSG_ROUTING_NONE, - NULL, // base WebContents - NULL // session storage namespace - )); - guest_observer = - guest_web_contents->browser_plugin_host(); - guest_observer->set_embedder_render_process_host( - render_view_host->GetProcess()); - guest_observer->set_instance_id(container_instance_id); - RegisterContainerInstance(container_instance_id, guest_observer); - AddGuest(guest_web_contents, frame_id); - } - GURL url(src); - guest_observer->web_contents()->SetDelegate(guest_observer); - guest_observer->web_contents()->GetController().LoadURL( - url, - Referrer(), - PAGE_TRANSITION_AUTO_SUBFRAME, - std::string()); -} - -void BrowserPluginHost::OnNavigateFromGuest( - PP_Instance instance, - const std::string& src) { - DCHECK(embedder_render_process_host()); - GURL url(src); - web_contents()->GetController().LoadURL( - url, - Referrer(), - PAGE_TRANSITION_AUTO_SUBFRAME, - std::string()); -} - -void BrowserPluginHost::ConnectEmbedderToChannel( - RenderViewHost* render_view_host, - const IPC::ChannelHandle& channel_handle) { - DCHECK(embedder_render_process_host()); - // Tell the BrowserPlugin in the embedder that we're done and that it can - // begin using the guest renderer. - embedder_render_process_host()->Send( - new BrowserPluginMsg_LoadGuest( - instance_id(), - render_view_host->GetProcess()-> - GetID(), - channel_handle)); -} - -void BrowserPluginHost::AddGuest(WebContentsImpl* guest, int64 frame_id) { - guests_[guest] = frame_id; -} - -void BrowserPluginHost::RemoveGuest(WebContentsImpl* guest) { - guests_.erase(guest); -} - -void BrowserPluginHost::DestroyGuests() { - for (GuestMap::const_iterator it = guests_.begin(); - it != guests_.end(); ++it) { - WebContentsImpl* web_contents = it->first; - delete web_contents; - } - guests_.clear(); - guests_by_container_id_.clear(); -} - -void BrowserPluginHost::DidCommitProvisionalLoadForFrame( - int64 frame_id, - bool is_main_frame, - const GURL& url, - PageTransition transition_type, - RenderViewHost* render_view_host) { - // Clean-up guests that lie in the frame that we're navigating. - typedef std::set GuestSet; - GuestSet guests_to_delete; - for (GuestMap::const_iterator it = guests_.begin(); - it != guests_.end(); ++it) { - WebContentsImpl* web_contents = it->first; - if (it->second == frame_id) { - guests_to_delete.insert(web_contents); - } - } - for (GuestSet::const_iterator it = guests_to_delete.begin(); - it != guests_to_delete.end(); ++it) { - delete *it; - guests_.erase(*it); - } -} - -void BrowserPluginHost::RenderViewDeleted(RenderViewHost* render_view_host) { - // TODO(fsamuel): For some reason ToT hangs when killing a guest, this wasn't - // the case earlier. Presumably, when a guest is killed/crashes, one of - // RenderViewDeleted, RenderViewGone or WebContentsDestroyed will get called. - // At that point, we should remove reference to this BrowserPluginHost - // from its embedder, in addition to destroying its guests, to ensure - // that we do not attempt a double delete. - DestroyGuests(); -} - -void BrowserPluginHost::RenderViewGone(base::TerminationStatus status) { - DestroyGuests(); -} - -void BrowserPluginHost::WebContentsDestroyed(WebContents* web_contents) { - DestroyGuests(); -} - -void BrowserPluginHost::Observe( - int type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type) { - case NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { - RenderViewHost* render_view_host = - Details(details).ptr(); - // BrowserPluginHostHelper is destroyed when its associated RenderViewHost - // is destroyed. - new BrowserPluginHostHelper(this, render_view_host); - break; - } - case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { - bool visible = *Details(details).ptr(); - // If the embedder is hidden we need to hide the guests as well. - for (GuestMap::const_iterator it = guests_.begin(); - it != guests_.end(); ++it) { - WebContentsImpl* web_contents = it->first; - if (visible) - web_contents->ShowContents(); - else - web_contents->HideContents(); - } - break; - } - default: - NOTREACHED() << "Unexpected notification type: " << type; - } -} - -} // namespace content diff --git a/content/browser/browser_plugin/browser_plugin_host.h b/content/browser/browser_plugin/browser_plugin_host.h deleted file mode 100644 index 7b8f18e..0000000 --- a/content/browser/browser_plugin/browser_plugin_host.h +++ /dev/null @@ -1,129 +0,0 @@ -// 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. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ -#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__ -#pragma once - -#include - -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_contents_observer.h" -#include "ppapi/c/pp_instance.h" -#include "ui/gfx/size.h" - -class WebContentsImpl; - -namespace content { - -class RenderProcessHost; - -// A BrowserPluginHost object is used by both embedders and guests. -// The primary purpose of BrowserPluginHost is to allow an embedder -// to manage the lifetime of its guests. It cleans up its guests -// on navigation, crashes, and "hides" guests when it hides. -// For the guest, BrowserPluginHost keeps track of its embedder, -// and its BrowserPlugin instance ID. -class BrowserPluginHost : public WebContentsObserver, - public NotificationObserver, - public WebContentsDelegate { - public: - // BrowserPluginHost is owned by a WebContentsImpl. Here it takes in its - // owner. The owner can be either a guest or embedder WebContents. - explicit BrowserPluginHost(WebContentsImpl* web_contents); - - virtual ~BrowserPluginHost(); - - void ConnectEmbedderToChannel(RenderViewHost* render_view_host, - const IPC::ChannelHandle& handle); - - // This is called on the first navigation of the browser plugin. It creates - // a new WebContentsImpl for the guest, associates it with its embedder, sets - // its size and navigates it to the src URL. - void NavigateGuestFromEmbedder(RenderViewHost* render_view_host, - int container_instance_id, - long long frame_id, - const std::string& src); - - RenderProcessHost* embedder_render_process_host() const { - return embedder_render_process_host_; - } - int instance_id() const { return instance_id_; } - - private: - typedef std::map GuestMap; - typedef std::map ContainerInstanceMap; - - // Get a guest BrowserPluginHost by its container ID specified - // in BrowserPlugin. - BrowserPluginHost* GetGuestByContainerID(int container_id); - - // Associate a guest with its container instance ID. - void RegisterContainerInstance( - int container_id, - BrowserPluginHost* observer); - - // An embedder BrowserPluginHost keeps track of - // its guests so that if it navigates away, its associated RenderView - // crashes or it is hidden, it takes appropriate action on the guest. - void AddGuest(WebContentsImpl* guest, int64 frame_id); - - // This removes a guest from an embedder's guest list. - // TODO(fsamuel): Use this when deleting guest after they crash. - // ToT plugin crash handling seems to be broken in this case and so I can't - // test this scenario at the moment. Delete this comment once fixed. - void RemoveGuest(WebContentsImpl* guest); - - void set_embedder_render_process_host( - RenderProcessHost* embedder_render_process_host) { - embedder_render_process_host_ = embedder_render_process_host; - } - void set_instance_id(int instance_id) { instance_id_ = instance_id; } - - void OnNavigateFromGuest(PP_Instance instance, - const std::string& src); - - void DestroyGuests(); - - // WebContentsDelegate implementation. - virtual bool TakeFocus(bool reverse) OVERRIDE; - - // WebContentObserver implementation. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - // Used to monitor frame navigation to cleanup guests when a frame navigates - // away from the browser plugin it's hosting. - virtual void DidCommitProvisionalLoadForFrame( - int64 frame_id, - bool is_main_frame, - const GURL& url, - PageTransition transition_type, - RenderViewHost* render_view_host) OVERRIDE; - virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; - virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; - virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; - - // NotificationObserver method override. - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) OVERRIDE; - - // A scoped container for notification registries. - NotificationRegistrar registrar_; - RenderProcessHost* embedder_render_process_host_; - std::string embedder_channel_name_; - // An identifier that uniquely identifies a browser plugin container - // within an embedder. - int instance_id_; - gfx::Size initial_size_; - GuestMap guests_; - ContainerInstanceMap guests_by_container_id_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPluginHost); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H_ diff --git a/content/browser/browser_plugin/browser_plugin_host_helper.cc b/content/browser/browser_plugin/browser_plugin_host_helper.cc deleted file mode 100644 index d7bd973..0000000 --- a/content/browser/browser_plugin/browser_plugin_host_helper.cc +++ /dev/null @@ -1,61 +0,0 @@ -// 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/browser_plugin_host_helper.h" - -#include "content/browser/browser_plugin/browser_plugin_host.h" -#include "content/common/browser_plugin_messages.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/render_widget_host_view.h" -#include "ui/gfx/size.h" - -namespace content { - -BrowserPluginHostHelper::BrowserPluginHostHelper( - BrowserPluginHost* browser_plugin_host, - RenderViewHost* render_view_host) - : RenderViewHostObserver(render_view_host), - browser_plugin_host_(browser_plugin_host) { -} - -BrowserPluginHostHelper::~BrowserPluginHostHelper() { -} - - -bool BrowserPluginHostHelper::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(BrowserPluginHostHelper, message) - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ConnectToChannel, - OnConnectToChannel) - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromEmbedder, - OnNavigateGuestFromEmbedder) - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void BrowserPluginHostHelper::OnConnectToChannel( - const IPC::ChannelHandle& channel_handle) { - browser_plugin_host_->ConnectEmbedderToChannel( - render_view_host(), - channel_handle); -} - -void BrowserPluginHostHelper::OnNavigateGuestFromEmbedder( - int32 instance_id, - long long frame_id, - const std::string& src) { - browser_plugin_host_->NavigateGuestFromEmbedder( - render_view_host(), - instance_id, - frame_id, - src); -} - -void BrowserPluginHostHelper::OnResizeGuest(int width, int height) { - render_view_host()->GetView()->SetSize(gfx::Size(width, height)); -} - -} // namespace content diff --git a/content/browser/browser_plugin/browser_plugin_host_helper.h b/content/browser/browser_plugin/browser_plugin_host_helper.h deleted file mode 100644 index f96892b..0000000 --- a/content/browser/browser_plugin/browser_plugin_host_helper.h +++ /dev/null @@ -1,50 +0,0 @@ -// 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. - -#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_HELPER_H__ -#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_HELPER_H__ -#pragma once - -#include - -#include "content/public/browser/render_view_host_observer.h" - -namespace gfx { -class Size; -} - -namespace content { - -class BrowserPluginHost; - -// This class acts as a plumber helper for BrowserPluginHost. A lot -// of messages coming from guests need to know the guest's RenderViewHost. -// BrowserPluginHostHelper handles BrowserPluginHost messages and relays -// them with their associated RenderViewHosts to BrowserPluginHost where they -// will be handled. -class BrowserPluginHostHelper : public RenderViewHostObserver { - public: - BrowserPluginHostHelper(BrowserPluginHost* browser_plugin_host, - RenderViewHost* render_view_host); - virtual ~BrowserPluginHostHelper(); - - private: - void OnConnectToChannel(const IPC::ChannelHandle& channel_handle); - void OnNavigateGuestFromEmbedder(int container_instance_id, - long long frame_id, - const std::string& src); - void OnResizeGuest(int width, int height); - - // RenderViewHostObserver implementation. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - - BrowserPluginHost* browser_plugin_host_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostHelper); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_HELPER_H__ - diff --git a/content/browser/browser_plugin/old/browser_plugin_host.cc b/content/browser/browser_plugin/old/browser_plugin_host.cc new file mode 100644 index 0000000..9997f09 --- /dev/null +++ b/content/browser/browser_plugin/old/browser_plugin_host.cc @@ -0,0 +1,227 @@ +// 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/old/browser_plugin_host.h" + +#include "content/browser/browser_plugin/old/browser_plugin_host_helper.h" +#include "content/browser/renderer_host/render_view_host_impl.h" +#include "content/browser/web_contents/web_contents_impl.h" +#include "content/common/browser_plugin_messages.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_types.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/site_instance.h" +#include "content/public/browser/web_contents_view.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace content { + +BrowserPluginHost::BrowserPluginHost( + WebContentsImpl* web_contents) + : WebContentsObserver(web_contents), + embedder_render_process_host_(NULL), + instance_id_(0) { + // Listen to visibility changes so that an embedder hides its guests + // as well. + registrar_.Add(this, + NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, + Source(web_contents)); + // Construct plumbing helpers when a new RenderViewHost is created for + // this BrowserPluginHost's WebContentsImpl. + registrar_.Add(this, + NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, + Source(web_contents)); +} + +BrowserPluginHost::~BrowserPluginHost() { +} + +BrowserPluginHost* BrowserPluginHost::GetGuestByContainerID(int container_id) { + ContainerInstanceMap::const_iterator it = + guests_by_container_id_.find(container_id); + if (it != guests_by_container_id_.end()) + return it->second; + return NULL; +} + +void BrowserPluginHost::RegisterContainerInstance( + int container_id, + BrowserPluginHost* observer) { + DCHECK(guests_by_container_id_.find(container_id) == + guests_by_container_id_.end()); + guests_by_container_id_[container_id] = observer; +} + +bool BrowserPluginHost::TakeFocus(bool reverse) { + embedder_render_process_host()->Send( + new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); + return true; +} + +bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(BrowserPluginHost, message) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromGuest, + OnNavigateFromGuest) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void BrowserPluginHost::NavigateGuestFromEmbedder( + RenderViewHost* render_view_host, + int container_instance_id, + long long frame_id, + const std::string& src) { + BrowserPluginHost* guest_observer = + GetGuestByContainerID(container_instance_id); + WebContentsImpl* guest_web_contents = + guest_observer ? + static_cast(guest_observer->web_contents()): NULL; + if (!guest_observer) { + guest_web_contents = + static_cast( + WebContents::Create( + web_contents()->GetBrowserContext(), + render_view_host->GetSiteInstance(), + MSG_ROUTING_NONE, + NULL, // base WebContents + NULL // session storage namespace + )); + guest_observer = + guest_web_contents->browser_plugin_host(); + guest_observer->set_embedder_render_process_host( + render_view_host->GetProcess()); + guest_observer->set_instance_id(container_instance_id); + RegisterContainerInstance(container_instance_id, guest_observer); + AddGuest(guest_web_contents, frame_id); + } + GURL url(src); + guest_observer->web_contents()->SetDelegate(guest_observer); + guest_observer->web_contents()->GetController().LoadURL( + url, + Referrer(), + PAGE_TRANSITION_AUTO_SUBFRAME, + std::string()); +} + +void BrowserPluginHost::OnNavigateFromGuest( + PP_Instance instance, + const std::string& src) { + DCHECK(embedder_render_process_host()); + GURL url(src); + web_contents()->GetController().LoadURL( + url, + Referrer(), + PAGE_TRANSITION_AUTO_SUBFRAME, + std::string()); +} + +void BrowserPluginHost::ConnectEmbedderToChannel( + RenderViewHost* render_view_host, + const IPC::ChannelHandle& channel_handle) { + DCHECK(embedder_render_process_host()); + // Tell the BrowserPlugin in the embedder that we're done and that it can + // begin using the guest renderer. + embedder_render_process_host()->Send( + new BrowserPluginMsg_LoadGuest( + instance_id(), + render_view_host->GetProcess()-> + GetID(), + channel_handle)); +} + +void BrowserPluginHost::AddGuest(WebContentsImpl* guest, int64 frame_id) { + guests_[guest] = frame_id; +} + +void BrowserPluginHost::RemoveGuest(WebContentsImpl* guest) { + guests_.erase(guest); +} + +void BrowserPluginHost::DestroyGuests() { + for (GuestMap::const_iterator it = guests_.begin(); + it != guests_.end(); ++it) { + WebContentsImpl* web_contents = it->first; + delete web_contents; + } + guests_.clear(); + guests_by_container_id_.clear(); +} + +void BrowserPluginHost::DidCommitProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& url, + PageTransition transition_type, + RenderViewHost* render_view_host) { + // Clean-up guests that lie in the frame that we're navigating. + typedef std::set GuestSet; + GuestSet guests_to_delete; + for (GuestMap::const_iterator it = guests_.begin(); + it != guests_.end(); ++it) { + WebContentsImpl* web_contents = it->first; + if (it->second == frame_id) { + guests_to_delete.insert(web_contents); + } + } + for (GuestSet::const_iterator it = guests_to_delete.begin(); + it != guests_to_delete.end(); ++it) { + delete *it; + guests_.erase(*it); + } +} + +void BrowserPluginHost::RenderViewDeleted(RenderViewHost* render_view_host) { + // TODO(fsamuel): For some reason ToT hangs when killing a guest, this wasn't + // the case earlier. Presumably, when a guest is killed/crashes, one of + // RenderViewDeleted, RenderViewGone or WebContentsDestroyed will get called. + // At that point, we should remove reference to this BrowserPluginHost + // from its embedder, in addition to destroying its guests, to ensure + // that we do not attempt a double delete. + DestroyGuests(); +} + +void BrowserPluginHost::RenderViewGone(base::TerminationStatus status) { + DestroyGuests(); +} + +void BrowserPluginHost::WebContentsDestroyed(WebContents* web_contents) { + DestroyGuests(); +} + +void BrowserPluginHost::Observe( + int type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type) { + case NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { + RenderViewHost* render_view_host = + Details(details).ptr(); + // BrowserPluginHostHelper is destroyed when its associated RenderViewHost + // is destroyed. + new BrowserPluginHostHelper(this, render_view_host); + break; + } + case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { + bool visible = *Details(details).ptr(); + // If the embedder is hidden we need to hide the guests as well. + for (GuestMap::const_iterator it = guests_.begin(); + it != guests_.end(); ++it) { + WebContentsImpl* web_contents = it->first; + if (visible) + web_contents->ShowContents(); + else + web_contents->HideContents(); + } + break; + } + default: + NOTREACHED() << "Unexpected notification type: " << type; + } +} + +} // namespace content diff --git a/content/browser/browser_plugin/old/browser_plugin_host.h b/content/browser/browser_plugin/old/browser_plugin_host.h new file mode 100644 index 0000000..3e86502 --- /dev/null +++ b/content/browser/browser_plugin/old/browser_plugin_host.h @@ -0,0 +1,129 @@ +// 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. + +#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_H__ +#define CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_H__ +#pragma once + +#include + +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_observer.h" +#include "ppapi/c/pp_instance.h" +#include "ui/gfx/size.h" + +class WebContentsImpl; + +namespace content { + +class RenderProcessHost; + +// A BrowserPluginHost object is used by both embedders and guests. +// The primary purpose of BrowserPluginHost is to allow an embedder +// to manage the lifetime of its guests. It cleans up its guests +// on navigation, crashes, and "hides" guests when it hides. +// For the guest, BrowserPluginHost keeps track of its embedder, +// and its BrowserPlugin instance ID. +class BrowserPluginHost : public WebContentsObserver, + public NotificationObserver, + public WebContentsDelegate { + public: + // BrowserPluginHost is owned by a WebContentsImpl. Here it takes in its + // owner. The owner can be either a guest or embedder WebContents. + explicit BrowserPluginHost(WebContentsImpl* web_contents); + + virtual ~BrowserPluginHost(); + + void ConnectEmbedderToChannel(RenderViewHost* render_view_host, + const IPC::ChannelHandle& handle); + + // This is called on the first navigation of the browser plugin. It creates + // a new WebContentsImpl for the guest, associates it with its embedder, sets + // its size and navigates it to the src URL. + void NavigateGuestFromEmbedder(RenderViewHost* render_view_host, + int container_instance_id, + long long frame_id, + const std::string& src); + + RenderProcessHost* embedder_render_process_host() const { + return embedder_render_process_host_; + } + int instance_id() const { return instance_id_; } + + private: + typedef std::map GuestMap; + typedef std::map ContainerInstanceMap; + + // Get a guest BrowserPluginHost by its container ID specified + // in BrowserPlugin. + BrowserPluginHost* GetGuestByContainerID(int container_id); + + // Associate a guest with its container instance ID. + void RegisterContainerInstance( + int container_id, + BrowserPluginHost* observer); + + // An embedder BrowserPluginHost keeps track of + // its guests so that if it navigates away, its associated RenderView + // crashes or it is hidden, it takes appropriate action on the guest. + void AddGuest(WebContentsImpl* guest, int64 frame_id); + + // This removes a guest from an embedder's guest list. + // TODO(fsamuel): Use this when deleting guest after they crash. + // ToT plugin crash handling seems to be broken in this case and so I can't + // test this scenario at the moment. Delete this comment once fixed. + void RemoveGuest(WebContentsImpl* guest); + + void set_embedder_render_process_host( + RenderProcessHost* embedder_render_process_host) { + embedder_render_process_host_ = embedder_render_process_host; + } + void set_instance_id(int instance_id) { instance_id_ = instance_id; } + + void OnNavigateFromGuest(PP_Instance instance, + const std::string& src); + + void DestroyGuests(); + + // WebContentsDelegate implementation. + virtual bool TakeFocus(bool reverse) OVERRIDE; + + // WebContentObserver implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + // Used to monitor frame navigation to cleanup guests when a frame navigates + // away from the browser plugin it's hosting. + virtual void DidCommitProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& url, + PageTransition transition_type, + RenderViewHost* render_view_host) OVERRIDE; + virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; + virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; + virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; + + // NotificationObserver method override. + virtual void Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) OVERRIDE; + + // A scoped container for notification registries. + NotificationRegistrar registrar_; + RenderProcessHost* embedder_render_process_host_; + std::string embedder_channel_name_; + // An identifier that uniquely identifies a browser plugin container + // within an embedder. + int instance_id_; + gfx::Size initial_size_; + GuestMap guests_; + ContainerInstanceMap guests_by_container_id_; + + DISALLOW_COPY_AND_ASSIGN(BrowserPluginHost); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_H_ diff --git a/content/browser/browser_plugin/old/browser_plugin_host_helper.cc b/content/browser/browser_plugin/old/browser_plugin_host_helper.cc new file mode 100644 index 0000000..794aed4 --- /dev/null +++ b/content/browser/browser_plugin/old/browser_plugin_host_helper.cc @@ -0,0 +1,61 @@ +// 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/old/browser_plugin_host_helper.h" + +#include "content/browser/browser_plugin/old/browser_plugin_host.h" +#include "content/common/browser_plugin_messages.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/render_widget_host_view.h" +#include "ui/gfx/size.h" + +namespace content { + +BrowserPluginHostHelper::BrowserPluginHostHelper( + BrowserPluginHost* browser_plugin_host, + RenderViewHost* render_view_host) + : RenderViewHostObserver(render_view_host), + browser_plugin_host_(browser_plugin_host) { +} + +BrowserPluginHostHelper::~BrowserPluginHostHelper() { +} + + +bool BrowserPluginHostHelper::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(BrowserPluginHostHelper, message) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ConnectToChannel, + OnConnectToChannel) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromEmbedder, + OnNavigateGuestFromEmbedder) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void BrowserPluginHostHelper::OnConnectToChannel( + const IPC::ChannelHandle& channel_handle) { + browser_plugin_host_->ConnectEmbedderToChannel( + render_view_host(), + channel_handle); +} + +void BrowserPluginHostHelper::OnNavigateGuestFromEmbedder( + int32 instance_id, + long long frame_id, + const std::string& src) { + browser_plugin_host_->NavigateGuestFromEmbedder( + render_view_host(), + instance_id, + frame_id, + src); +} + +void BrowserPluginHostHelper::OnResizeGuest(int width, int height) { + render_view_host()->GetView()->SetSize(gfx::Size(width, height)); +} + +} // namespace content diff --git a/content/browser/browser_plugin/old/browser_plugin_host_helper.h b/content/browser/browser_plugin/old/browser_plugin_host_helper.h new file mode 100644 index 0000000..05b8259 --- /dev/null +++ b/content/browser/browser_plugin/old/browser_plugin_host_helper.h @@ -0,0 +1,50 @@ +// 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. + +#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_HELPER_H__ +#define CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_HELPER_H__ +#pragma once + +#include + +#include "content/public/browser/render_view_host_observer.h" + +namespace gfx { +class Size; +} + +namespace content { + +class BrowserPluginHost; + +// This class acts as a plumber helper for BrowserPluginHost. A lot +// of messages coming from guests need to know the guest's RenderViewHost. +// BrowserPluginHostHelper handles BrowserPluginHost messages and relays +// them with their associated RenderViewHosts to BrowserPluginHost where they +// will be handled. +class BrowserPluginHostHelper : public RenderViewHostObserver { + public: + BrowserPluginHostHelper(BrowserPluginHost* browser_plugin_host, + RenderViewHost* render_view_host); + virtual ~BrowserPluginHostHelper(); + + private: + void OnConnectToChannel(const IPC::ChannelHandle& channel_handle); + void OnNavigateGuestFromEmbedder(int container_instance_id, + long long frame_id, + const std::string& src); + void OnResizeGuest(int width, int height); + + // RenderViewHostObserver implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + BrowserPluginHost* browser_plugin_host_; + + DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostHelper); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_HELPER_H__ + diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index c077141..f00fd5d 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -14,7 +14,7 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "content/browser/browser_plugin/browser_plugin_host.h" +#include "content/browser/browser_plugin/old/browser_plugin_host.h" #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/dom_storage/session_storage_namespace_impl.h" diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 7a9c198..cc18b58 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -14,7 +14,7 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/property_bag.h" -#include "content/browser/browser_plugin/browser_plugin_host.h" +#include "content/browser/browser_plugin/old/browser_plugin_host.h" #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/renderer_host/render_widget_host_delegate.h" diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 168a9ad..82e28070 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -221,10 +221,10 @@ 'browser/browser_main_loop.cc', 'browser/browser_main_loop.h', 'browser/browser_main_runner.cc', - 'browser/browser_plugin/browser_plugin_host.cc', - 'browser/browser_plugin/browser_plugin_host.h', - 'browser/browser_plugin/browser_plugin_host_helper.cc', - 'browser/browser_plugin/browser_plugin_host_helper.h', + 'browser/browser_plugin/old/browser_plugin_host.cc', + 'browser/browser_plugin/old/browser_plugin_host.h', + 'browser/browser_plugin/old/browser_plugin_host_helper.cc', + 'browser/browser_plugin/old/browser_plugin_host_helper.h', 'browser/browser_process_sub_thread.cc', 'browser/browser_process_sub_thread.h', 'browser/browser_thread_impl.cc', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 8f26bf3..0b37609 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -162,18 +162,18 @@ 'renderer/pepper/pepper_proxy_channel_delegate_impl.h', 'renderer/plugin_channel_host.cc', 'renderer/plugin_channel_host.h', - 'renderer/browser_plugin/browser_plugin.cc', - 'renderer/browser_plugin/browser_plugin.h', - 'renderer/browser_plugin/browser_plugin_channel_manager.cc', - 'renderer/browser_plugin/browser_plugin_channel_manager.h', - 'renderer/browser_plugin/browser_plugin_constants.cc', - 'renderer/browser_plugin/browser_plugin_constants.h', - 'renderer/browser_plugin/browser_plugin_registry.cc', - 'renderer/browser_plugin/browser_plugin_registry.h', - 'renderer/browser_plugin/browser_plugin_var_serialization_rules.cc', - 'renderer/browser_plugin/browser_plugin_var_serialization_rules.h', - 'renderer/browser_plugin/guest_to_embedder_channel.cc', - 'renderer/browser_plugin/guest_to_embedder_channel.h', + 'renderer/browser_plugin/old/browser_plugin.cc', + 'renderer/browser_plugin/old/browser_plugin.h', + 'renderer/browser_plugin/old/browser_plugin_channel_manager.cc', + 'renderer/browser_plugin/old/browser_plugin_channel_manager.h', + 'renderer/browser_plugin/old/browser_plugin_constants.cc', + 'renderer/browser_plugin/old/browser_plugin_constants.h', + 'renderer/browser_plugin/old/browser_plugin_registry.cc', + 'renderer/browser_plugin/old/browser_plugin_registry.h', + 'renderer/browser_plugin/old/browser_plugin_var_serialization_rules.cc', + 'renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h', + 'renderer/browser_plugin/old/guest_to_embedder_channel.cc', + 'renderer/browser_plugin/old/guest_to_embedder_channel.h', 'renderer/render_process.h', 'renderer/render_process_impl.cc', 'renderer/render_process_impl.h', diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc deleted file mode 100644 index 8be36e8..0000000 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ /dev/null @@ -1,157 +0,0 @@ -// 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/browser_plugin/browser_plugin.h" - -#include "base/atomic_sequence_num.h" -#include "base/id_map.h" -#include "base/lazy_instance.h" -#include "base/process.h" -#include "base/string_number_conversions.h" -#include "base/string_piece.h" -#include "base/string_util.h" -#include "base/values.h" -#include "content/common/browser_plugin_messages.h" -#include "content/public/common/url_constants.h" -#include "content/renderer/render_view_impl.h" -#include "ipc/ipc_channel_handle.h" -#include "ppapi/proxy/host_dispatcher.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" -#include "webkit/plugins/webview_plugin.h" - -static int g_next_id = 0; - -// The global list of all Browser Plugin Placeholders within a process. -base::LazyInstance >::Leaky - g_all_browser_plugins = LAZY_INSTANCE_INITIALIZER; - -using WebKit::WebPlugin; -using WebKit::WebPluginContainer; -using webkit::WebViewPlugin; - -void Register(int id, BrowserPlugin* browser_plugin) { - g_all_browser_plugins.Get().AddWithID(browser_plugin, id); -} - -void Unregister(int id) { - if (g_all_browser_plugins.Get().Lookup(id)) - g_all_browser_plugins.Get().Remove(id); -} - -// static -WebKit::WebPlugin* BrowserPlugin::Create( - RenderViewImpl* render_view, - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params) { - // TODO(fsamuel): Figure out what the lifetime is of this class. - // It seems we need to blow away this object once a WebPluginContainer is - // gone. How do we detect it's gone? A WebKit change perhaps? - BrowserPlugin* browser_plugin = new BrowserPlugin( - render_view, frame, params, ""); - return browser_plugin->placeholder(); -} - -// static -BrowserPlugin* BrowserPlugin::FromID(int id) { - return g_all_browser_plugins.Get().Lookup(id); -} - -BrowserPlugin::BrowserPlugin( - RenderViewImpl* render_view, - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params, - const std::string& html_data) - : render_view_(render_view), - plugin_params_(params), - placeholder_(webkit::WebViewPlugin::Create( - NULL, - render_view->GetWebkitPreferences(), - html_data, - GURL(chrome::kAboutBlankURL))), - plugin_(NULL) { - id_ = ++g_next_id; - Register(id_, this); - - // By default we do not navigate and simply stay with an - // about:blank placeholder. - std::string src; - ParseSrcAttribute("", &src); - - if (!src.empty()) { - render_view->Send(new BrowserPluginHostMsg_NavigateFromEmbedder( - render_view->GetRoutingID(), - id_, - frame->identifier(), - src)); - } -} - -BrowserPlugin::~BrowserPlugin() { - Unregister(id_); -} - -void BrowserPlugin::ParseSrcAttribute( - const std::string& default_src, - std::string* src) { - // Get the src attribute from the attributes vector - for (unsigned i = 0; i < plugin_params_.attributeNames.size(); ++i) { - std::string attributeName = plugin_params_.attributeNames[i].utf8(); - if (LowerCaseEqualsASCII(attributeName, "src")) { - *src = plugin_params_.attributeValues[i].utf8(); - break; - } - } - // If we didn't find the attributes set or they're not sensible, - // we reset our attributes to the default. - if (src->empty()) { - *src = default_src; - } -} - -void BrowserPlugin::LoadGuest( - int guest_process_id, - const IPC::ChannelHandle& channel_handle) { - webkit::ppapi::WebPluginImpl* new_guest = - render_view()->CreateBrowserPlugin(channel_handle, - guest_process_id, - plugin_params()); - Replace(new_guest); -} - -void BrowserPlugin::AdvanceFocus(bool reverse) { - // TODO(fsamuel): Uncomment this once http://wkbug.com/88827 lands. - // render_view()->GetWebView()->advanceFocus(reverse); -} - -void BrowserPlugin::Replace( - webkit::ppapi::WebPluginImpl* new_plugin) { - WebKit::WebPlugin* current_plugin = - plugin_ ? static_cast(plugin_) : placeholder_; - WebKit::WebPluginContainer* container = current_plugin->container(); - if (!new_plugin || !new_plugin->initialize(container)) - return; - - // Clear the container's backing texture ID. - if (plugin_) - plugin_->instance()->BindGraphics(plugin_->instance()->pp_instance(), 0); - - PP_Instance instance = new_plugin->instance()->pp_instance(); - ppapi::proxy::HostDispatcher* dispatcher = - ppapi::proxy::HostDispatcher::GetForInstance(instance); - dispatcher->Send(new BrowserPluginMsg_GuestReady(instance, id_)); - - // TODO(fsamuel): We should delay the swapping out of the current plugin - // until after the guest's WebGraphicsContext3D has been initialized. That - // way, we immediately have something to render onto the screen. - container->setPlugin(new_plugin); - container->invalidate(); - container->reportGeometry(); - if (plugin_) - plugin_->destroy(); - plugin_ = new_plugin; -} diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h deleted file mode 100644 index b1b2112..0000000 --- a/content/renderer/browser_plugin/browser_plugin.h +++ /dev/null @@ -1,90 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ -#pragma once - -#include "base/process.h" -#include "content/renderer/render_view_impl.h" -#include "ipc/ipc_channel_handle.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" -#include "ui/gfx/size.h" -#include "webkit/plugins/webview_plugin.h" - -namespace content { -class RenderView; -} - -namespace WebKit { -class WebPlugin; -} - -// A browser plugin is a plugin container that hosts an out-of-process "guest" -// RenderView. Loading up a new process, creating a new RenderView, navigating -// to a given URL, and establishing a guest-to-embedder channel can take -// hundreds of milliseconds. Furthermore, a RenderView's associated browser-side -// WebContents, RenderViewHost, and SiteInstance must be created and accessed on -// the UI thread of the browser process. -// -// To avoid blocking the embedder RenderView and to avoid introducing the -// potential for deadlock, BrowserPlugin attaches a placeholder that takes -// place of the guest RenderView until the guest has established a connection -// with its embedder RenderView. This permits asynchronously loading of the -// guest while the embedder RenderView is permitted to continue to receive and -// process events. -// -// Furthermore, certain navigations can swap to a new guest RenderView on an -// different process. BrowserPlugin is the consistent facade that the embedder's -// WebKit instance talks to regardless of which process it's communicating with. -class BrowserPlugin { - public: - // Creates a new WebViewPlugin with a BrowserPlugin as a delegate. - static WebKit::WebPlugin* Create( - RenderViewImpl* render_view, - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params); - - static BrowserPlugin* FromID(int id); - - webkit::WebViewPlugin* placeholder() { return placeholder_; } - - webkit::ppapi::WebPluginImpl* plugin() { return plugin_; } - - const WebKit::WebPluginParams& plugin_params() const { - return plugin_params_; - } - - void LoadGuest(int guest_process_id, - const IPC::ChannelHandle& channel_handle); - - void AdvanceFocus(bool reverse); - - RenderViewImpl* render_view() { return render_view_; } - - private: - BrowserPlugin(RenderViewImpl* render_view, - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params, - const std::string& html_data); - virtual ~BrowserPlugin(); - - // Parses the source URL of the browser plugin from the element's attributes - // and outputs them. If not found, it outputs the defaults specified here as - // parameters. - void ParseSrcAttribute(const std::string& default_src, std::string* src); - // Replace the current guest with a new guest. - void Replace(webkit::ppapi::WebPluginImpl* new_plugin); - - RenderViewImpl* render_view_; - WebKit::WebPluginParams plugin_params_; - webkit::WebViewPlugin* placeholder_; - webkit::ppapi::WebPluginImpl* plugin_; - int id_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); -}; - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ diff --git a/content/renderer/browser_plugin/browser_plugin_channel_manager.cc b/content/renderer/browser_plugin/browser_plugin_channel_manager.cc deleted file mode 100644 index 0a49e9d..0000000 --- a/content/renderer/browser_plugin/browser_plugin_channel_manager.cc +++ /dev/null @@ -1,144 +0,0 @@ -// 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/browser_plugin/browser_plugin_channel_manager.h" - -#include "base/process_util.h" -#include "content/common/browser_plugin_messages.h" -#include "content/common/view_messages.h" -#include "content/renderer/browser_plugin/browser_plugin.h" -#include "content/renderer/browser_plugin/guest_to_embedder_channel.h" -#include "content/renderer/render_thread_impl.h" -#include "content/renderer/render_view_impl.h" -#include "ppapi/c/pp_instance.h" - -namespace content { - -BrowserPluginChannelManager::BrowserPluginChannelManager() { -} - -BrowserPluginChannelManager::~BrowserPluginChannelManager() { -} - -void BrowserPluginChannelManager::CreateRenderView( - const ViewMsg_New_Params& params) { - IPC::ChannelHandle embedder_channel_handle; - embedder_channel_handle.name = - IPC::Channel::GenerateVerifiedChannelID(params.embedder_channel_name); - bool success = true; - scoped_refptr channel = - GetChannelByName(params.embedder_channel_name); - if (!channel) { - channel = new GuestToEmbedderChannel(params.embedder_channel_name, - embedder_channel_handle.name); - success = channel->InitChannel(embedder_channel_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. - embedder_channel_handle.socket = - base::FileDescriptor(channel->TakeRendererFD(), true); - if (embedder_channel_handle.socket.fd == -1) - success = false; -#endif - DCHECK(success); - embedder_channels_[params.embedder_channel_name] = channel; - } - RenderViewImpl* render_view = - RenderViewImpl::Create( - params.parent_window, - params.opener_route_id, - params.renderer_preferences, - params.web_preferences, - new SharedRenderViewCounter(0), - params.view_id, - params.surface_id, - params.session_storage_namespace_id, - params.frame_name, - false, - params.swapped_out, - params.next_page_id, - params.screen_info, - channel, - params.accessibility_mode); - ReportChannelToEmbedder(render_view, - embedder_channel_handle, - params.embedder_channel_name, - params.embedder_container_id); -} - -void BrowserPluginChannelManager::ReportChannelToEmbedder( - RenderViewImpl* render_view, - const IPC::ChannelHandle& embedder_channel_handle, - const std::string& embedder_channel_name, - int embedder_container_id) { - std::pair pending_guests_key = - std::make_pair(embedder_channel_name, embedder_container_id); - DCHECK(pending_guests_.find(pending_guests_key) == - pending_guests_.end()); - pending_guests_[pending_guests_key] = render_view->AsWeakPtr(); - RenderThreadImpl::current()->Send( - new BrowserPluginHostMsg_ConnectToChannel(render_view->GetRoutingID(), - embedder_channel_handle)); -} - -bool BrowserPluginChannelManager::OnControlMessageReceived( - const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(BrowserPluginChannelManager, message) - IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadGuest, OnLoadGuest) - IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - - return handled; -} - -GuestToEmbedderChannel* BrowserPluginChannelManager::GetChannelByName( - const std::string& embedder_channel_name) { - EmbedderChannelNameToChannelMap::iterator it = - embedder_channels_.find(embedder_channel_name); - if (it != embedder_channels_.end()) - return it->second; - return NULL; -} - -void BrowserPluginChannelManager::RemoveChannelByName( - const std::string& embedder_channel_name) { - embedder_channels_.erase(embedder_channel_name); -} - -void BrowserPluginChannelManager::GuestReady( - PP_Instance instance, - const std::string& embedder_channel_name, - int embedder_container_id) { - std::pair pending_guests_key = - make_pair(embedder_channel_name, embedder_container_id); - DCHECK(pending_guests_.find(pending_guests_key) != - pending_guests_.end()); - RenderViewImpl* render_view = pending_guests_[pending_guests_key]; - pending_guests_.erase(pending_guests_key); - GuestToEmbedderChannel* channel = render_view->GetGuestToEmbedderChannel(); - // Associate the RenderView with the provided PP_Instance ID, request the - // receipt of events, and initialize the graphics context. - channel->AddGuest(instance, render_view); - render_view->GuestReady(instance); -} - -void BrowserPluginChannelManager::OnLoadGuest( - int instance_id, - int guest_process_id, - const IPC::ChannelHandle& channel_handle) { - BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); - browser_plugin->LoadGuest(guest_process_id, channel_handle); -} - -void BrowserPluginChannelManager::OnAdvanceFocus(int instance_id, - bool reverse) { - BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); - browser_plugin->AdvanceFocus(reverse); -} - -} // namespace content diff --git a/content/renderer/browser_plugin/browser_plugin_channel_manager.h b/content/renderer/browser_plugin/browser_plugin_channel_manager.h deleted file mode 100644 index cbe578d..0000000 --- a/content/renderer/browser_plugin/browser_plugin_channel_manager.h +++ /dev/null @@ -1,82 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ -#pragma once - -#include - -#include "base/id_map.h" -#include "content/public/renderer/render_process_observer.h" -#include "content/renderer/browser_plugin/guest_to_embedder_channel.h" -#include "content/renderer/render_view_impl.h" - -class GuestToEmbedderChannel; -struct ViewMsg_New_Params; - -namespace content { - -// BrowserPluginChannelManager manages the lifetime of GuestToEmbedderChannels. -// When a new RenderView is requested, it checks the embedder channel name -// in ViewMsg_New_Params and decides whether to reuse an existing channel or -// create a new channel. On the guest renderer process, it informs a -// RenderView once a channel has been established with its embedder. -// On the embedder side, it tells BrowserPlugin to load the guest -// PluginInstance once a channel has been established. -class BrowserPluginChannelManager - : public RenderProcessObserver { - public: - BrowserPluginChannelManager(); - - virtual ~BrowserPluginChannelManager(); - - void CreateRenderView(const ViewMsg_New_Params& params); - - void ReportChannelToEmbedder( - RenderViewImpl* render_view, - const IPC::ChannelHandle& embedder_channel_handle, - const std::string& embedder_channel_name, - int embedder_container_id); - - // Get the GuestToEmbedderChannel associated with the given - // embedder_channel_name. - GuestToEmbedderChannel* GetChannelByName( - const std::string& embedder_channel_name); - - // Remove the pointer to the GuestToEmbedderChannel associated with the given - // routing_id. - void RemoveChannelByName(const std::string& embedder_channel_name); - - void GuestReady(PP_Instance instance, - const std::string& embedder_channel_name, - int embedder_container_id); - - private: - typedef std::map > - EmbedderChannelNameToChannelMap; - - void OnLoadGuest(int instance_id, - int guest_renderer_id, - const IPC::ChannelHandle& channel_handle); - void OnAdvanceFocus(int instance_id, bool reverse); - - // RenderProcessObserver override. Call on render thread. - virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; - - // Map from Host process ID to GuestToEmbedderChannel - EmbedderChannelNameToChannelMap embedder_channels_; - - // Map from to RenderViewImpl - // that points to RenderViewImpl guests that have been constructed but don't - // have a PP_Instance and so they aren't yet ready to composite. - std::map, - base::WeakPtr > pending_guests_; - - DISALLOW_COPY_AND_ASSIGN(BrowserPluginChannelManager); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ diff --git a/content/renderer/browser_plugin/browser_plugin_constants.cc b/content/renderer/browser_plugin/browser_plugin_constants.cc deleted file mode 100644 index b1543ac..0000000 --- a/content/renderer/browser_plugin/browser_plugin_constants.cc +++ /dev/null @@ -1,10 +0,0 @@ -// 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/browser_plugin/browser_plugin_constants.h" - -const char kBrowserPluginName[] = "Browser Plugin"; -const FilePath::CharType kBrowserPluginPath[] = - FILE_PATH_LITERAL("internal/browser-plugin"); -const char kBrowserPluginDescription[] = "Out-of-Process Browser Plugin"; diff --git a/content/renderer/browser_plugin/browser_plugin_constants.h b/content/renderer/browser_plugin/browser_plugin_constants.h deleted file mode 100644 index fe70e0b..0000000 --- a/content/renderer/browser_plugin/browser_plugin_constants.h +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CONSTANTS_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CONSTANTS_H_ -#pragma once - -#include "base/file_path.h" - -extern const char kBrowserPluginName[]; -extern const FilePath::CharType kBrowserPluginPath[]; -extern const char kBrowserPluginDescription[]; - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CONSTANTS_H_ diff --git a/content/renderer/browser_plugin/browser_plugin_registry.cc b/content/renderer/browser_plugin/browser_plugin_registry.cc deleted file mode 100644 index 14725e7..0000000 --- a/content/renderer/browser_plugin/browser_plugin_registry.cc +++ /dev/null @@ -1,45 +0,0 @@ -// 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/browser_plugin/browser_plugin_registry.h" - -#include "base/logging.h" - -namespace content { - -BrowserPluginRegistry::BrowserPluginRegistry() { -} - -BrowserPluginRegistry::~BrowserPluginRegistry() { -} - -webkit::ppapi::PluginModule* BrowserPluginRegistry::GetModule( - int guest_process_id) { - return modules_.Lookup(guest_process_id); -} - -void BrowserPluginRegistry::AddModule(int guest_process_id, - webkit::ppapi::PluginModule* module) { - modules_.AddWithID(module, guest_process_id); -} - -void BrowserPluginRegistry::PluginModuleDead( - webkit::ppapi::PluginModule* dead_module) { - // DANGER: Don't dereference the dead_module pointer! It may be in the - // process of being deleted. - - // Modules aren't destroyed very often and there are normally at most a - // couple of them. So for now we just do a brute-force search. - IDMap::iterator iter(&modules_); - while (!iter.IsAtEnd()) { - if (iter.GetCurrentValue() == dead_module) { - modules_.Remove(iter.GetCurrentKey()); - return; - } - iter.Advance(); - } - NOTREACHED(); // Should have always found the module above. -} - -} // namespace content diff --git a/content/renderer/browser_plugin/browser_plugin_registry.h b/content/renderer/browser_plugin/browser_plugin_registry.h deleted file mode 100644 index 7740015..0000000 --- a/content/renderer/browser_plugin/browser_plugin_registry.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_REGISTRY_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_REGISTRY_H_ -#pragma once - -#include "base/id_map.h" -#include "base/process.h" -#include "webkit/plugins/ppapi/plugin_delegate.h" - -namespace content { - -// This class holds references to all of the known live browser plugin -// modules. There is one browser plugin module per guest renderer process. -class BrowserPluginRegistry - : public webkit::ppapi::PluginDelegate::ModuleLifetime { - public: - BrowserPluginRegistry(); - virtual ~BrowserPluginRegistry(); - - webkit::ppapi::PluginModule* GetModule(int guest_process_id); - void AddModule(int guest_process_id, - webkit::ppapi::PluginModule* module); - - // ModuleLifetime implementation. - virtual void PluginModuleDead( - webkit::ppapi::PluginModule* dead_module) OVERRIDE; - - private: - IDMap modules_; -}; - -} // namespace content - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_REGISTRY_H_ diff --git a/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.cc b/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.cc deleted file mode 100644 index 874527c..0000000 --- a/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.cc +++ /dev/null @@ -1,51 +0,0 @@ -// 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/browser_plugin/browser_plugin_var_serialization_rules.h" - -#include "base/logging.h" - -namespace content { - -BrowserPluginVarSerializationRules::BrowserPluginVarSerializationRules() { -} - -BrowserPluginVarSerializationRules::~BrowserPluginVarSerializationRules() { -} - -PP_Var BrowserPluginVarSerializationRules::SendCallerOwned(const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); - return var; -} - -PP_Var BrowserPluginVarSerializationRules::BeginReceiveCallerOwned( - const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); - return var; -} - -void BrowserPluginVarSerializationRules::EndReceiveCallerOwned( - const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); -} - -PP_Var BrowserPluginVarSerializationRules::ReceivePassRef(const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); - return var; -} - -PP_Var BrowserPluginVarSerializationRules::BeginSendPassRef(const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); - return var; -} - -void BrowserPluginVarSerializationRules::EndSendPassRef(const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); -} - -void BrowserPluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { - DCHECK(var.type != PP_VARTYPE_OBJECT); -} - -} // namespace content diff --git a/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.h b/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.h deleted file mode 100644 index f169912..0000000 --- a/content/renderer/browser_plugin/browser_plugin_var_serialization_rules.h +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ - -#include "ppapi/proxy/var_serialization_rules.h" - -namespace content { - -// Implementation of the VarSerializationRules interface for the browser plugin. -class BrowserPluginVarSerializationRules : - public ppapi::proxy::VarSerializationRules { - public: - explicit BrowserPluginVarSerializationRules(); - - // VarSerialization implementation. - virtual PP_Var SendCallerOwned(const PP_Var& var) OVERRIDE; - virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var) OVERRIDE; - virtual void EndReceiveCallerOwned(const PP_Var& var) OVERRIDE; - virtual PP_Var ReceivePassRef(const PP_Var& var) OVERRIDE; - virtual PP_Var BeginSendPassRef(const PP_Var& var) OVERRIDE; - virtual void EndSendPassRef(const PP_Var& var) OVERRIDE; - virtual void ReleaseObjectRef(const PP_Var& var) OVERRIDE; - - private: - virtual ~BrowserPluginVarSerializationRules(); - - DISALLOW_COPY_AND_ASSIGN(BrowserPluginVarSerializationRules); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ diff --git a/content/renderer/browser_plugin/guest_to_embedder_channel.cc b/content/renderer/browser_plugin/guest_to_embedder_channel.cc deleted file mode 100644 index 4edd0a4..0000000 --- a/content/renderer/browser_plugin/guest_to_embedder_channel.cc +++ /dev/null @@ -1,306 +0,0 @@ -// 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/browser_plugin/guest_to_embedder_channel.h" - -#include "base/process_util.h" -#include "content/common/browser_plugin_messages.h" -#include "content/common/child_process.h" -#include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" -#include "content/renderer/browser_plugin/browser_plugin_var_serialization_rules.h" -#include "content/renderer/render_thread_impl.h" -#include "content/renderer/render_view_impl.h" -#include "ppapi/c/pp_bool.h" -#include "ppapi/c/pp_graphics_3d.h" -#include "ppapi/proxy/ppapi_command_buffer_proxy.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/api_id.h" -#include "ppapi/shared_impl/ppapi_globals.h" -#include "ppapi/shared_impl/var.h" -#include "webkit/plugins/ppapi/event_conversion.h" - -namespace content { - -GuestToEmbedderChannel::GuestToEmbedderChannel( - const std::string& embedder_channel_name, - const IPC::ChannelHandle& embedder_channel_handle) - : Dispatcher(NULL), - embedder_channel_name_(embedder_channel_name), - embedder_channel_handle_(embedder_channel_handle) { - SetSerializationRules(new BrowserPluginVarSerializationRules()); -} - -GuestToEmbedderChannel::~GuestToEmbedderChannel() { -} - -bool GuestToEmbedderChannel::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(GuestToEmbedderChannel, message) - IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnSupportsInterface) - IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnSetPreferences) - IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnReserveInstanceId) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, - OnDidCreate) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, - OnDidDestroy) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, - OnDidChangeView) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, - OnDidChangeFocus) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, - OnHandleMessage) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent, - OnHandleFilteredInputEvent) - IPC_MESSAGE_HANDLER(PpapiMsg_PPPGraphics3D_ContextLost, - OnContextLost) - IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestReady, - OnGuestReady) - // Have the super handle all other messages. - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - - return handled; -} - -bool GuestToEmbedderChannel::Send(IPC::Message* message) { - // We always want guest->host messages to arrive in-order. If some sync - // and some async messages are sent in response to a synchronous - // host->guest call, the sync reply will be processed before the async - // reply, and everything will be confused. - // - // Allowing all async messages to unblock the renderer means more reentrancy - // there but gives correct ordering. - message->set_unblock(true); - return ProxyChannel::Send(message); -} - -void GuestToEmbedderChannel::OnChannelError() { - // We cannot destroy the GuestToEmbedderChannel here because a - // PpapiCommandBufferProxy may still refer to this object. - // However, we should not be using this channel again once we get a - // channel error so we remove it from the channel manager. - RenderThreadImpl::current()->browser_plugin_channel_manager()-> - RemoveChannelByName(embedder_channel_name_); -} - -bool GuestToEmbedderChannel::IsPlugin() const { - return true; -} - -WebGraphicsContext3DCommandBufferImpl* - GuestToEmbedderChannel::CreateWebGraphicsContext3D( - RenderViewImpl* render_view, - const WebKit::WebGraphicsContext3D::Attributes& attributes, - bool offscreen) { - scoped_ptr context( - new WebGraphicsContext3DCommandBufferImpl( - 0, GURL(), NULL, - render_view->AsWeakPtr())); - - // Special case: RenderView initialization has not yet completed. - if (!render_view->guest_pp_instance()) - return context.release(); - - if (CreateGraphicsContext(context.get(), - attributes, - offscreen, - render_view)) - return context.release(); - - return NULL; -} - -void GuestToEmbedderChannel::IssueSwapBuffers( - const ppapi::HostResource& resource) { - Send(new PpapiHostMsg_PPBGraphics3D_SwapBuffers( - ppapi::API_ID_PPB_GRAPHICS_3D, resource)); -} - -bool GuestToEmbedderChannel::InitChannel( - const IPC::ChannelHandle& channel_handle) { - return ProxyChannel::InitWithChannel(&delegate_, channel_handle, false); -} - -void GuestToEmbedderChannel::OnSupportsInterface( - const std::string& interface_name, - bool* result) { - // TODO(fsamuel): This is a hack to avoid getting GetInstanceObject messages - // and failing a CHECK. A more correct solution is to implement - // VarSerializationRules for GuestToEmbedderChannel. - *result = interface_name.find("PPP_Instance_Private") == std::string::npos; -} - -void GuestToEmbedderChannel::OnSetPreferences(const ppapi::Preferences& prefs) { - // TODO(fsamuel): Do we care about these preferences? - // These look like some font stuff from WebPreferences. - // Perhaps this should be plumbed into our associated RenderView? - NOTIMPLEMENTED(); -} - -void GuestToEmbedderChannel::OnReserveInstanceId(PP_Instance instance, - bool* usable) { - *usable = - render_view_instances_.find(instance) == render_view_instances_.end(); -} - -void GuestToEmbedderChannel::RequestInputEvents(PP_Instance instance) { - // Request receipt of input events - Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( - ppapi::API_ID_PPB_INSTANCE, instance, true, - PP_INPUTEVENT_CLASS_MOUSE | - PP_INPUTEVENT_CLASS_KEYBOARD | - PP_INPUTEVENT_CLASS_WHEEL | - PP_INPUTEVENT_CLASS_TOUCH)); -} - -bool GuestToEmbedderChannel::CreateGraphicsContext( - WebGraphicsContext3DCommandBufferImpl* context, - const WebKit::WebGraphicsContext3D::Attributes& attributes, - bool offscreen, - RenderViewImpl* render_view) { - std::vector attribs; - attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); - - ppapi::HostResource resource; - DCHECK(render_view->guest_pp_instance()); - // TODO(fsamuel): Support shared contexts. - bool success = Send(new PpapiHostMsg_PPBGraphics3D_Create( - ppapi::API_ID_PPB_GRAPHICS_3D, - render_view->guest_pp_instance(), - ppapi::HostResource(), - attribs, - &resource)); - if (!success || resource.is_null()) - return false; - if (!offscreen) { - PP_Bool result = PP_FALSE; - Send(new PpapiHostMsg_PPBInstance_BindGraphics( - ppapi::API_ID_PPB_INSTANCE, - render_view->guest_pp_instance(), - resource, - &result)); - if (result != PP_TRUE) - return false; - } - - CommandBufferProxy* command_buffer = - new ppapi::proxy::PpapiCommandBufferProxy(resource, this); - command_buffer->Initialize(); - context->InitializeWithCommandBuffer( - command_buffer, - attributes, - false /* bind generates resources */); - render_view->set_guest_graphics_resource(resource); - return true; -} - -void GuestToEmbedderChannel::AddGuest( - PP_Instance instance, - RenderViewImpl* render_view) { - DCHECK(instance); - DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); - render_view_instances_[instance] = render_view->AsWeakPtr(); -} - - -void GuestToEmbedderChannel::RemoveGuest(PP_Instance instance) { - DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); - render_view_instances_.erase(instance); -} - -void GuestToEmbedderChannel::OnDidCreate( - PP_Instance instance, - const std::vector& argn, - const std::vector& argv, - PP_Bool* result) { - DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); - RequestInputEvents(instance); - *result = PP_TRUE; -} - -void GuestToEmbedderChannel::OnDidDestroy(PP_Instance instance) { - InstanceMap::iterator it = render_view_instances_.find(instance); - DCHECK(it != render_view_instances_.end()); - RenderViewImpl* render_view = it->second; - render_view->SetGuestToEmbedderChannel(NULL); - render_view->set_guest_pp_instance(0); - RemoveGuest(instance); -} - -void GuestToEmbedderChannel::OnDidChangeView( - PP_Instance instance, - const ppapi::ViewData& new_data, - PP_Bool flash_fullscreen) { - // We can't do anything with this message if we don't have a render view - // yet. If we do have a RenderView then we need to tell the associated - // WebContentsObserver to resize. - if (render_view_instances_.find(instance) != render_view_instances_.end()) { - RenderViewImpl* render_view = render_view_instances_[instance]; - render_view->Send( - new BrowserPluginHostMsg_ResizeGuest( - render_view->GetRoutingID(), - new_data.rect.size.width, - new_data.rect.size.height)); - } -} - -void GuestToEmbedderChannel::OnDidChangeFocus(PP_Instance instance, - PP_Bool has_focus) { - InstanceMap::iterator it = render_view_instances_.find(instance); - if (it == render_view_instances_.end()) - return; - RenderViewImpl* render_view = it->second; - render_view->GetWebView()->setFocus(PP_ToBool(has_focus)); -} - -void GuestToEmbedderChannel::OnHandleMessage( - PP_Instance instance, - ppapi::proxy::SerializedVarReceiveInput message_data) { - InstanceMap::iterator it = render_view_instances_.find(instance); - if (it == render_view_instances_.end()) - return; - - PP_Var received_var(message_data.Get(this)); - DCHECK(received_var.type == PP_VARTYPE_STRING); - ppapi::VarTracker* tracker = ppapi::PpapiGlobals::Get()->GetVarTracker(); - ppapi::StringVar* var = tracker->GetVar(received_var)->AsStringVar(); - DCHECK(var); - - RenderViewImpl* render_view = it->second; - render_view->Send( - new BrowserPluginHostMsg_NavigateFromGuest( - render_view->GetRoutingID(), - instance, - var->value())); -} - -void GuestToEmbedderChannel::OnHandleFilteredInputEvent( - PP_Instance instance, - const ppapi::InputEventData& data, - PP_Bool* result) { - if (render_view_instances_.find(instance) == render_view_instances_.end()) - return; - - RenderViewImpl* render_view = render_view_instances_[instance]; - scoped_ptr web_input_event( - webkit::ppapi::CreateWebInputEvent(data)); - *result = PP_FromBool( - render_view->GetWebView()->handleInputEvent(*web_input_event)); -} - -void GuestToEmbedderChannel::OnContextLost(PP_Instance instance) { - DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); - RenderViewImpl* render_view = render_view_instances_[instance]; - // TODO(fsamuel): This is test code. Need to find a better way to tell - // a WebView to drop its context. - render_view->GetWebView()->loseCompositorContext(1); -} - -void GuestToEmbedderChannel::OnGuestReady(PP_Instance instance, - int embedder_container_id) { - RenderThreadImpl::current()->browser_plugin_channel_manager()-> - GuestReady(instance, embedder_channel_name(), embedder_container_id); -} - -} // namespace content diff --git a/content/renderer/browser_plugin/guest_to_embedder_channel.h b/content/renderer/browser_plugin/guest_to_embedder_channel.h deleted file mode 100644 index 1eb83ce..0000000 --- a/content/renderer/browser_plugin/guest_to_embedder_channel.h +++ /dev/null @@ -1,138 +0,0 @@ -// 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. - -#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ -#define CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ -#pragma once - -#include "base/memory/ref_counted.h" -#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" -#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" -#include "content/renderer/render_view_impl.h" -#include "ipc/ipc_channel_handle.h" -#include "ppapi/c/pp_bool.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/shared_impl/ppb_view_shared.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/serialized_var.h" -#include "ppapi/shared_impl/host_resource.h" -#include "ppapi/shared_impl/ppapi_preferences.h" -#include "ppapi/shared_impl/ppb_input_event_shared.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" - -namespace content { - -class BrowserPluginChannelManager; - -// GuestToEmbedderChannel is a Dispatcher that sends and receives ppapi messages -// from the browser plugin embedder. It is reference counted because it is held -// by a RenderViewImpl which (indirectly) owns a PpapiCommandBufferProxy through -// a WebGraphicsContext3DCommandBufferImpl which is owned by WebKit. Since the -// lifetime of this context is less than the lifetime of the RenderViewImpl, we -// keep the GuestToEmbedderChannel alive as long as a RenderViewImpl has access -// to it. If the context is lost, then the PpapiCommandBufferProxy is destroyed -// and we can safely release the reference to this GuestToEmbedderChannel held -// by RenderViewImpl. -class GuestToEmbedderChannel - : public ppapi::proxy::Dispatcher, - public base::RefCounted { - public: - GuestToEmbedderChannel( - const std::string& embedder_channel_name, - const IPC::ChannelHandle& embedder_channel_handle); - - // This must be called before anything else. Returns true on success. - bool InitChannel(const IPC::ChannelHandle& channel_handle); - - // Creates a new WebGraphicsContext3DCommandBufferImpl and returns it. - WebGraphicsContext3DCommandBufferImpl* CreateWebGraphicsContext3D( - RenderViewImpl* render_view, - const WebKit::WebGraphicsContext3D::Attributes& attributes, - bool offscreen); - - // Inform the host to invalidate its plugin container after a swap buffer. - void IssueSwapBuffers(const ppapi::HostResource& resource); - - // Request the receipt of events from the embedder renderer. - void RequestInputEvents(PP_Instance instance); - - // Request a graphics context from the embedder renderer. - bool CreateGraphicsContext( - WebGraphicsContext3DCommandBufferImpl* context, - const WebKit::WebGraphicsContext3D::Attributes& attributes, - bool offscreen, - RenderViewImpl* render_view); - - // Register the given RenderView with the given PP_Instance. - void AddGuest(PP_Instance instance, RenderViewImpl* render_view); - - // Removes the guest with the given instance identifier from the - // InstanceMap. - void RemoveGuest(PP_Instance instance); - - const std::string& embedder_channel_name() const { - return embedder_channel_name_; - } - - const IPC::ChannelHandle& embedder_channel_handle() const { - return embedder_channel_handle_; - } - - // ppapi::proxy::Dispatcher implementation. - virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - virtual bool Send(IPC::Message* message) OVERRIDE; - virtual void OnChannelError() OVERRIDE; - virtual bool IsPlugin() const OVERRIDE; - - private: - friend class base::RefCounted; - typedef std::map > InstanceMap; - typedef std::map RoutingIDToInstanceMap; - - virtual ~GuestToEmbedderChannel(); - - void OnSupportsInterface(const std::string& interface_name, bool* result); - void OnSetPreferences(const ppapi::Preferences& prefs); - void OnReserveInstanceId(PP_Instance instance, bool* usable); - void OnDidCreate(PP_Instance instance, - const std::vector& argn, - const std::vector& argv, - PP_Bool* result); - void OnDidDestroy(PP_Instance instance); - void OnDidChangeView(PP_Instance instance, - const ppapi::ViewData& new_data, - PP_Bool flash_fullscreen); - void OnDidChangeFocus(PP_Instance instance, PP_Bool has_focus); - void OnGetInstanceObject(PP_Instance instance, - ppapi::proxy::SerializedVarReturnValue result); - - void OnHandleMessage(PP_Instance instance, - ppapi::proxy::SerializedVarReceiveInput data); - - void OnHandleFilteredInputEvent(PP_Instance instance, - const ppapi::InputEventData& data, - PP_Bool* result); - - void OnSwapBuffersACK(const ppapi::HostResource& context, - int32_t pp_error); - - void OnContextLost(PP_Instance instance); - - void OnGuestReady(PP_Instance instance, int embedder_container_id); - - base::WeakPtr render_view_; - std::string embedder_channel_name_; - IPC::ChannelHandle embedder_channel_handle_; - PepperProxyChannelDelegateImpl delegate_; - - InstanceMap render_view_instances_; - RoutingIDToInstanceMap routing_id_instance_map_; - - DISALLOW_COPY_AND_ASSIGN(GuestToEmbedderChannel); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_BROWSER_PLUGIN_GUEST_TO_EMBEDDER_CHANNEL_H_ diff --git a/content/renderer/browser_plugin/old/browser_plugin.cc b/content/renderer/browser_plugin/old/browser_plugin.cc new file mode 100644 index 0000000..c57fba3 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin.cc @@ -0,0 +1,157 @@ +// 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/browser_plugin/old/browser_plugin.h" + +#include "base/atomic_sequence_num.h" +#include "base/id_map.h" +#include "base/lazy_instance.h" +#include "base/process.h" +#include "base/string_number_conversions.h" +#include "base/string_piece.h" +#include "base/string_util.h" +#include "base/values.h" +#include "content/common/browser_plugin_messages.h" +#include "content/public/common/url_constants.h" +#include "content/renderer/render_view_impl.h" +#include "ipc/ipc_channel_handle.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" +#include "webkit/plugins/webview_plugin.h" + +static int g_next_id = 0; + +// The global list of all Browser Plugin Placeholders within a process. +base::LazyInstance >::Leaky + g_all_browser_plugins = LAZY_INSTANCE_INITIALIZER; + +using WebKit::WebPlugin; +using WebKit::WebPluginContainer; +using webkit::WebViewPlugin; + +void Register(int id, BrowserPlugin* browser_plugin) { + g_all_browser_plugins.Get().AddWithID(browser_plugin, id); +} + +void Unregister(int id) { + if (g_all_browser_plugins.Get().Lookup(id)) + g_all_browser_plugins.Get().Remove(id); +} + +// static +WebKit::WebPlugin* BrowserPlugin::Create( + RenderViewImpl* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params) { + // TODO(fsamuel): Figure out what the lifetime is of this class. + // It seems we need to blow away this object once a WebPluginContainer is + // gone. How do we detect it's gone? A WebKit change perhaps? + BrowserPlugin* browser_plugin = new BrowserPlugin( + render_view, frame, params, ""); + return browser_plugin->placeholder(); +} + +// static +BrowserPlugin* BrowserPlugin::FromID(int id) { + return g_all_browser_plugins.Get().Lookup(id); +} + +BrowserPlugin::BrowserPlugin( + RenderViewImpl* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params, + const std::string& html_data) + : render_view_(render_view), + plugin_params_(params), + placeholder_(webkit::WebViewPlugin::Create( + NULL, + render_view->GetWebkitPreferences(), + html_data, + GURL(chrome::kAboutBlankURL))), + plugin_(NULL) { + id_ = ++g_next_id; + Register(id_, this); + + // By default we do not navigate and simply stay with an + // about:blank placeholder. + std::string src; + ParseSrcAttribute("", &src); + + if (!src.empty()) { + render_view->Send(new BrowserPluginHostMsg_NavigateFromEmbedder( + render_view->GetRoutingID(), + id_, + frame->identifier(), + src)); + } +} + +BrowserPlugin::~BrowserPlugin() { + Unregister(id_); +} + +void BrowserPlugin::ParseSrcAttribute( + const std::string& default_src, + std::string* src) { + // Get the src attribute from the attributes vector + for (unsigned i = 0; i < plugin_params_.attributeNames.size(); ++i) { + std::string attributeName = plugin_params_.attributeNames[i].utf8(); + if (LowerCaseEqualsASCII(attributeName, "src")) { + *src = plugin_params_.attributeValues[i].utf8(); + break; + } + } + // If we didn't find the attributes set or they're not sensible, + // we reset our attributes to the default. + if (src->empty()) { + *src = default_src; + } +} + +void BrowserPlugin::LoadGuest( + int guest_process_id, + const IPC::ChannelHandle& channel_handle) { + webkit::ppapi::WebPluginImpl* new_guest = + render_view()->CreateBrowserPlugin(channel_handle, + guest_process_id, + plugin_params()); + Replace(new_guest); +} + +void BrowserPlugin::AdvanceFocus(bool reverse) { + // TODO(fsamuel): Uncomment this once http://wkbug.com/88827 lands. + // render_view()->GetWebView()->advanceFocus(reverse); +} + +void BrowserPlugin::Replace( + webkit::ppapi::WebPluginImpl* new_plugin) { + WebKit::WebPlugin* current_plugin = + plugin_ ? static_cast(plugin_) : placeholder_; + WebKit::WebPluginContainer* container = current_plugin->container(); + if (!new_plugin || !new_plugin->initialize(container)) + return; + + // Clear the container's backing texture ID. + if (plugin_) + plugin_->instance()->BindGraphics(plugin_->instance()->pp_instance(), 0); + + PP_Instance instance = new_plugin->instance()->pp_instance(); + ppapi::proxy::HostDispatcher* dispatcher = + ppapi::proxy::HostDispatcher::GetForInstance(instance); + dispatcher->Send(new BrowserPluginMsg_GuestReady(instance, id_)); + + // TODO(fsamuel): We should delay the swapping out of the current plugin + // until after the guest's WebGraphicsContext3D has been initialized. That + // way, we immediately have something to render onto the screen. + container->setPlugin(new_plugin); + container->invalidate(); + container->reportGeometry(); + if (plugin_) + plugin_->destroy(); + plugin_ = new_plugin; +} diff --git a/content/renderer/browser_plugin/old/browser_plugin.h b/content/renderer/browser_plugin/old/browser_plugin.h new file mode 100644 index 0000000..a4b6f9c --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin.h @@ -0,0 +1,90 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_H_ +#pragma once + +#include "base/process.h" +#include "content/renderer/render_view_impl.h" +#include "ipc/ipc_channel_handle.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" +#include "ui/gfx/size.h" +#include "webkit/plugins/webview_plugin.h" + +namespace content { +class RenderView; +} + +namespace WebKit { +class WebPlugin; +} + +// A browser plugin is a plugin container that hosts an out-of-process "guest" +// RenderView. Loading up a new process, creating a new RenderView, navigating +// to a given URL, and establishing a guest-to-embedder channel can take +// hundreds of milliseconds. Furthermore, a RenderView's associated browser-side +// WebContents, RenderViewHost, and SiteInstance must be created and accessed on +// the UI thread of the browser process. +// +// To avoid blocking the embedder RenderView and to avoid introducing the +// potential for deadlock, BrowserPlugin attaches a placeholder that takes +// place of the guest RenderView until the guest has established a connection +// with its embedder RenderView. This permits asynchronously loading of the +// guest while the embedder RenderView is permitted to continue to receive and +// process events. +// +// Furthermore, certain navigations can swap to a new guest RenderView on an +// different process. BrowserPlugin is the consistent facade that the embedder's +// WebKit instance talks to regardless of which process it's communicating with. +class BrowserPlugin { + public: + // Creates a new WebViewPlugin with a BrowserPlugin as a delegate. + static WebKit::WebPlugin* Create( + RenderViewImpl* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params); + + static BrowserPlugin* FromID(int id); + + webkit::WebViewPlugin* placeholder() { return placeholder_; } + + webkit::ppapi::WebPluginImpl* plugin() { return plugin_; } + + const WebKit::WebPluginParams& plugin_params() const { + return plugin_params_; + } + + void LoadGuest(int guest_process_id, + const IPC::ChannelHandle& channel_handle); + + void AdvanceFocus(bool reverse); + + RenderViewImpl* render_view() { return render_view_; } + + private: + BrowserPlugin(RenderViewImpl* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params, + const std::string& html_data); + virtual ~BrowserPlugin(); + + // Parses the source URL of the browser plugin from the element's attributes + // and outputs them. If not found, it outputs the defaults specified here as + // parameters. + void ParseSrcAttribute(const std::string& default_src, std::string* src); + // Replace the current guest with a new guest. + void Replace(webkit::ppapi::WebPluginImpl* new_plugin); + + RenderViewImpl* render_view_; + WebKit::WebPluginParams plugin_params_; + webkit::WebViewPlugin* placeholder_; + webkit::ppapi::WebPluginImpl* plugin_; + int id_; + + DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); +}; + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_H_ diff --git a/content/renderer/browser_plugin/old/browser_plugin_channel_manager.cc b/content/renderer/browser_plugin/old/browser_plugin_channel_manager.cc new file mode 100644 index 0000000..e00df2b --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_channel_manager.cc @@ -0,0 +1,144 @@ +// 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/browser_plugin/old/browser_plugin_channel_manager.h" + +#include "base/process_util.h" +#include "content/common/browser_plugin_messages.h" +#include "content/common/view_messages.h" +#include "content/renderer/browser_plugin/old/browser_plugin.h" +#include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h" +#include "content/renderer/render_thread_impl.h" +#include "content/renderer/render_view_impl.h" +#include "ppapi/c/pp_instance.h" + +namespace content { + +BrowserPluginChannelManager::BrowserPluginChannelManager() { +} + +BrowserPluginChannelManager::~BrowserPluginChannelManager() { +} + +void BrowserPluginChannelManager::CreateRenderView( + const ViewMsg_New_Params& params) { + IPC::ChannelHandle embedder_channel_handle; + embedder_channel_handle.name = + IPC::Channel::GenerateVerifiedChannelID(params.embedder_channel_name); + bool success = true; + scoped_refptr channel = + GetChannelByName(params.embedder_channel_name); + if (!channel) { + channel = new GuestToEmbedderChannel(params.embedder_channel_name, + embedder_channel_handle.name); + success = channel->InitChannel(embedder_channel_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. + embedder_channel_handle.socket = + base::FileDescriptor(channel->TakeRendererFD(), true); + if (embedder_channel_handle.socket.fd == -1) + success = false; +#endif + DCHECK(success); + embedder_channels_[params.embedder_channel_name] = channel; + } + RenderViewImpl* render_view = + RenderViewImpl::Create( + params.parent_window, + params.opener_route_id, + params.renderer_preferences, + params.web_preferences, + new SharedRenderViewCounter(0), + params.view_id, + params.surface_id, + params.session_storage_namespace_id, + params.frame_name, + false, + params.swapped_out, + params.next_page_id, + params.screen_info, + channel, + params.accessibility_mode); + ReportChannelToEmbedder(render_view, + embedder_channel_handle, + params.embedder_channel_name, + params.embedder_container_id); +} + +void BrowserPluginChannelManager::ReportChannelToEmbedder( + RenderViewImpl* render_view, + const IPC::ChannelHandle& embedder_channel_handle, + const std::string& embedder_channel_name, + int embedder_container_id) { + std::pair pending_guests_key = + std::make_pair(embedder_channel_name, embedder_container_id); + DCHECK(pending_guests_.find(pending_guests_key) == + pending_guests_.end()); + pending_guests_[pending_guests_key] = render_view->AsWeakPtr(); + RenderThreadImpl::current()->Send( + new BrowserPluginHostMsg_ConnectToChannel(render_view->GetRoutingID(), + embedder_channel_handle)); +} + +bool BrowserPluginChannelManager::OnControlMessageReceived( + const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(BrowserPluginChannelManager, message) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadGuest, OnLoadGuest) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +GuestToEmbedderChannel* BrowserPluginChannelManager::GetChannelByName( + const std::string& embedder_channel_name) { + EmbedderChannelNameToChannelMap::iterator it = + embedder_channels_.find(embedder_channel_name); + if (it != embedder_channels_.end()) + return it->second; + return NULL; +} + +void BrowserPluginChannelManager::RemoveChannelByName( + const std::string& embedder_channel_name) { + embedder_channels_.erase(embedder_channel_name); +} + +void BrowserPluginChannelManager::GuestReady( + PP_Instance instance, + const std::string& embedder_channel_name, + int embedder_container_id) { + std::pair pending_guests_key = + make_pair(embedder_channel_name, embedder_container_id); + DCHECK(pending_guests_.find(pending_guests_key) != + pending_guests_.end()); + RenderViewImpl* render_view = pending_guests_[pending_guests_key]; + pending_guests_.erase(pending_guests_key); + GuestToEmbedderChannel* channel = render_view->GetGuestToEmbedderChannel(); + // Associate the RenderView with the provided PP_Instance ID, request the + // receipt of events, and initialize the graphics context. + channel->AddGuest(instance, render_view); + render_view->GuestReady(instance); +} + +void BrowserPluginChannelManager::OnLoadGuest( + int instance_id, + int guest_process_id, + const IPC::ChannelHandle& channel_handle) { + BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); + browser_plugin->LoadGuest(guest_process_id, channel_handle); +} + +void BrowserPluginChannelManager::OnAdvanceFocus(int instance_id, + bool reverse) { + BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); + browser_plugin->AdvanceFocus(reverse); +} + +} // namespace content diff --git a/content/renderer/browser_plugin/old/browser_plugin_channel_manager.h b/content/renderer/browser_plugin/old/browser_plugin_channel_manager.h new file mode 100644 index 0000000..4656139 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_channel_manager.h @@ -0,0 +1,82 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ +#pragma once + +#include + +#include "base/id_map.h" +#include "content/public/renderer/render_process_observer.h" +#include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h" +#include "content/renderer/render_view_impl.h" + +class GuestToEmbedderChannel; +struct ViewMsg_New_Params; + +namespace content { + +// BrowserPluginChannelManager manages the lifetime of GuestToEmbedderChannels. +// When a new RenderView is requested, it checks the embedder channel name +// in ViewMsg_New_Params and decides whether to reuse an existing channel or +// create a new channel. On the guest renderer process, it informs a +// RenderView once a channel has been established with its embedder. +// On the embedder side, it tells BrowserPlugin to load the guest +// PluginInstance once a channel has been established. +class BrowserPluginChannelManager + : public RenderProcessObserver { + public: + BrowserPluginChannelManager(); + + virtual ~BrowserPluginChannelManager(); + + void CreateRenderView(const ViewMsg_New_Params& params); + + void ReportChannelToEmbedder( + RenderViewImpl* render_view, + const IPC::ChannelHandle& embedder_channel_handle, + const std::string& embedder_channel_name, + int embedder_container_id); + + // Get the GuestToEmbedderChannel associated with the given + // embedder_channel_name. + GuestToEmbedderChannel* GetChannelByName( + const std::string& embedder_channel_name); + + // Remove the pointer to the GuestToEmbedderChannel associated with the given + // routing_id. + void RemoveChannelByName(const std::string& embedder_channel_name); + + void GuestReady(PP_Instance instance, + const std::string& embedder_channel_name, + int embedder_container_id); + + private: + typedef std::map > + EmbedderChannelNameToChannelMap; + + void OnLoadGuest(int instance_id, + int guest_renderer_id, + const IPC::ChannelHandle& channel_handle); + void OnAdvanceFocus(int instance_id, bool reverse); + + // RenderProcessObserver override. Call on render thread. + virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; + + // Map from Host process ID to GuestToEmbedderChannel + EmbedderChannelNameToChannelMap embedder_channels_; + + // Map from to RenderViewImpl + // that points to RenderViewImpl guests that have been constructed but don't + // have a PP_Instance and so they aren't yet ready to composite. + std::map, + base::WeakPtr > pending_guests_; + + DISALLOW_COPY_AND_ASSIGN(BrowserPluginChannelManager); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_CHANNEL_MANAGER_H_ diff --git a/content/renderer/browser_plugin/old/browser_plugin_constants.cc b/content/renderer/browser_plugin/old/browser_plugin_constants.cc new file mode 100644 index 0000000..020385a --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_constants.cc @@ -0,0 +1,10 @@ +// 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/browser_plugin/old/browser_plugin_constants.h" + +const char kBrowserPluginName[] = "Browser Plugin"; +const FilePath::CharType kBrowserPluginPath[] = + FILE_PATH_LITERAL("internal/browser-plugin"); +const char kBrowserPluginDescription[] = "Out-of-Process Browser Plugin"; diff --git a/content/renderer/browser_plugin/old/browser_plugin_constants.h b/content/renderer/browser_plugin/old/browser_plugin_constants.h new file mode 100644 index 0000000..01748d8 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_constants.h @@ -0,0 +1,15 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_CONSTANTS_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_CONSTANTS_H_ +#pragma once + +#include "base/file_path.h" + +extern const char kBrowserPluginName[]; +extern const FilePath::CharType kBrowserPluginPath[]; +extern const char kBrowserPluginDescription[]; + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_CONSTANTS_H_ diff --git a/content/renderer/browser_plugin/old/browser_plugin_registry.cc b/content/renderer/browser_plugin/old/browser_plugin_registry.cc new file mode 100644 index 0000000..823fd80 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_registry.cc @@ -0,0 +1,45 @@ +// 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/browser_plugin/old/browser_plugin_registry.h" + +#include "base/logging.h" + +namespace content { + +BrowserPluginRegistry::BrowserPluginRegistry() { +} + +BrowserPluginRegistry::~BrowserPluginRegistry() { +} + +webkit::ppapi::PluginModule* BrowserPluginRegistry::GetModule( + int guest_process_id) { + return modules_.Lookup(guest_process_id); +} + +void BrowserPluginRegistry::AddModule(int guest_process_id, + webkit::ppapi::PluginModule* module) { + modules_.AddWithID(module, guest_process_id); +} + +void BrowserPluginRegistry::PluginModuleDead( + webkit::ppapi::PluginModule* dead_module) { + // DANGER: Don't dereference the dead_module pointer! It may be in the + // process of being deleted. + + // Modules aren't destroyed very often and there are normally at most a + // couple of them. So for now we just do a brute-force search. + IDMap::iterator iter(&modules_); + while (!iter.IsAtEnd()) { + if (iter.GetCurrentValue() == dead_module) { + modules_.Remove(iter.GetCurrentKey()); + return; + } + iter.Advance(); + } + NOTREACHED(); // Should have always found the module above. +} + +} // namespace content diff --git a/content/renderer/browser_plugin/old/browser_plugin_registry.h b/content/renderer/browser_plugin/old/browser_plugin_registry.h new file mode 100644 index 0000000..54f0c13 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_registry.h @@ -0,0 +1,37 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_REGISTRY_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_REGISTRY_H_ +#pragma once + +#include "base/id_map.h" +#include "base/process.h" +#include "webkit/plugins/ppapi/plugin_delegate.h" + +namespace content { + +// This class holds references to all of the known live browser plugin +// modules. There is one browser plugin module per guest renderer process. +class BrowserPluginRegistry + : public webkit::ppapi::PluginDelegate::ModuleLifetime { + public: + BrowserPluginRegistry(); + virtual ~BrowserPluginRegistry(); + + webkit::ppapi::PluginModule* GetModule(int guest_process_id); + void AddModule(int guest_process_id, + webkit::ppapi::PluginModule* module); + + // ModuleLifetime implementation. + virtual void PluginModuleDead( + webkit::ppapi::PluginModule* dead_module) OVERRIDE; + + private: + IDMap modules_; +}; + +} // namespace content + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_REGISTRY_H_ diff --git a/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.cc b/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.cc new file mode 100644 index 0000000..0091c8c --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.cc @@ -0,0 +1,51 @@ +// 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/browser_plugin/old/browser_plugin_var_serialization_rules.h" + +#include "base/logging.h" + +namespace content { + +BrowserPluginVarSerializationRules::BrowserPluginVarSerializationRules() { +} + +BrowserPluginVarSerializationRules::~BrowserPluginVarSerializationRules() { +} + +PP_Var BrowserPluginVarSerializationRules::SendCallerOwned(const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); + return var; +} + +PP_Var BrowserPluginVarSerializationRules::BeginReceiveCallerOwned( + const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); + return var; +} + +void BrowserPluginVarSerializationRules::EndReceiveCallerOwned( + const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); +} + +PP_Var BrowserPluginVarSerializationRules::ReceivePassRef(const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); + return var; +} + +PP_Var BrowserPluginVarSerializationRules::BeginSendPassRef(const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); + return var; +} + +void BrowserPluginVarSerializationRules::EndSendPassRef(const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); +} + +void BrowserPluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { + DCHECK(var.type != PP_VARTYPE_OBJECT); +} + +} // namespace content diff --git a/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h b/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h new file mode 100644 index 0000000..cf669d6 --- /dev/null +++ b/content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ + +#include "ppapi/proxy/var_serialization_rules.h" + +namespace content { + +// Implementation of the VarSerializationRules interface for the browser plugin. +class BrowserPluginVarSerializationRules : + public ppapi::proxy::VarSerializationRules { + public: + explicit BrowserPluginVarSerializationRules(); + + // VarSerialization implementation. + virtual PP_Var SendCallerOwned(const PP_Var& var) OVERRIDE; + virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var) OVERRIDE; + virtual void EndReceiveCallerOwned(const PP_Var& var) OVERRIDE; + virtual PP_Var ReceivePassRef(const PP_Var& var) OVERRIDE; + virtual PP_Var BeginSendPassRef(const PP_Var& var) OVERRIDE; + virtual void EndSendPassRef(const PP_Var& var) OVERRIDE; + virtual void ReleaseObjectRef(const PP_Var& var) OVERRIDE; + + private: + virtual ~BrowserPluginVarSerializationRules(); + + DISALLOW_COPY_AND_ASSIGN(BrowserPluginVarSerializationRules); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_VAR_SERIALIZATION_RULES_H_ diff --git a/content/renderer/browser_plugin/old/guest_to_embedder_channel.cc b/content/renderer/browser_plugin/old/guest_to_embedder_channel.cc new file mode 100644 index 0000000..deffad5 --- /dev/null +++ b/content/renderer/browser_plugin/old/guest_to_embedder_channel.cc @@ -0,0 +1,306 @@ +// 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/browser_plugin/old/guest_to_embedder_channel.h" + +#include "base/process_util.h" +#include "content/common/browser_plugin_messages.h" +#include "content/common/child_process.h" +#include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h" +#include "content/renderer/browser_plugin/old/browser_plugin_var_serialization_rules.h" +#include "content/renderer/render_thread_impl.h" +#include "content/renderer/render_view_impl.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_graphics_3d.h" +#include "ppapi/proxy/ppapi_command_buffer_proxy.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/api_id.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/var.h" +#include "webkit/plugins/ppapi/event_conversion.h" + +namespace content { + +GuestToEmbedderChannel::GuestToEmbedderChannel( + const std::string& embedder_channel_name, + const IPC::ChannelHandle& embedder_channel_handle) + : Dispatcher(NULL), + embedder_channel_name_(embedder_channel_name), + embedder_channel_handle_(embedder_channel_handle) { + SetSerializationRules(new BrowserPluginVarSerializationRules()); +} + +GuestToEmbedderChannel::~GuestToEmbedderChannel() { +} + +bool GuestToEmbedderChannel::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(GuestToEmbedderChannel, message) + IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnSupportsInterface) + IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnSetPreferences) + IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnReserveInstanceId) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidCreate, + OnDidCreate) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidDestroy, + OnDidDestroy) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeView, + OnDidChangeView) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstance_DidChangeFocus, + OnDidChangeFocus) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, + OnHandleMessage) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPInputEvent_HandleFilteredInputEvent, + OnHandleFilteredInputEvent) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPGraphics3D_ContextLost, + OnContextLost) + IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestReady, + OnGuestReady) + // Have the super handle all other messages. + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +bool GuestToEmbedderChannel::Send(IPC::Message* message) { + // We always want guest->host messages to arrive in-order. If some sync + // and some async messages are sent in response to a synchronous + // host->guest call, the sync reply will be processed before the async + // reply, and everything will be confused. + // + // Allowing all async messages to unblock the renderer means more reentrancy + // there but gives correct ordering. + message->set_unblock(true); + return ProxyChannel::Send(message); +} + +void GuestToEmbedderChannel::OnChannelError() { + // We cannot destroy the GuestToEmbedderChannel here because a + // PpapiCommandBufferProxy may still refer to this object. + // However, we should not be using this channel again once we get a + // channel error so we remove it from the channel manager. + RenderThreadImpl::current()->browser_plugin_channel_manager()-> + RemoveChannelByName(embedder_channel_name_); +} + +bool GuestToEmbedderChannel::IsPlugin() const { + return true; +} + +WebGraphicsContext3DCommandBufferImpl* + GuestToEmbedderChannel::CreateWebGraphicsContext3D( + RenderViewImpl* render_view, + const WebKit::WebGraphicsContext3D::Attributes& attributes, + bool offscreen) { + scoped_ptr context( + new WebGraphicsContext3DCommandBufferImpl( + 0, GURL(), NULL, + render_view->AsWeakPtr())); + + // Special case: RenderView initialization has not yet completed. + if (!render_view->guest_pp_instance()) + return context.release(); + + if (CreateGraphicsContext(context.get(), + attributes, + offscreen, + render_view)) + return context.release(); + + return NULL; +} + +void GuestToEmbedderChannel::IssueSwapBuffers( + const ppapi::HostResource& resource) { + Send(new PpapiHostMsg_PPBGraphics3D_SwapBuffers( + ppapi::API_ID_PPB_GRAPHICS_3D, resource)); +} + +bool GuestToEmbedderChannel::InitChannel( + const IPC::ChannelHandle& channel_handle) { + return ProxyChannel::InitWithChannel(&delegate_, channel_handle, false); +} + +void GuestToEmbedderChannel::OnSupportsInterface( + const std::string& interface_name, + bool* result) { + // TODO(fsamuel): This is a hack to avoid getting GetInstanceObject messages + // and failing a CHECK. A more correct solution is to implement + // VarSerializationRules for GuestToEmbedderChannel. + *result = interface_name.find("PPP_Instance_Private") == std::string::npos; +} + +void GuestToEmbedderChannel::OnSetPreferences(const ppapi::Preferences& prefs) { + // TODO(fsamuel): Do we care about these preferences? + // These look like some font stuff from WebPreferences. + // Perhaps this should be plumbed into our associated RenderView? + NOTIMPLEMENTED(); +} + +void GuestToEmbedderChannel::OnReserveInstanceId(PP_Instance instance, + bool* usable) { + *usable = + render_view_instances_.find(instance) == render_view_instances_.end(); +} + +void GuestToEmbedderChannel::RequestInputEvents(PP_Instance instance) { + // Request receipt of input events + Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( + ppapi::API_ID_PPB_INSTANCE, instance, true, + PP_INPUTEVENT_CLASS_MOUSE | + PP_INPUTEVENT_CLASS_KEYBOARD | + PP_INPUTEVENT_CLASS_WHEEL | + PP_INPUTEVENT_CLASS_TOUCH)); +} + +bool GuestToEmbedderChannel::CreateGraphicsContext( + WebGraphicsContext3DCommandBufferImpl* context, + const WebKit::WebGraphicsContext3D::Attributes& attributes, + bool offscreen, + RenderViewImpl* render_view) { + std::vector attribs; + attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); + + ppapi::HostResource resource; + DCHECK(render_view->guest_pp_instance()); + // TODO(fsamuel): Support shared contexts. + bool success = Send(new PpapiHostMsg_PPBGraphics3D_Create( + ppapi::API_ID_PPB_GRAPHICS_3D, + render_view->guest_pp_instance(), + ppapi::HostResource(), + attribs, + &resource)); + if (!success || resource.is_null()) + return false; + if (!offscreen) { + PP_Bool result = PP_FALSE; + Send(new PpapiHostMsg_PPBInstance_BindGraphics( + ppapi::API_ID_PPB_INSTANCE, + render_view->guest_pp_instance(), + resource, + &result)); + if (result != PP_TRUE) + return false; + } + + CommandBufferProxy* command_buffer = + new ppapi::proxy::PpapiCommandBufferProxy(resource, this); + command_buffer->Initialize(); + context->InitializeWithCommandBuffer( + command_buffer, + attributes, + false /* bind generates resources */); + render_view->set_guest_graphics_resource(resource); + return true; +} + +void GuestToEmbedderChannel::AddGuest( + PP_Instance instance, + RenderViewImpl* render_view) { + DCHECK(instance); + DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); + render_view_instances_[instance] = render_view->AsWeakPtr(); +} + + +void GuestToEmbedderChannel::RemoveGuest(PP_Instance instance) { + DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); + render_view_instances_.erase(instance); +} + +void GuestToEmbedderChannel::OnDidCreate( + PP_Instance instance, + const std::vector& argn, + const std::vector& argv, + PP_Bool* result) { + DCHECK(render_view_instances_.find(instance) == render_view_instances_.end()); + RequestInputEvents(instance); + *result = PP_TRUE; +} + +void GuestToEmbedderChannel::OnDidDestroy(PP_Instance instance) { + InstanceMap::iterator it = render_view_instances_.find(instance); + DCHECK(it != render_view_instances_.end()); + RenderViewImpl* render_view = it->second; + render_view->SetGuestToEmbedderChannel(NULL); + render_view->set_guest_pp_instance(0); + RemoveGuest(instance); +} + +void GuestToEmbedderChannel::OnDidChangeView( + PP_Instance instance, + const ppapi::ViewData& new_data, + PP_Bool flash_fullscreen) { + // We can't do anything with this message if we don't have a render view + // yet. If we do have a RenderView then we need to tell the associated + // WebContentsObserver to resize. + if (render_view_instances_.find(instance) != render_view_instances_.end()) { + RenderViewImpl* render_view = render_view_instances_[instance]; + render_view->Send( + new BrowserPluginHostMsg_ResizeGuest( + render_view->GetRoutingID(), + new_data.rect.size.width, + new_data.rect.size.height)); + } +} + +void GuestToEmbedderChannel::OnDidChangeFocus(PP_Instance instance, + PP_Bool has_focus) { + InstanceMap::iterator it = render_view_instances_.find(instance); + if (it == render_view_instances_.end()) + return; + RenderViewImpl* render_view = it->second; + render_view->GetWebView()->setFocus(PP_ToBool(has_focus)); +} + +void GuestToEmbedderChannel::OnHandleMessage( + PP_Instance instance, + ppapi::proxy::SerializedVarReceiveInput message_data) { + InstanceMap::iterator it = render_view_instances_.find(instance); + if (it == render_view_instances_.end()) + return; + + PP_Var received_var(message_data.Get(this)); + DCHECK(received_var.type == PP_VARTYPE_STRING); + ppapi::VarTracker* tracker = ppapi::PpapiGlobals::Get()->GetVarTracker(); + ppapi::StringVar* var = tracker->GetVar(received_var)->AsStringVar(); + DCHECK(var); + + RenderViewImpl* render_view = it->second; + render_view->Send( + new BrowserPluginHostMsg_NavigateFromGuest( + render_view->GetRoutingID(), + instance, + var->value())); +} + +void GuestToEmbedderChannel::OnHandleFilteredInputEvent( + PP_Instance instance, + const ppapi::InputEventData& data, + PP_Bool* result) { + if (render_view_instances_.find(instance) == render_view_instances_.end()) + return; + + RenderViewImpl* render_view = render_view_instances_[instance]; + scoped_ptr web_input_event( + webkit::ppapi::CreateWebInputEvent(data)); + *result = PP_FromBool( + render_view->GetWebView()->handleInputEvent(*web_input_event)); +} + +void GuestToEmbedderChannel::OnContextLost(PP_Instance instance) { + DCHECK(render_view_instances_.find(instance) != render_view_instances_.end()); + RenderViewImpl* render_view = render_view_instances_[instance]; + // TODO(fsamuel): This is test code. Need to find a better way to tell + // a WebView to drop its context. + render_view->GetWebView()->loseCompositorContext(1); +} + +void GuestToEmbedderChannel::OnGuestReady(PP_Instance instance, + int embedder_container_id) { + RenderThreadImpl::current()->browser_plugin_channel_manager()-> + GuestReady(instance, embedder_channel_name(), embedder_container_id); +} + +} // namespace content diff --git a/content/renderer/browser_plugin/old/guest_to_embedder_channel.h b/content/renderer/browser_plugin/old/guest_to_embedder_channel.h new file mode 100644 index 0000000..83bf6e3 --- /dev/null +++ b/content/renderer/browser_plugin/old/guest_to_embedder_channel.h @@ -0,0 +1,138 @@ +// 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. + +#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_OLD_GUEST_TO_EMBEDDER_CHANNEL_H_ +#define CONTENT_RENDERER_BROWSER_PLUGIN_OLD_GUEST_TO_EMBEDDER_CHANNEL_H_ +#pragma once + +#include "base/memory/ref_counted.h" +#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" +#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" +#include "content/renderer/render_view_impl.h" +#include "ipc/ipc_channel_handle.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/shared_impl/ppb_view_shared.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/host_resource.h" +#include "ppapi/shared_impl/ppapi_preferences.h" +#include "ppapi/shared_impl/ppb_input_event_shared.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" + +namespace content { + +class BrowserPluginChannelManager; + +// GuestToEmbedderChannel is a Dispatcher that sends and receives ppapi messages +// from the browser plugin embedder. It is reference counted because it is held +// by a RenderViewImpl which (indirectly) owns a PpapiCommandBufferProxy through +// a WebGraphicsContext3DCommandBufferImpl which is owned by WebKit. Since the +// lifetime of this context is less than the lifetime of the RenderViewImpl, we +// keep the GuestToEmbedderChannel alive as long as a RenderViewImpl has access +// to it. If the context is lost, then the PpapiCommandBufferProxy is destroyed +// and we can safely release the reference to this GuestToEmbedderChannel held +// by RenderViewImpl. +class GuestToEmbedderChannel + : public ppapi::proxy::Dispatcher, + public base::RefCounted { + public: + GuestToEmbedderChannel( + const std::string& embedder_channel_name, + const IPC::ChannelHandle& embedder_channel_handle); + + // This must be called before anything else. Returns true on success. + bool InitChannel(const IPC::ChannelHandle& channel_handle); + + // Creates a new WebGraphicsContext3DCommandBufferImpl and returns it. + WebGraphicsContext3DCommandBufferImpl* CreateWebGraphicsContext3D( + RenderViewImpl* render_view, + const WebKit::WebGraphicsContext3D::Attributes& attributes, + bool offscreen); + + // Inform the host to invalidate its plugin container after a swap buffer. + void IssueSwapBuffers(const ppapi::HostResource& resource); + + // Request the receipt of events from the embedder renderer. + void RequestInputEvents(PP_Instance instance); + + // Request a graphics context from the embedder renderer. + bool CreateGraphicsContext( + WebGraphicsContext3DCommandBufferImpl* context, + const WebKit::WebGraphicsContext3D::Attributes& attributes, + bool offscreen, + RenderViewImpl* render_view); + + // Register the given RenderView with the given PP_Instance. + void AddGuest(PP_Instance instance, RenderViewImpl* render_view); + + // Removes the guest with the given instance identifier from the + // InstanceMap. + void RemoveGuest(PP_Instance instance); + + const std::string& embedder_channel_name() const { + return embedder_channel_name_; + } + + const IPC::ChannelHandle& embedder_channel_handle() const { + return embedder_channel_handle_; + } + + // ppapi::proxy::Dispatcher implementation. + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + virtual bool Send(IPC::Message* message) OVERRIDE; + virtual void OnChannelError() OVERRIDE; + virtual bool IsPlugin() const OVERRIDE; + + private: + friend class base::RefCounted; + typedef std::map > InstanceMap; + typedef std::map RoutingIDToInstanceMap; + + virtual ~GuestToEmbedderChannel(); + + void OnSupportsInterface(const std::string& interface_name, bool* result); + void OnSetPreferences(const ppapi::Preferences& prefs); + void OnReserveInstanceId(PP_Instance instance, bool* usable); + void OnDidCreate(PP_Instance instance, + const std::vector& argn, + const std::vector& argv, + PP_Bool* result); + void OnDidDestroy(PP_Instance instance); + void OnDidChangeView(PP_Instance instance, + const ppapi::ViewData& new_data, + PP_Bool flash_fullscreen); + void OnDidChangeFocus(PP_Instance instance, PP_Bool has_focus); + void OnGetInstanceObject(PP_Instance instance, + ppapi::proxy::SerializedVarReturnValue result); + + void OnHandleMessage(PP_Instance instance, + ppapi::proxy::SerializedVarReceiveInput data); + + void OnHandleFilteredInputEvent(PP_Instance instance, + const ppapi::InputEventData& data, + PP_Bool* result); + + void OnSwapBuffersACK(const ppapi::HostResource& context, + int32_t pp_error); + + void OnContextLost(PP_Instance instance); + + void OnGuestReady(PP_Instance instance, int embedder_container_id); + + base::WeakPtr render_view_; + std::string embedder_channel_name_; + IPC::ChannelHandle embedder_channel_handle_; + PepperProxyChannelDelegateImpl delegate_; + + InstanceMap render_view_instances_; + RoutingIDToInstanceMap routing_id_instance_map_; + + DISALLOW_COPY_AND_ASSIGN(GuestToEmbedderChannel); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_BROWSER_PLUGIN_OLD_GUEST_TO_EMBEDDER_CHANNEL_H_ diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index 18c40a9..39401e8 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -33,8 +33,8 @@ #include "content/public/common/media_stream_request.h" #include "content/public/common/referrer.h" #include "content/public/renderer/content_renderer_client.h" -#include "content/renderer/browser_plugin/browser_plugin_constants.h" -#include "content/renderer/browser_plugin/browser_plugin_registry.h" +#include "content/renderer/browser_plugin/old/browser_plugin_constants.h" +#include "content/renderer/browser_plugin/old/browser_plugin_registry.h" #include "content/renderer/gamepad_shared_memory_reader.h" #include "content/renderer/media/audio_hardware.h" #include "content/renderer/media/media_stream_dispatcher.h" diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index d3729aa..03d56c3 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -46,8 +46,8 @@ #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/render_process_observer.h" #include "content/public/renderer/render_view_visitor.h" -#include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" -#include "content/renderer/browser_plugin/browser_plugin_registry.h" +#include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h" +#include "content/renderer/browser_plugin/old/browser_plugin_registry.h" #include "content/renderer/devtools_agent_filter.h" #include "content/renderer/dom_storage/dom_storage_dispatcher.h" #include "content/renderer/dom_storage/webstoragearea_impl.h" diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index ba634a3..b4ff5f5 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -56,10 +56,10 @@ #include "content/public/renderer/navigation_state.h" #include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_visitor.h" -#include "content/renderer/browser_plugin/browser_plugin.h" -#include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" -#include "content/renderer/browser_plugin/browser_plugin_constants.h" -#include "content/renderer/browser_plugin/guest_to_embedder_channel.h" +#include "content/renderer/browser_plugin/old/browser_plugin.h" +#include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h" +#include "content/renderer/browser_plugin/old/browser_plugin_constants.h" +#include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h" #include "content/renderer/device_orientation_dispatcher.h" #include "content/renderer/devtools_agent.h" #include "content/renderer/dom_automation_controller.h" -- cgit v1.1