Commit a445d5da authored by Johann's avatar Johann Committed by Commit Bot

Migrate MidiSession interface from Process to Frame

If mojo interfaces are bound to a RenderProcessHost then the interface
cannot be frozen for a specific Frame. This is problematic for
prerendering. Bind them to a RenderFrameHost (via PopulateFrameBinders)
instead.

BUG=chromium:1126758

Change-Id: I8c6683b45737a8276cb28391532b0e6a036386d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2400554
Commit-Queue: Johann Koenig <johannkoenig@google.com>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806896}
parent e23f04c9
......@@ -25,6 +25,7 @@
#include "content/browser/image_capture/image_capture_impl.h"
#include "content/browser/keyboard_lock/keyboard_lock_service_impl.h"
#include "content/browser/loader/content_security_notifier.h"
#include "content/browser/media/midi_host.h"
#include "content/browser/media/session/media_session_service_impl.h"
#include "content/browser/picture_in_picture/picture_in_picture_service_impl.h"
#include "content/browser/process_internals/process_internals.mojom.h"
......@@ -543,6 +544,15 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, mojo::BinderMap* map) {
base::Unretained(host)));
}
// BrowserMainLoop::GetInstance() may be null on unit tests.
if (BrowserMainLoop::GetInstance()) {
map->Add<midi::mojom::MidiSessionProvider>(
base::BindRepeating(&MidiHost::BindReceiver,
host->GetProcess()->GetID(),
BrowserMainLoop::GetInstance()->midi_service()),
GetIOThreadTaskRunner({}));
}
map->Add<blink::mojom::NotificationService>(base::BindRepeating(
&RenderFrameHostImpl::CreateNotificationService, base::Unretained(host)));
......
......@@ -128,6 +128,8 @@ void MidiHost::ReceiveMidiData(uint32_t port,
// SendData() does.
if (message[0] == kSysExByte) {
if (!has_sys_ex_permission_) {
// TODO(987505): This should check permission with the Frame and not the
// Process.
has_sys_ex_permission_ =
ChildProcessSecurityPolicyImpl::GetInstance()
->CanSendMidiSysExMessage(renderer_process_id_);
......
......@@ -102,7 +102,6 @@
#include "content/browser/locks/lock_manager.h"
#include "content/browser/media/capture/audio_mirroring_manager.h"
#include "content/browser/media/media_internals.h"
#include "content/browser/media/midi_host.h"
#include "content/browser/mime_registry_impl.h"
#include "content/browser/native_file_system/native_file_system_manager_impl.h"
#include "content/browser/native_io/native_io_context.h"
......@@ -2415,10 +2414,6 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::BindRepeating(&FileSystemManagerImpl::BindReceiver,
base::Unretained(file_system_manager_impl_.get())));
registry->AddInterface(base::BindRepeating(
&MidiHost::BindReceiver, GetID(),
base::Unretained(BrowserMainLoop::GetInstance()->midi_service())));
if (gpu_client_) {
// |gpu_client_| outlives the registry, because its destruction is posted to
// IO thread from the destructor of |this|.
......
......@@ -140,7 +140,8 @@ void MIDIAccessInitializer::StartSession() {
// See https://bit.ly/2S0zRAS for task types.
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI);
dispatcher_ = std::make_unique<MIDIDispatcher>(task_runner);
dispatcher_ =
std::make_unique<MIDIDispatcher>(task_runner, GetExecutionContext());
dispatcher_->SetClient(this);
}
......
......@@ -7,9 +7,11 @@
#include <utility>
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
......@@ -24,10 +26,13 @@ static const size_t kMaxUnacknowledgedBytesSent = 10 * 1024 * 1024; // 10 MB.
} // namespace
MIDIDispatcher::MIDIDispatcher(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
ExecutionContext* execution_context)
// TODO(1049056): Now that this has ExecutionContext, generate task_runner
// here.
: task_runner_(std::move(task_runner)) {
TRACE_EVENT0("midi", "MIDIDispatcher::MIDIDispatcher");
Platform::Current()->GetBrowserInterfaceBroker()->GetInterface(
execution_context->GetBrowserInterfaceBroker().GetInterface(
midi_session_provider_.BindNewPipeAndPassReceiver(task_runner_));
midi_session_provider_->StartSession(
midi_session_.BindNewPipeAndPassReceiver(),
......
......@@ -8,6 +8,7 @@
#include "media/midi/midi_service.mojom-blink.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
......@@ -40,7 +41,8 @@ class MIDIDispatcher : public midi::mojom::blink::MidiSessionClient {
};
explicit MIDIDispatcher(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
ExecutionContext* execution_context);
~MIDIDispatcher() override;
void SetClient(Client* client) { client_ = client; }
......@@ -76,6 +78,8 @@ class MIDIDispatcher : public midi::mojom::blink::MidiSessionClient {
// TODO(toyoshim): Consider to have a per-process limit.
size_t unacknowledged_bytes_sent_ = 0u;
// TODO(1049056): Now that MidiSession is passed an ExecutionContext use it to
// convert these to HeapMojo.
mojo::Remote<midi::mojom::blink::MidiSession> midi_session_;
mojo::Receiver<midi::mojom::blink::MidiSessionClient> receiver_{this};
......
......@@ -9,7 +9,7 @@ class MockMIDIService {
this.start_session_result_ = midi.mojom.Result.OK;
this.interceptor_ = new MojoInterfaceInterceptor(
midi.mojom.MidiSessionProvider.name, 'process');
midi.mojom.MidiSessionProvider.name);
this.binding_ = new mojo.Binding(midi.mojom.MidiSessionProvider, this);
this.session_binding_ = new mojo.Binding(midi.mojom.MidiSession, this);
this.interceptor_.oninterfacerequest = e => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment