| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
| 4 * Copyright 2010, The Android Open Source Project | 4 * Copyright 2010, The Android Open Source Project |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 m_timer.stop(); | 112 m_timer.stop(); |
| 113 m_timer.startOneShot(0, FROM_HERE); | 113 m_timer.startOneShot(0, FROM_HERE); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void Geolocation::GeoNotifier::setUseCachedPosition() | 116 void Geolocation::GeoNotifier::setUseCachedPosition() |
| 117 { | 117 { |
| 118 m_useCachedPosition = true; | 118 m_useCachedPosition = true; |
| 119 m_timer.startOneShot(0, FROM_HERE); | 119 m_timer.startOneShot(0, FROM_HERE); |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool Geolocation::GeoNotifier::hasZeroTimeout() const | |
| 123 { | |
| 124 return m_options->hasTimeout() && m_options->timeout() == 0; | |
| 125 } | |
| 126 | |
| 127 void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) | 122 void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) |
| 128 { | 123 { |
| 129 // If we are here and the Geolocation permission is not approved, something
has | 124 // If we are here and the Geolocation permission is not approved, something
has |
| 130 // gone horribly wrong. | 125 // gone horribly wrong. |
| 131 if (!m_geolocation->isAllowed()) | 126 if (!m_geolocation->isAllowed()) |
| 132 CRASH(); | 127 CRASH(); |
| 133 | 128 |
| 134 m_successCallback->handleEvent(position); | 129 m_successCallback->handleEvent(position); |
| 135 } | 130 } |
| 136 | 131 |
| 137 void Geolocation::GeoNotifier::runErrorCallback(PositionError* error) | 132 void Geolocation::GeoNotifier::runErrorCallback(PositionError* error) |
| 138 { | 133 { |
| 139 if (m_errorCallback) | 134 if (m_errorCallback) |
| 140 m_errorCallback->handleEvent(error); | 135 m_errorCallback->handleEvent(error); |
| 141 } | 136 } |
| 142 | 137 |
| 143 void Geolocation::GeoNotifier::startTimerIfNeeded() | 138 void Geolocation::GeoNotifier::startTimer() |
| 144 { | 139 { |
| 145 if (m_options->hasTimeout()) | 140 m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE); |
| 146 m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE); | |
| 147 } | 141 } |
| 148 | 142 |
| 149 void Geolocation::GeoNotifier::stopTimer() | 143 void Geolocation::GeoNotifier::stopTimer() |
| 150 { | 144 { |
| 151 m_timer.stop(); | 145 m_timer.stop(); |
| 152 } | 146 } |
| 153 | 147 |
| 154 void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*) | 148 void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*) |
| 155 { | 149 { |
| 156 m_timer.stop(); | 150 m_timer.stop(); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 337 } |
| 344 | 338 |
| 345 void Geolocation::startRequest(GeoNotifier *notifier) | 339 void Geolocation::startRequest(GeoNotifier *notifier) |
| 346 { | 340 { |
| 347 // Check whether permissions have already been denied. Note that if this is
the case, | 341 // Check whether permissions have already been denied. Note that if this is
the case, |
| 348 // the permission state can not change again in the lifetime of this page. | 342 // the permission state can not change again in the lifetime of this page. |
| 349 if (isDenied()) | 343 if (isDenied()) |
| 350 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_
DENIED, permissionDeniedErrorMessage)); | 344 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_
DENIED, permissionDeniedErrorMessage)); |
| 351 else if (haveSuitableCachedPosition(notifier->options())) | 345 else if (haveSuitableCachedPosition(notifier->options())) |
| 352 notifier->setUseCachedPosition(); | 346 notifier->setUseCachedPosition(); |
| 353 else if (notifier->hasZeroTimeout()) | 347 else if (!notifier->options()->timeout()) |
| 354 notifier->startTimerIfNeeded(); | 348 notifier->startTimer(); |
| 355 else if (!isAllowed()) { | 349 else if (!isAllowed()) { |
| 356 // if we don't yet have permission, request for permission before callin
g startUpdating() | 350 // if we don't yet have permission, request for permission before callin
g startUpdating() |
| 357 m_pendingForPermissionNotifiers.add(notifier); | 351 m_pendingForPermissionNotifiers.add(notifier); |
| 358 requestPermission(); | 352 requestPermission(); |
| 359 } else if (startUpdating(notifier)) | 353 } else if (startUpdating(notifier)) |
| 360 notifier->startTimerIfNeeded(); | 354 notifier->startTimer(); |
| 361 else | 355 else |
| 362 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN
AVAILABLE, failedToStartServiceErrorMessage)); | 356 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN
AVAILABLE, failedToStartServiceErrorMessage)); |
| 363 } | 357 } |
| 364 | 358 |
| 365 void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) | 359 void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) |
| 366 { | 360 { |
| 367 // This request has failed fatally. Remove it from our lists. | 361 // This request has failed fatally. Remove it from our lists. |
| 368 m_oneShots.remove(notifier); | 362 m_oneShots.remove(notifier); |
| 369 m_watchers.remove(notifier); | 363 m_watchers.remove(notifier); |
| 370 | 364 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 401 GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end(); | 395 GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end(); |
| 402 for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.
begin(); iter != end; ++iter) { | 396 for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.
begin(); iter != end; ++iter) { |
| 403 GeoNotifier* notifier = iter->get(); | 397 GeoNotifier* notifier = iter->get(); |
| 404 notifier->runSuccessCallback(lastPosition()); | 398 notifier->runSuccessCallback(lastPosition()); |
| 405 | 399 |
| 406 // If this is a one-shot request, stop it. Otherwise, if the watch still | 400 // If this is a one-shot request, stop it. Otherwise, if the watch still |
| 407 // exists, start the service to get updates. | 401 // exists, start the service to get updates. |
| 408 if (m_oneShots.contains(notifier)) | 402 if (m_oneShots.contains(notifier)) |
| 409 m_oneShots.remove(notifier); | 403 m_oneShots.remove(notifier); |
| 410 else if (m_watchers.contains(notifier)) { | 404 else if (m_watchers.contains(notifier)) { |
| 411 if (notifier->hasZeroTimeout() || startUpdating(notifier)) | 405 if (!notifier->options()->timeout() || startUpdating(notifier)) |
| 412 notifier->startTimerIfNeeded(); | 406 notifier->startTimer(); |
| 413 else | 407 else |
| 414 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); | 408 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
| 415 } | 409 } |
| 416 } | 410 } |
| 417 | 411 |
| 418 m_requestsAwaitingCachedPosition.clear(); | 412 m_requestsAwaitingCachedPosition.clear(); |
| 419 | 413 |
| 420 if (!hasListeners()) | 414 if (!hasListeners()) |
| 421 stopUpdating(); | 415 stopUpdating(); |
| 422 } | 416 } |
| 423 | 417 |
| 424 void Geolocation::requestTimedOut(GeoNotifier* notifier) | 418 void Geolocation::requestTimedOut(GeoNotifier* notifier) |
| 425 { | 419 { |
| 426 // If this is a one-shot request, stop it. | 420 // If this is a one-shot request, stop it. |
| 427 m_oneShots.remove(notifier); | 421 m_oneShots.remove(notifier); |
| 428 | 422 |
| 429 if (!hasListeners()) | 423 if (!hasListeners()) |
| 430 stopUpdating(); | 424 stopUpdating(); |
| 431 } | 425 } |
| 432 | 426 |
| 433 bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) | 427 bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) |
| 434 { | 428 { |
| 435 Geoposition* cachedPosition = lastPosition(); | 429 Geoposition* cachedPosition = lastPosition(); |
| 436 if (!cachedPosition) | 430 if (!cachedPosition) |
| 437 return false; | 431 return false; |
| 438 if (!options->hasMaximumAge()) | |
| 439 return true; | |
| 440 if (!options->maximumAge()) | 432 if (!options->maximumAge()) |
| 441 return false; | 433 return false; |
| 442 DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime())
; | 434 DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime())
; |
| 443 return cachedPosition->timestamp() > currentTimeMillis - options->maximumAge
(); | 435 return cachedPosition->timestamp() > currentTimeMillis - options->maximumAge
(); |
| 444 } | 436 } |
| 445 | 437 |
| 446 void Geolocation::clearWatch(int watchID) | 438 void Geolocation::clearWatch(int watchID) |
| 447 { | 439 { |
| 448 if (watchID <= 0) | 440 if (watchID <= 0) |
| 449 return; | 441 return; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 // While we iterate through the list, we need not worry about list being mod
ified as the permission | 683 // While we iterate through the list, we need not worry about list being mod
ified as the permission |
| 692 // is already set to Yes/No and no new listeners will be added to the pendin
g list | 684 // is already set to Yes/No and no new listeners will be added to the pendin
g list |
| 693 GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end(); | 685 GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end(); |
| 694 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.b
egin(); iter != end; ++iter) { | 686 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.b
egin(); iter != end; ++iter) { |
| 695 GeoNotifier* notifier = iter->get(); | 687 GeoNotifier* notifier = iter->get(); |
| 696 | 688 |
| 697 if (isAllowed()) { | 689 if (isAllowed()) { |
| 698 // start all pending notification requests as permission granted. | 690 // start all pending notification requests as permission granted. |
| 699 // The notifier is always ref'ed by m_oneShots or m_watchers. | 691 // The notifier is always ref'ed by m_oneShots or m_watchers. |
| 700 if (startUpdating(notifier)) | 692 if (startUpdating(notifier)) |
| 701 notifier->startTimerIfNeeded(); | 693 notifier->startTimer(); |
| 702 else | 694 else |
| 703 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); | 695 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
| 704 } else { | 696 } else { |
| 705 notifier->setFatalError(PositionError::create(PositionError::PERMISS
ION_DENIED, permissionDeniedErrorMessage)); | 697 notifier->setFatalError(PositionError::create(PositionError::PERMISS
ION_DENIED, permissionDeniedErrorMessage)); |
| 706 } | 698 } |
| 707 } | 699 } |
| 708 } | 700 } |
| 709 | 701 |
| 710 } // namespace WebCore | 702 } // namespace WebCore |
| OLD | NEW |