| 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 "content/public/common/service_registry.h" | 8 #include "content/public/common/service_registry.h" |
| 9 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
| 10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" | 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 12 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIOptions.h" | 13 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIOptions.h" |
| 13 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIPermissionRequest
.h" | 14 #include "third_party/WebKit/public/web/modules/webmidi/WebMIDIPermissionRequest
.h" |
| 14 | 15 |
| 15 using blink::WebMIDIPermissionRequest; | 16 using blink::WebMIDIPermissionRequest; |
| 16 using blink::WebMIDIOptions; | 17 using blink::WebMIDIOptions; |
| 17 using blink::WebSecurityOrigin; | 18 using blink::WebSecurityOrigin; |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) | 22 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 int permission_request_id = | 35 int permission_request_id = |
| 35 requests_.Add(new WebMIDIPermissionRequest(request)); | 36 requests_.Add(new WebMIDIPermissionRequest(request)); |
| 36 | 37 |
| 37 blink::mojom::PermissionName permission_name = | 38 blink::mojom::PermissionName permission_name = |
| 38 (options.sysex == WebMIDIOptions::SysexPermission::WithSysex) | 39 (options.sysex == WebMIDIOptions::SysexPermission::WithSysex) |
| 39 ? blink::mojom::PermissionName::MIDI_SYSEX | 40 ? blink::mojom::PermissionName::MIDI_SYSEX |
| 40 : blink::mojom::PermissionName::MIDI; | 41 : blink::mojom::PermissionName::MIDI; |
| 41 | 42 |
| 42 permission_service_->RequestPermission( | 43 permission_service_->RequestPermission( |
| 43 permission_name, request.getSecurityOrigin().toString().utf8(), | 44 permission_name, request.getSecurityOrigin().toString().utf8(), |
| 45 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 44 base::Bind(&MidiDispatcher::OnPermissionSet, base::Unretained(this), | 46 base::Bind(&MidiDispatcher::OnPermissionSet, base::Unretained(this), |
| 45 permission_request_id)); | 47 permission_request_id)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void MidiDispatcher::cancelPermissionRequest( | 50 void MidiDispatcher::cancelPermissionRequest( |
| 49 const WebMIDIPermissionRequest& request) { | 51 const WebMIDIPermissionRequest& request) { |
| 50 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { | 52 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { |
| 51 WebMIDIPermissionRequest* value = it.GetCurrentValue(); | 53 WebMIDIPermissionRequest* value = it.GetCurrentValue(); |
| 52 if (!value->equals(request)) | 54 if (!value->equals(request)) |
| 53 continue; | 55 continue; |
| 54 requests_.Remove(it.GetCurrentKey()); | 56 requests_.Remove(it.GetCurrentKey()); |
| 55 break; | 57 break; |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| 59 void MidiDispatcher::OnPermissionSet(int request_id, | 61 void MidiDispatcher::OnPermissionSet(int request_id, |
| 60 blink::mojom::PermissionStatus status) { | 62 blink::mojom::PermissionStatus status) { |
| 61 // |request| can be NULL when the request is canceled. | 63 // |request| can be NULL when the request is canceled. |
| 62 WebMIDIPermissionRequest* request = requests_.Lookup(request_id); | 64 WebMIDIPermissionRequest* request = requests_.Lookup(request_id); |
| 63 if (!request) | 65 if (!request) |
| 64 return; | 66 return; |
| 65 request->setIsAllowed(status == blink::mojom::PermissionStatus::GRANTED); | 67 request->setIsAllowed(status == blink::mojom::PermissionStatus::GRANTED); |
| 66 requests_.Remove(request_id); | 68 requests_.Remove(request_id); |
| 67 } | 69 } |
| 68 | 70 |
| 69 } // namespace content | 71 } // namespace content |
| OLD | NEW |