mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 928217 - Enable core location geolocation conditionally. r=jdm/smichaud
This commit is contained in:
parent
9694719958
commit
b228df0f72
@ -675,7 +675,8 @@ nsresult nsGeolocationService::Init()
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_COCOA
|
||||
if (Preferences::GetBool("geo.provider.use_corelocation", false)) {
|
||||
if (Preferences::GetBool("geo.provider.use_corelocation", true) &&
|
||||
CoreLocationLocationProvider::IsCoreLocationAvailable()) {
|
||||
mProvider = new CoreLocationLocationProvider();
|
||||
}
|
||||
#endif
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
NS_DECL_NSIGEOLOCATIONPROVIDER
|
||||
|
||||
CoreLocationLocationProvider();
|
||||
static bool IsCoreLocationAvailable();
|
||||
|
||||
private:
|
||||
virtual ~CoreLocationLocationProvider() {};
|
||||
|
||||
|
@ -17,6 +17,12 @@
|
||||
#include <CoreLocation/CLLocationManager.h>
|
||||
#include <CoreLocation/CLLocationManagerDelegate.h>
|
||||
|
||||
#include <objc/objc.h>
|
||||
#include <objc/objc-runtime.h>
|
||||
|
||||
#include "nsObjCExceptions.h"
|
||||
#import <CoreWLAN/CoreWLAN.h>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static const CLLocationAccuracy kHIGH_ACCURACY = kCLLocationAccuracyBest;
|
||||
@ -125,6 +131,35 @@ CoreLocationLocationProvider::CoreLocationLocationProvider()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
CoreLocationLocationProvider::IsCoreLocationAvailable()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@try {
|
||||
NSBundle * bundle = [[[NSBundle alloc] initWithPath:@"/System/Library/Frameworks/CoreWLAN.framework"] autorelease];
|
||||
if (!bundle) {
|
||||
[pool release];
|
||||
return false;
|
||||
}
|
||||
|
||||
Class CWI_class = [bundle classNamed:@"CWInterface"];
|
||||
if (!CWI_class) {
|
||||
[pool release];
|
||||
return false;
|
||||
}
|
||||
|
||||
if ([[[CWI_class interface] interfaceState] intValue] == kCWInterfaceStateRunning) {
|
||||
[pool release];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@catch(NSException *e) {
|
||||
}
|
||||
[pool release];
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CoreLocationLocationProvider::Startup()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user