| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 code = PositionError::PERMISSION_DENIED; | 72 code = PositionError::PERMISSION_DENIED; |
| 73 break; | 73 break; |
| 74 case GeolocationError::PositionUnavailable: | 74 case GeolocationError::PositionUnavailable: |
| 75 code = PositionError::POSITION_UNAVAILABLE; | 75 code = PositionError::POSITION_UNAVAILABLE; |
| 76 break; | 76 break; |
| 77 } | 77 } |
| 78 | 78 |
| 79 return PositionError::create(code, error->message()); | 79 return PositionError::create(code, error->message()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<Posit
ionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, P
ositionOptions* options) | |
| 83 : m_geolocation(geolocation) | |
| 84 , m_successCallback(successCallback) | |
| 85 , m_errorCallback(errorCallback) | |
| 86 , m_options(options) | |
| 87 , m_timer(this, &Geolocation::GeoNotifier::timerFired) | |
| 88 , m_useCachedPosition(false) | |
| 89 { | |
| 90 ASSERT(m_geolocation); | |
| 91 ASSERT(m_successCallback); | |
| 92 // If no options were supplied from JS, we should have created a default set | |
| 93 // of options in JSGeolocationCustom.cpp. | |
| 94 ASSERT(m_options); | |
| 95 } | |
| 96 | |
| 97 void Geolocation::GeoNotifier::trace(Visitor* visitor) | |
| 98 { | |
| 99 visitor->trace(m_geolocation); | |
| 100 visitor->trace(m_options); | |
| 101 visitor->trace(m_fatalError); | |
| 102 } | |
| 103 | |
| 104 void Geolocation::GeoNotifier::setFatalError(PositionError* error) | |
| 105 { | |
| 106 // If a fatal error has already been set, stick with it. This makes sure tha
t | |
| 107 // when permission is denied, this is the error reported, as required by the | |
| 108 // spec. | |
| 109 if (m_fatalError) | |
| 110 return; | |
| 111 | |
| 112 m_fatalError = error; | |
| 113 // An existing timer may not have a zero timeout. | |
| 114 m_timer.stop(); | |
| 115 m_timer.startOneShot(0, FROM_HERE); | |
| 116 } | |
| 117 | |
| 118 void Geolocation::GeoNotifier::setUseCachedPosition() | |
| 119 { | |
| 120 m_useCachedPosition = true; | |
| 121 m_timer.startOneShot(0, FROM_HERE); | |
| 122 } | |
| 123 | |
| 124 void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) | |
| 125 { | |
| 126 // If we are here and the Geolocation permission is not approved, something
has | |
| 127 // gone horribly wrong. | |
| 128 if (!m_geolocation->isAllowed()) | |
| 129 CRASH(); | |
| 130 | |
| 131 m_successCallback->handleEvent(position); | |
| 132 } | |
| 133 | |
| 134 void Geolocation::GeoNotifier::runErrorCallback(PositionError* error) | |
| 135 { | |
| 136 if (m_errorCallback) | |
| 137 m_errorCallback->handleEvent(error); | |
| 138 } | |
| 139 | |
| 140 void Geolocation::GeoNotifier::startTimer() | |
| 141 { | |
| 142 m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE); | |
| 143 } | |
| 144 | |
| 145 void Geolocation::GeoNotifier::stopTimer() | |
| 146 { | |
| 147 m_timer.stop(); | |
| 148 } | |
| 149 | |
| 150 void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*) | |
| 151 { | |
| 152 m_timer.stop(); | |
| 153 | |
| 154 // Test for fatal error first. This is required for the case where the Local
Frame is | |
| 155 // disconnected and requests are cancelled. | |
| 156 if (m_fatalError) { | |
| 157 runErrorCallback(m_fatalError.get()); | |
| 158 // This will cause this notifier to be deleted. | |
| 159 m_geolocation->fatalErrorOccurred(this); | |
| 160 return; | |
| 161 } | |
| 162 | |
| 163 if (m_useCachedPosition) { | |
| 164 // Clear the cached position flag in case this is a watch request, which | |
| 165 // will continue to run. | |
| 166 m_useCachedPosition = false; | |
| 167 m_geolocation->requestUsesCachedPosition(this); | |
| 168 return; | |
| 169 } | |
| 170 | |
| 171 if (m_errorCallback) | |
| 172 m_errorCallback->handleEvent(PositionError::create(PositionError::TIMEOU
T, "Timeout expired")); | |
| 173 m_geolocation->requestTimedOut(this); | |
| 174 } | |
| 175 | |
| 176 void Geolocation::Watchers::trace(Visitor* visitor) | 82 void Geolocation::Watchers::trace(Visitor* visitor) |
| 177 { | 83 { |
| 178 visitor->trace(m_idToNotifierMap); | 84 visitor->trace(m_idToNotifierMap); |
| 179 visitor->trace(m_notifierToIdMap); | 85 visitor->trace(m_notifierToIdMap); |
| 180 } | 86 } |
| 181 | 87 |
| 182 bool Geolocation::Watchers::add(int id, GeoNotifier* notifier) | 88 bool Geolocation::Watchers::add(int id, GeoNotifier* notifier) |
| 183 { | 89 { |
| 184 ASSERT(id > 0); | 90 ASSERT(id > 0); |
| 185 if (!m_idToNotifierMap.add(id, notifier).isNewEntry) | 91 if (!m_idToNotifierMap.add(id, notifier).isNewEntry) |
| 186 return false; | 92 return false; |
| 187 m_notifierToIdMap.set(notifier, id); | 93 m_notifierToIdMap.set(notifier, id); |
| 188 return true; | 94 return true; |
| 189 } | 95 } |
| 190 | 96 |
| 191 Geolocation::GeoNotifier* Geolocation::Watchers::find(int id) | 97 GeoNotifier* Geolocation::Watchers::find(int id) |
| 192 { | 98 { |
| 193 ASSERT(id > 0); | 99 ASSERT(id > 0); |
| 194 IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id); | 100 IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id); |
| 195 if (iter == m_idToNotifierMap.end()) | 101 if (iter == m_idToNotifierMap.end()) |
| 196 return 0; | 102 return 0; |
| 197 return iter->value.get(); | 103 return iter->value.get(); |
| 198 } | 104 } |
| 199 | 105 |
| 200 void Geolocation::Watchers::remove(int id) | 106 void Geolocation::Watchers::remove(int id) |
| 201 { | 107 { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 else if (!isAllowed()) { | 245 else if (!isAllowed()) { |
| 340 // if we don't yet have permission, request for permission before callin
g startUpdating() | 246 // if we don't yet have permission, request for permission before callin
g startUpdating() |
| 341 m_pendingForPermissionNotifiers.add(notifier); | 247 m_pendingForPermissionNotifiers.add(notifier); |
| 342 requestPermission(); | 248 requestPermission(); |
| 343 } else if (startUpdating(notifier)) | 249 } else if (startUpdating(notifier)) |
| 344 notifier->startTimer(); | 250 notifier->startTimer(); |
| 345 else | 251 else |
| 346 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN
AVAILABLE, failedToStartServiceErrorMessage)); | 252 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN
AVAILABLE, failedToStartServiceErrorMessage)); |
| 347 } | 253 } |
| 348 | 254 |
| 349 void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) | 255 void Geolocation::fatalErrorOccurred(GeoNotifier* notifier) |
| 350 { | 256 { |
| 351 // This request has failed fatally. Remove it from our lists. | 257 // This request has failed fatally. Remove it from our lists. |
| 352 m_oneShots.remove(notifier); | 258 m_oneShots.remove(notifier); |
| 353 m_watchers.remove(notifier); | 259 m_watchers.remove(notifier); |
| 354 | 260 |
| 355 if (!hasListeners()) | 261 if (!hasListeners()) |
| 356 stopUpdating(); | 262 stopUpdating(); |
| 357 } | 263 } |
| 358 | 264 |
| 359 void Geolocation::requestUsesCachedPosition(GeoNotifier* notifier) | 265 void Geolocation::requestUsesCachedPosition(GeoNotifier* notifier) |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 { | 599 { |
| 694 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); | 600 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); |
| 695 } | 601 } |
| 696 | 602 |
| 697 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const | 603 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const |
| 698 { | 604 { |
| 699 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); | 605 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); |
| 700 } | 606 } |
| 701 | 607 |
| 702 } // namespace WebCore | 608 } // namespace WebCore |
| OLD | NEW |