Bug 1676932 - Remove nsIContentPermissionRequester. r=nika

It's an empty, useless interface after the previous patches. Also remove
a bunch of expired geolocation probes which were null-checking the requester
object for some reason.

Depends on D96882

Differential Revision: https://phabricator.services.mozilla.com/D96883
This commit is contained in:
Emilio Cobos Álvarez 2020-11-12 20:23:52 +00:00
parent 48f4d27aa6
commit ab402ee088
5 changed files with 4 additions and 205 deletions

View File

@ -443,18 +443,6 @@ void nsContentPermissionUtils::NotifyRemoveContentPermissionRequestChild(
ContentPermissionRequestChildMap().erase(it);
}
NS_IMPL_ISUPPORTS(nsContentPermissionRequester, nsIContentPermissionRequester)
nsContentPermissionRequester::nsContentPermissionRequester(
nsPIDOMWindowInner* aWindow)
: mWindow(do_GetWeakReference(aWindow)),
mListener(new VisibilityChangeListener(aWindow)) {}
nsContentPermissionRequester::~nsContentPermissionRequester() {
mListener->RemoveListener();
mListener = nullptr;
}
static nsIPrincipal* GetTopLevelPrincipal(nsPIDOMWindowInner* aWindow) {
MOZ_ASSERT(aWindow);
@ -491,7 +479,6 @@ ContentPermissionRequestBase::ContentPermissionRequestBase(
: mPrincipal(aPrincipal),
mTopLevelPrincipal(aWindow ? ::GetTopLevelPrincipal(aWindow) : nullptr),
mWindow(aWindow),
mRequester(aWindow ? new nsContentPermissionRequester(aWindow) : nullptr),
mPrefName(aPrefName),
mType(aType),
mIsHandlingUserInput(false),
@ -569,16 +556,6 @@ ContentPermissionRequestBase::GetIsHandlingUserInput(
return NS_OK;
}
NS_IMETHODIMP
ContentPermissionRequestBase::GetRequester(
nsIContentPermissionRequester** aRequester) {
NS_ENSURE_ARG_POINTER(aRequester);
nsCOMPtr<nsIContentPermissionRequester> requester = mRequester;
requester.forget(aRequester);
return NS_OK;
}
NS_IMETHODIMP
ContentPermissionRequestBase::GetTypes(nsIArray** aTypes) {
nsTArray<nsString> emptyOptions;
@ -743,24 +720,6 @@ nsresult TranslateChoices(
} // namespace mozilla::dom
NS_IMPL_ISUPPORTS(
nsContentPermissionRequestProxy::nsContentPermissionRequesterProxy,
nsIContentPermissionRequester)
void nsContentPermissionRequestProxy::nsContentPermissionRequesterProxy ::
NotifyVisibilityResult(const bool& aIsVisible) {
if (mWaitGettingResult) {
MOZ_ASSERT(mGetCallback);
mWaitGettingResult = false;
mGetCallback->NotifyVisibility(aIsVisible);
return;
}
if (mOnChangeCallback) {
mOnChangeCallback->NotifyVisibility(aIsVisible);
}
}
nsContentPermissionRequestProxy::nsContentPermissionRequestProxy(
ContentPermissionRequestParent* parent)
: mParent(parent) {
@ -772,7 +731,6 @@ nsContentPermissionRequestProxy::~nsContentPermissionRequestProxy() = default;
nsresult nsContentPermissionRequestProxy::Init(
const nsTArray<PermissionRequest>& requests) {
mPermissionRequests = requests.Clone();
mRequester = new nsContentPermissionRequesterProxy();
nsCOMPtr<nsIContentPermissionPrompt> prompt =
do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
@ -785,7 +743,6 @@ nsresult nsContentPermissionRequestProxy::Init(
}
void nsContentPermissionRequestProxy::OnParentDestroyed() {
mRequester = nullptr;
mParent = nullptr;
}
@ -924,22 +881,6 @@ nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices) {
return NS_OK;
}
void nsContentPermissionRequestProxy::NotifyVisibility(const bool& aIsVisible) {
MOZ_ASSERT(mRequester);
mRequester->NotifyVisibilityResult(aIsVisible);
}
NS_IMETHODIMP
nsContentPermissionRequestProxy::GetRequester(
nsIContentPermissionRequester** aRequester) {
NS_ENSURE_ARG_POINTER(aRequester);
RefPtr<nsContentPermissionRequesterProxy> requester = mRequester;
requester.forget(aRequester);
return NS_OK;
}
// RemotePermissionRequest
NS_IMPL_ISUPPORTS(RemotePermissionRequest, nsIContentPermissionRequestCallback);

View File

@ -90,21 +90,6 @@ class nsContentPermissionUtils {
PContentPermissionRequestChild* aChild);
};
class nsContentPermissionRequester final
: public nsIContentPermissionRequester {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTPERMISSIONREQUESTER
explicit nsContentPermissionRequester(nsPIDOMWindowInner* aWindow);
private:
virtual ~nsContentPermissionRequester();
nsWeakPtr mWindow;
RefPtr<VisibilityChangeListener> mListener;
};
nsresult TranslateChoices(
JS::HandleValue aChoices,
const nsTArray<PermissionRequest>& aPermissionRequests,
@ -125,7 +110,6 @@ class ContentPermissionRequestBase : public nsIContentPermissionRequest {
NS_IMETHOD GetIsHandlingUserInput(bool* aIsHandlingUserInput) override;
NS_IMETHOD GetMaybeUnsafePermissionDelegate(
bool* aMaybeUnsafePermissionDelegate) override;
NS_IMETHOD GetRequester(nsIContentPermissionRequester** aRequester) override;
// Overrides for Allow() and Cancel() aren't provided by this class.
// That is the responsibility of the subclasses.
@ -158,7 +142,6 @@ class ContentPermissionRequestBase : public nsIContentPermissionRequest {
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
nsCOMPtr<nsPIDOMWindowInner> mWindow;
nsCOMPtr<nsIContentPermissionRequester> mRequester;
RefPtr<PermissionDelegateHandler> mPermissionHandler;
nsCString mPrefName;
nsCString mType;
@ -186,23 +169,6 @@ class nsContentPermissionRequestProxy : public nsIContentPermissionRequest {
void NotifyVisibility(const bool& aIsVisible);
private:
class nsContentPermissionRequesterProxy final
: public nsIContentPermissionRequester {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTPERMISSIONREQUESTER
explicit nsContentPermissionRequesterProxy() : mWaitGettingResult(false) {}
void NotifyVisibilityResult(const bool& aIsVisible);
private:
virtual ~nsContentPermissionRequesterProxy() = default;
bool mWaitGettingResult;
nsCOMPtr<nsIContentPermissionRequestCallback> mGetCallback;
nsCOMPtr<nsIContentPermissionRequestCallback> mOnChangeCallback;
};
virtual ~nsContentPermissionRequestProxy();
@ -210,7 +176,6 @@ class nsContentPermissionRequestProxy : public nsIContentPermissionRequest {
// this proxy.
ContentPermissionRequestParent* mParent;
nsTArray<mozilla::dom::PermissionRequest> mPermissionRequests;
RefPtr<nsContentPermissionRequesterProxy> mRequester;
};
/**

View File

@ -77,7 +77,7 @@ class nsGeolocationRequest final : public ContentPermissionRequestBase,
nsGeolocationRequest(Geolocation* aLocator, GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
UniquePtr<PositionOptions>&& aOptions,
uint8_t aProtocolType, nsIEventTarget* aMainThreadTarget,
nsIEventTarget* aMainThreadTarget,
bool aWatchPositionRequest = false,
int32_t aWatchId = 0);
@ -140,8 +140,6 @@ class nsGeolocationRequest final : public ContentPermissionRequestBase,
int32_t mWatchId;
bool mShutdown;
nsCOMPtr<nsIContentPermissionRequester> mRequester;
uint8_t mProtocolType;
nsCOMPtr<nsIEventTarget> mMainThreadTarget;
};
@ -192,7 +190,7 @@ static nsPIDOMWindowInner* ConvertWeakReferenceToWindow(
nsGeolocationRequest::nsGeolocationRequest(
Geolocation* aLocator, GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
UniquePtr<PositionOptions>&& aOptions, uint8_t aProtocolType,
UniquePtr<PositionOptions>&& aOptions,
nsIEventTarget* aMainThreadTarget, bool aWatchPositionRequest,
int32_t aWatchId)
: ContentPermissionRequestBase(
@ -206,7 +204,6 @@ nsGeolocationRequest::nsGeolocationRequest(
mLocator(aLocator),
mWatchId(aWatchId),
mShutdown(false),
mProtocolType(aProtocolType),
mMainThreadTarget(aMainThreadTarget) {
if (nsCOMPtr<nsPIDOMWindowInner> win =
do_QueryReferent(mLocator->GetOwner())) {
@ -242,14 +239,6 @@ void nsGeolocationRequest::NotifyErrorAndShutdown(uint16_t aErrorCode) {
NS_IMETHODIMP
nsGeolocationRequest::Cancel() {
if (mRequester) {
// Record the number of denied requests for regular web content.
// This method is only called when the user explicitly denies the request,
// and is not called when the page is simply unloaded, or similar.
Telemetry::Accumulate(Telemetry::GEOLOCATION_REQUEST_GRANTED,
mProtocolType);
}
if (mLocator->ClearPendingRequest(this)) {
return NS_OK;
}
@ -262,31 +251,6 @@ NS_IMETHODIMP
nsGeolocationRequest::Allow(JS::HandleValue aChoices) {
MOZ_ASSERT(aChoices.isUndefined());
if (mRequester) {
// Record the number of granted requests for regular web content.
Telemetry::Accumulate(Telemetry::GEOLOCATION_REQUEST_GRANTED,
mProtocolType + 10);
// Record whether a location callback is fulfilled while the owner window
// is not visible.
bool isVisible = false;
nsCOMPtr<nsPIDOMWindowInner> window = mLocator->GetParentObject();
if (window) {
nsCOMPtr<Document> doc = window->GetDoc();
isVisible = doc && !doc->Hidden();
}
if (IsWatch()) {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::GEOLOCATION_WATCHPOSITION_VISIBLE, isVisible);
} else {
mozilla::Telemetry::Accumulate(
mozilla::Telemetry::GEOLOCATION_GETCURRENTPOSITION_VISIBLE,
isVisible);
}
}
if (mLocator->ClearPendingRequest(this)) {
return NS_OK;
}
@ -1025,14 +989,10 @@ nsresult Geolocation::GetCurrentPosition(GeoPositionCallback callback,
// After this we hand over ownership of options to our nsGeolocationRequest.
// Count the number of requests per protocol/scheme.
Telemetry::Accumulate(Telemetry::GEOLOCATION_GETCURRENTPOSITION_SECURE_ORIGIN,
static_cast<uint8_t>(mProtocolType));
nsIEventTarget* target = MainThreadTarget(this);
RefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(
this, std::move(callback), std::move(errorCallback), std::move(options),
static_cast<uint8_t>(mProtocolType), target);
target);
if (!StaticPrefs::geo_enabled() || ShouldBlockInsecureRequests() ||
!request->CheckPermissionDelegate()) {
@ -1094,18 +1054,13 @@ int32_t Geolocation::WatchPosition(GeoPositionCallback aCallback,
return -1;
}
// Count the number of requests per protocol/scheme.
Telemetry::Accumulate(Telemetry::GEOLOCATION_WATCHPOSITION_SECURE_ORIGIN,
static_cast<uint8_t>(mProtocolType));
// The watch ID:
int32_t watchId = mLastWatchId++;
nsIEventTarget* target = MainThreadTarget(this);
RefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(
this, std::move(aCallback), std::move(aErrorCallback),
std::move(aOptions), static_cast<uint8_t>(mProtocolType), target, true,
watchId);
std::move(aOptions), target, true, watchId);
if (!StaticPrefs::geo_enabled() || ShouldBlockInsecureRequests() ||
!request->CheckPermissionDelegate()) {

View File

@ -38,14 +38,6 @@ interface nsIContentPermissionRequestCallback : nsISupports {
void notifyVisibility(in boolean isVisible);
};
/**
* Interface provides the way to get the visibility and
* the notification.
*/
[scriptable, uuid(f8577124-6a5f-486f-ae04-c5bcae911eb5)]
interface nsIContentPermissionRequester : nsISupports {
};
/**
* Interface allows access to a content to request
* permission to perform a privileged operation such as
@ -81,11 +73,6 @@ interface nsIContentPermissionRequest : nsISupports {
readonly attribute boolean isHandlingUserInput;
readonly attribute boolean maybeUnsafePermissionDelegate;
/**
* The requester to get the required information of
* the window.
*/
readonly attribute nsIContentPermissionRequester requester;
/*
* Get delegate principal of the permission request. This will return nullptr,

View File

@ -1032,37 +1032,6 @@
"kind": "flag",
"description": "Has seen location error"
},
"GEOLOCATION_GETCURRENTPOSITION_SECURE_ORIGIN" : {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["mds@mozilla.com"],
"expires_in_version": "60",
"kind": "enumerated",
"n_values": 10,
"bug_numbers": [1230209],
"description" : "Number of navigator.geolocation.getCurrentPosition() calls (0=other, 1=http, 2=https)"
},
"GEOLOCATION_REQUEST_GRANTED": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["tdsmith@mozilla.com"],
"expires_in_version": "72",
"kind": "enumerated",
"n_values": 20,
"releaseChannelCollection": "opt-out",
"bug_numbers": [1230209, 1494496, 1519170, 1544539],
"description": "Geolocation requests either granted or denied (0=denied/other, 1=denied/http, 2=denied/https, ..., 10=granted/other, 11=granted/http, 12=granted/https)"
},
"GEOLOCATION_WATCHPOSITION_SECURE_ORIGIN" : {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["mds@mozilla.com"],
"expires_in_version": "60",
"kind": "enumerated",
"n_values": 10,
"bug_numbers": [1230209],
"description" : "Number of navigator.geolocation.watchPosition() calls (0=other, 1=http, 2=https)"
},
"GEOLOCATION_WIN8_SOURCE_IS_MLS": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
@ -1077,24 +1046,6 @@
"kind": "boolean",
"description": "Geolocation on OS X is either MLS or CoreLocation"
},
"GEOLOCATION_GETCURRENTPOSITION_VISIBLE": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["mds@mozilla.com"],
"expires_in_version": "60",
"kind": "boolean",
"bug_numbers": [1255198],
"description": "This metric is recorded every time a navigator.geolocation.getCurrentPosition() request gets allowed/fulfilled. A false value is recorded if the owner is not visible according to document.isVisible."
},
"GEOLOCATION_WATCHPOSITION_VISIBLE": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],
"alert_emails": ["mds@mozilla.com"],
"expires_in_version": "60",
"kind": "boolean",
"bug_numbers": [1255198],
"description": "This metric is recorded every time a navigator.geolocation.watchPosition() request gets allowed/fulfilled. A false value is recorded if the owner is not visible according to document.isVisible."
},
"GPU_PROCESS_LAUNCH_TIME_MS_2" : {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],