OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/renderer/media/midi_dispatcher.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/public/renderer/render_frame.h" |
| 9 #include "services/shell/public/cpp/interface_provider.h" |
| 10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 13 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIOptions.h" |
| 14 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIPermissionRequest
.h" |
| 15 |
| 16 using blink::WebMIDIPermissionRequest; |
| 17 using blink::WebMIDIOptions; |
| 18 using blink::WebSecurityOrigin; |
| 19 |
| 20 namespace content { |
| 21 |
| 22 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) |
| 23 : RenderFrameObserver(render_frame) { |
| 24 } |
| 25 |
| 26 MidiDispatcher::~MidiDispatcher() {} |
| 27 |
| 28 void MidiDispatcher::OnDestruct() { |
| 29 delete this; |
| 30 } |
| 31 |
| 32 void MidiDispatcher::requestPermission(const WebMIDIPermissionRequest& request, |
| 33 const WebMIDIOptions& options) { |
| 34 if (!permission_service_.get()) |
| 35 render_frame()->GetRemoteInterfaces()->GetInterface(&permission_service_); |
| 36 |
| 37 int permission_request_id = |
| 38 requests_.Add(new WebMIDIPermissionRequest(request)); |
| 39 |
| 40 blink::mojom::PermissionName permission_name = |
| 41 (options.sysex == WebMIDIOptions::SysexPermission::WithSysex) |
| 42 ? blink::mojom::PermissionName::MIDI_SYSEX |
| 43 : blink::mojom::PermissionName::MIDI; |
| 44 |
| 45 permission_service_->RequestPermission( |
| 46 permission_name, request.getSecurityOrigin().toString().utf8(), |
| 47 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 48 base::Bind(&MidiDispatcher::OnPermissionSet, base::Unretained(this), |
| 49 permission_request_id)); |
| 50 } |
| 51 |
| 52 void MidiDispatcher::cancelPermissionRequest( |
| 53 const WebMIDIPermissionRequest& request) { |
| 54 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { |
| 55 WebMIDIPermissionRequest* value = it.GetCurrentValue(); |
| 56 if (!value->equals(request)) |
| 57 continue; |
| 58 requests_.Remove(it.GetCurrentKey()); |
| 59 break; |
| 60 } |
| 61 } |
| 62 |
| 63 void MidiDispatcher::OnPermissionSet(int request_id, |
| 64 blink::mojom::PermissionStatus status) { |
| 65 // |request| can be NULL when the request is canceled. |
| 66 WebMIDIPermissionRequest* request = requests_.Lookup(request_id); |
| 67 if (!request) |
| 68 return; |
| 69 request->setIsAllowed(status == blink::mojom::PermissionStatus::GRANTED); |
| 70 requests_.Remove(request_id); |
| 71 } |
| 72 |
| 73 } // namespace content |
OLD | NEW |