This source file includes following definitions.
- OnMessageReceived
- requestSysexPermission
- cancelSysexPermissionRequest
- OnSysExPermissionApproved
#include "content/renderer/media/midi_dispatcher.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "content/common/media/midi_messages.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/web/WebMIDIPermissionRequest.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
using blink::WebMIDIPermissionRequest;
using blink::WebSecurityOrigin;
namespace content {
MidiDispatcher::MidiDispatcher(RenderViewImpl* render_view)
: RenderViewObserver(render_view) {
}
MidiDispatcher::~MidiDispatcher() {}
bool MidiDispatcher::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(MidiDispatcher, message)
IPC_MESSAGE_HANDLER(MidiMsg_SysExPermissionApproved,
OnSysExPermissionApproved)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void MidiDispatcher::requestSysexPermission(
const WebMIDIPermissionRequest& request) {
int bridge_id = requests_.Add(new WebMIDIPermissionRequest(request));
WebSecurityOrigin security_origin = request.securityOrigin();
GURL url(security_origin.toString());
Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url,
blink::WebUserGestureIndicator::isProcessingUserGesture()));
}
void MidiDispatcher::cancelSysexPermissionRequest(
const WebMIDIPermissionRequest& request) {
for (IDMap<WebMIDIPermissionRequest>::iterator it(&requests_);
!it.IsAtEnd();
it.Advance()) {
WebMIDIPermissionRequest* value = it.GetCurrentValue();
if (value->equals(request)) {
base::string16 origin = request.securityOrigin().toString();
Send(new MidiHostMsg_CancelSysExPermissionRequest(
routing_id(), it.GetCurrentKey(), GURL(origin)));
requests_.Remove(it.GetCurrentKey());
break;
}
}
}
void MidiDispatcher::OnSysExPermissionApproved(int bridge_id,
bool is_allowed) {
WebMIDIPermissionRequest* request = requests_.Lookup(bridge_id);
if (!request)
return;
request->setIsAllowed(is_allowed);
requests_.Remove(bridge_id);
}
}