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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context.cc

Issue 265773002: [Media,Geolocation] Add permission bubble cancellation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rebase Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/geolocation/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 void GeolocationPermissionRequest::PermissionGranted() { 108 void GeolocationPermissionRequest::PermissionGranted() {
109 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); 109 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true);
110 } 110 }
111 111
112 void GeolocationPermissionRequest::PermissionDenied() { 112 void GeolocationPermissionRequest::PermissionDenied() {
113 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); 113 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
114 } 114 }
115 115
116 void GeolocationPermissionRequest::Cancelled() { 116 void GeolocationPermissionRequest::Cancelled() {
117 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
118 } 117 }
119 118
120 void GeolocationPermissionRequest::RequestFinished() { 119 void GeolocationPermissionRequest::RequestFinished() {
121 delete this; 120 // Deletes 'this'.
121 context_->RequestFinished(this);
122 } 122 }
123 123
124 124
125 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( 125 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext(
126 Profile* profile) 126 Profile* profile)
127 : profile_(profile), 127 : profile_(profile),
128 shutting_down_(false) { 128 shutting_down_(false) {
129 } 129 }
130 130
131 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { 131 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( 203 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
204 content::WebContents* web_contents, 204 content::WebContents* web_contents,
205 int bridge_id, 205 int bridge_id,
206 const GURL& requesting_frame) { 206 const GURL& requesting_frame) {
207 WebViewGuest* guest = 207 WebViewGuest* guest =
208 web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL; 208 web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL;
209 if (guest) { 209 if (guest) {
210 guest->CancelGeolocationPermissionRequest(bridge_id); 210 guest->CancelGeolocationPermissionRequest(bridge_id);
211 return; 211 return;
212 } 212 }
213 // TODO(gbillock): cancel permission bubble request.
214 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 213 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
215 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); 214 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
216 CancelPendingInfobarRequest(PermissionRequestID( 215 CancelPendingInfobarRequest(PermissionRequestID(
217 render_process_id, render_view_id, bridge_id, 0)); 216 render_process_id, render_view_id, bridge_id, 0));
218 } 217 }
219 218
220 void ChromeGeolocationPermissionContext::DecidePermission( 219 void ChromeGeolocationPermissionContext::DecidePermission(
221 content::WebContents* web_contents, 220 content::WebContents* web_contents,
222 const PermissionRequestID& id, 221 const PermissionRequestID& id,
223 const GURL& requesting_frame, 222 const GURL& requesting_frame,
(...skipping 12 matching lines...) Expand all
236 PermissionDecided(id, requesting_frame, embedder, callback, false); 235 PermissionDecided(id, requesting_frame, embedder, callback, false);
237 break; 236 break;
238 case CONTENT_SETTING_ALLOW: 237 case CONTENT_SETTING_ALLOW:
239 PermissionDecided(id, requesting_frame, embedder, callback, true); 238 PermissionDecided(id, requesting_frame, embedder, callback, true);
240 break; 239 break;
241 default: 240 default:
242 if (PermissionBubbleManager::Enabled()) { 241 if (PermissionBubbleManager::Enabled()) {
243 PermissionBubbleManager* mgr = 242 PermissionBubbleManager* mgr =
244 PermissionBubbleManager::FromWebContents(web_contents); 243 PermissionBubbleManager::FromWebContents(web_contents);
245 if (mgr) { 244 if (mgr) {
246 mgr->AddRequest(new GeolocationPermissionRequest( 245 GeolocationPermissionRequest* request =
246 new GeolocationPermissionRequest(
247 this, id, requesting_frame, user_gesture, callback, 247 this, id, requesting_frame, user_gesture, callback,
248 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); 248 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
249 pending_requests_[id.ToString()] = request;
250 mgr->AddRequest(request);
249 } 251 }
250 } else { 252 } else {
251 // setting == ask. Prompt the user. 253 // setting == ask. Prompt the user.
252 QueueController()->CreateInfoBarRequest( 254 QueueController()->CreateInfoBarRequest(
253 id, requesting_frame, embedder, accept_button_label, 255 id, requesting_frame, embedder, accept_button_label,
254 base::Bind( 256 base::Bind(
255 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 257 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
256 base::Unretained(this), id, requesting_frame, callback)); 258 base::Unretained(this), id, requesting_frame, callback));
257 } 259 }
258 } 260 }
259 } 261 }
260 262
261 void ChromeGeolocationPermissionContext::CreateInfoBarRequest( 263 void ChromeGeolocationPermissionContext::CreateInfoBarRequest(
262 const PermissionRequestID& id, 264 const PermissionRequestID& id,
263 const GURL& requesting_frame, 265 const GURL& requesting_frame,
264 const GURL& embedder, 266 const GURL& embedder,
265 const std::string accept_button_label, 267 const std::string accept_button_label,
266 base::Callback<void(bool)> callback) { 268 base::Callback<void(bool)> callback) {
267 QueueController()->CreateInfoBarRequest( 269 QueueController()->CreateInfoBarRequest(
268 id, requesting_frame, embedder, accept_button_label, base::Bind( 270 id, requesting_frame, embedder, accept_button_label, base::Bind(
269 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 271 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
270 base::Unretained(this), id, requesting_frame, callback)); 272 base::Unretained(this), id, requesting_frame, callback));
271 } 273 }
272 274
275 void ChromeGeolocationPermissionContext::RequestFinished(
276 GeolocationPermissionRequest* request) {
277 std::map<std::string, GeolocationPermissionRequest*>::iterator it;
278 for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) {
279 if (it->second == request) {
280 delete it->second;
281 pending_requests_.erase(it);
282 return;
283 }
284 }
285 }
286
287
273 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { 288 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() {
274 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 289 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
275 permission_queue_controller_.reset(); 290 permission_queue_controller_.reset();
276 shutting_down_ = true; 291 shutting_down_ = true;
277 } 292 }
278 293
279 void ChromeGeolocationPermissionContext::PermissionDecided( 294 void ChromeGeolocationPermissionContext::PermissionDecided(
280 const PermissionRequestID& id, 295 const PermissionRequestID& id,
281 const GURL& requesting_frame, 296 const GURL& requesting_frame,
282 const GURL& embedder, 297 const GURL& embedder,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return new PermissionQueueController(profile(), 334 return new PermissionQueueController(profile(),
320 CONTENT_SETTINGS_TYPE_GEOLOCATION); 335 CONTENT_SETTINGS_TYPE_GEOLOCATION);
321 } 336 }
322 337
323 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( 338 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest(
324 const PermissionRequestID& id) { 339 const PermissionRequestID& id) {
325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 340 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
326 if (shutting_down_) 341 if (shutting_down_)
327 return; 342 return;
328 343
329 // TODO(gbillock): handle permission bubble cancellation. 344 if (PermissionBubbleManager::Enabled()) {
345 GeolocationPermissionRequest* cancelling = NULL;
346 std::map<std::string, GeolocationPermissionRequest*>::iterator it;
347 for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) {
348 if (it->first == id.ToString()) {
349 cancelling = it->second;
350 break;
351 }
352 }
353
354 content::WebContents* web_contents = tab_util::GetWebContentsByID(
355 id.render_process_id(), id.render_view_id());
356 if (cancelling != NULL && web_contents != NULL &&
357 PermissionBubbleManager::FromWebContents(web_contents) != NULL) {
358 PermissionBubbleManager::FromWebContents(web_contents)->
359 CancelRequest(cancelling);
360 }
361 return;
362 }
363
330 QueueController()->CancelInfoBarRequest(id); 364 QueueController()->CancelInfoBarRequest(id);
331 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698