Chromium Code Reviews| 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/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
|
yhirano
2016/01/25 11:20:16
+#include ".../WebMidiOptions.h"
Takashi Toyoshima
2016/01/26 07:24:52
Done.
| |
| 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 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 14 | 14 |
| 15 using blink::WebMIDIPermissionRequest; | 15 using blink::WebMIDIPermissionRequest; |
| 16 using blink::WebMIDIOptions; | |
| 16 using blink::WebSecurityOrigin; | 17 using blink::WebSecurityOrigin; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) | 21 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) |
| 21 : RenderFrameObserver(render_frame) { | 22 : RenderFrameObserver(render_frame) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 MidiDispatcher::~MidiDispatcher() {} | 25 MidiDispatcher::~MidiDispatcher() {} |
| 25 | 26 |
| 26 void MidiDispatcher::requestSysexPermission( | 27 void MidiDispatcher::requestPermission(const WebMIDIPermissionRequest& request, |
| 27 const WebMIDIPermissionRequest& request) { | 28 const WebMIDIOptions& options) { |
| 29 // TODO(crbug.com/535181): Expose all requests to the content layer. | |
| 30 if (!options.sysex) | |
| 31 return WebMIDIPermissionRequest(request).setIsAllowed(true); | |
|
mlamouri (slow - plz ping)
2016/01/21 11:50:57
What about doing:
PermissionName permission_name =
Takashi Toyoshima
2016/01/22 04:33:22
Thank you for jumping in! I thought I will need yo
Takashi Toyoshima
2016/01/22 07:30:01
Some additional notes for this:
- PERMISSION_NAME
| |
| 32 | |
| 28 if (!permission_service_.get()) { | 33 if (!permission_service_.get()) { |
| 29 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 34 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 30 mojo::GetProxy(&permission_service_)); | 35 mojo::GetProxy(&permission_service_)); |
| 31 } | 36 } |
| 32 | 37 |
| 33 int permission_request_id = | 38 int permission_request_id = |
| 34 requests_.Add(new WebMIDIPermissionRequest(request)); | 39 requests_.Add(new WebMIDIPermissionRequest(request)); |
| 35 | 40 |
| 36 permission_service_->RequestPermission( | 41 permission_service_->RequestPermission( |
| 37 PERMISSION_NAME_MIDI_SYSEX, | 42 PERMISSION_NAME_MIDI_SYSEX, request.securityOrigin().toString().utf8(), |
| 38 request.securityOrigin().toString().utf8(), | |
| 39 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 43 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 40 base::Bind(&MidiDispatcher::OnSysExPermissionSet, | 44 base::Bind(&MidiDispatcher::OnPermissionSet, base::Unretained(this), |
| 41 base::Unretained(this), | |
| 42 permission_request_id)); | 45 permission_request_id)); |
| 43 } | 46 } |
| 44 | 47 |
| 45 void MidiDispatcher::cancelSysexPermissionRequest( | 48 void MidiDispatcher::cancelPermissionRequest( |
| 46 const WebMIDIPermissionRequest& request) { | 49 const WebMIDIPermissionRequest& request) { |
| 47 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { | 50 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { |
| 48 WebMIDIPermissionRequest* value = it.GetCurrentValue(); | 51 WebMIDIPermissionRequest* value = it.GetCurrentValue(); |
| 49 if (!value->equals(request)) | 52 if (!value->equals(request)) |
| 50 continue; | 53 continue; |
| 51 requests_.Remove(it.GetCurrentKey()); | 54 requests_.Remove(it.GetCurrentKey()); |
| 52 break; | 55 break; |
| 53 } | 56 } |
| 54 } | 57 } |
| 55 | 58 |
| 56 void MidiDispatcher::OnSysExPermissionSet(int request_id, | 59 void MidiDispatcher::OnPermissionSet(int request_id, PermissionStatus status) { |
| 57 PermissionStatus status) { | |
| 58 // |request| can be NULL when the request is canceled. | 60 // |request| can be NULL when the request is canceled. |
| 59 WebMIDIPermissionRequest* request = requests_.Lookup(request_id); | 61 WebMIDIPermissionRequest* request = requests_.Lookup(request_id); |
| 60 if (!request) | 62 if (!request) |
| 61 return; | 63 return; |
| 62 request->setIsAllowed(status == PERMISSION_STATUS_GRANTED); | 64 request->setIsAllowed(status == PERMISSION_STATUS_GRANTED); |
| 63 requests_.Remove(request_id); | 65 requests_.Remove(request_id); |
| 64 } | 66 } |
| 65 | 67 |
| 66 } // namespace content | 68 } // namespace content |
| OLD | NEW |