#include "modules/geolocation/Geolocation.h"
#include "core/dom/Document.h"
+#include "core/frame/UseCounter.h"
#include "modules/geolocation/Coordinates.h"
#include "modules/geolocation/GeolocationController.h"
#include "modules/geolocation/GeolocationError.h"
return m_lastPosition.get();
}
+void Geolocation::recordOriginTypeAccess() const
+{
+ ASSERT(frame());
+
+ Document* document = this->document();
+ ASSERT(document);
+
+ // It is required by canAccessFeatureRequiringSecureOrigin() but isn't
+ // actually used. This could be used later if a warning is shown in the
+ // developer console.
+ String insecureOriginMsg;
+ UseCounter::Feature counter = document->securityOrigin()->canAccessFeatureRequiringSecureOrigin(insecureOriginMsg)
+ ? UseCounter::GeolocationSecureOrigin : UseCounter::GeolocationInsecureOrigin;
+ UseCounter::count(document, counter);
+}
+
void Geolocation::getCurrentPosition(PositionCallback* successCallback, PositionErrorCallback* errorCallback, const Dictionary& options)
{
if (!frame())
return;
+ recordOriginTypeAccess();
+
GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, PositionOptions::create(options));
startRequest(notifier);
if (!frame())
return 0;
+ recordOriginTypeAccess();
+
GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, PositionOptions::create(options));
startRequest(notifier);
// All modifications to m_requestsAwaitingCachedPosition are done
// asynchronously, so we don't need to worry about it being modified from
// the callbacks.
- GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end();
- for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.begin(); iter != end; ++iter) {
- GeoNotifier* notifier = iter->get();
+ for (GeoNotifier* notifier : m_requestsAwaitingCachedPosition) {
notifier->runSuccessCallback(lastPosition());
// If this is a one-shot request, stop it. Otherwise, if the watch still
void Geolocation::sendError(GeoNotifierVector& notifiers, PositionError* error)
{
- GeoNotifierVector::const_iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it)
- (*it)->runErrorCallback(error);
+ for (GeoNotifier* notifier : notifiers)
+ notifier->runErrorCallback(error);
}
void Geolocation::sendPosition(GeoNotifierVector& notifiers, Geoposition* position)
{
- GeoNotifierVector::const_iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it)
- (*it)->runSuccessCallback(position);
+ for (GeoNotifier* notifier : notifiers)
+ notifier->runSuccessCallback(position);
}
void Geolocation::stopTimer(GeoNotifierVector& notifiers)
{
- GeoNotifierVector::const_iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it)
- (*it)->stopTimer();
+ for (GeoNotifier* notifier : notifiers)
+ notifier->stopTimer();
}
void Geolocation::stopTimersForOneShots()
void Geolocation::cancelRequests(GeoNotifierVector& notifiers)
{
- GeoNotifierVector::const_iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it)
- (*it)->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, framelessDocumentErrorMessage));
+ for (GeoNotifier* notifier : notifiers)
+ notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, framelessDocumentErrorMessage));
}
void Geolocation::cancelAllRequests()
void Geolocation::extractNotifiersWithCachedPosition(GeoNotifierVector& notifiers, GeoNotifierVector* cached)
{
GeoNotifierVector nonCached;
- GeoNotifierVector::iterator end = notifiers.end();
- for (GeoNotifierVector::const_iterator it = notifiers.begin(); it != end; ++it) {
- GeoNotifier* notifier = it->get();
+ for (GeoNotifier* notifier : notifiers) {
if (notifier->useCachedPosition()) {
if (cached)
cached->append(notifier);
void Geolocation::copyToSet(const GeoNotifierVector& src, GeoNotifierSet& dest)
{
- GeoNotifierVector::const_iterator end = src.end();
- for (GeoNotifierVector::const_iterator it = src.begin(); it != end; ++it) {
- GeoNotifier* notifier = it->get();
+ for (GeoNotifier* notifier : src)
dest.add(notifier);
- }
}
void Geolocation::handleError(PositionError* error)
void Geolocation::handlePendingPermissionNotifiers()
{
// While we iterate through the list, we need not worry about list being modified as the permission
- // is already set to Yes/No and no new listeners will be added to the pending list
- GeoNotifierSet::const_iterator end = m_pendingForPermissionNotifiers.end();
- for (GeoNotifierSet::const_iterator iter = m_pendingForPermissionNotifiers.begin(); iter != end; ++iter) {
- GeoNotifier* notifier = iter->get();
-
+ // is already set to Yes/No and no new listeners will be added to the pending list.
+ for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) {
if (isAllowed()) {
// start all pending notification requests as permission granted.
// The notifier is always ref'ed by m_oneShots or m_watchers.