276 // the permission state can not change again in the lifetime of this page. |
276 // the permission state can not change again in the lifetime of this page. |
277 if (isDenied()) |
277 if (isDenied()) |
278 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); |
278 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); |
279 else if (haveSuitableCachedPosition(notifier->m_options.get())) |
279 else if (haveSuitableCachedPosition(notifier->m_options.get())) |
280 notifier->setUseCachedPosition(); |
280 notifier->setUseCachedPosition(); |
281 else if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) { |
281 else if (notifier->hasZeroTimeout()) |
|
282 notifier->startTimerIfNeeded(); |
282 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
283 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
283 // Only start timer if we're not waiting for user permission. |
284 else if (!isAllowed()) { |
284 if (!m_startRequestPermissionNotifier) |
285 // if we don't yet have permission, request for permission before calling startUpdating() |
285 #endif |
286 m_pendingForPermissionNotifiers.add(notifier); |
286 notifier->startTimerIfNeeded(); |
287 requestPermission(); |
287 } else |
288 } |
|
289 #endif |
|
290 else if (startUpdating(notifier.get())) |
|
291 notifier->startTimerIfNeeded(); |
|
292 else |
288 notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
293 notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
289 |
294 |
290 return notifier.release(); |
295 return notifier.release(); |
291 } |
296 } |
292 |
297 |
399 // This may be due to either a new position from the service, or a cached |
404 // This may be due to either a new position from the service, or a cached |
400 // position. |
405 // position. |
401 m_allowGeolocation = allowed ? Yes : No; |
406 m_allowGeolocation = allowed ? Yes : No; |
402 |
407 |
403 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
408 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
404 if (m_startRequestPermissionNotifier) { |
409 // Permission request was made during the startRequest process |
405 if (isAllowed()) { |
410 if (!m_pendingForPermissionNotifiers.isEmpty()) { |
406 // Permission request was made during the startUpdating process |
411 handlePendingPermissionNotifiers(); |
407 m_startRequestPermissionNotifier->startTimerIfNeeded(); |
412 m_pendingForPermissionNotifiers.clear(); |
408 m_startRequestPermissionNotifier = 0; |
|
409 #if ENABLE(CLIENT_BASED_GEOLOCATION) |
|
410 if (!m_frame) |
|
411 return; |
|
412 Page* page = m_frame->page(); |
|
413 if (!page) |
|
414 return; |
|
415 page->geolocationController()->addObserver(this); |
|
416 #else |
|
417 // TODO: Handle startUpdate() for non-client based implementations using pre-emptive policy |
|
418 #endif |
|
419 } else { |
|
420 m_startRequestPermissionNotifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); |
|
421 m_oneShots.add(m_startRequestPermissionNotifier); |
|
422 m_startRequestPermissionNotifier = 0; |
|
423 } |
|
424 return; |
413 return; |
425 } |
414 } |
426 #endif |
415 #endif |
427 |
416 |
428 if (!isAllowed()) { |
417 if (!isAllowed()) { |
614 |
603 |
615 #endif |
604 #endif |
616 |
605 |
617 bool Geolocation::startUpdating(GeoNotifier* notifier) |
606 bool Geolocation::startUpdating(GeoNotifier* notifier) |
618 { |
607 { |
619 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
|
620 if (!isAllowed()) { |
|
621 m_startRequestPermissionNotifier = notifier; |
|
622 requestPermission(); |
|
623 return true; |
|
624 } |
|
625 #endif |
|
626 |
|
627 #if ENABLE(CLIENT_BASED_GEOLOCATION) |
608 #if ENABLE(CLIENT_BASED_GEOLOCATION) |
628 if (!m_frame) |
609 if (!m_frame) |
629 return false; |
610 return false; |
630 |
611 |
631 Page* page = m_frame->page(); |
612 Page* page = m_frame->page(); |
632 if (!page) |
613 if (!page) |
633 return false; |
614 return false; |
634 |
615 |
635 // FIXME: Pass options to client. |
616 page->geolocationController()->addObserver(this, notifier->m_options->enableHighAccuracy()); |
636 page->geolocationController()->addObserver(this); |
|
637 return true; |
617 return true; |
638 #else |
618 #else |
639 return m_service->startUpdating(notifier->m_options.get()); |
619 return m_service->startUpdating(notifier->m_options.get()); |
640 #endif |
620 #endif |
641 } |
621 } |
655 m_service->stopUpdating(); |
635 m_service->stopUpdating(); |
656 #endif |
636 #endif |
657 |
637 |
658 } |
638 } |
659 |
639 |
|
640 #if USE(PREEMPT_GEOLOCATION_PERMISSION) |
|
641 void Geolocation::handlePendingPermissionNotifiers() |
|
642 { |
|
643 // While we iterate through the list, we need not worry about list being modified as the permission |
|
644 // is already set to Yes/No and no new listeners will be added to the pending list |
|
645 GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end(); |
|
646 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.begin(); iter != end; ++iter) { |
|
647 GeoNotifier* notifier = iter->get(); |
|
648 |
|
649 if (isAllowed()) { |
|
650 // start all pending notification requests as permission granted. |
|
651 // The notifier is always ref'ed by m_oneShots or m_watchers. |
|
652 if (startUpdating(notifier)) |
|
653 notifier->startTimerIfNeeded(); |
|
654 else |
|
655 notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
|
656 } else |
|
657 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); |
|
658 } |
|
659 } |
|
660 #endif |
|
661 |
660 } // namespace WebCore |
662 } // namespace WebCore |
661 |
663 |
662 #else |
664 #else |
663 |
665 |
664 namespace WebCore { |
666 namespace WebCore { |