1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:37:35 +00:00

LibDesktop: Make allowlist APIs return ErrorOr<void>

This makes it very smooth to use TRY() when setting up these lists,
as you can see in the rest of this commit. :^)
This commit is contained in:
Andreas Kling 2021-11-24 00:23:00 +01:00
parent 4a64bb80ea
commit b6f49924be
8 changed files with 34 additions and 76 deletions

View file

@ -50,44 +50,36 @@ static LaunchServerConnection& connection()
return connection;
}
bool Launcher::add_allowed_url(const URL& url)
ErrorOr<void> Launcher::add_allowed_url(URL const& url)
{
auto response_or_error = connection().try_add_allowed_url(url);
if (response_or_error.is_error()) {
dbgln("Launcher::add_allowed_url: Failed");
return false;
}
return true;
if (response_or_error.is_error())
return Error::from_string_literal("Launcher::add_allowed_url: Failed"sv);
return {};
}
bool Launcher::add_allowed_handler_with_any_url(const String& handler)
ErrorOr<void> Launcher::add_allowed_handler_with_any_url(String const& handler)
{
auto response_or_error = connection().try_add_allowed_handler_with_any_url(handler);
if (response_or_error.is_error()) {
dbgln("Launcher::add_allowed_handler_with_any_url: Failed");
return false;
}
return true;
if (response_or_error.is_error())
return Error::from_string_literal("Launcher::add_allowed_handler_with_any_url: Failed"sv);
return {};
}
bool Launcher::add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>& urls)
ErrorOr<void> Launcher::add_allowed_handler_with_only_specific_urls(String const& handler, Vector<URL> const& urls)
{
auto response_or_error = connection().try_add_allowed_handler_with_only_specific_urls(handler, urls);
if (response_or_error.is_error()) {
dbgln("Launcher::add_allowed_handler_with_only_specific_urls: Failed");
return false;
}
return true;
if (response_or_error.is_error())
return Error::from_string_literal("Launcher::add_allowed_handler_with_only_specific_urls: Failed"sv);
return {};
}
bool Launcher::seal_allowlist()
ErrorOr<void> Launcher::seal_allowlist()
{
auto response_or_error = connection().try_seal_allowlist();
if (response_or_error.is_error()) {
dbgln("Launcher::seal_allowlist: Failed");
return false;
}
return true;
if (response_or_error.is_error())
return Error::from_string_literal("Launcher::seal_allowlist: Failed"sv);
return {};
}
bool Launcher::open(const URL& url, const String& handler_name)

View file

@ -31,10 +31,10 @@ public:
static NonnullRefPtr<Details> from_details_str(const String&);
};
[[nodiscard]] static bool add_allowed_url(const URL&);
[[nodiscard]] static bool add_allowed_handler_with_any_url(const String& handler);
[[nodiscard]] static bool add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>&);
[[nodiscard]] static bool seal_allowlist();
static ErrorOr<void> add_allowed_url(URL const&);
static ErrorOr<void> add_allowed_handler_with_any_url(String const& handler);
static ErrorOr<void> add_allowed_handler_with_only_specific_urls(String const& handler, Vector<URL> const&);
static ErrorOr<void> seal_allowlist();
static bool open(const URL&, const String& handler_name = {});
static bool open(const URL&, const Details& details);
static Vector<String> get_handlers_for_url(const URL&);