diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/Modules/geolocation/GeolocationController.cpp | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/Modules/geolocation/GeolocationController.cpp')
-rw-r--r-- | Source/WebCore/Modules/geolocation/GeolocationController.cpp | 84 |
1 files changed, 32 insertions, 52 deletions
diff --git a/Source/WebCore/Modules/geolocation/GeolocationController.cpp b/Source/WebCore/Modules/geolocation/GeolocationController.cpp index 0a10a8f5b..95717296c 100644 --- a/Source/WebCore/Modules/geolocation/GeolocationController.cpp +++ b/Source/WebCore/Modules/geolocation/GeolocationController.cpp @@ -34,22 +34,22 @@ namespace WebCore { -GeolocationController::GeolocationController(Page& page, GeolocationClient& client) - : m_page(page) - , m_client(client) +GeolocationController::GeolocationController(GeolocationClient* client) + : m_client(client) { - m_page.addViewStateChangeObserver(*this); } GeolocationController::~GeolocationController() { ASSERT(m_observers.isEmpty()); - // NOTE: We don't have to remove ourselves from page's ViewStateChangeObserver set, since - // we are supplement of the Page, and our destructor getting called means the page is being - // torn down. + if (m_client) + m_client->geolocationDestroyed(); +} - m_client.geolocationDestroyed(); +PassOwnPtr<GeolocationController> GeolocationController::create(GeolocationClient* client) +{ + return adoptPtr(new GeolocationController(client)); } void GeolocationController::addObserver(Geolocation* observer, bool enableHighAccuracy) @@ -61,10 +61,12 @@ void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc if (enableHighAccuracy) m_highAccuracyObservers.add(observer); - if (enableHighAccuracy) - m_client.setEnableHighAccuracy(true); - if (wasEmpty && m_page.isVisible()) - m_client.startUpdating(); + if (m_client) { + if (enableHighAccuracy) + m_client->setEnableHighAccuracy(true); + if (wasEmpty) + m_client->startUpdating(); + } } void GeolocationController::removeObserver(Geolocation* observer) @@ -75,28 +77,24 @@ void GeolocationController::removeObserver(Geolocation* observer) m_observers.remove(observer); m_highAccuracyObservers.remove(observer); - if (m_observers.isEmpty()) - m_client.stopUpdating(); - else if (m_highAccuracyObservers.isEmpty()) - m_client.setEnableHighAccuracy(false); + if (m_client) { + if (m_observers.isEmpty()) + m_client->stopUpdating(); + else if (m_highAccuracyObservers.isEmpty()) + m_client->setEnableHighAccuracy(false); + } } void GeolocationController::requestPermission(Geolocation* geolocation) { - if (!m_page.isVisible()) { - m_pendedPermissionRequest.add(geolocation); - return; - } - - m_client.requestPermission(geolocation); + if (m_client) + m_client->requestPermission(geolocation); } void GeolocationController::cancelPermissionRequest(Geolocation* geolocation) { - if (m_pendedPermissionRequest.remove(geolocation)) - return; - - m_client.cancelPermissionRequest(geolocation); + if (m_client) + m_client->cancelPermissionRequest(geolocation); } void GeolocationController::positionChanged(GeolocationPosition* position) @@ -104,16 +102,16 @@ void GeolocationController::positionChanged(GeolocationPosition* position) m_lastPosition = position; Vector<RefPtr<Geolocation>> observersVector; copyToVector(m_observers, observersVector); - for (auto& observer : observersVector) - observer->positionChanged(); + for (size_t i = 0; i < observersVector.size(); ++i) + observersVector[i]->positionChanged(); } void GeolocationController::errorOccurred(GeolocationError* error) { Vector<RefPtr<Geolocation>> observersVector; copyToVector(m_observers, observersVector); - for (auto& observer : observersVector) - observer->setError(error); + for (size_t i = 0; i < observersVector.size(); ++i) + observersVector[i]->setError(error); } GeolocationPosition* GeolocationController::lastPosition() @@ -121,26 +119,10 @@ GeolocationPosition* GeolocationController::lastPosition() if (m_lastPosition.get()) return m_lastPosition.get(); - return m_client.lastPosition(); -} - -void GeolocationController::viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState) -{ - // Toggle GPS based on page visibility to save battery. - ViewState::Flags changed = oldViewState ^ newViewState; - if (changed & ViewState::IsVisible && !m_observers.isEmpty()) { - if (newViewState & ViewState::IsVisible) - m_client.startUpdating(); - else - m_client.stopUpdating(); - } - - if (!m_page.isVisible()) - return; + if (!m_client) + return 0; - HashSet<RefPtr<Geolocation>> pendedPermissionRequests = WTFMove(m_pendedPermissionRequest); - for (auto& permissionRequest : pendedPermissionRequests) - m_client.requestPermission(permissionRequest.get()); + return m_client->lastPosition(); } const char* GeolocationController::supplementName() @@ -150,9 +132,7 @@ const char* GeolocationController::supplementName() void provideGeolocationTo(Page* page, GeolocationClient* client) { - ASSERT(page); - ASSERT(client); - Supplement<Page>::provideTo(page, GeolocationController::supplementName(), std::make_unique<GeolocationController>(*page, *client)); + Supplement<Page>::provideTo(page, GeolocationController::supplementName(), GeolocationController::create(client)); } } // namespace WebCore |