1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/media/midi_dispatcher_host.h"
8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/common/media/midi_messages.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
17 MidiDispatcherHost::MidiDispatcherHost(int render_process_id
,
18 BrowserContext
* browser_context
)
19 : BrowserMessageFilter(MidiMsgStart
),
20 render_process_id_(render_process_id
),
21 browser_context_(browser_context
) {
24 MidiDispatcherHost::~MidiDispatcherHost() {
27 bool MidiDispatcherHost::OnMessageReceived(const IPC::Message
& message
,
28 bool* message_was_ok
) {
30 IPC_BEGIN_MESSAGE_MAP_EX(MidiDispatcherHost
, message
, *message_was_ok
)
31 IPC_MESSAGE_HANDLER(MidiHostMsg_RequestSysExPermission
,
32 OnRequestSysExPermission
)
33 IPC_MESSAGE_HANDLER(MidiHostMsg_CancelSysExPermissionRequest
,
34 OnCancelSysExPermissionRequest
)
35 IPC_MESSAGE_UNHANDLED(handled
= false)
36 IPC_END_MESSAGE_MAP_EX()
40 void MidiDispatcherHost::OverrideThreadForMessage(
41 const IPC::Message
& message
, BrowserThread::ID
* thread
) {
42 if (IPC_MESSAGE_CLASS(message
) == MidiMsgStart
)
43 *thread
= BrowserThread::UI
;
46 void MidiDispatcherHost::OnRequestSysExPermission(int render_view_id
,
50 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
52 browser_context_
->RequestMidiSysExPermission(
58 base::Bind(&MidiDispatcherHost::WasSysExPermissionGranted
,
59 base::Unretained(this),
64 void MidiDispatcherHost::OnCancelSysExPermissionRequest(
67 const GURL
& requesting_frame
) {
68 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
69 DVLOG(1) << __FUNCTION__
<< " " << render_process_id_
<< ":" << render_view_id
71 browser_context_
->CancelMidiSysExPermissionRequest(
72 render_process_id_
, render_view_id
, bridge_id
, requesting_frame
);
74 void MidiDispatcherHost::WasSysExPermissionGranted(int render_view_id
,
77 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMidiSysExMessage(
79 Send(new MidiMsg_SysExPermissionApproved(render_view_id
, bridge_id
, success
));
82 } // namespace content