introspect: Make invocation check error-based

If we throw an error when the invocation isn't allowed instead of
returning false, we can simply return that error instead of duplicating
the error handling.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1970>
This commit is contained in:
Florian Müllner 2021-09-02 16:23:38 +02:00 committed by Marge Bot
parent 7298ee23e9
commit 3b9e672a09

View File

@ -137,21 +137,23 @@ var IntrospectService = class {
type == Meta.WindowType.UTILITY; type == Meta.WindowType.UTILITY;
} }
_isInvocationAllowed(invocation) { _checkInvocation(invocation) {
if (this._isIntrospectEnabled()) if (this._isIntrospectEnabled())
return true; return;
if (this._isSenderAllowed(invocation.get_sender())) if (this._isSenderAllowed(invocation.get_sender()))
return true; return;
return false; throw new GLib.Error(Gio.DBusError,
Gio.DBusError.ACCESS_DENIED,
'App introspection not allowed');
} }
GetRunningApplicationsAsync(params, invocation) { GetRunningApplicationsAsync(params, invocation) {
if (!this._isInvocationAllowed(invocation)) { try {
invocation.return_error_literal(Gio.DBusError, this._checkInvocation(invocation);
Gio.DBusError.ACCESS_DENIED, } catch (e) {
'App introspection not allowed'); invocation.return_gerror(e);
return; return;
} }
@ -163,10 +165,10 @@ var IntrospectService = class {
let apps = this._appSystem.get_running(); let apps = this._appSystem.get_running();
let windowsList = {}; let windowsList = {};
if (!this._isInvocationAllowed(invocation)) { try {
invocation.return_error_literal(Gio.DBusError, this._checkInvocation(invocation);
Gio.DBusError.ACCESS_DENIED, } catch (e) {
'App introspection not allowed'); invocation.return_gerror(e);
return; return;
} }