Skip to content

Commit

Permalink
Add mojo interfaces for pepper plugins.
Browse files Browse the repository at this point in the history
This adds some base plumbing for pepper plugin instance handling. The
pepper renderer code allocates and manages the PepperPluginInstanceImpl,
this creates the correct encapsulation moving code out of RenderFrameImpl.

On the browser side a PepperPluginInstance is created to handle the
messages and relay them to the WebContentsImpl which use to handle
the processing of Pepper messages.

BUG=1157519

Change-Id: I24941bb7eecef56a90bbf961e6396101c8d3c785
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585627
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836239}
  • Loading branch information
dtapuska authored and Chromium LUCI CQ committed Dec 11, 2020
1 parent bece741 commit 3da5569
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 56 deletions.
9 changes: 9 additions & 0 deletions content/browser/renderer_host/render_frame_host_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,15 @@ class CONTENT_EXPORT RenderFrameHostDelegate {
GetActiveTopLevelDocumentsInBrowsingContextGroup(
RenderFrameHostImpl* render_frame_host);

#if BUILDFLAG(ENABLE_PLUGINS)
virtual void OnPepperInstanceCreated(RenderFrameHostImpl* source,
int32_t pp_instance) {}
virtual void OnPepperStartsPlayback(RenderFrameHostImpl* source,
int32_t pp_instance) {}
virtual void OnPepperStopsPlayback(RenderFrameHostImpl* source,
int32_t pp_instance) {}
#endif

protected:
virtual ~RenderFrameHostDelegate() = default;
};
Expand Down
64 changes: 64 additions & 0 deletions content/browser/renderer_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,42 @@ void VerifyThatBrowserAndRendererCalculatedOriginsToCommitMatch(

} // namespace

#if BUILDFLAG(ENABLE_PLUGINS)
class PepperPluginInstance : public mojom::PepperPluginInstanceHost {
public:
PepperPluginInstance(
int32_t instance_id,
RenderFrameHostImpl* frame_host,
mojo::PendingAssociatedRemote<mojom::PepperPluginInstance> instance,
mojo::PendingAssociatedReceiver<mojom::PepperPluginInstanceHost> host)
: instance_id_(instance_id),
frame_host_(frame_host),
receiver_(this, std::move(host)),
remote_(std::move(instance)) {
frame_host_->delegate()->OnPepperInstanceCreated(frame_host_, instance_id);
remote_.set_disconnect_handler(
base::BindOnce(&RenderFrameHostImpl::PepperInstanceClosed,
base::Unretained(frame_host), instance_id_));
}
~PepperPluginInstance() override = default;

// mojom::PepperPluginInstanceHost overrides.
void StartsPlayback() override {
frame_host_->delegate()->OnPepperStartsPlayback(frame_host_, instance_id_);
}

void StopsPlayback() override {
frame_host_->delegate()->OnPepperStopsPlayback(frame_host_, instance_id_);
}

private:
int32_t const instance_id_;
RenderFrameHostImpl* const frame_host_;
mojo::AssociatedReceiver<mojom::PepperPluginInstanceHost> receiver_;
mojo::AssociatedRemote<mojom::PepperPluginInstance> remote_;
};
#endif // BUILDFLAG(ENABLE_PLUGINS)

class RenderFrameHostImpl::DroppedInterfaceRequestLogger
: public blink::mojom::BrowserInterfaceBroker {
public:
Expand Down Expand Up @@ -6871,6 +6907,18 @@ void RenderFrameHostImpl::SetUpMojoIfNeeded() {
GetProcess()->GetStoragePartition()->GetFileSystemContext(),
ChromeBlobStorageContext::GetFor(GetProcess()->GetBrowserContext())));

#if BUILDFLAG(ENABLE_PLUGINS)
associated_registry_->AddInterface(base::BindRepeating(
[](RenderFrameHostImpl* impl,
mojo::PendingAssociatedReceiver<mojom::PepperHost> receiver) {
impl->pepper_host_receiver_.Bind(std::move(receiver));
impl->pepper_host_receiver_.SetFilter(
impl->CreateMessageFilterForAssociatedReceiver(
mojom::PepperHost::Name_));
},
base::Unretained(this)));
#endif

mojo::PendingRemote<mojom::FrameFactory> frame_factory;
GetProcess()->BindReceiver(frame_factory.InitWithNewPipeAndPassReceiver());
mojo::Remote<mojom::FrameFactory>(std::move(frame_factory))
Expand Down Expand Up @@ -10083,6 +10131,22 @@ void RenderFrameHostImpl::Clone(
cookie_observers_.Add(this, std::move(observer));
}

#if BUILDFLAG(ENABLE_PLUGINS)
void RenderFrameHostImpl::InstanceCreated(
int32_t instance_id,
mojo::PendingAssociatedRemote<mojom::PepperPluginInstance> instance,
mojo::PendingAssociatedReceiver<mojom::PepperPluginInstanceHost> host) {
pepper_instance_map_.emplace(
instance_id,
std::make_unique<PepperPluginInstance>(
instance_id, this, std::move(instance), std::move(host)));
}

void RenderFrameHostImpl::PepperInstanceClosed(int32_t instance_id) {
pepper_instance_map_.erase(instance_id);
}
#endif // BUILDFLAG(ENABLE_PLUGINS)

void RenderFrameHostImpl::OnCookiesAccessed(
network::mojom::CookieAccessDetailsPtr details) {
EmitSameSiteCookiesDeprecationWarning(this, details);
Expand Down
26 changes: 26 additions & 0 deletions content/browser/renderer_host/render_frame_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
#include "media/mojo/mojom/remoting.mojom-forward.h"
#endif

#if BUILDFLAG(ENABLE_PLUGINS)
#include "content/common/pepper_plugin.mojom.h"
#endif

class GURL;

namespace blink {
Expand Down Expand Up @@ -211,6 +215,7 @@ class KeepAliveHandleFactory;
class MediaInterfaceProxy;
class NavigationEntryImpl;
class NavigationRequest;
class PepperPluginInstance;
class PermissionServiceContext;
class Portal;
class PrefetchedSignedExchangeCache;
Expand Down Expand Up @@ -259,6 +264,9 @@ class CONTENT_EXPORT RenderFrameHostImpl
public network::CSPContext,
public blink::mojom::LocalMainFrameHost,
public ui::AXActionHandlerBase,
#if BUILDFLAG(ENABLE_PLUGINS)
public mojom::PepperHost,
#endif // BUILDFLAG(ENABLE_PLUGINS)
public network::mojom::CookieAccessObserver {
public:
using AXTreeSnapshotCallback =
Expand Down Expand Up @@ -1863,6 +1871,10 @@ class CONTENT_EXPORT RenderFrameHostImpl
return accessibility_fatal_error_count_;
}

#if BUILDFLAG(ENABLE_PLUGINS)
void PepperInstanceClosed(int32_t instance_id);
#endif

protected:
friend class RenderFrameHostFactory;

Expand Down Expand Up @@ -2140,6 +2152,15 @@ class CONTENT_EXPORT RenderFrameHostImpl
void Clone(mojo::PendingReceiver<network::mojom::CookieAccessObserver>
observer) override;

#if BUILDFLAG(ENABLE_PLUGINS)
// mojom::PepperHost overrides:
void InstanceCreated(
int32_t instance_id,
mojo::PendingAssociatedRemote<mojom::PepperPluginInstance> instance,
mojo::PendingAssociatedReceiver<mojom::PepperPluginInstanceHost> host)
override;
#endif // BUILDFLAG(ENABLE_PLUGINS)

// Resets any waiting state of this RenderFrameHost that is no longer
// relevant.
void ResetWaitingState();
Expand Down Expand Up @@ -3030,6 +3051,11 @@ class CONTENT_EXPORT RenderFrameHostImpl
mojo::AssociatedReceiver<mojom::DomAutomationControllerHost>
dom_automation_controller_receiver_{this};

#if BUILDFLAG(ENABLE_PLUGINS)
mojo::AssociatedReceiver<mojom::PepperHost> pepper_host_receiver_{this};
std::map<int32_t, std::unique_ptr<PepperPluginInstance>> pepper_instance_map_;
#endif

std::unique_ptr<KeepAliveHandleFactory> keep_alive_handle_factory_;
base::TimeDelta keep_alive_timeout_;

Expand Down
6 changes: 0 additions & 6 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,15 +1148,9 @@ bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
bool handled = true;
#if BUILDFLAG(ENABLE_PLUGINS)
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
OnPepperInstanceCreated)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
OnPepperInstanceDeleted)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
OnPepperStartsPlayback)
IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
OnPepperStopsPlayback)
IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
Expand Down
12 changes: 8 additions & 4 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
std::vector<RenderFrameHostImpl*>
GetActiveTopLevelDocumentsInBrowsingContextGroup(
RenderFrameHostImpl* render_frame_host) override;
#if BUILDFLAG(ENABLE_PLUGINS)
void OnPepperInstanceCreated(RenderFrameHostImpl* source,
int32_t pp_instance) override;
void OnPepperStartsPlayback(RenderFrameHostImpl* source,
int32_t pp_instance) override;
void OnPepperStopsPlayback(RenderFrameHostImpl* source,
int32_t pp_instance) override;
#endif

// RenderViewHostDelegate ----------------------------------------------------
RenderViewHostDelegateView* GetDelegateView() override;
Expand Down Expand Up @@ -1500,16 +1508,12 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
int minimum_percent,
int maximum_percent);
#if BUILDFLAG(ENABLE_PLUGINS)
void OnPepperInstanceCreated(RenderFrameHostImpl* source,
int32_t pp_instance);
void OnPepperInstanceDeleted(RenderFrameHostImpl* source,
int32_t pp_instance);
void OnPepperPluginHung(RenderFrameHostImpl* source,
int plugin_child_id,
const base::FilePath& path,
bool is_hung);
void OnPepperStartsPlayback(RenderFrameHostImpl* source, int32_t pp_instance);
void OnPepperStopsPlayback(RenderFrameHostImpl* source, int32_t pp_instance);
void OnPluginCrashed(RenderFrameHostImpl* source,
const base::FilePath& plugin_path,
base::ProcessId plugin_pid);
Expand Down
4 changes: 4 additions & 0 deletions content/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ mojom("mojo_bindings") {
enabled_features += [ "clang_profiling_inside_sandbox" ]
}

if (enable_plugins) {
sources += [ "pepper_plugin.mojom" ]
}

cpp_typemaps = [
{
types = [
Expand Down
15 changes: 0 additions & 15 deletions content/common/frame_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ IPC_MESSAGE_ROUTED2(FrameMsg_SetPepperVolume,
// Messages sent from the renderer to the browser.

#if BUILDFLAG(ENABLE_PLUGINS)
// Notification sent from a renderer to the browser that a Pepper plugin
// instance is created in the DOM.
IPC_MESSAGE_ROUTED1(FrameHostMsg_PepperInstanceCreated,
int32_t /* pp_instance */)

// Notification sent from a renderer to the browser that a Pepper plugin
// instance is deleted from the DOM.
IPC_MESSAGE_ROUTED1(FrameHostMsg_PepperInstanceDeleted,
Expand All @@ -286,16 +281,6 @@ IPC_MESSAGE_ROUTED2(FrameHostMsg_PluginCrashed,
base::FilePath /* plugin_path */,
base::ProcessId /* plugin_pid */)

// Notification sent from a renderer to the browser that a Pepper plugin
// instance has started playback.
IPC_MESSAGE_ROUTED1(FrameHostMsg_PepperStartsPlayback,
int32_t /* pp_instance */)

// Notification sent from a renderer to the browser that a Pepper plugin
// instance has stopped playback.
IPC_MESSAGE_ROUTED1(FrameHostMsg_PepperStopsPlayback,
int32_t /* pp_instance */)

// Return information about a plugin for the given URL and MIME
// type. If there is no matching plugin, |found| is false.
// |actual_mime_type| is the actual mime type supported by the
Expand Down
26 changes: 26 additions & 0 deletions content/common/pepper_plugin.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020 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.

module content.mojom;

// Generic Pepper messages. Implemented by the browser.
interface PepperHost {
// Notification that a Pepper plugin instance is created in the DOM.
InstanceCreated(int32 instance_id,
pending_associated_remote<PepperPluginInstance> instance,
pending_associated_receiver<PepperPluginInstanceHost> host);
};

// Plugin instance specific messages. Implemented by the browser.
interface PepperPluginInstanceHost {
// Notification a plugin instance has started playback.
StartsPlayback();

// Notification a plugin instance has stopped playback.
StopsPlayback();
};

// Plugin instance specific messages. Implemented by the renderer.
interface PepperPluginInstance {
};
14 changes: 8 additions & 6 deletions content/renderer/pepper/pepper_audio_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,20 @@ void PepperAudioController::OnPepperInstanceDeleted() {
void PepperAudioController::NotifyPlaybackStopsOnEmpty() {
DCHECK(instance_);

RenderFrameImpl* render_frame = instance_->render_frame();
if (render_frame)
render_frame->PepperStopsPlayback(instance_);
mojom::PepperPluginInstanceHost* instance_host =
instance_->GetPepperPluginInstanceHost();
if (instance_host)
instance_host->StopsPlayback();
}

void PepperAudioController::StartPlaybackIfFirstInstance() {
DCHECK(instance_);

if (audio_output_hosts_.empty() && ppb_audios_.empty()) {
RenderFrameImpl* render_frame = instance_->render_frame();
if (render_frame)
render_frame->PepperStartsPlayback(instance_);
mojom::PepperPluginInstanceHost* instance_host =
instance_->GetPepperPluginInstanceHost();
if (instance_host)
instance_host->StartsPlayback();
}
}

Expand Down
4 changes: 3 additions & 1 deletion content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl(
module_->InstanceCreated(this);

if (render_frame_) { // NULL in tests or if the frame has been destroyed.
render_frame_->PepperInstanceCreated(this);
render_frame_->PepperInstanceCreated(
this, pepper_receiver_.BindNewEndpointAndPassRemote(),
pepper_host_remote_.BindNewEndpointAndPassReceiver());
view_data_.is_page_visible =
!render_frame_->GetLocalRootWebFrameWidget()->IsHidden();

Expand Down
17 changes: 16 additions & 1 deletion content/renderer/pepper/pepper_plugin_instance_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
#include "cc/paint/paint_canvas.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "content/common/content_export.h"
#include "content/common/pepper_plugin.mojom.h"
#include "content/public/renderer/pepper_plugin_instance.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "gin/handle.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/dev/ppp_text_input_dev.h"
Expand Down Expand Up @@ -119,7 +122,8 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
public PepperPluginInstance,
public ppapi::PPB_Instance_Shared,
public cc::TextureLayerClient,
public RenderFrameObserver {
public RenderFrameObserver,
public mojom::PepperPluginInstance {
public:
// Create and return a PepperPluginInstanceImpl object which supports the most
// recent version of PPP_Instance possible by querying the given
Expand All @@ -135,9 +139,17 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
// Currently only used in tests.
static PepperPluginInstanceImpl* GetForTesting(PP_Instance instance_id);

// Returns the associated RenderFrameImpl. Can be null (in tests) or if the
// frame has been destroyed.
RenderFrameImpl* render_frame() const { return render_frame_; }
PluginModule* module() const { return module_.get(); }

// Returns the associated mojo host channel to the browser. Can be null if
// `render_frame()` returns null.
mojom::PepperPluginInstanceHost* GetPepperPluginInstanceHost() {
return pepper_host_remote_.get();
}

blink::WebPluginContainer* container() const { return container_; }

// Returns the PP_Instance uniquely identifying this instance. Guaranteed
Expand Down Expand Up @@ -844,6 +856,9 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
// progress.
base::string16 composition_text_;

mojo::AssociatedRemote<mojom::PepperPluginInstanceHost> pepper_host_remote_;
mojo::AssociatedReceiver<mojom::PepperPluginInstance> pepper_receiver_{this};

// We use a weak ptr factory for scheduling DidChangeView events so that we
// can tell whether updates are pending and consolidate them. When there's
// already a weak ptr pending (HasWeakPtrs is true), code should update the
Expand Down
Loading

0 comments on commit 3da5569

Please sign in to comment.