Bug 928217 - Enable core location geolocation conditionally. r=jdm/smichaud

This commit is contained in:
Doug Turner 2013-10-20 17:53:09 -07:00
parent 9694719958
commit b228df0f72
3 changed files with 39 additions and 1 deletions

View File

@ -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

View File

@ -32,6 +32,8 @@ public:
NS_DECL_NSIGEOLOCATIONPROVIDER
CoreLocationLocationProvider();
static bool IsCoreLocationAvailable();
private:
virtual ~CoreLocationLocationProvider() {};

View File

@ -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()
{