Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: content/browser/renderer_host/media/midi_dispatcher_host.cc

Issue 38043004: Cancel MIDI permission request infobar on MIDIAccess stop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/child_process_security_policy_impl.h" 8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/common/media/midi_messages.h" 10 #include "content/common/media/midi_messages.h"
11 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 MIDIDispatcherHost::MIDIDispatcherHost(int render_process_id, 17 MIDIDispatcherHost::MIDIDispatcherHost(
18 BrowserContext* browser_context) 18 int render_process_id,
19 MidiPermissionContext* midi_permission_context_)
19 : render_process_id_(render_process_id), 20 : render_process_id_(render_process_id),
20 browser_context_(browser_context) { 21 midi_permission_context_(midi_permission_context_) {
21 } 22 }
22 23
23 MIDIDispatcherHost::~MIDIDispatcherHost() { 24 MIDIDispatcherHost::~MIDIDispatcherHost() {
24 } 25 }
25 26
26 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message& message, 27 bool MIDIDispatcherHost::OnMessageReceived(const IPC::Message& message,
27 bool* message_was_ok) { 28 bool* message_was_ok) {
28 bool handled = true; 29 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost, message, *message_was_ok) 30 IPC_BEGIN_MESSAGE_MAP_EX(MIDIDispatcherHost, message, *message_was_ok)
30 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission, 31 IPC_MESSAGE_HANDLER(MIDIHostMsg_RequestSysExPermission,
31 OnRequestSysExPermission) 32 OnRequestSysExPermission)
33 IPC_MESSAGE_HANDLER(MIDIHostMsg_CancelSysExPermissionRequest,
34 OnCancelSysExPermissionRequest)
32 IPC_MESSAGE_UNHANDLED(handled = false) 35 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP_EX() 36 IPC_END_MESSAGE_MAP_EX()
34 return handled; 37 return handled;
35 } 38 }
36 39
37 void MIDIDispatcherHost::OverrideThreadForMessage( 40 void MIDIDispatcherHost::OverrideThreadForMessage(
38 const IPC::Message& message, BrowserThread::ID* thread) { 41 const IPC::Message& message, BrowserThread::ID* thread) {
39 if (message.type() == MIDIHostMsg_RequestSysExPermission::ID) 42 if (message.type() == MIDIHostMsg_RequestSysExPermission::ID)
jam 2013/10/24 16:15:26 if (IPC_MESSAGE_CLASS(msg) == MIDIMsgStart) *thr
Kibeom Kim (inactive) 2013/10/24 19:36:26 Done.
40 *thread = BrowserThread::UI; 43 *thread = BrowserThread::UI;
41 } 44 }
42 45
43 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id, 46 void MIDIDispatcherHost::OnRequestSysExPermission(int render_view_id,
44 int client_id, 47 int bridge_id,
45 const GURL& origin) { 48 const GURL& origin) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47 50
48 browser_context_->RequestMIDISysExPermission( 51 if (midi_permission_context_.get()) {
49 render_process_id_, 52 midi_permission_context_->RequestMIDISysExPermission(
50 render_view_id, 53 render_process_id_,
51 origin, 54 render_view_id,
52 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted, 55 bridge_id,
53 base::Unretained(this), 56 origin,
54 render_view_id, 57 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted,
55 client_id)); 58 base::Unretained(this),
59 render_view_id,
60 bridge_id));
61 } else {
62 BrowserThread::PostTask(
63 BrowserThread::UI,
64 FROM_HERE,
65 base::Bind(&MIDIDispatcherHost::WasSysExPermissionGranted,
66 base::Unretained(this),
67 render_view_id,
68 bridge_id,
69 true));
70 }
71 }
72
73 void MIDIDispatcherHost::OnCancelSysExPermissionRequest(
74 int render_view_id,
75 int bridge_id,
76 const GURL& requesting_frame) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" << render_view_id
79 << ":" << bridge_id;
80 if (midi_permission_context_.get()) {
81 midi_permission_context_->CancelMIDISysExPermissionRequest(
82 render_process_id_, render_view_id, bridge_id, requesting_frame);
83 }
56 } 84 }
57 85
58 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id, 86 void MIDIDispatcherHost::WasSysExPermissionGranted(int render_view_id,
59 int client_id, 87 int bridge_id,
60 bool success) { 88 bool success) {
61 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMIDISysExMessage( 89 ChildProcessSecurityPolicyImpl::GetInstance()->GrantSendMIDISysExMessage(
62 render_process_id_); 90 render_process_id_);
63 Send(new MIDIMsg_SysExPermissionApproved(render_view_id, client_id, success)); 91 Send(new MIDIMsg_SysExPermissionApproved(render_view_id, bridge_id, success));
64 } 92 }
65 93
66 } // namespace content 94 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698