mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57: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:
parent
4a64bb80ea
commit
b6f49924be
8 changed files with 34 additions and 76 deletions
|
@ -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
|
// Connect to LaunchServer immediately and let it know that we won't ask for anything other than opening
|
||||||
// the user's downloads directory.
|
// the user's downloads directory.
|
||||||
// FIXME: This should go away with a standalone download manager at some point.
|
// 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()))
|
TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol(Core::StandardPaths::downloads_directory())));
|
||||||
|| !Desktop::Launcher::seal_allowlist()) {
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
warnln("Failed to set up allowed launch URLs");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY(Core::System::unveil("/home", "rwc"));
|
TRY(Core::System::unveil("/home", "rwc"));
|
||||||
TRY(Core::System::unveil("/res", "r"));
|
TRY(Core::System::unveil("/res", "r"));
|
||||||
|
|
|
@ -24,13 +24,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
auto app = TRY(GUI::Application::try_create(arguments));
|
auto app = TRY(GUI::Application::try_create(arguments));
|
||||||
|
|
||||||
if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") }));
|
||||||
"/bin/Help",
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
{ 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(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath", nullptr));
|
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath", nullptr));
|
||||||
|
|
||||||
|
|
|
@ -38,21 +38,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
auto app = TRY(GUI::Application::try_create(arguments));
|
auto app = TRY(GUI::Application::try_create(arguments));
|
||||||
|
|
||||||
if (!Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer")) {
|
TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer"));
|
||||||
warnln("Failed to set up allowed launch URLs");
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/ImageViewer.md") }));
|
||||||
return 1;
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto app_icon = GUI::Icon::default_icon("filetype-image");
|
auto app_icon = GUI::Icon::default_icon("filetype-image");
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") }));
|
||||||
"/bin/Help",
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
{ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
window->set_title("Inspector");
|
window->set_title("Inspector");
|
||||||
window->resize(685, 500);
|
window->resize(685, 500);
|
||||||
|
|
|
@ -66,13 +66,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto app = TRY(GUI::Application::try_create(arguments));
|
auto app = TRY(GUI::Application::try_create(arguments));
|
||||||
|
|
||||||
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath unix", nullptr));
|
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",
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") }));
|
||||||
{ URL::create_with_file_protocol("/usr/share/man/man1/Playground.md") })
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
|| !Desktop::Launcher::seal_allowlist()) {
|
|
||||||
warnln("Failed to set up allowed launch URLs");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr));
|
TRY(Core::System::pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr));
|
||||||
|
|
||||||
|
|
|
@ -78,13 +78,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
auto window = TRY(GUI::Window::try_create());
|
auto window = TRY(GUI::Window::try_create());
|
||||||
|
|
||||||
if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls(
|
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/Profiler.md") }));
|
||||||
"/bin/Help",
|
TRY(Desktop::Launcher::seal_allowlist());
|
||||||
{ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
window->set_title("Profiler");
|
window->set_title("Profiler");
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
|
@ -50,44 +50,36 @@ static LaunchServerConnection& connection()
|
||||||
return 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);
|
auto response_or_error = connection().try_add_allowed_url(url);
|
||||||
if (response_or_error.is_error()) {
|
if (response_or_error.is_error())
|
||||||
dbgln("Launcher::add_allowed_url: Failed");
|
return Error::from_string_literal("Launcher::add_allowed_url: Failed"sv);
|
||||||
return false;
|
return {};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
auto response_or_error = connection().try_add_allowed_handler_with_any_url(handler);
|
||||||
if (response_or_error.is_error()) {
|
if (response_or_error.is_error())
|
||||||
dbgln("Launcher::add_allowed_handler_with_any_url: Failed");
|
return Error::from_string_literal("Launcher::add_allowed_handler_with_any_url: Failed"sv);
|
||||||
return false;
|
return {};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
auto response_or_error = connection().try_add_allowed_handler_with_only_specific_urls(handler, urls);
|
||||||
if (response_or_error.is_error()) {
|
if (response_or_error.is_error())
|
||||||
dbgln("Launcher::add_allowed_handler_with_only_specific_urls: Failed");
|
return Error::from_string_literal("Launcher::add_allowed_handler_with_only_specific_urls: Failed"sv);
|
||||||
return false;
|
return {};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::seal_allowlist()
|
ErrorOr<void> Launcher::seal_allowlist()
|
||||||
{
|
{
|
||||||
auto response_or_error = connection().try_seal_allowlist();
|
auto response_or_error = connection().try_seal_allowlist();
|
||||||
if (response_or_error.is_error()) {
|
if (response_or_error.is_error())
|
||||||
dbgln("Launcher::seal_allowlist: Failed");
|
return Error::from_string_literal("Launcher::seal_allowlist: Failed"sv);
|
||||||
return false;
|
return {};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::open(const URL& url, const String& handler_name)
|
bool Launcher::open(const URL& url, const String& handler_name)
|
||||||
|
|
|
@ -31,10 +31,10 @@ public:
|
||||||
static NonnullRefPtr<Details> from_details_str(const String&);
|
static NonnullRefPtr<Details> from_details_str(const String&);
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] static bool add_allowed_url(const URL&);
|
static ErrorOr<void> add_allowed_url(URL const&);
|
||||||
[[nodiscard]] static bool add_allowed_handler_with_any_url(const String& handler);
|
static ErrorOr<void> add_allowed_handler_with_any_url(String const& handler);
|
||||||
[[nodiscard]] static bool add_allowed_handler_with_only_specific_urls(const String& handler, const Vector<URL>&);
|
static ErrorOr<void> add_allowed_handler_with_only_specific_urls(String const& handler, Vector<URL> const&);
|
||||||
[[nodiscard]] static bool seal_allowlist();
|
static ErrorOr<void> seal_allowlist();
|
||||||
static bool open(const URL&, const String& handler_name = {});
|
static bool open(const URL&, const String& handler_name = {});
|
||||||
static bool open(const URL&, const Details& details);
|
static bool open(const URL&, const Details& details);
|
||||||
static Vector<String> get_handlers_for_url(const URL&);
|
static Vector<String> get_handlers_for_url(const URL&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue