nsresult
nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal, bool aRequestPrivate)
{
  if (!sGeoEnabled || sGeoInitPending) {
    return NS_ERROR_NOT_AVAILABLE;
  }

  // we do not want to keep the geolocation devices online
  // indefinitely.  Close them down after a reasonable period of
  // inactivivity
  SetDisconnectTimer();

  if (XRE_GetProcessType() == GeckoProcessType_Content) {
    ContentChild* cpc = ContentChild::GetSingleton();
    cpc->SendAddGeolocationListener(IPC::Principal(aPrincipal),
                                    HighAccuracyRequested());
    return NS_OK;
  }

  // Start them up!
  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  if (!obs) {
    return NS_ERROR_FAILURE;
  }

  for (int32_t i = 0; i < mProviders.Count(); i++) {
    mProviders[i]->Startup();
    mProviders[i]->Watch(this, aRequestPrivate);
    obs->NotifyObservers(mProviders[i],
                         "geolocation-device-events",
                         NS_LITERAL_STRING("starting").get());
  }

  return NS_OK;
}
Beispiel #2
0
nsresult
nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal)
{
    if (!sGeoEnabled || sGeoInitPending) {
        return NS_ERROR_NOT_AVAILABLE;
    }

    // we do not want to keep the geolocation devices online
    // indefinitely.  Close them down after a reasonable period of
    // inactivivity
    SetDisconnectTimer();

    if (XRE_GetProcessType() == GoannaProcessType_Content) {
        ContentChild* cpc = ContentChild::GetSingleton();
        cpc->SendAddGeolocationListener(IPC::Principal(aPrincipal),
                                        HighAccuracyRequested());
        return NS_OK;
    }

    // Start them up!
    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
    if (!obs) {
        return NS_ERROR_FAILURE;
    }

    if (!mProvider) {
        return NS_ERROR_FAILURE;
    }

    nsresult rv;

    if (NS_FAILED(rv = mProvider->Startup()) ||
            NS_FAILED(rv = mProvider->Watch(this))) {

        NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
        return rv;
    }

    obs->NotifyObservers(mProvider,
                         "geolocation-device-events",
                         NS_LITERAL_STRING("starting").get());

    return NS_OK;
}