Chromium Code Reviews| Index: chrome/browser/media/chrome_midi_permission_context.cc |
| diff --git a/chrome/browser/media/chrome_midi_permission_context.cc b/chrome/browser/media/chrome_midi_permission_context.cc |
| index 223609ad9425d865a03c714459a49fe40b143e86..c29f1081e5ac948ab1eadded5b50c17433bf0047 100644 |
| --- a/chrome/browser/media/chrome_midi_permission_context.cc |
| +++ b/chrome/browser/media/chrome_midi_permission_context.cc |
| @@ -101,11 +101,11 @@ void MidiPermissionRequest::PermissionDenied() { |
| } |
| void MidiPermissionRequest::Cancelled() { |
|
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
NOTREACHED?
Greg Billock
2014/05/21 19:12:34
This is invoked if the user cancels the permission
|
| - context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); |
| } |
| void MidiPermissionRequest::RequestFinished() { |
| - delete this; |
| + // Deletes 'this'. |
|
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
IWBN to ensure that this is the only way ~MPR() ca
Greg Billock
2014/05/21 19:12:34
sounds good, done.
On 2014/05/20 17:09:53, Ami Fi
|
| + context_->RequestFinished(this); |
| } |
| ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile) |
| @@ -200,10 +200,12 @@ void ChromeMidiPermissionContext::DecidePermission( |
| PermissionBubbleManager* bubble_manager = |
| PermissionBubbleManager::FromWebContents(web_contents); |
| if (bubble_manager) { |
| - bubble_manager->AddRequest(new MidiPermissionRequest( |
| + MidiPermissionRequest* request = new MidiPermissionRequest( |
| this, id, requesting_frame, user_gesture, |
| profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| - callback)); |
| + callback); |
| + pending_requests_[id.ToString()] = request; |
|
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
This depends on id.ToString() being unique. Is th
Greg Billock
2014/05/21 19:12:34
It would be nice to key the map on PermissionReque
|
| + bubble_manager->AddRequest(request); |
| } |
| return; |
| } |
| @@ -256,11 +258,43 @@ PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() { |
| return permission_queue_controller_.get(); |
| } |
| +void ChromeMidiPermissionContext::RequestFinished( |
| + MidiPermissionRequest* request) { |
| + std::map<std::string, MidiPermissionRequest*>::iterator it; |
| + for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) { |
|
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
This is a map; why are you iterating??
Put anothe
Greg Billock
2014/05/21 19:12:34
This iteration is searching by value.
The one bel
|
| + if (it->second == request) { |
| + delete it->second; |
| + pending_requests_.erase(it); |
| + return; |
| + } |
| + } |
|
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
NOTREACHED() << "Missing request!";
?
Greg Billock
2014/05/21 19:12:34
Yes. That's correct.
|
| +} |
| + |
| void ChromeMidiPermissionContext::CancelPendingInfobarRequest( |
| const PermissionRequestID& id) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| if (shutting_down_) |
| return; |
| - // TODO(gbillock): Add support for cancellation to permission bubbles. |
| + |
| + if (PermissionBubbleManager::Enabled()) { |
| + MidiPermissionRequest* cancelling = NULL; |
| + std::map<std::string, MidiPermissionRequest*>::iterator it; |
| + for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) { |
| + if (it->first == id.ToString()) { |
| + cancelling = it->second; |
| + break; |
| + } |
| + } |
| + |
| + content::WebContents* web_contents = tab_util::GetWebContentsByID( |
| + id.render_process_id(), id.render_view_id()); |
| + if (cancelling != NULL && web_contents != NULL && |
| + PermissionBubbleManager::FromWebContents(web_contents) != NULL) { |
| + PermissionBubbleManager::FromWebContents(web_contents)-> |
| + CancelRequest(cancelling); |
| + } |
| + return; |
| + } |
| + |
| GetQueueController()->CancelInfoBarRequest(id); |
| } |