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 : render_process_id_(render_process_id
),
20 browser_context_(browser_context
) {
23 MIDIDispatcherHost::~MIDIDispatcherHost() {
26 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message
& message
,
27 bool* message_was_ok
) {
29 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost
, message
, *message_was_ok
)
30 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission
,
31 OnRequestSysExPermission
)
32 IPC_MESSAGE_HANDLER(MIDIHostMsg_CancelSysExPermissionRequest
,
33 OnCancelSysExPermissionRequest
)
34 IPC_MESSAGE_UNHANDLED(handled
= false)
35 IPC_END_MESSAGE_MAP_EX()
39 void MIDIDispatcherHost::OverrideThreadForMessage(
40 const IPC::Message
& message
, BrowserThread::ID
* thread
) {
41 if (IPC_MESSAGE_CLASS(message
) == MIDIMsgStart
)
42 *thread
= BrowserThread::UI
;
45 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id
,
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
50 browser_context_
->RequestMIDISysExPermission(
55 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted
,
56 base::Unretained(this),
61 void MIDIDispatcherHost::OnCancelSysExPermissionRequest(
64 const GURL
& requesting_frame
) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
66 DVLOG(1) << __FUNCTION__
<< " " << render_process_id_
<< ":" << render_view_id
68 browser_context_
->CancelMIDISysExPermissionRequest(
69 render_process_id_
, render_view_id
, bridge_id
, requesting_frame
);
71 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id
,
74 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMIDISysExMessage(
76 Send(new MIDIMsg_SysExPermissionApproved(render_view_id
, bridge_id
, success
));
79 } // namespace content