summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-24 00:23:00 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-24 00:25:23 +0100
commitb6f49924bec74d93d52dae7b311938e37c68947e (patch)
tree6b55f53a1528fb57a442e6f97742ac4e691cb2e5 /Userland
parent4a64bb80eaec84de46a12dac74c27cbf1a0b1bd8 (diff)
downloadserenity-b6f49924bec74d93d52dae7b311938e37c68947e.zip
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. :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Browser/main.cpp7
-rw-r--r--Userland/Applications/FontEditor/main.cpp9
-rw-r--r--Userland/Applications/ImageViewer/main.cpp18
-rw-r--r--Userland/DevTools/Inspector/main.cpp9
-rw-r--r--Userland/DevTools/Playground/main.cpp10
-rw-r--r--Userland/DevTools/Profiler/main.cpp9
-rw-r--r--Userland/Libraries/LibDesktop/Launcher.cpp40
-rw-r--r--Userland/Libraries/LibDesktop/Launcher.h8
8 files changed, 34 insertions, 76 deletions
diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp
index 339deb19aa..393dc5e0c7 100644
--- a/Userland/Applications/Browser/main.cpp
+++ b/Userland/Applications/Browser/main.cpp
@@ -54,11 +54,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// Connect to LaunchServer immediately and let it know that we won't ask for anything other than opening
// the user's downloads directory.
// FIXME: This should go away with a standalone download manager at some point.
- if (!Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol(Core::StandardPaths::downloads_directory()))
- || !Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
+ TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol(Core::StandardPaths::downloads_directory())));
+ TRY(Desktop::Launcher::seal_allowlist());
TRY(Core::System::unveil("/home", "rwc"));
TRY(Core::System::unveil("/res", "r"));
diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp
index b9c6e9c413..388454448b 100644
--- a/Userland/Applications/FontEditor/main.cpp
+++ b/Userland/Applications/FontEditor/main.cpp
@@ -24,13 +24,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
- if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
- "/bin/Help",
- { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") })
- || !Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
+ TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") }));
+ TRY(Desktop::Launcher::seal_allowlist());
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath", nullptr));
diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp
index b9fc9a88a5..e6cc44b60a 100644
--- a/Userland/Applications/ImageViewer/main.cpp
+++ b/Userland/Applications/ImageViewer/main.cpp
@@ -38,21 +38,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
- if (!Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer")) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
-
- if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
- "/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") })) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
-
- if (!Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to seal allowed launch URLs");
- return 1;
- }
+ TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer"));
+ TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") }));
+ TRY(Desktop::Launcher::seal_allowlist());
auto app_icon = GUI::Icon::default_icon("filetype-image");
diff --git a/Userland/DevTools/Inspector/main.cpp b/Userland/DevTools/Inspector/main.cpp
index d3abcaa10f..e9a5fe3682 100644
--- a/Userland/DevTools/Inspector/main.cpp
+++ b/Userland/DevTools/Inspector/main.cpp
@@ -79,13 +79,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
}
- if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
- "/bin/Help",
- { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") })
- || !Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
+ TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") }));
+ TRY(Desktop::Launcher::seal_allowlist());
window->set_title("Inspector");
window->resize(685, 500);
diff --git a/Userland/DevTools/Playground/main.cpp b/Userland/DevTools/Playground/main.cpp
index f35f5543c2..ce7f4b1b08 100644
--- a/Userland/DevTools/Playground/main.cpp
+++ b/Userland/DevTools/Playground/main.cpp
@@ -66,13 +66,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix", nullptr));
- if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
- "/bin/Help",
- { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") })
- || !Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
+
+ TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") }));
+ TRY(Desktop::Launcher::seal_allowlist());
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr));
diff --git a/Userland/DevTools/Profiler/main.cpp b/Userland/DevTools/Profiler/main.cpp
index 162ce7d536..822660755a 100644
--- a/Userland/DevTools/Profiler/main.cpp
+++ b/Userland/DevTools/Profiler/main.cpp
@@ -78,13 +78,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::Window::try_create());
- if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
- "/bin/Help",
- { URL::create_with_file_protocol("/usr/share/man/man1/Profiler.md") })
- || !Desktop::Launcher::seal_allowlist()) {
- warnln("Failed to set up allowed launch URLs");
- return 1;
- }
+ TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Profiler.md") }));
+ TRY(Desktop::Launcher::seal_allowlist());
window->set_title("Profiler");
window->set_icon(app_icon.bitmap_for_size(16));
diff --git a/Userland/Libraries/LibDesktop/Launcher.cpp b/Userland/Libraries/LibDesktop/Launcher.cpp
index 36a2af332c..4af7c4c8de 100644
--- a/Userland/Libraries/LibDesktop/Launcher.cpp
+++ b/Userland/Libraries/LibDesktop/Launcher.cpp
@@ -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)
diff --git a/Userland/Libraries/LibDesktop/Launcher.h b/Userland/Libraries/LibDesktop/Launcher.h
index 4612eb6afc..a74a6505a6 100644
--- a/Userland/Libraries/LibDesktop/Launcher.h
+++ b/Userland/Libraries/LibDesktop/Launcher.h
@@ -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&);