IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / media / midi_dispatcher_host.cc
blob2181dccdd7211358a705eeafc1b7bc04c6ef797a
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 : 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) {
28 bool handled = true;
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()
36 return handled;
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,
46 int bridge_id,
47 const GURL& origin) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 browser_context_->RequestMIDISysExPermission(
51 render_process_id_,
52 render_view_id,
53 bridge_id,
54 origin,
55 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted,
56 base::Unretained(this),
57 render_view_id,
58 bridge_id));
61 void MIDIDispatcherHost::OnCancelSysExPermissionRequest(
62 int render_view_id,
63 int bridge_id,
64 const GURL& requesting_frame) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id
67 << ":" << bridge_id;
68 browser_context_->CancelMIDISysExPermissionRequest(
69 render_process_id_, render_view_id, bridge_id, requesting_frame);
71 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id,
72 int bridge_id,
73 bool success) {
74 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMIDISysExMessage(
75 render_process_id_);
76 Send(new MIDIMsg_SysExPermissionApproved(render_view_id, bridge_id, success));
79 } // namespace content