예제 #1
0
void Geolocation::startRequest(GeoNotifier* notifier) {
  recordOriginTypeAccess();
  String errorMessage;
  if (!frame()->settings()->allowGeolocationOnInsecureOrigins() &&
      !getExecutionContext()->isSecureContext(errorMessage)) {
    notifier->setFatalError(
        PositionError::create(PositionError::kPermissionDenied, errorMessage));
    return;
  }

  // Check whether permissions have already been denied. Note that if this is
  // the case, the permission state can not change again in the lifetime of
  // this page.
  if (isDenied())
    notifier->setFatalError(PositionError::create(
        PositionError::kPermissionDenied, permissionDeniedErrorMessage));
  else if (haveSuitableCachedPosition(notifier->options()))
    notifier->setUseCachedPosition();
  else if (!notifier->options().timeout())
    notifier->startTimer();
  else if (!isAllowed()) {
    // If we don't yet have permission, request for permission before calling
    // startUpdating()
    m_pendingForPermissionNotifiers.add(notifier);
    requestPermission();
  } else {
    startUpdating(notifier);
    notifier->startTimer();
  }
}
예제 #2
0
void Geolocation::getCurrentPosition(PositionCallback* successCallback, PositionErrorCallback* errorCallback, const PositionOptions& options)
{
    if (!frame())
        return;

    recordOriginTypeAccess();

    GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
    startRequest(notifier);

    m_oneShots.add(notifier);
}
예제 #3
0
int Geolocation::watchPosition(PositionCallback* successCallback, PositionErrorCallback* errorCallback, const PositionOptions& options)
{
    if (!frame())
        return 0;

    recordOriginTypeAccess();

    GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, options);
    startRequest(notifier);

    int watchID;
    // Keep asking for the next id until we're given one that we don't already have.
    do {
        watchID = executionContext()->circularSequentialID();
    } while (!m_watchers.add(watchID, notifier));
    return watchID;
}
예제 #4
0
void Geolocation::startRequest(GeoNotifier *notifier)
{
    recordOriginTypeAccess();
    String errorMessage;
    if (!frame()->settings()->allowGeolocationOnInsecureOrigins() && !executionContext()->isSecureContext(errorMessage)) {
        notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, errorMessage));
        return;
    }

    if (RuntimeEnabledFeatures::restrictIFramePermissionsEnabled()) {
        // TODO(keenanb): kill the request if the parent is blocking the requester
        Element* owner = document()->ownerElement();
        if (owner && owner->hasAttribute(HTMLNames::permissionsAttr)) {
            String errorMessage = "A cross-origin iframe needs its permissions attribute properly set in order to use the geolocation API.";
            notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, errorMessage));
            return;
        }
    }

    // Check whether permissions have already been denied. Note that if this is the case,
    // the permission state can not change again in the lifetime of this page.
    if (isDenied())
        notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage));
    else if (haveSuitableCachedPosition(notifier->options()))
        notifier->setUseCachedPosition();
    else if (!notifier->options().timeout())
        notifier->startTimer();
    else if (!isAllowed()) {
        // if we don't yet have permission, request for permission before calling startUpdating()
        m_pendingForPermissionNotifiers.add(notifier);
        requestPermission();
    } else if (startUpdating(notifier))
        notifier->startTimer();
    else
        notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
}