| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 Document* Geolocation::document() const | 280 Document* Geolocation::document() const |
| 281 { | 281 { |
| 282 return toDocument(executionContext()); | 282 return toDocument(executionContext()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 LocalFrame* Geolocation::frame() const | 285 LocalFrame* Geolocation::frame() const |
| 286 { | 286 { |
| 287 return document() ? document()->frame() : 0; | 287 return document() ? document()->frame() : 0; |
| 288 } | 288 } |
| 289 | 289 |
| 290 Page* Geolocation::page() const | |
| 291 { | |
| 292 return document() ? document()->page() : 0; | |
| 293 } | |
| 294 | |
| 295 void Geolocation::stop() | 290 void Geolocation::stop() |
| 296 { | 291 { |
| 297 Page* page = this->page(); | 292 LocalFrame* frame = this->frame(); |
| 298 if (page && m_allowGeolocation == InProgress) | 293 if (frame && m_allowGeolocation == InProgress) |
| 299 GeolocationController::from(page)->cancelPermissionRequest(this); | 294 GeolocationController::from(frame)->cancelPermissionRequest(this); |
| 300 // The frame may be moving to a new page and we want to get the permissions
from the new page's client. | 295 // The frame may be moving to a new page and we want to get the permissions
from the new page's client. |
| 301 m_allowGeolocation = Unknown; | 296 m_allowGeolocation = Unknown; |
| 302 cancelAllRequests(); | 297 cancelAllRequests(); |
| 303 stopUpdating(); | 298 stopUpdating(); |
| 304 m_pendingForPermissionNotifiers.clear(); | 299 m_pendingForPermissionNotifiers.clear(); |
| 305 } | 300 } |
| 306 | 301 |
| 307 Geoposition* Geolocation::lastPosition() | 302 Geoposition* Geolocation::lastPosition() |
| 308 { | 303 { |
| 309 Page* page = this->page(); | 304 LocalFrame* frame = this->frame(); |
| 310 if (!page) | 305 if (!frame) |
| 311 return 0; | 306 return 0; |
| 312 | 307 |
| 313 m_lastPosition = createGeoposition(GeolocationController::from(page)->lastPo
sition()); | 308 m_lastPosition = createGeoposition(GeolocationController::from(frame)->lastP
osition()); |
| 314 | 309 |
| 315 return m_lastPosition.get(); | 310 return m_lastPosition.get(); |
| 316 } | 311 } |
| 317 | 312 |
| 318 void Geolocation::getCurrentPosition(PassOwnPtr<PositionCallback> successCallbac
k, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtrWillBeRawPtr<Posit
ionOptions> options) | 313 void Geolocation::getCurrentPosition(PassOwnPtr<PositionCallback> successCallbac
k, PassOwnPtr<PositionErrorCallback> errorCallback, PassRefPtrWillBeRawPtr<Posit
ionOptions> options) |
| 319 { | 314 { |
| 320 if (!frame()) | 315 if (!frame()) |
| 321 return; | 316 return; |
| 322 | 317 |
| 323 RefPtrWillBeRawPtr<GeoNotifier> notifier = GeoNotifier::create(this, success
Callback, errorCallback, options); | 318 RefPtrWillBeRawPtr<GeoNotifier> notifier = GeoNotifier::create(this, success
Callback, errorCallback, options); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 | 601 |
| 607 // Maintain a reference to the cached notifiers until their timer fires. | 602 // Maintain a reference to the cached notifiers until their timer fires. |
| 608 copyToSet(oneShotsWithCachedPosition, m_oneShots); | 603 copyToSet(oneShotsWithCachedPosition, m_oneShots); |
| 609 } | 604 } |
| 610 | 605 |
| 611 void Geolocation::requestPermission() | 606 void Geolocation::requestPermission() |
| 612 { | 607 { |
| 613 if (m_allowGeolocation > Unknown) | 608 if (m_allowGeolocation > Unknown) |
| 614 return; | 609 return; |
| 615 | 610 |
| 616 Page* page = this->page(); | 611 LocalFrame* frame = this->frame(); |
| 617 if (!page) | 612 if (!frame) |
| 618 return; | 613 return; |
| 619 | 614 |
| 620 m_allowGeolocation = InProgress; | 615 m_allowGeolocation = InProgress; |
| 621 | 616 |
| 622 // Ask the embedder: it maintains the geolocation challenge policy itself. | 617 // Ask the embedder: it maintains the geolocation challenge policy itself. |
| 623 GeolocationController::from(page)->requestPermission(this); | 618 GeolocationController::from(frame)->requestPermission(this); |
| 624 } | 619 } |
| 625 | 620 |
| 626 void Geolocation::makeSuccessCallbacks() | 621 void Geolocation::makeSuccessCallbacks() |
| 627 { | 622 { |
| 628 ASSERT(lastPosition()); | 623 ASSERT(lastPosition()); |
| 629 ASSERT(isAllowed()); | 624 ASSERT(isAllowed()); |
| 630 | 625 |
| 631 GeoNotifierVector oneShotsCopy; | 626 GeoNotifierVector oneShotsCopy; |
| 632 copyToVector(m_oneShots, oneShotsCopy); | 627 copyToVector(m_oneShots, oneShotsCopy); |
| 633 | 628 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 662 } | 657 } |
| 663 | 658 |
| 664 void Geolocation::setError(GeolocationError* error) | 659 void Geolocation::setError(GeolocationError* error) |
| 665 { | 660 { |
| 666 RefPtrWillBeRawPtr<PositionError> positionError = createPositionError(error)
; | 661 RefPtrWillBeRawPtr<PositionError> positionError = createPositionError(error)
; |
| 667 handleError(positionError.get()); | 662 handleError(positionError.get()); |
| 668 } | 663 } |
| 669 | 664 |
| 670 bool Geolocation::startUpdating(GeoNotifier* notifier) | 665 bool Geolocation::startUpdating(GeoNotifier* notifier) |
| 671 { | 666 { |
| 672 Page* page = this->page(); | 667 LocalFrame* frame = this->frame(); |
| 673 if (!page) | 668 if (!frame) |
| 674 return false; | 669 return false; |
| 675 | 670 |
| 676 GeolocationController::from(page)->addObserver(this, notifier->options()->en
ableHighAccuracy()); | 671 GeolocationController::from(frame)->addObserver(this, notifier->options()->e
nableHighAccuracy()); |
| 677 return true; | 672 return true; |
| 678 } | 673 } |
| 679 | 674 |
| 680 void Geolocation::stopUpdating() | 675 void Geolocation::stopUpdating() |
| 681 { | 676 { |
| 682 Page* page = this->page(); | 677 LocalFrame* frame = this->frame(); |
| 683 if (!page) | 678 if (!frame) |
| 684 return; | 679 return; |
| 685 | 680 |
| 686 GeolocationController::from(page)->removeObserver(this); | 681 GeolocationController::from(frame)->removeObserver(this); |
| 687 } | 682 } |
| 688 | 683 |
| 689 void Geolocation::handlePendingPermissionNotifiers() | 684 void Geolocation::handlePendingPermissionNotifiers() |
| 690 { | 685 { |
| 691 // While we iterate through the list, we need not worry about list being mod
ified as the permission | 686 // 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 | 687 // 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(); | 688 GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end(); |
| 694 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.b
egin(); iter != end; ++iter) { | 689 for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.b
egin(); iter != end; ++iter) { |
| 695 GeoNotifier* notifier = iter->get(); | 690 GeoNotifier* notifier = iter->get(); |
| 696 | 691 |
| 697 if (isAllowed()) { | 692 if (isAllowed()) { |
| 698 // start all pending notification requests as permission granted. | 693 // start all pending notification requests as permission granted. |
| 699 // The notifier is always ref'ed by m_oneShots or m_watchers. | 694 // The notifier is always ref'ed by m_oneShots or m_watchers. |
| 700 if (startUpdating(notifier)) | 695 if (startUpdating(notifier)) |
| 701 notifier->startTimerIfNeeded(); | 696 notifier->startTimerIfNeeded(); |
| 702 else | 697 else |
| 703 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); | 698 notifier->setFatalError(PositionError::create(PositionError::POS
ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); |
| 704 } else { | 699 } else { |
| 705 notifier->setFatalError(PositionError::create(PositionError::PERMISS
ION_DENIED, permissionDeniedErrorMessage)); | 700 notifier->setFatalError(PositionError::create(PositionError::PERMISS
ION_DENIED, permissionDeniedErrorMessage)); |
| 706 } | 701 } |
| 707 } | 702 } |
| 708 } | 703 } |
| 709 | 704 |
| 710 } // namespace WebCore | 705 } // namespace WebCore |
| OLD | NEW |