Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: content/renderer/media/midi_dispatcher.cc

Issue 755673002: Update MidiDispatcher to use Mojo Permission Service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/common/service_registry.h"
9 #include "content/common/media/midi_messages.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"
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"
14 13
15 using blink::WebMIDIPermissionRequest; 14 using blink::WebMIDIPermissionRequest;
16 using blink::WebSecurityOrigin; 15 using blink::WebSecurityOrigin;
17 16
18 namespace content { 17 namespace content {
19 18
20 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame) 19 MidiDispatcher::MidiDispatcher(RenderFrame* render_frame)
21 : RenderFrameObserver(render_frame) { 20 : RenderFrameObserver(render_frame) {
22 } 21 }
23 22
24 MidiDispatcher::~MidiDispatcher() {} 23 MidiDispatcher::~MidiDispatcher() {}
25 24
26 bool MidiDispatcher::OnMessageReceived(const IPC::Message& message) {
27 bool handled = true;
28 IPC_BEGIN_MESSAGE_MAP(MidiDispatcher, message)
29 IPC_MESSAGE_HANDLER(MidiMsg_SysExPermissionApproved,
30 OnSysExPermissionApproved)
31 IPC_MESSAGE_UNHANDLED(handled = false)
32 IPC_END_MESSAGE_MAP()
33 return handled;
34 }
35
36 void MidiDispatcher::requestSysexPermission( 25 void MidiDispatcher::requestSysexPermission(
37 const WebMIDIPermissionRequest& request) { 26 const WebMIDIPermissionRequest& request) {
38 int bridge_id = requests_.Add(new WebMIDIPermissionRequest(request)); 27 if (!permission_service_.get()) {
39 WebSecurityOrigin security_origin = request.securityOrigin(); 28 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
40 GURL url(security_origin.toString()); 29 &permission_service_);
41 Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url, 30 }
42 blink::WebUserGestureIndicator::isProcessingUserGesture())); 31
Tom Sepez 2014/11/24 18:10:02 Can the connect fail? Do we need to handle that ca
mlamouri (slow - plz ping) 2014/11/24 18:20:17 My understanding is that permission_service_ can't
Tom Sepez 2014/11/24 18:27:09 OK, can we add a debug assert?
mlamouri (slow - plz ping) 2014/11/24 18:29:40 qsr@, do you have some insights about this? It see
nasko 2014/11/25 00:30:59 I'm biased towards adding a (D)CHECK if we never e
qsr 2014/11/25 09:38:00 The DCHECK is not useful. The service cannot be nu
mlamouri (slow - plz ping) 2014/11/25 09:48:21 Thanks for the quick reply Benjamin! :)
32 int permission_request_id =
33 requests_.Add(new WebMIDIPermissionRequest(request));
34
35 permission_service_->RequestPermission(
36 PERMISSION_NAME_MIDI_SYSEX,
37 request.securityOrigin().toString().utf8(),
38 base::Bind(&MidiDispatcher::OnSysExPermissionSet,
39 base::Unretained(this),
40 permission_request_id));
43 } 41 }
44 42
45 void MidiDispatcher::cancelSysexPermissionRequest( 43 void MidiDispatcher::cancelSysexPermissionRequest(
46 const WebMIDIPermissionRequest& request) { 44 const WebMIDIPermissionRequest& request) {
47 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) { 45 for (Requests::iterator it(&requests_); !it.IsAtEnd(); it.Advance()) {
48 WebMIDIPermissionRequest* value = it.GetCurrentValue(); 46 WebMIDIPermissionRequest* value = it.GetCurrentValue();
49 if (!value->equals(request)) 47 if (!value->equals(request))
50 continue; 48 continue;
51 requests_.Remove(it.GetCurrentKey()); 49 requests_.Remove(it.GetCurrentKey());
52 break; 50 break;
53 } 51 }
54 } 52 }
55 53
56 void MidiDispatcher::OnSysExPermissionApproved(int bridge_id, 54 void MidiDispatcher::OnSysExPermissionSet(int request_id,
57 bool is_allowed) { 55 PermissionStatus status) {
58 // |request| can be NULL when the request is canceled. 56 // |request| can be NULL when the request is canceled.
59 WebMIDIPermissionRequest* request = requests_.Lookup(bridge_id); 57 WebMIDIPermissionRequest* request = requests_.Lookup(request_id);
60 if (!request) 58 if (!request)
61 return; 59 return;
62 request->setIsAllowed(is_allowed); 60 request->setIsAllowed(status == PERMISSION_STATUS_GRANTED);
63 requests_.Remove(bridge_id); 61 requests_.Remove(request_id);
64 } 62 }
65 63
66 } // namespace content 64 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698