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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 PositionErrorCallback* errorCallback, | 178 PositionErrorCallback* errorCallback, |
179 const PositionOptions& options) { | 179 const PositionOptions& options) { |
180 if (!frame()) | 180 if (!frame()) |
181 return 0; | 181 return 0; |
182 | 182 |
183 GeoNotifier* notifier = | 183 GeoNotifier* notifier = |
184 GeoNotifier::create(this, successCallback, errorCallback, options); | 184 GeoNotifier::create(this, successCallback, errorCallback, options); |
185 startRequest(notifier); | 185 startRequest(notifier); |
186 | 186 |
187 int watchID; | 187 int watchID; |
188 // Keep asking for the next id until we're given one that we don't already hav
e. | 188 // Keep asking for the next id until we're given one that we don't already |
| 189 // have. |
189 do { | 190 do { |
190 watchID = getExecutionContext()->circularSequentialID(); | 191 watchID = getExecutionContext()->circularSequentialID(); |
191 } while (!m_watchers.add(watchID, notifier)); | 192 } while (!m_watchers.add(watchID, notifier)); |
192 return watchID; | 193 return watchID; |
193 } | 194 } |
194 | 195 |
195 void Geolocation::startRequest(GeoNotifier* notifier) { | 196 void Geolocation::startRequest(GeoNotifier* notifier) { |
196 recordOriginTypeAccess(); | 197 recordOriginTypeAccess(); |
197 String errorMessage; | 198 String errorMessage; |
198 if (!frame()->settings()->allowGeolocationOnInsecureOrigins() && | 199 if (!frame()->settings()->allowGeolocationOnInsecureOrigins() && |
199 !getExecutionContext()->isSecureContext(errorMessage)) { | 200 !getExecutionContext()->isSecureContext(errorMessage)) { |
200 notifier->setFatalError( | 201 notifier->setFatalError( |
201 PositionError::create(PositionError::kPermissionDenied, errorMessage)); | 202 PositionError::create(PositionError::kPermissionDenied, errorMessage)); |
202 return; | 203 return; |
203 } | 204 } |
204 | 205 |
205 // Check whether permissions have already been denied. Note that if this is th
e case, | 206 // Check whether permissions have already been denied. Note that if this is |
206 // the permission state can not change again in the lifetime of this page. | 207 // the case, the permission state can not change again in the lifetime of |
| 208 // this page. |
207 if (isDenied()) | 209 if (isDenied()) |
208 notifier->setFatalError(PositionError::create( | 210 notifier->setFatalError(PositionError::create( |
209 PositionError::kPermissionDenied, permissionDeniedErrorMessage)); | 211 PositionError::kPermissionDenied, permissionDeniedErrorMessage)); |
210 else if (haveSuitableCachedPosition(notifier->options())) | 212 else if (haveSuitableCachedPosition(notifier->options())) |
211 notifier->setUseCachedPosition(); | 213 notifier->setUseCachedPosition(); |
212 else if (!notifier->options().timeout()) | 214 else if (!notifier->options().timeout()) |
213 notifier->startTimer(); | 215 notifier->startTimer(); |
214 else if (!isAllowed()) { | 216 else if (!isAllowed()) { |
215 // if we don't yet have permission, request for permission before calling st
artUpdating() | 217 // If we don't yet have permission, request for permission before calling |
| 218 // startUpdating() |
216 m_pendingForPermissionNotifiers.add(notifier); | 219 m_pendingForPermissionNotifiers.add(notifier); |
217 requestPermission(); | 220 requestPermission(); |
218 } else { | 221 } else { |
219 startUpdating(notifier); | 222 startUpdating(notifier); |
220 notifier->startTimer(); | 223 notifier->startTimer(); |
221 } | 224 } |
222 } | 225 } |
223 | 226 |
224 void Geolocation::fatalErrorOccurred(GeoNotifier* notifier) { | 227 void Geolocation::fatalErrorOccurred(GeoNotifier* notifier) { |
225 // This request has failed fatally. Remove it from our lists. | 228 // This request has failed fatally. Remove it from our lists. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 if (GeoNotifier* notifier = m_watchers.find(watchID)) | 277 if (GeoNotifier* notifier = m_watchers.find(watchID)) |
275 m_pendingForPermissionNotifiers.remove(notifier); | 278 m_pendingForPermissionNotifiers.remove(notifier); |
276 m_watchers.remove(watchID); | 279 m_watchers.remove(watchID); |
277 | 280 |
278 if (!hasListeners()) | 281 if (!hasListeners()) |
279 stopUpdating(); | 282 stopUpdating(); |
280 } | 283 } |
281 | 284 |
282 void Geolocation::onGeolocationPermissionUpdated( | 285 void Geolocation::onGeolocationPermissionUpdated( |
283 mojom::blink::PermissionStatus status) { | 286 mojom::blink::PermissionStatus status) { |
284 // This may be due to either a new position from the service, or a cached posi
tion. | 287 // This may be due to either a new position from the service, or a cached |
| 288 // position. |
285 m_geolocationPermission = status == mojom::blink::PermissionStatus::GRANTED | 289 m_geolocationPermission = status == mojom::blink::PermissionStatus::GRANTED |
286 ? PermissionAllowed | 290 ? PermissionAllowed |
287 : PermissionDenied; | 291 : PermissionDenied; |
288 m_permissionService.reset(); | 292 m_permissionService.reset(); |
289 | 293 |
290 // While we iterate through the list, we need not worry about the list being m
odified as the permission | 294 // While we iterate through the list, we need not worry about the list being |
291 // is already set to Yes/No and no new listeners will be added to the pending
list. | 295 // modified as the permission is already set to Yes/No and no new listeners |
| 296 // will be added to the pending list. |
292 for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) { | 297 for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) { |
293 if (isAllowed()) { | 298 if (isAllowed()) { |
294 // Start all pending notification requests as permission granted. | 299 // Start all pending notification requests as permission granted. |
295 // The notifier is always ref'ed by m_oneShots or m_watchers. | 300 // The notifier is always ref'ed by m_oneShots or m_watchers. |
296 startUpdating(notifier); | 301 startUpdating(notifier); |
297 notifier->startTimer(); | 302 notifier->startTimer(); |
298 } else { | 303 } else { |
299 notifier->setFatalError(PositionError::create( | 304 notifier->setFatalError(PositionError::create( |
300 PositionError::kPermissionDenied, permissionDeniedErrorMessage)); | 305 PositionError::kPermissionDenied, permissionDeniedErrorMessage)); |
301 } | 306 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 m_watchers.getNotifiersVector(watchersCopy); | 388 m_watchers.getNotifiersVector(watchersCopy); |
384 | 389 |
385 // Clear the lists before we make the callbacks, to avoid clearing notifiers | 390 // Clear the lists before we make the callbacks, to avoid clearing notifiers |
386 // added by calls to Geolocation methods from the callbacks, and to prevent | 391 // added by calls to Geolocation methods from the callbacks, and to prevent |
387 // further callbacks to these notifiers. | 392 // further callbacks to these notifiers. |
388 GeoNotifierVector oneShotsWithCachedPosition; | 393 GeoNotifierVector oneShotsWithCachedPosition; |
389 m_oneShots.clear(); | 394 m_oneShots.clear(); |
390 if (error->isFatal()) | 395 if (error->isFatal()) |
391 m_watchers.clear(); | 396 m_watchers.clear(); |
392 else { | 397 else { |
393 // Don't send non-fatal errors to notifiers due to receive a cached position
. | 398 // Don't send non-fatal errors to notifiers due to receive a cached |
| 399 // position. |
394 extractNotifiersWithCachedPosition(oneShotsCopy, | 400 extractNotifiersWithCachedPosition(oneShotsCopy, |
395 &oneShotsWithCachedPosition); | 401 &oneShotsWithCachedPosition); |
396 extractNotifiersWithCachedPosition(watchersCopy, 0); | 402 extractNotifiersWithCachedPosition(watchersCopy, 0); |
397 } | 403 } |
398 | 404 |
399 sendError(oneShotsCopy, error); | 405 sendError(oneShotsCopy, error); |
400 sendError(watchersCopy, error); | 406 sendError(watchersCopy, error); |
401 | 407 |
402 // hasListeners() doesn't distinguish between notifiers due to receive a | 408 // hasListeners() doesn't distinguish between notifiers due to receive a |
403 // cached position and those requiring a fresh position. Perform the check | 409 // cached position and those requiring a fresh position. Perform the check |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 // be called. In that case, blink has already shut down so do nothing. | 548 // be called. In that case, blink has already shut down so do nothing. |
543 // | 549 // |
544 // TODO(sammc): Remove this once renderer shutdown is no longer graceful. | 550 // TODO(sammc): Remove this once renderer shutdown is no longer graceful. |
545 if (!Platform::current()) | 551 if (!Platform::current()) |
546 return; | 552 return; |
547 | 553 |
548 onGeolocationPermissionUpdated(mojom::blink::PermissionStatus::DENIED); | 554 onGeolocationPermissionUpdated(mojom::blink::PermissionStatus::DENIED); |
549 } | 555 } |
550 | 556 |
551 } // namespace blink | 557 } // namespace blink |
OLD | NEW |