| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // the notification infrastructure would simplify. | 51 // the notification infrastructure would simplify. |
| 52 class GeolocationInfoBarQueueController { | 52 class GeolocationInfoBarQueueController { |
| 53 public: | 53 public: |
| 54 GeolocationInfoBarQueueController( | 54 GeolocationInfoBarQueueController( |
| 55 GeolocationPermissionContext* geolocation_permission_context, | 55 GeolocationPermissionContext* geolocation_permission_context, |
| 56 Profile* profile); | 56 Profile* profile); |
| 57 ~GeolocationInfoBarQueueController(); | 57 ~GeolocationInfoBarQueueController(); |
| 58 | 58 |
| 59 // The InfoBar will be displayed immediately if the tab is not already | 59 // The InfoBar will be displayed immediately if the tab is not already |
| 60 // displaying one, otherwise it'll be queued. | 60 // displaying one, otherwise it'll be queued. |
| 61 void CreateInfoBarRequest( | 61 void CreateInfoBarRequest(int render_process_id, |
| 62 int render_process_id, int render_view_id, int bridge_id, | 62 int render_view_id, |
| 63 const GURL& requesting_frame, const GURL& emebedder); | 63 int bridge_id, |
| 64 const GURL& requesting_frame, |
| 65 const GURL& emebedder); |
| 64 | 66 |
| 65 // Cancels a specific infobar request. | 67 // Cancels a specific infobar request. |
| 66 void CancelInfoBarRequest( | 68 void CancelInfoBarRequest(int render_process_id, |
| 67 int render_process_id, int render_view_id, int bridge_id); | 69 int render_view_id, |
| 70 int bridge_id); |
| 68 | 71 |
| 69 // Called by the InfoBarDelegate to notify it's closed. It'll display a new | 72 // Called by the InfoBarDelegate to notify it's closed. It'll display a new |
| 70 // InfoBar if there's any request pending for this tab. | 73 // InfoBar if there's any request pending for this tab. |
| 71 void OnInfoBarClosed( | 74 void OnInfoBarClosed(int render_process_id, |
| 72 int render_process_id, int render_view_id, int bridge_id); | 75 int render_view_id, |
| 76 int bridge_id); |
| 73 | 77 |
| 74 // Called by the InfoBarDelegate to notify permission has been set. | 78 // Called by the InfoBarDelegate to notify permission has been set. |
| 75 // It'll notify and dismiss any other pending InfoBar request for the same | 79 // It'll notify and dismiss any other pending InfoBar request for the same |
| 76 // |requesting_frame| and embedder. | 80 // |requesting_frame| and embedder. |
| 77 void OnPermissionSet( | 81 void OnPermissionSet(int render_process_id, |
| 78 int render_process_id, int render_view_id, int bridge_id, | 82 int render_view_id, |
| 79 const GURL& requesting_frame, const GURL& embedder, bool allowed); | 83 int bridge_id, |
| 84 const GURL& requesting_frame, |
| 85 const GURL& embedder, |
| 86 bool allowed); |
| 80 | 87 |
| 81 private: | 88 private: |
| 82 struct PendingInfoBarRequest; | 89 struct PendingInfoBarRequest; |
| 83 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; | 90 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; |
| 84 | 91 |
| 85 // Shows the first pending infobar for this tab. | 92 // Shows the first pending infobar for this tab. |
| 86 void ShowQueuedInfoBar(int render_process_id, int render_view_id); | 93 void ShowQueuedInfoBar(int render_process_id, int render_view_id); |
| 87 | 94 |
| 88 // Cancels an InfoBar request and returns the next iterator position. | 95 // Cancels the pending InfoBar request at |index|. This removes the request |
| 89 std::vector<PendingInfoBarRequest>::iterator CancelInfoBarRequestInternal( | 96 // from the pending list. |
| 90 std::vector<PendingInfoBarRequest>::iterator i); | 97 void CancelInfoBarRequestInternal(size_t index); |
| 91 | 98 |
| 92 GeolocationPermissionContext* const geolocation_permission_context_; | 99 GeolocationPermissionContext* const geolocation_permission_context_; |
| 93 Profile* const profile_; | 100 Profile* const profile_; |
| 94 // Contains all pending infobar requests. | 101 // Contains all pending infobar requests. |
| 95 PendingInfoBarRequests pending_infobar_requests_; | 102 PendingInfoBarRequests pending_infobar_requests_; |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 namespace { | 105 namespace { |
| 99 | 106 |
| 100 // This is the delegate used to display the confirmation info bar. | 107 // This is the delegate used to display the confirmation info bar. |
| 101 class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { | 108 class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 102 public: | 109 public: |
| 103 GeolocationConfirmInfoBarDelegate( | 110 GeolocationConfirmInfoBarDelegate( |
| 104 TabContents* tab_contents, GeolocationInfoBarQueueController* controller, | 111 TabContents* tab_contents, |
| 105 int render_process_id, int render_view_id, int bridge_id, | 112 GeolocationInfoBarQueueController* controller, |
| 113 int render_process_id, |
| 114 int render_view_id, |
| 115 int bridge_id, |
| 106 const GURL& requesting_frame_url, | 116 const GURL& requesting_frame_url, |
| 107 const std::string& display_languages) | 117 const std::string& display_languages) |
| 108 : ConfirmInfoBarDelegate(tab_contents), | 118 : ConfirmInfoBarDelegate(tab_contents), |
| 109 tab_contents_(tab_contents), | 119 tab_contents_(tab_contents), |
| 110 controller_(controller), | 120 controller_(controller), |
| 111 render_process_id_(render_process_id), | 121 render_process_id_(render_process_id), |
| 112 render_view_id_(render_view_id), | 122 render_view_id_(render_view_id), |
| 113 bridge_id_(bridge_id), | 123 bridge_id_(bridge_id), |
| 114 requesting_frame_url_(requesting_frame_url), | 124 requesting_frame_url_(requesting_frame_url), |
| 115 display_languages_(display_languages) { | 125 display_languages_(display_languages) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 GeolocationPermissionContext* geolocation_permission_context, | 220 GeolocationPermissionContext* geolocation_permission_context, |
| 211 Profile* profile) | 221 Profile* profile) |
| 212 : geolocation_permission_context_(geolocation_permission_context), | 222 : geolocation_permission_context_(geolocation_permission_context), |
| 213 profile_(profile) { | 223 profile_(profile) { |
| 214 } | 224 } |
| 215 | 225 |
| 216 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { | 226 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { |
| 217 } | 227 } |
| 218 | 228 |
| 219 void GeolocationInfoBarQueueController::CreateInfoBarRequest( | 229 void GeolocationInfoBarQueueController::CreateInfoBarRequest( |
| 220 int render_process_id, int render_view_id, int bridge_id, | 230 int render_process_id, |
| 221 const GURL& requesting_frame, const GURL& embedder) { | 231 int render_view_id, |
| 232 int bridge_id, |
| 233 const GURL& requesting_frame, |
| 234 const GURL& embedder) { |
| 222 // This makes sure that no duplicates are added to | 235 // This makes sure that no duplicates are added to |
| 223 // |pending_infobar_requests_| as an artificial permission request may | 236 // |pending_infobar_requests_| as an artificial permission request may |
| 224 // already exist in the queue as per | 237 // already exist in the queue as per |
| 225 // GeolocationPermissionContext::StartUpdatingRequested | 238 // GeolocationPermissionContext::StartUpdatingRequested |
| 226 // See http://crbug.com/51899 for more details. | 239 // See http://crbug.com/51899 for more details. |
| 227 // TODO(joth): Once we have CLIENT_BASED_GEOLOCATION and | 240 // TODO(joth): Once we have CLIENT_BASED_GEOLOCATION and |
| 228 // WTF_USE_PREEMPT_GEOLOCATION_PERMISSION set in WebKit we should be able to | 241 // WTF_USE_PREEMPT_GEOLOCATION_PERMISSION set in WebKit we should be able to |
| 229 // just use a DCHECK to check if a duplicate is attempting to be added. | 242 // just use a DCHECK to check if a duplicate is attempting to be added. |
| 230 PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 243 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
| 231 while (i != pending_infobar_requests_.end()) { | 244 i != pending_infobar_requests_.end(); ++i) { |
| 232 if (i->Equals(render_process_id, render_view_id, bridge_id)) { | 245 if (i->Equals(render_process_id, render_view_id, bridge_id)) { |
| 233 // The request already exists. | 246 // The request already exists. |
| 234 DCHECK(i->IsForPair(requesting_frame, embedder)); | 247 DCHECK(i->IsForPair(requesting_frame, embedder)); |
| 235 return; | 248 return; |
| 236 } | 249 } |
| 237 ++i; | |
| 238 } | 250 } |
| 239 PendingInfoBarRequest pending_infobar_request; | 251 PendingInfoBarRequest pending_infobar_request; |
| 240 pending_infobar_request.render_process_id = render_process_id; | 252 pending_infobar_request.render_process_id = render_process_id; |
| 241 pending_infobar_request.render_view_id = render_view_id; | 253 pending_infobar_request.render_view_id = render_view_id; |
| 242 pending_infobar_request.bridge_id = bridge_id; | 254 pending_infobar_request.bridge_id = bridge_id; |
| 243 pending_infobar_request.requesting_frame = requesting_frame; | 255 pending_infobar_request.requesting_frame = requesting_frame; |
| 244 pending_infobar_request.embedder = embedder; | 256 pending_infobar_request.embedder = embedder; |
| 245 pending_infobar_request.infobar_delegate = NULL; | 257 pending_infobar_request.infobar_delegate = NULL; |
| 246 pending_infobar_requests_.push_back(pending_infobar_request); | 258 pending_infobar_requests_.push_back(pending_infobar_request); |
| 247 ShowQueuedInfoBar(render_process_id, render_view_id); | 259 ShowQueuedInfoBar(render_process_id, render_view_id); |
| 248 } | 260 } |
| 249 | 261 |
| 250 void GeolocationInfoBarQueueController::CancelInfoBarRequest( | 262 void GeolocationInfoBarQueueController::CancelInfoBarRequest( |
| 251 int render_process_id, int render_view_id, int bridge_id) { | 263 int render_process_id, |
| 252 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 264 int render_view_id, |
| 253 i != pending_infobar_requests_.end(); ++i) { | 265 int bridge_id) { |
| 254 if (i->Equals(render_process_id, render_view_id, bridge_id)) { | 266 for (size_t i = 0; i < pending_infobar_requests_.size(); ++i) { |
| 267 if (pending_infobar_requests_[i].Equals(render_process_id, render_view_id, |
| 268 bridge_id)) { |
| 255 CancelInfoBarRequestInternal(i); | 269 CancelInfoBarRequestInternal(i); |
| 256 break; | 270 return; |
| 257 } | 271 } |
| 258 } | 272 } |
| 259 } | 273 } |
| 260 | 274 |
| 261 void GeolocationInfoBarQueueController::OnInfoBarClosed( | 275 void GeolocationInfoBarQueueController::OnInfoBarClosed(int render_process_id, |
| 262 int render_process_id, int render_view_id, int bridge_id) { | 276 int render_view_id, |
| 277 int bridge_id) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 279 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
| 265 i != pending_infobar_requests_.end(); ++i) { | 280 i != pending_infobar_requests_.end(); ++i) { |
| 266 if (i->Equals(render_process_id, render_view_id, bridge_id)) { | 281 if (i->Equals(render_process_id, render_view_id, bridge_id)) { |
| 267 pending_infobar_requests_.erase(i); | 282 pending_infobar_requests_.erase(i); |
| 268 break; | 283 break; |
| 269 } | 284 } |
| 270 } | 285 } |
| 271 ShowQueuedInfoBar(render_process_id, render_view_id); | 286 ShowQueuedInfoBar(render_process_id, render_view_id); |
| 272 } | 287 } |
| 273 | 288 |
| 274 void GeolocationInfoBarQueueController::OnPermissionSet( | 289 void GeolocationInfoBarQueueController::OnPermissionSet( |
| 275 int render_process_id, int render_view_id, int bridge_id, | 290 int render_process_id, |
| 276 const GURL& requesting_frame, const GURL& embedder, bool allowed) { | 291 int render_view_id, |
| 292 int bridge_id, |
| 293 const GURL& requesting_frame, |
| 294 const GURL& embedder, |
| 295 bool allowed) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 278 // Persist the permission. | 297 // Persist the permission. |
| 279 ContentSetting content_setting = | 298 ContentSetting content_setting = |
| 280 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 299 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 281 profile_->GetGeolocationContentSettingsMap()->SetContentSetting( | 300 profile_->GetGeolocationContentSettingsMap()->SetContentSetting( |
| 282 requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting); | 301 requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting); |
| 283 | 302 |
| 284 // Now notify all pending requests that the permission has been set. | 303 // Now notify all pending requests that the permission has been set. |
| 285 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 304 for (size_t i = 0; i < pending_infobar_requests_.size(); ) { |
| 286 i != pending_infobar_requests_.end();) { | 305 PendingInfoBarRequest& request = pending_infobar_requests_[i]; |
| 287 if (i->IsForPair(requesting_frame, embedder)) { | 306 if (request.IsForPair(requesting_frame, embedder)) { |
| 288 // There was a pending request for the same [frame, embedder]. | 307 // There was a pending request for the same [frame, embedder]. |
| 289 if (i->Equals(render_process_id, render_view_id, bridge_id)) { | 308 if (request.Equals(render_process_id, render_view_id, bridge_id)) { |
| 290 // The request that set permission will be removed by TabContents | 309 // The request that set permission will be removed by TabContents |
| 291 // itself, that is, we should not try to cancel the infobar that has | 310 // itself, that is, we should not try to cancel the infobar that has |
| 292 // just notified us. | 311 // just notified us. |
| 293 i->infobar_delegate = NULL; | 312 request.infobar_delegate = NULL; |
| 294 } | 313 } |
| 295 // Cancel it first, and then notify the permission. | 314 // Cancel it first, and then notify the permission. |
| 296 // Note: if the pending request had an infobar, TabContents will | 315 // Note: if the pending request had an infobar, TabContents will |
| 297 // eventually close it and we will pump the queue via OnInfoBarClosed(). | 316 // eventually close it and we will pump the queue via OnInfoBarClosed(). |
| 298 PendingInfoBarRequest other_request = *i; | 317 PendingInfoBarRequest copied_request(request); |
| 299 i = CancelInfoBarRequestInternal(i); | 318 CancelInfoBarRequestInternal(i); // |request| is now garbage! |
| 300 geolocation_permission_context_->NotifyPermissionSet( | 319 geolocation_permission_context_->NotifyPermissionSet( |
| 301 other_request.render_process_id, other_request.render_view_id, | 320 copied_request.render_process_id, copied_request.render_view_id, |
| 302 other_request.bridge_id, other_request.requesting_frame, allowed); | 321 copied_request.bridge_id, copied_request.requesting_frame, allowed); |
| 303 } else { | 322 } else { |
| 304 ++i; | 323 ++i; |
| 305 } | 324 } |
| 306 } | 325 } |
| 307 } | 326 } |
| 308 | 327 |
| 309 void GeolocationInfoBarQueueController::ShowQueuedInfoBar( | 328 void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, |
| 310 int render_process_id, int render_view_id) { | 329 int render_view_id) { |
| 311 TabContents* tab_contents = | 330 TabContents* tab_contents = |
| 312 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 331 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 313 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 332 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
| 314 i != pending_infobar_requests_.end();) { | 333 i != pending_infobar_requests_.end(); ) { |
| 315 if (!i->IsForTab(render_process_id, render_view_id)) { | 334 if (!i->IsForTab(render_process_id, render_view_id)) { |
| 316 ++i; | 335 ++i; |
| 317 continue; | 336 continue; |
| 318 } | 337 } |
| 319 if (!tab_contents) { | 338 if (!tab_contents) { |
| 320 i = pending_infobar_requests_.erase(i); | 339 i = pending_infobar_requests_.erase(i); |
| 321 continue; | 340 continue; |
| 322 } | 341 } |
| 323 // Check if already displayed. | 342 // Check if already displayed. |
| 324 if (i->infobar_delegate) | 343 if (i->infobar_delegate) |
| 325 break; | 344 break; |
| 326 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate( | 345 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate( |
| 327 tab_contents, this, | 346 tab_contents, this, |
| 328 render_process_id, render_view_id, | 347 render_process_id, render_view_id, |
| 329 i->bridge_id, i->requesting_frame, | 348 i->bridge_id, i->requesting_frame, |
| 330 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 349 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 331 tab_contents->AddInfoBar(i->infobar_delegate); | 350 tab_contents->AddInfoBar(i->infobar_delegate); |
| 332 break; | 351 break; |
| 333 } | 352 } |
| 334 } | 353 } |
| 335 | 354 |
| 336 std::vector<GeolocationInfoBarQueueController::PendingInfoBarRequest>::iterator | 355 void GeolocationInfoBarQueueController::CancelInfoBarRequestInternal(size_t i) { |
| 337 GeolocationInfoBarQueueController::CancelInfoBarRequestInternal( | 356 const PendingInfoBarRequest& request = pending_infobar_requests_[i]; |
| 338 std::vector<PendingInfoBarRequest>::iterator i) { | 357 TabContents* tab_contents = tab_util::GetTabContentsByID( |
| 339 TabContents* tab_contents = | 358 request.render_process_id, request.render_view_id); |
| 340 tab_util::GetTabContentsByID(i->render_process_id, i->render_view_id); | 359 InfoBarDelegate* delegate = request.infobar_delegate; |
| 341 if (tab_contents && i->infobar_delegate) { | 360 if (tab_contents && delegate) { |
| 342 // TabContents will destroy the InfoBar, which will remove from our vector | 361 // TabContents will destroy the InfoBar, which will synchronously remove it |
| 343 // asynchronously. | 362 // from our vector, so we need to increment the iterator first. |
| 344 tab_contents->RemoveInfoBar(i->infobar_delegate); | 363 tab_contents->RemoveInfoBar(delegate); |
| 345 return ++i; | |
| 346 } else { | 364 } else { |
| 347 // Remove it directly from the pending vector. | 365 pending_infobar_requests_.erase(pending_infobar_requests_.begin() + i); |
| 348 return pending_infobar_requests_.erase(i); | |
| 349 } | 366 } |
| 350 } | 367 } |
| 351 | 368 |
| 352 GeolocationPermissionContext::GeolocationPermissionContext( | 369 GeolocationPermissionContext::GeolocationPermissionContext( |
| 353 Profile* profile) | 370 Profile* profile) |
| 354 : profile_(profile), | 371 : profile_(profile), |
| 355 ALLOW_THIS_IN_INITIALIZER_LIST( | 372 ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_infobar_queue_controller_( |
| 356 geolocation_infobar_queue_controller_( | 373 new GeolocationInfoBarQueueController(this, profile))) { |
| 357 new GeolocationInfoBarQueueController(this, profile))) { | |
| 358 } | 374 } |
| 359 | 375 |
| 360 GeolocationPermissionContext::~GeolocationPermissionContext() { | 376 GeolocationPermissionContext::~GeolocationPermissionContext() { |
| 361 } | 377 } |
| 362 | 378 |
| 363 void GeolocationPermissionContext::RequestGeolocationPermission( | 379 void GeolocationPermissionContext::RequestGeolocationPermission( |
| 364 int render_process_id, int render_view_id, int bridge_id, | 380 int render_process_id, |
| 381 int render_view_id, |
| 382 int bridge_id, |
| 365 const GURL& requesting_frame) { | 383 const GURL& requesting_frame) { |
| 366 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 384 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 367 BrowserThread::PostTask( | 385 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( |
| 368 BrowserThread::UI, FROM_HERE, | 386 this, &GeolocationPermissionContext::RequestGeolocationPermission, |
| 369 NewRunnableMethod(this, | 387 render_process_id, render_view_id, bridge_id, requesting_frame)); |
| 370 &GeolocationPermissionContext::RequestGeolocationPermission, | |
| 371 render_process_id, render_view_id, bridge_id, requesting_frame)); | |
| 372 return; | 388 return; |
| 373 } | 389 } |
| 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 375 | 391 |
| 376 ExtensionsService* extensions = profile_->GetExtensionsService(); | 392 ExtensionsService* extensions = profile_->GetExtensionsService(); |
| 377 if (extensions) { | 393 if (extensions) { |
| 378 const Extension* ext = extensions->GetExtensionByURL(requesting_frame); | 394 const Extension* ext = extensions->GetExtensionByURL(requesting_frame); |
| 379 if (!ext) | 395 if (!ext) |
| 380 ext = extensions->GetExtensionByWebExtent(requesting_frame); | 396 ext = extensions->GetExtensionByWebExtent(requesting_frame); |
| 381 if (ext && ext->HasApiPermission(Extension::kGeolocationPermission)) { | 397 if (ext && ext->HasApiPermission(Extension::kGeolocationPermission)) { |
| 382 ExtensionProcessManager* epm = profile_->GetExtensionProcessManager(); | 398 ExtensionProcessManager* epm = profile_->GetExtensionProcessManager(); |
| 383 RenderProcessHost* process = epm->GetExtensionProcess(requesting_frame); | 399 RenderProcessHost* process = epm->GetExtensionProcess(requesting_frame); |
| 384 if (process && process->id() == render_process_id) { | 400 if (process && process->id() == render_process_id) { |
| 385 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 401 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 386 requesting_frame, true); | 402 requesting_frame, true); |
| 387 return; | 403 return; |
| 388 } | 404 } |
| 389 } | 405 } |
| 390 } | 406 } |
| 391 | 407 |
| 392 TabContents* tab_contents = | 408 TabContents* tab_contents = |
| 393 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 409 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 394 if (!tab_contents) { | 410 if (!tab_contents) { |
| 395 // The tab may have gone away, or the request may not be from a tab at all. | 411 // The tab may have gone away, or the request may not be from a tab at all. |
| 396 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " | 412 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| 397 << render_process_id << "," << render_view_id << "," << bridge_id | 413 << render_process_id << "," << render_view_id << "," |
| 398 << " (can't prompt user without a visible tab)"; | 414 << bridge_id << " (can't prompt user without a visible tab)"; |
| 399 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 415 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 400 requesting_frame, false); | 416 requesting_frame, false); |
| 401 return; | 417 return; |
| 402 } | 418 } |
| 403 | 419 |
| 404 GURL embedder = tab_contents->GetURL(); | 420 GURL embedder = tab_contents->GetURL(); |
| 405 if (!requesting_frame.is_valid() || !embedder.is_valid()) { | 421 if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
| 406 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " | 422 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
| 407 << requesting_frame << "," << embedder | 423 << requesting_frame << "," << embedder |
| 408 << " (geolocation is not supported in popups)"; | 424 << " (geolocation is not supported in popups)"; |
| 409 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 425 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 410 requesting_frame, false); | 426 requesting_frame, false); |
| 411 return; | 427 return; |
| 412 } | 428 } |
| 413 | 429 |
| 414 ContentSetting content_setting = | 430 ContentSetting content_setting = |
| 415 profile_->GetGeolocationContentSettingsMap()->GetContentSetting( | 431 profile_->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 416 requesting_frame, embedder); | 432 requesting_frame, embedder); |
| 417 if (content_setting == CONTENT_SETTING_BLOCK) { | 433 if (content_setting == CONTENT_SETTING_BLOCK) { |
| 418 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 434 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 419 requesting_frame, false); | 435 requesting_frame, false); |
| 420 } else if (content_setting == CONTENT_SETTING_ALLOW) { | 436 } else if (content_setting == CONTENT_SETTING_ALLOW) { |
| 421 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 437 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 422 requesting_frame, true); | 438 requesting_frame, true); |
| 423 } else { // setting == ask. Prompt the user. | 439 } else { // setting == ask. Prompt the user. |
| 424 geolocation_infobar_queue_controller_->CreateInfoBarRequest( | 440 geolocation_infobar_queue_controller_->CreateInfoBarRequest( |
| 425 render_process_id, render_view_id, bridge_id, requesting_frame, | 441 render_process_id, render_view_id, bridge_id, requesting_frame, |
| 426 embedder); | 442 embedder); |
| 427 } | 443 } |
| 428 } | 444 } |
| 429 | 445 |
| 430 void GeolocationPermissionContext::CancelGeolocationPermissionRequest( | 446 void GeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| 431 int render_process_id, int render_view_id, int bridge_id, | 447 int render_process_id, |
| 448 int render_view_id, |
| 449 int bridge_id, |
| 432 const GURL& requesting_frame) { | 450 const GURL& requesting_frame) { |
| 433 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); | 451 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); |
| 434 } | 452 } |
| 435 | 453 |
| 436 void GeolocationPermissionContext::StartUpdatingRequested( | 454 void GeolocationPermissionContext::StartUpdatingRequested( |
| 437 int render_process_id, int render_view_id, int bridge_id, | 455 int render_process_id, |
| 456 int render_view_id, |
| 457 int bridge_id, |
| 438 const GURL& requesting_frame) { | 458 const GURL& requesting_frame) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 440 // Note we cannot store the arbitrator as a member as it is not thread safe. | 460 // Note we cannot store the arbitrator as a member as it is not thread safe. |
| 441 GeolocationProvider* provider = GeolocationProvider::GetInstance(); | 461 GeolocationProvider* provider = GeolocationProvider::GetInstance(); |
| 442 | 462 |
| 443 // WebKit will not request permission until it has received a valid | 463 // WebKit will not request permission until it has received a valid |
| 444 // location, but the google network location provider will not give a | 464 // location, but the google network location provider will not give a |
| 445 // valid location until the user has granted permission. So we cut the Gordian | 465 // valid location until the user has granted permission. So we cut the Gordian |
| 446 // Knot by reusing the the 'start updating' request to also trigger | 466 // Knot by reusing the the 'start updating' request to also trigger |
| 447 // a 'permission request' should the provider still be awaiting permission. | 467 // a 'permission request' should the provider still be awaiting permission. |
| 448 if (!provider->HasPermissionBeenGranted()) { | 468 if (!provider->HasPermissionBeenGranted()) { |
| 449 RequestGeolocationPermission(render_process_id, render_view_id, bridge_id, | 469 RequestGeolocationPermission(render_process_id, render_view_id, bridge_id, |
| 450 requesting_frame); | 470 requesting_frame); |
| 451 } | 471 } |
| 452 } | 472 } |
| 453 | 473 |
| 454 void GeolocationPermissionContext::StopUpdatingRequested( | 474 void GeolocationPermissionContext::StopUpdatingRequested( |
| 455 int render_process_id, int render_view_id, int bridge_id) { | 475 int render_process_id, |
| 476 int render_view_id, |
| 477 int bridge_id) { |
| 456 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); | 478 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); |
| 457 } | 479 } |
| 458 | 480 |
| 459 void GeolocationPermissionContext::NotifyPermissionSet( | 481 void GeolocationPermissionContext::NotifyPermissionSet( |
| 460 int render_process_id, int render_view_id, int bridge_id, | 482 int render_process_id, |
| 461 const GURL& requesting_frame, bool allowed) { | 483 int render_view_id, |
| 484 int bridge_id, |
| 485 const GURL& requesting_frame, |
| 486 bool allowed) { |
| 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 463 | 488 |
| 464 TabContents* tab_contents = | 489 TabContents* tab_contents = |
| 465 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 490 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 466 | 491 |
| 467 // TabContents may have gone away (or not exists for extension). | 492 // TabContents may have gone away (or not exists for extension). |
| 468 if (tab_contents) { | 493 if (tab_contents) { |
| 469 TabSpecificContentSettings* content_settings = | 494 TabSpecificContentSettings* content_settings = |
| 470 tab_contents->GetTabSpecificContentSettings(); | 495 tab_contents->GetTabSpecificContentSettings(); |
| 471 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), | 496 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), |
| 472 allowed); | 497 allowed); |
| 473 } | 498 } |
| 474 | 499 |
| 475 CallRenderViewHost( | 500 CallRenderViewHost(render_process_id, render_view_id, &RenderViewHost::Send, |
| 476 render_process_id, render_view_id, | |
| 477 &RenderViewHost::Send, | |
| 478 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, | 501 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, |
| 479 allowed)); | 502 allowed)); |
| 480 if (allowed) { | 503 if (allowed) { |
| 481 BrowserThread::PostTask( | 504 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableMethod( |
| 482 BrowserThread::IO, FROM_HERE, | 505 this, &GeolocationPermissionContext::NotifyArbitratorPermissionGranted, |
| 483 NewRunnableMethod(this, | 506 requesting_frame)); |
| 484 &GeolocationPermissionContext::NotifyArbitratorPermissionGranted, | |
| 485 requesting_frame)); | |
| 486 } | 507 } |
| 487 } | 508 } |
| 488 | 509 |
| 489 void GeolocationPermissionContext::NotifyArbitratorPermissionGranted( | 510 void GeolocationPermissionContext::NotifyArbitratorPermissionGranted( |
| 490 const GURL& requesting_frame) { | 511 const GURL& requesting_frame) { |
| 491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 492 GeolocationProvider::GetInstance()->OnPermissionGranted(requesting_frame); | 513 GeolocationProvider::GetInstance()->OnPermissionGranted(requesting_frame); |
| 493 } | 514 } |
| 494 | 515 |
| 495 void GeolocationPermissionContext::CancelPendingInfoBarRequest( | 516 void GeolocationPermissionContext::CancelPendingInfoBarRequest( |
| 496 int render_process_id, int render_view_id, int bridge_id) { | 517 int render_process_id, |
| 518 int render_view_id, |
| 519 int bridge_id) { |
| 497 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 520 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 498 BrowserThread::PostTask( | 521 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( |
| 499 BrowserThread::UI, FROM_HERE, | 522 this, &GeolocationPermissionContext::CancelPendingInfoBarRequest, |
| 500 NewRunnableMethod(this, | 523 render_process_id, render_view_id, bridge_id)); |
| 501 &GeolocationPermissionContext::CancelPendingInfoBarRequest, | |
| 502 render_process_id, render_view_id, bridge_id)); | |
| 503 return; | 524 return; |
| 504 } | 525 } |
| 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 506 geolocation_infobar_queue_controller_->CancelInfoBarRequest( | 527 geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id, |
| 507 render_process_id, render_view_id, bridge_id); | 528 render_view_id, bridge_id); |
| 508 } | 529 } |
| OLD | NEW |