Bug 1529591 - Check Mac system geo permission prior to showing request permission dialog. r=jdm

Differential Revision: https://phabricator.services.mozilla.com/D42540

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Garvan Keeley 2019-08-19 20:42:17 +00:00
parent e2e22e8792
commit 4f07263f06
8 changed files with 67 additions and 8 deletions

View File

@ -30,6 +30,7 @@
#include "nsIObserverService.h"
#include "nsIScriptError.h"
#include "nsPIDOMWindow.h"
#include "nsIXULRuntime.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
@ -1216,22 +1217,57 @@ void Geolocation::NotifyAllowedRequest(nsGeolocationRequest* aRequest) {
}
}
bool Geolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) {
bool Geolocation::RegisterRequestWithPromptImpl(
nsGeolocationRequest* aRequest) {
nsIEventTarget* target = MainThreadTarget(this);
ContentPermissionRequestBase::PromptResult pr = request->CheckPromptPrefs();
ContentPermissionRequestBase::PromptResult pr = aRequest->CheckPromptPrefs();
if (pr == ContentPermissionRequestBase::PromptResult::Granted) {
request->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Allow);
aRequest->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Allow);
return true;
}
if (pr == ContentPermissionRequestBase::PromptResult::Denied) {
request->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Deny);
aRequest->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Deny);
return true;
}
request->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Request);
aRequest->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Request);
return true;
}
bool Geolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) {
if (XRE_IsParentProcess()) {
#ifdef MOZ_WIDGET_COCOA
if (!isMacGeoSystemPermissionEnabled()) {
return false;
}
#endif
return RegisterRequestWithPromptImpl(request);
}
RefPtr<Geolocation> self = this;
RefPtr<nsGeolocationRequest> req = request;
nsCOMPtr<nsISerialEventTarget> serialTarget =
SystemGroup::EventTargetFor(TaskCategory::Other);
ContentChild* cpc = ContentChild::GetSingleton();
cpc->SendGetGeoSysPermission()->Then(
serialTarget, __func__,
[req, self](bool aSysPermIsGranted) {
if (!aSysPermIsGranted) {
nsIEventTarget* target = MainThreadTarget(self);
req->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Deny);
} else {
self->RegisterRequestWithPromptImpl(req);
}
},
[req, self](mozilla::ipc::ResponseRejectReason aReason) {
nsIEventTarget* target = MainThreadTarget(self);
req->RequestDelayedTask(target,
nsGeolocationRequest::DelayedTaskType::Deny);
});
return true;
}

View File

@ -197,6 +197,8 @@ class Geolocation final : public nsIGeolocationUpdate, public nsWrapperCache {
bool RegisterRequestWithPrompt(nsGeolocationRequest* request);
bool RegisterRequestWithPromptImpl(nsGeolocationRequest* aRequest);
// Check if clearWatch is already called
bool IsAlreadyCleared(nsGeolocationRequest* aRequest);

View File

@ -236,6 +236,7 @@
#if defined(XP_MACOSX)
# include "nsMacUtilsImpl.h"
# include "CoreLocationLocationProvider.h"
#endif
#if defined(ANDROID) || defined(LINUX)
@ -4067,6 +4068,16 @@ mozilla::ipc::IPCResult ContentParent::RecvAddGeolocationListener(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvGetGeoSysPermission(
std::function<void(const bool)>&& aCallback) {
#ifdef MOZ_WIDGET_COCOA
aCallback(isMacGeoSystemPermissionEnabled());
#else
aCallback(true);
#endif
return IPC_OK();
}
mozilla::ipc::IPCResult ContentParent::RecvRemoveGeolocationListener() {
if (mGeolocationWatchID != -1) {
RefPtr<Geolocation> geo = Geolocation::NonWindowSingleton();

View File

@ -1000,6 +1000,9 @@ class ContentParent final : public PContentParent,
const IPC::Principal& aPrincipal, const bool& aHighAccuracy);
mozilla::ipc::IPCResult RecvRemoveGeolocationListener();
mozilla::ipc::IPCResult RecvGetGeoSysPermission(
std::function<void(const bool)>&& aCallback);
// MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
// in IPC code yet.
MOZ_CAN_RUN_SCRIPT_BOUNDARY

View File

@ -960,6 +960,8 @@ parent:
async RemoveGeolocationListener();
async SetGeolocationHigherAccuracy(bool enable);
async GetGeoSysPermission() returns (bool isok);
async ConsoleMessage(nsString message);
async ScriptError(nsString message, nsString sourceName, nsString sourceLine,
uint32_t lineNumber, uint32_t colNumber, uint32_t flags,

View File

@ -25,6 +25,8 @@
class CoreLocationObjects;
class MLSFallback;
bool isMacGeoSystemPermissionEnabled();
class CoreLocationLocationProvider : public nsIGeolocationProvider {
public:
NS_DECL_ISUPPORTS

View File

@ -32,6 +32,8 @@ using namespace mozilla;
static const CLLocationAccuracy kHIGH_ACCURACY = kCLLocationAccuracyBest;
static const CLLocationAccuracy kDEFAULT_ACCURACY = kCLLocationAccuracyNearestTenMeters;
bool isMacGeoSystemPermissionEnabled() { return [CLLocationManager locationServicesEnabled]; }
@interface LocationDelegate : NSObject <CLLocationManagerDelegate> {
CoreLocationLocationProvider* mProvider;
}

View File

@ -10,6 +10,7 @@ SOURCES += [
]
EXPORTS += [
'CoreLocationLocationProvider.h',
'nsOSPermissionRequest.h',
]