| 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/renderer/media/midi_dispatcher.h" | 5 #include "content/renderer/media/midi_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/common/media/midi_messages.h" | 9 #include "content/common/media/midi_messages.h" |
| 10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| 11 #include "third_party/WebKit/public/web/WebMIDIPermissionRequest.h" | 11 #include "third_party/WebKit/public/web/WebMIDIPermissionRequest.h" |
| 12 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 12 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 13 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 13 | 14 |
| 14 using blink::WebMIDIPermissionRequest; | 15 using blink::WebMIDIPermissionRequest; |
| 15 using blink::WebSecurityOrigin; | 16 using blink::WebSecurityOrigin; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 MidiDispatcher::MidiDispatcher(RenderViewImpl* render_view) | 20 MidiDispatcher::MidiDispatcher(RenderViewImpl* render_view) |
| 20 : RenderViewObserver(render_view) { | 21 : RenderViewObserver(render_view) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 MidiDispatcher::~MidiDispatcher() {} | 24 MidiDispatcher::~MidiDispatcher() {} |
| 24 | 25 |
| 25 bool MidiDispatcher::OnMessageReceived(const IPC::Message& message) { | 26 bool MidiDispatcher::OnMessageReceived(const IPC::Message& message) { |
| 26 bool handled = true; | 27 bool handled = true; |
| 27 IPC_BEGIN_MESSAGE_MAP(MidiDispatcher, message) | 28 IPC_BEGIN_MESSAGE_MAP(MidiDispatcher, message) |
| 28 IPC_MESSAGE_HANDLER(MidiMsg_SysExPermissionApproved, | 29 IPC_MESSAGE_HANDLER(MidiMsg_SysExPermissionApproved, |
| 29 OnSysExPermissionApproved) | 30 OnSysExPermissionApproved) |
| 30 IPC_MESSAGE_UNHANDLED(handled = false) | 31 IPC_MESSAGE_UNHANDLED(handled = false) |
| 31 IPC_END_MESSAGE_MAP() | 32 IPC_END_MESSAGE_MAP() |
| 32 return handled; | 33 return handled; |
| 33 } | 34 } |
| 34 | 35 |
| 35 void MidiDispatcher::requestSysexPermission( | 36 void MidiDispatcher::requestSysexPermission( |
| 36 const WebMIDIPermissionRequest& request) { | 37 const WebMIDIPermissionRequest& request) { |
| 37 int bridge_id = requests_.Add(new WebMIDIPermissionRequest(request)); | 38 int bridge_id = requests_.Add(new WebMIDIPermissionRequest(request)); |
| 38 WebSecurityOrigin security_origin = request.securityOrigin(); | 39 WebSecurityOrigin security_origin = request.securityOrigin(); |
| 39 std::string origin = security_origin.toString().utf8(); | 40 std::string origin = security_origin.toString().utf8(); |
| 40 GURL url(origin); | 41 GURL url(origin); |
| 41 Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url)); | 42 Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url, |
| 43 blink::WebUserGestureIndicator::isProcessingUserGesture())); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void MidiDispatcher::cancelSysexPermissionRequest( | 46 void MidiDispatcher::cancelSysexPermissionRequest( |
| 45 const WebMIDIPermissionRequest& request) { | 47 const WebMIDIPermissionRequest& request) { |
| 46 for (IDMap<WebMIDIPermissionRequest>::iterator it(&requests_); | 48 for (IDMap<WebMIDIPermissionRequest>::iterator it(&requests_); |
| 47 !it.IsAtEnd(); | 49 !it.IsAtEnd(); |
| 48 it.Advance()) { | 50 it.Advance()) { |
| 49 WebMIDIPermissionRequest* value = it.GetCurrentValue(); | 51 WebMIDIPermissionRequest* value = it.GetCurrentValue(); |
| 50 if (value->equals(request)) { | 52 if (value->equals(request)) { |
| 51 base::string16 origin = request.securityOrigin().toString(); | 53 base::string16 origin = request.securityOrigin().toString(); |
| 52 Send(new MidiHostMsg_CancelSysExPermissionRequest( | 54 Send(new MidiHostMsg_CancelSysExPermissionRequest( |
| 53 routing_id(), it.GetCurrentKey(), GURL(origin))); | 55 routing_id(), it.GetCurrentKey(), GURL(origin))); |
| 54 requests_.Remove(it.GetCurrentKey()); | 56 requests_.Remove(it.GetCurrentKey()); |
| 55 break; | 57 break; |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 | 61 |
| 60 void MidiDispatcher::OnSysExPermissionApproved(int bridge_id, | 62 void MidiDispatcher::OnSysExPermissionApproved(int bridge_id, |
| 61 bool is_allowed) { | 63 bool is_allowed) { |
| 62 // |request| can be NULL when the request is canceled. | 64 // |request| can be NULL when the request is canceled. |
| 63 WebMIDIPermissionRequest* request = requests_.Lookup(bridge_id); | 65 WebMIDIPermissionRequest* request = requests_.Lookup(bridge_id); |
| 64 if (!request) | 66 if (!request) |
| 65 return; | 67 return; |
| 66 request->setIsAllowed(is_allowed); | 68 request->setIsAllowed(is_allowed); |
| 67 requests_.Remove(bridge_id); | 69 requests_.Remove(bridge_id); |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace content | 72 } // namespace content |
| OLD | NEW |