mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1063572 - Geoclue2 geolocation provider. r=emilio
Add a Geoclue (version 2) geolocation provider. This way Firefox can make use of multiple location sources present in the system, from GNSS provided by a cellular modem or the current network to location based on visible WiFi networks and 3G tower data, all while sharing them with other applications. This is a pure D-Bus-based implementation using a proper state machine, it does not require any additional dependencies. Differential Revision: https://phabricator.services.mozilla.com/D145838
This commit is contained in:
parent
d3b15de2f1
commit
41cb3fd7d8
@ -45,6 +45,7 @@ class nsIPrincipal;
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
# include "mozilla/WidgetUtilsGtk.h"
|
||||
# include "GeoclueLocationProvider.h"
|
||||
# include "PortalLocationProvider.h"
|
||||
#endif
|
||||
|
||||
@ -494,15 +495,24 @@ nsresult nsGeolocationService::Init() {
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
# ifdef MOZ_GPSD
|
||||
if (Preferences::GetBool("geo.provider.use_gpsd", false)) {
|
||||
mProvider = new GpsdLocationProvider();
|
||||
}
|
||||
# endif
|
||||
# ifdef MOZ_ENABLE_DBUS
|
||||
if (!mProvider && widget::ShouldUsePortal(widget::PortalKind::Location)) {
|
||||
mProvider = new PortalLocationProvider();
|
||||
}
|
||||
// Geoclue includes GPS data so it has higher priority than raw GPSD
|
||||
if (!mProvider && StaticPrefs::geo_provider_use_geoclue()) {
|
||||
nsCOMPtr<nsIGeolocationProvider> gcProvider = new GeoclueLocationProvider();
|
||||
// The Startup() method will only succeed if Geoclue is available on D-Bus
|
||||
if (NS_SUCCEEDED(gcProvider->Startup())) {
|
||||
gcProvider->Shutdown();
|
||||
mProvider = std::move(gcProvider);
|
||||
}
|
||||
}
|
||||
# ifdef MOZ_GPSD
|
||||
if (!mProvider && Preferences::GetBool("geo.provider.use_gpsd", false)) {
|
||||
mProvider = new GpsdLocationProvider();
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
1024
dom/system/linux/GeoclueLocationProvider.cpp
Normal file
1024
dom/system/linux/GeoclueLocationProvider.cpp
Normal file
File diff suppressed because it is too large
Load Diff
32
dom/system/linux/GeoclueLocationProvider.h
Normal file
32
dom/system/linux/GeoclueLocationProvider.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef GeoclueLocationProvider_h
|
||||
#define GeoclueLocationProvider_h
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsIGeolocationProvider.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
class GCLocProviderPriv;
|
||||
|
||||
class GeoclueLocationProvider final : public nsIGeolocationProvider {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIGEOLOCATIONPROVIDER
|
||||
|
||||
GeoclueLocationProvider();
|
||||
|
||||
private:
|
||||
~GeoclueLocationProvider() = default;
|
||||
|
||||
RefPtr<GCLocProviderPriv> mPriv;
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
||||
#endif /* GeoclueLocationProvider_h */
|
@ -15,6 +15,7 @@ if CONFIG["MOZ_GPSD"]:
|
||||
|
||||
|
||||
if CONFIG["MOZ_ENABLE_DBUS"]:
|
||||
SOURCES += ["GeoclueLocationProvider.cpp"]
|
||||
SOURCES += ["PortalLocationProvider.cpp"]
|
||||
LOCAL_INCLUDES += ["/dom/geolocation"]
|
||||
CXXFLAGS += CONFIG["MOZ_DBUS_GLIB_CFLAGS"]
|
||||
|
@ -5073,6 +5073,23 @@
|
||||
value: 6000
|
||||
mirror: always
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
# Whether to use Geoclue location provider (if available on the system).
|
||||
- name: geo.provider.use_geoclue
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether to always provide high location accuracy, even if site
|
||||
# doesn't actually request this level of accuracy.
|
||||
# Almost no site correctly requests high accuracy so force it by default
|
||||
# for compatibility with other geolocation providers.
|
||||
- name: geo.provider.geoclue.always_high_accuracy
|
||||
type: bool
|
||||
value: true
|
||||
mirror: always
|
||||
#endif
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Prefs starting with "gfx."
|
||||
#---------------------------------------------------------------------------
|
||||
|
@ -9,6 +9,7 @@
|
||||
// Allows to use RefPtr<T> with various kinds of GObjects
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
@ -41,6 +42,7 @@ GOBJECT_TRAITS(GAppLaunchContext)
|
||||
GOBJECT_TRAITS(GdkDragContext)
|
||||
GOBJECT_TRAITS(GDBusMessage)
|
||||
GOBJECT_TRAITS(GdkPixbuf)
|
||||
GOBJECT_TRAITS(GCancellable)
|
||||
|
||||
#ifdef MOZ_ENABLE_DBUS
|
||||
GOBJECT_TRAITS(DBusGProxy)
|
||||
|
Loading…
Reference in New Issue
Block a user