OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/common/media/midi_messages.h" | 9 #include "content/common/media/midi_messages.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
11 #include "content/public/browser/browser_thread.h" | |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 MIDIDispatcherHost::MIDIDispatcherHost(int render_process_id, | 16 MIDIDispatcherHost::MIDIDispatcherHost(int render_process_id, |
16 BrowserContext* browser_context) | 17 BrowserContext* browser_context) |
17 : render_process_id_(render_process_id), | 18 : render_process_id_(render_process_id), |
18 browser_context_(browser_context) { | 19 browser_context_(browser_context) { |
19 } | 20 } |
20 | 21 |
21 MIDIDispatcherHost::~MIDIDispatcherHost() { | 22 MIDIDispatcherHost::~MIDIDispatcherHost() { |
22 } | 23 } |
23 | 24 |
24 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message& message, | 25 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message& message, |
25 bool* message_was_ok) { | 26 bool* message_was_ok) { |
26 bool handled = true; | 27 bool handled = true; |
27 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost, message, *message_was_ok) | 28 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost, message, *message_was_ok) |
28 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission, | 29 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission, |
29 OnRequestSysExPermission) | 30 OnRequestSysExPermission) |
30 IPC_MESSAGE_UNHANDLED(handled = false) | 31 IPC_MESSAGE_UNHANDLED(handled = false) |
31 IPC_END_MESSAGE_MAP_EX() | 32 IPC_END_MESSAGE_MAP_EX() |
32 return handled; | 33 return handled; |
33 } | 34 } |
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 | |
35 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id, | 42 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id, |
36 int client_id, | 43 int client_id, |
37 const GURL& origin) { | 44 const GURL& origin) { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
46 | |
38 browser_context_->RequestMIDISysExPermission( | 47 browser_context_->RequestMIDISysExPermission( |
39 render_process_id_, | 48 render_process_id_, |
40 render_view_id, | 49 render_view_id, |
41 origin, | 50 origin, |
42 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted, | 51 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted, |
43 base::Unretained(this), | 52 base::Unretained(this), |
44 render_view_id, | 53 render_view_id, |
45 client_id)); | 54 client_id)); |
46 } | 55 } |
47 | 56 |
48 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id, | 57 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id, |
49 int client_id, | 58 int client_id, |
50 bool success) { | 59 bool success) { |
51 RenderViewHostImpl* r = | 60 RenderViewHostImpl* r = |
52 RenderViewHostImpl::FromID(render_process_id_, render_view_id); | 61 RenderViewHostImpl::FromID(render_process_id_, render_view_id); |
Bernhard Bauer
2013/08/01 15:28:41
I don't think getting the RenderViewHostImpl is ne
Takashi Toyoshima
2013/08/01 15:36:26
I did like this because the message couldn't be ro
Bernhard Bauer
2013/08/01 22:24:33
As in, to the right render process? I thought this
| |
53 if (!r) | 62 if (!r) |
54 return; | 63 return; |
55 r->Send( | 64 r->Send( |
56 new MIDIMsg_SysExPermissionApproved(render_view_id, client_id, success)); | 65 new MIDIMsg_SysExPermissionApproved(render_view_id, client_id, success)); |
57 } | 66 } |
58 | 67 |
59 } // namespace content | 68 } // namespace content |
OLD | NEW |