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/renderer/media/midi_dispatcher.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/common/media/midi_messages.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebMIDIPermissionRequest.h"
12 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
13 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
15 using blink::WebMIDIPermissionRequest
;
16 using blink::WebSecurityOrigin
;
20 MidiDispatcher::MidiDispatcher(RenderFrame
* render_frame
)
21 : RenderFrameObserver(render_frame
) {
24 MidiDispatcher::~MidiDispatcher() {}
26 bool MidiDispatcher::OnMessageReceived(const IPC::Message
& message
) {
28 IPC_BEGIN_MESSAGE_MAP(MidiDispatcher
, message
)
29 IPC_MESSAGE_HANDLER(MidiMsg_SysExPermissionApproved
,
30 OnSysExPermissionApproved
)
31 IPC_MESSAGE_UNHANDLED(handled
= false)
36 void MidiDispatcher::requestSysexPermission(
37 const WebMIDIPermissionRequest
& request
) {
38 int bridge_id
= requests_
.Add(new WebMIDIPermissionRequest(request
));
39 WebSecurityOrigin security_origin
= request
.securityOrigin();
40 GURL
url(security_origin
.toString());
41 Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id
, url
,
42 blink::WebUserGestureIndicator::isProcessingUserGesture()));
45 void MidiDispatcher::cancelSysexPermissionRequest(
46 const WebMIDIPermissionRequest
& request
) {
47 for (Requests::iterator
it(&requests_
); !it
.IsAtEnd(); it
.Advance()) {
48 WebMIDIPermissionRequest
* value
= it
.GetCurrentValue();
49 if (value
->equals(request
)) {
50 base::string16 origin
= request
.securityOrigin().toString();
51 Send(new MidiHostMsg_CancelSysExPermissionRequest(
52 routing_id(), it
.GetCurrentKey(), GURL(origin
)));
53 // The request will be removed by OnSysExPermissionApproved once
54 // the blink MIDIAccessInitializer object is deleted.
60 void MidiDispatcher::OnSysExPermissionApproved(int bridge_id
,
62 // |request| can be NULL when the request is canceled.
63 WebMIDIPermissionRequest
* request
= requests_
.Lookup(bridge_id
);
66 request
->setIsAllowed(is_allowed
);
67 requests_
.Remove(bridge_id
);
70 } // namespace content