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. 4 5 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" 6 7 #include "base/bind.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/common/media/midi_messages.h" 10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_thread.h" 12 #include "url/gurl.h" 13 14 namespace content { 15 16 MIDIDispatcherHost::MIDIDispatcherHost(int render_process_id, 17 BrowserContext* browser_context) 18 : render_process_id_(render_process_id), 19 browser_context_(browser_context) { 20 } 21 22 MIDIDispatcherHost::~MIDIDispatcherHost() { 23 } 24 25 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message& message, 26 bool* message_was_ok) { 27 bool handled = true; 28 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost, message, *message_was_ok) 29 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission, 30 OnRequestSysExPermission) 31 IPC_MESSAGE_UNHANDLED(handled = false) 32 IPC_END_MESSAGE_MAP_EX() 33 return handled; 34 } 35 36 void MIDIDispatcherHost::OverrideThreadForMessage( 37 const IPC::Message& message, BrowserThread::ID* thread) { 38 if (message.type() == MIDIHostMsg_RequestSysExPermission::ID) 39 *thread = BrowserThread::UI; 40 } 41 42 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id, 43 int client_id, 44 const GURL& origin) { 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 46 47 browser_context_->RequestMIDISysExPermission( 48 render_process_id_, 49 render_view_id, 50 origin, 51 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted, 52 base::Unretained(this), 53 render_view_id, 54 client_id)); 55 } 56 57 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id, 58 int client_id, 59 bool success) { 60 Send(new MIDIMsg_SysExPermissionApproved(render_view_id, client_id, success)); 61 } 62 63 } // namespace content 64