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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 virtual void Cancelled() OVERRIDE; | 43 virtual void Cancelled() OVERRIDE; |
44 virtual void RequestFinished() OVERRIDE; | 44 virtual void RequestFinished() OVERRIDE; |
45 | 45 |
46 private: | 46 private: |
47 ChromeMidiPermissionContext* context_; | 47 ChromeMidiPermissionContext* context_; |
48 const PermissionRequestID id_; | 48 const PermissionRequestID id_; |
49 GURL requesting_frame_; | 49 GURL requesting_frame_; |
50 bool user_gesture_; | 50 bool user_gesture_; |
51 std::string display_languages_; | 51 std::string display_languages_; |
52 const content::BrowserContext::MidiSysExPermissionCallback& callback_; | 52 const content::BrowserContext::MidiSysExPermissionCallback& callback_; |
53 bool is_finished_; | |
53 | 54 |
54 DISALLOW_COPY_AND_ASSIGN(MidiPermissionRequest); | 55 DISALLOW_COPY_AND_ASSIGN(MidiPermissionRequest); |
55 }; | 56 }; |
56 | 57 |
57 MidiPermissionRequest::MidiPermissionRequest( | 58 MidiPermissionRequest::MidiPermissionRequest( |
58 ChromeMidiPermissionContext* context, | 59 ChromeMidiPermissionContext* context, |
59 const PermissionRequestID& id, | 60 const PermissionRequestID& id, |
60 const GURL& requesting_frame, | 61 const GURL& requesting_frame, |
61 bool user_gesture, | 62 bool user_gesture, |
62 const std::string& display_languages, | 63 const std::string& display_languages, |
63 const content::BrowserContext::MidiSysExPermissionCallback& callback) | 64 const content::BrowserContext::MidiSysExPermissionCallback& callback) |
64 : context_(context), | 65 : context_(context), |
65 id_(id), | 66 id_(id), |
66 requesting_frame_(requesting_frame), | 67 requesting_frame_(requesting_frame), |
67 user_gesture_(user_gesture), | 68 user_gesture_(user_gesture), |
68 display_languages_(display_languages), | 69 display_languages_(display_languages), |
69 callback_(callback) {} | 70 callback_(callback), |
71 is_finished_(false) {} | |
70 | 72 |
71 MidiPermissionRequest::~MidiPermissionRequest() {} | 73 MidiPermissionRequest::~MidiPermissionRequest() { |
74 DCHECK(is_finished_); | |
75 } | |
72 | 76 |
73 int MidiPermissionRequest::GetIconID() const { | 77 int MidiPermissionRequest::GetIconID() const { |
74 return IDR_ALLOWED_MIDI_SYSEX; | 78 return IDR_ALLOWED_MIDI_SYSEX; |
75 } | 79 } |
76 | 80 |
77 base::string16 MidiPermissionRequest::GetMessageText() const { | 81 base::string16 MidiPermissionRequest::GetMessageText() const { |
78 return l10n_util::GetStringFUTF16( | 82 return l10n_util::GetStringFUTF16( |
79 IDS_MIDI_SYSEX_INFOBAR_QUESTION, | 83 IDS_MIDI_SYSEX_INFOBAR_QUESTION, |
80 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_)); | 84 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_)); |
81 } | 85 } |
(...skipping 11 matching lines...) Expand all Loading... | |
93 } | 97 } |
94 | 98 |
95 void MidiPermissionRequest::PermissionGranted() { | 99 void MidiPermissionRequest::PermissionGranted() { |
96 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); | 100 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); |
97 } | 101 } |
98 | 102 |
99 void MidiPermissionRequest::PermissionDenied() { | 103 void MidiPermissionRequest::PermissionDenied() { |
100 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | 104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); |
101 } | 105 } |
102 | 106 |
103 void MidiPermissionRequest::Cancelled() { | 107 void MidiPermissionRequest::Cancelled() { |
Ami GONE FROM CHROMIUM
2014/05/21 20:15:13
// This is called if the info-bar is dismissed. P
Greg Billock
2014/05/21 22:46:42
Yeah, me too. That's why I put in initially that c
Ami GONE FROM CHROMIUM
2014/05/21 23:47:34
Shouldn't you find out before reverting the behavi
Greg Billock
2014/05/22 01:50:00
This (the change in behavior) is flagged off curre
| |
104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | |
105 } | 108 } |
106 | 109 |
107 void MidiPermissionRequest::RequestFinished() { | 110 void MidiPermissionRequest::RequestFinished() { |
108 delete this; | 111 is_finished_ = true; |
112 // Deletes 'this'. | |
113 context_->RequestFinished(this); | |
109 } | 114 } |
110 | 115 |
111 ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile) | 116 ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile) |
112 : profile_(profile), | 117 : profile_(profile), |
113 shutting_down_(false) { | 118 shutting_down_(false) { |
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
115 } | 120 } |
116 | 121 |
117 ChromeMidiPermissionContext::~ChromeMidiPermissionContext() { | 122 ChromeMidiPermissionContext::~ChromeMidiPermissionContext() { |
118 DCHECK(!permission_queue_controller_); | 123 DCHECK(!permission_queue_controller_); |
Ami GONE FROM CHROMIUM
2014/05/21 20:15:13
Did you miss this comment?
Would you
DCHECK(pendin
Greg Billock
2014/05/21 22:46:42
Ah, yes, I missed responding to that. Style guide
Ami GONE FROM CHROMIUM
2014/05/21 23:47:34
Where does it say that?
Greg Billock
2014/05/22 01:50:00
http://google-styleguide.googlecode.com/svn/trunk/
Ami GONE FROM CHROMIUM
2014/05/22 02:56:33
This is an unfortunate divergence between chromium
| |
119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 124 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
120 } | 125 } |
121 | 126 |
122 void ChromeMidiPermissionContext::Shutdown() { | 127 void ChromeMidiPermissionContext::Shutdown() { |
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
124 permission_queue_controller_.reset(); | 129 permission_queue_controller_.reset(); |
125 shutting_down_ = true; | 130 shutting_down_ = true; |
126 } | 131 } |
127 | 132 |
128 void ChromeMidiPermissionContext::RequestMidiSysExPermission( | 133 void ChromeMidiPermissionContext::RequestMidiSysExPermission( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 PermissionDecided(id, requesting_frame, embedder, callback, false); | 198 PermissionDecided(id, requesting_frame, embedder, callback, false); |
194 break; | 199 break; |
195 case CONTENT_SETTING_ALLOW: | 200 case CONTENT_SETTING_ALLOW: |
196 PermissionDecided(id, requesting_frame, embedder, callback, true); | 201 PermissionDecided(id, requesting_frame, embedder, callback, true); |
197 break; | 202 break; |
198 default: | 203 default: |
199 if (PermissionBubbleManager::Enabled()) { | 204 if (PermissionBubbleManager::Enabled()) { |
200 PermissionBubbleManager* bubble_manager = | 205 PermissionBubbleManager* bubble_manager = |
201 PermissionBubbleManager::FromWebContents(web_contents); | 206 PermissionBubbleManager::FromWebContents(web_contents); |
202 if (bubble_manager) { | 207 if (bubble_manager) { |
203 bubble_manager->AddRequest(new MidiPermissionRequest( | 208 MidiPermissionRequest* request = new MidiPermissionRequest( |
204 this, id, requesting_frame, user_gesture, | 209 this, id, requesting_frame, user_gesture, |
205 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 210 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
206 callback)); | 211 callback); |
212 bool inserted = pending_requests_.insert( | |
213 make_pair(id.ToString(), request)).second; | |
214 DCHECK(inserted) << "Duplicate id " << id.ToString(); | |
215 bubble_manager->AddRequest(request); | |
207 } | 216 } |
208 return; | 217 return; |
209 } | 218 } |
210 | 219 |
211 // TODO(gbillock): Delete this and the infobar delegate when | 220 // TODO(gbillock): Delete this and the infobar delegate when |
212 // we're using only bubbles. crbug.com/337458 | 221 // we're using only bubbles. crbug.com/337458 |
213 GetQueueController()->CreateInfoBarRequest( | 222 GetQueueController()->CreateInfoBarRequest( |
214 id, requesting_frame, embedder, std::string(), base::Bind( | 223 id, requesting_frame, embedder, std::string(), base::Bind( |
215 &ChromeMidiPermissionContext::NotifyPermissionSet, | 224 &ChromeMidiPermissionContext::NotifyPermissionSet, |
216 base::Unretained(this), id, requesting_frame, callback)); | 225 base::Unretained(this), id, requesting_frame, callback)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 258 |
250 PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() { | 259 PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() { |
251 if (!permission_queue_controller_) { | 260 if (!permission_queue_controller_) { |
252 permission_queue_controller_.reset( | 261 permission_queue_controller_.reset( |
253 new PermissionQueueController(profile_, | 262 new PermissionQueueController(profile_, |
254 CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 263 CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
255 } | 264 } |
256 return permission_queue_controller_.get(); | 265 return permission_queue_controller_.get(); |
257 } | 266 } |
258 | 267 |
268 void ChromeMidiPermissionContext::RequestFinished( | |
269 MidiPermissionRequest* request) { | |
270 std::map<std::string, MidiPermissionRequest*>::iterator it; | |
271 for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) { | |
272 if (it->second == request) { | |
273 delete it->second; | |
274 pending_requests_.erase(it); | |
275 return; | |
276 } | |
277 } | |
278 | |
279 NOTREACHED() << "Missing request"; | |
280 } | |
281 | |
259 void ChromeMidiPermissionContext::CancelPendingInfobarRequest( | 282 void ChromeMidiPermissionContext::CancelPendingInfobarRequest( |
260 const PermissionRequestID& id) { | 283 const PermissionRequestID& id) { |
261 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
262 if (shutting_down_) | 285 if (shutting_down_) |
263 return; | 286 return; |
264 // TODO(gbillock): Add support for cancellation to permission bubbles. | 287 |
288 if (PermissionBubbleManager::Enabled()) { | |
289 std::map<std::string, MidiPermissionRequest*>::iterator it = | |
290 pending_requests_.find(id.ToString()); | |
291 MidiPermissionRequest* cancelling = | |
292 (it != pending_requests_.end()) ? it->second : NULL; | |
293 | |
294 content::WebContents* web_contents = tab_util::GetWebContentsByID( | |
295 id.render_process_id(), id.render_view_id()); | |
296 if (cancelling != NULL && web_contents != NULL && | |
297 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | |
298 PermissionBubbleManager::FromWebContents(web_contents)-> | |
299 CancelRequest(cancelling); | |
300 } | |
301 return; | |
302 } | |
303 | |
265 GetQueueController()->CancelInfoBarRequest(id); | 304 GetQueueController()->CancelInfoBarRequest(id); |
266 } | 305 } |
OLD | NEW |