Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / media / midi_dispatcher_host.cc
blob2863e11ee591126f3551e8224185ad1f69311fae
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"
7 #include "base/bind.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"
13 #include "url/gurl.h"
15 namespace content {
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) {
29 bool handled = true;
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()
37 return handled;
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,
47 int bridge_id,
48 const GURL& origin,
49 bool user_gesture) {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
52 browser_context_->RequestMidiSysExPermission(
53 render_process_id_,
54 render_view_id,
55 bridge_id,
56 origin,
57 user_gesture,
58 base::Bind(&MidiDispatcherHost::WasSysExPermissionGranted,
59 base::Unretained(this),
60 render_view_id,
61 bridge_id));
64 void MidiDispatcherHost::OnCancelSysExPermissionRequest(
65 int render_view_id,
66 int bridge_id,
67 const GURL& requesting_frame) {
68 DCHECK_CURRENTLY_ON(BrowserThread::UI);
69 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id
70 << ":" << bridge_id;
71 browser_context_->CancelMidiSysExPermissionRequest(
72 render_process_id_, render_view_id, bridge_id, requesting_frame);
74 void MidiDispatcherHost::WasSysExPermissionGranted(int render_view_id,
75 int bridge_id,
76 bool success) {
77 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMidiSysExMessage(
78 render_process_id_);
79 Send(new MidiMsg_SysExPermissionApproved(render_view_id, bridge_id, success));
82 } // namespace content