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

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: rebase Created 6 years, 6 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 scoped_ptr<GeolocationPermissionRequest> request_ptr(
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 GeolocationPermissionRequest* request = request_ptr.get();
250 pending_requests_.add(id.ToString(), request_ptr.Pass());
251 mgr->AddRequest(request);
249 } 252 }
250 } else { 253 } else {
251 // setting == ask. Prompt the user. 254 // setting == ask. Prompt the user.
252 QueueController()->CreateInfoBarRequest( 255 QueueController()->CreateInfoBarRequest(
253 id, requesting_frame, embedder, accept_button_label, 256 id, requesting_frame, embedder, accept_button_label,
254 base::Bind( 257 base::Bind(
255 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 258 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
256 base::Unretained(this), id, requesting_frame, callback)); 259 base::Unretained(this), id, requesting_frame, callback));
257 } 260 }
258 } 261 }
259 } 262 }
260 263
261 void ChromeGeolocationPermissionContext::CreateInfoBarRequest( 264 void ChromeGeolocationPermissionContext::CreateInfoBarRequest(
262 const PermissionRequestID& id, 265 const PermissionRequestID& id,
263 const GURL& requesting_frame, 266 const GURL& requesting_frame,
264 const GURL& embedder, 267 const GURL& embedder,
265 const std::string accept_button_label, 268 const std::string accept_button_label,
266 base::Callback<void(bool)> callback) { 269 base::Callback<void(bool)> callback) {
267 QueueController()->CreateInfoBarRequest( 270 QueueController()->CreateInfoBarRequest(
268 id, requesting_frame, embedder, accept_button_label, base::Bind( 271 id, requesting_frame, embedder, accept_button_label, base::Bind(
269 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 272 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
270 base::Unretained(this), id, requesting_frame, callback)); 273 base::Unretained(this), id, requesting_frame, callback));
271 } 274 }
272 275
276 void ChromeGeolocationPermissionContext::RequestFinished(
277 GeolocationPermissionRequest* request) {
278 base::ScopedPtrHashMap<std::string,
279 GeolocationPermissionRequest>::iterator it;
280 for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) {
281 if (it->second == request) {
282 pending_requests_.take_and_erase(it);
283 return;
284 }
285 }
286 }
287
288
273 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { 289 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() {
274 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 290 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
275 permission_queue_controller_.reset(); 291 permission_queue_controller_.reset();
276 shutting_down_ = true; 292 shutting_down_ = true;
277 } 293 }
278 294
279 void ChromeGeolocationPermissionContext::PermissionDecided( 295 void ChromeGeolocationPermissionContext::PermissionDecided(
280 const PermissionRequestID& id, 296 const PermissionRequestID& id,
281 const GURL& requesting_frame, 297 const GURL& requesting_frame,
282 const GURL& embedder, 298 const GURL& embedder,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return new PermissionQueueController(profile(), 335 return new PermissionQueueController(profile(),
320 CONTENT_SETTINGS_TYPE_GEOLOCATION); 336 CONTENT_SETTINGS_TYPE_GEOLOCATION);
321 } 337 }
322 338
323 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( 339 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest(
324 const PermissionRequestID& id) { 340 const PermissionRequestID& id) {
325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 341 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
326 if (shutting_down_) 342 if (shutting_down_)
327 return; 343 return;
328 344
329 // TODO(gbillock): handle permission bubble cancellation. 345 if (PermissionBubbleManager::Enabled()) {
346 GeolocationPermissionRequest* cancelling =
347 pending_requests_.get(id.ToString());
348 content::WebContents* web_contents = tab_util::GetWebContentsByID(
349 id.render_process_id(), id.render_view_id());
350 if (cancelling != NULL && web_contents != NULL &&
351 PermissionBubbleManager::FromWebContents(web_contents) != NULL) {
352 PermissionBubbleManager::FromWebContents(web_contents)->
353 CancelRequest(cancelling);
354 }
355 return;
356 }
357
330 QueueController()->CancelInfoBarRequest(id); 358 QueueController()->CancelInfoBarRequest(id);
331 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698