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 "chrome/browser/media/chrome_midi_permission_context.h" | 5 #include "chrome/browser/media/chrome_midi_permission_context.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
9 #include "chrome/browser/content_settings/permission_queue_controller.h" | 9 #include "chrome/browser/content_settings/permission_queue_controller.h" |
10 #include "chrome/browser/content_settings/permission_request_id.h" | 10 #include "chrome/browser/content_settings/permission_request_id.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 93 } |
94 | 94 |
95 void MidiPermissionRequest::PermissionGranted() { | 95 void MidiPermissionRequest::PermissionGranted() { |
96 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); | 96 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); |
97 } | 97 } |
98 | 98 |
99 void MidiPermissionRequest::PermissionDenied() { | 99 void MidiPermissionRequest::PermissionDenied() { |
100 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | 100 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); |
101 } | 101 } |
102 | 102 |
103 void MidiPermissionRequest::Cancelled() { | 103 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
| |
104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | |
105 } | 104 } |
106 | 105 |
107 void MidiPermissionRequest::RequestFinished() { | 106 void MidiPermissionRequest::RequestFinished() { |
108 delete this; | 107 // 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
| |
108 context_->RequestFinished(this); | |
109 } | 109 } |
110 | 110 |
111 ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile) | 111 ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile) |
112 : profile_(profile), | 112 : profile_(profile), |
113 shutting_down_(false) { | 113 shutting_down_(false) { |
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
115 } | 115 } |
116 | 116 |
117 ChromeMidiPermissionContext::~ChromeMidiPermissionContext() { | 117 ChromeMidiPermissionContext::~ChromeMidiPermissionContext() { |
118 DCHECK(!permission_queue_controller_); | 118 DCHECK(!permission_queue_controller_); |
Ami GONE FROM CHROMIUM
2014/05/20 17:09:53
Would you
DCHECK(pending_requests_.empty());
or wo
| |
119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
120 } | 120 } |
121 | 121 |
122 void ChromeMidiPermissionContext::Shutdown() { | 122 void ChromeMidiPermissionContext::Shutdown() { |
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
124 permission_queue_controller_.reset(); | 124 permission_queue_controller_.reset(); |
125 shutting_down_ = true; | 125 shutting_down_ = true; |
126 } | 126 } |
127 | 127 |
128 void ChromeMidiPermissionContext::RequestMidiSysExPermission( | 128 void ChromeMidiPermissionContext::RequestMidiSysExPermission( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 PermissionDecided(id, requesting_frame, embedder, callback, false); | 193 PermissionDecided(id, requesting_frame, embedder, callback, false); |
194 break; | 194 break; |
195 case CONTENT_SETTING_ALLOW: | 195 case CONTENT_SETTING_ALLOW: |
196 PermissionDecided(id, requesting_frame, embedder, callback, true); | 196 PermissionDecided(id, requesting_frame, embedder, callback, true); |
197 break; | 197 break; |
198 default: | 198 default: |
199 if (PermissionBubbleManager::Enabled()) { | 199 if (PermissionBubbleManager::Enabled()) { |
200 PermissionBubbleManager* bubble_manager = | 200 PermissionBubbleManager* bubble_manager = |
201 PermissionBubbleManager::FromWebContents(web_contents); | 201 PermissionBubbleManager::FromWebContents(web_contents); |
202 if (bubble_manager) { | 202 if (bubble_manager) { |
203 bubble_manager->AddRequest(new MidiPermissionRequest( | 203 MidiPermissionRequest* request = new MidiPermissionRequest( |
204 this, id, requesting_frame, user_gesture, | 204 this, id, requesting_frame, user_gesture, |
205 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 205 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
206 callback)); | 206 callback); |
207 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
| |
208 bubble_manager->AddRequest(request); | |
207 } | 209 } |
208 return; | 210 return; |
209 } | 211 } |
210 | 212 |
211 // TODO(gbillock): Delete this and the infobar delegate when | 213 // TODO(gbillock): Delete this and the infobar delegate when |
212 // we're using only bubbles. crbug.com/337458 | 214 // we're using only bubbles. crbug.com/337458 |
213 GetQueueController()->CreateInfoBarRequest( | 215 GetQueueController()->CreateInfoBarRequest( |
214 id, requesting_frame, embedder, std::string(), base::Bind( | 216 id, requesting_frame, embedder, std::string(), base::Bind( |
215 &ChromeMidiPermissionContext::NotifyPermissionSet, | 217 &ChromeMidiPermissionContext::NotifyPermissionSet, |
216 base::Unretained(this), id, requesting_frame, callback)); | 218 base::Unretained(this), id, requesting_frame, callback)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 251 |
250 PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() { | 252 PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() { |
251 if (!permission_queue_controller_) { | 253 if (!permission_queue_controller_) { |
252 permission_queue_controller_.reset( | 254 permission_queue_controller_.reset( |
253 new PermissionQueueController(profile_, | 255 new PermissionQueueController(profile_, |
254 CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 256 CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
255 } | 257 } |
256 return permission_queue_controller_.get(); | 258 return permission_queue_controller_.get(); |
257 } | 259 } |
258 | 260 |
261 void ChromeMidiPermissionContext::RequestFinished( | |
262 MidiPermissionRequest* request) { | |
263 std::map<std::string, MidiPermissionRequest*>::iterator it; | |
264 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
| |
265 if (it->second == request) { | |
266 delete it->second; | |
267 pending_requests_.erase(it); | |
268 return; | |
269 } | |
270 } | |
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.
| |
271 } | |
272 | |
259 void ChromeMidiPermissionContext::CancelPendingInfobarRequest( | 273 void ChromeMidiPermissionContext::CancelPendingInfobarRequest( |
260 const PermissionRequestID& id) { | 274 const PermissionRequestID& id) { |
261 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 275 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
262 if (shutting_down_) | 276 if (shutting_down_) |
263 return; | 277 return; |
264 // TODO(gbillock): Add support for cancellation to permission bubbles. | 278 |
279 if (PermissionBubbleManager::Enabled()) { | |
280 MidiPermissionRequest* cancelling = NULL; | |
281 std::map<std::string, MidiPermissionRequest*>::iterator it; | |
282 for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) { | |
283 if (it->first == id.ToString()) { | |
284 cancelling = it->second; | |
285 break; | |
286 } | |
287 } | |
288 | |
289 content::WebContents* web_contents = tab_util::GetWebContentsByID( | |
290 id.render_process_id(), id.render_view_id()); | |
291 if (cancelling != NULL && web_contents != NULL && | |
292 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | |
293 PermissionBubbleManager::FromWebContents(web_contents)-> | |
294 CancelRequest(cancelling); | |
295 } | |
296 return; | |
297 } | |
298 | |
265 GetQueueController()->CancelInfoBarRequest(id); | 299 GetQueueController()->CancelInfoBarRequest(id); |
266 } | 300 } |
OLD | NEW |